/* Hand-written, mobile-first. Tokens on :root; dark mode via prefers-color-scheme. */
:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --line: #e2e2dc;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --done: #2e8b57;
  --done-bg: #e3f3ea;
  --partial-bg: #fbf1d9;
  --danger: #b3261e;
  --expense: #b3261e;
  --income: #2e7d32;
  --radius: 12px;
  --tap: 48px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1c1c1a;
    --text: #ecece6;
    --muted: #9a9a92;
    --line: #2e2e2b;
    --accent: #4fb39a;
    --accent-ink: #0d1f1a;
    --done: #5cc98a;
    --done-bg: #17321f;
    --partial-bg: #3a2f14;
    --danger: #f2827a;
    --expense: #f2827a;
    --income: #7fd08a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 560px; margin: 0 auto; padding: 12px 16px calc(84px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.5rem; margin: 8px 0 12px; }
h2 { font-size: 1.1rem; margin: 20px 0 8px; }
a { color: var(--accent); }
small { font-size: .8rem; }
.muted { color: var(--muted); }
.grow { flex: 1 1 auto; min-width: 0; }

/* Forms */
input, select, button { font: inherit; color: inherit; }
input, select {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: .9rem; color: var(--muted); }
label > input, label > select { margin-top: 4px; color: var(--text); font-size: 1rem; }
label.check { display: flex; gap: 8px; align-items: center; }
.amount { font-size: 1.6rem !important; font-variant-numeric: tabular-nums; }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); border-color: var(--danger); }
button:disabled, .btn.disabled { opacity: .35; cursor: default; }
button.icon { min-width: var(--tap); padding: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row > label { flex: 1 1 0; min-width: 0; }
form.inline { display: flex; gap: 4px; }
details > summary { cursor: pointer; min-height: 32px; font-weight: 600; }
details[open] > summary { margin-bottom: 8px; }
details.card:not([open]) { padding-block: 8px; }
details > summary { display: flex; align-items: center; }
details > summary::before { content: "▸"; margin-right: 8px; }
details[open] > summary::before { content: "▾"; }
details > summary::-webkit-details-marker { display: none; }
details > summary { list-style: none; }
.danger-zone { margin-top: 24px; }

/* Flash */
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 10px; background: var(--done-bg); }
.flash-error { background: var(--partial-bg); color: var(--danger); }

/* Bottom tab bar: thumb reach */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0; min-height: 56px; font-size: .75rem; color: var(--muted); text-decoration: none;
}
.tabbar a span { font-size: 1.1rem; }
.tabbar a.on { color: var(--accent); font-weight: 600; }

/* Day switcher */
.daybar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.daybar h1, .daybar h2 { margin: 0; text-align: center; flex: 1; }
.daybar .btn { min-width: var(--tap); padding: 0; }

/* Habits on /today */
.habits { display: grid; gap: 8px; margin: 12px 0; }
.habit { margin: 0; }
.habit-bool button, .habit-qty {
  width: 100%; min-height: 56px; display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-align: left; justify-content: flex-start;
}
.habit .name { flex: 1; color: var(--text); font-size: 1rem; }
.habit .name small { display: block; color: var(--muted); }
.habit .tick {
  width: 26px; height: 26px; flex: none; border-radius: 50%; border: 2px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center;
}
.habit.done .tick { background: var(--done); border-color: var(--done); }
.habit.done .tick::after { content: "✓"; color: var(--surface); font-weight: 700; font-size: .9rem; }
.habit.done button, .habit-qty.done { background: var(--done-bg); border-color: var(--done); }
.habit.busy { opacity: .6; }
.habit-qty input { width: 84px; flex: none; text-align: right; }
.habit-qty .unit { width: 52px; flex: none; color: var(--muted); font-size: .85rem; }
.streak { font-size: .8rem; color: var(--muted); white-space: nowrap; }

/* Kind tabs (radio buttons) */
.tabs { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.tabs input { position: absolute; opacity: 0; pointer-events: none; }
.tabs label {
  flex: 1; text-align: center; padding: 12px 4px; margin: 0; cursor: pointer;
  color: var(--text); font-size: .95rem; background: var(--surface);
}
.tabs label + input + label { border-left: 1px solid var(--line); }
.tabs input:checked + label { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.tabs input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -2px; }
.tabs input:disabled + label { opacity: .35; cursor: default; }

/* Show fields per kind with :has() — no JS needed. Expense is the default. */
.txn-form .only-income, .txn-form .only-transfer { display: none; }
.txn-form:has(input[value=income]:checked) .only-expense,
.txn-form:has(input[value=transfer]:checked) .only-expense { display: none; }
.txn-form:has(input[value=income]:checked) .only-income { display: block; }
.txn-form:has(input[value=transfer]:checked) .only-transfer { display: block; }
.txn-form span.only-income, .txn-form span.only-expense, .txn-form span.only-transfer { display: none; }
.txn-form:has(input[value=expense]:checked) span.only-expense,
.txn-form:has(input[value=income]:checked) span.only-income,
.txn-form:has(input[value=transfer]:checked) span.only-transfer { display: inline; }
.txn-form.same-currency .to-amount { display: none !important; }
.rate { display: block; margin-top: 4px; }
.habit-form .only-quantity { display: none; }
.habit-form:has(input[value=quantity]:checked) .only-quantity { display: flex; }

/* Money list */
.balances { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.bal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.bal span { display: block; font-size: .8rem; }
.bal strong { font-variant-numeric: tabular-nums; }
.bal.neg strong { color: var(--expense); }
.filters { margin-bottom: 12px; }
.txns, .list { list-style: none; margin: 0; padding: 0; }
.txns li { border-bottom: 1px solid var(--line); }
.txn { display: flex; gap: 10px; align-items: baseline; padding: 12px 2px; color: var(--text); text-decoration: none; }
.txn .date { width: 72px; flex: none; color: var(--muted); font-size: .8rem; }
.txn .what { flex: 1; min-width: 0; }
.txn .amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.txn .amt small { display: block; color: var(--muted); }
.txn-expense .amt { color: var(--expense); }
.txn-income .amt { color: var(--income); }
.note { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Generic list rows */
.item { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); min-height: 56px; }
.item a { color: var(--text); text-decoration: none; }
.item small { display: block; }

/* Month grid: scrolls inside its box, never the page */
.grid-scroll { overflow-x: auto; margin: 8px 0 4px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.grid { border-collapse: collapse; font-size: .75rem; font-variant-numeric: tabular-nums; }
.grid th, .grid td { padding: 0; text-align: center; border-bottom: 1px solid var(--line); min-width: 28px; height: 32px; }
.grid thead th { color: var(--muted); font-weight: 500; }
.grid tbody th { position: sticky; left: 0; background: var(--surface); text-align: left; padding: 0 8px; white-space: nowrap; font-weight: 500; }
.grid td a { display: block; line-height: 32px; color: var(--muted); text-decoration: none; }
.grid td.done { background: var(--done-bg); }
.grid td.done a { color: var(--done); font-weight: 700; }
.grid td.partial { background: var(--partial-bg); }
.grid .today { outline: 1px solid var(--accent); outline-offset: -1px; }
