/* ==========================================================================
   Guilder — design tokens
   Calm slate neutrals, one indigo accent, and semantic money colours.
   Dark is the base; light overrides it. The theme is chosen by the inline
   script in index.html (stored choice, else prefers-color-scheme), and the
   media query below covers the case where that script never ran.
   app.js reads --viz-*, --grid, --ink-2, --ink-3 and --surface for charts.
   ========================================================================== */
:root {
  color-scheme: dark;

  /* neutrals */
  --page: #0d0f13;
  --surface: #15181e;
  --surface-2: #1c2028;
  --surface-3: #262b35;
  --ink: #eceef3;
  --ink-2: #b2b8c4;
  --ink-3: #848b99;
  --hairline: rgba(255,255,255,0.08);
  --hairline-strong: rgba(255,255,255,0.14);
  --grid: #21252d;

  /* accent */
  --accent: #6366f1;
  --accent-hover: #7477f5;
  --accent-text: #a5a8ff;
  --accent-soft: rgba(124,128,255,.16);
  --on-accent: #ffffff;
  --focus-ring: rgba(124,128,255,.55);

  /* money & states */
  --good: #22a861;
  --good-text: #4ade80;
  --bad: #f2727f;
  --warn: #e0a028;
  --pos-bg: rgba(34,168,97,.18);
  --neg-bg: rgba(242,114,127,.17);
  --part-bg: rgba(224,160,40,.18);
  --banner-bg: rgba(224,160,40,.10);
  --banner-border: rgba(224,160,40,.32);
  --banner-text: #f3c463;
  --danger-border: rgba(242,114,127,.40);
  --danger-bg: rgba(242,114,127,.12);

  /* depth */
  --shadow: rgba(0,0,0,.55);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  --shadow-md: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
  --shadow-lg: 0 24px 64px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.35);
  --scrim: rgba(5,6,9,.66);

  /* charts (read by app.js) */
  --viz-blue: #7c80ff;
  --viz-red: #f2727f;
  --viz-teal: #1ca6b6;
  --viz-axis: #3a404c;

  /* shape, type, space */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", system-ui,
          Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --fs-xs: 11px;
  --fs-sm: 12.5px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-2xl: 24px;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --ease: cubic-bezier(.2,.7,.3,1);
}

:root[data-theme="light"] {
  color-scheme: light;
  --page: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --surface-3: #e6e9ef;
  --ink: #131620;
  --ink-2: #464d5c;
  --ink-3: #6b7280;
  --hairline: rgba(19,22,32,0.09);
  --hairline-strong: rgba(19,22,32,0.16);
  --grid: #eceef2;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-text: #4338ca;
  --accent-soft: rgba(79,70,229,.09);
  --on-accent: #ffffff;
  --focus-ring: rgba(79,70,229,.40);
  --good: #16a34a;
  --good-text: #0f7a3a;
  --bad: #cf2f45;
  --warn: #b7791f;
  --pos-bg: rgba(22,163,74,.11);
  --neg-bg: rgba(207,47,69,.10);
  --part-bg: rgba(217,145,20,.16);
  --banner-bg: rgba(217,145,20,.09);
  --banner-border: rgba(217,145,20,.38);
  --banner-text: #8a5800;
  --danger-border: rgba(207,47,69,.38);
  --danger-bg: rgba(207,47,69,.07);
  --shadow: rgba(16,24,40,.16);
  --shadow-sm: 0 1px 2px rgba(16,24,40,.05);
  --shadow-md: 0 1px 2px rgba(16,24,40,.05), 0 4px 12px rgba(16,24,40,.06);
  --shadow-lg: 0 24px 60px rgba(16,24,40,.18), 0 2px 8px rgba(16,24,40,.08);
  --scrim: rgba(17,20,28,.42);
  --viz-blue: #5b5ff0;
  --viz-red: #e5485d;
  --viz-teal: #0e9fb4;
  --viz-axis: #c4c9d3;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --page: #f4f5f8; --surface: #ffffff; --surface-2: #f2f4f7; --surface-3: #e6e9ef;
    --ink: #131620; --ink-2: #464d5c; --ink-3: #6b7280;
    --hairline: rgba(19,22,32,0.09); --hairline-strong: rgba(19,22,32,0.16); --grid: #eceef2;
    --accent: #4f46e5; --accent-hover: #4338ca; --accent-text: #4338ca; --accent-soft: rgba(79,70,229,.09);
    --focus-ring: rgba(79,70,229,.40);
    --good: #16a34a; --good-text: #0f7a3a; --bad: #cf2f45; --warn: #b7791f;
    --pos-bg: rgba(22,163,74,.11); --neg-bg: rgba(207,47,69,.10); --part-bg: rgba(217,145,20,.16);
    --banner-bg: rgba(217,145,20,.09); --banner-border: rgba(217,145,20,.38); --banner-text: #8a5800;
    --danger-border: rgba(207,47,69,.38); --danger-bg: rgba(207,47,69,.07);
    --shadow: rgba(16,24,40,.16);
    --shadow-sm: 0 1px 2px rgba(16,24,40,.05);
    --shadow-md: 0 1px 2px rgba(16,24,40,.05), 0 4px 12px rgba(16,24,40,.06);
    --shadow-lg: 0 24px 60px rgba(16,24,40,.18), 0 2px 8px rgba(16,24,40,.08);
    --scrim: rgba(17,20,28,.42);
    --viz-blue: #5b5ff0; --viz-red: #e5485d; --viz-teal: #0e9fb4; --viz-axis: #c4c9d3;
  }
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: var(--fs-md)/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
a { color: var(--accent-text); text-underline-offset: 2px; }
::selection { background: var(--accent-soft); }

:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
a:focus-visible, button:focus-visible { border-radius: var(--radius-sm); }

* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }

#app { display: flex; height: 100vh; }

/* ==========================================================================
   Sidebar
   ========================================================================== */
#sidebar {
  width: 264px; flex: 0 0 264px;
  background: var(--surface);
  border-right: 1px solid var(--hairline);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.brand {
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  font-size: 18px; font-weight: 700; letter-spacing: -0.015em;
  display: flex; align-items: center; gap: 10px;
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(140deg, #6d72ff 0%, #4f46e5 55%, #4338ca 100%);
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: Georgia, "Times New Roman", serif; font-style: italic; font-size: 18px;
  padding-bottom: 1px;
  box-shadow: 0 1px 2px rgba(0,0,0,.2), inset 0 1px 0 rgba(255,255,255,.18);
}
#nav { flex: 1; padding: var(--sp-1) var(--sp-3) var(--sp-3); }
.nav-item {
  display: flex; justify-content: space-between; align-items: center; gap: var(--sp-2);
  padding: 7px 10px; margin: 1px 0; border-radius: 8px; cursor: pointer;
  color: var(--ink-2); text-decoration: none; font-weight: 500;
  transition: background-color .12s var(--ease), color .12s var(--ease);
}
.nav-item > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active {
  background: var(--accent-soft); color: var(--accent-text); font-weight: 600;
}
.nav-item .amt { font-size: var(--fs-sm); font-weight: 500; flex-shrink: 0; }
.nav-item.active .amt.muted { color: var(--accent-text); opacity: .75; }
.nav-section {
  margin: var(--sp-5) 10px 6px; font-size: var(--fs-xs); font-weight: 650;
  letter-spacing: .08em; color: var(--ink-3); text-transform: uppercase;
}
.nav-item.closed { opacity: .5; }
.sidebar-footer {
  padding: var(--sp-3);
  border-top: 1px solid var(--hairline);
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
#btn-bug[hidden] { display: none; }
.sidebar-footer .btn { width: 100%; justify-content: flex-start; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ==========================================================================
   Main layout
   ========================================================================== */
#main { flex: 1; overflow-y: auto; min-width: 0; }
.view { padding: var(--sp-6) var(--sp-8) 64px; max-width: 1200px; }
.view-header {
  display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}
.view-header h1 { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.02em; }
.spacer { flex: 1; }
.subtle { color: var(--ink-3); font-size: var(--fs-sm); }
.subtle b { font-weight: 650; }

/* ==========================================================================
   Buttons & inputs
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: var(--on-accent);
  border: 1px solid transparent;
  padding: 7px 14px; border-radius: 8px; cursor: pointer;
  font-weight: 600; font-size: var(--fs-md); line-height: 1.3;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,.12);
  transition: background-color .12s var(--ease), border-color .12s var(--ease),
              color .12s var(--ease), box-shadow .12s var(--ease), transform .06s var(--ease);
}
.btn:hover { background: var(--accent-hover); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.ghost {
  background: var(--surface); border-color: var(--hairline-strong); color: var(--ink-2);
  font-weight: 500; box-shadow: var(--shadow-sm);
}
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); border-color: var(--hairline-strong); }
.btn.danger { background: transparent; border-color: var(--danger-border); color: var(--bad); box-shadow: none; }
.btn.danger:hover { background: var(--danger-bg); }
.btn.small { padding: 5px 11px; font-size: var(--fs-sm); border-radius: 7px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:disabled:hover { background: var(--accent); }
.btn.ghost:disabled:hover { background: var(--surface); }

input[type=text], input[type=date], input[type=number], input[type=month], input[type=search], select, textarea {
  background: var(--surface); border: 1px solid var(--hairline-strong);
  border-radius: 8px; padding: 6px 10px; outline: none; min-width: 0;
  box-shadow: var(--shadow-sm);
  transition: border-color .12s var(--ease), box-shadow .12s var(--ease);
}
input[type=text]:hover, input[type=date]:hover, input[type=number]:hover, input[type=month]:hover,
input[type=search]:hover, select:hover, textarea:hover { border-color: var(--ink-3); }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
label.fld { display: block; margin-bottom: var(--sp-4); color: var(--ink-2); font-size: var(--fs-sm); font-weight: 550; }
label.fld > input, label.fld > select { display: block; width: 100%; margin-top: 6px; font-size: var(--fs-md); font-weight: 400; color: var(--ink); }
.checkline { display: flex; gap: var(--sp-2); align-items: center; color: var(--ink-2); margin-bottom: var(--sp-3); cursor: pointer; }

/* ==========================================================================
   Month nav & Ready to Assign
   ========================================================================== */
.month-nav { display: flex; align-items: center; gap: var(--sp-2); }
.month-nav button {
  background: var(--surface); border: 1px solid var(--hairline-strong); color: var(--ink-2);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 17px; line-height: 1;
  box-shadow: var(--shadow-sm);
  transition: background-color .12s var(--ease), color .12s var(--ease);
}
.month-nav button:hover { color: var(--ink); background: var(--surface-2); }
.month-nav .month-label { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.015em; min-width: 170px; text-align: center; }
.month-nav button:disabled { opacity: .4; cursor: default; background: var(--surface); color: var(--ink-2); }
/* A budget period: its dates, with where you are in it underneath. */
.period-head { display: flex; flex-direction: column; align-items: center; min-width: 170px; }
.period-head .month-label { min-width: 0; }
.period-link { cursor: pointer; border-radius: 6px; padding: 0 6px; transition: background-color .12s var(--ease); }
.period-link:hover { background: var(--surface-2); }
.period-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.period-sub { font-size: var(--fs-xs); color: var(--ink-3); white-space: nowrap; margin-top: 1px; }
.pm-section { border-top: 1px solid var(--hairline); padding: var(--sp-4) 0 var(--sp-2); }
.pm-section h3 { font-size: var(--fs-md); font-weight: 650; margin-bottom: var(--sp-1); }
.pm-row { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; margin-top: var(--sp-3); }
.ps-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.ps-preview { border: 1px solid var(--hairline); border-radius: var(--radius); padding: var(--sp-3); min-height: 44px; }
.ps-head { font-size: var(--fs-xs); color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; margin-bottom: var(--sp-2); }
.ps-item { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 3px 0; font-size: var(--fs-sm); }
.ps-item.past { color: var(--ink-3); }
.ps-item.first { font-weight: 650; }
.settings-line { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-top: 6px;
  font-weight: 400; color: var(--ink); font-size: var(--fs-md); }
.rta {
  border-radius: var(--radius); padding: 10px 18px; text-align: left;
  display: flex; flex-direction: column; gap: 2px; min-width: 190px;
  background: var(--pos-bg); color: var(--good-text);
  border: 1px solid color-mix(in srgb, var(--good) 35%, transparent);
}
.rta.negative {
  background: var(--neg-bg); color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 40%, transparent);
}
.rta.zero { background: var(--surface); color: var(--ink-2); border-color: var(--hairline-strong); box-shadow: var(--shadow-sm); }
.rta .rta-amount { font-size: 22px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.2; }
.rta .rta-label { font-size: var(--fs-xs); opacity: .85; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; }

.banner {
  background: var(--banner-bg); border: 1px solid var(--banner-border);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: var(--sp-4);
  display: flex; align-items: center; gap: 10px; color: var(--banner-text);
}
.banner a { color: inherit; font-weight: 650; }

/* ==========================================================================
   Data tables
   ========================================================================== */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
  text-align: right; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-3); font-weight: 650; padding: 8px 12px; border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}
table.grid th:first-child { text-align: left; }
table.grid td { padding: 7px 12px; border-bottom: 1px solid var(--grid); }
table.grid tbody tr:last-child td { border-bottom: none; }

/* top-level tables (budget, register) sit on a card */
.view > table.grid {
  border-collapse: separate; border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.view > table.grid th { background: var(--surface); padding-top: 11px; padding-bottom: 9px; }
.view > table.grid thead tr:first-child th:first-child { border-top-left-radius: var(--radius-lg); }
.view > table.grid thead tr:first-child th:last-child { border-top-right-radius: var(--radius-lg); }
.view > table.grid tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius-lg); }
.view > table.grid tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius-lg); }

tr.group-row td {
  background: var(--surface-2); font-weight: 650; font-size: var(--fs-sm);
  padding-top: 8px; padding-bottom: 8px; cursor: pointer;
  border-bottom-color: var(--hairline);
}
tr.group-row td:first-child { color: var(--ink); }
tr.group-row:hover td { background: var(--surface-3); }
tr.group-row .group-tools { visibility: hidden; }
tr.group-row:hover .group-tools { visibility: visible; }
table.grid td.num { text-align: right; white-space: nowrap; }
tr.cat-row td { transition: background-color .08s var(--ease); }
tr.cat-row:hover td { background: var(--surface-2); }
tr.cat-row .cat-name { cursor: pointer; font-weight: 500; }
tr.cat-row .cat-name:hover { color: var(--accent-text); }
tr.cat-row .copy-prev { visibility: hidden; margin-right: 4px; }
tr.cat-row:hover .copy-prev { visibility: visible; }
.goal-hint { font-size: var(--fs-xs); color: var(--ink-3); margin-left: var(--sp-2); white-space: nowrap; }
.goal-hint.met { color: var(--good-text); }
.goal-hint.under { color: var(--banner-text); }
/* goals: progress bar of what was put in vs the target, status, Close */
.goal-line { display: flex; align-items: center; flex-wrap: wrap; gap: 2px var(--sp-2); margin-top: 4px; }
.goal-line .goal-hint { margin-left: 0; }
.goal-bar { width: 120px; height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; flex: none; }
.goal-bar span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.goal-bar.met span { background: var(--good); }
.goal-close { padding: 1px 10px; font-size: var(--fs-xs); }
tr.cat-row.closed .cat-name, tr.cat-row.closed td { color: var(--ink-3); }
.link-btn { background: none; border: 0; padding: 0 0 0 var(--sp-2); color: var(--accent-text); font: inherit;
  font-size: var(--fs-xs); font-weight: 500; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.goal-more { margin: var(--sp-2) 0; }
.goal-more summary { cursor: pointer; }
.goal-more .pm-row { margin-top: var(--sp-2); }
.warn-t { color: var(--banner-text); }
.goal-pool { margin: 0 0 var(--sp-3); }
.goal-whatif { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 var(--sp-3); }
.goal-whatif .seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
td.goal-rank { width: 1%; white-space: nowrap; vertical-align: top; }
.goal-prio { display: inline-flex; gap: 2px; margin-left: 6px; }
.goal-prio .btn { padding: 0 6px; min-width: 0; line-height: 1.4; }
td.held-cell { cursor: pointer; }
tr.cat-row td.held-cell:hover {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 6px;
}
td.held-cell input { width: 108px; text-align: right; padding: 3px 8px; }
table.goals-report td { vertical-align: top; }
td.assigned-cell { cursor: pointer; }
tr.cat-row td.assigned-cell:hover {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 6px;
}
td.assigned-cell input {
  width: 108px; text-align: right; padding: 3px 8px;
}
.pill {
  display: inline-block; min-width: 84px; text-align: right;
  padding: 2px 10px; margin-right: -4px; border-radius: 99px; font-weight: 650;
  font-size: 13.5px;
}
.pill.pos { background: var(--pos-bg); color: var(--good-text); }
.pill.neg { background: var(--neg-bg); color: var(--bad); }
.pill.zero { background: var(--surface-2); color: var(--ink-3); }
.pill.part { background: var(--part-bg); color: var(--banner-text); }
.muted { color: var(--ink-3); }
.pos-t { color: var(--good-text); }
.neg-t { color: var(--bad); }
.totals-row td { font-weight: 700; border-top: 1px solid var(--hairline-strong); background: var(--surface-2); }
.row-tools { visibility: hidden; }
tr:hover .row-tools { visibility: visible; }
.icon-btn {
  background: none; border: none; cursor: pointer; color: var(--ink-3);
  padding: 2px 6px; border-radius: 6px; font-size: 13px; line-height: 1.4;
  transition: background-color .1s var(--ease), color .1s var(--ease);
}
.icon-btn:hover { color: var(--ink); background: var(--surface-3); }

/* ==========================================================================
   Register
   ========================================================================== */
.acct-stats {
  display: flex; gap: var(--sp-8); margin: 0 0 var(--sp-5);
  padding: var(--sp-4) var(--sp-5);
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  width: fit-content; max-width: 100%;
}
.acct-stat .lbl { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); font-weight: 650; margin-bottom: 2px; }
.acct-stat .val { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.toolbar { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-4); align-items: center; flex-wrap: wrap; }
.toolbar input[type=search] { width: 260px; }
table.register td, table.register th { vertical-align: middle; }
table.register .num { text-align: right; white-space: nowrap; }
table.register td select, table.register td input { width: 100%; padding: 4px 8px; }
table.register td.c-date { width: 108px; white-space: nowrap; color: var(--ink-2); }
table.register td.c-out, table.register td.c-in { width: 110px; }
table.register td.c-clr { width: 34px; text-align: center; }
table.register td.c-acct { width: 140px; }
table.register td.c-acct a { text-decoration: none; }
table.register td.c-acct a:hover { text-decoration: underline; }
tr.txn-row td { transition: background-color .08s var(--ease); }
tr.txn-row:hover td { background: var(--surface-2); cursor: pointer; }
tr.txn-edit td { background: var(--accent-soft); padding: 8px 6px; }
.clr-dot {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--ink-3); cursor: pointer; vertical-align: middle;
  transition: transform .1s var(--ease);
}
.clr-dot:hover { transform: scale(1.15); }
.clr-dot.on { background: var(--good); border-color: var(--good); }
.clr-dot.rec { background: var(--accent); border-color: var(--accent); }
select.cat-inline {
  width: 100%; min-width: 150px; max-width: 240px; padding: 3px 6px;
  background: transparent; border-color: transparent; box-shadow: none;
  text-overflow: ellipsis;
}
tr:hover select.cat-inline { border-color: var(--hairline-strong); background: var(--surface); }
select.cat-inline.needs-cat, #e-cat.needs-cat { color: var(--bad); font-weight: 600; }
/* off-budget side of an on/off-budget transfer: shows the on-budget side's category */
select.cat-inline.cat-mirror { font-style: italic; }
.load-more { text-align: center; padding: var(--sp-4); }
.txn-transfer { color: var(--accent-text); font-style: italic; }
.memo-sub { color: var(--ink-3); font-size: 12px; max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ==========================================================================
   Modal
   ========================================================================== */
@keyframes g-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes g-rise { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
.modal-backdrop {
  position: fixed; inset: 0; background: var(--scrim);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh var(--sp-4); z-index: 50;
  animation: g-fade .14s var(--ease);
}
.modal {
  background: var(--surface); border: 1px solid var(--hairline-strong);
  border-radius: 16px; padding: var(--sp-6); width: 460px; max-width: 100%;
  max-height: 82vh; overflow-y: auto; box-shadow: var(--shadow-lg);
  animation: g-rise .18s var(--ease);
}
.modal.wide { width: 780px; }
.modal h2 { font-size: 18px; margin-bottom: var(--sp-5); }
.modal-actions {
  display: flex; gap: var(--sp-2); justify-content: flex-end; flex-wrap: wrap;
  margin-top: var(--sp-6); padding-top: var(--sp-4); border-top: 1px solid var(--hairline);
}
.modal-actions .left { margin-right: auto; }
@media (prefers-reduced-motion: reduce) {
  .modal, .modal-backdrop, .toast { animation: none; }
  * { transition: none !important; }
}

/* ==========================================================================
   Import preview
   ========================================================================== */
.import-summary { display: flex; gap: var(--sp-5); margin: var(--sp-3) 0; flex-wrap: wrap; }
.import-summary .stat b { font-size: var(--fs-xl); display: block; }
.import-summary .stat { color: var(--ink-2); font-size: 12px; }
.preview-scroll { max-height: 320px; overflow: auto; border: 1px solid var(--hairline); border-radius: var(--radius); }
.preview-scroll table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.preview-scroll th { position: sticky; top: 0; background: var(--surface-2); padding: 7px 8px; text-align: left; font-size: var(--fs-xs); color: var(--ink-3); font-weight: 650; }
.preview-scroll td { padding: 5px 8px; border-top: 1px solid var(--grid); white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.preview-scroll tr.dup { opacity: .38; }
.tag { font-size: 10.5px; padding: 1px 8px; border-radius: 99px; background: var(--surface-3); color: var(--ink-2); font-weight: 600; }
.tag.new { background: var(--pos-bg); color: var(--good-text); }

/* ==========================================================================
   Reports
   ========================================================================== */
.report-card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius-lg); padding: var(--sp-5) var(--sp-6); margin-bottom: var(--sp-5);
  box-shadow: var(--shadow-md);
}
.report-card h2 { font-size: var(--fs-lg); margin-bottom: 2px; }
.report-card .sub { color: var(--ink-3); font-size: var(--fs-sm); margin-bottom: var(--sp-4); }
.chart-wrap { overflow-x: auto; }
.legend { display: flex; gap: var(--sp-4); font-size: var(--fs-sm); color: var(--ink-2); margin-bottom: 10px; flex-wrap: wrap; }
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-5); }
.stat-tile {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 14px var(--sp-4);
  box-shadow: var(--shadow-sm);
}
.stat-tile .lbl { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); font-weight: 650; margin-bottom: 6px; }
.stat-tile .val { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.015em; line-height: 1.2; }
.report-card table.grid th { padding-left: 10px; padding-right: 10px; }
.report-card table.grid td { padding: 6px 10px; }
.report-card table.grid tbody tr:hover td { background: var(--surface-2); }
table.heatmap { border-collapse: collapse; min-width: 640px; }
table.heatmap th { font-size: 10.5px; color: var(--ink-3); font-weight: 650; padding: 6px 2px; text-align: center; }
table.heatmap td.hm-name { font-size: 12px; color: var(--ink-2); padding: 2px 10px 2px 8px; white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
table.heatmap td.hm-cell { padding: 2px; }
.hm-fill, .hm-zero { display: block; width: 100%; min-width: 30px; height: 22px; border-radius: 5px; }
.hm-zero { background: var(--surface-2); }
.cal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3); flex-wrap: wrap; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; max-width: 840px; }
.cal-grid .cal-head { display: block; text-align: center; font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); font-weight: 650; padding: 0 0 6px; }
.cal-grid .cal-head.we { color: var(--ink-2); }
.cal-cell {
  position: relative; min-height: 60px; border-radius: 8px; background: var(--surface-2);
  padding: 6px 8px; overflow: hidden; cursor: default;
  box-shadow: inset 0 0 0 1px var(--hairline);
  transition: box-shadow .1s var(--ease);
}
.cal-cell:hover { box-shadow: inset 0 0 0 1.5px var(--accent); }
.cal-cell.empty { background: var(--surface); padding: 6px 8px; text-align: left; } /* not the .empty state block */
.cal-cell > .cal-fill { position: absolute; inset: 0; z-index: 0; }
.cal-cell > .cal-day, .cal-cell > .cal-total { position: relative; z-index: 1; }
.cal-cell.we .cal-day { color: var(--accent-text); }
.cal-day { font-size: 12px; font-weight: 650; color: var(--ink-2); }
.cal-total { font-size: 11.5px; font-weight: 650; color: var(--ink); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-blank { min-height: 60px; }
tr.inactive-rec { opacity: .5; }
tr.hm-unc td.hm-name { color: var(--ink-3); font-style: italic; }
.range-presets { display: flex; gap: 4px; }
.report-jump { display: flex; gap: 6px; flex-wrap: wrap; margin: calc(-1 * var(--sp-2)) 0 var(--sp-2); }
h2.report-section {
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 700;
  margin: var(--sp-6) 0 var(--sp-3); scroll-margin-top: var(--sp-4);
}
.report-note { margin-top: var(--sp-3); font-size: var(--fs-sm); color: var(--ink-3); }
.legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
svg text { font-family: var(--font); font-variant-numeric: tabular-nums; }
.viz-tip {
  position: fixed; z-index: 60; pointer-events: none;
  background: var(--surface); border: 1px solid var(--hairline-strong); border-radius: 8px;
  padding: 7px 11px; font-size: var(--fs-sm); box-shadow: var(--shadow-lg);
  color: var(--ink);
}

/* ==========================================================================
   Retire early (Reports › Retire early)
   ========================================================================== */
.fire-teaser { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); color: inherit; text-decoration: none; }
.fire-teaser .sub { margin-bottom: 0; }
.fire-teaser:hover { border-color: var(--hairline-strong); }
.fire-teaser:hover .btn { background: var(--surface-2); color: var(--ink); }
.fire-lede { color: var(--ink-2); max-width: 70ch; margin: calc(-1 * var(--sp-2)) 0 var(--sp-5); }
.fire-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 370px); gap: var(--sp-5); align-items: start; }
.fire-results, .fire-inputs { min-width: 0; }
.fire-inputs { position: sticky; top: var(--sp-4); padding: var(--sp-4) var(--sp-5); }
.fire-h { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 700;
  margin: var(--sp-5) 0 var(--sp-3); padding-top: var(--sp-4); border-top: 1px solid var(--hairline); }
.fire-h:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.fire-h .muted { text-transform: none; letter-spacing: 0; font-weight: 500; }
.fire-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--sp-3); }
.fire-field { margin-bottom: var(--sp-3); min-width: 0; }
.fire-field.fire-source { margin-top: calc(-1 * var(--sp-1)); }
.fire-lbl { display: block; color: var(--ink-2); font-size: var(--fs-sm); font-weight: 550; margin-bottom: 6px; }
.fire-in { display: flex; align-items: center; gap: var(--sp-2); }
.fire-in input { width: 100%; min-width: 0; font-variant-numeric: tabular-nums; }
.fire-suffix { color: var(--ink-3); font-size: var(--fs-sm); white-space: nowrap; }
.fire-src { color: var(--ink-3); font-size: var(--fs-xs); line-height: 1.45; margin-top: 5px; }
.fire-src:empty { display: none; }
.fire-src a { color: var(--accent-text); }
.fire-reset {
  background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-weight: 650;
  color: var(--accent-text); white-space: nowrap;
}
.fire-reset:hover { text-decoration: underline; }
.fire-real { margin: calc(-1 * var(--sp-1)) 0 var(--sp-3); font-size: var(--fs-xs); line-height: 1.45; }
.fire-accts { display: flex; flex-direction: column; gap: 2px; margin-bottom: var(--sp-2); }
.fire-acct { margin-bottom: 0; padding: 3px 0; font-size: var(--fs-sm); }
.fire-acct-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fire-acct .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.fire-acct-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: var(--sp-3); }
.fire-tiles { grid-template-columns: repeat(auto-fit, minmax(122px, 1fr)); }
.fire-status {
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: var(--sp-4); font-size: var(--fs-md); line-height: 1.5;
  border: 1px solid var(--hairline-strong); background: var(--surface-2); color: var(--ink);
}
.fire-status.good { background: var(--pos-bg); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.fire-status.bad { background: var(--danger-bg); border-color: var(--danger-border); }
.fire-status.warn { background: var(--banner-bg); border-color: var(--banner-border); }
.fire-empty h2 { margin-bottom: var(--sp-2); }
.fire-empty .sub { margin-bottom: 0; }
.fire-ways { margin: 0; }
.fire-ways dt { font-weight: 650; display: flex; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.fire-ways dd { margin: 4px 0 var(--sp-4); color: var(--ink-2); font-size: var(--fs-sm); line-height: 1.5; }
.fire-ways dd:last-child { margin-bottom: 0; }
.fire-way-amt { font-variant-numeric: tabular-nums; }
table.fire-sens { min-width: 420px; }
table.fire-sens td.num, table.fire-sens th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.fire-sens td.base { font-weight: 750; color: var(--accent-text); }
table.fire-sens th.base { color: var(--ink-2); }
.legend .swatch.line.dashed { background: none !important; height: 0; border-top: 2px dashed; border-radius: 0; vertical-align: 3px; }
.fire-disclaimer { color: var(--ink-3); font-size: var(--fs-sm); line-height: 1.5; max-width: 80ch; margin-top: var(--sp-2); }
@media (max-width: 1100px) {
  .fire-layout { grid-template-columns: minmax(0, 1fr); }
  .fire-inputs { position: static; }
  .fire-layout.needs-age .fire-inputs { order: -1; }
}
@media (max-width: 560px) {
  .fire-teaser { flex-direction: column; align-items: flex-start; }
  .fire-row { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Toast / empty
   ========================================================================== */
#toast-root {
  position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: var(--sp-2);
  width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  background: var(--surface); border: 1px solid var(--hairline-strong); border-radius: var(--radius);
  padding: 10px 16px; box-shadow: var(--shadow-lg); font-size: 13.5px;
  animation: g-rise .18s var(--ease);
}
.toast.error { border-color: var(--danger-border); color: var(--bad); background: color-mix(in srgb, var(--surface) 92%, var(--bad)); }
.empty {
  text-align: center; padding: 72px var(--sp-5); color: var(--ink-3);
}
.empty h2 { color: var(--ink-2); margin-bottom: var(--sp-2); font-size: var(--fs-lg); }

/* ==========================================================================
   Trends report
   ========================================================================== */
table.trends td { vertical-align: middle; }
table.trends .num { text-align: right; white-space: nowrap; }
table.trends svg { display: block; }

/* ==========================================================================
   Savings
   ========================================================================== */
/* "Savings waiting" pot, next to Ready to Assign on the budget screen */
.rta.pot {
  background: var(--accent-soft); color: var(--accent-text); text-decoration: none;
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  transition: border-color .12s var(--ease);
}
.rta.pot:hover { border-color: var(--accent); }
td.saved-cell { cursor: pointer; }
tr.cat-row td.saved-cell:hover {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 6px;
}
.saved-add { color: var(--ink-3); visibility: hidden; font-weight: 600; }
tr.cat-row:hover .saved-add { visibility: visible; }
.saved-in { font-size: var(--fs-xs); color: var(--good-text); font-weight: 600; }

/* log-a-saving and sweep dialogs */
.save-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--sp-3); }
.save-form .sv-memo { grid-column: 1 / -1; }
.save-list { margin-top: var(--sp-4); border-top: 1px solid var(--hairline); padding-top: var(--sp-3); }
.save-list-head { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); font-weight: 650; margin-bottom: var(--sp-2); }
.save-item {
  display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3);
  padding: 7px 0; border-bottom: 1px solid var(--grid);
}
.save-item:last-child { border-bottom: none; }
.save-item > div:first-child { min-width: 0; }
a.btn { text-decoration: none; }
.save-item .memo-sub { white-space: normal; max-width: none; }
.save-item-tools { display: flex; align-items: center; gap: var(--sp-1); flex-shrink: 0; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn:disabled:hover { background: none; color: var(--ink-3); }
#sw-explain { margin-top: -4px; }

/* Savings view */
.sweep-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3); flex-wrap: wrap; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tag.part { background: var(--part-bg); color: var(--banner-text); }
.held-item { border-top: 1px solid var(--hairline); padding: var(--sp-3) 0; display: grid; gap: 6px; }
.held-hit code { white-space: pre-wrap; word-break: break-word; }
.held-actions { display: flex; gap: var(--sp-2); margin-top: 2px; }
.dest-sub { font-size: 12px; color: var(--ink-3); font-weight: 400; white-space: normal; margin-top: 1px; }
table.sv-overview td.num .dest-sub { max-width: 260px; margin-left: auto; }
table.sv-overview .pill { min-width: 0; }
table.sweeps td { vertical-align: middle; }
table.sweeps td:first-child { white-space: nowrap; }
table.sweeps th:nth-child(2), table.sweeps th:nth-child(4) { text-align: left; }

/* entries grid: every cell is a real input so Tab walks it like a sheet */
table.sheet { min-width: 780px; }
table.sheet th { text-align: left; }
table.sheet th:nth-child(3) { text-align: right; }
table.sheet td { padding: 3px 4px; vertical-align: middle; }
table.sheet td.c-date { width: 150px; }
table.sheet td.c-cat { width: 170px; }
table.sheet td.c-amt { width: 112px; }
table.sheet td.c-fund { font-size: var(--fs-sm); color: var(--ink-2); padding-left: 10px; }
table.sheet td.c-swept { white-space: nowrap; font-size: var(--fs-sm); }
table.sheet td.c-del { width: 36px; text-align: center; }
table.sheet .cell {
  width: 100%; padding: 4px 7px; border-radius: 6px;
  background: transparent; border-color: transparent; box-shadow: none;
}
table.sheet .cell.amount { text-align: right; }
table.sheet tr:hover .cell { border-color: var(--hairline-strong); background: var(--surface); }
table.sheet .cell:focus {
  background: var(--surface); border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
table.sheet tr.sheet-add td { background: var(--accent-soft); padding-top: 7px; padding-bottom: 7px; }
table.sheet tr.sheet-add .cell { background: var(--surface); border-color: var(--hairline-strong); box-shadow: var(--shadow-sm); }
table.sheet tr.sheet-add .cell:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
table.sheet tbody tr[data-id] td { transition: background-color .4s var(--ease); }
table.sheet tr.saved-flash td { background: var(--pos-bg); transition: none; }
table.sheet tr[data-id] .icon-btn { visibility: hidden; }
table.sheet tr[data-id]:hover .icon-btn, table.sheet tr[data-id]:focus-within .icon-btn { visibility: visible; }

/* ==========================================================================
   Capital growth
   ========================================================================== */
.txn-growth { color: var(--good-text); font-weight: 550; }
.txn-growth.down { color: var(--bad); }
.growth-cat { color: var(--ink-3); font-size: var(--fs-sm); font-style: italic; padding: 0 6px; }
.growth-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.growth-tiles { margin-bottom: var(--sp-4); }
.growth-card .card-head { margin-bottom: var(--sp-4); }
.growth-card .card-head .sub { margin-bottom: 0; }
.stat-tile .tile-sub span { white-space: nowrap; }
.stat-tile .tile-sub { font-size: var(--fs-xs); color: var(--ink-3); margin-top: 4px; line-height: 1.35; }
.legend .swatch.dashed { background: none; border-top: 2px dashed; height: 0; width: 14px; border-radius: 0; vertical-align: 3px; }
.legend .swatch.line { height: 2px; width: 14px; border-radius: 1px; vertical-align: 3px; }
svg.nw-hover .nw-col:not(.on) { opacity: .45; }
table.growth-table { min-width: 560px; }
table.growth-table td:first-child a { color: var(--ink); text-decoration: none; font-weight: 550; }
table.growth-table td:first-child a:hover { color: var(--accent-text); }
table.growth-table td.num .memo-sub { margin-left: auto; }

/* ==========================================================================
   Budgets, sign-in, profile
   ========================================================================== */
.budget-switch {
  display: block; margin: calc(-1 * var(--sp-1)) var(--sp-3) var(--sp-2);
  width: calc(100% - 2 * var(--sp-3)); font-weight: 600; color: var(--ink);
}
div.budget-switch.single {
  padding: 6px 10px; border-radius: 8px; background: var(--surface-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#topbar-budget {
  margin-left: auto; padding-right: 6px; color: var(--ink-2); font-size: var(--fs-sm); font-weight: 600;
  max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

#login-root { display: none; }
body.logged-out #login-root {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: var(--sp-4);
}
body.logged-out #app, body.logged-out #topbar, body.logged-out #nav-backdrop { display: none !important; }
.login-card {
  width: 400px; max-width: 100%;
  background: var(--surface); border: 1px solid var(--hairline-strong); border-radius: 16px;
  padding: var(--sp-6); box-shadow: var(--shadow-lg);
  animation: g-rise .18s var(--ease);
}
.login-card .brand { padding: 0 0 var(--sp-2); }
.login-card .btn { width: 100%; }
.login-error { color: var(--bad); font-size: var(--fs-sm); min-height: 1.4em; margin: calc(-1 * var(--sp-2)) 0 var(--sp-2); }
.login-help { margin-top: var(--sp-4); line-height: 1.5; }
.google-g { width: 18px; height: 18px; flex: none; vertical-align: -3px; }
.btn.google-btn { gap: var(--sp-2); margin-bottom: var(--sp-3); }
.login-key summary { cursor: pointer; color: var(--ink-2); font-size: var(--fs-sm); margin-bottom: var(--sp-3); }
.google-row { margin-top: var(--sp-4); }
.google-row h3 { font-size: var(--fs-sm); color: var(--ink-2); margin: 0 0 var(--sp-2); }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em;
  background: var(--surface-2); padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere;
}
.inline-form { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.inline-form input[type=text] { flex: 1 1 200px; max-width: 320px; }
.profile-view .card-head > div { flex: 1 1 320px; min-width: 0; }
table.profile td { vertical-align: middle; }
table.profile input[type=text] { width: 100%; max-width: 280px; }
table.profile td.num { white-space: nowrap; }
.key-reveal { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.key-reveal input {
  flex: 1; min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px;
}

/* ==========================================================================
   Mobile
   ========================================================================== */
#topbar { display: none; }
#nav-backdrop { display: none; }

@media (max-width: 860px) {
  #topbar {
    display: flex; align-items: center; gap: var(--sp-1);
    position: sticky; top: 0; z-index: 45;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--hairline);
    padding: 6px 10px;
    padding-top: calc(6px + env(safe-area-inset-top));
  }
  #topbar .brand { padding: 0; font-size: 17px; }
  #topbar .brand-mark { width: 26px; height: 26px; font-size: 16px; border-radius: 8px; }
  #btn-menu {
    background: none; border: none; color: var(--ink); font-size: 22px;
    padding: 4px 10px; cursor: pointer; border-radius: 8px;
  }
  #btn-menu:hover { background: var(--surface-2); }
  #app { display: block; height: auto; min-height: calc(100vh - 45px); }
  #main { overflow: visible; }

  /* sidebar becomes a slide-in drawer */
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 280px; max-width: 85vw;
    z-index: 56; transform: translateX(-105%); transition: transform .2s var(--ease);
    box-shadow: var(--shadow-lg);
    padding-top: env(safe-area-inset-top);
  }
  body.nav-open #sidebar { transform: none; }
  body.nav-open #nav-backdrop, body.nav-drag #nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 55; background: var(--scrim);
  }
  body.nav-drag #sidebar { transition: none; } /* follows the finger */
  /* a sideways swipe opens the drawer; it must not make Chrome go back a page */
  html, body { overscroll-behavior-x: none; }

  .view { padding: var(--sp-4) var(--sp-3) 80px; max-width: none; }
  .view-header { gap: 10px; margin-bottom: var(--sp-4); }
  .view-header h1 { font-size: var(--fs-xl); }
  .month-nav .month-label { min-width: 0; font-size: 17px; }
  .period-head { min-width: 0; }
  .period-sub { white-space: normal; text-align: center; }
  .ps-pair { grid-template-columns: 1fr; gap: 0; }
  .rta { min-width: 0; padding: 8px 14px; }
  .rta .rta-amount { font-size: 18px; }
  .acct-stats { flex-wrap: wrap; gap: var(--sp-3) var(--sp-5); width: auto; padding: var(--sp-3) var(--sp-4); }
  .toolbar input[type=search] { width: 100%; }
  .memo-sub { max-width: 200px; }
  table.grid th, table.grid td { padding-left: 6px; padding-right: 6px; }
  .view > table.grid { border-radius: var(--radius); }
  .view > table.grid thead tr:first-child th:first-child { border-top-left-radius: var(--radius); }
  .view > table.grid thead tr:first-child th:last-child { border-top-right-radius: var(--radius); }
  .view > table.grid tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius); }
  .view > table.grid tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius); }
  table.register td.c-date { width: auto; font-size: 12px; }
  table.register td.c-acct { display: none; }
  table.register th.c-acct { display: none; }
  /* the All Accounts header cell has no c-acct class; hide it alongside its column */
  table.register:has(td.c-acct) thead th:first-child { display: none; }
  /* the register is wider than a phone: let it scroll inside its card, not the page */
  .view > table.register { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  select.cat-inline { min-width: 120px; }
  .report-card { padding: var(--sp-4); }
  h2.report-section { scroll-margin-top: 60px; } /* clear the sticky top bar */
  /* 16px inputs stop iOS Safari from zooming in on focus */
  input[type=text], input[type=date], input[type=search], select { font-size: 16px; }
  .modal { padding: var(--sp-5) var(--sp-4); }
  .modal-backdrop { padding: 4vh var(--sp-2); }
}

@media (max-width: 560px) {
  /* budget table: drop the Activity column, keep Assigned + Available */
  table.budget th:nth-child(3), table.budget td:nth-child(3) { display: none; }
  /* goals: keep #, Goal, Covered, Still needed; the bar shows progress */
  table.goals-page th:nth-child(3), table.goals-page td:nth-child(3),
  table.goals-page th:last-child, table.goals-page td:last-child { display: none; }
  table.goals-page th:nth-child(4), table.goals-page td:nth-child(4),
  table.goals-page th:nth-child(5), table.goals-page td:nth-child(5),
  table.goals-page th:nth-child(6):not(:last-child), table.goals-page td:nth-child(6):not(:last-child) { display: table-cell; }
  table.goals-page.what-if th:nth-child(5), table.goals-page.what-if td:nth-child(5) { display: none; } /* room for the what-if */
  table.goals-page th { white-space: normal; }
  table.goals-page td.goal-rank .goal-prio { display: flex; flex-direction: column; margin: 4px 0 0; }
  .goal-hint { display: block; margin-left: 0; }
  tr.cat-row .copy-prev { visibility: visible; }
  .pill { min-width: 0; }
  .cal-grid { gap: 3px; }
  .cal-cell, .cal-cell.empty { padding: 4px 5px; min-height: 52px; }
  .cal-total { font-size: 10px; }
  /* budget: Saved stays visible but tight; the pot sits beside RTA */
  table.budget td.saved-cell { font-size: 12.5px; }
  .saved-in-lbl { display: none; }
  /* four number columns on a phone: trim padding so the card fits 360px+ */
  table.budget th, table.budget td { padding-left: 4px; padding-right: 4px; }
  table.budget th:first-child, table.budget td:first-child { padding-left: 8px; }
  table.budget th:last-child, table.budget td:last-child { padding-right: 6px; }
  table.budget .pill { padding: 2px 7px; margin-right: 0; }
  table.budget th { letter-spacing: .04em; }
  table.budget .goal-hint { white-space: normal; }
  table.sv-overview { min-width: 540px; }
  table.sheet { min-width: 640px; }
  table.sheet td.c-date { width: 132px; }
  table.sheet td.c-cat { width: 140px; }
  table.sheet td.c-amt { width: 92px; }
  .saved-add { visibility: visible; opacity: .5; }
  .save-form { grid-template-columns: 1fr; }
  .sweep-actions { width: 100%; }
  .growth-actions { width: 100%; }
  .growth-actions .btn { flex: 1; }
  .sweep-actions .btn { flex: 1; }
  table.sheet tr[data-id] .icon-btn { visibility: visible; }
}

/* ==========================================================================
   Privacy mode: hide amounts
   ========================================================================== */
.btn.ghost.active { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
/* chart y-axis tick labels are plain numbers, not fmt() output — blur them */
:root.hide-amounts svg text.tick { filter: blur(4px); opacity: .5; }
/* …except Reports axes relabelled as a % of a base (pctAxis), which reveal no amounts */
:root.hide-amounts .pct-axis svg text.tick { filter: none; opacity: 1; }
/* amount inputs still show real values while editing (you asked to edit), but
   blur them until focused so a glance doesn't reveal them */
:root.hide-amounts input.amount:not(:focus) { filter: blur(4px); }

/* ==========================================================================
   Guilder Plus: locks, the Plus prompt and the over-the-limit cleanup
   ========================================================================== */
.plus-badge {
  display: inline-flex; align-items: center; vertical-align: middle;
  font: 650 10.5px/1.5 var(--font); letter-spacing: .02em;
  padding: 1px 8px; border-radius: 99px; cursor: pointer;
  background: var(--accent-soft); color: var(--accent-text);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.plus-badge::before { content: "✦"; margin-right: 4px; font-size: 9px; }
.plus-badge:hover { border-color: var(--accent); }
.plus-badge:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.checkline.locked { cursor: default; }
.checkline.locked > input { opacity: .55; }
.btn-with-badge { display: flex; align-items: center; gap: var(--sp-2); }
.profile-view .card-head > .btn-with-badge { flex: 0 0 auto; }
.plan-card .sub { margin-bottom: 0; }
.report-card.plus-locked { border-style: dashed; border-color: var(--hairline-strong); }
.report-card.plus-locked .sub { margin-bottom: 0; max-width: 60ch; }
.plus-locked h2 .plus-badge { margin-left: 6px; }
.banner.plus-banner { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--accent-text); }
.banner.plus-banner > span:first-of-type { flex: 1; }
td.assigned-cell.locked { cursor: not-allowed; color: var(--ink-3); }

/* the gate: a modal layer above the normal one */
.modal-backdrop.gate { z-index: 70; }
.plan-intro { margin: -8px 0 var(--sp-4); color: var(--ink-2); }
.plan-compare { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.plan-compare > div { border: 1px solid var(--hairline); border-radius: var(--radius); padding: var(--sp-3) var(--sp-4); }
.plan-compare > div:last-child { border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: var(--accent-soft); }
.plan-compare h3 { font-size: var(--fs-md); font-weight: 650; margin-bottom: var(--sp-2); }
.plan-compare ul { margin: 0; padding-left: 18px; color: var(--ink-2); font-size: var(--fs-sm); }
.plan-compare li { margin: 3px 0; }
.plan-choose > div { display: flex; flex-direction: column; gap: var(--sp-2); }
.plan-choose .plan-price b { font-size: var(--fs-lg); }
.plan-choose .btn { align-self: flex-start; margin-top: auto; }
.plan-note { font-size: var(--fs-sm); margin-top: var(--sp-3); }
.plan-sub { margin-top: var(--sp-2); }

.cleanup-sec { border-top: 1px solid var(--hairline); padding: var(--sp-4) 0 var(--sp-2); }
.cleanup-sec h3 { font-size: var(--fs-md); font-weight: 650; margin-bottom: var(--sp-1); }
.cleanup-sec > p { font-size: var(--fs-sm); margin-bottom: var(--sp-2); }
.cleanup-row {
  display: flex; gap: var(--sp-3); align-items: flex-start; justify-content: space-between; flex-wrap: wrap;
  padding: var(--sp-2) 0; border-top: 1px solid var(--grid);
}
.cleanup-row:first-of-type { border-top: 0; }
.cleanup-what { min-width: 160px; flex: 1 1 160px; }
.cleanup-what .subtle { font-size: var(--fs-sm); }
.cleanup-actions { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; justify-content: flex-end; flex: 1 1 280px; }
.cleanup-actions select { max-width: 220px; }
.cleanup-actions [hidden] { display: none; }
.cl-note { flex-basis: 100%; text-align: right; font-size: var(--fs-sm); color: var(--banner-text); }
.cl-note:empty { display: none; }
#f-close-note { text-align: left; margin-top: 6px; }
@media (max-width: 640px) {
  .plan-compare { grid-template-columns: 1fr; }
  .cleanup-actions { justify-content: flex-start; }
  .cl-note { text-align: left; }
}
