/* net - global styles. Colors and sizes are defined once as tokens. */

:root {
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --radius: 6px;
    --sidebar-width: 224px;
    --topbar-height: 56px;

    --bg: #eef1f8;
    --surface: #fafbfe;
    --surface-2: #e6eaf4;
    --border: #cfd6e6;
    --border-strong: #a9b4cc;
    --text: #1a2238;
    --text-muted: #5a6582;
    --accent: #3a5bb0;
    --accent-hover: #2d4990;
    --accent-text: #ffffff;
    --accent-soft: #dbe4f8;
    --focus: #1f3fa0;
    --ok: #166534;
    --ok-bg: #dcfce7;
    --off: #566080;
    --off-bg: #e2e6f0;
    --warn: #8a4b00;
    --warn-bg: #fdecc8;
    --info: #34508c;
    --info-bg: #e2e8f4;
    --danger: #b42318;
    --danger-bg: #fde4e1;
    --shadow: 0 1px 2px rgb(16 24 40 / 8%), 0 4px 12px rgb(16 24 40 / 6%);
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #131826;
    --surface: #1a2133;
    --surface-2: #222b41;
    --border: #2f3a55;
    --border-strong: #465577;
    --text: #e3e8f4;
    --text-muted: #9aa6c2;
    --accent: #86a8f5;
    --accent-hover: #a9c1fa;
    --accent-text: #0e1730;
    --accent-soft: #26365f;
    --focus: #b7cbff;
    --ok: #86efac;
    --ok-bg: #12351f;
    --off: #a4aec6;
    --off-bg: #2a3349;
    --warn: #fbbf62;
    --warn-bg: #3d2c0c;
    --info: #a8bbe6;
    --info-bg: #26314d;
    --danger: #ff9b90;
    --danger-bg: #4a1a15;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 12px rgb(0 0 0 / 30%);
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { font-size: 15px; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
h1, h2, p { margin: 0; }
p + p { margin-top: 0.5rem; }

.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.nowrap { white-space: nowrap; }

/* --- layout ------------------------------------------------------------ */

.shell { min-height: 100vh; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border);
    z-index: 30;
}
.brand { padding: 0.9rem 1rem 0.8rem; border-bottom: 1px solid var(--border); }
.brand-link { display: block; font-size: 1.35rem; font-weight: 700; color: var(--text); }
.brand-link:hover { text-decoration: none; color: var(--accent); }
.brand-sub { font-size: 0.8rem; color: var(--text-muted); }
.side-search { padding: 0.7rem 0.75rem 0.1rem; }
.menu { flex: 1; overflow-y: auto; padding: 0.6rem 0.5rem; display: flex; flex-direction: column; gap: 2px; }
.menu-item {
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius);
    color: var(--text);
    border-left: 3px solid transparent;
}
.menu-item:hover { background: var(--surface-2); text-decoration: none; }
.menu-section { margin-top: 0.5rem; display: flex; flex-direction: column; gap: 2px; }
.menu-children { display: flex; flex-direction: column; gap: 2px; }
.menu-group { font: inherit; display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 0.35rem 0.7rem 0.3rem calc(0.7rem + 3px); border: 0; border-radius: var(--radius); background: none; cursor: pointer; font-size: 0.78rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.menu-group:hover { color: var(--text); background: var(--surface-2); }
.menu-group.has-active[aria-expanded="false"] { color: var(--accent); }
.menu-chevron { transition: transform 0.12s; font-size: 0.9rem; }
.menu-group[aria-expanded="false"] .menu-chevron { transform: rotate(-90deg); }
.menu-sub { padding-left: 1.4rem; }
.menu-section + .menu-item { margin-top: 0.5rem; }
.menu-item.active { background: var(--accent-soft); border-left-color: var(--accent); font-weight: 600; }
.side-foot {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.87rem;
}
.side-user-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.side-user { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user.active { color: var(--accent); }
.side-buttons { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.side-version { color: var(--text-muted); font-size: 0.8rem; }

.main { margin-left: var(--sidebar-width); min-width: 0; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 1.1rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 0 1 auto; min-width: 4rem; }
.topbar-actions { display: flex; align-items: center; gap: 0.4rem; margin-left: auto; }
.dirty-hint { color: var(--warn); background: var(--warn-bg); padding: 0.2rem 0.55rem; border-radius: 999px; font-size: 0.82rem; white-space: nowrap; }
.content { padding: 1.25rem; max-width: 1500px; }
.btn.burger { display: none; }
.backdrop { display: none; }

/* --- controls ---------------------------------------------------------- */

.btn {
    font: inherit;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    display: inline-block;
}
.btn:hover:not(:disabled) { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }
.btn-small { padding: 0.2rem 0.55rem; font-size: 0.85rem; }
.btn-icon { display: inline-flex; align-items: center; justify-content: center; padding: 0.25rem 0.45rem; }

.input {
    font: inherit;
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}
.input:disabled { background: var(--surface-2); color: var(--text-muted); }
textarea.input { resize: vertical; min-height: 4.5rem; }
.input-row { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.input-row > .input { flex: 1 1 7rem; width: auto; min-width: 0; }

.segmented { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.segment {
    font: inherit;
    padding: 0.38rem 0.75rem;
    border: 0;
    border-right: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    cursor: pointer;
}
.segment:last-child { border-right: 0; }
.segment:hover:not(:disabled) { background: var(--surface-2); }
.segment[aria-checked="true"], .segment[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.segment[aria-checked="true"] .muted, .segment[aria-pressed="true"] .muted { color: inherit; }
.segment:disabled { cursor: not-allowed; opacity: 0.7; }

.switch { font: inherit; display: inline-flex; align-items: center; gap: 0.55rem; padding: 0.2rem 0; border: 0; background: none; color: var(--text); cursor: pointer; }
.switch:disabled { cursor: not-allowed; opacity: 0.7; }
.switch-track { width: 2.6rem; height: 1.45rem; border-radius: 999px; background: var(--border-strong); position: relative; transition: background 0.12s; flex: none; }
.switch-thumb { position: absolute; top: 0.17rem; left: 0.17rem; width: 1.1rem; height: 1.1rem; border-radius: 50%; background: #fff; transition: transform 0.12s; }
.switch[aria-checked="true"] .switch-track { background: var(--accent); }
.switch[aria-checked="true"] .switch-thumb { transform: translateX(1.15rem); }
.switch[aria-checked="true"] .switch-text { font-weight: 600; }

/* --- forms ------------------------------------------------------------- */

.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0.9rem 1.1rem; align-items: start; }
.field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; align-items: flex-start; }
.field > .input, .field > .input-row, .field > .targets { width: 100%; }
.field > .input.input-num, .input-num { width: calc(7ch + 1.4rem); }
.form-stack { grid-template-columns: minmax(0, 24rem); }
.field-wide { grid-column: 1 / -1; }
.field-span2 { grid-column: span 2; }
.form-compact { grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 0.7rem 1rem; }
.form-compact textarea.input { min-height: 3.2rem; }
.form-address { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.7rem 1rem; max-width: 54rem; }
.form-account { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.7rem 1rem; max-width: 44rem; }
.field-newrow { grid-column: 1 / span 2; }
.field-right > .input { text-align: right; }
.field-label { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); }
.required { color: var(--danger); }
.field-hint { font-size: 0.8rem; color: var(--text-muted); }
.field-error { font-size: 0.82rem; color: var(--danger); }
.field-error:empty { display: none; }
.field-invalid .input, .field-invalid .segmented { border-color: var(--danger); }

.targets { display: flex; flex-direction: column; gap: 0.55rem; }
.target-editor { min-height: 1.9rem; align-items: center; }

/* --- panels, heads, tabs ---------------------------------------------- */

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.panel-title { font-size: 0.95rem; font-weight: 650; margin-bottom: 0.8rem; }
.panel > .muted { margin-bottom: 0.8rem; }
.empty { padding: 1.5rem; text-align: center; color: var(--text-muted); }

.page-head { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1.1rem 0; margin-bottom: 1rem; }
.page-head-title { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; font-size: 1.15rem; font-weight: 650; padding-bottom: 0.8rem; }
.page-head-title .muted { font-weight: 400; font-size: 0.95rem; }
.page-head .info { padding-bottom: 0.9rem; }
.kid { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.05rem 0.45rem; }
.tabs { display: flex; gap: 0.25rem; overflow-x: auto; }
.tabs-only { padding-top: 0.2rem; }
.tab { padding: 0.5rem 0.85rem; color: var(--text-muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-count { margin-left: 0.4rem; background: var(--surface-2); border-radius: 999px; padding: 0 0.45rem; font-size: 0.8rem; }

.info { display: flex; flex-wrap: wrap; gap: 0.6rem 2rem; margin: 0; }
.info-item dt { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); }
.info-item dd { margin: 0; }
.panel > .info { margin-bottom: 1rem; }

.split { display: grid; grid-template-columns: 15rem minmax(0, 1fr); gap: 1rem; align-items: start; }
.side-list {
    position: sticky;
    top: calc(var(--topbar-height) + 1rem);
    max-height: calc(100vh - var(--topbar-height) - 2rem);
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
}
.side-list-head { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.7rem 0.4rem calc(0.7rem + 3px); border-bottom: 1px solid var(--border); background: var(--surface-2); font-size: 0.82rem; min-height: 2.3rem; position: sticky; top: 0; }
.side-list-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.7rem; border-bottom: 1px solid var(--border); border-left: 3px solid transparent; }
.side-list-link { flex: 1; min-width: 0; color: var(--text); }
.side-list-link:hover { text-decoration: none; }
.side-list-item .check, .side-list-head .check { flex: none; }
.side-list-item:last-child { border-bottom: 0; }
.side-list-item:hover { background: var(--surface-2); text-decoration: none; }
.side-list-item.active { background: var(--accent-soft); border-left-color: var(--accent); }
.side-list-main { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-weight: 600; }
.side-list-sub { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.82rem; color: var(--text-muted); min-height: 1.1rem; }
.side-list-sub { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.side-list-count { font-variant-numeric: tabular-nums; }
.dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; flex: none; }
.dot-ok { background: var(--ok); }
.dot-off { background: var(--border-strong); }

/* --- badges and chips -------------------------------------------------- */

.badge { display: inline-block; padding: 0.08rem 0.5rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; line-height: 1.5; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-off { background: var(--off-bg); color: var(--off); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

.chips { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; }
.chip { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.05rem 0.5rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); font-size: 0.85rem; color: var(--text); }
.chip-local { border-color: var(--border-strong); background: var(--surface); font-weight: 600; }
.chip-off { border-style: dashed; color: var(--text-muted); background: var(--surface-2); border-color: var(--border-strong); }
.chip-ext { border-color: var(--border); background: var(--surface-2); color: var(--text-muted); }
.chip-warn { border-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.chip-more { border-style: dashed; color: var(--text-muted); }
.chip-remove { font: inherit; border: 0; background: none; color: inherit; cursor: pointer; padding: 0 0.1rem; line-height: 1; }
.chip-remove:hover { color: var(--danger); }

/* --- tables ------------------------------------------------------------ */

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin-bottom: 0.8rem; }
.filter-input { flex: 1 1 14rem; max-width: 26rem; width: auto; }
.counter { color: var(--text-muted); font-size: 0.87rem; margin-left: auto; }
.pager { display: flex; gap: 0.4rem; justify-content: flex-end; margin-top: 0.8rem; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 0.45rem 0.7rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.table tbody tr:last-child td { border-bottom: 0; }
.table th { font-size: 0.8rem; font-weight: 650; color: var(--text-muted); background: var(--surface-2); white-space: nowrap; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.th-sort { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; display: inline-flex; gap: 0.3rem; align-items: center; }
.th-sort:hover { color: var(--text); }
th[aria-sort] .th-sort { color: var(--accent); }
.sort-mark { font-size: 0.65rem; min-width: 0.7rem; }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--surface-2); }
.cell-link { font-weight: 600; white-space: nowrap; }
.cell-check { width: 2.2rem; }
.check { width: 1.15rem; height: 1.15rem; padding: 0; border: 1px solid var(--border-strong); border-radius: 4px; background: var(--surface); color: var(--accent-text); cursor: pointer; font-size: 0.8rem; line-height: 1; display: inline-grid; place-items: center; vertical-align: middle; }
.check[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
.check[aria-pressed="true"]::after { content: "✓"; }
.cell-note { max-width: 18rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-history td { font-size: 0.9rem; }
.changes { list-style: none; margin: 0; padding: 0; }
.changes li { overflow-wrap: anywhere; }
.change-field { font-weight: 600; }
.arrow { color: var(--text-muted); }
.reveal { user-select: all; }

/* --- feedback ---------------------------------------------------------- */

.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 100; display: flex; flex-direction: column; gap: 0.5rem; max-width: min(28rem, calc(100vw - 2rem)); }
.toast { padding: 0.6rem 0.9rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border-strong); border-left: 4px solid var(--info); box-shadow: var(--shadow); }
.toast-ok { border-left-color: var(--ok); }
.toast-error { border-left-color: var(--danger); }

.dialog { border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 1.2rem; max-width: 26rem; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgb(0 0 0 / 45%); }
.dialog-form { width: min(46rem, calc(100vw - 2rem)); max-width: none; max-height: calc(100vh - 2rem); overflow-y: auto; }
.dialog-title { font-size: 1.1rem; font-weight: 650; margin-bottom: 0.6rem; }
.dialog-context { font-weight: 600; margin-bottom: 0.4rem; }
.dialog-form .form { margin-top: 0.9rem; }
.dialog-error { color: var(--danger); margin-top: 0.8rem; font-size: 0.9rem; }
.dialog-error:empty { display: none; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.1rem; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-box { width: min(22rem, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; box-shadow: var(--shadow); }
.login-box .btn { margin-top: 0.6rem; }
.login-box .field-label { margin-top: 0.4rem; }
.login-link { font-size: 0.87rem; margin-top: 0.4rem; align-self: flex-start; }
.login-box .btn.login-link, .login-box a.btn { align-self: stretch; text-align: center; }
.login-code { display: flex; flex-direction: column; gap: 0.5rem; }
.totp-row { max-width: 24rem; margin-top: 0.6rem; }
.totp-info { margin: 0.8rem 0; }
.notice { display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem; margin: 0.8rem 0; padding: 0.6rem 0.8rem; border: 1px solid var(--warn); border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); }
.notice-panel { border-color: var(--ok); }
.message { margin-bottom: 0.6rem; padding: 0.7rem 1rem; }
.message-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.6rem; margin-bottom: 0.3rem; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.add-row { margin-top: 0.8rem; max-width: 46rem; }
.add-row > select.input { flex: 0 1 11rem; width: auto; }
.panel > .chips { margin-bottom: 0.7rem; display: flex; }
.fold { margin-top: 0.8rem; }
.fold summary { cursor: pointer; color: var(--accent); width: fit-content; }
.qr { display: block; width: 13rem; height: 13rem; margin: 0.8rem 0; border: 1px solid var(--border); border-radius: var(--radius); }
.totp-uri { overflow-wrap: anywhere; font-size: 0.85rem; color: var(--text-muted); }

.doc { max-width: 54rem; }
.doc-section { scroll-margin-top: calc(var(--topbar-height) + 1rem); }
.doc-section p, .doc-section .doc-list { margin: 0 0 0.7rem; }
.doc-list { padding-left: 1.3rem; }
.doc-list li { margin-bottom: 0.25rem; }
.doc-toc .doc-list { margin: 0; }
.doc-sub { font-size: 0.9rem; font-weight: 650; margin: 0.9rem 0 0.35rem; }
.doc-code { margin: 0 0 0.7rem; padding: 0.6rem 0.8rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); font-family: var(--font); font-size: 0.9rem; white-space: pre; overflow-x: auto; user-select: all; }

/* --- responsive -------------------------------------------------------- */

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.15s; box-shadow: var(--shadow); }
    .nav-open .sidebar { transform: none; }
    .nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgb(0 0 0 / 40%); z-index: 25; }
    .main { margin-left: 0; }
    .btn.burger { display: inline-block; }
    .topbar { flex-wrap: wrap; padding: 0.5rem 0.75rem; }
    .topbar-title { flex: 1 1 0; }
    .content { padding: 0.75rem; }
    .split { grid-template-columns: 1fr; }
    .side-list { position: static; max-height: 13rem; }
}

@media (max-width: 640px) {
    .form-address, .form-account { grid-template-columns: minmax(0, 1fr); }
    .field-span2, .field-newrow { grid-column: 1 / -1; }
}

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