:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #15181d;
  --muted: #5f6673;
  --line: #e2e5ea;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --pos: #15803d;
  --neg: #b91c1c;
  --danger: #b91c1c;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1f242c; --text: #eceff3; --muted: #9aa3b0; --line: #2a3038;
    --accent: #2dd4bf; --accent-ink: #06201d; --pos: #4ade80; --neg: #f87171; --danger: #f87171;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #171b21; --surface-2: #1f242c; --text: #eceff3; --muted: #9aa3b0; --line: #2a3038;
  --accent: #2dd4bf; --accent-ink: #06201d; --pos: #4ade80; --neg: #f87171; --danger: #f87171;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { overflow-x: hidden; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.app { min-height: 100dvh; display: flex; flex-direction: column; }
.content {
  flex: 1; width: 100%; max-width: 760px; margin: 0 auto; min-width: 0;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
}
.page-head { margin: 4px 0 14px; }
.page-head.nav-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; text-align: center; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line); z-index: 20;
}
.bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 0.7rem; color: var(--muted); }
.bottom-nav a .ico { font-size: 1.3rem; line-height: 1; }
.bottom-nav a.active { color: var(--accent); }
.bottom-nav a.add .ico { background: var(--accent); color: var(--accent-ink); border-radius: 999px; width: 34px; height: 34px; display: grid; place-items: center; font-weight: 600; }

.hero { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.stat.big { grid-column: 1 / -1; }
.stat .label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value { font-size: 1.35rem; font-weight: 600; }
.stat.big .value { font-size: 2.2rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li + li { border-top: 1px solid var(--line); }
.rows li.group { border-top: none; padding: 10px 0 4px; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.rows.compact .row { padding: 8px 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; width: 100%; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.row .main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 0.8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.row .amt { font-weight: 600; white-space: nowrap; }
.row .amt-stack { display: flex; flex-direction: column; align-items: flex-end; }
.row .chev { color: var(--muted); font-size: 1.3rem; }
.link { color: var(--accent); font-size: 0.9rem; display: inline-block; margin-top: 6px; }

.grid { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.grid th, .grid td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.grid th { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.grid .num { text-align: right; white-space: nowrap; }
.grid tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.detail { background: var(--surface-2); border-radius: 10px; padding: 6px 12px 10px; margin: 0 0 10px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form.inline { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--muted); flex: 1; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 0.95rem; color: var(--text); }
input, select, button { font: inherit; }
input:not([type="checkbox"]), select {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); color: var(--text); font-size: 1rem; min-height: 46px;
}
input[type="number"] { font-size: 1.25rem; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.filter-row { display: flex; gap: 8px; }
.filter-row > * { flex: 1; min-width: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 500;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn.icon { width: 46px; padding: 0; font-size: 1.4rem; }
.btn:disabled { opacity: 0.5; cursor: default; }

.segmented { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 12px; gap: 2px; }
.segmented button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 10px 6px; border-radius: 8px; cursor: pointer; font-weight: 500; }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.15); }
.segmented.small button { padding: 8px 4px; font-size: 0.85rem; }

.alert { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.toast { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }

/* sign-in page (served by the server, outside the app shell) */
.login-body { display: grid; place-items: center; min-height: 100dvh; margin: 0; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.login-card h1 { margin-bottom: 16px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--muted); }
.login-card .error { color: var(--danger); }
.login-card .error[hidden] { display: none; }
.login-card .btn.primary { width: 100%; }
.login-card p.muted { margin-top: 16px; }

@media (min-width: 640px) {
  .hero { grid-template-columns: repeat(3, 1fr); }
  .stat.big { grid-column: span 3; }
}
