/* EZ Money Tracker. Layout: one centered column; cards wrap to one per row on phones. */
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17232e;
  --muted: #5d6b78;
  --line: #dde3e8;
  --accent: #1d3b53;
  --accent-ink: #ffffff;
  --now: #2f6f9f;
  --past: #b9c7d3;
  --ok: #217a4b;
  --warn: #a76100;
  --bad: #b3261e;
  --track: #e6ebef;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f161c; --panel: #17212a; --ink: #e8eef3; --muted: #9aa9b6; --line: #2a3742;
    --accent: #9cc3de; --accent-ink: #0f161c; --now: #7fb3d9; --past: #3b4c5a;
    --ok: #5cc48d; --warn: #f0a640; --bad: #ff8a80; --track: #24313b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); font-variant-numeric: tabular-nums; }
.wrap { max-width: 960px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
main.wrap { padding-block: 20px 48px; display: grid; gap: 20px; }
h1, h2, h3 { line-height: 1.2; text-wrap: balance; margin: 0; }
h1 { font-family: var(--serif); font-weight: 400; font-size: 2rem; }
h2 { font-size: 1.05rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
a { color: var(--now); }
code { font-family: ui-monospace, Menlo, Consolas, monospace; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--now); outline-offset: 2px; }

/* Header */
.top { background: var(--accent); color: var(--accent-ink); padding-top: env(safe-area-inset-top); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; flex-wrap: wrap; }
.brand { color: inherit; text-decoration: none; font-family: var(--serif); font-size: 1.25rem; }
.nav { display: flex; align-items: center; gap: 14px; font-size: .9rem; }
.nav a, .nav .linkish { color: inherit; }
.who { opacity: .8; }

/* Building blocks */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: grid; gap: 12px; min-width: 0; }
.note, .muted, .legend { color: var(--muted); font-size: .875rem; margin: 0; }
.legend { margin-top: -8px; }
.btn { font: inherit; font-size: .95rem; display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.linkish { font: inherit; background: none; border: 0; padding: 0; color: var(--now); text-decoration: underline; cursor: pointer; }
.inline { display: inline; margin: 0; }
.gap { margin-top: 4px; }
input, select { font: inherit; width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
input:focus, select:focus { border-color: var(--now); }
input[type=checkbox] { width: auto; min-height: 0; }
label { font-size: .85rem; color: var(--muted); }
.stack { display: grid; gap: 6px; }
.stack .btn { margin-top: 8px; justify-self: start; }
.narrow { max-width: 420px; }
.narrow-input { max-width: 220px; }
.flash { margin: 0; padding: 10px 14px; border-radius: 8px; border: 1px solid currentColor; background: var(--panel); }
.flash.ok { color: var(--ok); } .flash.bad { color: var(--bad); }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }
.pill { font-size: .75rem; padding: 1px 9px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; color: var(--muted); }
.pill.ok { color: var(--ok); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); }

/* Sign-in */
.auth { max-width: 460px; width: 100%; justify-self: center; margin-top: 4vh; }
.steps { margin: 0; padding-left: 1.2em; display: grid; gap: 8px; }
.key { display: block; margin: 6px 0; padding: 10px 12px; background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; font-size: 1.05rem; letter-spacing: .06em; word-break: break-all; user-select: all; }
.checks { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; font-size: .9rem; }
.cancel { justify-self: start; font-size: .9rem; }

/* Log a purchase */
.add { border-color: var(--accent); }
.add-form { display: grid; gap: 10px; }
.say { display: flex; gap: 8px; }
.say input { font-size: 1.05rem; }
.mic { flex: none; width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; }
.mic svg { width: 24px; height: 24px; fill: currentColor; }
.mic.on { background: var(--bad); }
@media (prefers-reduced-motion: no-preference) { .mic.on { animation: pulse 1.2s ease-in-out infinite; } }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--bad) 25%, transparent); } }
.hint { margin: 0; min-height: 1.2em; font-size: .875rem; color: var(--warn); }
.fields { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); }
.f { display: grid; gap: 4px; min-width: 0; }
.add-form > .btn { justify-self: start; min-width: 120px; }

/* Week summary */
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.head-text { min-width: 0; }
.take { margin: 6px 0 0; color: var(--muted); max-width: 62ch; }
.weeknav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.weeklabel { min-width: 11ch; text-align: center; font-size: .95rem; }
.totals { display: flex; flex-wrap: wrap; gap: 12px 40px; }
.totals .k { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.totals .v { font-family: var(--serif); font-size: 2rem; line-height: 1.1; }
.totals .sub { font-size: .8rem; color: var(--muted); }

/* Category cards */
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: grid; gap: 8px; align-content: start; min-width: 0; }
.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.big { font-family: var(--serif); font-size: 1.8rem; line-height: 1.1; }
.of { color: var(--muted); }
.bar { width: 100%; height: 10px; display: block; overflow: visible; }
.bar .track { fill: var(--track); }
.bar .fill { fill: currentColor; }
.bar .pace { stroke: var(--ink); stroke-width: 2; opacity: .55; }
.left { margin: 0; font-size: .85rem; color: var(--muted); }
.left b { color: var(--ink); }
.subs { list-style: none; margin: 0; padding: 0; font-size: .85rem; display: grid; gap: 2px; }
.subs li { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dotted var(--line); padding: 2px 0; }
.spark { width: 100%; height: 44px; display: block; }

/* Charts */
.b-now { fill: var(--now); }
.b-past { fill: var(--past); }
.b-bad { fill: var(--bad); }
.ref { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; fill: none; }
.grid { stroke: var(--line); stroke-width: 1; }
.trend { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; }
.trend .col { display: grid; grid-template-rows: auto 160px auto; gap: 4px; text-decoration: none; color: var(--muted); border-radius: 6px; padding: 2px 0; }
.trend .col:hover { background: var(--bg); }
.trend .col.sel { color: var(--ink); }
.trend svg { width: 100%; height: 160px; display: block; }
.trend .amt, .trend .wk { font-size: .72rem; line-height: 1.3; min-height: 1.3em; text-align: center; white-space: nowrap; overflow: visible; display: block; }
@media (max-width: 560px) { .trend .amt { visibility: hidden; } .trend .sel .amt { visibility: visible; overflow: visible; } .trend .col { grid-template-rows: auto 120px auto; } .trend svg { height: 120px; } }

/* Tables */
.tablebox { overflow-x: auto; }
.tx { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tx th { text-align: left; font-weight: 600; font-size: .78rem; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tx td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tx .meta { display: none; font-size: .78rem; color: var(--muted); margin-top: 2px; }
.tx .num { text-align: right; white-space: nowrap; }
.tx .actions { white-space: nowrap; display: flex; gap: 12px; }
.x { font: inherit; font-size: 1.2rem; line-height: 1; width: 32px; height: 32px; border-radius: 6px; border: 1px solid transparent; background: none; color: var(--muted); cursor: pointer; }
.x:hover { border-color: var(--line); color: var(--bad); }
@media (max-width: 560px) { .wide { display: none; } .tx .meta { display: block; } h1 { font-size: 1.7rem; } .totals { gap: 8px 24px; } .totals .v { font-size: 1.6rem; } }

/* Settings */
.budget-grid { display: grid; gap: 10px; }
.budget-row { display: grid; grid-template-columns: 7rem minmax(0, 8rem) 1fr; align-items: center; gap: 10px; }
.budget-row label:first-child { color: var(--ink); font-size: 1rem; }
.check { display: flex; align-items: center; gap: 6px; }
@media (max-width: 480px) { .budget-row { grid-template-columns: 1fr 1fr; } .budget-row .check { grid-column: 1 / -1; } }
