/* Layout: one month on one board. Equation summary on top (income − expenses = remaining),
   charts + upcoming reminders beneath, then the three ledgers as editable spreadsheet-style tables. */
:root {
  color-scheme: dark;
  --ink: #0e1419;        /* page */
  --panel: #151d24;      /* raised surfaces */
  --panel-2: #1b252e;    /* hover / stripe */
  --line: #26323d;       /* rules */
  --text: #e4ebef;
  --muted: #8a9aa7;
  --faint: #5c6b77;
  --brass: #e2b55c;      /* accent: reminders + focus */
  --brass-dim: rgba(226, 181, 92, .14);
  --gain: #72d1a8;       /* money in / left over */
  --loss: #ef8a72;       /* money out */
  --loss-2: #c9705c;
  --danger: #d93b3f;     /* destructive actions */

  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "Figtree", "Segoe UI", system-ui, sans-serif;
  --f-num: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --r: 10px;
}

* { box-sizing: border-box; }
html, body { background: var(--ink); }
body {
  color: var(--text);
  font: 15px/1.5 var(--f-body);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0 64px;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1560px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { display: block; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding-block: 22px 18px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.brand h1 { margin: 0; font: 650 26px/1 var(--f-display); letter-spacing: -.01em; }
.brand h1 .logo { width: 32px; height: 32px; margin-right: 10px; vertical-align: -7px; border-radius: 7px; }
.brand p { margin: 0; color: var(--muted); font-size: 14px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 10px;
  border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 13px; background: var(--panel);
}
.pill svg { width: 15px; height: 15px; color: var(--brass); }
.pill b { color: var(--text); font-weight: 600; }

/* ---------- summary equation ---------- */
.equation {
  display: grid; grid-template-columns: 1fr auto 1fr auto 1.15fr; align-items: stretch; gap: 8px 20px;
}
.fig { display: flex; flex-direction: column; gap: 6px; padding-block: 18px; min-width: 0; }
.fig-label { font-size: 12px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 600; }
.fig-val { font: 600 clamp(32px, 4.4vw, 48px)/1.05 var(--f-display); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.fig-val .cents { font-size: .5em; color: var(--muted); font-weight: 500; letter-spacing: 0; margin-left: 2px; }
.fig-sub { font-size: 13.5px; color: var(--muted); }
.fig-sub .tag { color: var(--faint); }
#v-expenses { color: var(--loss); }
.op { align-self: center; font: 300 40px/1 var(--f-display); color: var(--faint); }
.fig.result {
  padding: 18px 22px; border-radius: var(--r); background: var(--panel); border: 1px solid var(--line);
}
.fig.result .fig-val { color: var(--gain); }
.fig.result.short .fig-val { color: var(--loss); }

/* ---------- charts row ---------- */
.board { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 20px 22px; min-width: 0; }
.panel-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-h h2 { margin: 0; font: 600 17px/1.2 var(--f-display); }
.panel-h .meta { color: var(--muted); font-size: 13px; }

.track { display: flex; height: 34px; border-radius: 6px; overflow: hidden; background: var(--panel-2); gap: 2px; }
.seg { height: 100%; min-width: 2px; background: var(--loss); transition: filter .15s; }
.seg:nth-child(even) { background: var(--loss-2); }
.seg.left { background: var(--gain); opacity: .85; }
.seg:hover { filter: brightness(1.15); }
.track-labels { display: flex; justify-content: space-between; gap: 12px; margin-top: 10px; font-size: 13.5px; flex-wrap: wrap; }
.track-labels .k { color: var(--muted); }
.track-labels .out { color: var(--loss); }
.track-labels .in { color: var(--gain); }
.excluded-note { margin-top: 6px; font-size: 13px; color: var(--faint); }

.ranked { list-style: none; margin: 22px 0 0; padding: 18px 0 0; border-top: 1px solid var(--line); display: grid; gap: 9px; }
.ranked li { display: grid; grid-template-columns: minmax(110px, 190px) 1fr 84px; align-items: center; gap: 14px; font-size: 14px; }
.ranked .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.ranked .bar { height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.ranked .bar i { display: block; height: 100%; background: var(--loss); border-radius: 4px; }
.ranked .amt { text-align: right; color: var(--muted); font-size: 13px; }
.ranked .more { display: block; color: var(--faint); font-size: 13px; padding-top: 2px; }

.upcoming { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.upcoming li { display: grid; grid-template-columns: 46px 1fr; gap: 12px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.upcoming li:last-child { border-bottom: 0; }
.cal { display: flex; flex-direction: column; align-items: center; border: 1px solid var(--line); border-radius: 7px; padding: 4px 0 5px; background: var(--ink); }
.cal small { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--brass); font-weight: 700; }
.cal b { font: 600 18px/1 var(--f-display); }
.up-t { font-size: 14px; font-weight: 600; line-height: 1.3; }
.up-s { font-size: 12.5px; color: var(--muted); }
.empty-state { color: var(--muted); font-size: 14px; padding: 6px 0; }
.empty-state svg { width: 22px; height: 22px; color: var(--faint); margin-bottom: 8px; }

/* ---------- ledgers ---------- */
.ledgers { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.ledger { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; overflow: hidden; }
.ledger-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 12px; flex-wrap: wrap; }
.ledger-h h2 { margin: 0; font: 600 19px/1.2 var(--f-display); display: flex; align-items: baseline; gap: 10px; }
.ledger-h h2 span { font: 500 13px var(--f-body); color: var(--muted); }
.ledger-note { margin: -4px 18px 12px; font-size: 13px; color: var(--muted); max-width: 60ch; }
.btn-add {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px 6px 9px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--panel-2); font-size: 13.5px; font-weight: 600;
}
.btn-add svg { width: 16px; height: 16px; color: var(--brass); }
.btn-add:hover { border-color: var(--faint); }

/* Positioned so it contains and clips absolutely positioned descendants, such as the
   .sr header labels; otherwise they escape the scroll box and widen the page. */
.scroller { position: relative; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; min-width: 560px; }
thead th {
  text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; height: 34px; background: var(--ink);
}
thead th.r { text-align: right; }
thead th.c { text-align: center; }
th .sort {
  all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
  width: 100%; height: 34px; padding: 0 10px; letter-spacing: inherit; text-transform: inherit;
}
th.r .sort { justify-content: flex-end; }
th .sort:hover { color: var(--text); }
th .sort:focus-visible { outline: 2px solid var(--brass); outline-offset: -2px; }
th .sort svg { width: 12px; height: 12px; opacity: .35; }
th[aria-sort="ascending"] .sort, th[aria-sort="descending"] .sort { color: var(--brass); }
th[aria-sort="ascending"] .sort svg, th[aria-sort="descending"] .sort svg { opacity: 1; }
th[aria-sort="descending"] .sort svg { transform: rotate(180deg); }
th .plain { display: block; padding: 0 10px; }

tbody tr { border-bottom: 1px solid var(--line); }
tbody tr:nth-child(even) { background: rgba(255,255,255,.018); }
tbody tr:hover { background: var(--panel-2); }
td { padding: 0 4px; height: 44px; vertical-align: middle; }
td:first-child { padding-left: 8px; }
.cell {
  width: 100%; height: 32px; padding: 0 6px; border: 1px solid transparent; border-radius: 6px; background: transparent;
  min-width: 0; text-overflow: ellipsis;
}
.cell:hover { border-color: var(--line); }
.cell:focus { outline: none; border-color: var(--brass); background: var(--ink); }
select.cell { appearance: none; cursor: pointer; }
select.cell.unset, input.cell.unset { color: var(--faint); }
input[type="date"].cell { font-size: 13.5px; }
.amt-wrap { display: flex; align-items: center; justify-content: flex-end; }
.amt-wrap .cur { color: var(--faint); font-size: 13px; margin-right: -2px; }
.amt-wrap input { text-align: right; font-family: var(--f-num); font-variant-numeric: tabular-nums; font-size: 14px; max-width: 110px; }
.amt-wrap input::-webkit-inner-spin-button { display: none; }
.amt-wrap input { -moz-appearance: textfield; }
tr.excluded .c-src .cell, tr.excluded .amt-wrap input { color: var(--faint); text-decoration: line-through; text-decoration-color: var(--faint); }
td.ctr { text-align: center; }

.switch {
  position: relative; width: 36px; height: 20px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel-2); padding: 0; vertical-align: middle; transition: background .15s, border-color .15s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--faint); transition: transform .15s, background .15s;
}
.switch[aria-checked="true"] { background: rgba(114, 209, 168, .18); border-color: rgba(114, 209, 168, .5); }
.switch[aria-checked="true"]::after { transform: translateX(16px); background: var(--gain); }
.switch.brass[aria-checked="true"] { background: var(--brass-dim); border-color: rgba(226,181,92,.55); }
.switch.brass[aria-checked="true"]::after { background: var(--brass); }

.bell {
  position: relative; width: 34px; height: 32px; border-radius: 7px; border: 1px solid transparent; background: transparent;
  display: inline-grid; place-items: center; color: var(--faint); vertical-align: middle;
}
.bell svg { width: 18px; height: 18px; }
.bell:hover { color: var(--text); border-color: var(--line); }
.bell.on { color: var(--brass); background: var(--brass-dim); }
.bell.on svg path:first-child { fill: currentColor; }
.bell .badge {
  position: absolute; top: 1px; right: 1px; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px;
  background: var(--brass); color: var(--ink); font: 700 10px/15px var(--f-body); text-align: center;
}
.del {
  width: 30px; height: 30px; border-radius: 7px; border: 0; background: transparent; color: var(--faint);
  display: inline-grid; place-items: center; opacity: .55; vertical-align: middle;
}
.del svg { width: 15px; height: 15px; }
tr:hover .del, .del:focus-visible { opacity: 1; }
.del:hover { color: var(--loss); background: rgba(239,138,114,.1); }

tfoot td { height: 46px; font-size: 13.5px; color: var(--muted); background: var(--ink); }
tfoot .tot { text-align: right; padding-right: 14px; }
tfoot .tot b { color: var(--text); font-family: var(--f-num); font-weight: 500; font-variant-numeric: tabular-nums; font-size: 14.5px; margin-left: 8px; }
tfoot .aside { display: block; font-size: 12px; color: var(--faint); }
.row-empty td { color: var(--muted); text-align: center; font-size: 14px; height: 64px; }

/* ---------- reminder dialog ---------- */
dialog {
  width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border-radius: 14px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); box-shadow: 0 30px 80px rgba(0,0,0,.55);
}
dialog::backdrop { background: rgba(6, 10, 13, .66); backdrop-filter: blur(3px); }
.dlg { display: flex; flex-direction: column; }
.dlg-head { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 18px 18px 14px; border-bottom: 1px solid var(--line); }
.dlg-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--brass-dim); color: var(--brass); display: grid; place-items: center; }
.dlg-icon svg { width: 20px; height: 20px; }
.dlg-eyebrow { font-size: 11.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.dlg-head h3 { margin: 2px 0 0; font: 600 19px/1.2 var(--f-display); overflow-wrap: anywhere; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }
.dlg-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 16px; }
.field { display: grid; grid-template-columns: 92px 1fr; gap: 10px; align-items: center; }
.field label, .field .lbl { font-size: 13.5px; color: var(--muted); }
.ctl {
  height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--ink); width: 100%;
}
.ctl:focus { outline: none; border-color: var(--brass); }
.hint { grid-column: 2; font-size: 12.5px; color: var(--muted); margin-top: -4px; }
.hint.warn { color: var(--brass); }
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--ink); border: 1px solid var(--line); }
.toggle-row strong { display: block; font-size: 14.5px; }
.toggle-row span { font-size: 12.5px; color: var(--muted); }
.rem { display: flex; flex-direction: column; gap: 12px; transition: opacity .15s; }
.rem.is-off { opacity: .45; }
.rem h4 { margin: 0; font-size: 11.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.rem-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rem-list li { display: grid; grid-template-columns: 1fr auto 30px; align-items: center; gap: 10px; padding: 8px 6px 8px 12px; border-radius: 8px; background: var(--panel-2); font-size: 14px; }
.rem-list .when { color: var(--muted); font-size: 12.5px; text-align: right; }
.rem-list li.none { grid-template-columns: 1fr; color: var(--muted); background: transparent; border: 1px dashed var(--line); }
.rem-list .x { width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--faint); display: grid; place-items: center; }
.rem-list .x:hover { color: var(--loss); background: rgba(239,138,114,.1); }
.rem-list .x svg { width: 14px; height: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 11px 5px 9px; border-radius: 999px; border: 1px solid var(--line); background: transparent; font-size: 13px; display: inline-flex; align-items: center; gap: 5px; color: var(--text); }
.chip svg { width: 13px; height: 13px; color: var(--brass); }
.chip:hover { border-color: var(--brass); }
.custom { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); }
.custom .ctl { width: auto; }
.custom #dlg-n { width: 64px; }
.btn { height: 36px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); font-weight: 600; font-size: 14px; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--brass); border-color: var(--brass); color: var(--ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(1.1); }
.dlg-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.dlg-foot .next { font-size: 13px; color: var(--muted); }
.dlg-foot .next b { color: var(--text); font-weight: 600; }

/* ---------- remove confirmation ---------- */
dialog.confirm { width: min(380px, calc(100vw - 32px)); }
.confirm .dlg-body { gap: 6px; padding-top: 20px; }
.confirm h3 { margin: 0; font: 600 19px/1.25 var(--f-display); overflow-wrap: anywhere; }
.confirm p { margin: 0; font-size: 14px; color: var(--muted); }
.confirm .dlg-foot { justify-content: flex-end; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 14px; padding: 10px 10px 10px 16px; border-radius: 10px;
  background: var(--text); color: var(--ink); font-size: 14px; font-weight: 500; box-shadow: 0 12px 40px rgba(0,0,0,.5);
  max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }
.toast button { border: 0; background: var(--ink); color: var(--brass); font-weight: 700; padding: 6px 12px; border-radius: 7px; }

/* ---------- responsive ---------- */
/* Ledgers sit side by side only when each is wide enough (~690px+) for a readable Source column. */
@media (max-width: 1400px) {
  .ledgers { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .board { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .equation { grid-template-columns: 1fr; gap: 0; }
  .op { display: none; }
  .fig { padding-block: 12px; border-bottom: 1px solid var(--line); }
  .fig.result { margin-top: 14px; border-bottom: 1px solid var(--line); }
  .ranked li { grid-template-columns: minmax(0, 1fr) 70px; }
  .ranked .bar { grid-column: 1 / -1; grid-row: 2; }
}
/* Narrow phones: labels sit above their controls so the controls get the full width. */
@media (max-width: 420px) {
  .field { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .hint { grid-column: 1; margin-top: 0; }
}
/* iOS Safari zooms into a focused field whose text is under 16px. On touch screens,
   every text-entry control gets at least 16px; this floor overrides the smaller
   desktop sizes above. */
@media (pointer: coarse) {
  input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"]), select, textarea {
    font-size: max(16px, 1em) !important;
  }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- app additions: sign out, loading, account ---------- */
.acct {
  width: 34px; height: 32px; border-radius: 7px; border: 1px solid transparent; background: transparent;
  display: inline-grid; place-items: center; color: var(--faint); vertical-align: middle;
}
.acct svg { width: 18px; height: 18px; }
.acct.set { color: var(--text); }
.acct.set svg { color: var(--acct); }
/* One hue per account type so rows can be told apart at a glance. */
.acct-ach { --acct: #5ea4f2; }
.acct-debit { --acct: #a98bf5; }
.acct-credit { --acct: #f2994a; }
.acct-ebt { --acct: #5fcb7e; }
.acct-hsa { --acct: #f0646e; }
.acct-fsa { --acct: #4ecdc4; }
.acct:hover, .acct[aria-expanded="true"] { color: var(--text); border-color: var(--line); }
.grip {
  width: 22px; height: 30px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--faint);
  display: inline-grid; place-items: center; vertical-align: middle; cursor: grab; touch-action: none; opacity: .6;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.grip svg { width: 14px; height: 14px; }
tr:hover .grip, .grip:focus-visible { opacity: 1; }
.grip:hover { color: var(--text); background: var(--panel-2); }
tr.dragging { background: var(--panel-2); box-shadow: 0 6px 18px rgba(0,0,0,.35); position: relative; z-index: 1; }
tr.dragging .grip { color: var(--brass); opacity: 1; cursor: grabbing; }
/* While a row is dragged, no text under the pointer may be selected. */
body.dragging-row { cursor: grabbing; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.dragging-row * { -webkit-user-select: none; user-select: none; }
.menu {
  position: fixed; z-index: 20; min-width: 210px; padding: 6px; display: grid; gap: 2px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel); box-shadow: 0 18px 50px rgba(0,0,0,.5);
}
.menu[hidden] { display: none; }
.menu button {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 7px;
  background: transparent; font-size: 14px; text-align: left; color: var(--text);
}
.menu button svg { width: 18px; height: 18px; flex: none; color: var(--acct, var(--muted)); }
.menu button:hover, .menu button:focus-visible { background: var(--panel-2); outline: none; }
.menu button[aria-checked="true"] { color: var(--brass); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.top-actions form { margin: 0; }
.signout {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
}
.signout svg { width: 16px; height: 16px; }
.signout:hover { color: var(--text); border-color: var(--faint); }
body.loading .wrap > section { opacity: .4; pointer-events: none; }
