:root {
  --bg:#0f1115; --surface:#181b21; --surface-2:#20242c; --line:#2a2f39;
  --text:#e7e9ee; --muted:#8b919e; --accent:#4cc38a; --danger:#e5685f; --radius:12px;
}
@media (prefers-color-scheme: light) {
  :root { --bg:#f5f6f8; --surface:#fff; --surface-2:#f0f2f5; --line:#e2e5ea;
    --text:#1a1d23; --muted:#6b7280; }
}
* { box-sizing:border-box; }
body { margin:0; background:var(--bg); color:var(--text);
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
  -webkit-font-smoothing:antialiased; line-height:1.5; }
.hidden { display:none !important; }
.muted { color:var(--muted); font-size:14px; }
.err { color:var(--danger); font-size:14px; }
.brand { font-weight:600; letter-spacing:-0.02em; }

button { font:inherit; cursor:pointer; border:none; border-radius:8px; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline:2px solid var(--accent); outline-offset:1px; }
input, select { font:inherit; color:var(--text); background:var(--surface-2);
  border:1px solid var(--line); border-radius:8px; padding:11px 12px; width:100%; }
.primary { background:var(--accent); color:#07150e; font-weight:600; padding:12px 16px; width:100%; }
.ghost { background:transparent; color:var(--muted); padding:6px 10px; }

.login { min-height:100dvh; display:grid; place-items:center; padding:24px; }
.login-card { background:var(--surface); border:1px solid var(--line); border-radius:var(--radius);
  padding:28px; width:100%; max-width:340px; display:grid; gap:12px; }
.login-card h1 { margin:0; font-size:28px; }
.login-card .muted { margin:-6px 0 6px; }

#app { max-width:640px; margin:0 auto; padding:0 16px 48px;
  padding-bottom:calc(48px + env(safe-area-inset-bottom)); }
.topbar { display:flex; align-items:center; gap:12px; padding:14px 0;
  position:sticky; top:0; background:var(--bg); z-index:5; }
.topbar .brand { font-size:18px; }
.tabs { margin-left:auto; display:flex; gap:4px; background:var(--surface-2); padding:4px; border-radius:8px; }
.tabs button { background:transparent; color:var(--muted); padding:6px 14px; }
.tabs button.active { background:var(--surface); color:var(--text); font-weight:600; }

.cards { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-bottom:16px; }
.card { background:var(--surface); border:1px solid var(--line); border-radius:var(--radius);
  padding:14px; display:grid; gap:4px; }
.card-label { font-size:12px; color:var(--muted); }
.card-value { font-size:20px; font-weight:600; }
.card.income .card-value { color:var(--accent); }
.card.expense .card-value { color:var(--danger); }

.block { background:var(--surface); border:1px solid var(--line); border-radius:var(--radius);
  padding:16px; margin-bottom:14px; }
.section-title { font-size:14px; color:var(--muted); font-weight:500; margin:0 0 12px; }
.block .primary { margin-top:4px; }

.pill-list { list-style:none; margin:0; padding:0; display:grid; gap:8px; }
.pill { display:flex; align-items:center; justify-content:space-between; gap:10px;
  background:var(--surface-2); border-radius:10px; padding:10px 12px; }
.pill b { font-weight:600; white-space:nowrap; }
.tag { font-style:normal; font-size:11px; color:var(--muted); background:var(--surface);
  padding:1px 6px; border-radius:6px; margin-left:4px; }

.kind-toggle { display:grid; grid-template-columns:1fr 1fr; gap:6px;
  background:var(--surface-2); padding:4px; border-radius:8px; margin-bottom:12px; }
.kind-toggle button { background:transparent; color:var(--muted); padding:8px; }
.kind-toggle button.active { background:var(--surface); color:var(--text); font-weight:600; }
.add-row { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-bottom:10px; }
.add-row:has(> :only-child) { grid-template-columns:1fr; }

.list ul, #txList { list-style:none; margin:0; padding:0; display:grid; gap:8px; }
#txList { list-style:none; margin:0; padding:0; display:grid; gap:8px; }
.tx { display:flex; align-items:center; gap:12px; background:var(--surface-2);
  border-radius:10px; padding:11px 13px; }
.tx-main { display:grid; gap:2px; min-width:0; }
.tx-cat { font-weight:500; }
.tx-meta { font-size:12px; color:var(--muted); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.tx-amount { margin-left:auto; font-weight:600; white-space:nowrap; }
.tx-amount.income, .tx-amount.allocation { color:var(--accent); }
.tx-amount.expense { color:var(--danger); }
.tx-src { font-size:11px; padding:1px 6px; border-radius:6px; background:var(--surface); color:var(--muted); }
.rule-list { list-style:none; margin:14px 0 0; padding:0; display:grid; gap:8px; }
