:root {
    --bg: #ffffff;
    --surface: #f7f8fa;
    --border: #e2e5ea;
    --text: #1a1d23;
    --muted: #6b7280;
    --accent: #1f6feb;
    --pos: #12603a;
    --neg: #a4232b;
    --warn: #8a5a00;
    --warn-bg: #fff8e6;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171c;
        --surface: #1b1f26;
        --border: #2b313b;
        --text: #e6e8ec;
        --muted: #9aa3b2;
        --accent: #6ea8ff;
        --pos: #4ec98a;
        --neg: #ff8b93;
        --warn: #f0c674;
        --warn-bg: #2a2419;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

.topbar {
    display: flex;
    align-items: baseline;
    gap: 2rem;
    padding: 0.9rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.brand { font-weight: 650; font-size: 1.05rem; color: var(--text); }
.topbar nav { display: flex; gap: 1.25rem; }
.nav-link { color: var(--muted); }
.nav-link.active { color: var(--text); font-weight: 600; }

main { padding: 1.5rem; max-width: 1400px; }

h1 { font-size: 1.5rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.05rem; margin: 2rem 0 0.5rem; }
.lede { color: var(--muted); margin-top: 0; }

.crumbs { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.4rem; }

/* Cards -------------------------------------------------------------- */
.cards { display: flex; flex-wrap: wrap; gap: 1rem; margin: 1.5rem 0; }

.card {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 13rem;
    padding: 1rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

a.card:hover { border-color: var(--accent); text-decoration: none; }
.card-figure { font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.card-label { font-size: 0.9rem; }
.card-note { font-size: 0.8rem; color: var(--muted); }

/* Tables ------------------------------------------------------------- */
.grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    font-variant-numeric: tabular-nums;
}

.grid.narrow { width: auto; min-width: 32rem; }

.grid th, .grid td {
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.grid thead th {
    position: sticky;
    top: 0;
    background: var(--surface);
    font-weight: 600;
    white-space: nowrap;
}

.grid tbody tr:hover { background: var(--surface); }
.grid tfoot td { font-weight: 600; border-top: 2px solid var(--border); border-bottom: none; }

.group-row { background: var(--surface); }
.group-row td { font-weight: 650; }

.num { text-align: right; white-space: nowrap; }
.code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.address { max-width: 26rem; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.zero { color: var(--muted); }

.src {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.78rem;
    padding: 0.05rem 0.3rem;
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--muted);
}

.tag {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0.05rem 0.35rem;
    border-radius: 3px;
    background: var(--border);
    color: var(--muted);
    font-size: 0.72rem;
}

/* Forms and summaries ------------------------------------------------ */
.filters {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1rem 0;
    flex-wrap: wrap;
}

.filters input[type="search"] {
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--bg);
    color: var(--text);
    min-width: 18rem;
}

.filters button {
    padding: 0.35rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.filters button:hover { border-color: var(--accent); }
.filters label { display: flex; align-items: center; gap: 0.3rem; color: var(--muted); }

.summary { display: flex; flex-wrap: wrap; gap: 1.75rem; margin: 1rem 0 1.5rem; }
.summary div { display: flex; flex-direction: column; }
.summary dt { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.summary dd { margin: 0.15rem 0 0; font-size: 1.05rem; font-variant-numeric: tabular-nums; }

.address-block { color: var(--muted); margin: 0 0 1rem; }
.empty { color: var(--muted); font-style: italic; }

.notice {
    margin: 1.5rem 0;
    padding: 0.8rem 1rem;
    border-left: 3px solid var(--warn);
    border-radius: 0 5px 5px 0;
    background: var(--warn-bg);
    font-size: 0.88rem;
}

.provenance {
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.8rem;
}

.provenance .warn { color: var(--neg); }

/* Dashboard ----------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1rem; margin: 1.25rem 0; }

.tile {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.9rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

a.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile-label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.tile-figure { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-note { font-size: 0.78rem; color: var(--muted); }

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(21rem, 1fr)); gap: 1rem; align-items: start; }

.panel {
    padding: 1rem 1.15rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.panel.wide { grid-column: 1 / -1; }
.panel h2 { margin: 0; font-size: 0.95rem; }
.panel-sub { margin: 0.15rem 0 0.9rem; font-size: 0.82rem; color: var(--muted); }
.small { font-size: 0.78rem; }

.chart { width: 100%; height: auto; display: block; }

/* Data-viz roles. Ordinal ageing ramp and the diverging inflow/outflow pair are both
   validated against the light and dark surfaces — see the dataviz palette. */
.chart {
    --inflow: #2a78d6;
    --outflow: #e34948;
    --total: #52514e;
    --age0: #86b6ef;
    --age1: #3987e5;
    --age2: #256abf;
    --age3: #104281;
    --axis: #c9c9c4;
}

@media (prefers-color-scheme: dark) {
    .chart {
        --inflow: #3987e5;
        --outflow: #e66767;
        --total: #c3c2b7;
        --age0: #b7d3f6;
        --age1: #6da7ec;
        --age2: #2a78d6;
        --age3: #184f95;
        --axis: #3a3f48;
    }
}

.bar { stroke: var(--surface); stroke-width: 2; }
.bar.inflow { fill: var(--inflow); }
.bar.outflow { fill: var(--outflow); }
.bar.total { fill: var(--total); }
.bar.age0 { fill: var(--age0); }
.bar.age1 { fill: var(--age1); }
.bar.age2 { fill: var(--age2); }
.bar.age3 { fill: var(--age3); }
.bar:hover { stroke: var(--accent); }

.axis { stroke: var(--axis); stroke-width: 1; }

.bar-value, .bar-label, .row-label, .row-value {
    font: 11px system-ui, sans-serif;
    fill: var(--text);
    font-variant-numeric: tabular-nums;
}

.bar-value, .bar-label { text-anchor: middle; }
.bar-label { fill: var(--muted); }
.row-label { fill: var(--muted); }

.legend { display: flex; gap: 1rem; margin: 0.5rem 0 0.75rem; font-size: 0.78rem; color: var(--muted); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin-right: 0.3rem; }
.swatch.inflow { background: #2a78d6; }
.swatch.outflow { background: #e34948; }
.swatch.total { background: #52514e; }

@media (prefers-color-scheme: dark) {
    .swatch.inflow { background: #3987e5; }
    .swatch.outflow { background: #e66767; }
    .swatch.total { background: #c3c2b7; }
}

.tasks { list-style: none; margin: 0; padding: 0; }
.tasks li { display: flex; gap: 0.75rem; align-items: baseline; padding: 0.5rem 0; border-bottom: 1px solid var(--border); font-size: 0.86rem; }
.tasks li:last-child { border-bottom: none; }
.task-figure { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 7rem; text-align: right; }

.subtotal td { border-top: 1px solid var(--border); font-weight: 600; }
.subtotal td:first-child { color: var(--muted); font-weight: 400; }
.ageing-percent td { border-top: none; font-weight: 400; color: var(--muted); }

/* Login --------------------------------------------------------------- */
.signout { margin-left: auto; }
.signout button {
    padding: 0.25rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.82rem;
}
.signout button:hover { border-color: var(--accent); color: var(--text); }

.login-shell { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.5rem; }

.login-card {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    width: min(22rem, 100%);
    padding: 1.75rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.login-card h1 { font-size: 1.25rem; margin: 0; }
.login-card p { margin: -0.6rem 0 0.4rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.82rem; color: var(--muted); }

.login-card input {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
}

.login-card button {
    margin-top: 0.4rem;
    padding: 0.5rem;
    border: 1px solid var(--accent);
    border-radius: 5px;
    background: var(--accent);
    color: #fff;
    font-size: 0.92rem;
    cursor: pointer;
}

.login-error {
    margin: 0 !important;
    padding: 0.5rem 0.7rem;
    border-radius: 5px;
    background: var(--warn-bg);
    color: var(--neg);
    font-size: 0.84rem;
}

.bar.year { fill: var(--inflow); }

.filters select {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--bg);
    color: var(--text);
}
