/* Daily Flow Next — calm, legible, one number first. */

:root {
  --bg: #f6f3ec;
  --bg-card: #fffdf8;
  --bg-sunk: #efeae0;
  --ink: #1d2320;
  --ink-2: #5b635e;
  --ink-3: #8b918c;
  --line: #e3ddd1;
  --track: #e9e3d7;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --good: #3f8f6b;
  --good-soft: #d9ecdf;
  --warn: #c98a2b;
  --bad: #d0573f;
  --bad-soft: #f7ddd5;
  --shadow: 0 1px 2px rgba(40, 35, 20, .05), 0 6px 20px rgba(40, 35, 20, .06);
  --radius: 20px;
  --radius-s: 12px;
  --sans: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: ui-rounded, "SF Pro Rounded", -apple-system, "Segoe UI", Roboto, sans-serif;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412; --bg-card: #171e1b; --bg-sunk: #121816; --ink: #eef2ee; --ink-2: #a9b3ad; --ink-3: #75807a;
    --line: #26302c; --track: #243029; --accent: #6cc3a4; --accent-ink: #0c1411; --good: #6cc3a4; --good-soft: #1d3a2f;
    --warn: #e6b35e; --bad: #f08a70; --bad-soft: #3a211b; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --bg-card: #171e1b; --bg-sunk: #121816; --ink: #eef2ee; --ink-2: #a9b3ad; --ink-3: #75807a;
  --line: #26302c; --track: #243029; --accent: #6cc3a4; --accent-ink: #0c1411; --good: #6cc3a4; --good-soft: #1d3a2f;
  --warn: #e6b35e; --bad: #f08a70; --bad-soft: #3a211b; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* Only .content scrolls; the page itself never does, so nav and header stay put. */
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--bg); color: var(--ink); font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h2 { font-size: 17px; }
h3 { font-size: 14px; margin: 18px 0 6px; color: var(--ink-2); }
p { margin: 8px 0; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.right { text-align: right; }
.good { color: var(--good); }
.bad { color: var(--bad) !important; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.big { font: 700 26px/1.15 var(--display); letter-spacing: -.02em; }
.big small { font: 500 14px var(--sans); color: var(--ink-2); letter-spacing: 0; }

/* ---------- shell ---------- */
.shell { height: 100%; display: grid; grid-template-rows: 1fr auto; }
.content { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; min-height: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 12px;
  max-width: 1080px; margin: 0 auto; padding: 22px 16px 10px;
}
/* Installed on iOS: the status bar is real. Clear it with max(), never by adding. */
:root.standalone .topbar { padding-top: max(38px, calc(env(safe-area-inset-top) + 24px)); }
.topbar h1 { font: 800 30px/1.1 var(--display); letter-spacing: -.03em; }
.top-actions { display: flex; align-items: center; gap: 10px; }
main { max-width: 1080px; margin: 0 auto; padding: 4px 16px 28px; display: grid; gap: 14px; }

.rail {
  order: 2; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  background: color-mix(in srgb, var(--bg-card) 92%, transparent); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.rail .brand, .rail .rail-settings { display: none; }
.rail button {
  border: 0; background: none; display: grid; justify-items: center; gap: 2px; padding: 6px 0;
  font-size: 11px; font-weight: 600; color: var(--ink-3); cursor: pointer; border-radius: 12px;
}
.rail button .ni { font-size: 20px; line-height: 1; }
.rail button[aria-current="page"] { color: var(--accent); }
.rail .fab {
  justify-self: center; width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  font-size: 28px; font-weight: 400; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent); margin-top: -22px;
}
.rail .fab:active { transform: scale(.94); }
.top-settings { display: grid; }

@media (min-width: 900px) {
  .shell { grid-template-columns: 220px 1fr; grid-template-rows: 1fr; }
  .rail {
    order: 0; grid-template-columns: 1fr; align-content: start; gap: 4px; padding: 22px 14px;
    border-top: 0; border-right: 1px solid var(--line); background: var(--bg-sunk);
  }
  .rail .brand { order: -2; display: flex; align-items: center; gap: 10px; font: 800 18px var(--display); padding: 6px 10px 22px; }
  .rail .rail-settings { display: flex; }
  .rail button { display: flex; gap: 12px; padding: 10px 12px; font-size: 15px; justify-items: start; color: var(--ink-2); }
  .rail button[aria-current="page"] { background: var(--bg-card); color: var(--ink); box-shadow: var(--shadow); }
  .rail .fab { order: -1; width: auto; justify-self: stretch; height: 44px; border-radius: 12px; margin: 0 0 14px; font-size: 15px; justify-content: center; }
  .rail .fab span::after { content: " Log spending"; }
  .top-settings { display: none; }
  .topbar { padding: 34px 28px 12px; }
  main { padding: 4px 28px 40px; }
}
.logo { width: 26px; height: 26px; border-radius: 50%; background: conic-gradient(var(--accent) 0 62%, var(--track) 0); position: relative; }
.logo::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--bg-sunk); }

/* ---------- cards & basics ---------- */
.card { background: var(--bg-card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid color-mix(in srgb, var(--line) 60%, transparent); min-width: 0; }
button.card { text-align: left; cursor: pointer; width: 100%; }
button.card:hover { border-color: var(--line); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.row-between { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.row-gap { display: flex; gap: 8px; align-items: center; margin: 10px 0 4px; flex-wrap: wrap; }
.row-gap input, .row-gap select { flex: 1 1 120px; min-width: 0; }
.stack { display: grid; gap: 8px; }
.grid-2 { display: grid; gap: 14px; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; align-items: start; } }
.cards { display: grid; gap: 12px; }
@media (min-width: 640px) { .cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 18px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--bg-card); font-weight: 650; cursor: pointer;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.danger:not(.ghost) { border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.wide { width: 100%; }
.link { border: 0; background: none; color: var(--accent); font-weight: 650; cursor: pointer; padding: 0; }
.icon-btn { border: 0; background: var(--bg-sunk); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; color: var(--ink-2); flex: none; }
input, select {
  min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 0 12px; width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.banner { background: var(--good-soft); border-radius: var(--radius-s); padding: 10px 14px; font-size: 14px; }

.bar { position: relative; height: 10px; border-radius: 99px; background: var(--track); overflow: hidden; margin: 10px 0 6px; }
.bar.thin { height: 6px; margin: 6px 0 4px; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--good); transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.bar > span.over { background: var(--bad); }
.bar > span.done { background: var(--accent); }
.bar .pace { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); opacity: .35; }

/* ---------- today ---------- */
.hero { display: grid; justify-items: center; text-align: center; padding: 22px 18px 18px; gap: 6px; }
.hero-ring { position: relative; width: 220px; height: 220px; }
.ring-fill { transition: stroke-dasharray .7s cubic-bezier(.2, .8, .2, 1); }
.hero-center { position: absolute; inset: 0; display: grid; place-content: center; gap: 2px; }
.hero-num { font: 800 44px/1 var(--display); letter-spacing: -.04em; }
.hero.is-over .hero-num, .hero.is-over .hero-center .eyebrow { color: var(--bad); }
.hero-sub { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.hero-note { color: var(--ink-2); max-width: 36ch; min-height: 1.4em; }
.hero .btn { max-width: 360px; margin-top: 6px; }
@media (min-width: 900px) {
  main[data-current="today"] { grid-template-columns: 380px 1fr; align-items: start; }
  .today-side { display: grid; gap: 14px; align-content: start; }
  main[data-current="today"] > .banner, main[data-current="today"] > .grid-2, main[data-current="today"] > section:not(.hero) { grid-column: 1 / -1; }
}
.weekstrip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 10px; }
.wd { display: grid; justify-items: center; gap: 5px; font-size: 11px; color: var(--ink-3); font-weight: 700; }
.wd-dot { width: 26px; height: 26px; border-radius: 50%; background: var(--track); }
.wd.under .wd-dot { background: var(--good-soft); box-shadow: inset 0 0 0 2px var(--good); }
.wd.over .wd-dot { background: var(--bad-soft); box-shadow: inset 0 0 0 2px var(--bad); }
.wd.future .wd-dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.wd.is-today { color: var(--ink); }
.wd.is-today .wd-dot { transform: scale(1.12); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { padding: 14px 12px; display: grid; gap: 2px; align-content: start; }
.stat .big { font-size: 22px; }
@media (max-width: 420px) { .stat .big { font-size: 18px; } .stat { padding: 12px 10px; } }

.list { list-style: none; margin: 0; padding: 0; }
.list.card { padding: 4px 14px; }
.li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); cursor: pointer; min-width: 0; }
.li:last-child { border-bottom: 0; }
.li.dim { opacity: .55; }
.li-ic { width: 38px; height: 38px; flex: none; display: grid; place-items: center; background: var(--bg-sunk); border-radius: 12px; font-size: 18px; }
.li-main { flex: 1; min-width: 0; display: grid; }
.li-main b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-main small { color: var(--ink-2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-amt { font-weight: 650; white-space: nowrap; }
.li-amt small { color: var(--ink-3); font-weight: 500; }

.goal-strip { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(180px, 1fr); gap: 10px; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x mandatory; }
.goal-mini { scroll-snap-align: start; display: grid; gap: 2px; text-align: left; border: 1px solid var(--line); background: var(--bg); border-radius: 16px; padding: 12px; cursor: pointer; }
.gm-ic { font-size: 18px; }
.gm-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gm-meta { font-size: 12.5px; color: var(--ink-2); }
.gc-title { display: flex; gap: 8px; align-items: center; min-width: 0; }
.goal-card, .bucket-card { display: grid; gap: 4px; }

.welcome { text-align: center; padding: 30px 22px; max-width: 520px; margin: 10px auto; display: grid; gap: 8px; }
.welcome h2 { font: 800 26px/1.15 var(--display); }
.welcome-mark { font-size: 52px; color: var(--accent); line-height: 1; }

/* ---------- activity ---------- */
.toolbar { display: grid; gap: 8px; grid-template-columns: 1fr; }
@media (min-width: 700px) { .toolbar { grid-template-columns: 1fr auto 200px; } }
.search { background: var(--bg-card); }
.day-group { display: grid; gap: 6px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 4px 0; gap: 10px; }
.empty { text-align: center; display: grid; justify-items: center; gap: 8px; }

.seg { display: flex; background: var(--bg-sunk); border-radius: 13px; padding: 3px; gap: 2px; }
.seg > button, .seg > label { flex: 1; border: 0; background: none; min-height: 38px; border-radius: 10px; font-weight: 650; font-size: 14px; color: var(--ink-2); cursor: pointer; display: grid; place-items: center; padding: 0 10px; }
.seg > label { position: relative; }
.seg > label input { position: absolute; opacity: 0; pointer-events: none; }
.seg > label span { display: grid; place-items: center; width: 100%; height: 100%; }
.seg > button[aria-selected="true"], .seg > label:has(input:checked) { background: var(--bg-card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.big-seg > button { min-height: 42px; }

/* ---------- plan ---------- */
.explain { color: var(--ink-2); font-size: 14px; margin: 0 4px; }
.flows { display: grid; gap: 8px; margin: 14px 0 4px; }
.flow { display: grid; grid-template-columns: 70px 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.flow-bar { height: 10px; background: var(--track); border-radius: 99px; overflow: hidden; }
.flow-bar i { display: block; height: 100%; background: var(--ink-3); border-radius: inherit; }
.flow-bar i.good { background: var(--good); }
.flow b { font-weight: 650; }
details summary { cursor: pointer; font-weight: 650; padding: 4px 0; }

/* ---------- insights ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.tick { font-size: 11px; fill: var(--ink-3); }
.chart-note { font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.heatmap { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.hm-h { text-align: center; font-size: 11px; color: var(--ink-3); font-weight: 700; }
.hm-c { aspect-ratio: 1; border-radius: 9px; display: grid; place-items: center; font-size: 12px; font-weight: 650; background: var(--track); color: var(--ink-2); }
.hm-c.great { background: var(--good); color: var(--accent-ink); }
.hm-c.ok { background: color-mix(in srgb, var(--good) 30%, var(--bg-card)); color: var(--ink); }
.hm-c.over { background: var(--bad); color: #fff; }
.hm-c.future { background: transparent; box-shadow: inset 0 0 0 1px var(--line); color: var(--ink-3); }
.hm-c.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.legend { display: flex; gap: 6px; align-items: center; margin-top: 10px; color: var(--ink-2); flex-wrap: wrap; }
.lg { width: 12px; height: 12px; border-radius: 4px; display: inline-block; margin-left: 6px; }
.lg.great { background: var(--good); } .lg.ok { background: var(--good-soft); } .lg.over { background: var(--bad); }
.cats { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.cats li { display: grid; grid-template-columns: minmax(110px, 150px) 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.cat-l { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-bar { position: relative; height: 12px; background: var(--track); border-radius: 99px; }
.cat-bar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; opacity: .85; }
.cat-bar b { position: absolute; top: -3px; bottom: -3px; width: 3px; margin-left: -1.5px; background: var(--ink); border-radius: 2px; opacity: .55; }
.whatif-out { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; padding: 14px; background: var(--bg-sunk); border-radius: var(--radius-s); }
.whatif-out .big { font-size: 20px; }

/* ---------- forms & sheets ---------- */
.form { display: grid; gap: 12px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fields label { display: grid; gap: 4px; font-size: 12.5px; font-weight: 650; color: var(--ink-2); min-width: 0; }
.fields .span2 { grid-column: 1 / -1; }
.fields .icon-in { grid-column: span 1; }
.field-inline { display: grid; gap: 4px; margin-top: 12px; font-size: 13px; font-weight: 650; color: var(--ink-2); }
input[type="date"] { min-width: 0; }

dialog#sheet {
  border: 0; padding: 0; background: transparent; color: var(--ink); max-width: 100vw; max-height: 100dvh; width: 100%; height: 100%;
  margin: 0; display: none; place-items: end center;
}
dialog#sheet[open] { display: grid; }
dialog#sheet::backdrop { background: rgba(10, 14, 12, .45); backdrop-filter: blur(2px); }
.sheet-card {
  width: 100%; max-width: 560px; max-height: calc(100dvh - 40px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg-card); border-radius: 24px 24px 0 0; padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  animation: up .28s cubic-bezier(.2, .8, .2, 1);
}
@media (min-width: 700px) {
  dialog#sheet { place-items: center; }
  .sheet-card { border-radius: 24px; padding: 18px 22px 22px; }
  .grab { display: none; }
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet-card, .ring-fill, .bar > span { animation: none; transition: none; } }
.grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.sheet-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.sheet-actions .danger.ghost { margin-right: auto; }
.small-seg { min-width: 190px; }
.small-seg > label { min-height: 34px; font-size: 13px; }
.amount-field { display: flex; align-items: center; gap: 4px; border-bottom: 2px solid var(--line); padding: 4px 2px; }
.amount-field:focus-within { border-color: var(--accent); }
.amount-field .cur { font: 700 30px var(--display); color: var(--ink-3); }
.amount-field input { font: 800 40px var(--display); letter-spacing: -.03em; border: 0; background: transparent; padding: 0; min-height: 56px; outline: none; }
.amount-field input::-webkit-outer-spin-button, .amount-field input::-webkit-inner-spin-button { -webkit-appearance: none; }
.picks { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.pick { flex: none; border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: 7px 12px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.pick small { color: var(--ink-2); font-weight: 500; }
.cat-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
@media (max-width: 480px) { .cat-grid { grid-template-columns: repeat(5, 1fr); } }
.cat { cursor: pointer; position: relative; }
.cat input { position: absolute; opacity: 0; pointer-events: none; }
.cat span { display: grid; justify-items: center; gap: 2px; padding: 8px 2px; border-radius: 12px; font-size: 20px; border: 1.5px solid transparent; background: var(--bg-sunk); }
.cat small { font-size: 10px; color: var(--ink-2); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.cat input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--bg-card)); }
.cat input:focus-visible + span { outline: 2px solid var(--accent); }
.hint { margin: 0; }
.calc { display: grid; gap: 2px; margin: 12px 0; }
.calc-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.calc-row.total { border-bottom: 0; border-top: 2px solid var(--ink); font-size: 18px; margin-top: 4px; }
.qs-preview { display: grid; justify-items: center; padding: 14px; background: var(--bg-sunk); border-radius: var(--radius-s); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 22px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); border-radius: 14px; padding: 12px 16px; display: flex; gap: 14px; align-items: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25); opacity: 0; pointer-events: none; transition: .25s; max-width: calc(100vw - 32px); z-index: 10; font-size: 14px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast .link { color: var(--good-soft); }
:root[data-theme="dark"] .toast .link { color: var(--accent-ink); }
@media (min-width: 900px) { .toast { bottom: 28px; } }

.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ink-3); }
.sync-dot[data-state="idle"] { background: var(--good); }
.sync-dot[data-state="syncing"] { background: var(--warn); }
.sync-dot[data-state="error"] { background: var(--bad); }
.about p { font-size: 14px; }
