:root {
    --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
    color-scheme: dark;
    --paper: #12101c;
    --panel: #1b1829;
    --ink: #ece9f7;
    --muted: #9a96b3;
    --line: #2e2a45;
    --graphite: #0c0a15;
    --graphite-2: #221e36;
    --accent: #8a6cf5;
    --accent-ink: #ffffff;
    --accent-soft: #2b2452;
    --ok: #4cc28f;
    --ok-soft: #14352a;
    --bad: #ef6b7c;
    --bad-soft: #3b1c24;
    --warn: #e0a64a;
    --warn-soft: #3a2d13;
    --info: #86a0f2;
    --info-soft: #1d2650;
    --surface-2: #211e34;
    --surface-hover: #292540;
    --row-line: #26223b;
    --row-hover: #211e33;
    --chip: #2a2640;
    --tab-hover: #2a2640;
    --input-bg: #141220;
    --input-focus: #181526;
    --editor-bg: #131120;
    --disabled: #5f5b78;
    --notice-ink: #f6a9b4;
    --notice-line: #5c2a35;
}

html[data-theme="light"] {
    color-scheme: light;
    --paper: #f3f2f8;
    --panel: #ffffff;
    --ink: #1d1a2b;
    --muted: #6b6880;
    --line: #e2e0ec;
    --graphite: #1f1b2e;
    --graphite-2: #2b2640;
    --accent: #6d4ae0;
    --accent-ink: #ffffff;
    --accent-soft: #ece8fb;
    --ok: #1c8f64;
    --ok-soft: #dff4ea;
    --bad: #c63a4c;
    --bad-soft: #fbe3e6;
    --warn: #a86b12;
    --warn-soft: #fbefd6;
    --info: #3b59c7;
    --info-soft: #e3e9fb;
    --surface-2: #faf9fd;
    --surface-hover: #f4f2fb;
    --row-line: #efedf6;
    --row-hover: #f8f7fc;
    --chip: #efedf6;
    --tab-hover: #e9e6f5;
    --input-bg: #faf9fd;
    --input-focus: #ffffff;
    --editor-bg: #fcfbff;
    --disabled: #aaa7bd;
    --notice-ink: #8d2232;
    --notice-line: #f1c3ca;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    background: var(--paper);
    color: var(--ink);
    font: 14px/1.5 var(--sans);
    min-height: 100vh;
}

h1 { font-size: 24px; line-height: 1.2; margin: 0 0 4px; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.muted-light { color: #b4aed0; }
.mono { font-family: var(--mono); font-size: 13px; }
.strong { font-weight: 600; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top {
    background: var(--graphite);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 0 24px;
    height: 58px;
    position: sticky;
    top: 0;
    z-index: 30;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    text-decoration: none;
    font-weight: 650;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.brand.big { font-size: 20px; }

.mark {
    width: 22px;
    height: 22px;
    border-radius: 6px 6px 6px 2px;
    background: var(--accent);
    box-shadow: inset 0 0 0 5px var(--graphite), inset 0 0 0 11px #a58cf5;
    flex: none;
}

.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }

.nav a {
    color: #c9c4e3;
    text-decoration: none;
    padding: 8px 14px;
    border-radius: 6px;
    white-space: nowrap;
    font-weight: 500;
}

.nav a:hover { background: var(--graphite-2); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; }

.who { display: flex; align-items: center; gap: 10px; }

.chip {
    background: var(--graphite-2);
    padding: 4px 12px;
    border-radius: 99px;
    font-weight: 500;
}

.switch { display: flex; align-items: center; gap: 8px; color: #c9c4e3; }

.switch select {
    background: var(--graphite-2);
    color: #fff;
    border: 1px solid #4a4466;
    border-radius: 6px;
    padding: 5px 8px;
    font: inherit;
    max-width: 160px;
}

.role {
    font-size: 12px;
    padding: 2px 10px;
    border-radius: 99px;
    font-weight: 600;
}

.role.admin { background: #a58cf5; color: #1b1433; }
.role.user { background: #4a4466; color: #e6e2f7; }

.wrap { max-width: 1320px; margin: 0 auto; padding: 28px 24px 60px; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.stats { display: flex; gap: 10px; flex-wrap: wrap; }

.stat {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 16px;
    min-width: 96px;
}

.stat b { display: block; font-size: 18px; line-height: 1.3; }
.stat span { color: var(--muted); font-size: 12px; }

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.search {
    flex: 1;
    min-width: 160px;
    max-width: 320px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 7px 10px;
    font: inherit;
    background: var(--input-bg);
    color: var(--ink);
}

.search:focus { border-color: var(--accent); background: var(--input-focus); }

.btn {
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--ink);
    border-radius: 6px;
    padding: 7px 14px;
    font: inherit;
    font-weight: 550;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.btn:hover { background: var(--surface-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #5b39cc; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { background: #a82d3d; }
.btn.ghost { background: transparent; border-color: #4a4466; color: #e6e2f7; padding: 5px 12px; }
.btn.ghost:hover { background: var(--graphite-2); }
.btn.block { width: 100%; padding: 11px 14px; }

.table-wrap { overflow-x: auto; position: relative; }

.grid { width: 100%; border-collapse: collapse; }

.grid th {
    text-align: left;
    font-weight: 600;
    font-size: 12.5px;
    color: var(--muted);
    padding: 10px 14px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.grid td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--row-line);
    vertical-align: middle;
    white-space: nowrap;
}

.grid td.wrap-cell { white-space: normal; max-width: 280px; word-break: break-word; }

.grid tbody tr { cursor: default; }
.grid tbody tr:hover { background: var(--row-hover); }
.grid tbody tr.sel { background: var(--accent-soft); }
.grid tbody tr.hidden { display: none; }

.badge {
    display: inline-block;
    padding: 1px 9px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
}

.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.muted { background: var(--chip); color: var(--muted); }

.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.pad { padding: 24px; text-align: center; }

.notice { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.notice.error { background: var(--bad-soft); color: var(--notice-ink); border: 1px solid var(--notice-line); }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }

.tab {
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    padding: 8px 16px;
    border-radius: 6px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.tab:hover { background: var(--tab-hover); color: var(--ink); }
.tab.active { background: var(--panel); border-color: var(--line); color: var(--accent); }

.count {
    background: var(--tab-hover);
    color: var(--muted);
    border-radius: 99px;
    padding: 0 8px;
    font-size: 12px;
    margin-left: 4px;
}

.tab.active .count { background: var(--accent-soft); color: var(--accent); }

.crumbs {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 2;
    min-width: 200px;
    overflow-x: auto;
    padding: 2px 4px;
    font-family: var(--mono);
    font-size: 13px;
}

.crumbs button {
    background: none;
    border: 0;
    padding: 4px 6px;
    border-radius: 4px;
    font: inherit;
    color: var(--ink);
    cursor: pointer;
    white-space: nowrap;
}

.crumbs button:hover { background: var(--accent-soft); }
.crumbs button:last-child { font-weight: 700; }
.crumbs .sep { color: var(--muted); }

.fm-area { min-height: 420px; max-height: calc(100vh - 290px); overflow-y: auto; }
.fm-grid td.name { display: flex; align-items: center; gap: 10px; }
.fm-grid tbody tr { user-select: none; }
.fname { font-weight: 550; }
.ico { display: inline-flex; width: 20px; height: 20px; flex: none; }
.ico svg { width: 20px; height: 20px; }
.ico.dir { color: #e0a43a; }
.ico.file { color: #8a86a3; }
.fm-status { padding: 8px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; }

.ctx {
    position: fixed;
    z-index: 1000;
    min-width: 200px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(31, 27, 46, 0.22);
    padding: 5px;
}

.ctx-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    border-radius: 5px;
    padding: 8px 12px;
    font: inherit;
    color: var(--ink);
    cursor: pointer;
}

.ctx-item:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); }
.ctx-item.danger { color: var(--bad); }
.ctx-item.danger:hover:not(:disabled) { background: var(--bad-soft); color: var(--bad); }
.ctx-item:disabled { color: var(--disabled); cursor: not-allowed; }
.ctx-sep { height: 1px; background: var(--line); margin: 5px 4px; }

.modal-back {
    position: fixed;
    inset: 0;
    background: rgba(24, 20, 38, 0.55);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal {
    background: var(--panel);
    border-radius: 12px;
    width: 100%;
    max-width: 460px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.modal-head { padding: 16px 20px 6px; font-size: 16px; font-weight: 650; }
.modal-body { padding: 6px 20px 16px; }
.modal-body p { color: var(--muted); margin-bottom: 10px; word-break: break-word; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }

.modal-input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 9px 11px;
    font: inherit;
    background: var(--input-bg);
    color: var(--ink);
    font-family: var(--mono);
    font-size: 13px;
}

.modal-input:focus { border-color: var(--accent); }

.modal.editor {
    max-width: 1100px;
    height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
}

.modal.editor .modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.ed-title { display: flex; flex-direction: column; min-width: 0; }
.ed-title span { font-size: 12px; font-weight: 400; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-actions { display: flex; align-items: center; gap: 8px; font-weight: 400; }

.ed-area {
    flex: 1;
    width: 100%;
    border: 0;
    resize: none;
    padding: 14px 16px;
    font-family: var(--mono);
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--editor-bg);
    tab-size: 4;
    white-space: pre;
    overflow: auto;
}

.ed-area:focus { outline: none; }

.ed-foot {
    display: flex;
    justify-content: space-between;
    padding: 7px 16px;
    border-top: 1px solid var(--line);
    font-size: 12px;
    color: var(--muted);
    font-family: var(--mono);
}

.toasts {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--graphite);
    color: #fff;
    padding: 10px 16px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    max-width: 360px;
    word-break: break-word;
}

.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }

.login-body { background: var(--graphite); display: flex; align-items: center; justify-content: center; padding: 24px; }

.login {
    width: 100%;
    max-width: 880px;
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    background: var(--panel);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.login-side {
    background: var(--graphite-2);
    color: #fff;
    padding: 36px 32px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.login-side p { color: #c9c4e3; font-size: 15px; }

.login-list { margin-top: auto; }

.login-list-head {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
}

.login-chips { display: flex; flex-wrap: wrap; gap: 6px; max-height: 140px; overflow-y: auto; }

.login-chips button {
    background: var(--graphite);
    color: #e6e2f7;
    border: 1px solid #4a4466;
    border-radius: 99px;
    padding: 3px 12px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.login-chips button:hover { background: var(--accent); border-color: var(--accent); }

.login-form { padding: 36px 36px 40px; }
.login-form h1 { font-size: 26px; }
.login-form form { margin-top: 22px; display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-weight: 600; font-size: 13px; }

.field input {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 12px;
    font: inherit;
    background: var(--input-bg);
    color: var(--ink);
}

.field input:focus { border-color: var(--accent); background: var(--input-focus); }

@media (max-width: 860px) {
    .top { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 10px; }
    .nav { order: 3; flex-basis: 100%; }
    .who { margin-left: auto; }
    .wrap { padding: 20px 14px 50px; }
    .login { grid-template-columns: 1fr; }
    .login-side { padding: 24px; }
    .fm-area { max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

.theme-toggle { min-width: 64px; }

.modal.form { max-width: 520px; }
.modal.form .modal-body { max-height: calc(100vh - 220px); overflow-y: auto; }
.form-grid { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field > label { font-weight: 600; font-size: 13px; }
.form-field.check { flex-direction: row; align-items: center; gap: 10px; }
.form-field.check > label { font-weight: 500; font-size: 14px; }
.form-field input[type="text"],
.form-field input[type="password"],
.form-field select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 9px 11px;
    font: inherit;
    background: var(--input-bg);
    color: var(--ink);
}
.form-field input:focus,
.form-field select:focus { border-color: var(--accent); background: var(--input-focus); }
.form-field small { color: var(--muted); font-size: 12px; }
.input-group { display: flex; align-items: stretch; }
.input-group .prefix {
    display: flex;
    align-items: center;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-right: 0;
    border-radius: 6px 0 0 6px;
    background: var(--surface-2);
    color: var(--muted);
    font-family: var(--mono);
    font-size: 13px;
    white-space: nowrap;
}
.input-group input[type="text"] { border-radius: 0 6px 6px 0; }
.pw-row { display: flex; gap: 6px; }
.pw-row input { flex: 1; font-family: var(--mono); }
.form-error {
    background: var(--bad-soft);
    color: var(--notice-ink);
    border: 1px solid var(--notice-line);
    border-radius: 6px;
    padding: 9px 12px;
    font-size: 13px;
}
.form-error[hidden] { display: none; }
.cred-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.cred-list dt { color: var(--muted); }
.cred-list dd { margin: 0; font-family: var(--mono); font-size: 13px; word-break: break-all; }

.perm-grid { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.perm-grid th,
.perm-grid td { padding: 8px; text-align: center; border-bottom: 1px solid var(--row-line); }
.perm-grid th { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.perm-grid th:first-child,
.perm-grid td:first-child { text-align: left; font-weight: 600; }
.perm-grid input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.perm-line { display: flex; align-items: center; gap: 12px; }
.perm-line label { font-weight: 600; font-size: 13px; }
.modal-input.perm-octal { width: 90px; text-align: center; letter-spacing: 0.15em; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); gap: 16px; margin-bottom: 16px; }
.panel.stack { margin-bottom: 16px; }
.card-title { margin: 0; padding: 12px 16px; font-size: 14px; font-weight: 650; border-bottom: 1px solid var(--line); }
.card-body { padding: 6px 16px 12px; }
.kv-row { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--row-line); }
.kv-row:last-child { border-bottom: 0; }
.kv-row span:first-child { color: var(--muted); }
.kv-row span:last-child { font-weight: 600; text-align: right; word-break: break-word; }
.bar { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; min-width: 90px; flex: 1; }
.bar-fill { display: block; height: 100%; border-radius: 99px; background: var(--ok); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.bad { background: var(--bad); }
.bar-cell { display: flex; align-items: center; gap: 10px; }
.bar-cell.usage { padding: 12px 0 8px; }
.stats .btn { align-self: stretch; }