:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --card-2: #f8f7f4;
  --text: #1d2321;
  --muted: #6b7470;
  --line: #e4e1da;
  --brand: #2f7d6d;
  --brand-soft: #dcefe9;
  --ok: #2f8f5b;
  --warn: #c7811b;
  --warn-soft: #fbefd9;
  --bad: #c9433f;
  --bad-soft: #fbe3e1;
  --track: #ebe8e1;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121615; --card: #1b2120; --card-2: #222927; --text: #e8ecea; --muted: #97a29e; --line: #2c3432;
    --brand: #5cc2a8; --brand-soft: #1d3a33; --ok: #5cc28a; --warn: #e8a64a; --warn-soft: #3a2e1a;
    --bad: #ef7a72; --bad-soft: #3d2221; --track: #2a3230; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121615; --card: #1b2120; --card-2: #222927; --text: #e8ecea; --muted: #97a29e; --line: #2c3432;
  --brand: #5cc2a8; --brand-soft: #1d3a33; --ok: #5cc28a; --warn: #e8a64a; --warn-soft: #3a2e1a;
  --bad: #ef7a72; --bad-soft: #3d2221; --track: #2a3230; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

/* layout */
.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
header.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 0 10px;
}
.month-nav { display: flex; align-items: center; gap: 4px; flex: 1; }
.month-nav h1 { font-size: 18px; margin: 0; flex: 1; text-align: center; }
.icon-btn {
  border: 0; background: var(--card); width: 40px; height: 40px; border-radius: 12px; cursor: pointer;
  display: grid; place-items: center; font-size: 18px; box-shadow: var(--shadow);
}
.icon-btn:disabled { opacity: .35; cursor: default; }
.demo-banner { background: var(--warn-soft); color: var(--text); border-radius: 12px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h2 small { font-weight: 400; color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.stack > * + * { margin-top: 8px; }

/* hero */
.hero { background: var(--brand); color: #fff; }
:root[data-theme="dark"] .hero { color: #0d1513; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hero { color: #0d1513; } }
.hero .label { opacity: .85; font-size: 13px; }
.hero .big { font-size: 34px; font-weight: 700; letter-spacing: -.5px; margin: 2px 0 6px; }
.hero .sub { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; opacity: .92; }
.hero .safe { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: rgba(255,255,255,.16); font-size: 14px; }

.notice { border-radius: 12px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; display: flex; gap: 8px; align-items: center; }
.notice.bad { background: var(--bad-soft); }
.notice.warn { background: var(--warn-soft); }
.notice.info { background: var(--brand-soft); }
.notice .grow { flex: 1; }

/* quick actions */
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.quick button { border: 0; background: var(--card); border-radius: 14px; padding: 10px 6px; cursor: pointer; box-shadow: var(--shadow); font-size: 13px; }
.quick button span { display: block; font-size: 20px; margin-bottom: 2px; }

/* categories */
.cat { padding: 12px 0; border-top: 1px solid var(--line); cursor: pointer; }
.cat:first-of-type { border-top: 0; padding-top: 4px; }
.cat-head { display: flex; align-items: center; gap: 10px; }
.cat-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 18px; flex: none; }
.cat-name { font-weight: 600; }
.cat-meta { font-size: 13px; color: var(--muted); }
.cat-left { font-weight: 700; text-align: right; }
.cat-left small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.bar { height: 8px; background: var(--track); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--ok); transition: width .3s; }
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }
.over { color: var(--bad); }
.warn-text { color: var(--warn); }
.ok-text { color: var(--ok); }
.chip-btn { border: 0; background: var(--bad-soft); color: var(--bad); border-radius: 99px; padding: 4px 10px; font-size: 12px; font-weight: 600; cursor: pointer; }

/* fixed payments */
.fixed-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.fixed-item:first-of-type { border-top: 0; }
.pay-btn { border: 1.5px solid var(--brand); color: var(--brand); background: transparent; border-radius: 99px; padding: 5px 12px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.pay-btn.paid { background: var(--brand); color: var(--card); }

/* lists */
.tx { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.tx:first-child { border-top: 0; }
.tx .amt { font-weight: 600; white-space: nowrap; }
.day-label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 4px 6px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 4px; margin-bottom: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 6px 12px; font-size: 13px; white-space: nowrap; cursor: pointer; }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--card); }
.cat-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cat-pick button { border: 1.5px solid var(--line); background: var(--card-2); border-radius: 12px; padding: 10px 4px; cursor: pointer; font-size: 12px; line-height: 1.2; }
.cat-pick button span { display: block; font-size: 20px; margin-bottom: 3px; }
.cat-pick button.on { border-color: var(--brand); background: var(--brand-soft); font-weight: 600; }
.cat-pick button small { display: block; color: var(--muted); margin-top: 2px; font-size: 11px; }

/* forms */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input.in, select.in, textarea.in {
  width: 100%; border: 1.5px solid var(--line); background: var(--card-2); border-radius: 12px; padding: 10px 12px; outline: none;
}
input.in:focus, select.in:focus { border-color: var(--brand); }
input.amount { font-size: 30px; font-weight: 700; text-align: center; padding: 12px; }
.btn { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; cursor: pointer; background: var(--brand); color: var(--card); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--card-2); color: var(--text); border: 1.5px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; gap: 8px; margin-top: 12px; }
.btns > * { flex: 1; }
.edit-row { display: grid; grid-template-columns: 44px 1fr 110px 32px; gap: 6px; align-items: center; margin-bottom: 8px; }
.edit-row.fx { grid-template-columns: 1fr 96px 110px 32px; }
.edit-row input, .edit-row select { padding: 8px; }
.edit-row .x { border: 0; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.total-line { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px dashed var(--line); font-size: 14px; }
.seg { display: flex; background: var(--card-2); border-radius: 12px; padding: 3px; margin-bottom: 12px; border: 1px solid var(--line); }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--card); box-shadow: var(--shadow); font-weight: 600; }

/* bottom nav + add button */
nav.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom);
}
nav.bottom .inner { display: grid; grid-template-columns: repeat(5, 1fr); max-width: 560px; width: 100%; }
nav.bottom button { border: 0; background: transparent; padding: 8px 0 10px; font-size: 11px; color: var(--muted); cursor: pointer; }
nav.bottom button span { display: block; font-size: 20px; }
nav.bottom button.on { color: var(--brand); font-weight: 600; }
.fab {
  position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 7;
  width: 60px; height: 60px; border-radius: 20px; border: 0; background: var(--brand); color: var(--card);
  font-size: 30px; cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,.2);
}

/* sheet (pop-up from bottom) */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 10px; }
.sheet h3 { margin: 0 0 14px; font-size: 18px; display: flex; justify-content: space-between; align-items: center; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* toast */
#toast-root { position: fixed; left: 0; right: 0; top: calc(12px + env(safe-area-inset-top)); z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 520px; box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: up .2s; }
.toast.warn { background: var(--warn); color: #1d1405; }
.toast.bad { background: var(--bad); color: #fff; }

/* charts */
.donut-wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.donut-wrap svg { width: 150px; height: 150px; flex: none; }
.legend { flex: 1; min-width: 160px; font-size: 13px; }
.legend div { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 8px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; font-size: 11px; color: var(--muted); }
.bars .pair { display: flex; align-items: flex-end; gap: 3px; height: 110px; width: 100%; justify-content: center; }
.bars .pair i { width: 40%; max-width: 18px; border-radius: 5px 5px 0 0; background: var(--track); }
.bars .pair i.s { background: var(--brand); }
.bars .pair i.s.over { background: var(--bad); }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th, table.t td { padding: 6px 4px; border-top: 1px solid var(--line); text-align: right; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t th { color: var(--muted); font-weight: 500; border-top: 0; }
.scroll-x { overflow-x: auto; }

details.card summary { cursor: pointer; list-style: none; }
details.card summary::before { content: '▸ '; color: var(--muted); }
details.card[open] summary::before { content: '▾ '; }
details.card .card { box-shadow: none; border: 1px solid var(--line); }

/* login + splash */
.splash, .login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 8px; }
.login .logo { width: 84px; height: 84px; border-radius: 24px; }
.login h1 { margin: 8px 0 0; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--track); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
