/* Family Finances Tracker — v1
   Dark by default (off-black + yellow), light available in Settings.
   Every colour is a token so both themes stay in one place. */

:root, html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0E0F0B;
  --surface: #171812;
  --surface-2: #1F2019;
  --surface-3: #282A21;
  --line: #2B2D24;
  --line-2: #3B3D33;
  --ink: #F0EFE7;
  --ink-2: #C5C4B8;
  --muted: #8F8E83;
  --accent: #E8B83A;
  --accent-2: #F3CC63;
  --accent-ink: #171409;
  --accent-soft: rgba(232,184,58,.13);
  --grid: rgba(240,239,231,.07);
  --axis: rgba(240,239,231,.28);
  --pos: #3987e5;
  --neg: #e66767;
  --good: #0ca30c;
  --warn: #fab219;
  --bad: #d03b3b;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --shadow: 0 10px 40px rgba(0,0,0,.45);
  --backdrop: rgba(5,6,4,.72);
}
html[data-theme="light"] {
  color-scheme: light;
  --bg: #F1F1E6;
  --surface: #FCFCF7;
  --surface-2: #F4F4EA;
  --surface-3: #EAEADD;
  --line: #E0E0D1;
  --line-2: #CFCFBE;
  --ink: #171A10;
  --ink-2: #474A3D;
  --muted: #727466;
  --accent: #8A6420;
  --accent-2: #6F4F15;
  --accent-ink: #FFFDF6;
  --accent-soft: rgba(138,100,32,.10);
  --grid: rgba(23,26,16,.07);
  --axis: rgba(23,26,16,.30);
  --pos: #2a78d6;
  --neg: #e34948;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --shadow: 0 10px 40px rgba(40,40,20,.18);
  --backdrop: rgba(30,32,22,.45);
}
@media (prefers-color-scheme: light) {
  html[data-theme="system"] {
    color-scheme: light;
    --bg: #F1F1E6; --surface: #FCFCF7; --surface-2: #F4F4EA; --surface-3: #EAEADD;
    --line: #E0E0D1; --line-2: #CFCFBE; --ink: #171A10; --ink-2: #474A3D; --muted: #727466;
    --accent: #8A6420; --accent-2: #6F4F15; --accent-ink: #FFFDF6; --accent-soft: rgba(138,100,32,.10);
    --grid: rgba(23,26,16,.07); --axis: rgba(23,26,16,.30); --pos: #2a78d6; --neg: #e34948;
    --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
    --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
    --shadow: 0 10px 40px rgba(40,40,20,.18); --backdrop: rgba(30,32,22,.45);
  }
}

:root {
  --font-display: "Iowan Old Style", Georgia, "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 16px;
  --r-sm: 10px;
  --gutter: 16px;
  --nav-h: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font-body);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0; letter-spacing: .005em; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
.num, .money { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- gates ---------- */
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px var(--gutter); }
.gate-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); }
.brand { font-family: var(--font-display); font-size: 22px; font-weight: 600; letter-spacing: .01em; white-space: nowrap; }
.brand em { color: var(--accent); font-style: italic; }
.gate-card .brand { font-size: 26px; margin-bottom: 8px; }
.gate-sub { color: var(--ink-2); font-size: 14px; margin-bottom: 18px; }
.gate-error { color: var(--neg); font-size: 13px; min-height: 18px; margin-top: 10px; }
.gate-hint { color: var(--muted); font-size: 12px; margin-top: 12px; }

/* ---------- form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field label, .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.input, select.input, textarea.input {
  width: 100%; min-width: 0; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--r-sm);
  padding: 10px 12px; font-size: 16px; outline: none; transition: border-color .15s, background .15s;
}
textarea.input { resize: vertical; min-height: 90px; line-height: 1.45; }
.input:focus { border-color: var(--accent); background: var(--surface); }
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
.inline-num {
  width: 110px; max-width: 34vw; background: transparent; border: 1px solid transparent; border-radius: 8px;
  padding: 6px 8px; text-align: right; font-size: 16px; font-variant-numeric: tabular-nums; outline: none;
}
.inline-num:hover { border-color: var(--line-2); }
.inline-num:focus { border-color: var(--accent); background: var(--surface-2); }
.inline-text { width: 100%; min-width: 0; background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; font-size: 16px; outline: none; }
.inline-text:hover { border-color: var(--line-2); }
.inline-text:focus { border-color: var(--accent); background: var(--surface-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
  border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface-2); padding: 8px 14px; font-size: 14px; font-weight: 500;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.block { width: 100%; padding: 12px 16px; font-size: 15px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--neg); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface-2); color: var(--ink-2); flex: none; }
.icon-btn:hover { color: var(--ink); border-color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }
.x-btn { border: 0; background: transparent; color: var(--muted); padding: 4px 6px; border-radius: 6px; font-size: 18px; line-height: 1; }
.x-btn:hover { color: var(--neg); background: var(--surface-3); }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); padding: 3px; border-radius: 999px; max-width: 100%; }
.seg button { border: 0; background: transparent; color: var(--ink-2); padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 500; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.seg button:not(.on):hover { color: var(--ink); }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 36px; height: 21px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--line-2); position: relative; margin: 0; cursor: pointer; flex: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: var(--ink-2); transition: transform .15s; }
.switch input:checked { background: var(--accent); border-color: var(--accent); }
.switch input:checked::after { transform: translateX(15px); background: var(--accent-ink); }

/* ---------- app shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top);
}
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 10px var(--gutter); display: flex; align-items: center; gap: 12px; }
.topbar .brand { font-size: 19px; flex: none; }
.topbar .spacer { flex: 1; min-width: 0; }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); min-width: 0; overflow: hidden; }
.sync span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); flex: none; }
.sync-dot.saving { background: var(--warn); }
.sync-dot.error { background: var(--bad); }
.sync-dot.preview { background: var(--accent); }

.tabs { display: none; }
.tabs button {
  border: 0; background: transparent; color: var(--ink-2); padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 7px;
}
.tabs button svg { width: 17px; height: 17px; }
.tabs button.on { background: var(--accent-soft); color: var(--accent); }
.tabs button:not(.on):hover { color: var(--ink); }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav button { border: 0; background: transparent; color: var(--muted); height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 500; min-width: 0; }
.bottomnav button svg { width: 22px; height: 22px; }
.bottomnav button.on { color: var(--accent); }

.preview-bar { background: var(--accent-soft); border-bottom: 1px solid var(--line); color: var(--ink-2); font-size: 13px; }
.preview-bar .inner { max-width: 1200px; margin: 0 auto; padding: 8px var(--gutter); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.preview-bar strong { color: var(--accent); }
.preview-bar .bar-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

main { max-width: 1200px; margin: 0 auto; padding: 16px var(--gutter) calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 0 14px; }
.page-head h1 { font-size: 26px; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.grid > * { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head > div:first-child { min-width: 0; }
.card-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.card-head .actions { display: flex; gap: 6px; flex: none; align-items: center; }
.card.flush { padding: 0; overflow: hidden; }
.card.accent { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: linear-gradient(180deg, var(--accent-soft), transparent 70%), var(--surface); }

.filters { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 14px; }
.filters .f { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filters .f > .lbl { flex: none; }

/* ---------- hero + stats ---------- */
.hero-label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.hero-value { font-family: var(--font-display); font-size: 44px; line-height: 1.08; font-weight: 600; margin: 6px 0 8px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.hero-deltas { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 14px; color: var(--ink-2); }
.hero-deltas b { font-weight: 600; font-variant-numeric: tabular-nums; }
.verdict { display: flex; gap: 12px; align-items: flex-start; margin-top: 16px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.verdict .vi { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex: none; font-weight: 700; font-size: 14px; color: #fff; }
.verdict .vi.good { background: var(--good); }
.verdict .vi.warn { background: var(--warn); color: #241a00; }
.verdict .vi.bad { background: var(--bad); }
.verdict .vt { font-size: 14px; color: var(--ink-2); }
.verdict .vt strong { color: var(--ink); display: block; font-size: 15px; margin-bottom: 2px; }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px; min-width: 0; text-align: left; }
button.stat:hover { border-color: var(--accent); }
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .v { font-family: var(--font-display); font-size: 23px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .d { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.est-badge { display: inline-block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border: 1px dashed var(--line-2); border-radius: 6px; padding: 0 5px; margin-left: 6px; vertical-align: 2px; font-family: var(--font-body); font-weight: 500; }

.update-card .month { font-family: var(--font-display); font-size: 22px; font-weight: 600; }
.update-card .when { color: var(--ink-2); font-size: 14px; margin: 4px 0 14px; }
.steps { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.steps li { display: flex; gap: 10px; align-items: center; font-size: 14px; color: var(--ink-2); }
.steps .tick { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--line-2); display: flex; align-items: center; justify-content: center; font-size: 11px; flex: none; }
.steps .tick.done { background: var(--good); border-color: var(--good); color: #fff; }

/* ---------- lists / rows ---------- */
.rows { display: flex; flex-direction: column; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .name { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.row .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.row .right { text-align: right; font-variant-numeric: tabular-nums; }
.row .right .big { font-weight: 600; }
.row .right .chg { font-size: 12.5px; }
.row.clickable { cursor: pointer; border-radius: 10px; margin: 0 -8px; padding-left: 8px; padding-right: 8px; }
.row.clickable:hover { background: var(--surface-2); }
.acc-row { grid-template-columns: minmax(0, 1fr) 76px auto; }
.acc-row .spark { width: 76px; height: 28px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; padding: 1px 8px 1px 6px; border-radius: 999px; background: var(--surface-3); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.chip .sw { width: 8px; height: 8px; border-radius: 50%; flex: none; }
button.chip { cursor: pointer; font-size: 13px; padding: 5px 12px 5px 9px; }
button.chip.on { border-color: var(--accent); color: var(--ink); background: var(--accent-soft); }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; user-select: none; }
.group-head .gt { display: flex; align-items: center; gap: 8px; min-width: 0; }
.group-head .caret { color: var(--muted); transition: transform .15s; flex: none; }
.group.collapsed .caret { transform: rotate(-90deg); }
.group.collapsed .group-body { display: none; }
.group-head .tot { text-align: right; font-variant-numeric: tabular-nums; flex: none; }
.group-head .tot .chg { font-size: 12.5px; }
.group-body { margin-top: 8px; }

.kind { display: inline-block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line-2); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.kind.income, .kind.bonus { color: var(--pos); border-color: color-mix(in srgb, var(--pos) 40%, transparent); }
.kind.fixed { color: var(--ink-2); }
.kind.extra { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.b-row { grid-template-columns: minmax(0, 1fr) auto 64px; gap: 6px; }
.b-row .dlt { font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.b-row .name { cursor: pointer; }
.b-row .name:hover { color: var(--accent); }
.b-row.off { opacity: .55; }

/* ---------- horizontal bars (html) ---------- */
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar .top { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; margin-bottom: 4px; }
.hbar .top span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.hbar .top span:last-child { font-variant-numeric: tabular-nums; flex: none; }
.hbar .track { height: 10px; background: var(--surface-3); border-radius: 999px; overflow: hidden; display: flex; gap: 2px; }
.hbar .fill { height: 100%; border-radius: 999px; min-width: 2px; }
.ladder .track { height: 14px; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; min-height: 120px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font-family: var(--font-body); font-size: 11px; fill: var(--muted); }
.chart .dl { font-size: 11.5px; font-weight: 600; fill: var(--ink-2); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--ink-2); margin: 0 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 12px; height: 3px; border-radius: 2px; }
.legend .sw.box { height: 10px; width: 10px; border-radius: 3px; }
.legend .sw.dash { background: none !important; border-top: 2px dashed var(--muted); height: 0; }
.tip {
  position: absolute; z-index: 5; pointer-events: none; background: var(--surface-3); border: 1px solid var(--line-2); color: var(--ink);
  border-radius: 10px; padding: 8px 10px; font-size: 12.5px; box-shadow: var(--shadow); min-width: 130px; max-width: 240px; opacity: 0; transition: opacity .1s;
}
.tip.on { opacity: 1; }
.tip .th { font-weight: 600; margin-bottom: 4px; }
.tip .tr { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.tip .tr .l { color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.tip .tr .l i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.tip .tn { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.readout { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--ink-2); margin-top: 10px; }
.readout b { color: var(--ink); font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: 14px; padding: 18px 4px; text-align: center; }
.note { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.note.box { background: var(--surface-2); border: 1px solid var(--line); padding: 10px 12px; border-radius: 10px; margin-top: 12px; }

/* ---------- tables ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; padding: 8px 6px; border-bottom: 1px solid var(--line-2); position: sticky; top: 0; background: var(--surface); }
.tbl td { padding: 8px 6px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.tbl .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tr.est td { color: var(--muted); font-style: italic; }
.tbl tr.yr td { background: var(--surface-2); font-weight: 600; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: var(--backdrop); opacity: 0; pointer-events: none; transition: opacity .18s; }
.modal.on { opacity: 1; pointer-events: auto; }
.sheet {
  background: var(--surface); border: 1px solid var(--line-2); border-bottom: 0; width: 100%; max-height: 94vh; max-height: 94dvh;
  border-radius: 20px 20px 0 0; display: flex; flex-direction: column; transform: translateY(24px); transition: transform .2s; box-shadow: var(--shadow);
}
.modal.on .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 12px; border-bottom: 1px solid var(--line); flex: none; }
.sheet-head h2 { font-size: 19px; min-width: 0; overflow-wrap: anywhere; }
.sheet-head .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.sheet-body { padding: 16px; overflow-y: auto; overscroll-behavior: contain; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet-foot { flex: none; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); border-radius: 0; }
.sheet .section { margin-top: 22px; }
.sheet .section:first-child { margin-top: 0; }
.sheet .section > h3 { margin-bottom: 10px; }

/* log balances */
.log-row { display: grid; grid-template-columns: minmax(0, 1fr) 128px; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.log-row:first-child { border-top: 0; }
.log-row .prev { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.log-row .dl { font-size: 12.5px; font-variant-numeric: tabular-nums; }
.log-row .input { padding: 9px 10px; }
.log-totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.log-totals div { min-width: 0; }
.log-totals .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.log-totals .v { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }

.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; padding: 0; }
.swatches button.on { border-color: var(--ink); box-shadow: 0 0 0 2px var(--surface) inset; }

.edit-list .er { display: grid; grid-template-columns: minmax(0, 1fr) 110px 30px; gap: 6px; align-items: center; padding: 4px 0; }
.edit-list .er.three { grid-template-columns: minmax(0, 1fr) 100px 96px 30px; }
.edit-list .er.dated { grid-template-columns: 138px minmax(0, 1fr) 100px 30px; }
.edit-list .input { padding: 8px 10px; }
.add-link { border: 0; background: transparent; color: var(--accent); font-weight: 500; padding: 8px 0; font-size: 14px; }

.scn { border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: var(--surface-2); }
.scn + .scn { margin-top: 10px; }
.scn-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.scn-head .inline-text { font-family: var(--font-display); font-weight: 600; font-size: 17px; }
.impact { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.impact div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.impact .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.impact .v { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 500; opacity: 0; transition: opacity .2s, transform .2s; z-index: 60; pointer-events: none; max-width: calc(100vw - 32px); text-align: center; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

.search { margin-bottom: 10px; }
.foot-credit { text-align: center; color: var(--muted); font-size: 12px; margin-top: 28px; }

/* ---------- side menu (drawer on small screens, fixed sidebar on wide) ---------- */
.side { position: fixed; top: 0; bottom: 0; left: 0; width: min(300px, 86vw); z-index: 45; background: var(--surface); border-right: 1px solid var(--line);
  transform: translateX(-102%); transition: transform .22s ease; display: flex; flex-direction: column; overflow-y: auto;
  padding: calc(14px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom)); }
.side.open { transform: none; box-shadow: var(--shadow); }
.side-backdrop { position: fixed; inset: 0; z-index: 44; background: var(--backdrop); opacity: 0; pointer-events: none; transition: opacity .2s; }
.side.open + .side-backdrop { opacity: 1; pointer-events: auto; }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px 16px; }
.side-head .brand { font-size: 19px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav button, .side-sec button.si { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: transparent; color: var(--ink-2); padding: 10px 12px; border-radius: 10px; font-size: 15px; font-weight: 500; text-align: left; }
.side-nav button svg, .side-sec button.si svg { width: 19px; height: 19px; flex: none; }
.side-nav button.on { background: var(--accent-soft); color: var(--accent); }
.side-nav button:not(.on):hover, .side-sec button.si:hover { background: var(--surface-2); color: var(--ink); }
.side-sec { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.side-sec > .lbl { padding: 0 12px 6px; display: block; }
.side-foot { margin-top: auto; padding: 14px 6px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.side-foot .seg { align-self: flex-start; }
.nbadge { margin-left: auto; font-size: 11.5px; font-weight: 600; background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 1px 8px; }
.bottomnav button { position: relative; }
.dot-badge { position: absolute; top: 9px; left: calc(50% + 8px); width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--surface); }

/* ---------- tick-box pills (show / hide chart series) ---------- */
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.pill { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line-2); background: transparent; color: var(--muted); padding: 5px 12px 5px 7px; border-radius: 999px; font-size: 13px; font-weight: 500; }
.pill .tk { width: 16px; height: 16px; border-radius: 5px; border: 1.5px solid var(--c, var(--line-2)); display: inline-flex; align-items: center; justify-content: center; font-size: 11px; line-height: 1; color: transparent; flex: none; }
.pill .tk::after { content: "✓"; font-weight: 700; }
.pill.on { color: var(--ink); background: var(--surface-2); }
.pill.on .tk { background: var(--c, var(--accent)); color: #fff; }
.pill:hover { border-color: var(--accent); }

/* ---------- check-in ---------- */
.progress { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin: 12px 0 6px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.progress.done > div { background: var(--good); }
.checklist { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 2px; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; padding: 6px 2px; }
.checklist .box { width: 22px; height: 22px; border-radius: 7px; border: 1.5px solid var(--line-2); background: transparent; flex: none; display: flex; align-items: center; justify-content: center; color: transparent; font-size: 12px; font-weight: 700; padding: 0; margin-top: 1px; }
.checklist .box:hover { border-color: var(--accent); }
.checklist .box.done { background: var(--good); border-color: var(--good); color: #fff; }
.checklist .txt { font-size: 14px; color: var(--ink-2); min-width: 0; }
.checklist .txt .sub { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.checklist li.done .txt > span:first-child { color: var(--muted); }
.outstanding { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.upd { font-size: 12px; color: var(--muted); }
.upd.ok { color: var(--good); }
.upd.due { color: var(--accent); }
.log-row .same { border: 1px solid var(--line-2); background: transparent; color: var(--ink-2); border-radius: 999px; font-size: 12px; padding: 2px 9px; margin-top: 4px; }
.log-row .same:hover { border-color: var(--accent); color: var(--ink); }
.log-row.is-done .name::after { content: " ✓"; color: var(--good); font-weight: 700; }

.mgrid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.mgrid button { border: 1px solid var(--line-2); background: transparent; border-radius: 8px; padding: 8px 0; font-size: 13px; color: var(--ink-2); }
.mgrid button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.paid { display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; vertical-align: 1px; font-weight: 600; }

/* ---------- responsive ---------- */
@media (max-width: 380px) {
  .acc-row { grid-template-columns: minmax(0, 1fr) auto; }
  .acc-row .spark { display: none; }
  .hero-value { font-size: 38px; }
  .hide-xs { display: none; }
  .log-row { grid-template-columns: minmax(0, 1fr) 112px; }
  .edit-list .er.dated { grid-template-columns: 120px minmax(0, 1fr) 84px 30px; }
}
@media (max-width: 560px) {
  .hide-sm { display: none; }
  .topbar .sync span:last-child { max-width: 96px; }
  .edit-list .er.three { grid-template-columns: minmax(0, 1fr) 92px 30px; }
  .edit-list .er.three .type { grid-column: 1 / 2; }
  .edit-list .er.dated { grid-template-columns: minmax(0, 1fr) 100px 30px; }
  .edit-list .er.dated .date { grid-column: 1 / -1; }
  .impact { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (min-width: 640px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .modal { align-items: center; padding: 24px; }
  .sheet { width: min(860px, 100%); max-height: 88vh; border-radius: 20px; border-bottom: 1px solid var(--line-2); }
  .sheet.narrow { width: min(560px, 100%); }
  .sheet-foot { border-radius: 0 0 20px 20px; }
  .card { padding: 18px 20px; }
}
@media (min-width: 900px) {
  :root { --gutter: 24px; }
  .bottomnav { display: none; }
  main { padding-bottom: 48px; }
  .toast { bottom: 28px; }
  .grid { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
  .grid > * { grid-column: span 12; }
  .grid > .s4 { grid-column: span 4; }
  .grid > .s5 { grid-column: span 5; }
  .grid > .s6 { grid-column: span 6; }
  .grid > .s7 { grid-column: span 7; }
  .grid > .s8 { grid-column: span 8; }
  .hero-value { font-size: 52px; }
  .page-head h1 { font-size: 30px; }
}
@media (min-width: 1100px) {
  #app:not(.hidden) { display: grid; grid-template-columns: 248px minmax(0, 1fr); }
  .side { position: sticky; top: 0; height: 100vh; width: auto; transform: none; z-index: 20; box-shadow: none !important; }
  .side-backdrop, .side-close, .menu-btn, .top-brand { display: none !important; }
  .topbar-inner { max-width: 1240px; }
}
@media print { .topbar, .bottomnav { display: none; } }
@media (forced-colors: active) { .chart svg path { forced-color-adjust: auto; } }

/* spend drill-down: a month's buckets, each opening to its lines */
.drill { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.drill-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; margin-bottom: 8px; }
.drill-g { border-bottom: 1px solid var(--line); }
.drill-g > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: minmax(0,1fr) auto 64px; gap: 10px; align-items: center; padding: 10px 2px; font-size: 14px; }
.drill-g > summary::-webkit-details-marker { display: none; }
.drill-g > summary .dg-name { display: inline-flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drill-g > summary .dg-name::before { content: '›'; color: var(--muted); display: inline-block; width: 10px; transition: transform .15s; }
.drill-g[open] > summary .dg-name::before { transform: rotate(90deg); }
.drill-g > summary .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.drill-g > summary .dg-num { font-variant-numeric: tabular-nums; }
.drill-g > summary .dg-pct { text-align: right; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.drill-g > summary:hover { background: var(--surface-2); }
.drill-lines { padding: 4px 2px 14px 18px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.drill-lines .hbars { align-self: stretch; }
.drill > .btn { margin-top: 10px; }
@media (min-width: 640px) { .drill-g > summary { grid-template-columns: minmax(0,1fr) auto 110px; } }

/* ---------- first-run guide (8 cards over the real app) ---------- */
.tour { position: fixed; inset: 0; z-index: 55; display: none; align-items: flex-end; justify-content: center;
  padding: 16px 16px calc(var(--nav-h) + 14px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--backdrop) 70%, transparent); }
.tour.on { display: flex; animation: tour-in .2s ease-out; }
.touring .bottomnav, .touring .side { z-index: 56; }
.tour-card { width: 100%; max-width: 460px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 18px;
  box-shadow: var(--shadow); padding: 18px 18px 16px; animation: tour-up .22s ease-out; }
.tour-card h2 { font-family: var(--font-display); font-size: 22px; font-weight: 600; margin: 12px 0 6px; line-height: 1.2; }
.tour-card p { color: var(--ink-2); font-size: 15px; line-height: 1.5; margin: 0; }
.tour-tip { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--ink); font-size: 14px; line-height: 1.45; border-left: 3px solid var(--accent); }
.tour-top { display: flex; align-items: center; gap: 10px; }
.tour-ic { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.tour-ic svg { width: 21px; height: 21px; }
.tour-step { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.tour-skip { margin-left: auto; background: none; border: 0; color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; padding: 6px 2px; }
.tour-skip:hover { color: var(--ink); }
.tour-foot { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.tour-dots { display: flex; gap: 6px; margin-right: auto; }
.tour-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line-2); transition: width .2s, background .2s; }
.tour-dots i.done { background: color-mix(in srgb, var(--accent) 45%, var(--line-2)); }
.tour-dots i.on { width: 20px; border-radius: 4px; background: var(--accent); }
.tour-hl { position: relative; color: var(--accent) !important; }
.tour-hl::after { content: ''; position: absolute; inset: 3px; border-radius: 12px; border: 2px solid var(--accent); animation: tour-pulse 1.6s ease-out infinite; pointer-events: none; }
@keyframes tour-pulse { 0% { opacity: 1; transform: scale(.94); } 70% { opacity: 0; transform: scale(1.08); } 100% { opacity: 0; } }
@keyframes tour-in { from { opacity: 0; } }
@keyframes tour-up { from { opacity: 0; transform: translateY(14px); } }
@media (min-width: 900px) { .tour { align-items: center; padding: 24px; } }
@media (prefers-reduced-motion: reduce) { .tour.on, .tour-card, .tour-hl::after { animation: none; } }
