/* Expense Analyzer — calm, readable, accessible. Tokens from docs/ui-ux-final.md §6. */
:root {
  --canvas: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --text: #0F172A;
  --muted: #475569;
  --action: #4F46E5;
  --action-hover: #4338CA;
  --on-action: #FFFFFF;
  --focus: #4F46E5;
  --spent: #C2410C;
  --income: #15803D;
  --invested: #7E22CE;
  --moved: #475569;
  --unchecked: #B45309;
  --ok: #15803D;
  --warn: #B45309;
  --danger: #B91C1C;
  --note-bg: #EEF2FF;
  --warn-bg: #FFFBEB;
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 1px 3px rgb(15 23 42 / 8%);
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --w: 720px;
  --w-wide: 1040px;
  color-scheme: light;
}
[data-theme='dark'] {
  --canvas: #0B1220;
  --surface: #111827;
  --surface-2: #1F2937;
  --border: #1F2937;
  --border-strong: #374151;
  --text: #F1F5F9;
  --muted: #CBD5E1;
  --action: #A5B4FC;
  --action-hover: #C7D2FE;
  --on-action: #111827;
  --focus: #A5B4FC;
  --spent: #FDBA74;
  --income: #86EFAC;
  --invested: #D8B4FE;
  --moved: #CBD5E1;
  --unchecked: #FCD34D;
  --ok: #86EFAC;
  --warn: #FCD34D;
  --danger: #FCA5A5;
  --note-bg: #1E1B4B;
  --warn-bg: #2A2110;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/24px system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
  background: var(--canvas);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--action); text-underline-offset: 3px; }
a:hover { color: var(--action-hover); }
h1 { font-size: 28px; line-height: 36px; margin: 0 0 12px; }
h2 { font-size: 20px; line-height: 28px; margin: 0 0 12px; }
h3 { font-size: 16px; line-height: 24px; margin: 16px 0 8px; }
p { margin: 0 0 12px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 4px; }
main:focus, h1:focus, h2:focus, [tabindex='-1']:focus { outline: none; }
main:focus-visible [tabindex='-1']:focus-visible { outline: 3px solid var(--focus); }

.hidden { display: none !important; }
[hidden] { display: none !important; }
.sr-only, .sr-only-input {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }
.small { font-size: 14px; line-height: 20px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }
.pos { color: var(--income); }
svg { flex: none; vertical-align: middle; }

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100; padding: 10px 16px;
  background: var(--surface); color: var(--text); border: 2px solid var(--focus); border-radius: var(--r-sm);
}
.skip-link:focus { top: 8px; }

/* ---------- top bar & navigation ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: var(--w-wide); margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; min-height: 44px; min-width: 44px; }
.nav-top { display: flex; gap: 4px; flex: 1; }
.nav-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px;
  border-radius: var(--r-sm); color: var(--muted); text-decoration: none; font-weight: 500; position: relative;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { color: var(--action); background: var(--note-bg); }
.nav-top .nav-link svg { display: none; }
.badge {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; font-size: 12px; line-height: 20px;
  background: var(--unchecked); color: var(--surface); text-align: center; font-weight: 700;
}
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.private-badge {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-height: 44px; min-width: 44px; padding: 0 10px; border-radius: 999px;
  color: var(--ok); text-decoration: none; font-weight: 600; font-size: 14px;
}
.private-badge:hover { background: var(--surface-2); color: var(--ok); }
.btn-add { padding: 0 12px; }
/* "+ Add statement" in full on computers; on phones and tablets it doesn't fit next to "On this device", so "+ Add"
   (screen readers always hear "Add statement"). */
.btn-add-more { display: none; }
@media (min-width: 1024px) {
  .btn-add-more { display: inline; }
}
.nav-bottom { display: none; }

/* Portrait tablets, phones turned sideways and half-screen windows: the logo alone keeps the top bar on one line,
   so it never scrolls sideways or cuts off Add. */
@media (max-width: 959px) {
  .brand span { display: none; }
}
/* Phones turned sideways and high zoom: the top bar scrolls away, so content gets the height. */
@media (max-height: 500px) {
  .topbar { position: static; }
}

@media (max-width: 720px) {
  .nav-top { display: none; }
  .topbar-inner { gap: 8px; }
  .nav-bottom {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  .nav-bottom .nav-link { flex: 1; flex-direction: column; gap: 2px; font-size: 12px; line-height: 16px; min-height: 56px; justify-content: center; border-radius: 0; }
  .nav-bottom .nav-link.active { background: transparent; }
  .nav-bottom .badge { position: absolute; top: 4px; left: calc(50% + 6px); }
  body { padding-bottom: 72px; }
}
/* "On this device" doesn't fit on the smallest phones, or next to the top tabs below 800 px: the lock alone
   (screen readers still hear "On this device"). */
@media (max-width: 360px), (min-width: 721px) and (max-width: 799px) {
  .private-badge span { display: none; }
}

/* ---------- layout ---------- */
.banner-slot { max-width: var(--w); width: 100%; margin: 0 auto; padding: 0 16px; }
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-top: 12px; padding: 10px 14px; border-radius: var(--r-md); background: var(--note-bg); border: 1px solid var(--border);
}
.banner-demo { background: var(--warn-bg); }
main { flex: 1; width: 100%; max-width: var(--w); margin: 0 auto; padding: 16px 16px 32px; }
.footer {
  max-width: var(--w-wide); width: 100%; margin: 0 auto; padding: 16px; display: flex; gap: 12px; flex-wrap: wrap;
  justify-content: center; color: var(--muted); font-size: 14px; border-top: 1px solid var(--border);
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.page-head h1 { margin: 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 20px; margin: 16px 0; box-shadow: var(--shadow);
}
.card > :last-child { margin-bottom: 0; }
.card-action { border-color: var(--unchecked); border-left-width: 4px; }
.card-done { border-color: var(--ok); border-left-width: 4px; }
.card-done h2 svg { color: var(--ok); }
.card-note { background: var(--note-bg); }
.note { background: var(--note-bg); border-radius: var(--r-md); padding: 12px; margin: 12px 0; }
.note.warn { background: var(--warn-bg); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.plain { list-style: none; padding: 0; margin: 0 0 12px; }
.plain > li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.plain > li:last-child { border-bottom: 0; }
.back { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; text-decoration: none; }
.big-number { font-size: 32px; line-height: 40px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.coverage { margin: 0 0 4px; }
.whats-new {
  display: flex; align-items: center; gap: 8px; margin: 16px 0; padding: 0 0 0 14px;
  border-radius: var(--r-md); background: var(--note-bg); border: 1px solid var(--border);
}
.whats-new > .icon { flex: none; color: var(--action); }
.whats-new > a { flex: 1; min-width: 0; padding: 10px 0; }
.whats-new > .btn-icon { flex: none; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: var(--r-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--action); border-color: var(--action); color: var(--on-action); }
.btn-primary:hover { background: var(--action-hover); border-color: var(--action-hover); color: var(--on-action); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn-danger:hover { filter: brightness(0.92); background: var(--danger); color: var(--surface); }
.btn-sm { min-height: 44px; padding: 0 12px; font-size: 14px; }
.btn-lg { min-height: 52px; padding: 0 22px; font-size: 17px; }
.btn-link, .btn.btn-link {
  background: none; border: 0; padding: 0 4px; min-height: 44px; color: var(--action); font: inherit;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-weight: 500;
}
.btn-inverse { background: var(--surface); color: var(--text); border-color: var(--surface); }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: var(--r-sm);
  border: 1px solid transparent; background: none; color: var(--text); cursor: pointer;
}
.btn-icon:hover { background: var(--surface-2); }
.btn-icon:disabled { opacity: 0.35; cursor: not-allowed; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); min-height: 44px; padding: 8px 12px; max-width: 100%;
}
input[type='checkbox'], input[type='radio'] { min-height: 0; width: 20px; height: 20px; accent-color: var(--action); margin: 0; flex: none; }
label { display: inline-flex; flex-direction: column; gap: 4px; font-weight: 500; }
label.check, label.choice { flex-direction: row; align-items: center; gap: 10px; min-height: 44px; font-weight: 400; cursor: pointer; }
label.choice { align-items: flex-start; padding: 10px 0; }
label.choice input { margin-top: 2px; }
fieldset { border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
legend { font-weight: 600; padding: 0; margin-bottom: 4px; }
.choices.inline { display: flex; flex-wrap: wrap; gap: 16px; }
.custom-dates { display: flex; gap: 12px; flex-wrap: wrap; padding: 0 0 8px 30px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 16px; }
.form-grid fieldset { grid-column: 1 / -1; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin: 12px 0; }
.form-row output { flex-basis: 100%; }
details { margin: 8px 0; }
summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--action); font-weight: 500; }
progress { width: 100%; height: 8px; accent-color: var(--action); }
.progress { margin: 4px 0 8px; }

/* ---------- period control ---------- */
.period { display: flex; align-items: center; gap: 4px; }
.period .btn-icon { flex: none; }
.period-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 4px 14px; font: inherit; font-weight: 600; line-height: 1.3; text-align: center;
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 999px; cursor: pointer;
}
.period-dates { display: inline-block; }
.period-btn:hover { background: var(--surface-2); }
.period-choices label.choice { display: flex; }

/* ---------- home ---------- */
.hero { padding: 24px 0; }
.hero h1 { font-size: 32px; line-height: 40px; }
.lead { font-size: 18px; line-height: 28px; color: var(--muted); }
.trust { list-style: none; padding: 0; margin: 24px 0 0; }
.trust li { display: flex; gap: 10px; align-items: center; padding: 6px 0; }
.trust svg, .trust-line svg { color: var(--ok); }
.trust-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.flow-list { list-style: none; padding: 0; margin: 0; }
.flow-row, .flow-total {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 4px; color: var(--text); text-decoration: none;
  border-bottom: 1px solid var(--border);
}
a.flow-row:hover { background: var(--surface-2); color: var(--text); }
.flow-label { flex: 1; display: flex; flex-direction: column; font-weight: 500; }
.flow-label .dot { display: none; }
.flow-note { font-size: 14px; line-height: 20px; color: var(--muted); font-weight: 400; }
.flow-amt { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 18px; }
.flow-row svg { color: var(--muted); }
.flow-row.income .flow-amt { color: var(--income); }
.flow-row.spent .flow-amt { color: var(--spent); }
.flow-row.invested .flow-amt { color: var(--invested); }
.flow-row.moved .flow-amt { color: var(--moved); }
.flow-row.unchecked .flow-amt { color: var(--unchecked); }
.flow-total { border-bottom: 0; border-top: 2px solid var(--text); font-weight: 700; padding-right: 34px; }
.balance {
  display: flex; align-items: center; gap: 8px; width: 100%; margin: 8px 0; padding: 8px 12px; min-height: 44px;
  border-radius: var(--r-md); font: inherit; text-align: left; border: 1px solid var(--border);
}
button.balance { cursor: pointer; background: var(--surface); color: var(--ok); font-weight: 600; }
button.balance span { flex: 1; }
.balance.warn { background: var(--warn-bg); color: var(--warn); }
.balance.warn span { flex: 1; }
.offer { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.ai-inline { margin-top: 12px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.k-spent { background: var(--spent); } .k-income { background: var(--income); }
.k-invested { background: var(--invested); } .k-moved { background: var(--moved); } .k-unchecked { background: var(--unchecked); }
.k-spent-text { color: var(--spent); } .k-income-text { color: var(--income); }

.bars { list-style: none; padding: 0; margin: 0 0 12px; }
.bars a { display: grid; grid-template-columns: minmax(110px, 1fr) 2fr auto; gap: 12px; align-items: center; min-height: 44px; color: var(--text); text-decoration: none; border-radius: var(--r-sm); padding: 0 4px; }
.bars a:hover { background: var(--surface-2); }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; }
.bar > span.unchecked { background: var(--unchecked); }
.bar-amt { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
@media (max-width: 480px) {
  .bars a { grid-template-columns: 1fr auto; }
  .bars .bar { grid-column: 1 / -1; order: 3; }
}

/* ---------- transactions ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin: 8px 0; }
.search { position: relative; flex: 1 1 220px; display: flex; }
.search svg { position: absolute; left: 12px; top: 13px; color: var(--muted); }
.search input { width: 100%; padding-left: 38px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px; }
.chip {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border-strong); color: var(--text); text-decoration: none; background: var(--surface); font-weight: 500;
}
.chip.active { background: var(--action); color: var(--on-action); border-color: var(--action); }
.date-head { font-size: 14px; color: var(--muted); margin: 16px 0 4px; font-weight: 600; }
.date-head:first-child { margin-top: 0; }
.tx-list { list-style: none; padding: 0; margin: 0; }
.tx {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 4px; font: inherit; color: var(--text);
  background: none; border: 0; border-bottom: 1px solid var(--border); text-align: left; cursor: pointer;
}
.tx:hover { background: var(--surface-2); }
.tx-date { color: var(--muted); font-size: 14px; width: 52px; flex: none; }
.tx-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tx-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-cat { font-size: 14px; line-height: 20px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; background: none !important; }
.tx-cat.k-unchecked { color: var(--unchecked); font-weight: 600; }
.tx-amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.tx-amt.pos { color: var(--income); }
.table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 15px; }
.table th, .table td { padding: 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-weight: 600; color: var(--muted); font-size: 14px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card:has(> .table), .card:has(> details .table) { overflow-x: auto; }

/* ---------- edit sheet & check ---------- */
.tx-head-name { font-size: 20px; font-weight: 700; margin: 0; }
.tx-head-amt { font-size: 24px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.tx-head-amt.pos { color: var(--income); }
.cat-group { margin-top: 12px; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.cat-opt { flex-direction: row; font-weight: 400; }
.cat-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.cat-opt > span {
  display: flex; align-items: center; width: 100%; min-height: 44px; padding: 8px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); cursor: pointer; background: var(--surface);
}
.cat-opt input:checked + span { border: 2px solid var(--action); background: var(--note-bg); font-weight: 600; }
.cat-opt input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.cat-opt.suggested > span { border-style: dashed; }
.extras { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 8px; }
.mini-list { margin: 0; padding-left: 20px; font-size: 14px; color: var(--muted); }
.check-card h2 { font-size: 22px; margin: 4px 0 0; }
.suggest { background: var(--note-bg); padding: 8px 12px; border-radius: var(--r-sm); }
.q { margin-top: 16px; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }
.quick-pick[aria-pressed='true'] { border: 2px solid var(--action); background: var(--note-bg); }
.check-nav { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; }
.check-end { text-align: center; }
.check-end .actions { justify-content: center; }

/* ---------- add statement ---------- */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 40px 16px;
  border: 2px dashed var(--border-strong); border-radius: var(--r-lg); background: var(--surface); cursor: pointer; text-align: center; margin: 16px 0;
}
.drop:hover, .drop.over { border-color: var(--action); background: var(--note-bg); }
.drop:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
.drop svg { color: var(--action); }
.drop-title { font-size: 18px; font-weight: 700; }
.facts { display: grid; gap: 8px; margin: 16px 0; }
.facts > div { display: grid; grid-template-columns: 110px 1fr; gap: 12px; align-items: center; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.facts input { width: 100%; max-width: 320px; }

/* ---------- insights chart ---------- */
.trend-show { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; }
/* "Show on chart" scrolls here; keep the heading clear of the sticky top bar. */
#tr-h { scroll-margin-top: 76px; }
@media (max-height: 500px) { #tr-h { scroll-margin-top: 12px; } }
.trend-show label { flex-direction: row; }
.trend-show select { flex: 1 1 auto; min-width: 0; max-width: 320px; }
.chart { list-style: none; display: flex; align-items: flex-end; gap: 4px; height: 200px; padding: 0; margin: 8px 0 12px; overflow-x: auto; }
.chart li { flex: 1 0 44px; display: flex; flex-direction: column; align-items: center; height: 100%; }
.chart .col { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; background: none; border: 0; padding: 0; cursor: pointer; border-radius: var(--r-sm) var(--r-sm) 0 0; }
.chart a.col { text-decoration: none; color: inherit; }
.chart span.col { cursor: default; }
.chart .col:hover .col-bar { filter: brightness(1.15); }
.col-bar { display: block; width: 70%; max-width: 40px; background: var(--spent); border-radius: 6px 6px 0 0; }
.chart .gap .col { border-bottom: 2px dashed var(--border-strong); cursor: default; }
.chart .sel .col { outline: 2px solid var(--text); outline-offset: -2px; }
.chart .sel .col-label { font-weight: 700; color: var(--text); }
.chart li .col:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.col-label { font-size: 12px; line-height: 16px; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.col-note { font-size: 11px; line-height: 14px; color: var(--muted); white-space: nowrap; }

/* ---------- dialogs & toasts ---------- */
dialog {
  border: 0; padding: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--text);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 50px rgb(0 0 0 / 30%);
}
dialog::backdrop { background: rgb(15 23 42 / 55%); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 20px 8px; }
.dlg-head h2 { margin: 0; }
.dlg-body { padding: 0 20px; overflow-y: auto; }
.dlg-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--border); }
.error-text { color: var(--danger); padding: 8px 20px 0; margin: 0; }
dialog.sheet { width: min(640px, 100vw); }
@media (max-width: 640px) {
  dialog.sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92vh; }
  dialog.sheet form { max-height: 92vh; }
}
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; width: min(520px, calc(100vw - 24px)); }
@media (max-width: 720px) { .toasts { bottom: 84px; } }
/* While the AI panel is open, messages sit above it so they never cover Stop or Continue. Wide windows have room beside it. */
@media (max-width: 1299px) { body.ai-panel-open .toasts { bottom: calc(24px + var(--ai-panel-h, 0px)); } }
@media (max-width: 720px) { body.ai-panel-open .toasts { bottom: calc(84px + var(--ai-panel-h, 0px)); } }
.toast {
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px; border-radius: var(--r-md);
  background: var(--text); color: var(--canvas); box-shadow: 0 8px 24px rgb(0 0 0 / 25%);
}
.toast .grow { flex: 1; }
.toast .btn-icon { color: var(--canvas); }
.toast-error { background: var(--danger); color: #fff; }
.toast-error .btn-icon { color: #fff; }

/* ---------- how it works ---------- */
.help { line-height: 26px; }
.help h1 { font-size: 28px; }
.help h2 { margin-top: 28px; }
.help ul, .help ol { padding-left: 24px; }
.help li { margin: 4px 0; }
.help blockquote { margin: 12px 0; padding: 12px 16px; background: var(--note-bg); border-radius: var(--r-md); border-left: 4px solid var(--action); }
.help blockquote p:last-child { margin: 0; }
.help code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.help pre { background: var(--surface-2); padding: 12px; border-radius: var(--r-md); overflow-x: auto; }
.help table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 15px; display: block; overflow-x: auto; }
.help th, .help td { border-bottom: 1px solid var(--border); padding: 8px; text-align: left; vertical-align: top; }
.help details { border: 1px solid var(--border); border-radius: var(--r-md); padding: 0 12px; }
.help details[open] { padding-bottom: 12px; }
.flow, .seq { list-style: none; padding: 0 !important; margin: 16px 0; display: flex; flex-direction: column; align-items: stretch; gap: 0; }
.flow-box, .seq li {
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--r-md); padding: 10px 14px; text-align: center; margin: 0 !important;
}
.flow-arrow { text-align: center; color: var(--muted); font-size: 14px; padding: 2px 0; margin: 0 !important; }
.flow-arrow::before { content: '↓ '; font-size: 18px; }
.seq li { text-align: left; margin: 0 0 6px !important; }
.seq-opt { border-style: dashed !important; }
.seq-note { background: var(--note-bg) !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (max-width: 400px) {
  main { padding: 12px 12px 24px; }
  .card { padding: 16px; }
  h1 { font-size: 24px; line-height: 32px; }
  .hero h1 { font-size: 26px; line-height: 34px; }
}

/* Editable preview before adding a statement */
.table-wrap { overflow-x: auto; }
.pv-table select { min-width: 150px; max-width: 220px; font-size: 14px; padding: 4px 6px; }
.pv-table td { vertical-align: middle; }
.pv-known { margin-top: 16px; }
.pv-known > summary { cursor: pointer; font-weight: 600; padding: 8px 0; }
@media (max-width: 560px) {
  .pv-table thead { display: none; }
  .pv-table tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
  .pv-table td { border: 0; padding: 0; }
  .pv-table td:nth-child(1) { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
  .pv-table td:nth-child(4) { grid-column: 1 / -1; }
  .pv-table select { width: 100%; max-width: none; }
}

/* AI download / suggestion progress panel (stays visible on every page) */
.ai-panel { position: fixed; right: 16px; bottom: 16px; z-index: 45; width: min(360px, calc(100vw - 24px)); background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); padding: 12px 14px; }
.ai-panel.hidden { display: none; }
.ai-panel-head { display: flex; align-items: center; gap: 8px; }
.ai-panel progress { width: 100%; height: 10px; margin: 10px 0 4px; accent-color: var(--action); }
.ai-panel p { margin: 4px 0 0; }
.ai-panel .actions { margin-top: 8px; }
@media (max-width: 720px) { .ai-panel { right: 12px; left: 12px; width: auto; bottom: 76px; } }
.model-choice { align-items: flex-start; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.model-choice:has(input:checked) { border-color: var(--action); }
.model-choice.locked { opacity: .6; cursor: not-allowed; background: var(--note-bg); }
.chip-ai { min-height: 32px; padding: 0 10px; display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; font-size: 13px; border-style: dashed; border-color: var(--invested); color: var(--invested); background: transparent; cursor: pointer; }
.chip-ai:hover { background: var(--note-bg); }
[data-draft-ai] .actions { margin: 8px 0 4px; }

/* Check payments — all at once */
.seg { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.view-check .page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.view-check .page-head h1 { margin-right: auto; }
.ck-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
.ck-sort { flex-direction: row; align-items: center; gap: 8px; }
.ck-progress { margin: 4px 0 8px; }
.ck-progress p { margin: 0 0 4px; }
.ck-progress .progress { margin: 0; }
.ck-bulk { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.ck-bulk h3 { font-size: 16px; line-height: 24px; margin: 0 0 8px; }
.ck-bulk-row { display: flex; flex-wrap: wrap; gap: 12px; }
.ck-bulk-row label { flex: 1 1 200px; min-width: 0; }
.ck-bulk-row select { width: 100%; }
.ck-rem { display: flex; margin-top: 6px; color: var(--muted); font-size: 13px; gap: 6px; align-items: center; }
.pv-table tr.ck-saved td { opacity: .7; }
.pv-table tr.ck-saved select { opacity: 1; }
[data-check-ai] .actions { margin: 8px 0 4px; }
.pv-table tr:not(.ck-saved) .ck-rem { display: none; }

/* Insights: ask, story, what changed, worth checking */
.ask-form { display: flex; gap: 8px; margin: 8px 0; }
.ask-form input { flex: 1; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chip-toggle { display: none; color: var(--action); border-style: dashed; cursor: pointer; }
/* Phones: the first four questions, then "More questions", so the summary shows sooner. */
@media (max-width: 720px) {
  .ask-chips:not(.open) .chip-more { display: none; }
  .ask-chips:not(.open) .chip-toggle { display: inline-flex; }
}
.ask-answer:empty { display: none; }
.ask-answer { border-left: 4px solid var(--action); padding: 4px 0 4px 12px; margin: 12px 0; }
.ask-answer .ask-a { font-size: 1.05rem; }
.story li, .glance li, .worth li, .change-parts li { padding: 6px 0; }
.story .dot { margin-right: 6px; }
.story [data-change] { margin-top: 2px; }
.story [data-change] details { margin: 0; }
.ask-links { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.change-parts .up { color: var(--spent); font-weight: 600; }
.change-parts .down { color: var(--income, inherit); font-weight: 600; }
.worth li { border-bottom: 1px solid var(--border, #e5e7eb); }
.worth li:last-child { border-bottom: 0; }
/* Regular payments: name and price, then "next about · a year"; one "Stopped paying one of these?" link below. */
.regular li { padding: 6px 0; border-bottom: 1px solid var(--border, #e5e7eb); overflow-wrap: anywhere; }
.regular li:last-child { border-bottom: 0; }
.regular-stop { margin: 4px 0 0; }
.stopped .btn-link { min-height: 32px; padding: 0 2px; }
.stopped { margin-top: 8px; }
.stopped summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--muted); }
[data-fixed] details { margin: 0; }
/* Your names on statements: removable chips. */
.name-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; padding: 0; list-style: none; }
.name-chips li { display: inline-flex; align-items: center; gap: 2px; padding-left: 12px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); overflow-wrap: anywhere; }
.name-chips .btn-icon { width: 40px; height: 40px; border-radius: 999px; }
[data-me] .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.footnote { text-align: center; margin: 16px 0; }

/* AI helper: what we checked on this computer */
.checks ul { list-style: none; padding-left: 0; margin: .4rem 0; }
.checks li { margin: .15rem 0; }
