/* fintrack — design system.
   Dark by default because that is what a money app gets checked in at night;
   the light palette is a full swap, not an afterthought. */

:root {
  --bg: #0a0c11;
  --surface: #12151d;
  --surface-2: #191d27;
  --surface-3: #212633;
  --line: #262c3a;
  --line-soft: #1c212c;
  --text: #e9ecf3;
  --text-dim: #a2abbd;
  --muted: #6f7891;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, .14);
  --good: #34c98b;
  --good-soft: rgba(52, 201, 139, .14);
  --bad: #f4626a;
  --bad-soft: rgba(244, 98, 106, .14);
  --warn: #eba53c;
  --warn-soft: rgba(235, 165, 60, .14);

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .5);

  --header-h: 60px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f2f4f8;
  --surface-3: #e8ecf3;
  --line: #dee3ec;
  --line-soft: #eaeef5;
  --text: #10141c;
  --text-dim: #4a5468;
  --muted: #78829a;
  --accent: #2f6bf0;
  --accent-soft: rgba(47, 107, 240, .10);
  --good: #12a46b;
  --good-soft: rgba(18, 164, 107, .10);
  --bad: #dc3b45;
  --bad-soft: rgba(220, 59, 69, .10);
  --warn: #c67d10;
  --warn-soft: rgba(198, 125, 16, .10);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .18);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }

/* Money and dates line up column-wise only with tabular figures. */
.num, .stat, table td.num, table th.num { font-variant-numeric: tabular-nums; }

/* ── Privacy ────────────────────────────────────────────────────────────────
   One class on <body> hides every figure at once. Blur rather than a mask so
   the layout never moves and the shape of the page stays familiar; the value
   is unreadable but you can still see where it is. */

.sensitive {
  transition: filter .18s ease;
}

body.private .sensitive {
  filter: blur(7px);
  /* Stops a shoulder-surfer copy-pasting what they cannot read. */
  user-select: none;
  pointer-events: none;
}

body.private .sensitive-soft { filter: blur(4px); }

/* ── Header ─────────────────────────────────────────────────────────────── */

header.app {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--header-h);
  padding: 0 18px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -.02em;
  white-space: nowrap;
}

.brand .mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(140deg, var(--accent), #8f6bff);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

nav.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  margin-left: 6px;
}
nav.tabs::-webkit-scrollbar { display: none; }

nav.tabs button {
  flex: 0 0 auto;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
}
nav.tabs button:hover { color: var(--text); background: var(--surface-2); }
nav.tabs button.active { color: var(--text); background: var(--surface-3); }

.spacer { flex: 1 1 auto; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn svg { width: 17px; height: 17px; display: block; }
.icon-btn.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.who {
  color: var(--muted);
  font-size: 13px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */

main { padding: 22px 18px 64px; max-width: 1240px; margin: 0 auto; }
section { display: none; }
section.active { display: block; animation: rise .22s ease; }

@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.grid { display: grid; gap: 14px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.wide { grid-column: 1 / -1; }
.stack { display: grid; gap: 14px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px;
  min-width: 0;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.panel-head h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  font-weight: 600;
}

.panel-head .hint { font-size: 12px; color: var(--muted); text-transform: none; letter-spacing: 0; }

/* A heading that is the user's own words, not a fixed label — so it keeps the
   capitalisation they typed rather than being shouted in uppercase. */
.panel-head .card-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
  text-transform: none;
  color: var(--text);
}

/* ── Hero + stats ───────────────────────────────────────────────────────── */

.hero {
  background:
    radial-gradient(120% 140% at 0% 0%, var(--accent-soft), transparent 58%),
    var(--surface);
}

.hero .stat {
  font-size: clamp(30px, 6vw, 42px);
  font-weight: 680;
  letter-spacing: -.03em;
  line-height: 1.1;
  margin-top: 2px;
}

.stat { font-size: 24px; font-weight: 650; letter-spacing: -.02em; }
.stat.sm { font-size: 21px; }
.sub { color: var(--muted); font-size: 12.5px; margin-top: 5px; }

.split {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-dim);
}
.split b { font-weight: 600; color: var(--text); }

.pos { color: var(--good); }
.neg { color: var(--bad); }

.delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}
.delta.up { background: var(--good-soft); color: var(--good); }
.delta.down { background: var(--bad-soft); color: var(--bad); }

/* ── Charts ─────────────────────────────────────────────────────────────── */

.chart { width: 100%; overflow: hidden; }
.chart svg { display: block; width: 100%; height: auto; }
svg .axis { stroke: var(--line-soft); stroke-width: 1; }
svg .zero { stroke: var(--line); stroke-width: 1; }
svg .label { fill: var(--muted); font-size: 10.5px; font-family: var(--font); }
svg .line { fill: none; stroke: var(--accent); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
svg .dot { fill: var(--accent); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }

/* ── Tables ─────────────────────────────────────────────────────────────── */

.scroll-x { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }

.t-main { font-weight: 500; }
.t-sub { color: var(--muted); font-size: 12px; margin-top: 1px; }

/* ── Forms ──────────────────────────────────────────────────────────────── */

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 11px;
  border-radius: var(--r-sm);
  font: inherit;
  font-size: 13.5px;
  min-width: 0;
}
input::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

label.field { display: grid; gap: 5px; font-size: 12px; color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 13px;
  border-radius: var(--r-sm);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .12s ease, background .12s ease;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.btn:disabled:hover { border-color: var(--line); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: 5px 9px; font-size: 12.5px; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); background: var(--bad-soft); }
.btn.ghost { background: transparent; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}

/* ── Bits ───────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 1.5px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
  background: var(--surface-2);
}
.badge.transfer { color: var(--accent); border-color: transparent; background: var(--accent-soft); }
.badge.edited { color: var(--warn); border-color: transparent; background: var(--warn-soft); }
.badge.rule { color: var(--good); border-color: transparent; background: var(--good-soft); }

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-dim);
}

.bar { height: 7px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s ease; }
.bar > span.over { background: var(--bad); }
.bar > span.near { background: var(--warn); }

/* ── Chart tooltips ─────────────────────────────────────────────────────── */

.chart { position: relative; }

.chart-tip {
  position: absolute;
  top: 10px;
  z-index: 5;
  pointer-events: none;
  min-width: 160px;
  padding: 9px 11px;
  border-radius: var(--r);
  background: var(--surface-3);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 12.5px;
  margin-left: 10px;
}
.chart-tip .tip-head { font-weight: 650; margin-bottom: 5px; font-size: 13px; }
.chart-tip .tip-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 1px 0;
  color: var(--text-dim);
}
.chart-tip .tip-row i { width: 8px; height: 8px; border-radius: 2px; flex: 0 0 auto; }
.chart-tip .tip-row b { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; }
.chart-tip .tip-foot { margin-top: 5px; color: var(--muted); font-size: 11.5px; }

svg .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; }
svg .focus { fill: var(--accent); stroke: var(--surface); stroke-width: 2.5; opacity: 0; }
svg .dot { fill: var(--accent); opacity: .75; }

/* ── Spending bars ──────────────────────────────────────────────────────── */

.spend-row {
  display: grid;
  grid-template-columns: minmax(120px, 1.1fr) 3fr auto 52px;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}
.spend-row:hover { background: var(--surface-2); }
.spend-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spend-bar { height: 9px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.spend-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.spend-amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.spend-pct { text-align: right; color: var(--muted); font-size: 12px; }

/* ── Budget bars, with a marker for where the month is ──────────────────── */

.bar.with-mark { position: relative; overflow: visible; }
.bar.with-mark > span { position: relative; z-index: 1; }
.bar.with-mark > em {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--text-dim);
  border-radius: 2px;
  z-index: 2;
}

.dot-good { color: var(--good); }
.dot-warn { color: var(--warn); }
.dot-bad { color: var(--bad); }

.callout.warn { background: var(--warn-soft); }
.callout.bad { background: var(--bad-soft); }
.notice.bad { border-color: var(--bad); color: var(--bad); background: var(--bad-soft); }

/* ── Budget history ─────────────────────────────────────────────────────── */

.hist-row {
  display: grid;
  grid-template-columns: minmax(120px, 200px) 1fr;
  gap: 16px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}
.hist-row:last-child { border-bottom: 0; }
.hist-bars {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 62px;
}
.hist-bar { flex: 1 1 0; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.hist-bar > i { display: block; background: var(--accent); border-radius: 3px 3px 0 0; }
.hist-bar > i.over { background: var(--bad); }
.hist-bar > em { font-style: normal; font-size: 10px; color: var(--muted); text-align: center; padding-top: 3px; }
.hist-limit {
  position: absolute;
  left: 0; right: 0;
  height: 0;
  border-top: 1px dashed var(--muted);
  opacity: .7;
  margin-bottom: 16px;
}

/* ── Rules ──────────────────────────────────────────────────────────────── */

.rule-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}
.rule-row:last-child { border-bottom: 0; }
.rule-order {
  flex: 0 0 auto;
  min-width: 30px;
  text-align: center;
  padding: 2px 6px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.rule-text { flex: 1 1 auto; min-width: 0; font-size: 13.5px; line-height: 1.5; }

.preview-list { margin-top: 9px; border-top: 1px solid var(--line); padding-top: 7px; }
.preview-item {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 12px;
  padding: 3px 0;
  font-size: 12.5px;
}
.preview-item > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-item b { font-variant-numeric: tabular-nums; }

/* ── Transfer candidates ────────────────────────────────────────────────── */

.cand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
}
.cand-row:last-child { border-bottom: 0; }

/* Which cells belong to which layout. Kept as classes rather than duplicated
   markup so a row is one row in the DOM at every width. */
.phone-only { display: none; }

@media (max-width: 760px) {
  .desktop-only { display: none !important; }
  .phone-only { display: inline; }
  .spend-row { grid-template-columns: 1fr auto; gap: 4px 10px; }
  .spend-bar { grid-column: 1 / -1; order: 3; }
  .spend-pct { display: none; }
  .hist-row { grid-template-columns: 1fr; gap: 8px; }
  .preview-item { grid-template-columns: 1fr auto; }
  .preview-item > span:nth-child(3) { display: none; }
  .chart-tip { min-width: 130px; font-size: 12px; }
}

/* Row actions are noise on every row at rest; a pointer reveals them. Never
   hidden on touch, where there is no hover to reveal anything with, and never
   hidden from the keyboard. */
@media (hover: hover) and (min-width: 761px) {
  td[data-col="actions"] .btn { opacity: 0; transition: opacity .12s ease; }
  tr:hover td[data-col="actions"] .btn,
  td[data-col="actions"] .btn:focus-visible { opacity: 1; }
  /* Expanders are not row actions — they are the only way to see what is
     inside a group, so they stay visible whether or not anything is hovered. */
  td[data-col="actions"] .btn.js-expand { opacity: 1; }
}

.muted { color: var(--muted); }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.empty {
  color: var(--muted);
  padding: 34px 20px;
  text-align: center;
  font-size: 13.5px;
}
.empty strong { display: block; color: var(--text-dim); font-weight: 600; margin-bottom: 4px; }

.notice {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 12px 14px;
  color: var(--text-dim);
  font-size: 12.5px;
}

.callout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: var(--r);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.callout h3 { font-size: 14px; margin-bottom: 3px; }
.callout p { margin: 0; font-size: 13px; color: var(--text-dim); }

/* Toast — errors and confirmations, bottom-centre so it never covers the nav. */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(8px);
  z-index: 60;
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: var(--r);
  font-size: 13.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
  border: 1px solid var(--line);
  background: var(--surface-3);
  color: var(--text);
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.toast.ok { background: var(--good-soft); border-color: var(--good); color: var(--good); }

/* Skeletons, so a slow query looks like loading rather than emptiness. */
.skel {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
  border-radius: 6px;
  height: 13px;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  margin-right: 7px;
  background: var(--muted);
}
.status-dot.active { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.status-dot.connecting { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); animation: pulse 1.4s ease infinite; }
.status-dot.error { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
@keyframes pulse { 50% { opacity: .35; } }

/* ── Auth gate ──────────────────────────────────────────────────────────── */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(80% 60% at 50% -10%, var(--accent-soft), transparent 70%),
    var(--bg);
}

.gate-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 26px;
  box-shadow: var(--shadow);
}
.gate-card .brand { margin-bottom: 18px; font-size: 17px; }
.gate-card h1 { font-size: 19px; }
.gate-card > .sub { margin: 4px 0 20px; font-size: 13.5px; }
.gate-card label.field { margin-bottom: 13px; }
.gate-card input { width: 100%; padding: 10px 12px; font-size: 14px; }
.gate-card .btn { width: 100%; padding: 11px; margin-top: 8px; font-size: 14px; }

.switch { margin-top: 16px; text-align: center; font-size: 13px; color: var(--muted); }
.switch button {
  background: none; border: 0; color: var(--accent);
  cursor: pointer; font: inherit; padding: 0; font-weight: 500;
}

.form-err {
  background: var(--bad-soft);
  border: 1px solid var(--bad);
  color: var(--bad);
  padding: 9px 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  margin-bottom: 14px;
}

/* ── Mobile ─────────────────────────────────────────────────────────────── */

/* One-handed reach beats a header on a phone, so navigation moves to a bottom
   bar below 760px. Two separate <nav>s rather than one that moves, because the
   header's backdrop-filter would capture a position:fixed child — and because
   the phone needs fewer destinations than the desktop, not the same ones
   squeezed. */
nav.mobile-tabs, .sheet { display: none; }

@media (max-width: 760px) {
  main { padding: 16px 12px calc(84px + env(safe-area-inset-bottom)); }
  .panel { padding: 15px; border-radius: var(--r); }
  header.app { padding: 0 12px; gap: 8px; }
  .who { display: none; }
  nav.desktop-tabs { display: none; }
  /* Theme and sign-out live in the sheet on a phone; the header keeps the two
     things worth reaching for mid-glance. */
  header.app #theme, header.app #logout { display: none; }

  nav.mobile-tabs {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: calc(64px + env(safe-area-inset-bottom));
    padding: 0 4px env(safe-area-inset-bottom);
    gap: 0;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
    z-index: 40;
  }
  nav.mobile-tabs button {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 64px;
    padding: 0 2px;
    border-radius: 0;
    background: none;
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 500;
    line-height: 1.1;
  }
  nav.mobile-tabs button svg { width: 22px; height: 22px; display: block; }
  nav.mobile-tabs button span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  nav.mobile-tabs button.active { color: var(--accent); background: none; }
  /* The dot marks the current destination without stealing a row of height. */
  nav.mobile-tabs button.active::after {
    content: "";
    position: absolute;
    top: 6px;
    width: 4px; height: 4px;
    border-radius: 999px;
    background: var(--accent);
  }
  nav.mobile-tabs button { position: relative; }

  /* ── The More sheet ───────────────────────────────────────────────────── */

  .sheet { display: block; position: fixed; inset: 0; z-index: 50; }
  .sheet[hidden] { display: none; }

  .sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    animation: fade .16s ease;
  }

  .sheet-panel {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    background: var(--surface);
    border-top: 1px solid var(--line);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: 8px 14px calc(18px + env(safe-area-inset-bottom));
    box-shadow: 0 -12px 40px -12px rgba(0, 0, 0, .5);
    animation: slide-up .2s cubic-bezier(.2, .8, .3, 1);
  }

  .sheet-grab {
    display: block;
    width: 44px; height: 5px;
    margin: 4px auto 14px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--line);
    cursor: pointer;
  }

  .sheet-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .sheet-grid button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    /* Comfortably past the 44px minimum, because this is the one place every
       secondary destination is reached from. */
    min-height: 84px;
    padding: 12px 6px;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: var(--surface-2);
    color: var(--text-dim);
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
  }
  .sheet-grid button svg { width: 22px; height: 22px; }
  .sheet-grid button.active {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-soft);
  }

  .sheet-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line-soft);
  }
  .sheet-actions .btn { flex: 1 1 0; justify-content: center; min-height: 44px; }
  .sheet-actions .btn svg { width: 17px; height: 17px; }
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: none; }
}

@media (max-width: 760px) {
  /* Tables become stacked rows — a 5-column grid is unreadable at 380px.
     Name and amount share the top line, everything else stacks under it. */
  table.stackable thead { display: none; }
  table.stackable tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 6px 10px;
    padding: 12px 2px;
    border-bottom: 1px solid var(--line-soft);
  }
  table.stackable tbody tr:hover { background: none; }
  table.stackable td { border: 0; padding: 0; min-width: 0; }
  table.stackable td[data-col="name"] { grid-column: 1; grid-row: 1; }
  table.stackable td[data-col="amount"] {
    grid-column: 2; grid-row: 1;
    text-align: right;
    font-weight: 600;
    font-size: 14px;
  }
  table.stackable td[data-col="date"] { grid-column: 1 / -1; font-size: 12px; }
  /* Category and its actions share the second line rather than taking one
     each — at ~30 rows a screen that is a whole extra scroll saved. */
  table.stackable td[data-col="meta"] { grid-column: 1; }
  table.stackable td[data-col="actions"] { grid-column: 2; justify-self: end; }
  table.stackable td[data-col="actions"]:empty { display: none; }
  /* Section headers inside the balances table keep their own single-cell row. */
  table.stackable td[colspan] { grid-column: 1 / -1; }
  table.stackable select { max-width: 190px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Grouped transfers: one row per recurring movement, its months folded under it. */
tr.group-head td { border-bottom-color: var(--line); }
tr.group-child td { padding-top: 5px; padding-bottom: 5px; font-size: 12.5px; }
tr.group-child td.indent { padding-left: 22px; }

/* Goal trend: a sparkline of the real balance beside what it implies. */
.goal-trend {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}
.goal-trend > div { flex: 1 1 180px; min-width: 0; }
svg.spark { flex: 0 0 auto; overflow: visible; }

/* ── Loan projection ────────────────────────────────────────────────────── */

.loan-block {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.loan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.loan-grid .t-main { font-size: 15px; font-weight: 600; margin-top: 1px; }

.loan-outcome {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}
.loan-what-if { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.loan-what-if .field { margin: 0; }

.saved-note {
  flex: 1 1 100%;
  background: var(--good-soft);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text-dim);
}
.saved-note strong { color: var(--good); }
.saved-note.muted { background: var(--surface-2); }

.loan-months { margin-top: 14px; border-top: 1px solid var(--line-soft); padding-top: 10px; }
.loan-months summary {
  cursor: pointer;
  font-size: 12.5px;
  color: var(--muted);
  list-style: none;
}
.loan-months summary::-webkit-details-marker { display: none; }
.loan-months summary::before { content: "▸ "; }
.loan-months[open] summary::before { content: "▾ "; }
.loan-months summary:hover { color: var(--text); }
.loan-months .field { max-width: 130px; }

/* ── Installed as an app ────────────────────────────────────────────────────
   Launched from a home screen the page owns the whole screen, including the
   area behind the status bar and the home indicator. Nothing else changes —
   it is the same app, not a separate mobile build. */

body.installed header.app {
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
}
body.installed main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

/* No text selection on a chrome-less app: a long press should feel like a
   press, not a drag-select. Inputs and figures keep theirs. */
body.installed { -webkit-touch-callout: none; }
body.installed nav.tabs button, body.installed .icon-btn { -webkit-user-select: none; user-select: none; }
