/* One stylesheet, light and dark chosen separately rather than inverted, with
   the report's validated palette so both read as one product. Text never wears
   a series color. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6e69;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --hover: rgba(11, 11, 11, 0.045);
  --baseline: #8f8e88;
  --accent: #1f66bd;
  --accent-ink: #ffffff;
  --accent-wash: rgba(42, 120, 214, 0.12);
  --good: #006300;
  --bad: #b3261e;
  --warn-bg: #fff6df;
  --warn-ink: #6b4c00;
  --s0: #2a78d6; --s1: #eb6834; --s2: #1baf7a; --s3: #eda100;
  --s4: #e87ba4; --s5: #008300; --s6: #4a3aa7; --s7: #e34948;
  --other: #b9b8b1;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #9c9b95;
    --grid: #2c2c2a; --axis: #383835; --baseline: #7d7c77;
    --border: rgba(255, 255, 255, 0.10); --hover: rgba(255, 255, 255, 0.06);
    --accent: #3987e5; --accent-ink: #0b0b0b; --accent-wash: rgba(57, 135, 229, 0.18);
    --good: #0ca30c; --bad: #e66767;
    --warn-bg: #3a2f12; --warn-ink: #f3d58a;
    --s0: #3987e5; --s1: #d95926; --s2: #199e70; --s3: #c98500;
    --s4: #d55181; --s5: #008300; --s6: #9085e9; --s7: #e66767;
    --other: #55544f;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #9c9b95;
  --grid: #2c2c2a; --axis: #383835; --baseline: #7d7c77;
  --border: rgba(255, 255, 255, 0.10); --hover: rgba(255, 255, 255, 0.06);
  --accent: #3987e5; --accent-ink: #0b0b0b; --accent-wash: rgba(57, 135, 229, 0.18);
  --good: #0ca30c; --bad: #e66767;
  --warn-bg: #3a2f12; --warn-ink: #f3d58a;
  --s0: #3987e5; --s1: #d95926; --s2: #199e70; --s3: #c98500;
  --s4: #d55181; --s5: #008300; --s6: #9085e9; --s7: #e66767;
  --other: #55544f;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--page); color: var(--ink); }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior-y: none; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.small { font-size: 13px; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }

/* ---- shell ---- */
.app { display: flex; flex-direction: column; height: 100dvh; }
.content { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.page { max-width: 720px; margin: 0 auto; padding: calc(12px + env(safe-area-inset-top)) 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.page-title { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.page-title h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.nav { display: flex; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.nav a { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 6px; text-decoration: none; color: var(--muted); font-size: 11.5px; position: relative; }
.nav a[aria-current="page"] { color: var(--ink); font-weight: 600; }
.nav a[aria-current="page"] svg { color: var(--accent); }
.nav svg { width: 24px; height: 24px; }
.nav .count { position: absolute; top: 3px; left: calc(50% + 6px); background: var(--accent); color: var(--accent-ink); border-radius: 999px; min-width: 18px; height: 18px; padding: 0 5px; font-size: 11px; line-height: 18px; font-weight: 650; text-align: center; }
@media (min-width: 900px) {
  .app { flex-direction: row-reverse; }
  .nav { flex-direction: column; width: 200px; border-top: 0; border-right: 1px solid var(--border); padding: 16px 8px; gap: 2px; }
  .nav a { flex: none; flex-direction: row; gap: 10px; padding: 10px 12px; font-size: 14px; border-radius: 10px; }
  .nav a[aria-current="page"] { background: var(--hover); }
  .nav .count { position: static; margin-left: auto; }
  .page { padding-top: 24px; }
}

/* ---- pieces ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.card h2 { font-size: 15px; font-weight: 600; }
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 9px 14px; min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.icon-btn { border: 0; background: transparent; width: 42px; height: 42px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); flex: none; }
.icon-btn svg { width: 22px; height: 22px; }
.chip { border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 7px 13px; min-height: 38px; display: inline-flex; align-items: center; gap: 6px; font-size: 14.5px; max-width: 100%; overflow-wrap: anywhere; text-align: left; }
.chip.suggest { background: var(--accent-wash); border-color: transparent; font-weight: 550; }
.chip.small { padding: 2px 9px; min-height: 26px; font-size: 13px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip .x { opacity: 0.7; font-size: 15px; line-height: 1; }
.badge { display: inline-flex; align-items: center; border-radius: 6px; padding: 0 6px; font-size: 12px; line-height: 18px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
input.field, textarea.field, select.field { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 42px; }
textarea.field { resize: vertical; min-height: 44px; }
label.stack { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
label.stack > * { font-size: 16px; color: var(--ink); }
.callout { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.empty { text-align: center; color: var(--ink-2); padding: 32px 16px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.empty svg { width: 40px; height: 40px; color: var(--muted); }
.error { color: var(--bad); font-size: 14px; }
.skeleton { color: var(--muted); padding: 24px; text-align: center; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 6px 8px; border-radius: 8px; color: var(--ink-2); font-size: 14px; min-height: 34px; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.12); }

/* ---- answering ---- */
.answer .merchant { font-size: 19px; font-weight: 650; overflow-wrap: anywhere; }
.answer .amount { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.picker { display: flex; flex-direction: column; gap: 8px; }

/* ---- transaction rows ---- */
.txn { display: flex; align-items: center; gap: 10px; padding: 10px 12px; text-decoration: none; min-width: 0; width: 100%; background: transparent; border: 0; text-align: left; }
.txn .main { flex: 1; min-width: 0; }
.txn .name { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn .sub { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn .value { text-align: right; flex: none; }
.txn .value .date { font-size: 12.5px; color: var(--muted); }
.amount-in { color: var(--good); }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.list > * + * { border-top: 1px solid var(--border); }
.virtual { position: relative; }
.virtual .slot { position: absolute; left: 0; right: 0; height: 64px; border-top: 1px solid var(--border); background: var(--surface); }
.list-scroll { flex: 1; min-height: 0; overflow-y: auto; background: var(--surface); border-top: 1px solid var(--border); }
.search-page { display: flex; flex-direction: column; height: 100%; }
.search-head { padding: calc(10px + env(safe-area-inset-top)) 16px 8px; display: flex; flex-direction: column; gap: 8px; max-width: 720px; width: 100%; margin: 0 auto; }
.virtual-inner { max-width: 720px; margin: 0 auto; }
.totals { display: flex; gap: 2px 14px; flex-wrap: wrap; font-size: 13.5px; color: var(--ink-2); }
.totals b { color: var(--ink); font-weight: 600; }

/* ---- charts ---- */
.hero { display: flex; flex-direction: column; gap: 2px; }
.hero .value { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.kpis { display: flex; gap: 18px; flex-wrap: wrap; }
.kpi .label { font-size: 12.5px; color: var(--ink-2); }
.kpi .value { font-size: 17px; font-weight: 650; }
.chart { position: relative; width: 100%; touch-action: pan-y; }
.chart svg { display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tooltip { position: absolute; top: 0; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 8px; padding: 5px 9px; font-size: 12.5px; white-space: nowrap; pointer-events: none; z-index: 2; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.bars { display: flex; flex-direction: column; }
.bar { display: flex; flex-direction: column; gap: 4px; padding: 7px 0; border: 0; background: transparent; width: 100%; text-align: left; border-radius: 8px; }
.bar .top { display: flex; justify-content: space-between; gap: 10px; font-size: 14.5px; }
.bar .top span:first-child { min-width: 0; overflow-wrap: anywhere; }
.bar .track { height: 8px; }
.bar .fill { height: 8px; border-radius: 0 4px 4px 0; min-width: 2px; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--page); border-radius: 12px; padding: 8px 8px 8px 14px; display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px); box-shadow: var(--shadow); z-index: 10; font-size: 14.5px; }
.toast span { min-width: 0; overflow-wrap: anywhere; }
.toast button { border: 0; background: transparent; color: inherit; font-weight: 650; padding: 6px 10px; border-radius: 8px; text-decoration: underline; flex: none; }
.toast.plain { padding-right: 14px; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* ---- detail ---- */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14.5px; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.receipt { width: 100%; max-height: 420px; object-fit: contain; border-radius: 10px; background: var(--surface-2); display: block; }
details summary { cursor: pointer; font-size: 14px; color: var(--ink-2); }
pre.raw { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12.5px; background: var(--surface-2); border-radius: 8px; padding: 8px; margin: 6px 0 0; }
.report-frame { flex: 1; width: 100%; border: 0; min-height: 0; background: var(--page); }
.report-page { display: flex; flex-direction: column; height: 100%; }
.report-head { display: flex; align-items: center; gap: 4px; padding: calc(4px + env(safe-area-inset-top)) 8px 4px; }
.menu-link { display: flex; align-items: center; gap: 12px; padding: 13px 14px; text-decoration: none; }
.menu-link svg { width: 22px; height: 22px; color: var(--ink-2); flex: none; }
.menu-link .sub { font-size: 13px; color: var(--ink-2); }

/* ---- planning ---- */
.forecast-line { display: flex; justify-content: space-between; gap: 12px; font-size: 14.5px; color: var(--ink-2); text-decoration: none; }
.forecast-line b { color: var(--ink); font-weight: 650; }
.ledger { display: flex; flex-direction: column; font-size: 14.5px; }
.ledger .line { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; color: var(--ink-2); }
.ledger .line span:last-child { color: var(--ink); font-variant-numeric: tabular-nums; }
.meter { display: flex; flex-direction: column; gap: 5px; padding: 10px 0; background: transparent; border: 0; width: 100%; text-align: left; color: inherit; font: inherit; }
.meter + .meter { border-top: 1px solid var(--border); }
.meter .top { display: flex; justify-content: space-between; gap: 12px; }
.meter .name { font-weight: 550; min-width: 0; overflow-wrap: anywhere; }
.meter .track { position: relative; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter .spent { position: absolute; left: 0; top: 0; bottom: 0; background: var(--s0); border-radius: 0 4px 4px 0; }
.meter .coming { position: absolute; left: 0; top: 0; bottom: 0; background: var(--s0); opacity: 0.28; border-radius: 0 4px 4px 0; }
.meter.over .spent, .meter.over .coming { background: var(--bad); }
.meter .note { font-size: 13px; color: var(--ink-2); }
.meter.over .note { color: var(--bad); }
.plan-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 8px 0; font-size: 14.5px; text-decoration: none; color: inherit; }
.plan-row + .plan-row { border-top: 1px solid var(--border); }
.plan-row .where { min-width: 0; overflow-wrap: anywhere; }
.plan-form { display: flex; flex-direction: column; gap: 10px; padding: 10px 0 2px; }

/* ---- receipts ---- */
.receipt-split { display: flex; flex-direction: column; gap: 12px; }
.receipt-frame { max-height: 60vh; overflow: auto; border-radius: 10px; background: var(--surface-2); touch-action: pan-x pan-y pinch-zoom; }
.receipt-frame.open { max-height: none; }
.receipt-photo { display: block; width: 100%; height: auto; }
.receipt-lines { display: flex; flex-direction: column; }
.receipt-line { display: flex; flex-direction: column; gap: 2px; padding: 9px 0; }
.receipt-line + .receipt-line { border-top: 1px solid var(--border); }
.receipt-line .top { display: flex; justify-content: space-between; gap: 12px; }
.receipt-line .text { min-width: 0; overflow-wrap: anywhere; font-size: 14.5px; }
.receipt-line .sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 13px; color: var(--ink-2); }
.receipt-line .link { border: 0; background: transparent; padding: 2px 0; font: inherit; color: var(--accent); text-align: left; }
.edit-line { display: grid; grid-template-columns: 1fr 92px 34px; gap: 6px; align-items: center; padding: 8px 0; }
.edit-line + .edit-line { border-top: 1px solid var(--border); }
.edit-line .wide { grid-column: 1 / 3; }
.edit-line .field { min-width: 0; width: 100%; }
.edit-line .amount { text-align: right; }
.sum-check { display: flex; justify-content: space-between; gap: 12px; font-weight: 600; padding: 8px 0 0; }
.sum-check.off { color: var(--bad); }
.change { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.price-row { display: flex; align-items: center; gap: 10px; padding: 11px 14px; text-decoration: none; color: inherit; }
.price-row .main { flex: 1; min-width: 0; }
.price-row .name { font-weight: 550; overflow-wrap: anywhere; }
.price-row .sub { font-size: 13px; color: var(--ink-2); }
.price-row .value { text-align: right; flex: none; }
.table-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 8px 0; font-size: 14.5px; }
.table-row + .table-row { border-top: 1px solid var(--border); }
.table-row .where { min-width: 0; overflow-wrap: anywhere; }
.table-row.bare { width: 100%; border-width: 1px 0 0; border-style: solid; border-color: var(--border); background: transparent; color: inherit; font: inherit; font-size: 14.5px; }
.table-row.bare:first-of-type { border-top: 0; }
.stack-gap { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
@media (min-width: 900px) {
  .receipt-split { flex-direction: row; align-items: flex-start; }
  .receipt-split > * { flex: 1; min-width: 0; }
  .receipt-side { position: sticky; top: 12px; }
  .receipt-frame { max-height: calc(100dvh - 60px); }
}

/* Hover only where there is one, or it sticks after a tap on a phone. */
@media (hover: hover) {
  .btn:hover, .icon-btn:hover, .chip:hover, .txn:hover, .bar:hover, .menu-link:hover, .price-row:hover { background: var(--hover); }
  .btn.primary:hover { background: var(--accent); filter: brightness(1.08); }
  .chip.suggest:hover { background: var(--accent-wash); filter: brightness(0.96); }
}
.segments { display: inline-flex; align-self: flex-start; background: var(--surface-2); padding: 3px; border-radius: 10px; gap: 2px; }
.segments button { border: 0; background: transparent; padding: 5px 11px; border-radius: 8px; color: var(--ink-2); font-size: 13.5px; min-height: 32px; }
.segments button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.12); }
