:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #14201d;
  --muted: #64736f;
  --line: #e3e8e6;
  --accent: #0f766e;
  --accent-soft: #d8efec;
  --warn: #b45309;
  --bad: #b91c1c;
  --good: #15803d;
  --track: #e7ecea;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1412; --card: #16201d; --ink: #e8efec; --muted: #93a39e; --line: #26332f;
    --accent: #2dd4bf; --accent-soft: #123a35; --warn: #f59e0b; --bad: #f87171; --good: #4ade80; --track: #22302c;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.err { color: var(--bad); min-height: 1em; margin: 4px 0; font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* layout */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
}
main { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 .card { margin-bottom: 0; }
.grid2 + .card { margin-top: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.gap { display: flex; gap: 8px; }

/* hero */
.hero .label, .stat .label { font-size: 12px; color: var(--muted); }
.big { font-size: 34px; font-weight: 700; letter-spacing: -0.5px; font-variant-numeric: tabular-nums; }
.mid { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.hero-row { display: flex; justify-content: space-between; align-items: center; }
.hero-meta { margin-top: 8px; font-size: 13px; color: var(--muted); }
.ring {
  --p: 0; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--track) 0);
}
.ring span { width: 50px; height: 50px; border-radius: 50%; background: var(--card); display: grid; place-items: center; font-size: 13px; font-weight: 600; }
.ring.over { background: conic-gradient(var(--bad) 100%, var(--track) 0); }
.bar { height: 8px; border-radius: 99px; background: var(--track); overflow: hidden; margin-top: 12px; }
.bar > div { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .3s; }
.bar.warn > div { background: var(--warn); }
.bar.over > div { background: var(--bad); }

/* category rows */
.cat { padding: 8px 0; border-top: 1px solid var(--line); }
.cat:first-child { border-top: 0; }
.cat .bar { height: 6px; margin-top: 6px; }
.cat .row-between span:last-child { font-variant-numeric: tabular-nums; font-size: 13px; }

/* lists */
.tx, .bill { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.tx:first-child, .bill:first-child { border-top: 0; }
.tx .main, .bill .main { flex: 1; min-width: 0; }
.tx .title, .bill .title { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .sub, .bill .sub { font-size: 12px; color: var(--muted); }
.tx .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt.in { color: var(--good); }
.day { font-size: 12px; font-weight: 600; color: var(--muted); padding: 12px 0 2px; text-transform: uppercase; letter-spacing: .3px; }
.group-h { font-size: 12px; font-weight: 700; color: var(--accent); padding: 14px 0 2px; text-transform: uppercase; letter-spacing: .4px; }
.check {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line); background: transparent; flex: none;
  display: grid; place-items: center; color: #fff; font-size: 15px; cursor: pointer;
}
.check.on { background: var(--accent); border-color: var(--accent); }
.bill.paid .title { color: var(--muted); text-decoration: line-through; }
.pot { background: var(--accent-soft); border-radius: 12px; padding: 12px; margin-bottom: 8px; display: flex; gap: 12px; align-items: center; }
.pot .main { flex: 1; }
.due-soon { color: var(--warn); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }

/* chips */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 4px; scrollbar-width: none; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 99px; padding: 5px 12px; font: inherit; font-size: 13px; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* year table */
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tr.total td { font-weight: 700; border-bottom: 0; }
.neg { color: var(--bad); }

/* buttons + forms */
.btn {
  font: inherit; font-weight: 600; border-radius: 12px; padding: 11px 16px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; text-align: center;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.full { width: 100%; margin-top: 10px; }
.btn.danger { color: var(--bad); }
.icon-btn { font-size: 26px; line-height: 1; width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; color: var(--ink); cursor: pointer; }
.form { display: flex; flex-direction: column; gap: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
input, select {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%; font-weight: 400;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.budget-row { display: grid; grid-template-columns: 1fr 110px; gap: 10px; align-items: center; padding: 4px 0; font-size: 14px; }

/* bottom tabs */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabs button { font: inherit; font-size: 11px; background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; cursor: pointer; }
.tabs button span { font-size: 19px; line-height: 1.1; }
.tabs button.active { color: var(--accent); font-weight: 600; }
.tabs .add span {
  width: 48px; height: 48px; margin-top: -18px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 26px; box-shadow: 0 4px 14px rgba(15, 118, 110, .35);
}

/* sheets */
.sheet {
  width: 100%; max-width: 560px; border: 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0; margin: auto auto 0; background: var(--card); color: var(--ink); max-height: 92vh;
}
.sheet::backdrop { background: rgba(0, 0, 0, .45); }
@media (min-width: 640px) { .sheet { border-radius: 20px; margin: auto; } }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bg); border-radius: 12px; padding: 3px; }
.seg button { font: inherit; font-weight: 600; border: 0; background: transparent; color: var(--muted); padding: 8px; border-radius: 10px; cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.amount { font-size: 34px !important; font-weight: 700; text-align: center; border: 0 !important; background: transparent !important; }
.cat-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-grid button { font: inherit; font-size: 13px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 99px; padding: 6px 12px; cursor: pointer; }
.cat-grid button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.logo { width: 64px; height: 64px; margin: 0 auto; border-radius: 18px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 32px; font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.pot .check { border-color: var(--accent); }
