/* Household ledger. One family (Figtree), cool paper, ink, one action colour.
   Totals are set as worked sums: figures above a rule, the result beneath it. */
@font-face {
  font-family: "Figtree";
  src: url("../fonts/figtree-latin-wght-normal.woff2") format("woff2");
  font-weight: 300 900; font-display: swap;
}
:root {
  --paper: #f1f5f4; --surface: #fff; --ink: #15262b; --muted: #52646a; --rule: #d2dcda; --rule-strong: #9fb0ae;
  --action: #0e5a66; --action-ink: #fff; --action-soft: #e0eeee;
  --in: #12875a; --out: #7a58b8;
  --review: #7a4a00; --review-bg: #fcefd2; --danger: #a3271f;
  --r: 6px;
  --step--1: .8125rem; --step-0: 1rem; --step-1: 1.25rem; --step-2: 1.5625rem; --step-3: 1.953rem;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 var(--step-0)/1.5 "Figtree", system-ui, sans-serif; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h1 { font-size: var(--step-3); font-weight: 700; }
h2 { font-size: var(--step-1); font-weight: 700; }
h3 { font-size: var(--step-0); font-weight: 700; }
p { margin: 0 0 .75rem; max-width: 70ch; }
a { color: var(--action); text-underline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: var(--step--1); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.in { font-weight: 700; }
:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; border-radius: 3px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff; padding: .5rem 1rem; z-index: 50; }
.skip:focus { left: 0; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; min-height: 0 !important; padding: 0 !important; border: 0 !important; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
label.button:has(+ .visually-hidden:focus-visible) { outline: 3px solid var(--action); outline-offset: 2px; }

/* ---- controls ---- */
button, select, input, textarea { font: inherit; color: inherit; }
button, .button { min-height: 2.5rem; padding: 0 .9rem; border: 1px solid var(--rule-strong); background: var(--surface); border-radius: var(--r); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
button:hover, .button:hover { border-color: var(--ink); }
button.primary, .button.primary { background: var(--action); border-color: var(--action); color: var(--action-ink); font-weight: 600; }
button.primary:hover { background: #0a4651; }
button.ghost { border-color: transparent; background: none; }
button.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--action); text-decoration: underline; text-underline-offset: 2px; }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=search], input[type=date], input[type=number], input[type=month], input[type=file], select, textarea {
  min-height: 2.5rem; padding: .35rem .6rem; border: 1px solid var(--rule-strong); border-radius: var(--r); background: var(--surface); width: 100%; min-width: 0; }
input[type=number] { font-variant-numeric: tabular-nums; text-align: right; }
input[type=checkbox], input[type=radio] { width: 1.15rem; height: 1.15rem; accent-color: var(--action); margin: 0; flex: none; }
textarea { min-height: 4.5rem; resize: vertical; }
.field { display: grid; gap: .25rem; min-width: 0; }
.field > label, .field > .label { font-weight: 600; font-size: var(--step--1); }
.hint { font-size: var(--step--1); color: var(--muted); margin: 0; }
.check { display: flex; align-items: center; gap: .5rem; min-height: 2.5rem; }
.row { display: flex; gap: .5rem; align-items: center; }
.row > button { flex: none; white-space: nowrap; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
.form-grid { display: grid; gap: .85rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.seg label { padding: 0 .75rem; min-height: 2.4rem; display: inline-flex; align-items: center; cursor: pointer; font-variant-numeric: tabular-nums; }
.seg label + label { border-left: 1px solid var(--rule); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--ink); color: #fff; font-weight: 600; }
.seg label:has(input:focus-visible) { outline: 3px solid var(--action); outline-offset: -3px; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip, .tag { display: inline-flex; align-items: center; gap: .25rem; background: var(--action-soft); border-radius: 99px; padding: 0 .55rem; font-size: var(--step--1); line-height: 1.6; white-space: nowrap; }
.chip button { min-height: 1.4rem; width: 1.4rem; padding: 0; border: 0; background: none; border-radius: 50%; }
.flag { display: inline-block; background: var(--review-bg); color: var(--review); border: 1px solid #e3c98f; border-radius: 4px; padding: 0 .4rem; font-size: var(--step--1); line-height: 1.5; white-space: nowrap; }
.mark { display: inline-block; border: 1px solid var(--rule-strong); border-radius: 4px; padding: 0 .35rem; font-size: var(--step--1); line-height: 1.5; color: var(--muted); white-space: nowrap; }
.notice { border-left: 4px solid var(--rule-strong); background: var(--surface); padding: .7rem .9rem; margin: 0 0 1rem; max-width: 80ch; }
.notice.warn { border-color: #c9962e; background: var(--review-bg); }
.error { color: var(--danger); font-weight: 600; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 15rem minmax(0, 1fr); min-height: 100dvh; }
.side { background: var(--ink); color: #dfe8e7; padding: 1.25rem .75rem; display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 0; height: 100dvh; overflow-y: auto; }
.brand { color: #fff; font-weight: 700; font-size: var(--step-1); text-decoration: none; padding: 0 .6rem; letter-spacing: -.01em; }
#nav { display: grid; gap: 2px; }
#nav a, #nav button { display: flex; justify-content: space-between; align-items: center; gap: .5rem; color: inherit; text-decoration: none; padding: 0 .6rem; min-height: 2.5rem; border-radius: var(--r); border: 0; background: none; width: 100%; text-align: left; }
#nav a:hover, #nav button:hover { background: #22383e; }
#nav a[aria-current=page] { background: #fff; color: var(--ink); font-weight: 700; }
#nav .count { font-size: var(--step--1); font-variant-numeric: tabular-nums; background: var(--review-bg); color: var(--review); border-radius: 99px; padding: 0 .45rem; font-weight: 700; }
#nav :focus-visible, .side :focus-visible { outline-color: #9fd8e0; }
.side-add { margin: 0 0 .25rem; }
.fab { display: none; position: fixed; right: 1rem; bottom: calc(4.4rem + env(safe-area-inset-bottom)); z-index: 25; min-height: 3.25rem; padding: 0 1.4rem; border-radius: 99px; box-shadow: 0 6px 18px rgba(21, 38, 43, .3); }
.side-foot { margin-top: auto; display: grid; gap: .6rem; padding: 0 .6rem; font-size: var(--step--1); }
.side-foot .seg { border-color: #46595e; background: transparent; }
.side-foot .seg label { flex: 1; justify-content: center; }
.side-foot .seg label + label { border-color: #46595e; }
.side-foot .seg label:has(input:checked) { background: #fff; color: var(--ink); }
.side-foot a, .side-foot button.link { color: #bfe3e8; }
main { padding: 2rem clamp(1rem, 3vw, 2.5rem) 4rem; min-width: 0; }
main:focus { outline: none; }
.page-head { display: flex; flex-wrap: wrap; gap: .75rem 1.5rem; align-items: end; justify-content: space-between; margin-bottom: 1.5rem; }
.page-head p { margin: .3rem 0 0; color: var(--muted); }
section.block { margin-bottom: 2.25rem; }
section.block > h2 { margin-bottom: .75rem; }
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r); padding: 1rem 1.1rem; }
.loading { color: var(--muted); }

/* ---- worked sums ---- */
.sum { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 1.25rem; row-gap: .3rem; align-items: baseline; margin: 0; }
.sum dt { color: var(--muted); min-width: 0; }
.sum dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.sum .total { border-top: 2px solid var(--ink); padding-top: .4rem; margin-top: .25rem; font-weight: 700; color: var(--ink); }
.sum dd.total { font-size: var(--step-2); line-height: 1.15; }
.sum .sub { font-size: var(--step--1); padding-left: 1rem; }
.sum.lead dd { font-size: var(--step-1); }
.sum.lead dd.total { font-size: var(--step-2); }
.bar-pair { display: grid; gap: 6px; margin: .9rem 0 .2rem; }
.bar-pair div { height: 10px; border-radius: 0 4px 4px 0; min-width: 2px; }
.fig h3 { font-weight: 600; color: var(--muted); font-size: var(--step--1); margin-bottom: .15rem; }
.fig .big { font-size: var(--step-2); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .45rem .7rem; text-align: left; border-bottom: 1px solid var(--rule); vertical-align: middle; }
thead th { font-size: var(--step--1); font-weight: 600; color: var(--muted); background: #f7faf9; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; }
td.num, th.num { text-align: right; }
td select { min-width: 9rem; }
td.desc { min-width: 12rem; overflow-wrap: anywhere; }

/* ---- charts ---- */
.hbars { display: grid; grid-template-columns: minmax(6rem, max-content) minmax(3rem, 1fr) max-content; gap: .35rem .75rem; align-items: center; }
.hbars .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 16rem; }
.hbars .track { height: 12px; }
.hbars .bar { height: 12px; background: var(--out); border-radius: 0 4px 4px 0; min-width: 2px; }
.legend { display: flex; gap: 1rem; font-size: var(--step--1); color: var(--muted); margin-bottom: .4rem; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .35rem; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font: 400 12px "Figtree", system-ui, sans-serif; fill: var(--muted); }
.chart .hit { fill: transparent; }
.chart .hit:hover, .chart .hit:focus { fill: rgba(21, 38, 43, .06); outline: none; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; padding: .4rem .6rem; border-radius: var(--r); font-size: var(--step--1); white-space: nowrap; z-index: 5; font-variant-numeric: tabular-nums; }

/* ---- transactions list ---- */
.chipbar { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; align-items: center; }
.fchip { min-height: 2.25rem; padding: 0 .8rem; border-radius: 99px; border: 1px solid var(--rule-strong); background: var(--surface); display: inline-flex; align-items: center; gap: .3rem; font-size: .9375rem; }
.fchip[aria-pressed=true], .fchip.on { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
.fchip[aria-pressed=true]::before { content: "\2713"; }
.fchip.on button { min-height: 1.5rem; width: 1.5rem; padding: 0; border: 0; background: none; color: inherit; border-radius: 50%; }
.filters { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 10.5rem), 1fr)); align-items: end; margin-bottom: .75rem; }
.filters .wide { grid-column: 1 / -1; }
.tagchecks { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: 0 .75rem; margin-top: .3rem; }
.list-bar { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; margin-bottom: .5rem; font-size: var(--step--1); }
.vlist { position: relative; overflow-y: auto; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r); height: calc(100dvh - 15.5rem); min-height: 20rem; contain: strict; max-width: 56rem; }
.dayhead { position: absolute; left: 0; right: 0; height: 38px; display: flex; justify-content: space-between; align-items: center; padding: 0 .9rem; background: #f4f8f7; border-bottom: 1px solid var(--rule); font-size: var(--step--1); font-weight: 700; color: var(--muted); }
.dayhead .num { font-weight: 400; }
.trow { position: absolute; left: 0; right: 0; height: 64px; border-bottom: 1px solid var(--rule); display: flex; align-items: stretch; }
.trow:hover { background: #f7faf9; }
.trow.void { color: var(--muted); }
.trow.void .t, .trow.void .c-orig { text-decoration: line-through; text-decoration-color: var(--rule-strong); }
.trow .pick { display: flex; align-items: center; padding: 0 0 0 .9rem; }
.trow .open { position: absolute; inset: 0; width: 100%; min-height: 0; padding: 0; border: 0; border-radius: 0; background: none; z-index: 0; }
.trow .open:focus-visible { outline-offset: -3px; }
.trow .pick { position: relative; z-index: 2; }
.trow .c-main, .trow .amts { position: relative; z-index: 1; pointer-events: none; }
.trow a.t { pointer-events: auto; align-self: flex-start; max-width: 100%; }
.trow .c-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; padding-left: .9rem; justify-content: center; }
.trow .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.trow .sub { display: flex; gap: .4rem; align-items: center; overflow: hidden; white-space: nowrap; font-size: var(--step--1); color: var(--muted); }
.trow .sub > * { flex: none; }
.trow .cat { background: var(--action-soft); color: var(--ink); border-radius: 99px; padding: 0 .55rem; line-height: 1.5; }
.trow .amts { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; line-height: 1.3; flex: none; padding: 0 .9rem; }
.trow .c-usd { font-size: var(--step--1); color: var(--muted); }
.selbar { position: sticky; bottom: .5rem; margin-top: .5rem; background: var(--ink); color: #fff; border-radius: var(--r); padding: .5rem .75rem; display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; z-index: 6; max-width: 56rem; }
.selbar button { min-height: 2.2rem; }

/* ---- dialogs ---- */
dialog.dialog { border: 0; border-radius: 10px; padding: 0; width: min(38rem, calc(100vw - 1.5rem)); max-height: calc(100dvh - 1.5rem); color: var(--ink); background: var(--surface); box-shadow: 0 20px 60px rgba(21, 38, 43, .35); }
dialog.dialog.wide { width: min(56rem, calc(100vw - 1.5rem)); }
dialog::backdrop { background: rgba(21, 38, 43, .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .8rem 1.1rem; border-bottom: 1px solid var(--rule); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.dialog-body { padding: 1rem 1.1rem 1.2rem; }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: .15rem 1rem; font-size: var(--step--1); margin: 0 0 1rem; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; overflow-wrap: anywhere; }
.split-line { display: grid; grid-template-columns: 8rem minmax(0, 1fr); gap: .5rem; padding: .75rem 0; border-bottom: 1px solid var(--rule); align-items: end; }
.left-to-assign { display: flex; justify-content: space-between; align-items: baseline; border-top: 2px solid var(--ink); margin-top: 1rem; padding-top: .5rem; font-weight: 700; }
.left-to-assign output { font-size: var(--step-2); }
.left-to-assign.done output::after { content: " \2713"; }
dialog.dialog.sheet { margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(30rem, 100vw); border-radius: 0; }
.sticky-actions { position: sticky; bottom: 0; background: var(--surface); padding: .75rem 0; border-top: 1px solid var(--rule); margin-bottom: -1.2rem; z-index: 1; }
.split-line .full { grid-column: 1 / -1; }

/* ---- review ---- */
.rv-wrap { display: grid; grid-template-columns: minmax(0, 34rem) minmax(0, 18rem); gap: 1.5rem; align-items: start; }
.rv-card { padding: 1.25rem; }
.rv-top { display: flex; justify-content: space-between; gap: 1rem; align-items: start; }
.rv-desc { font-size: var(--step-1); font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.rv-amt { font-size: var(--step-2); line-height: 1.2; }
.rv-actions { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: .5rem; margin-top: 1rem; }
.rv-actions button { min-height: 3rem; }
.rv-actions #rv-edit { grid-column: 1 / -1; min-height: 2.5rem; border-color: transparent; background: none; color: var(--action); text-decoration: underline; }
.rv-next { list-style: none; margin: 0; padding: 0; }
.rv-next li { display: flex; justify-content: space-between; gap: .75rem; padding: .45rem 0; border-bottom: 1px solid var(--rule); font-size: var(--step--1); }
.rv-next .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rule-offer { margin-top: .3rem; font-size: .9375rem; }

/* ---- home ---- */
.answers { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: 1rem; }
.answers .fig h2 { font-size: var(--step-0); font-weight: 600; color: var(--muted); margin-bottom: .2rem; }
.answers .fig p { margin: .35rem 0 0; }
.answers .fig .button { margin-top: .6rem; }
.bar-pair.cmp { margin: .5rem 0 .1rem; gap: 4px; }
.bar-pair.cmp div { height: 8px; }

/* ---- more ---- */
.more-list { display: grid; padding: 0; max-width: 40rem; }
.more-list a { display: grid; gap: .1rem; padding: .85rem 1.1rem; text-decoration: none; color: inherit; border-bottom: 1px solid var(--rule); }
.more-list a:last-child { border-bottom: 0; }
.more-list a:hover { background: #f7faf9; }
.more-list strong { color: var(--action); }

.toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .65rem 1rem; border-radius: var(--r); z-index: 100; display: flex; gap: 1rem; align-items: center; max-width: calc(100vw - 2rem); box-shadow: 0 8px 24px rgba(21, 38, 43, .3); }
.toast button.link { color: #bfe3e8; white-space: nowrap; }
details.fold > summary { cursor: pointer; font-weight: 700; font-size: var(--step-1); padding: .5rem 0; }
.month-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr)); gap: .6rem; }
.month-grid .m { border: 1px solid var(--rule); background: var(--surface); border-radius: var(--r); padding: .6rem .7rem; display: grid; gap: .4rem; }
.month-grid .m .pair { display: grid; grid-template-columns: 2.6rem minmax(0, 1fr); gap: .4rem; align-items: center; }

/* ---- small screens: bottom tab bar, full-screen sheets ---- */
@media (max-width: 859px) {
  :root { --step-3: 1.6rem; --step-2: 1.35rem; }
  .shell { display: block; }
  main { padding: 1rem .9rem 9rem; }
  .side { position: fixed; inset: auto 0 0 0; height: auto; flex-direction: row; padding: 0; z-index: 30; overflow: visible; padding-bottom: env(safe-area-inset-bottom); }
  .brand, .side-foot, .side-add { display: none; }
  #nav { display: flex; width: 100%; gap: 0; }
  #nav a { flex: 1 1 0; flex-direction: column; justify-content: center; text-align: center; min-height: 3.5rem; font-size: .8125rem; padding: 0 .1rem; border-radius: 0; gap: 0; line-height: 1.2; position: relative; }
  #nav a[aria-current=page] { background: none; color: #fff; font-weight: 700; box-shadow: inset 0 3px 0 #9fd8e0; }
  #nav .count { position: absolute; top: .25rem; left: calc(50% + .9rem); font-size: .65rem; }
  .fab { display: inline-flex; }
  .vlist { height: calc(100dvh - 19rem); }
  .trow .acct { display: none; }
  .rv-wrap { grid-template-columns: minmax(0, 1fr); }
  .rv-desc { font-size: var(--step-0); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .rv-card { padding: 1rem; }
  .chipbar.scroll { flex-wrap: nowrap; overflow-x: auto; margin-inline: -.9rem; padding-inline: .9rem; scrollbar-width: none; }
  .chipbar.scroll .fchip { flex: none; }
  td.desc { min-width: 8.5rem; font-size: var(--step--1); }
  td select { min-width: 7.5rem; }
  .rv-actions button { min-height: 3.25rem; }
  .keys { display: none; }
  dialog.dialog.sheet { width: 100vw; max-width: 100vw; }
  th, td { padding: .45rem .5rem; }
  .hide-sm { display: none; }
  .toast { bottom: 4.5rem; }
  .hbars { grid-template-columns: minmax(0, 7.5rem) minmax(2rem, 1fr) max-content; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
@media (forced-colors: active) { .hbars .bar, .bar-pair div { background: CanvasText !important; } }
.suggest { display: block; width: 100%; text-align: left; min-height: 3rem; padding: .6rem .8rem; margin: 0 0 .9rem; border: 1px solid var(--action); background: var(--action-soft); border-radius: var(--r); line-height: 1.35; white-space: normal; }
.notice.linked { border-color: var(--action); }
