:root {
  color-scheme: light dark;
  --bg: #fafaf9;
  --surface: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --border: #e7e5e4;
  --accent: #0f766e;
  --error: #b91c1c;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --nav-h: 3.75rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
/* Dark follows the system unless Settings → Preferences forces a theme on
   this device (data-theme on <html>). The dark values appear twice because
   CSS cannot share one block between a media query and a selector. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131211;
    --surface: #1c1a19;
    --text: #f5f5f4;
    --muted: #a8a29e;
    --border: #2e2b29;
    --accent: #2dd4bf;
    --error: #fca5a5;
    --warn: #fbbf24;
    --warn-bg: #2a2112;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131211;
  --surface: #1c1a19;
  --text: #f5f5f4;
  --muted: #a8a29e;
  --border: #2e2b29;
  --accent: #2dd4bf;
  --error: #fca5a5;
  --warn: #fbbf24;
  --warn-bg: #2a2112;
}
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
/* The HTML hidden attribute does not apply to SVG elements in every browser;
   without this the icon sprite takes a 300×150 box above the page. */
svg[hidden] { display: none; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
.content {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1rem 16px calc(var(--nav-h) + 1.5rem + env(safe-area-inset-bottom));
}
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
.muted { color: var(--muted); }
.bottom-nav {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .125rem;
  min-height: 48px;
  color: var(--muted);
  font-size: .75rem;
  text-decoration: none;
}
.bottom-nav a[aria-current="page"] { color: var(--accent); }
.icon { width: 1.5rem; height: 1.5rem; }
@media (min-width: 48rem) {
  .content { padding-top: 2rem; }
}
.stack { display: grid; gap: .75rem; margin-top: 1.5rem; }
label { font-size: .875rem; }
input {
  min-height: 44px;
  padding: 0 .75rem;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
}
.btn {
  min-height: 48px;
  padding: 0 1.25rem;
  font: inherit;
  font-weight: 600;
  color: var(--bg);
  background: var(--accent);
  border: 0;
  border-radius: .5rem;
  cursor: pointer;
}
.btn:disabled { opacity: .6; cursor: progress; }

.htmx-indicator { opacity: 0; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; transition: opacity 200ms ease-in; }

h2 { font-size: 1.125rem; margin: 0; }
a { color: var(--accent); }
.plain-list { list-style: none; margin: 1rem 0; padding: 0; display: grid; gap: .75rem; }
.category-form {
  display: grid;
  gap: .5rem;
  padding: .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
}
.category-form label { display: grid; gap: .25rem; }
.category-form label.check { display: flex; align-items: center; gap: .5rem; min-height: 44px; }
.category-form input[type="checkbox"] { min-height: 0; width: 1.25rem; height: 1.25rem; }
.dimmed .category-form { opacity: .6; }
.field-error { margin: 0; color: var(--error); font-size: .875rem; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.btn-link { display: inline-flex; align-items: center; text-decoration: none; }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.account-list { gap: .5rem; }
.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 56px;
  padding: .5rem .75rem;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
}
.account-name { display: grid; min-width: 0; overflow-wrap: anywhere; }
.account-meta { font-size: .8125rem; }
.dimmed .account-row, .account-list.dimmed .account-row { opacity: .6; }
.inactive-accounts summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
.account-header { margin-bottom: 1rem; }
.account-header p { margin: 0; }
.account-balance { font-size: 1.5rem; font-weight: 600; }
.account-form {
  display: grid;
  gap: .5rem;
  padding: .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
}
.account-form label { display: grid; gap: .25rem; }
.account-form label.check { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; min-height: 44px; }
.account-form input[type="checkbox"] { min-height: 0; width: 1.25rem; height: 1.25rem; }
.export-form label.check { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; min-height: 44px; }
.export-form input[type="checkbox"] { min-height: 0; width: 1.25rem; height: 1.25rem; }
select, textarea {
  min-height: 44px;
  padding: .5rem .75rem;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
}
.segmented { display: flex; margin: 0; padding: 0; border: 0; min-width: 0; }
.segmented legend { padding: 0; margin-bottom: .25rem; font-size: .875rem; }
.segmented label { flex: 1; display: block; min-width: 0; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 .5rem;
  border: 1px solid var(--border);
  margin-left: -1px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.segmented label:first-of-type span { border-radius: .5rem 0 0 .5rem; margin-left: 0; }
.segmented label:last-of-type span { border-radius: 0 .5rem .5rem 0; }
.segmented input:checked + span { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Transaction entry: expense/income wording follows the checked type. */
.txn-form .when-income { display: none; }
.txn-form:has(input[name="type"][value="income"]:checked) .when-income { display: inline; }
.txn-form:has(input[name="type"][value="income"]:checked) .when-expense { display: none; }
.advanced summary, .confirm-delete summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--muted); }
.advanced-fields { display: grid; gap: .5rem; }
.advanced-fields label { display: grid; gap: .25rem; }
.details { display: grid; grid-template-columns: auto 1fr; gap: .25rem 1rem; margin: 0 0 1rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.details .note { white-space: pre-line; }
.income { color: var(--accent); }
.badge { display: inline-block; padding: 0 .375rem; font-size: .75rem; border: 1px solid var(--border); border-radius: .25rem; }
.confirm-delete { margin-top: 1rem; }
.confirm-delete form { display: grid; gap: .5rem; justify-items: start; }
.btn-danger { background: #b91c1c; color: #fff; }

/* Reconcile: a quiet disclosure above the account's edit form. */
.reconcile { margin: 0 0 1rem; }
.reconcile summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }

/* Transaction list: filter sheet, chips, rows grouped by day. */
.filter-sheet { margin: .5rem 0 1rem; }
.filter-sheet summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--accent); }
.filter-actions { display: flex; align-items: center; gap: 1rem; }
.chips { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  min-height: 44px;
  padding: 0 .75rem;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .875rem;
  overflow-wrap: anywhere;
}
.day { margin-bottom: 1rem; }
.day-head { font-size: .875rem; font-weight: 600; color: var(--muted); margin: 0 0 .375rem; }
.txn-rows { margin: 0; gap: .375rem; }
.txn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 56px;
  padding: .5rem .75rem;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
}
.txn-main { display: grid; min-width: 0; }
.txn-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-meta { font-size: .8125rem; }
.txn-row .amount { font-weight: 600; }
.empty-state { margin: 2rem 0; text-align: center; }

/* Home: month selector, ownership toggle, summary cards, strips. */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.month-label { flex: 1; text-align: center; font-size: 1.25rem; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  font-size: 1.5rem;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
}
.icon-btn.disabled { opacity: .35; }
.month-jump summary { min-height: 44px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); font-size: .875rem; }
.inline-form { display: flex; gap: .5rem; justify-content: center; margin-bottom: .5rem; }
.segmented { display: flex; flex-wrap: wrap; gap: .25rem; margin: .25rem 0 1rem; padding: .25rem; background: var(--surface); border: 1px solid var(--border); border-radius: .5rem; }
.segmented a {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 .75rem;
  color: inherit;
  text-decoration: none;
  border-radius: .375rem;
  overflow-wrap: anywhere;
}
.segmented a.active { background: var(--accent); color: var(--bg); font-weight: 600; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: 1.5rem; }
.card { padding: .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: .5rem; min-width: 0; }
.card-wide { grid-column: 1 / -1; }
.card p { margin: 0; }
.card-label { font-size: .8125rem; color: var(--muted); }
.card-figure { font-size: clamp(1.0625rem, 5vw, 1.5rem); font-weight: 600; }
.card-sub { font-size: .9375rem; }
.section-head { margin: 1.25rem 0 .5rem; }
.rows { margin: 0 0 .5rem; gap: .25rem; }
.row { display: flex; justify-content: space-between; gap: 1rem; min-height: 40px; align-items: center; border-bottom: 1px solid var(--border); }
.compare { width: 100%; border-collapse: collapse; font-size: .9375rem; }
.compare th, .compare td { padding: .375rem .25rem; text-align: right; border-bottom: 1px solid var(--border); }
.compare th[scope="row"] { text-align: left; font-weight: 400; }
.compare thead th { font-size: .8125rem; font-weight: 400; color: var(--muted); }
.strip { list-style: none; margin: 0 0 .5rem; padding: 0 0 .25rem; display: flex; gap: .5rem; overflow-x: auto; }
.strip-item {
  display: grid;
  min-width: 8rem;
  min-height: 56px;
  padding: .5rem .75rem;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
}

/* Add chooser and quick amount. */
.add-choices { gap: .5rem; }
.add-choice {
  display: grid;
  gap: .125rem;
  min-height: 64px;
  align-content: center;
  padding: .5rem .75rem;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
}
.add-title { font-weight: 600; }
.add-secondary { margin-top: .75rem; }
.quick-form { grid-template-columns: minmax(0, 1fr); }
.quick-amount { width: 100%; min-width: 0; font-size: 1.75rem; font-variant-numeric: tabular-nums; }
.quick-defaults { display: grid; gap: .5rem; }
.quick-defaults p { margin: 0; }
.quick-defaults label { display: grid; gap: .25rem; }

/* Transfers in lists: dashed and labelled, never income-coloured. */
.txn-row.transfer { border-style: dashed; }
.txn-row.transfer .amount { font-weight: 400; color: var(--muted); }
.account-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* Receipt scan. Uncertain fields are marked amber and say "Check" in
   words; nothing turns red unless it is an actual error. */
.btn-secondary { color: var(--text); background: var(--surface); border: 1px solid var(--border); }
.scan-preview { display: block; max-width: 100%; max-height: 40vh; margin: .5rem 0; object-fit: contain; border: 1px solid var(--border); border-radius: .5rem; }
.scan-preview[hidden] { display: none; }
.scan-pick { display: grid; gap: .5rem; }
.scan-pick input[type="file"] { min-height: 44px; }
.scan-busy { display: none; margin: 0; }
.scan-form.htmx-request .scan-busy { display: block; }
.import-form { display: grid; gap: .75rem; justify-items: start; }
.import-busy { display: none; margin: 0; }
.import-form.htmx-request .import-busy { display: block; }
.scan-job { display: grid; gap: .75rem; }
.scan-status { margin: 0; font-weight: 600; }
.scan-review h2 { margin-bottom: .25rem; }
.scan-note { margin: 0; padding: .25rem .5rem; font-size: .875rem; color: var(--text); background: var(--warn-bg); border-left: 3px solid var(--warn); border-radius: .25rem; }
.low-confidence input, .low-confidence select { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn); }
.flag { display: inline-block; padding: 0 .375rem; font-size: .75rem; font-weight: 600; color: var(--warn); border: 1px solid var(--warn); border-radius: .25rem; }
.line-items summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--muted); }
.line-items ul { margin: .25rem 0 0; gap: .25rem; }
.line-item { display: flex; justify-content: space-between; gap: 1rem; font-size: .875rem; overflow-wrap: anywhere; }
.scan-actions { margin-top: .5rem; }

/* Plans (docs/02 §Plans): each rule is a disclosure row that opens to
   its edit form, so the tab works without JS. */
.recurring-list { gap: .5rem; }
.recurring-rule > summary { list-style: none; cursor: pointer; }
.recurring-rule > summary::-webkit-details-marker { display: none; }
.recurring-rule[open] > summary { margin-bottom: .5rem; }
.add-recurring { margin: 1rem 0; }
.add-recurring > summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--accent); }
.suggestion-list { gap: .5rem; }
.suggestion { display: grid; gap: .25rem; }
.suggestion-actions { display: flex; align-items: center; gap: 1rem; margin-top: .25rem; }
.upcoming-list { gap: .5rem; }
.upcoming-item { display: flex; align-items: center; justify-content: space-between; gap: 1rem; width: 100%; min-height: 44px; color: inherit; text-decoration: none; }
.suggestion-note { margin: 0 0 .5rem; }
.confirm-occurrence { display: grid; gap: .25rem; justify-items: start; margin: .25rem 0 0 .75rem; }
/* Five nav items (docs/02 §Global navigation) must fit a 320px phone. */
.bottom-nav a { min-width: 0; font-size: .6875rem; }
.bottom-nav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Loading and failure feedback (web/static/app.js). The bar appears only
   if a request outlasts a moment, so quick swaps do not flicker. */
body.is-loading::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 20;
  height: 3px;
  background: var(--accent);
  transform-origin: left;
  animation: busy-in .2s linear .3s backwards, busy-run 1.2s ease-in-out .3s infinite;
}
@keyframes busy-in { from { opacity: 0; } }
@keyframes busy-run { 0% { transform: scaleX(.05); } 60% { transform: scaleX(.8); } 100% { transform: scaleX(1); opacity: .4; } }
form.htmx-request button[type="submit"] { opacity: .6; cursor: progress; }
a.htmx-request, .icon-btn.htmx-request { opacity: .6; }
.toast {
  position: fixed;
  inset: auto 16px calc(var(--nav-h) + .75rem + env(safe-area-inset-bottom)) 16px;
  z-index: 30;
  max-width: 36rem;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem 3rem .75rem .75rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid #b91c1c;
  border-radius: .5rem;
  box-shadow: 0 2px 8px rgb(0 0 0 / .15);
}
.toast[hidden] { display: none; }
.toast-close {
  position: absolute;
  inset: 0 0 0 auto;
  width: 44px;
  font-size: 1.5rem;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
/* Error pages (docs/02 §Error behavior) and empty states share a calm look. */
.error { margin: 2rem 0; }

/* Accessibility (docs/02 §Accessibility, docs/12 §Motion). */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
main:focus { outline: none; }
.skip-link {
  position: absolute;
  inset: .5rem auto auto 16px;
  z-index: 40;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 1rem;
  color: var(--bg);
  background: var(--accent);
  border-radius: .5rem;
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }
/* The current page is marked by weight and a bar, not by colour alone. */
.bottom-nav a[aria-current="page"] { font-weight: 700; box-shadow: inset 0 3px 0 var(--accent); }
[data-focus-target]:focus { outline: none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
  body.is-loading::before { transform: none; opacity: .6; }
}

/* Settings sections. */
.facts { display: grid; gap: .25rem; margin: 1rem 0; }
.facts dt { font-weight: 600; margin-top: .75rem; }
.facts dd { margin: 0; }
.device-row { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.recovery-codes { list-style: none; padding: 0; display: grid; gap: .25rem; font-size: 1.0625rem; }
.recovery-codes code { user-select: all; }
