/*
  Quarterday: household net worth and budgeting dashboard (Screenery template "networth")
  Private-bank minimalism: ivory paper, hairline rules, Source Serif 4 for headings and figures, Source Sans 3 for the
  working labels, one deep green. Oldstyle figures in running text, lining tabular figures in every table and chart.
  Contents: 1 tokens, 2 base and browser surfaces, 3 primitives, 4 shell, 5 statement and chart, 6 accounts and bills,
  7 spending and budgets, 8 register, 9 dialogs, 10 states (skeleton, error, offline, empty), 11 motion, 12 narrow screens.
*/

/* ---------- 1. Tokens ---------- */
:root {
  color-scheme: light;

  /* Paper */
  --paper: #f6f1e6;        /* the sheet */
  --paper-2: #eee7d7;      /* sidebar, tracks, skeletons */
  --paper-3: #fbf8f1;      /* dialogs, raised */
  --rule: #d9cfbc;         /* hairlines */
  --rule-2: #b8ab92;       /* stronger hairlines, inputs */

  /* Ink */
  --ink: #1b201c;
  --ink-2: #464b45;        /* secondary text, 8:1 on paper */
  --ink-3: #62665e;        /* quiet text, 5.3:1 on paper */

  /* The one colour: a deep green, and its quiet tints */
  --green: #1d4a37;
  --green-2: #2a6049;
  --green-ink: #f6f1e6;
  --green-tint: rgba(29, 74, 55, .075);
  --green-line: rgba(29, 74, 55, .38);

  /* Meaning only: over budget, errors */
  --over: #8c2d21;
  --over-tint: rgba(140, 45, 33, .08);

  /* Type */
  --serif: 'Source Serif 4', 'Iowan Old Style', Georgia, serif;
  --sans: 'Source Sans 3', 'Segoe UI', system-ui, sans-serif;
  --fs-xs: .75rem;      /* 12px: chart ticks, fine print */
  --fs-sm: .8125rem;    /* 13px: meta lines */
  --fs-base: .9375rem;  /* 15px: UI text */
  --fs-h2: 1.375rem;
  --fs-h1: 2.125rem;
  --fs-lede: 1.6875rem;

  /* Space and shape */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --r: 3px;
  --r-2: 6px;
  --side-w: 248px;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --shadow: 0 18px 50px -18px rgba(27, 32, 28, .28), 0 2px 6px rgba(27, 32, 28, .06);
}

/* ---------- 2. Base and browser surfaces ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 24px; scrollbar-color: var(--rule-2) var(--paper); }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 var(--fs-base)/1.5 var(--sans);
  font-variant-numeric: oldstyle-nums proportional-nums;
  -webkit-font-smoothing: antialiased;
  caret-color: var(--green);
  accent-color: var(--green);
}
::selection { background: rgba(29, 74, 55, .2); color: var(--ink); }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; margin: 0; text-wrap: balance; letter-spacing: -.005em; }
p { margin: 0; text-wrap: pretty; }
a { color: var(--green); text-underline-offset: .2em; text-decoration-thickness: 1px; }
a:hover { color: var(--green-2); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 2px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--paper); }
::-webkit-scrollbar-thumb { background: var(--rule-2); border-radius: 10px; border: 2px solid var(--paper); }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.skip { position: absolute; left: var(--s4); top: -60px; z-index: 50; background: var(--green); color: var(--green-ink); padding: 10px 14px; border-radius: var(--r); }
.skip:focus { top: var(--s4); }
.skip:hover { color: var(--green-ink); }
.muted { color: var(--ink-3); }
[hidden] { display: none !important; }

/* Lining tabular figures for anything in columns */
.num, .tbl td, .tbl tfoot th, .chart svg text, kbd, .count, .d-amt, .b-date, .bud-fig {
  font-variant-numeric: lining-nums tabular-nums;
}

/* ---------- 3. Primitives ---------- */
.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 36px; padding: 0 14px; border-radius: var(--r);
  border: 1px solid var(--rule-2); background: transparent; color: var(--ink);
  font-weight: 500; font-size: var(--fs-base); white-space: nowrap;
  transition: background-color .16s var(--ease), border-color .16s var(--ease), color .16s var(--ease);
}
.btn:hover { background: var(--paper-2); }
.btn:disabled { cursor: progress; opacity: .75; }
.btn-primary { background: var(--green); border-color: var(--green); color: var(--green-ink); }
.btn-primary:hover { background: var(--green-2); border-color: var(--green-2); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: var(--fs-sm); }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r);
  border: 1px solid transparent; background: transparent; color: var(--ink-2);
}
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.icon-btn.sm { width: 28px; height: 28px; }
.text-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 2px;
  border: 0; background: none; color: var(--green); font-weight: 500;
  text-decoration: underline; text-decoration-color: var(--green-line); text-underline-offset: .25em; text-decoration-thickness: 1px;
}
.text-btn:hover { text-decoration-color: var(--green); }
kbd {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px;
  border: 1px solid var(--rule-2); box-shadow: 0 1px 0 var(--rule-2); border-radius: 3px;
  font: 500 11px/1 var(--sans); color: var(--ink-2); background: var(--paper-3);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px;
  border: 1px solid var(--rule-2); border-radius: 999px; background: transparent; color: var(--ink);
  font-size: var(--fs-sm); font-weight: 500;
}
.chip span { font-weight: 600; color: var(--green); }
.chip[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: var(--green-ink); }
.chip[aria-pressed="true"] span { color: var(--green-ink); }
.fine { margin-top: var(--s3); font-size: var(--fs-sm); color: var(--ink-3); max-width: 62ch; }
.spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(246, 241, 230, .35); border-top-color: var(--green-ink); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }

/* ---------- 4. Shell ---------- */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--s5);
  padding: var(--s6) var(--s5) var(--s5);
  background: var(--paper-2); border-right: 1px solid var(--rule);
}
.mark { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font: 600 1.25rem/1 var(--serif); letter-spacing: -.01em; }
.mark-glyph { width: 26px; height: 26px; }
.mark-glyph rect { fill: var(--green); }
.mark-glyph circle, .mark-glyph path { fill: none; stroke: var(--green-ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.household { font: 500 1rem/1.35 var(--serif); padding-bottom: var(--s5); border-bottom: 1px solid var(--rule); }
.household span { font: 400 var(--fs-sm)/1.4 var(--sans); color: var(--ink-3); }
.index { display: grid; gap: 2px; }
.index a {
  display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 10px; margin: 0 -10px;
  border-radius: var(--r); color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.index a:hover { background: rgba(255, 255, 255, .45); color: var(--ink); }
.index a[aria-current] { color: var(--green); background: var(--paper-3); box-shadow: inset 0 0 0 1px var(--rule); }
.count { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--green); color: var(--green-ink); font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; }
.count:empty { display: none; }
.side-add { align-self: flex-start; }
.side-foot { margin-top: auto; display: grid; gap: var(--s3); font-size: var(--fs-sm); color: var(--ink-3); }
.sync { display: flex; align-items: center; gap: 8px; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-tint); }
.sync.is-off .sync-dot { background: var(--over); box-shadow: 0 0 0 3px var(--over-tint); }
.keys { line-height: 1.9; }
.topbar, .bottombar { display: none; }

.main { padding: var(--s7) clamp(24px, 4.2vw, 64px) var(--s8); max-width: 1180px; width: 100%; outline: none; }

/* ---------- 5. Statement header, written statement and chart ---------- */
.sheet-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s4) var(--s5);
  padding-bottom: var(--s4); border-bottom: 1px solid var(--ink);
}
.sheet-head h1 { font-size: var(--fs-h1); line-height: 1.1; }
.as-at { margin-top: 6px; color: var(--ink-3); font-size: var(--fs-sm); }
.period { display: flex; border: 1px solid var(--rule-2); border-radius: var(--r); background: var(--paper-3); }
.period button, .seg button {
  min-height: 34px; padding: 0 14px; border: 0; border-right: 1px solid var(--rule); background: transparent;
  color: var(--ink-2); font-weight: 500; font-size: var(--fs-sm); white-space: nowrap;
}
.period button:last-child, .seg button:last-child { border-right: 0; }
.period button:hover, .seg button:hover { color: var(--ink); background: var(--paper-2); }
.period [aria-checked="true"], .seg [aria-checked="true"] { background: var(--green); color: var(--green-ink); }
.period [aria-checked="true"]:hover, .seg [aria-checked="true"]:hover { background: var(--green-2); color: var(--green-ink); }

.block { padding-top: var(--s7); }
.position { padding-top: var(--s6); }
.lede { max-width: 50em; min-height: 7.5em; }
.statement {
  font: 400 var(--fs-lede)/1.42 var(--serif); font-optical-sizing: auto; letter-spacing: -.008em;
  font-variant-numeric: oldstyle-nums proportional-nums; max-width: 34em;
}
.statement .fig { font-weight: 600; color: var(--green); }
.lede-sub { margin-top: var(--s3); font: 400 1.0625rem/1.55 var(--serif); color: var(--ink-2); max-width: 62ch; font-variant-numeric: oldstyle-nums; }

.chart { margin: var(--s6) 0 0; }
.chart-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3) var(--s4); padding-bottom: var(--s3); border-bottom: 1px solid var(--rule); }
.chart-head figcaption { font: italic 400 1rem/1.3 var(--serif); color: var(--ink-2); }
.chart-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s4); }
.seg { display: flex; border: 1px solid var(--rule-2); border-radius: var(--r); background: var(--paper-3); }
.seg button { min-height: 30px; padding: 0 12px; }
.chart-frame { position: relative; margin-top: var(--s3); min-height: 220px; }
.chart-frame svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.nw:focus-visible { outline-offset: 6px; }
.nw text { font: 400 12px var(--sans); fill: var(--ink-3); }
.nw .xtick tspan { fill: var(--ink-2); font-weight: 600; }
.nw .tick line { stroke: var(--rule); stroke-width: 1; }
.nw .axis { stroke: var(--ink); stroke-width: 1; }
.nw .xtick line { stroke: var(--ink); }
.nw .band { fill: var(--green-tint); }
.nw .band-label { font: italic 400 12.5px var(--serif); fill: var(--green); }
.nw path { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.nw .ln-net, .nw .ln-own { stroke: var(--green); stroke-width: 2; }
.nw .ln-owe { stroke: var(--ink-2); stroke-width: 1.5; stroke-dasharray: 5 4; }
.nw circle.end { stroke: var(--paper); stroke-width: 2; }
.nw circle.ln-net, .nw circle.ln-own { fill: var(--green); }
.nw circle.ln-owe { fill: var(--ink-2); stroke-dasharray: none; }
.nw .cursor line { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 2 3; }
.nw .cursor circle { stroke: var(--paper); stroke-width: 2; }
.nw .legend line { stroke-width: 2; }
.nw .legend text { fill: var(--ink-2); }
.nw .hit { fill: transparent; cursor: crosshair; }
.chart-readout {
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); align-items: baseline;
  margin-top: var(--s3); padding: var(--s3) 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
  font-size: var(--fs-sm); color: var(--ink-2); font-variant-numeric: lining-nums tabular-nums; min-height: 46px;
}
.chart-readout .ro-when { font: italic 400 .9375rem var(--serif); color: var(--ink); margin-right: auto; }
.chart-readout b { font: 600 1rem var(--serif); color: var(--green); }
.ro-k { color: var(--ink-3); }
.chart-readout:empty { display: none; }
.chart-empty { display: grid; place-items: center; height: 220px; border: 1px dashed var(--rule-2); border-radius: var(--r-2); color: var(--ink-3); font: italic 1rem var(--serif); }
.chart-table { margin-top: var(--s4); }
.scroll { max-height: 360px; overflow: auto; border: 1px solid var(--rule); border-radius: var(--r); }
.scroll .tbl thead th { position: sticky; top: 0; background: var(--paper-3); }

/* ---------- Shared table voice ---------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 9px 0; text-align: left; vertical-align: baseline; font-weight: 400; }
.tbl th + th, .tbl th + td, .tbl td + td { padding-left: var(--s4); }
.tbl thead th { font-size: var(--fs-xs); font-weight: 600; color: var(--ink-3); letter-spacing: .02em; padding-top: 0; border-bottom: 1px solid var(--ink); }
.scroll .tbl th, .scroll .tbl td { padding-left: var(--s3); padding-right: var(--s3); }
.tbl .num { text-align: right; white-space: nowrap; font-family: var(--serif); font-size: 1rem; }
.tbl thead .num { font-family: var(--sans); font-size: var(--fs-xs); }
.tbl tbody tr + tr > * { border-top: 1px solid var(--rule); }

.block-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s2) var(--s4); padding-bottom: var(--s3); margin-bottom: var(--s4); border-bottom: 1px solid var(--ink); }
.block-head h2 { font-size: var(--fs-h2); line-height: 1.2; }
.block-note { color: var(--ink-3); font-size: var(--fs-sm); font-variant-numeric: lining-nums tabular-nums; }
.pair { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 0 var(--s7); align-items: start; }

/* ---------- 6. Accounts statement and bills ---------- */
.stmt th[scope="row"] { padding-right: var(--s4); }
.a-name { display: block; font-weight: 500; }
.a-meta { display: block; font-size: var(--fs-sm); color: var(--ink-3); }
.stmt .chg { font-size: .875rem; color: var(--ink-2); width: 7.5em; }
.stmt .grp-h th { padding: var(--s4) 0 4px; font: italic 400 1.0625rem var(--serif); color: var(--ink-2); border-top: 0 !important; }
.stmt tbody.grp:first-of-type .grp-h th { padding-top: var(--s2); }
.stmt tr.sub > * { border-top: 1px solid var(--ink) !important; font-weight: 600; }
.stmt tr.sub th { font-weight: 600; }
.stmt tr.total > * { border-top: 1px solid var(--ink); border-bottom: 3px double var(--ink); padding: 12px 0 10px; }
.stmt tr.total th { font: 600 1.125rem var(--serif); }
.stmt tr.total .num { font-size: 1.1875rem; font-weight: 600; color: var(--green); }
.stmt tr.total .chg { font-size: .9375rem; color: var(--green); }
.stmt tr.is-new { background: var(--green-tint); }

.bills-sum { font: 400 1.0625rem/1.5 var(--serif); color: var(--ink-2); font-variant-numeric: oldstyle-nums; }
.bills-sum b { color: var(--ink); font-weight: 600; }
.ruler { display: block; width: 100%; height: 46px; margin-top: var(--s4); }
.ruler line { stroke-width: 1; vector-effect: non-scaling-stroke; }
.r-day { stroke: var(--rule-2); }
.r-we { stroke: var(--rule); }
.r-month { stroke: var(--ink); }
.r-base { stroke: var(--ink); }
.r-bill { fill: var(--green); }
.ruler-labels { position: relative; height: 18px; font-size: var(--fs-xs); color: var(--ink-3); font-variant-numeric: lining-nums; }
.ruler-labels span { position: absolute; top: 0; white-space: nowrap; }
.ruler-labels span:nth-child(2) { top: -52px; margin-left: 5px; color: var(--ink-2); }
.bill-list { list-style: none; margin: var(--s4) 0 0; padding: 0; }
.bill-list li { display: grid; grid-template-columns: 5.6em minmax(0, 1fr) auto; gap: var(--s3); align-items: baseline; padding: 9px 0; border-top: 1px solid var(--rule); }
.bill-list li:first-child { border-top: 1px solid var(--ink); }
.b-date { font-size: var(--fs-sm); color: var(--ink-2); white-space: nowrap; }
.b-wd { color: var(--ink-3); }
.b-name { font-weight: 500; min-width: 0; }
.b-meta { display: block; font-weight: 400; font-size: var(--fs-sm); color: var(--ink-3); }
.b-amt { font-family: var(--serif); font-size: 1rem; text-align: right; }

/* ---------- 7. Spending and budgets ---------- */
.spend-sum, .bud-sum { color: var(--ink-2); font: 400 1.0625rem/1.5 var(--serif); margin-bottom: var(--s4); font-variant-numeric: oldstyle-nums; max-width: 60ch; }
.bars th[scope="row"] { width: 9.5em; }
.bar-btn {
  white-space: nowrap; border: 0; background: none; padding: 2px 0; text-align: left; color: var(--ink); font-weight: 500;
  text-decoration: underline; text-decoration-color: transparent; text-underline-offset: .25em;
}
.bar-btn:hover { text-decoration-color: var(--green-line); color: var(--green); }
.bar-cell { width: 100%; vertical-align: middle !important; }
.bar { display: block; height: 10px; width: var(--w); min-width: 2px; background: var(--green); border-radius: 1px; transition: width .6s var(--ease); }
.is-uncat .bar { background: repeating-linear-gradient(135deg, var(--ink-3) 0 2px, transparent 2px 5px); box-shadow: inset 0 0 0 1px var(--ink-3); }
.is-uncat .bar-btn { font-style: italic; }
.bars .pct { width: 3.2em; color: var(--ink-3); font-family: var(--sans); font-size: var(--fs-sm); }
.bars tfoot > * > * { border-top: 1px solid var(--ink); padding-top: 10px; font-weight: 600; }
.bars tfoot th { font: 600 1rem var(--serif); }

.bud-list { list-style: none; margin: 0; padding: 0; }
.bud { padding: 10px 0 9px; border-top: 1px solid var(--rule); }
.bud:first-child { border-top: 1px solid var(--ink); }
.bud-top { display: flex; align-items: center; gap: var(--s3); }
.bud-name { font-weight: 500; }
.bud-fig { margin-left: auto; font-family: var(--serif); font-size: 1rem; }
.bud-fig .muted { font-size: .875rem; }
.bud .icon-btn { margin-right: -6px; color: var(--ink-3); }
.meter { position: relative; height: 6px; margin-top: 6px; background: var(--paper-2); box-shadow: inset 0 0 0 1px var(--rule); border-radius: 1px; }
.meter-fill { position: absolute; inset: 0 auto 0 0; width: var(--w); background: var(--green); border-radius: 1px; transition: width .6s var(--ease); }
.meter-pace { position: absolute; top: -4px; bottom: -4px; left: var(--x); width: 1.5px; background: var(--ink); }
.bud-status { margin-top: 4px; font-size: var(--fs-sm); color: var(--ink-3); font-variant-numeric: lining-nums; }
.bud.is-over .meter-fill { background: var(--over); }
.bud.is-over .bud-status { color: var(--over); font-weight: 600; }
.bud-edit label { display: block; font-weight: 500; margin-bottom: 6px; }
.bud-edit-row { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.bud-edit .money-in { width: 9em; }

/* ---------- 8. Transaction register ---------- */
.tools { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s3); align-items: center; margin-bottom: var(--s4); }
.search { position: relative; flex: 1 1 260px; display: flex; align-items: center; }
.search .i { position: absolute; left: 11px; color: var(--ink-3); pointer-events: none; }
.search kbd { position: absolute; right: 9px; pointer-events: none; }
.search input {
  width: 100%; min-height: 38px; padding: 0 36px 0 34px;
  border: 1px solid var(--rule-2); border-radius: var(--r); background: var(--paper-3);
}
.search input::placeholder, .field input::placeholder, textarea::placeholder { color: var(--ink-3); opacity: 1; }
.search input::-webkit-search-cancel-button { display: none; }
.search input:focus-visible { outline-offset: 0; }
.select { position: relative; display: inline-flex; align-items: center; }
.select select {
  appearance: none; min-height: 38px; padding: 0 32px 0 12px; border: 1px solid var(--rule-2); border-radius: var(--r);
  background: var(--paper-3); font-size: var(--fs-sm); font-weight: 500; cursor: pointer;
}
.select .i { position: absolute; right: 10px; pointer-events: none; color: var(--ink-2); }

.reg .c-acct { width: 6em; color: var(--ink-3); font-size: var(--fs-sm); }
.reg .c-cat { width: 11em; }
.reg thead .c-acct { color: var(--ink-3); }
.reg tr.day th {
  padding: var(--s4) 0 4px; font: italic 400 1rem var(--serif); color: var(--ink-2); border-top: 0 !important;
  font-variant-numeric: oldstyle-nums;
}
.reg tr.day + tr.tx > * { border-top: 1px solid var(--rule-2); }
.reg tr.tx > * { padding: 7px 0; }
.reg tr.tx > * + * { padding-left: var(--s4); }
.tx-open { display: block; width: 100%; padding: 2px 0; border: 0; background: none; text-align: left; }
.tx-payee { display: block; font-weight: 500; }
.tx-open:hover .tx-payee { color: var(--green); text-decoration: underline; text-decoration-color: var(--green-line); text-underline-offset: .2em; }
.tx-note { display: block; font-size: var(--fs-sm); color: var(--ink-3); }
.cat-pill {
  min-height: 28px; padding: 0 8px; margin-left: -8px; border: 1px solid transparent; border-radius: var(--r);
  background: transparent; color: var(--ink-2); font-size: var(--fs-sm); text-align: left;
}
.cat-pill:hover { border-color: var(--rule-2); background: var(--paper-3); color: var(--ink); }
.cat-pill.need { margin-left: 0; border-color: var(--green); color: var(--green); font-weight: 600; background: var(--paper-3); }
.cat-pill.need:hover { background: var(--green); color: var(--green-ink); }
.reg .amt { font-size: 1rem; }
.reg .amt.in { color: var(--green); font-weight: 600; }
.reg tr.flash > * { animation: flash 1.6s var(--ease); }
@keyframes flash { from { background: rgba(29, 74, 55, .16); } to { background: transparent; } }
.more { margin-top: var(--s4); text-align: center; }

.foot { margin-top: var(--s8); padding-top: var(--s4); border-top: 1px solid var(--ink); display: grid; gap: var(--s2); font-size: var(--fs-sm); color: var(--ink-3); max-width: 76ch; }

/* ---------- 9. Dialogs: transaction drawer and add an account ---------- */
dialog { padding: 0; border: 0; color: var(--ink); background: var(--paper-3); }
dialog::backdrop { background: rgba(27, 32, 28, .32); }
.drawer { margin: 0 0 0 auto; width: min(460px, 100vw); height: 100dvh; max-height: 100dvh; max-width: 100vw; border-left: 1px solid var(--rule-2); box-shadow: var(--shadow); }
.drawer-inner, .modal-inner { display: flex; flex-direction: column; height: 100%; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s5) var(--s5) var(--s4); border-bottom: 1px solid var(--rule); }
.drawer-head h2 { font-size: 1.375rem; line-height: 1.2; overflow-wrap: anywhere; }
[data-d-body], .add-body { flex: 1; overflow-y: auto; padding: var(--s5); display: grid; align-content: start; gap: var(--s5); }
.drawer-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--s2); padding: var(--s4) var(--s5); border-top: 1px solid var(--rule); background: var(--paper); }
.form-msg { flex: 1 1 100%; font-size: var(--fs-sm); color: var(--ink-2); }
.form-msg:empty { display: none; }
.form-msg.bad { color: var(--over); font-weight: 600; }
.d-amt { font: 500 2.25rem/1 var(--serif); }
.d-amt.in { color: var(--green); }
.d-facts { margin: 0; display: grid; gap: var(--s2); }
.d-facts div { display: grid; grid-template-columns: 6em 1fr; gap: var(--s3); padding-top: var(--s2); border-top: 1px solid var(--rule); }
.d-facts dt { color: var(--ink-3); font-size: var(--fs-sm); }
.d-facts dd { margin: 0; }
.d-info { color: var(--ink-2); font-style: italic; font-family: var(--serif); }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: var(--s2); font-weight: 600; }
.d-cat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.d-cat, .kind { position: relative; display: flex; }
.d-cat input, .kind input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.d-cat span, .kind span {
  flex: 1; display: flex; align-items: center; min-height: 38px; padding: 6px 12px; border: 1px solid var(--rule-2); border-radius: var(--r);
  background: var(--paper); font-size: var(--fs-sm); font-weight: 500;
}
.d-cat input:hover + span, .kind input:hover + span { border-color: var(--ink-2); }
.d-cat input:checked + span, .kind input:checked + span { background: var(--green); border-color: var(--green); color: var(--green-ink); }
.d-cat input:focus-visible + span, .kind input:focus-visible + span { outline: 2px solid var(--green); outline-offset: 2px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: var(--fs-sm); cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; flex: none; }
.field { display: grid; gap: 6px; align-content: start; }
.field label { font-weight: 600; }
.opt { font-weight: 400; color: var(--ink-3); font-size: var(--fs-sm); }
.field input, .field textarea, .money-in {
  width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--rule-2); border-radius: var(--r); background: var(--paper);
}
.field textarea { resize: vertical; line-height: 1.45; }
.money-in { display: flex; align-items: center; gap: 4px; padding: 0 0 0 12px; }
.money-in span { color: var(--ink-3); font-family: var(--serif); }
.money-in input { flex: 1; min-width: 0; min-height: 38px; border: 0; padding: 0 12px 0 0; background: transparent; font-family: var(--serif); font-size: 1.0625rem; font-variant-numeric: lining-nums tabular-nums; }
.money-in input:focus-visible { outline: none; }
.money-in:focus-within { outline: 2px solid var(--green); outline-offset: 1px; }
.field input[aria-invalid="true"], .money-in:has(input[aria-invalid="true"]) { border-color: var(--over); box-shadow: inset 0 0 0 1px var(--over); }
.hint { font-size: var(--fs-sm); color: var(--ink-3); }
.hint.bad { color: var(--over); font-weight: 600; }
.err { font-size: var(--fs-sm); color: var(--over); font-weight: 600; }
.err:empty { display: none; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }

.modal { width: min(600px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); border: 1px solid var(--rule-2); border-radius: var(--r-2); box-shadow: var(--shadow); }
.modal-inner { max-height: calc(100dvh - 48px); }
.add-intro { color: var(--ink-2); font: 400 1rem/1.5 var(--serif); max-width: 52ch; }
.kind-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.kind-h { grid-column: 1 / -1; margin-top: var(--s2); font: italic 400 .9375rem var(--serif); color: var(--ink-2); }
.kind-h:first-child { margin-top: 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 40; transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  max-width: min(520px, calc(100vw - 32px)); padding: 12px 16px; border-radius: var(--r);
  background: var(--ink); color: var(--paper); font-size: var(--fs-sm); box-shadow: var(--shadow);
  transition: opacity .2s var(--ease), transform .35s var(--ease);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 10. States ---------- */
.banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); margin-bottom: var(--s5); padding: var(--s3) var(--s4);
  border: 1px solid var(--over); border-radius: var(--r); background: var(--over-tint); color: var(--ink);
}
.banner > .i { color: var(--over); }
.banner p { flex: 1 1 300px; font-size: var(--fs-sm); }
.empty { padding: var(--s5) 0; display: grid; gap: var(--s2); justify-items: start; color: var(--ink-2); max-width: 52ch; }
.empty-title { font: italic 400 1.1875rem var(--serif); color: var(--ink); }
.empty .btn { margin-top: var(--s2); }
.fail { display: flex; gap: var(--s4); align-items: flex-start; padding: var(--s5); border: 1px solid var(--over); border-radius: var(--r-2); background: var(--over-tint); max-width: 40em; }
.fail > .i { width: 22px; height: 22px; color: var(--over); margin-top: 4px; }
.fail p { color: var(--ink-2); margin-bottom: var(--s3); }
.fail-title { font: 500 1.375rem var(--serif); color: var(--ink) !important; margin-bottom: var(--s2) !important; }

.sk-wrap { display: grid; gap: 12px; padding: var(--s2) 0; }
.sk { display: block; height: 14px; width: var(--sw); border-radius: 2px; background: var(--paper-2); }
.sk-big { height: 26px; }
.sk-chart { height: 280px; border-radius: 2px; background: var(--paper-2); }
@media (prefers-reduced-motion: no-preference) {
  .sk-wrap:not(.is-still) .sk, .sk-chart:not(.is-still) { animation: pulse 1.4s ease-in-out infinite; }
}
@keyframes pulse { 50% { opacity: .45; } }

/* ---------- 11. Motion: the net worth line is drawn once, from left to right ---------- */
@media (prefers-reduced-motion: no-preference) {
  .chart-frame.draw .nw path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.4s var(--ease) .15s forwards; }
  .chart-frame.draw .nw path.ln-owe { stroke-dasharray: 5 4; stroke-dashoffset: 0; opacity: 0; animation: fadein .8s var(--ease) .6s forwards; }
  .chart-frame.draw .nw circle.end { opacity: 0; animation: fadein .4s var(--ease) 1.2s forwards; }
  .chart-frame.draw .nw .band { transform-origin: left; animation: fadein .8s var(--ease); }
}
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* ---------- 12. Narrow screens ---------- */
@media (max-width: 1240px) {
  .pair { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1100px) {
  :root { --side-w: 216px; }
  .side { padding-left: var(--s4); padding-right: var(--s4); }
}
@media (max-width: 860px) {
  :root { --fs-lede: 1.375rem; --fs-h1: 1.75rem; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 20;
    padding: 10px var(--s4); background: var(--paper); border-bottom: 1px solid var(--rule);
  }
  .topbar .icon-btn { width: 44px; height: 44px; color: var(--green); border-color: var(--rule-2); }
  .main { padding: var(--s5) var(--s4) calc(96px + env(safe-area-inset-bottom)); }
  .bottombar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); background: var(--paper-2); border-top: 1px solid var(--rule-2);
  }
  .bottombar a { display: grid; justify-items: center; gap: 2px; min-height: 52px; padding: 7px 2px 4px; color: var(--ink-2); text-decoration: none; font-size: 11.5px; font-weight: 500; border-radius: var(--r); }
  .bottombar a .i { width: 20px; height: 20px; }
  .bottombar a[aria-current] { color: var(--green); background: var(--paper-3); }
  html { scroll-padding-top: 72px; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .sheet-head { align-items: stretch; flex-direction: column; }
  .period { width: 100%; }
  .period button { flex: 1; padding: 0 6px; min-height: 40px; }
}
@media (max-width: 600px) {
  .lede { min-height: 0; }
  .statement { font-size: 1.3125rem; line-height: 1.45; }
  .chart-tools { width: 100%; justify-content: space-between; }
  .chart-readout .ro-when { flex-basis: 100%; }
  .chart-frame { min-height: 0; }

  /* Accounts: change column drops under the balance */
  .stmt thead { display: none; }
  .stmt tr:not(.grp-h) { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--s3); padding: 9px 0; }
  .stmt tbody tr + tr > * { border-top: 0; }
  .stmt tbody tr + tr { border-top: 1px solid var(--rule); }
  .stmt tr > * { padding: 0 !important; border: 0 !important; }
  .stmt tr:not(.grp-h) > th { grid-row: span 2; }
  .stmt .chg { width: auto; text-align: right; font-size: var(--fs-sm); }
  .stmt tr.sub { border-top: 1px solid var(--ink) !important; }
  .stmt tr.sub > *, .stmt tr.total > * { border: 0 !important; }
  .stmt tr.total { border-top: 1px solid var(--ink); border-bottom: 3px double var(--ink); padding: 12px 0 10px; }
  .stmt .grp-h { display: block; }
  .stmt .grp-h th { display: block; padding: var(--s4) 0 6px !important; }

  /* Register: every transaction is a two-line row */
  .reg thead { display: none; }
  .reg, .reg tbody { display: block; }
  .reg tr.day { display: block; }
  .reg tr.day th { display: block; padding: var(--s4) 0 6px !important; }
  .reg tr.tx { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "payee amt" "cat acct"; column-gap: var(--s3); padding: 9px 0; border-top: 1px solid var(--rule); }
  .reg tr.day + tr.tx { border-top-color: var(--rule-2); }
  .reg tr.tx > * { padding: 0 !important; border: 0 !important; width: auto !important; }
  .reg tr.tx > th { grid-area: payee; }
  .reg tr.tx .amt { grid-area: amt; }
  .reg tr.tx .c-cat { grid-area: cat; }
  .reg tr.tx .c-acct { grid-area: acct; text-align: right; align-self: center; }
  .cat-pill { min-height: 30px; margin-left: -8px; }
  .cat-pill.need { margin: 4px 0 0; }

  .tools .search { flex-basis: 100%; }
  .tools .select { flex: 1 1 calc(50% - 6px); }
  .tools .select select { width: 100%; min-height: 44px; }
  .search input { min-height: 44px; }
  .search kbd { display: none; }
  .chip { min-height: 44px; }

  .bars th[scope="row"] { width: 7.4em; }
  .bars .pct { width: 2.8em; }
  .kind-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-row { grid-template-columns: 1fr; }
  .modal { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; border: 0; }
  .modal-inner { max-height: 100dvh; }
  .d-cat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .d-cat span, .kind span { min-height: 44px; }
  .bud .icon-btn.sm { width: 36px; height: 36px; }
}

/* Tablet portrait gets a little more margin than a phone */
@media (min-width: 601px) and (max-width: 860px) {
  .main { padding-left: var(--s5); padding-right: var(--s5); }
}

/* Without JavaScript the pre-written November statement stays readable; controls that need a script step aside. */
.no-js .period, .no-js .chart-tools, .no-js .tools, .no-js [data-open-add], .no-js .chart-readout, .no-js .bud .icon-btn, .no-js .more { display: none !important; }
