@font-face {
  font-family: "DM Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/dm-sans-latin.woff2") format("woff2");
}

:root {
  --bg: #f4f1eb; --bg2: #ebe6dc; --card: #fffcf7; --ink: #1c1916; --muted: #6b645b; --line: #e2dbd0;
  --accent: #2f6f5e; --accent-ink: #fff; --accent-soft: #e4f0eb;
  --warn: #8a4f22; --warn-soft: #f7ebdd; --bad: #a33b3b; --bad-soft: #f6e4e2;
  --blue: #3d5a80; --blue-soft: #e5ecf5;
  --radius: 18px; --tap: 48px;
  --shadow: 0 1px 2px rgba(28,25,22,.04), 0 8px 24px rgba(28,25,22,.06);
  --tabbar-h: 64px;
  --prog-s: 78%; --prog-l: 42%;
  color-scheme: light;
  font-family: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
/* Dark palette is declared twice: once for "match my phone", once for an explicit Dark choice. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161412; --bg2: #26221e; --card: #211e1a; --ink: #f3eee6; --muted: #a39a8e; --line: #342f29;
    --accent: #6fbfa8; --accent-ink: #10201a; --accent-soft: #223730;
    --warn: #e6ab72; --warn-soft: #3a2c1f; --bad: #ec8b8b; --bad-soft: #3d2423;
    --blue: #8eb0d4; --blue-soft: #232e3b;
    --shadow: 0 1px 2px rgba(0,0,0,.25), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark; --prog-s: 82%; --prog-l: 60%;
  }
}
:root[data-theme="dark"] {
  --bg: #161412; --bg2: #26221e; --card: #211e1a; --ink: #f3eee6; --muted: #a39a8e; --line: #342f29;
  --accent: #6fbfa8; --accent-ink: #10201a; --accent-soft: #223730;
  --warn: #e6ab72; --warn-soft: #3a2c1f; --bad: #ec8b8b; --bad-soft: #3d2423;
  --blue: #8eb0d4; --blue-soft: #232e3b;
  --shadow: 0 1px 2px rgba(0,0,0,.25), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark; --prog-s: 82%; --prog-l: 60%;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.4;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

main {
  max-width: 640px; margin: 0 auto; outline: none;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
}
.boot { padding: 60px 0; text-align: center; color: var(--muted); }
.page > * + * { margin-top: 12px; }

/* ----- type ----- */
.top { padding: 6px 2px 2px; min-height: 48px; }
.top h1 { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.15; }
.eyebrow { color: var(--muted); font-size: .85rem; font-weight: 500; margin-bottom: 2px; }
.label { font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.big { font-size: clamp(2.2rem, 11vw, 3rem); font-weight: 700; letter-spacing: -0.04em; line-height: 1.05; font-variant-numeric: tabular-nums; margin: 4px 0; }
.big.neg { color: var(--bad); } .big.good { color: var(--accent); }
.mid { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.sub { color: var(--muted); font-size: .95rem; }
.tiny { font-size: .8rem; } .muted { color: var(--muted); } .center { text-align: center; } .right { text-align: right; }
.bad { color: var(--bad) !important; } .good-text { color: var(--accent); }
.top-gap { margin-top: 14px; }
.section-title { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 4px 0; }
.empty { color: var(--muted); padding: 6px 0; } .empty.pad { padding: 18px 16px; }
.pad-bottom { height: 12px; }

/* ----- cards ----- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card > * + * { margin-top: 10px; }
.card h2 { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.card.flush { padding: 4px 0; }
.card.flush > * + * { margin-top: 0; }
.hero { padding: 20px 18px; background: linear-gradient(160deg, var(--accent-soft), var(--card) 70%); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; flex-wrap: nowrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; align-items: start; }
@media (max-width: 380px) { .grid3 { grid-template-columns: 1fr; } }

/* ----- buttons ----- */
.btn {
  min-height: var(--tap); padding: 0 18px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg2); font-weight: 600; font-size: .98rem; display: inline-flex; gap: 6px;
  align-items: center; justify-content: center; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); background: transparent; }
.btn.danger-solid { background: var(--bad); color: #fff; border-color: transparent; }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: .9rem; border-radius: 12px; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 10px 4px; min-height: 44px; font-size: .92rem; }
.icon-btn {
  width: var(--tap); height: var(--tap); border-radius: 14px; border: 0; background: transparent;
  color: var(--muted); display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn:active { background: var(--bg2); }
.actions { margin-top: 12px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ----- banners, pills, chips ----- */
.banner {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; width: 100%;
  background: var(--accent-soft); color: var(--accent); font-weight: 500; font-size: .92rem; text-align: left; border: 0;
}
.banner > span { flex: 1; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner svg { flex: none; }
button.banner { min-height: var(--tap); }
.pill { display: inline-block; padding: 6px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: .8rem; font-weight: 700; white-space: nowrap; }
.pill.alt { background: var(--blue-soft); color: var(--blue); }
.chips, .chips-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-row { margin: 2px 0 8px; }
.chip {
  display: inline-flex; align-items: center; min-height: 28px; padding: 3px 10px; border-radius: 999px;
  font-size: .76rem; font-weight: 600; background: var(--bg2); color: var(--muted); border: 0;
}
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.ok { background: var(--accent-soft); color: var(--accent); }
.chip.soft { background: transparent; border: 1px solid var(--line); font-weight: 500; }
button.chip { cursor: pointer; min-height: 36px; padding: 4px 12px; }
.chips-row .chip { min-height: 40px; padding: 4px 16px; font-size: .9rem; }

/* ----- progress ----- */
.progress { height: 10px; background: var(--bg2); border-radius: 999px; overflow: hidden; margin: 10px 0 6px; }
.progress > span { display: block; height: 100%; background: var(--blue); border-radius: 999px; transition: width .3s ease; }
.progress.good > span { background: var(--accent); }
.progress.util > span { background: var(--accent); } .progress.util.hot > span { background: var(--bad); }
.progress.pc > span { transition: width .3s ease, background-color .3s ease; }
.ring {
  --track: var(--bg2); width: 56px; height: 56px; flex: none; border-radius: 50%; position: relative;
  display: grid; place-items: center;
  background: conic-gradient(var(--pc) calc(var(--p) * 1%), var(--track) 0);
}
.ring::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--card); }
.ring span { position: relative; font-size: .78rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.ring.done { background: var(--pc); }
.ring.done span { font-size: 1.2rem; color: var(--pc); }
.debt-card.done { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.debt-card.pif { background: var(--card); }
.card-head { display: flex; gap: 14px; align-items: center; }
.progress.util { height: 8px; }

/* ----- list rows ----- */
.row-item { display: flex; align-items: center; gap: 12px; padding: 8px 0; min-height: 56px; width: 100%; background: none; border: 0; text-align: left; }
.row-item + .row-item { border-top: 1px solid var(--line); }
.row-item.tap { padding: 8px 0; }
.name { font-weight: 600; } .meta { color: var(--muted); font-size: .84rem; }
.amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt-inline { font-weight: 700; font-variant-numeric: tabular-nums; }

.check {
  width: 44px; height: 44px; flex: none; border-radius: 50%; border: 2px solid var(--line);
  background: transparent; color: transparent; display: inline-flex; align-items: center; justify-content: center;
}
.check.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check:active { transform: scale(.92); }

/* ----- bills ----- */
.bill { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: start; padding: 14px 16px; }
.bill + .bill { border-top: 1px solid var(--line); }
.bill .check { margin-top: 2px; }
.bill-body { min-width: 0; }
.bill-main { background: none; border: 0; padding: 0; text-align: left; width: 100%; min-height: 44px; display: block; }
.bill-main .note { color: var(--warn); font-size: .8rem; margin-top: 2px; }
.bill-main .name { font-size: 1.05rem; }
.bill .chips { margin-top: 2px; }
.bill .amt { font-size: 1.05rem; padding-top: 2px; }
.bill.paid .name, .bill.paid .amt { text-decoration: line-through; color: var(--muted); }
.monthnav { display: flex; align-items: center; gap: 4px; }
.monthnav .center { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.monthnav strong { font-size: 1.05rem; }

/* ----- debt ----- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--bg); border-radius: 14px; padding: 12px; }
.stat .val { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.list-tight > * + * { margin-top: 4px; }
.divider { height: 1px; background: var(--line); margin: 14px 0 !important; }
.plan-note { background: var(--accent-soft); color: var(--ink); padding: 12px 14px; border-radius: 14px; font-size: .95rem; line-height: 1.45; }
.plan-day { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 2px; }
.plan-day .pill { padding: 2px 10px; font-size: .72rem; }
.goal-out { display: grid; gap: 8px; justify-items: start; }
.goal-out:empty { display: none; }

/* ----- forms ----- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field label { font-size: .82rem; font-weight: 600; color: var(--muted); }
.field small { color: var(--muted); font-size: .78rem; }
.field input, .field select {
  width: 100%; min-height: var(--tap); border: 1.5px solid var(--line); background: var(--bg); border-radius: 12px;
  padding: 0 12px; font-size: 1rem; /* 16px+ stops iOS zooming on focus */ font-variant-numeric: tabular-nums;
  appearance: none; -webkit-appearance: none;
}
.field select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="date"] { min-width: 0; }
.fs { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px 12px; margin: 0; display: grid; gap: 8px; min-width: 0; }
.fs legend { padding: 0 6px; font-size: .82rem; font-weight: 600; color: var(--muted); }
.form-error { color: var(--bad); font-weight: 600; font-size: .9rem; min-height: 0; }
.form-error:empty { display: none; }
.switch { display: flex; justify-content: space-between; align-items: center; min-height: var(--tap); font-weight: 600; position: relative; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .knob { width: 52px; height: 32px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: background .2s; }
.switch .knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked ~ .knob { background: var(--accent); }
.switch input:checked ~ .knob::after { transform: translateX(20px); }
.switch input:focus-visible ~ .knob { outline: 3px solid var(--accent); outline-offset: 2px; }
.steps { padding-left: 18px; margin: 10px 0 0; color: var(--muted); font-size: .92rem; display: grid; gap: 6px; }

/* ----- sheet ----- */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; pointer-events: none; }
.sheet-back { position: absolute; inset: 0; background: rgba(10,8,6,.45); opacity: 0; transition: opacity .2s; pointer-events: auto; }
.sheet.open .sheet-back { opacity: 1; }
.sheet-panel {
  position: relative; width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--card); border-radius: 24px 24px 0 0; padding: 8px 18px calc(env(safe-area-inset-bottom) + 18px);
  transform: translateY(100%); transition: transform .25s cubic-bezier(.2,.8,.2,1); pointer-events: auto;
  box-shadow: 0 -10px 40px rgba(0,0,0,.25);
}
.sheet.open .sheet-panel { transform: none; }
.sheet-grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet-title { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 14px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }
.sheet-actions .btn.primary { flex: 2; }
body.sheet-open { overflow: hidden; }

/* ----- toast ----- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--ink); color: var(--bg);
  padding: 12px 16px; border-radius: 14px; display: flex; gap: 14px; align-items: center; max-width: calc(100% - 32px);
  font-weight: 500; font-size: .92rem; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 6px; min-height: 36px; filter: brightness(1.3); }

/* ----- tab bar ----- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.tabbar .tab {
  flex: 1; max-width: 128px; height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600;
}
.tabbar .tab.active { color: var(--accent); }
.tabbar .tab:active { opacity: .6; }
body.sheet-open .tabbar { visibility: hidden; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (display-mode: standalone) { html { overscroll-behavior-y: none; } }
