:root {
  --bg: #f4f6f5; --card: #ffffff; --text: #17201c; --muted: #5d6b65; --line: #dde3e0;
  --brand: #1f7a5a; --brand-ink: #ffffff; --out: #c0392b; --in: #1f7a5a; --warn: #d68910;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #101513; --card: #19201d; --text: #e7eeeb; --muted: #9aa8a2; --line: #2a3430;
    --brand: #3fb98a; --brand-ink: #08130e; --out: #ff7b6b; --in: #3fb98a; --warn: #f5b041; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* labels/rows set display, which would beat the attribute */
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
button, input, select { font: inherit; color: inherit; }
.top { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; background: var(--brand); color: var(--brand-ink); }
.top h1 { font-size: 1.1rem; margin: 0; font-weight: 600; }
.month-btn { background: none; border: 0; color: inherit; font-size: 1.6rem; width: 44px; height: 44px; border-radius: 22px; cursor: pointer; }
.month-btn:hover { background: rgb(255 255 255 / .15); }
main { max-width: 760px; margin: 0 auto; padding: 16px 16px 72px; } /* room so the + button never covers the last row */
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 2; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; text-align: center; padding: 14px 2px; color: var(--muted); text-decoration: none; font-size: .82rem; font-weight: 500; }
.tabs a[aria-current="page"] { color: var(--brand); box-shadow: inset 0 3px 0 var(--brand); }
.fab { position: fixed; right: 18px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 3; width: 58px; height: 58px; border-radius: 29px;
  border: 0; background: var(--brand); color: var(--brand-ink); font-size: 2rem; line-height: 1; box-shadow: 0 4px 14px rgb(0 0 0 / .25); cursor: pointer; }

.signed-out .fab, .signed-out .tabs, .signed-out .month-btn { display: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 14px; }
.card h2 { font-size: .95rem; margin: 0 0 10px; color: var(--muted); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat b { display: block; font-size: 1.15rem; }
.stat span { color: var(--muted); font-size: .8rem; }
.row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .sub { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.row { width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; cursor: pointer; }
.dot { width: 12px; height: 12px; border-radius: 6px; flex: none; }
.amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.amt.out { color: var(--out); } .amt.in { color: var(--in); }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--brand); }
.bar.warn i { background: var(--warn); } .bar.over i { background: var(--out); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 18px; padding: 7px 14px; cursor: pointer; }
.day { margin: 14px 0 4px; font-size: .82rem; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); } .center { text-align: center; }
.btn { border: 0; border-radius: 10px; padding: 10px 16px; background: var(--brand); color: var(--brand-ink); font-weight: 600; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--out); border: 1px solid var(--line); }
.btn.small { padding: 6px 12px; font-size: .88rem; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.filters select { flex: 1; min-width: 120px; }
select, input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(480px, calc(100vw - 32px)); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { padding: 18px; display: grid; gap: 12px; }
dialog h3 { margin: 0; }
dialog label { display: grid; gap: 4px; font-size: .88rem; color: var(--muted); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; padding: 9px; background: none; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.actions .left { margin-right: auto; }
.error { color: var(--out); font-size: .9rem; margin: 0; }
#toast { position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 5;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: calc(100vw - 32px); }
@media (max-width: 420px) { .stat b { font-size: 1rem; } }
