/* =====================================================================
   Lyd & Lys - design system
   Scandinavian, minimal: warm off-white paper, hairline borders,
   muted slate/sage accents, generous whitespace, no heavy shadows.
   ===================================================================== */

:root {
    /* Surfaces */
    --bg: #f4f3f0;
    --surface: #ffffff;
    --surface-2: #fbfaf8;
    --surface-3: #f0eeea;
    --line: #e4e1da;
    --line-strong: #d3cfc5;

    /* Text */
    --ink: #21262b;
    --ink-soft: #4a5058;
    --muted: #7a7d82;

    /* Brand */
    --primary: #2e4756;
    --primary-hover: #243844;
    --primary-soft: #e8eef1;
    --accent: #7d9d9c;
    --accent-soft: #e9f0ef;

    /* Status */
    --success: #4f7f63;
    --success-soft: #e6f0ea;
    --warning: #a8801f;
    --warning-soft: #f7efdc;
    --danger: #a8503c;
    --danger-soft: #f6e8e4;
    --info: #4f6f8c;
    --info-soft: #e8eef4;

    /* Shape */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(33, 38, 43, .05);
    --shadow: 0 6px 24px rgba(33, 38, 43, .07);
    --shadow-lg: 0 24px 60px rgba(33, 38, 43, .16);

    /* Type */
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    --header-h: 62px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #15181a;
        --surface: #1d2124;
        --surface-2: #22272a;
        --surface-3: #272c30;
        --line: #2f3438;
        --line-strong: #3d4348;
        --ink: #e7e5e0;
        --ink-soft: #c3c6c9;
        --muted: #949a9f;
        --primary: #8fb3c7;
        --primary-hover: #a4c3d4;
        --primary-soft: #23323b;
        --accent: #8fb0ae;
        --accent-soft: #223230;
        --success: #7fb094;
        --success-soft: #1f2d26;
        --warning: #d3ac54;
        --warning-soft: #322a1a;
        --danger: #d08d79;
        --danger-soft: #33221e;
        --info: #8aa8c4;
        --info-soft: #202b34;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
        --shadow: 0 6px 24px rgba(0, 0, 0, .35);
        --shadow-lg: 0 24px 60px rgba(0, 0, 0, .5);
    }
}

:root[data-theme="dark"] {
    --bg: #15181a;
    --surface: #1d2124;
    --surface-2: #22272a;
    --surface-3: #272c30;
    --line: #2f3438;
    --line-strong: #3d4348;
    --ink: #e7e5e0;
    --ink-soft: #c3c6c9;
    --muted: #949a9f;
    --primary: #8fb3c7;
    --primary-hover: #a4c3d4;
    --primary-soft: #23323b;
    --accent: #8fb0ae;
    --accent-soft: #223230;
    --success: #7fb094;
    --success-soft: #1f2d26;
    --warning: #d3ac54;
    --warning-soft: #322a1a;
    --danger: #d08d79;
    --danger-soft: #33221e;
    --info: #8aa8c4;
    --info-soft: #202b34;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 6px 24px rgba(0, 0, 0, .35);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .5);
}

/* ------------------------------- base ------------------------------ */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.015em; line-height: 1.25; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1rem; }
p:last-child { margin-bottom: 0; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

hr { border: 0; border-top: 1px solid var(--line); margin: 1.5rem 0; }

::selection { background: var(--accent-soft); }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

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

.container {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 24px;
}

.container-narrow { max-width: 860px; }
.container-wide { max-width: 1500px; }

.page { padding: 32px 0 72px; }

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

.page-head .eyebrow {
    text-transform: uppercase;
    letter-spacing: .09em;
    font-size: .69rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 6px;
}

.page-head p.lede { color: var(--muted); margin: 6px 0 0; max-width: 62ch; }

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

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* dashboard: bred kolonne + sidepanel   |   formularer: to lige kolonner */
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.grid-split { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.grid-stack { align-content: start; }

@media (max-width: 980px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-main, .grid-split { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
    .container { padding: 0 16px; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
}

/* ------------------------------ header ----------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--line);
}

@supports not (background: color-mix(in srgb, red 50%, blue)) {
    .topbar { background: var(--surface); }
}

.topbar-inner {
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -.01em;
    margin-right: 14px;
    white-space: nowrap;
}

.brand:hover { text-decoration: none; }

.brand-mark {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: var(--primary);
    color: var(--surface);
    display: grid;
    place-items: center;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .02em;
}

.nav { display: flex; align-items: center; gap: 2px; flex: 1; }

.nav a, .nav button.nav-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--ink-soft);
    font-size: .9rem;
    font-weight: 500;
    background: none;
    border: 0;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
}

.nav a:hover, .nav button.nav-link:hover {
    background: var(--surface-3);
    color: var(--ink);
    text-decoration: none;
}

.nav a.is-active,
.nav button.nav-link.is-active {
    background: var(--primary-soft);
    color: var(--primary);
}

.nav-menu a.is-active { background: var(--primary-soft); color: var(--primary); }

.nav-group { position: relative; }

.nav-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 230px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 6px;
    display: none;
    z-index: 50;
}

.nav-group.is-open .nav-menu { display: block; }

.nav-menu a {
    display: block;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: .88rem;
    color: var(--ink-soft);
}

.nav-menu a small { display: block; color: var(--muted); font-size: .74rem; font-weight: 400; }

.nav-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.chev { width: 9px; height: 9px; opacity: .55; }

.icon-btn {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink-soft);
    cursor: pointer;
    padding: 0;
}

.icon-btn:hover { background: var(--surface-3); color: var(--ink); }

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--primary);
    display: grid;
    place-items: center;
    font-size: .74rem;
    font-weight: 600;
    flex: none;
}

.nav-toggle { display: none; }

@media (max-width: 900px) {
    .nav-toggle { display: grid; }
    .nav {
        display: none;
        position: absolute;
        top: var(--header-h);
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        background: var(--surface);
        border-bottom: 1px solid var(--line);
        padding: 10px 16px 16px;
        gap: 2px;
        box-shadow: var(--shadow);
    }
    .topbar.is-open .nav { display: flex; }
    .nav-menu { position: static; display: block; border: 0; box-shadow: none; padding: 0 0 0 12px; min-width: 0; }
    .nav-group > .nav-link { display: none; }
}

/* ------------------------------- cards ----------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-head {
    padding: 18px 22px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.card-head h2 { font-size: 1rem; }
.card-head .sub { color: var(--muted); font-size: .82rem; margin-top: 2px; }

.card-body { padding: 22px; }
.card-body.tight { padding: 14px 18px; }
.card-foot {
    padding: 14px 22px;
    border-top: 1px solid var(--line);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius) var(--radius);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* stat tiles */

.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 104px;
    justify-content: center;
}

.stat .label {
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    font-weight: 600;
}

.stat .value { font-size: 1.55rem; font-weight: 600; letter-spacing: -.02em; }
.stat .meta { font-size: .8rem; color: var(--muted); }
.stat.accent-revenue { border-left: 3px solid var(--success); }
.stat.accent-expense { border-left: 3px solid var(--danger); }
.stat.accent-balance { border-left: 3px solid var(--primary); }
.stat.accent-budget { border-left: 3px solid var(--warning); }

.progress {
    height: 5px;
    border-radius: 99px;
    background: var(--surface-3);
    overflow: hidden;
    margin-top: 8px;
}

.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.progress.is-over > span { background: var(--danger); }

/* ------------------------------ buttons ---------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font: inherit;
    font-size: .89rem;
    font-weight: 550;
    line-height: 1.3;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .12s ease, border-color .12s ease, color .12s ease, opacity .12s ease;
    text-decoration: none;
}

.btn:hover { text-decoration: none; }
.btn:disabled, .btn.is-loading { opacity: .6; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

:root[data-theme="dark"] .btn-primary,
:root[data-theme="dark"] .btn-danger { color: #12171a; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .btn-primary,
    :root:not([data-theme="light"]) .btn-danger { color: #12171a; }
}

.btn-secondary {
    background: var(--surface);
    border-color: var(--line-strong);
    color: var(--ink);
}

.btn-secondary:hover:not(:disabled) { background: var(--surface-3); }

.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--ink); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.94); }

.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-danger-soft:hover:not(:disabled) { filter: brightness(.97); }

.btn-sm { padding: 6px 11px; font-size: .82rem; }
.btn-lg { padding: 12px 22px; font-size: .95rem; }
.btn-block { width: 100%; }

.btn .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    display: none;
}

.btn.is-loading .spinner { display: inline-block; }

@keyframes spin { to { transform: rotate(360deg); } }

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

.form-section { margin-bottom: 30px; }

.form-section > .section-title {
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--muted);
    font-weight: 650;
    padding-bottom: 8px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
}

.field { margin-bottom: 16px; }

.field > label, .label {
    display: block;
    font-size: .82rem;
    font-weight: 550;
    color: var(--ink-soft);
    margin-bottom: 6px;
}

.field .hint { font-size: .76rem; color: var(--muted); margin-top: 5px; }

.field .req { color: var(--danger); margin-left: 2px; }

input[type="text"], input[type="email"], input[type="tel"], input[type="number"],
input[type="password"], input[type="date"], input[type="datetime-local"],
input[type="search"], input[type="file"], select, textarea {
    width: 100%;
    padding: 9px 12px;
    font: inherit;
    font-size: .9rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    transition: border-color .12s ease, box-shadow .12s ease;
}

textarea { resize: vertical; min-height: 84px; }

input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) {
    border-color: var(--muted);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

input:disabled, select:disabled, textarea:disabled, input[readonly] {
    background: var(--surface-3);
    color: var(--ink-soft);
    cursor: default;
}

input.is-invalid, select.is-invalid, textarea.is-invalid {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px var(--danger-soft);
}

.field-error { display: none; color: var(--danger); font-size: .77rem; margin-top: 5px; }
.field.has-error .field-error { display: block; }

select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%237a7d82' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 10px;
    padding-right: 32px;
}

.input-suffix { position: relative; display: flex; align-items: stretch; }

.input-suffix input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }

.input-suffix .suffix {
    display: grid;
    place-items: center;
    padding: 0 12px;
    font-size: .82rem;
    color: var(--muted);
    background: var(--surface-3);
    border: 1px solid var(--line-strong);
    border-left: 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    white-space: nowrap;
}

.checkbox {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 13px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    cursor: pointer;
    font-size: .87rem;
}

.checkbox input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--primary); flex: none; }
.checkbox:hover { border-color: var(--line-strong); }
.checkbox span small { display: block; color: var(--muted); font-size: .76rem; }

.row { display: grid; gap: 0 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.row-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

@media (max-width: 720px) {
    .row, .row-3, .row-1-2, .row-2-1 { grid-template-columns: minmax(0, 1fr); }
}

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

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

.table-search { position: relative; flex: 1; min-width: 200px; max-width: 340px; }
.table-search input { padding-left: 34px; }

.table-search svg {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: var(--muted);
    pointer-events: none;
}

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

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: .87rem;
}

table.data th, table.data td {
    padding: 11px 14px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    white-space: nowrap;
}

table.data thead th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    font-weight: 650;
    z-index: 1;
    user-select: none;
}

table.data thead th.sortable { cursor: pointer; }
table.data thead th.sortable:hover { color: var(--ink); }

table.data thead th .sort-arrow { opacity: 0; margin-left: 5px; font-size: .7em; }
table.data thead th.sorted-asc .sort-arrow,
table.data thead th.sorted-desc .sort-arrow { opacity: 1; }
table.data thead th.sorted-desc .sort-arrow { transform: rotate(180deg); display: inline-block; }

table.data tbody tr { transition: background-color .1s ease; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr.is-selected { background: var(--primary-soft); }
table.data tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody td.wrap { white-space: normal; min-width: 220px; }
table.data tbody td.actions { text-align: right; }

table.data tbody td.actions .btn { margin-left: 6px; }

.table-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 18px;
    border-top: 1px solid var(--line);
    font-size: .82rem;
    color: var(--muted);
    flex-wrap: wrap;
}

.pager { display: flex; gap: 4px; align-items: center; }

.pager button {
    min-width: 30px;
    height: 30px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink-soft);
    font: inherit;
    font-size: .82rem;
    cursor: pointer;
}

.pager button:hover:not(:disabled) { background: var(--surface-3); }
.pager button.is-current { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager button:disabled { opacity: .4; cursor: default; }

/* ------------------------------ badges ----------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 99px;
    font-size: .74rem;
    font-weight: 600;
    letter-spacing: .01em;
    background: var(--surface-3);
    color: var(--ink-soft);
    white-space: nowrap;
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }

.mono { font-family: var(--font-mono); font-size: .84em; }

/* ------------------------------ alerts ----------------------------- */

.alert {
    display: flex;
    gap: 11px;
    align-items: flex-start;
    padding: 13px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface-2);
    font-size: .88rem;
    margin-bottom: 18px;
}

.alert strong { font-weight: 600; }
.alert-success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.alert-error, .alert-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.alert-warning { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.alert-info { background: var(--info-soft); border-color: transparent; color: var(--info); }
.alert .alert-close { margin-left: auto; background: none; border: 0; color: inherit; opacity: .6; cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0 2px; }
.alert .alert-close:hover { opacity: 1; }

/* ------------------------------ toasts ----------------------------- */

.toast-stack {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(390px, calc(100vw - 40px));
}

.toast {
    display: flex;
    gap: 11px;
    align-items: flex-start;
    padding: 13px 15px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    font-size: .87rem;
    animation: toast-in .22s ease;
}

.toast .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--muted); }
.toast.success .dot { background: var(--success); }
.toast.error .dot { background: var(--danger); }
.toast.warning .dot { background: var(--warning); }
.toast.info .dot { background: var(--info); }
.toast .toast-body { flex: 1; }
.toast .toast-title { font-weight: 600; margin-bottom: 2px; }
.toast .toast-text { color: var(--ink-soft); word-break: break-word; }
.toast .toast-close { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.05rem; line-height: 1; padding: 0 2px; }
.toast.is-out { animation: toast-out .18s ease forwards; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

/* ------------------------------ modal ------------------------------ */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(23, 27, 30, .42);
    backdrop-filter: blur(2px);
    z-index: 120;
    display: none;
    padding: 24px;
    overflow-y: auto;
}

.modal-backdrop.is-open { display: flex; align-items: flex-start; justify-content: center; }

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 640px;
    margin: auto;
    animation: modal-in .18s ease;
    overflow: hidden;
}

.modal.modal-wide { max-width: 900px; }

@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.99); } to { opacity: 1; transform: none; } }

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--line);
}

.modal-head .sub { color: var(--muted); font-size: .82rem; margin-top: 3px; }

.modal-body { padding: 22px 24px; max-height: min(66vh, 720px); overflow-y: auto; }

.modal-foot {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 16px 24px;
    border-top: 1px solid var(--line);
    background: var(--surface-2);
    flex-wrap: wrap;
}

.modal-foot .spacer { margin-right: auto; }

/* definition list used in the detail modal */

.dl { display: grid; grid-template-columns: minmax(120px, 32%) 1fr; gap: 0; font-size: .88rem; }
.dl dt { color: var(--muted); padding: 8px 0; border-bottom: 1px solid var(--line); }
.dl dd { margin: 0; padding: 8px 0; border-bottom: 1px solid var(--line); word-break: break-word; }
.dl dt:last-of-type, .dl dd:last-of-type { border-bottom: 0; }

/* ---------------------------- empty state -------------------------- */

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

.empty .empty-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--surface-3);
    display: grid;
    place-items: center;
    margin: 0 auto 14px;
    color: var(--muted);
}

.empty h3 { color: var(--ink); margin-bottom: 6px; }

.skeleton {
    background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.3s ease infinite;
    border-radius: 6px;
    height: 12px;
}

@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ------------------------------ auth ------------------------------- */

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 40px 20px;
    background:
        radial-gradient(1100px 520px at 15% -10%, var(--accent-soft), transparent 62%),
        radial-gradient(900px 460px at 100% 0%, var(--primary-soft), transparent 58%),
        var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 34px;
}

.auth-card.wide { max-width: 720px; }

.auth-head { text-align: center; margin-bottom: 26px; }
.auth-head .brand-mark { width: 40px; height: 40px; margin: 0 auto 14px; font-size: .82rem; border-radius: 12px; }
.auth-head p { color: var(--muted); font-size: .88rem; margin: 4px 0 0; }
.auth-foot { text-align: center; margin-top: 20px; font-size: .86rem; color: var(--muted); }

/* ---------------------------- error page --------------------------- */

.page-error { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.error-box { max-width: 560px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 34px; }
.error-detail { text-align: left; background: var(--surface-3); padding: 12px; border-radius: var(--radius-sm); font-size: .78rem; overflow-x: auto; }

/* ---------------------------- utilities ---------------------------- */

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-6 { gap: 6px; }
.gap-10 { gap: 10px; }
.gap-16 { gap: 16px; }
.wrap { flex-wrap: wrap; }
.mt-0 { margin-top: 0; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mt-32 { margin-top: 32px; }
.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.w-full { width: 100%; }

.chart-wrap { position: relative; height: 320px; }

.summary-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 22px;
    padding: 16px 22px;
    background: var(--surface-2);
    border-top: 1px solid var(--line);
    border-radius: 0 0 var(--radius) var(--radius);
}

.summary-bar div { display: flex; flex-direction: column; gap: 2px; }
.summary-bar .k { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
.summary-bar .v { font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }

@media print {
    .topbar, .page-actions, .table-toolbar, .table-foot, .toast-stack { display: none !important; }
    body { background: #fff; }
    .card { border: 0; box-shadow: none; }
}
