:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #d1d5db;
  --accent: #0f766e;
  --accent-hover: #115e59;
  --error-bg: #fef2f2;
  --error-text: #991b1b;
  --info-bg: #ecfdf5;
  --info-text: #065f46;
  --card-glass: rgba(255, 255, 255, 0.86);
  --bill-opacity: 0.28;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1114;
    --card: #151d22;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #2d3a42;
    --accent: #14b8a6;
    --accent-hover: #2dd4bf;
    --error-bg: #3b1214;
    --error-text: #fca5a5;
    --info-bg: #0f2e27;
    --info-text: #6ee7b7;
    --card-glass: rgba(21, 29, 34, 0.84);
    --bill-opacity: 0.16;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* beats .btn/.chip display rules */
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#bill-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: var(--bill-opacity);
  filter: saturate(0.6) sepia(0.15);  /* faded-photo look */
}

main {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
main.auth {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
main.app { max-width: 720px; margin: 0 auto; }

.card {
  width: 100%;
  max-width: 400px;
  background: var(--card-glass);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}
.card.wide { max-width: none; }

.brand { text-align: center; margin-bottom: 20px; }
.logo {
  display: inline-grid;
  place-items: center;
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 26px;
}
.logo.sm { width: 28px; height: 28px; font-size: 15px; border-radius: 8px; }
h1 { margin: 10px 0 0; font-size: 26px; }
h2 { margin: 0 0 6px; font-size: 21px; }
.muted { color: var(--muted); margin: 4px 0 18px; }
.small { font-size: 13px; margin-bottom: 0; }
code { font: 13px ui-monospace, Menlo, monospace; word-break: break-all; }

label { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; }
form > label:first-of-type { margin-top: 0; }
input {
  width: 100%;
  font-size: 16px; /* 16px stops iOS Safari from zooming on focus */
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

button {
  width: 100%;
  margin-top: 22px;
  padding: 13px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }
button.ghost {
  width: auto; margin: 0; padding: 8px 14px;
  background: transparent; color: var(--text);
  border: 1px solid var(--border);
}
button.ghost:hover { background: var(--card); }

.links {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
  font-size: 14px;
}
.links:has(> :only-child) { justify-content: center; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.flash {
  width: 100%;
  max-width: 400px;
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 14px;
}
main.app .flash { max-width: none; }
.flash-error { background: var(--error-bg); color: var(--error-text); }
.flash-info { background: var(--info-bg); color: var(--info-text); }

/* ---------- app pages ---------- */

:root {
  /* chart tokens: validated categorical palette (light) + chrome */
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --prior: #c3c2b7;
  --surface: #fcfcfb;
  --ink-1: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --grid: #e1e0d9;
  --up: #b42318;
  --down: #006300;
}
@media (prefers-color-scheme: dark) {
  :root {
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --prior: #5a5955;
    --surface: #1a1a19;
    --ink-1: #f0efec;
    --ink-2: #c3c2b7;
    --ink-muted: #898781;
    --grid: #2c2c2a;
    --up: #f97066;
    --down: #0ca30c;
  }
}

main.app { max-width: 1100px; padding-top: 16px; touch-action: pan-y; will-change: transform; }
/* These keep their own sideways scrolling inside a swipeable page. */
main.app .table-scroll, .nav-inner { touch-action: pan-x pan-y; }
body { overflow-x: hidden; }
main.app .card { margin-bottom: 16px; padding: 20px; }
main.app h3 { margin: 0 0 4px; font-size: 16px; }

.nav {
  position: sticky; top: 0; z-index: 2;
  background: var(--card-glass);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.nav-inner { max-width: 1100px; margin: 0 auto; display: flex; gap: 4px; padding: 8px 12px; overflow-x: auto; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 15px; white-space: nowrap; }
.nav a.on { color: var(--text); background: var(--bg); }
.nav a:hover { text-decoration: none; color: var(--text); }

.page-head { margin: 8px 0 16px; }
.page-head h1 { margin: 0; font-size: 26px; }
.page-head .muted { margin: 2px 0 0; }
.wordmark { letter-spacing: 0.12em; font-weight: 800; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 12px; }
.tile {
  background: var(--card-glass); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.tile-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.tile-value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.tile.hero .tile-value { font-size: 36px; }
.tile-value.small-value { font-size: 20px; }
.tile-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.delta { font-weight: 700; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }

.note { font-size: 14px; color: var(--muted); margin: 0 0 16px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 0 16px; }
.chart-box { position: relative; height: 240px; margin-top: 12px; }

.table-view { margin-top: 12px; font-size: 14px; }
.table-view summary { cursor: pointer; color: var(--accent); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { border-collapse: collapse; width: 100%; font-size: 14px; margin-top: 8px; }
table.data th, table.data td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tfoot td { font-weight: 700; border-bottom: 0; }
table.matrix .sticky { position: sticky; left: 0; background: var(--card); z-index: 1; }
.strong { font-weight: 700; }
.faint { color: var(--muted); font-size: 13px; }

.btn, a.btn {
  display: inline-block; width: auto; margin: 8px 0 0; padding: 10px 18px; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; border: 0; cursor: pointer;
}
a.btn:hover { text-decoration: none; background: var(--accent-hover); }
.btn.small { padding: 8px 14px; font-size: 14px; margin: 0; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }

.filters { padding: 14px 16px !important; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); font-size: 14px; color: var(--text); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip:hover { text-decoration: none; }
.filter-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filter-row label { margin: 0; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.filter-row label.grow { flex: 1 1 200px; }
select, .filter-row input {
  font-size: 16px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); width: auto;
}
/* Transactions filters: search across the top, then From | To | Filter on one line that never wraps. */
.tx-filter { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.filters:has(.cat-drop) { position: relative; z-index: 10; }   /* open category list sits above the list card */
.tx-filter .search { grid-column: 1; }
.tx-filter .dates-field { grid-column: 1 / -1; }
.date-drop { display: block; width: 100%; }
.cat-drop.date-drop summary { max-width: none; width: 100%; }
.date-panel { left: 0; right: auto; width: 100%; min-width: 260px; max-height: none;
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.date-panel .date-custom, .date-panel .cat-actions { grid-column: 1 / -1; }
.date-opt { display: block; padding: 9px 10px; border-radius: 8px; font-size: 15px; color: var(--text); white-space: nowrap; }
.date-opt:hover { text-decoration: none; background: var(--bg); }
.date-opt.on { background: var(--accent); color: #fff; font-weight: 600; }
.date-custom { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 4px 4px; border-top: 1px solid var(--border); margin-top: 4px; }
.date-custom label { min-width: 0; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; margin: 0; }
.cat-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); position: relative; }
.cat-drop summary {
  list-style: none; cursor: pointer; height: 38px; box-sizing: border-box; display: flex; align-items: center; gap: 6px;
  padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text);
  font-size: 16px; max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cat-drop summary::-webkit-details-marker { display: none; }
.cat-drop summary::after { content: "▾"; margin-left: auto; color: var(--muted); }
.cat-panel {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; width: 230px; max-height: 50dvh; overflow-y: auto;
  background: var(--card, var(--bg)); border: 1px solid var(--border); border-radius: 12px; padding: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.cat-opt { display: flex !important; flex-direction: row !important; align-items: center; gap: 10px; padding: 9px 8px;
  font-size: 15px !important; color: var(--text) !important; border-radius: 8px; }
.cat-opt input { width: 18px !important; height: 18px; margin: 0; accent-color: var(--accent); }
.cat-actions { position: sticky; bottom: -6px; background: var(--card); display: flex; justify-content: space-between; gap: 8px; padding: 8px 4px 6px; border-top: 1px solid var(--border); margin-top: 4px; }
.tx-filter input { width: 100%; min-width: 0; box-sizing: border-box; }
.tx-filter input[type=date] { -webkit-appearance: none; appearance: none; display: block; text-align: left; height: 38px; padding: 0 8px; }
.tx-filter .btn { height: 38px; align-self: end; }
select.warn { border-color: var(--series-2); }
.warn-text { color: var(--up); font-weight: 600; }

.tx-list { list-style: none; margin: 8px 0; padding: 0; }
.tx-list li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.tx-list li:last-child { border-bottom: 0; }
.tx-main { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.tx-merchant { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amt { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.tx-amt.pos { color: var(--down); }
.tx-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 2px; }
.tx-list.compact li { padding: 8px 0; }
.tx-cat { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.tx-cat select { font-size: 14px; padding: 6px 8px; }
.check { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 400; margin: 0; }
.check input { width: auto; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--border); color: var(--muted); }
.tx-line select { max-width: 100%; flex: 1 1 220px; }
.filed-check { display: inline-flex; align-items: center; gap: 8px; margin: 0; padding: 6px 12px; border-radius: 999px;
               border: 1px solid var(--accent); background: var(--bg); font-size: 14px; font-weight: 600; color: var(--text);
               cursor: pointer; }
.filed-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.tx-filed.unchecked .filed-check { border-style: dashed; color: var(--muted); }
.tx-filed.unchecked .filed-check span { text-decoration: line-through; }
.suggest { margin: 4px 0 0; }
/* Transactions tab: each row is one tap target that opens the transaction popup */
.tx-rows li { padding: 0; }
.tx-row { width: 100%; margin: 0; padding: 12px 4px; background: none; color: var(--text); text-align: left;
          display: flex; flex-direction: column; gap: 3px; border-radius: 8px; font-weight: 400; font-size: 15px; }
.tx-row:hover, .tx-row:focus-visible { background: var(--bg); }
.tx-row .tx-main { display: flex; justify-content: space-between; gap: 12px; }
.tx-row .tx-amt.neg { color: var(--up); }
.tx-filed-as { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.filed-line { font-weight: 600; color: var(--ink-2); }
.tx-note-text { margin: 4px 0 0; font-size: 13px; color: var(--ink-2); font-style: italic; }
.badge-file { border-color: var(--series-1); color: var(--series-1); font-weight: 600; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }

/* ---------- budget wheels ---------- */
:root { --st-good: #0ca30c; --st-warning: #fab219; --st-critical: #d03b3b; }

.tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 560px) {
  .tiles.three { gap: 8px; }
  .tiles.three .tile { padding: 12px; }
  .tiles.three .tile-value, .tiles.three .tile.hero .tile-value { font-size: 22px; }
  .tiles.three .tile-sub { font-size: 12px; }
}
a.tile-link { color: inherit; display: block; }
a.tile-link:hover { text-decoration: none; border-color: var(--accent); }

.section-title { font-size: 18px; margin: 24px 0 10px; }
.budget-card h2 { margin: 0; font-size: 20px; }
.budget-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.budget-hero { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; margin: 12px 0 4px; }
.budget-facts { display: grid; grid-template-columns: repeat(2, minmax(110px, auto)); gap: 10px 28px; margin: 0; }
.budget-facts dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.budget-facts dd { margin: 2px 0 0; font-size: 22px; font-weight: 700; }
.budget-facts dd.neg { color: var(--st-critical); }
.budget-facts .wide-fact { grid-column: 1 / -1; }
.budget-facts .wide-fact dd { font-size: 15px; font-weight: 600; }

.ring { display: block; }
.ring-lg { width: 180px; height: 180px; }
.ring-sm { width: 104px; height: 104px; margin: 0 auto; }
.ring circle { fill: none; stroke-width: 9; }
.ring-lg circle { stroke-width: 8; }
.ring-track { stroke: var(--grid); }
.ring-a { stroke: var(--series-1); }
.ring-b { stroke: var(--series-2); }
.ring-tick { stroke: var(--ink-1); stroke-width: 2; }
.ring-num { font-size: 15px; font-weight: 700; text-anchor: middle; fill: var(--ink-1); }
.ring-lg .ring-num { font-size: 14px; }
.ring-sub { font-size: 9px; text-anchor: middle; fill: var(--ink-muted); }
.ring-none { display: grid; place-items: center; border-radius: 50%; border: 9px solid var(--grid); font-weight: 700; }

.ring-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 12px 0 4px; }
.ring-legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.sw-a { background: var(--series-1); }
.sw-b { background: var(--series-2); }
.sw-tick { width: 2px; height: 12px; background: var(--ink-1); border-radius: 0; }

.ring-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 12px; }
@media (max-width: 560px) { .ring-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } }
.ring-cell {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px;
  padding: 12px 8px; border: 1px solid var(--border); border-radius: 12px; color: inherit;
}
.ring-cell:hover { text-decoration: none; border-color: var(--accent); }
.ring-name { font-weight: 700; font-size: 14px; margin-top: 6px; }
.ring-meta { font-size: 13px; color: var(--muted); }
.ring-today { font-size: 13px; font-weight: 600; color: var(--ink-1); }
.ring-today::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--series-2); margin-right: 5px; }

.status { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.status > span { font-size: 13px; }
.st-good > span { color: var(--st-good); }
.st-warning > span { color: var(--st-warning); }
.st-critical > span { color: var(--st-critical); }
.st-muted { color: var(--muted); font-weight: 400; }

.budget-table input { width: 110px; text-align: right; font-size: 16px; padding: 6px 8px; }

/* ---------- plan ---------- */
.month-head { display: flex; align-items: center; gap: 12px; }
.month-head h1 { margin: 0; }
.muted-year { color: var(--muted); font-weight: 600; }
.month-step { font-size: 28px; line-height: 1; padding: 4px 12px; border-radius: 8px; color: var(--text); }
.month-step:hover { text-decoration: none; background: var(--card-glass); }

.balance p { margin: 0; }
.balance { border-left: 4px solid var(--border); }
.balance.ok { border-left-color: var(--st-good); }
.balance.under { border-left-color: var(--st-warning); }
.balance.over { border-left-color: var(--st-critical); }
.balance.ok .b-icon { color: var(--st-good); }
.balance.under .b-icon { color: var(--st-warning); }
.balance.over .b-icon { color: var(--st-critical); }
.plan-hint { margin: -4px 0 12px; }
.grip-demo { letter-spacing: -2px; font-weight: 700; }

.month-title { width: auto; margin: 0; padding: 4px 10px; background: none; color: var(--text); font-size: 26px;
               font-weight: 800; border-radius: 10px; }
.month-title:hover { background: var(--card-glass); }
.caret { font-size: 14px; color: var(--muted); }
.jumps { display: flex; gap: 8px; margin: -6px 0 12px; flex-wrap: wrap; }
.chip.strong, .btn.strong { font-weight: 700; }
.jumps:empty { display: none; }

.group-head { display: grid; grid-template-columns: 32px 1fr auto; gap: 10px; align-items: center; cursor: pointer; -webkit-tap-highlight-color: transparent; user-select: none; }
.group-toggle { width: 32px; height: 32px; margin: 0; padding: 0; border-radius: 8px; background: var(--bg);
                color: var(--text); border: 1px solid var(--border); font-size: 20px; font-weight: 700; line-height: 1; }
.budget-ring { flex: none; display: block; }
.group-ring { width: 64px; height: 64px; }
.cat-ring { width: 52px; height: 52px; }
.line-ring { width: 52px; height: 52px; }      /* same as the sub-category rings (e.g. Home Expenses) */
.line .line-planned { padding: 0; margin: 0; border: 0; border-radius: 50%; line-height: 0; }
.budget-ring circle { fill: none; stroke-width: 6; }
.gr-track { stroke: var(--grid); }
.gr-arc { stroke: var(--down); stroke-linecap: round; transition: stroke-dasharray 0.3s ease; }
.budget-ring.over .gr-arc { stroke: var(--st-critical); }
.budget-ring.empty .gr-arc { display: none; }        /* nothing used yet: just the track, no stray dot */
.line .line-planned:hover, .line .line-planned:focus { background: none; border-color: transparent; }
.line .line-planned:focus-visible .gr-track { stroke: var(--accent); }
.gr-num { font-size: 11px; letter-spacing: -0.2px; font-weight: 800; text-anchor: middle; fill: var(--ink-1); font-variant-numeric: tabular-nums; }
.group-sum { text-align: right; font-size: 12px; color: var(--muted); line-height: 1.5; }
.group-sum strong { font-size: 15px; color: var(--text); font-variant-numeric: tabular-nums; }
.group-body { margin-top: 4px; }
.group-card.collapsed .group-body { display: none; }
.cat-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.cat-sum { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.group-name { font-size: 20px; font-weight: 800; color: var(--text); }
.group-name span { color: var(--muted); }
.cat-num { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; display: flex; flex-direction: column; }
.cat-num small, .line-left small { font-weight: 400; font-size: 11px; color: var(--muted); }
.cat-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-top: 10px; background: var(--card); }
.cat-name { font-weight: 700; color: var(--text); }
a.cat-name:hover { color: var(--accent); }

.line-list { list-style: none; margin: 6px 0 0; padding: 0; min-height: 28px; }
/* Name on the left; numbers stacked compactly on the right (planned over received/left),
   which leaves most of the row's width for the name. */
.line {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 4px 10px; align-items: center;
  padding: 8px 0 6px; border-top: 1px solid var(--border);
}
.line-nums { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.line-nums .line-planned { padding: 2px 6px; margin-right: -6px; }
.line-nums .line-left { font-size: 12px; color: var(--muted); display: block; text-align: right; white-space: nowrap; }
.line-nums .line-left.neg { color: var(--st-critical); }
.line-name { width: auto; margin: 0; padding: 4px 6px; background: none; color: var(--text); font-size: 16px;
             font-weight: 400; text-align: left; border-radius: 6px; border: 1px solid transparent; overflow-wrap: anywhere; }
.line-name:hover { border-color: transparent; background: none; }   /* no box on hover: clicking still opens the line */
.line-name-edit { font-size: 16px; padding: 4px 6px; }
.grip {
  width: 22px; margin: 0; padding: 6px 0; background: none; color: var(--muted); font-weight: 700;
  letter-spacing: -2px; cursor: grab; touch-action: none; border-radius: 4px;
}
.grip:hover { background: var(--bg); color: var(--text); }
.line-planned {
  width: auto; margin: 0; padding: 6px 8px; background: none; color: var(--accent); font-weight: 600;
  font-variant-numeric: tabular-nums; border: 1px solid transparent; border-radius: 8px;
}
.line-planned:hover { background: var(--bg); border-color: var(--border); }
.line-left { text-align: right; font-variant-numeric: tabular-nums; display: flex; flex-direction: column; }
.line-left.neg { color: var(--st-critical); font-weight: 600; }
.line-bar { grid-column: 2 / -1; height: 4px; border-radius: 2px; background: var(--grid); overflow: hidden; }
.line-bar i { display: block; height: 100%; width: 0; background: var(--series-1); border-radius: 2px; }
.line-bar i.over { background: var(--st-critical); }
.unplanned { font-size: 13px; margin: 8px 0 0; }
.add-line { display: flex; gap: 8px; margin-top: 8px; }
.add-line input { flex: 1; font-size: 15px; padding: 7px 10px; }
/* "+ Add … category" at the bottom of each section, set apart from the item boxes inside cards */
.add-category { display: flex; gap: 8px; margin-top: 12px; padding: 10px; border: 1px dashed var(--accent);
                border-radius: 12px; }
.add-category input { flex: 1; font-size: 15px; padding: 8px 10px; font-weight: 600; }
.add-category input::placeholder { color: var(--accent); }
.filing .add-category, .filing .add-line { visibility: hidden; }

.line-dragging { display: none; }
.line-holder { border: 2px dashed var(--accent); border-radius: 8px; list-style: none; margin: 4px 0; opacity: 0.6; }
.line-ghost {
  position: fixed; z-index: 50; pointer-events: none; background: var(--card); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); padding: 8px 10px; list-style: none; border: 1px solid var(--accent);
}
body.dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }

/* amount picker: a bottom sheet with digit wheels */
.sheet { border: 0; padding: 0; border-radius: 18px 18px 0 0; width: 100%; max-width: 480px; margin: auto auto 0;
         background: var(--card); color: var(--text); }
@media (min-width: 600px) { .sheet { border-radius: 18px; margin: auto; } }
.sheet::backdrop { background: rgba(0, 0, 0, 0.4); }
.sheet-inner { padding: 16px 16px max(16px, env(safe-area-inset-bottom)); }
/* Popups fit the screen you can actually see (dvh follows Safari's address bar showing or
   hiding), scroll inside themselves when taller, and never pass the scroll to the page behind. */
.sheet { max-height: calc(100vh - 12px); max-height: calc(100dvh - 12px); overflow-y: auto;
         overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
html.modal-open, html.modal-open body { overflow: hidden; }
.sheet h3 { margin: 0 0 10px; font-size: 17px; }
.sheet-input { display: flex; align-items: center; gap: 6px; font-size: 28px; font-weight: 700; margin: 0 0 10px; }
.sheet-input input { font-size: 28px; font-weight: 700; padding: 6px 10px; }
.wheels { position: relative; display: flex; justify-content: center; align-items: center; gap: 2px; height: 180px;
          -webkit-mask-image: linear-gradient(transparent, #000 30%, #000 70%, transparent);
          mask-image: linear-gradient(transparent, #000 30%, #000 70%, transparent); }
.wheels::before { content: ""; position: absolute; left: 0; right: 0; top: 72px; height: 36px; border-radius: 8px;
                  background: var(--bg); z-index: 0; }
.wheel { position: relative; z-index: 1; width: 34px; height: 180px; overflow-y: scroll; scroll-snap-type: y mandatory;
         padding: 72px 0; box-sizing: border-box; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.wheel::-webkit-scrollbar { display: none; }
.wheel-cell { height: 36px; line-height: 36px; text-align: center; font-size: 22px; font-weight: 600;
              scroll-snap-align: center; font-variant-numeric: tabular-nums; }
.wheel-sep { position: relative; z-index: 1; font-size: 22px; font-weight: 700; width: 10px; text-align: center; }
.year-row { display: flex; align-items: center; justify-content: space-between; }
.year-row h3 { margin: 0; font-size: 20px; }
.year-strip { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0; scrollbar-width: none; touch-action: pan-x; }
.year-strip::-webkit-scrollbar { display: none; }
.year-strip .chip { width: auto; margin: 0; background: none; color: var(--text); font-weight: 600; }
.year-strip .chip.on { background: var(--accent); color: #fff; }
.month-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 6px 0 10px; }
.month-cell { padding: 12px 0; text-align: center; border-radius: 10px; border: 1px solid var(--border); color: var(--muted); }
.month-cell.has-plan { color: var(--text); font-weight: 700; }
.month-cell.now { border-color: var(--accent); }
.month-cell.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.month-cell:hover { text-decoration: none; background: var(--bg); }
.month-cell.on:hover { background: var(--accent-hover); }
/* amount slider */
.slider { width: 100%; margin: 14px 0 4px; height: 36px; accent-color: var(--accent); touch-action: pan-x; }
.slider-scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted);
                font-variant-numeric: tabular-nums; }

/* ---------- tray of new transactions + filing ---------- */
main.app.has-tray { padding-bottom: 190px; }
/* Just the bubbles floating over the budget: no bar behind them, and the gaps between
   bubbles let taps through to the page. */
.tray {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 8px 0 max(10px, env(safe-area-inset-bottom)); pointer-events: none;
}
.tray .tray-scroll, .tray .tray-close { pointer-events: auto; }   /* swipes anywhere on the strip scroll it */
.tray[hidden], .file-fab[hidden] { display: none; }
/* The single "to file" bubble; tapping it fans out the transactions. */
.file-fab {
  position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 20;
  width: 68px; height: 68px; margin: 0; padding: 0; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1;
  background: var(--accent); color: #fff; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
}
.file-fab:hover { background: var(--accent-hover); }
.file-fab { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.file-fab.moving { transform: scale(1.12); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35); cursor: grabbing; }
.fab-plus { font-size: 38px; font-weight: 400; line-height: 1; margin-top: -3px; }
.add-bubble .b-circle { border: 2.5px dashed var(--accent); color: var(--accent); }
.b-plus { font-size: 30px; line-height: 1; color: var(--accent); }
.add-bubble .b-name { color: var(--accent); }
.fab-count { font-size: 24px; font-weight: 800; }
.fab-label { font-size: 10px; font-weight: 600; margin-top: 3px; }
.tray-close {
  display: block; width: 40px; height: 40px; margin: 4px auto 0; padding: 0; border-radius: 50%;
  background: var(--bg); color: var(--text); border: 1px solid var(--border); font-size: 18px; font-weight: 700;
}
.tray-close:hover { background: var(--card); }
.tray-scroll { display: flex; gap: 10px; overflow-x: auto; padding: 4px 16px; scroll-snap-type: x proximity;
               scrollbar-width: none; touch-action: pan-x; overscroll-behavior-x: contain; }
.tray-scroll::-webkit-scrollbar { display: none; }
.bubble {
  flex: 0 0 84px; width: 84px; margin: 0; padding: 0; background: none; color: var(--text);
  display: flex; flex-direction: column; align-items: center; scroll-snap-align: start;
  touch-action: pan-x; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.bubble:hover, .bubble:focus, .bubble:active { background: none; outline: none; }
.bubble:focus-visible .b-circle { box-shadow: 0 0 0 3px var(--accent); }
.bubble.sel { touch-action: none; }      /* sideways moves now paint the selection instead of scrolling */
/* Inside each bubble: small date, bold amount, short vendor. Red = money out, green = money in. */
.b-circle {
  width: 80px; height: 80px; border-radius: 50%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 1px; padding: 0 6px; text-align: center; line-height: 1.15;
  background: var(--card); border: 2.5px solid var(--border); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: transform 0.12s ease;
}
.b-date { font-size: 10px; color: var(--ink-1); }
.b-amt { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bubble.neg .b-amt { color: var(--up); }
.bubble.pos .b-amt { color: var(--down); }
.b-name { font-size: 10.5px; font-weight: 600; color: var(--ink-1); max-width: 62px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bubble.sel .b-circle { background: var(--bg); box-shadow: 0 0 0 3px var(--series-1); transform: scale(1.05); }
.b-circle { position: relative; }
.bubble.sel .b-circle::after { content: "✓"; position: absolute; top: -4px; right: -4px; width: 18px; height: 18px;
  border-radius: 50%; background: var(--ink-1); color: var(--surface); font-size: 11px; display: grid; place-items: center; }

/* While dragging transactions the budget stays exactly as it is on screen; only the target lights up. */
body.filing { user-select: none; -webkit-user-select: none; }
.filing .group-card.collapsed.peek .group-body { display: block; }
.filing .cat-card { transition: border-color 0.1s; }
.filing .cat-card.drop-cat { border-color: var(--accent); }
.filing .line.drop-target { background: var(--bg); box-shadow: inset 4px 0 0 var(--accent), 0 0 0 2px var(--accent); border-radius: 6px; }
.filing .grip { visibility: hidden; }
.fly {
  position: fixed; z-index: 60; pointer-events: none; transform: translate(-50%, -110%);
  display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px;
  background: var(--series-1); color: #fff; font-weight: 800; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.fly-count { background: #fff; color: var(--series-1); border-radius: 999px; min-width: 22px; height: 22px;
             display: grid; place-items: center; font-size: 12px; padding: 0 6px; }

/* transaction detail popup */
.tx-top { display: grid; grid-template-columns: 34px 1fr; gap: 6px 10px; align-items: center; margin-bottom: 4px; }
.tx-top h3 { margin: 0; }
.tx-close { width: 36px; height: 36px; margin: 0; padding: 0; border-radius: 50%; background: var(--bg);
            color: var(--text); border: 1px solid var(--border); font-size: 16px; font-weight: 700; }
.kind-toggle { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; padding: 4px;
               background: var(--bg); border-radius: 12px; border: 1px solid var(--border); }
.kind-toggle label { margin: 0; }
.kind-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.kind-toggle span { display: block; text-align: center; padding: 6px; border-radius: 9px; font-weight: 700;
                    font-size: 15px; color: var(--muted); cursor: pointer; }
.kind-toggle input:checked + span { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.kind-toggle input[value=expense]:checked + span { color: var(--up); }
.kind-toggle input[value=income]:checked + span, .kind-toggle input[value=return]:checked + span { color: var(--down); }
.kind-toggle input:focus-visible + span { outline: 2px solid var(--accent); }
.tx-section { border-top: 1px solid var(--border); padding: 8px 0 2px; }
.tx-section h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.tx-section h4 label { margin: 0; font-size: inherit; font-weight: inherit; }
.tx-details { margin: 0; display: grid; gap: 6px; }
.tx-details div { display: grid; grid-template-columns: 90px 1fr; gap: 10px; }
.tx-details dt { color: var(--muted); font-size: 14px; }
.tx-details dd { margin: 0; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
#tx-note { width: 100%; font-size: 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
           background: var(--bg); color: var(--text); font-family: inherit; resize: vertical; }
/* line item popup */
.line-sheet .sheet-inner { padding-bottom: 0; }
.line-where { margin: 0; font-size: 14px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.field-label { display: block; margin: 0 0 6px; font-size: 12px; font-weight: 600; color: var(--muted);
               text-transform: uppercase; letter-spacing: 0.06em; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.amount-status { font-size: 12px; font-weight: 700; color: var(--down); }
.amount-status.err { color: var(--st-critical); }
.line-title-input { font-size: 22px; font-weight: 800; padding: 8px 10px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.activity-sum { text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--ink-2); }
.activity { list-style: none; margin: 0 0 8px; padding: 0; }
.activity li.muted { padding: 8px 0; }
.act-row {
  width: 100%; margin: 0; padding: 10px 4px; background: none; color: var(--text); text-align: left;
  display: grid; grid-template-columns: 52px 1fr auto; gap: 2px 10px; align-items: baseline;
  border-top: 1px solid var(--border); border-radius: 0; font-weight: 400;
}
.activity li:first-child .act-row { border-top: 0; }
.act-row:hover { background: var(--bg); }
.act-date { font-size: 13px; color: var(--ink-1); }
.act-who { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act-amt { font-weight: 800; font-variant-numeric: tabular-nums; }
.act-amt.neg { color: var(--up); }
.act-amt.pos { color: var(--down); }
.act-sub { grid-column: 2 / -1; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.line-actions { display: grid; grid-template-columns: auto 1fr; gap: 10px; }
.line-actions .btn { width: auto; }
.line-actions .btn:last-child { width: 100%; }

/* Save stays on screen however long the popup gets. */
.tx-actions { position: sticky; bottom: 0; margin: 8px -16px 0; padding: 8px 16px max(10px, env(safe-area-inset-bottom));
              background: var(--card); border-top: 1px solid var(--border); }
.tx-sheet .sheet-inner { padding-bottom: 0; }
.tx-actions .btn { width: 100%; margin: 0; padding: 10px; font-size: 15px; }
.tx-actions { display: grid; gap: 6px; }
.tx-actions .btn.small { padding: 7px; font-size: 13px; }
.tx-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.tx-fields label { margin: 0; font-size: 12px; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.tx-fields input { font-size: 16px; padding: 7px 9px; width: 100%; min-width: 0; }
.tx-fields label { min-width: 0; }
.tx-fields input[type=date] { -webkit-appearance: none; appearance: none; display: block; text-align: left; }   /* iOS gives dates a fixed min width */
.amt-wrap { display: flex; align-items: center; gap: 4px; }
.amt-sign { font-size: 18px; font-weight: 800; color: var(--ink-1); }
#tx-amount { font-size: 20px; font-weight: 800; }
#tx-amount.neg { color: var(--up); }
#tx-amount.pos { color: var(--down); }
.split-list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 6px; }
.split-list li { display: grid; grid-template-columns: 1fr auto 32px; gap: 8px; align-items: center;
                 padding: 8px 10px; border: 1px solid var(--accent); border-radius: 10px; background: var(--bg); }
.split-list li:has(> :only-child), .split-list li:not(:has(input)) { grid-template-columns: 1fr 32px; }
.split-name { font-weight: 600; overflow-wrap: anywhere; }
.split-list input { width: 110px; font-size: 16px; padding: 6px 8px; text-align: right; }
.split-remove { width: 32px; height: 32px; margin: 0; padding: 0; border-radius: 50%; background: none; color: var(--muted);
                border: 1px solid var(--border); font-size: 18px; }
.split-left { margin: 0 0 8px; font-size: 13px; font-weight: 700; }
.split-left.ok { color: var(--down); }
.split-left.off { color: var(--up); }
.line-results { list-style: none; margin: 6px 0 0; padding: 0; border-radius: 10px; overflow: hidden; }
.line-results:not(:empty) { border: 1px solid var(--border); }
.line-results li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; cursor: pointer;
                   border-top: 1px solid var(--border); }
.line-results li:first-child { border-top: 0; }
.line-results li span { color: var(--muted); font-size: 13px; text-align: right; }
.line-results li:hover, .line-results li:focus { background: var(--bg); outline: none; }
.line-results li.none { color: var(--muted); cursor: default; }
#tx-search { width: 100%; font-size: 16px; padding: 10px 12px; }

.undo-toast {
  position: fixed; left: 50%; bottom: 200px; transform: translateX(-50%); z-index: 70;
  display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; border-radius: 999px;
  background: var(--ink-1); color: var(--surface); font-weight: 600; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3); max-width: calc(100vw - 32px);
}
.undo-toast[hidden] { display: none; }
.undo-toast .btn { background: var(--surface); color: var(--ink-1); }

.sheet-move { display: flex; align-items: center; gap: 10px; margin: 12px 0 0; font-size: 14px; font-weight: 600; }
.sheet-move select { flex: 1; }
.sheet-error { color: var(--st-critical); font-size: 14px; min-height: 1em; margin: 8px 0 0; }
.sheet-actions { display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px; margin-top: 8px; }
.sheet-actions .btn { margin: 0; }

/* ---------- group insights ---------- */
.seg-tabs { display: flex; gap: 4px; padding: 4px; background: var(--card-glass); border: 1px solid var(--border);
            border-radius: 12px; overflow-x: auto; margin-bottom: 8px; }
.seg-tabs a { flex: 1; text-align: center; padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.seg-tabs a.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
.seg-tabs a:hover { text-decoration: none; color: var(--text); }
.insight-hero { text-align: center; }
.sub-tabs { margin-bottom: 10px; }
.sub-tabs + .seg-tabs a { font-size: 14px; padding: 6px 10px; }
.hero-total { font-size: 40px; font-weight: 800; }
.trend-line { display: inline-block; margin: 14px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--bg);
              font-weight: 600; text-align: left; }
.chart-box.tall { height: 320px; }
.crumbs { margin: 4px 0 8px; }
.chart-ranges { justify-content: center; margin: 16px 0 0; }
.readout { min-height: 1.4em; margin: 8px 0 4px; font-size: 14px; font-weight: 600; color: var(--ink-1); }
.html-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 6px 0 4px; }
.lg-chip, .lg-more {
  width: auto; margin: 0; display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; font-size: 13px;
  font-weight: 500; color: var(--ink-2); background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
}
.lg-chip:hover, .lg-more:hover { background: var(--card); }
.lg-chip.extra { display: none; }
.html-legend.open .lg-chip.extra { display: inline-flex; }
.lg-chip.off { opacity: 0.45; text-decoration: line-through; }
.lg-chip.hl { border-color: var(--ink-1); color: var(--ink-1); font-weight: 700; box-shadow: 0 0 0 1px var(--ink-1); }
.lg-box { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.lg-line { width: 14px; height: 2px; display: inline-block; }
.lg-more { color: var(--accent); font-weight: 600; }
.breakdown { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 16px; }
.bd-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.bd-head h3 a { color: var(--text); }
.bd-total { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.share { height: 6px; border-radius: 3px; background: var(--grid); margin: 8px 0 6px; overflow: hidden; }
.share-fill { display: block; height: 100%; width: 0; background: var(--series-1); border-radius: 3px; }
.bd-line { font-size: 14px; margin: 0 0 8px; color: var(--ink-2); }
.bd-grid { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: start; }
.bd-spark svg { width: 120px; height: 28px; display: block; }
.bd-spark polyline { fill: none; stroke: var(--series-1); stroke-width: 2; vector-effect: non-scaling-stroke; }
.bd-facts { list-style: none; margin: 0; padding: 0; font-size: 13px; color: var(--ink-2); display: grid; gap: 3px; }
.neg { color: var(--st-critical); }

form.stack label { margin-top: 12px; }
input[type="file"] { padding: 10px; }

/* Line popup envelope: what's left, how much is used, and where an even pace would be today. */
.envelope { padding-top: 4px; }
.env-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.env-left { font-size: 26px; font-weight: 800; color: var(--down); font-variant-numeric: tabular-nums; }
.env-left.over { color: var(--up); }
.env-of { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.env-bar { position: relative; height: 14px; border-radius: 7px; background: var(--border); margin-bottom: 18px; }
.env-bar i { display: block; height: 100%; width: 0; border-radius: 7px; background: var(--down); transition: width .3s ease, background .3s; }
.env-bar i.ahead { background: var(--series-4); }
.env-bar i.over { background: var(--up); }
.env-bar b { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--text); border-radius: 1px; }
.env-bar b span { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 2px;
  font-size: 10px; font-weight: 600; color: var(--muted); }

/* Pending (from an alert, not on a statement yet) vs completed: pending rows get an amber edge,
   an amber badge and a softer amount, so the settled ones read as final. */
.tx-row.is-pending { box-shadow: inset 3px 0 0 var(--series-4); padding-left: 12px; }
.tx-row.is-pending .tx-amt { opacity: .65; font-style: italic; }
.badge-pending { border-color: var(--series-4); color: var(--series-4); font-weight: 700; }

/* Another month's purchase while a different month's budget is on screen. */
.bubble.other-month .b-circle { border: 2px dashed var(--series-4); }
.bubble.other-month .b-date { color: var(--series-4); font-weight: 800; }
.month-warn { margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; font-size: 13px; font-weight: 600;
  color: var(--series-4); background: color-mix(in srgb, var(--series-4) 12%, transparent); }
.undo-toast.warn { box-shadow: inset 4px 0 0 var(--series-4); }

/* Budget month in the transaction popup, and the tag on a row that counts in another month. */
.bm-row { display: flex !important; flex-direction: row !important; align-items: center; gap: 10px; margin-top: 10px;
  font-size: 13px; color: var(--muted); }
.bm-pick { position: relative; flex: 1; }
.bm-btn { width: 100%; margin: 0; text-align: left; font-size: 16px; font-weight: 600; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.bm-panel { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30; padding: 8px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card); box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
.bm-year { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-weight: 800; color: var(--text); font-size: 15px; }
.bm-year button { margin: 0; padding: 4px 14px; font-size: 20px; background: none; color: var(--text); border: 0; }
.bm-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.bm-grid button { margin: 0; padding: 9px 0; font-size: 14px; font-weight: 600; border-radius: 8px; border: 0;
  background: var(--bg); color: var(--text); }
.bm-grid button.on { background: var(--accent); color: #fff; }
.month-warn { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.month-warn[hidden] { display: none; }
.month-warn .btn { margin: 0; white-space: nowrap; }
.badge-month { border-color: var(--series-1); color: var(--series-1); font-weight: 600; }
.badge-split { border-color: var(--series-7); color: var(--series-7); font-weight: 600; }
.tx-actions:has(#tx-delete:not([hidden])) { grid-template-columns: auto 1fr; }
#tx-delete { color: var(--up); border-color: var(--up); padding: 10px 18px; }

/* Transactions tab: New / Filed / Deleted views, Pending as an extra filter, deleted rows. */
.view-chips { gap: 5px; flex-wrap: nowrap; }
.view-chips .chip { padding: 6px 10px; white-space: nowrap; }
.chip-filter { border-style: dashed; }
.chip-filter.on { border-style: solid; }
.deleted-row > * { min-width: 0; }
.deleted-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; align-items: center; padding: 12px 4px !important; }
.deleted-row .tx-main, .deleted-row .tx-meta { grid-column: 1; }
.deleted-row .tx-amt { opacity: .6; text-decoration: line-through; }
.restore-btn { grid-column: 2; grid-row: 1 / span 2; margin: 0; }

/* Desktop (a Mac with a mouse or trackpad, a wide window): the phone sizes read small on a big
   screen, so text, rings and bubbles step up. Phones and touch iPads keep the sizes above. */
@media (hover: hover) and (pointer: fine) and (min-width: 900px) {
  body { font-size: 18px; }
  main.app.plan-page, main.app.tx-page { max-width: 880px; }   /* keeps rings close to their names */
  main.app h3 { font-size: 19px; }
  .nav a { font-size: 17px; padding: 9px 14px; }
  .month-title { font-size: 34px; }
  .plan-hint { font-size: 15px; }
  .group-ring { width: 96px; height: 96px; }
  .cat-ring, .line-ring { width: 80px; height: 80px; }
  .gr-num { font-size: 12px; }                  /* in ring units: as big as "$16.2k" still fits inside */
  .group-name { font-size: 28px; }
  .cat-name { font-size: 20px; }
  .line-name { font-size: 19px; }
  .b-circle { width: 96px; height: 96px; }
  .b-date { font-size: 12px; }
  .b-amt { font-size: 18px; }
  .b-name { font-size: 12.5px; max-width: 76px; }
  .sheet { max-width: 560px; font-size: 17px; }
  .env-left { font-size: 32px; }
  .env-of { font-size: 15px; }
  .tx-row, .tx-list li { font-size: 17px; }
  .tx-meta { font-size: 15px; }
  .chip { font-size: 16px; }
  .filter-row label, .cat-field { font-size: 14px; }
}

/* Transactions search: an × inside the box to clear it. */
.search-wrap { position: relative; display: block; }
.search-wrap input { padding-right: 40px !important; }
.search-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 20px; line-height: 1;
  color: var(--muted); background: var(--border); }
.search-clear:hover { text-decoration: none; color: var(--text); }
.search-clear[hidden] { display: none; }

/* Fund lines: a small tag by the name; in the popup, the switch, the opening amount and the math. */
/* Fund lines: an envelope with a $100 bill peeking out, before the name. */
.fund-icon { display: inline-block; flex: none; width: 24px; height: 24px; margin-right: 8px; margin-top: -1px; }
/* A wrapped name lines up under its first word, not under the icon. */
.line-name { display: inline-flex; align-items: flex-start; }
.line-name .ln-text { min-width: 0; }
.fund-icon svg { width: 100%; height: 100%; display: block; overflow: visible; }
.fi-bill { fill: #3f9a52; stroke: #2c7a3d; stroke-width: .8; }
.fi-seal { fill: none; stroke: #d9f2dd; stroke-width: .9; }
.fi-back { fill: var(--card); stroke: var(--text); stroke-width: 1.3; stroke-linejoin: round; }
.fi-front { fill: var(--card); stroke: var(--text); stroke-width: 1.3; stroke-linejoin: round; }
.fi-flap-open { fill: var(--card); stroke: var(--text); stroke-width: 1.4; stroke-linejoin: round; }
.fi-pocket { fill: none; stroke: var(--text); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }

@media (hover: hover) and (pointer: fine) and (min-width: 900px) { .fund-icon { width: 31px; height: 31px; margin-right: 10px; margin-top: -3px; } }
.env-fund-math { margin: -6px 0 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.fund-switch { display: flex !important; flex-direction: row !important; align-items: center; gap: 10px; font-size: 15px;
  font-weight: 600; color: var(--text); margin: 0; }
.fund-switch input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.fund-opening { margin-top: 10px; }
.fund-opening label { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; color: var(--muted); margin: 0; }
.sheet-input.small { font-size: 16px; max-width: 150px; }
.sheet-input.small input { font-size: 16px; padding: 6px 8px; }

/* Rings only where they mean the most: on line items, and on a closed section. An open section
   and its sub-categories show a plain total instead (red once over). */
.sum-total { font-size: 20px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sum-total.over { color: var(--up); }
.cat-head .sum-total { font-size: 17px; }
.group-sum { display: flex; align-items: center; }
.group-card .group-sum .sum-total { display: none; }
.group-card:not(.collapsed) .group-sum .group-ring { display: none; }
.group-card:not(.collapsed) .group-sum .sum-total { display: inline; }
@media (hover: hover) and (pointer: fine) and (min-width: 900px) {
  .sum-total { font-size: 24px; }
  .cat-head .sum-total { font-size: 20px; }
}

/* Budgeted / Spent / Left: what the numbers in the rings and totals show. */
.ring-mode { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; margin: 4px 0 10px;
  border-radius: 12px; background: var(--card-glass); border: 1px solid var(--border); }
.ring-mode button { margin: 0; padding: 7px 0; border: 0; border-radius: 9px; background: none; color: var(--muted);
  font-size: 15px; font-weight: 700; }
.ring-mode button:hover { background: none; color: var(--text); }
.ring-mode button[aria-checked=true] { background: var(--accent); color: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
@media (hover: hover) and (pointer: fine) and (min-width: 900px) { .ring-mode button { font-size: 17px; padding: 9px 0; } }

/* The word under a ring's number says which view is on (budgeted / spent / left); the rings and
   totals are the switch. */
.gr-mode { font-size: 7px; font-weight: 700; text-anchor: middle; fill: var(--muted); letter-spacing: .2px; }
.line-planned, .group-sum, .cat-head .sum-total { cursor: pointer; }

/* Income received beyond the plan: a second line in the banner. */
.balance .b-extra { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
.balance .b-extra .b-icon { color: var(--down); font-weight: 800; }
.env-head { flex-wrap: wrap; }
.env-of { white-space: normal; }

/* Spending sub-categories: −/+ like the sections; closed shows the ring, open shows the total. */
.cat-head.cat-toggleable { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; cursor: pointer;
  -webkit-tap-highlight-color: transparent; user-select: none; }
.cat-toggle { width: 26px; height: 26px; margin: 0; padding: 0; border-radius: 7px; font-size: 16px; font-weight: 800;
  line-height: 1; background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.cat-toggle:hover { background: var(--bg); }
.cat-sum { display: flex; align-items: center; cursor: pointer; }
.cat-card .cat-sum .cat-ring { display: none; }
.cat-card.collapsed .cat-sum .cat-ring { display: block; }
.cat-card.collapsed .cat-sum .sum-total { display: none; }
.cat-card.collapsed .line-list, .cat-card.collapsed .unplanned, .cat-card.collapsed .add-line { display: none; }
.filing .cat-card.collapsed.peek .line-list { display: block; }
@media (hover: hover) and (pointer: fine) and (min-width: 900px) {
  .cat-head.cat-toggleable { grid-template-columns: 34px 1fr auto; }
  .cat-toggle { width: 32px; height: 32px; font-size: 19px; }
}

/* Long press on a section header: a quick flash at each step (sub-categories, then the section). */
.group-head { -webkit-touch-callout: none; }
.group-head.lp-flash { animation: lp-flash .35s ease; border-radius: 10px; }
@keyframes lp-flash { 0% { background: color-mix(in srgb, var(--accent) 28%, transparent); } 100% { background: transparent; } }
/* Holding a header must not select its text (Safari needs the -webkit- form). */
.group-head, .group-head *, .cat-head, .cat-head * {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}

/* Line popup: this month's income still to plan, under the amount. */
.left-to-plan { margin: 4px 0 6px; font-size: 14px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.left-to-plan.over { color: var(--up); }
.left-to-plan.done { color: var(--down); }
@media (hover: hover) and (pointer: fine) and (min-width: 900px) { .left-to-plan { font-size: 16px; } }

/* Planned amount: − slider + ; the amount pulses on each round-number tick. */
.slider-row { display: grid; grid-template-columns: 44px 1fr 44px; gap: 10px; align-items: center; margin-top: 10px; }
.slider-row .slider { margin: 0; }
.nudge { width: 44px; height: 44px; margin: 0; padding: 0; border-radius: 50%; font-size: 24px; font-weight: 700; line-height: 1;
  background: var(--bg); color: var(--text); border: 1px solid var(--border); touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.nudge:hover { background: var(--bg); }
.nudge:active { background: var(--accent); color: #fff; border-color: var(--accent); }
.haptic { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.sheet-input.tick input { animation: amt-tick .18s ease; }
@keyframes amt-tick { 50% { transform: scale(1.04); } }

/* Line popup: past spending on the line (last month, same month last year, 12-month average). */
.past-spend { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 6px 0 4px; }
.past-spend > div { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--border); min-width: 0; }
.ps-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.ps-val { font-size: 16px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (hover: hover) and (pointer: fine) and (min-width: 900px) { .ps-label { font-size: 12px; } .ps-val { font-size: 18px; } }

/* Upload tab: alert emails that looked like purchases but couldn't be read. */
.unreadable { margin-top: 14px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--series-4);
  background: color-mix(in srgb, var(--series-4) 8%, transparent); }
.unreadable h4 { margin: 0 0 4px; color: var(--series-4); }

/* Sign-in pages and the nav's Sign out. */
.login-card { max-width: 380px; margin: 12vh auto 0; }
.nav-signout { margin: 0 0 0 auto; }
.nav-out { margin: 0; padding: 8px 12px; background: none; color: var(--muted); font-weight: 600; font-size: 15px; border: 0; white-space: nowrap; }
.nav-out:hover { background: none; color: var(--text); }
/* Passkey buttons */
.passkey-btn { width: 100%; margin: 14px 0 6px; padding: 14px; font-size: 17px; font-weight: 700; }
.passkey-msg { min-height: 1.2em; margin: 4px 0; font-size: 14px; color: var(--muted); }
.passkey-msg.err { color: var(--up); }

/* Returns: link a refund to its purchase; a purchase lists its returns. */
.ret-chip { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--accent); background: var(--bg); }
.ret-go { flex: 1; width: 100%; margin: 0; padding: 6px 2px; background: none; border: 0; color: var(--text); text-align: left;
  display: grid; grid-template-columns: 1fr auto; gap: 0 8px; align-items: center; }
.ret-go:hover { background: none; }
.ret-label { grid-column: 1; font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.ret-what { grid-column: 1; font-size: 15px; font-weight: 600; }
.ret-arrow { grid-column: 2; grid-row: 1 / span 2; font-size: 24px; color: var(--accent); }
.ret-list li { border-bottom: 1px solid var(--border); }
.ret-hint { margin: 6px 0 2px; font-size: 13px; color: var(--muted); }
.tx-role { margin-left: 8px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.tx-role.is-refund { color: var(--down); border: 1px solid var(--down); }
.tx-role.is-purchase { color: var(--up); border: 1px solid var(--up); }
.ret-go:hover { background: none; text-decoration: underline; }
.ret-suggestion { width: 100%; margin: 0 0 8px; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; text-align: left;
  padding: 10px 12px; border-radius: 10px; border: 1px dashed var(--accent); background: none; color: var(--text); }
.ret-suggestion span { grid-column: 1; font-size: 12px; color: var(--muted); }
.ret-suggestion strong { grid-column: 1; font-size: 15px; }
.ret-suggestion em { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-style: normal; font-weight: 800; color: var(--accent); }
.ret-suggestion:hover { background: var(--bg); }
.ret-list { list-style: none; margin: 0; padding: 0; }
.ret-kept { margin: 6px 0 0; font-size: 14px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.badge-return { border-color: var(--down); color: var(--down); font-weight: 600; }

/* Budget tab: pull down to check for new transactions (Safari's own pull-to-reload is off here). */
html:has(main.plan-page), html:has(main.plan-page) body,
html:has(main.tx-page), html:has(main.tx-page) body { overscroll-behavior-y: none; }
.ptr { height: 0; overflow: hidden; display: flex; align-items: flex-end; justify-content: center; gap: 8px;
  padding-bottom: 8px; font-size: 14px; font-weight: 600; color: var(--muted); transition: height .2s ease; }
.ptr-icon { display: inline-block; transition: transform .2s; }
.ptr.ready .ptr-icon { transform: rotate(180deg); color: var(--accent); }
.ptr.busy .ptr-icon { animation: ptr-spin 1s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* Upload tab: clear alert errors. */
.alert-error { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.alert-error form, .unreadable-row form { margin: 0; }
.clear-x { width: 30px; height: 30px; margin: 0; padding: 0; border-radius: 50%; font-size: 18px; line-height: 1;
  background: none; color: var(--muted); border: 1px solid var(--border); flex: none; }
.clear-x:hover { background: var(--bg); color: var(--text); }
.unreadable-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.unreadable-actions { display: flex; gap: 8px; margin-top: 8px; }
.unreadable-actions form { margin: 0; }
