:root {
  --bg: #f4f5f7; --card: #ffffff; --ink: #0f172a; --muted: #64748b; --line: #e5e7eb;
  --accent: #0f172a; --pos: #059669; --neg: #0f172a; --warn: #d97706; --bad: #dc2626;
  --save: #2563eb; --chip: #eef0f3; --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b0f17; --card: #151b26; --ink: #e6e9ef; --muted: #8b95a7; --line: #263042;
          --accent: #e6e9ef; --neg: #e6e9ef; --chip: #1e2633; --pos: #34d399; --save: #60a5fa; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(var(--safe-t) + 10px) 18px 8px; display: flex; align-items: center; justify-content: space-between; }
.topbar h1 { font-size: 26px; margin: 0; letter-spacing: -.02em; }
main { padding: 4px 14px calc(96px + var(--safe-b)); max-width: 760px; margin: 0 auto; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around;
  align-items: center; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 6px 6px calc(6px + var(--safe-b)); }
.tabbar button { background: none; border: 0; display: flex; flex-direction: column; align-items: center;
  font-size: 11px; color: var(--muted); padding: 4px 10px; min-width: 60px; }
.tabbar button .ti { font-size: 20px; line-height: 1.1; }
.tabbar button.active { color: var(--ink); font-weight: 600; }
.tabbar .add { width: 52px; height: 52px; min-width: 52px; border-radius: 50%; background: var(--accent); color: var(--bg);
  font-size: 30px; line-height: 1; font-weight: 300; box-shadow: 0 4px 14px rgba(0,0,0,.18); margin-top: -18px; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin: 10px 0;
  box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.monthnav { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 6px; }
.monthnav button { background: var(--card); border: 0; border-radius: 10px; width: 38px; height: 34px; font-size: 18px; }
.monthnav strong { font-size: 17px; text-transform: capitalize; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.kpi { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.kpi .l { font-size: 12.5px; color: var(--muted); }
.kpi .v { font-size: 21px; font-weight: 650; letter-spacing: -.01em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi.big { grid-column: span 2; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .save { color: var(--save); } .bad { color: var(--bad); }

.bar { height: 7px; background: var(--chip); border-radius: 6px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--pos); border-radius: 6px; }
.bar.warn > i { background: var(--warn); } .bar.over > i { background: var(--bad); }

.group { padding: 10px 0; border-top: 1px solid var(--line); }
.group:first-of-type { border-top: 0; }
.group .icon { width: 34px; height: 34px; border-radius: 10px; background: var(--chip); display: grid; place-items: center; font-size: 17px; flex: none; }
.group .sub { margin: 8px 0 0 44px; }
.group .sub .row { padding: 3px 0; font-size: 13.5px; }
.amt { font-variant-numeric: tabular-nums; white-space: nowrap; }

.alert { background: color-mix(in srgb, var(--warn) 14%, var(--card)); color: var(--ink); border-radius: 12px;
  padding: 10px 14px; margin: 10px 0; display: flex; justify-content: space-between; align-items: center; border: 0; width: 100%; text-align: left; }

.txday { font-size: 12.5px; color: var(--muted); margin: 14px 4px 4px; text-transform: capitalize; }
.tx { display: flex; gap: 12px; align-items: center; padding: 10px 12px; background: var(--card); border: 0; width: 100%; text-align: left; }
.txlist .tx:first-child { border-radius: 14px 14px 0 0; }
.txlist .tx:last-child { border-radius: 0 0 14px 14px; }
.txlist .tx:only-child { border-radius: 14px; }
.txlist .tx + .tx { border-top: 1px solid var(--line); }
.txlist { border-radius: 14px; overflow: hidden; }
.tx .icon { width: 36px; height: 36px; border-radius: 10px; background: var(--chip); display: grid; place-items: center; font-size: 17px; flex: none; }
.badge { display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 6px; background: var(--chip); color: var(--muted); margin-left: 4px; vertical-align: 1px; }

.search { display: flex; gap: 8px; margin: 6px 0; }
.search input, .search select { flex: 1; min-width: 0; }
input, select, textarea { background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 0; }
label.f { display: block; margin: 10px 0; }
label.f > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.chip { border: 0; background: var(--chip); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.chip.on { background: var(--accent); color: var(--bg); }

.btn { border: 0; background: var(--accent); color: var(--bg); border-radius: 12px; padding: 11px 16px; font-weight: 600; cursor: pointer; }
.btn.ghost { background: var(--chip); color: var(--ink); }
.btn.danger { background: transparent; color: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.link { background: none; border: 0; color: var(--save); padding: 0; cursor: pointer; }

.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--bg); border-radius: 20px 20px 0 0;
  max-height: 92vh; overflow: auto; padding: 8px 16px calc(18px + var(--safe-b)); max-width: 640px; margin: 0 auto;
  box-shadow: 0 -10px 40px rgba(0,0,0,.2); }
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.amountInput { font-size: 36px; font-weight: 650; text-align: center; border: 0; background: transparent; padding: 6px; font-variant-numeric: tabular-nums; }
.seg { display: flex; background: var(--chip); border-radius: 11px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px; border-radius: 9px; font-size: 14px; }
.seg button.on { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(92px + var(--safe-b)); z-index: 30;
  background: var(--accent); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; }

table.prev { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.prev td, table.prev th { padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.prev td.amt, table.prev th.amt { text-align: right; }
.scrollx { overflow-x: auto; }

.chart { width: 100%; height: 150px; display: block; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }

details.set { background: var(--card); border-radius: var(--radius); margin: 10px 0; padding: 0 16px; }
details.set > summary { list-style: none; padding: 14px 0; font-weight: 600; cursor: pointer; display: flex; justify-content: space-between; }
details.set > summary::-webkit-details-marker { display: none; }
details.set > summary::after { content: '›'; color: var(--muted); transition: transform .2s; }
details.set[open] > summary::after { transform: rotate(90deg); }
details.set > .body { padding-bottom: 14px; }
.list .row { padding: 8px 0; border-top: 1px solid var(--line); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
code { background: var(--chip); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; word-break: break-all; }
