/* Family finance — light/dark, validated tokens.
   Data marks use ONE hue (magnitude, not identity), so no categorical palette and
   no legend is needed. Status colours are the reserved set and always ship with an
   icon + label, never colour alone. */

:root {
    color-scheme: light;
    --surface:        #fcfcfb;
    --plane:          #f9f9f7;
    --ink:            #0b0b0b;
    --ink-2:          #52514e;
    --ink-muted:      #898781;
    --grid:           #e1e0d9;
    --baseline:       #c3c2b7;
    --border:         rgba(11, 11, 11, .10);

    --series:         #0e7a55;   /* mint: 5.20:1 on surface, 5.34:1 vs white text */
    --series-soft:    #d6efe4;
    --primary-btn:    #0e7a55;

    --good:           #0ca30c;
    --warning:        #fab219;
    --serious:        #ec835a;
    --critical:       #d03b3b;
    --delta-good:     #006300;

    --radius:         14px;
    --radius-sm:      10px;
    --pad:            18px;
    --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) {
        color-scheme: dark;
        --surface:     #1a1a19;
        --plane:       #0d0d0d;
        --ink:         #ffffff;
        --ink-2:       #c3c2b7;
        --ink-muted:   #898781;
        --grid:        #2c2c2a;
        --baseline:    #383835;
        --border:      rgba(255, 255, 255, .10);
        --series:      #1bb07a;
        --series-soft: #12402f;
        --primary-btn: #0e7a55;   /* not stepped up: white text must stay readable */
        --delta-good:  #0ca30c;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --surface:     #1a1a19;
    --plane:       #0d0d0d;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --ink-muted:   #898781;
    --grid:        #2c2c2a;
    --baseline:    #383835;
    --border:      rgba(255, 255, 255, .10);
    --series:      #1bb07a;
    --series-soft: #12402f;
    --primary-btn: #0e7a55;
    --delta-good:  #0ca30c;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--plane);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--series); }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

.side {
    width: 218px; flex: 0 0 218px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { font-weight: 800; font-size: 1.05rem; padding: 0 8px 16px; }
.brand small { display: block; font-weight: 500; color: var(--ink-muted); font-size: .76rem; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
    display: block; padding: 9px 12px; border-radius: var(--radius-sm);
    text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: .9rem;
}
.nav a:hover { background: var(--plane); color: var(--ink); }
.nav a.on { background: var(--series-soft); color: var(--ink); }

.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }

.head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.head h1 { margin: 0; font-size: 1.45rem; font-weight: 800; }

/* ── Cards ── */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: var(--pad); margin-bottom: 18px;
}
.card h2 { margin: 0 0 4px; font-size: 1rem; font-weight: 700; }
.card .sub { color: var(--ink-muted); font-size: .84rem; margin: 0 0 14px; }

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }

/* ── Stat tiles: a number is the mark, so no chart, no colour-coding ── */
.tile {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 15px 16px;
}
.tile .label { font-size: .76rem; color: var(--ink-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-size: 1.6rem; font-weight: 800; margin-top: 4px; }
.tile .foot { font-size: .78rem; color: var(--ink-2); margin-top: 3px; }
.tile.accent { border-left: 3px solid var(--series); }
.pos { color: var(--delta-good); }
.neg { color: var(--critical); }

/* ── Bars: single hue, magnitude only ── */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 1.4fr) 1fr auto; gap: 10px; align-items: center; }
.bar-row .name { font-size: .86rem; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--grid); border-radius: 4px; height: 10px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--series); border-radius: 0 4px 4px 0; }
.bar-row .amt { font-size: .86rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Monthly history: vertical bars, 4px rounded data-ends on the baseline */
.hist { display: flex; align-items: flex-end; gap: 8px; height: 132px; padding-top: 6px; border-bottom: 1px solid var(--baseline); }
.hist .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; min-width: 0; }
.hist .stack { width: 100%; display: flex; justify-content: center; align-items: flex-end; flex: 1; }
.hist .mark { width: 60%; min-width: 12px; background: var(--series); border-radius: 4px 4px 0 0; }
.hist .mark.forecast { background: var(--series-soft); border: 1px dashed var(--series); }
.hist .v { font-size: .7rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.hist-x { display: flex; gap: 8px; margin-top: 6px; }
.hist-x span { flex: 1; text-align: center; font-size: .72rem; color: var(--ink-muted); min-width: 0; }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-muted); padding: 8px 10px; border-bottom: 1px solid var(--border); font-weight: 700; }
td { padding: 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.t-wrap { overflow-x: auto; }

/* ── Forms ── */
label { display: block; font-size: .78rem; font-weight: 700; color: var(--ink-2); margin-bottom: 5px; }
input, select, textarea {
    width: 100%; padding: 10px 12px; font-family: inherit; font-size: .9rem;
    color: var(--ink); background: var(--surface);
    border: 1.5px solid var(--baseline); border-radius: var(--radius-sm);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--series); }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { width: 110px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 16px; min-height: 40px; border-radius: var(--radius-sm);
    border: 1.5px solid transparent; background: var(--primary-btn); color: #fff;
    font: inherit; font-size: .88rem; font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: var(--ink-2); border-color: var(--baseline); }
.btn.ghost:hover { color: var(--series); border-color: var(--series); }
.btn.sm { padding: 6px 11px; min-height: 32px; font-size: .8rem; }
.btn.danger { background: transparent; color: var(--critical); border-color: var(--border); }

/* ── Status: icon + label always, never colour alone ── */
.chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: 999px; font-size: .76rem; font-weight: 700;
    border: 1px solid var(--border); color: var(--ink);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.chip.good .dot { background: var(--good); }
.chip.warn .dot { background: var(--warning); }
.chip.serious .dot { background: var(--serious); }
.chip.crit .dot { background: var(--critical); }

.alert {
    display: flex; gap: 10px; align-items: flex-start;
    padding: 11px 14px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--plane);
    font-size: .86rem; margin-bottom: 10px;
}
.alert .ic { font-weight: 800; flex: 0 0 auto; }
.alert.crit { border-left: 3px solid var(--critical); }
.alert.warn { border-left: 3px solid var(--warning); }
.alert.info { border-left: 3px solid var(--series); }

.why { margin: 10px 0 0; padding-left: 18px; color: var(--ink-2); font-size: .84rem; }
.why li { margin: 3px 0; }

.muted { color: var(--ink-muted); }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.empty { color: var(--ink-muted); padding: 18px 0; font-size: .9rem; }

.monthnav { display: flex; align-items: center; gap: 8px; }
.monthnav .now { font-weight: 700; min-width: 96px; text-align: center; }

/* ── Login ── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 380px; }

@media (max-width: 820px) {
    .layout { flex-direction: column; }
    .side { width: auto; flex: none; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
    .nav { flex-direction: row; flex-wrap: wrap; }
    .main { padding: 18px 16px 50px; }
}
