:root {
  --bg: #f4f5fb; --card: #ffffff; --text: #0f172a; --muted: #64748b; --line: #e5e7ef;
  --brand: #4f46e5; --brand-ink: #ffffff; --pos: #059669; --neg: #dc2626; --warn-bg: #fef2f2; --ok-bg: #ecfdf5;
  --radius: 16px; --tab-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1020; --card: #151b2f; --text: #e8ebf5; --muted: #8b95b0; --line: #262e48;
          --brand: #818cf8; --brand-ink: #0b1020; --pos: #34d399; --neg: #f87171; --warn-bg: #3b1620; --ok-bg: #0f2a22; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 1.5rem; margin: .6rem 0 .6rem; }
h2 { font-size: 1.15rem; margin: 2.2rem 0 .9rem; }
h3 { font-size: 1rem; margin: 0 0 1rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.grow { flex: 1; min-width: 0; }
.ico { width: 24px; height: 24px; }

/* layout */
.page { max-width: 760px; margin: 0 auto; padding: 22px 18px calc(var(--tab-h) + 40px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; gap: 14px; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 800; letter-spacing: -.02em; color: var(--text); font-size: 1.1rem; }
.brand span { color: var(--brand); } .brand.big { font-size: 1.8rem; margin: 0 0 .2rem; }
.desk-nav { display: none; gap: 4px; margin-left: 12px; }
.desk-nav a { padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 500; }
.desk-nav a.on, .desk-nav a:hover { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }
.who { margin-left: auto; display: flex; gap: 12px; align-items: center; font-size: .9rem; }
.who form { margin: 0; }
button.link { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 0; }
.who a.on { font-weight: 700; }

/* mobile bottom tab bar */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; z-index: 20; }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .7rem; min-width: 0; }
.tabbar a.on { color: var(--brand); font-weight: 600; }

/* cards & lists */
.card { background: var(--card); border-radius: var(--radius); padding: 22px 20px; margin: 20px 0;
  box-shadow: 0 1px 2px rgba(15,23,42,.05), 0 4px 14px rgba(15,23,42,.04); }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 20px; }
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 14px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.list .row:last-child { border-bottom: 0; }
.row.total { border-top: 1px solid var(--line); border-bottom: 0; margin-top: 8px; font-weight: 600; }
.row.sub { padding-top: 0; font-size: .85rem; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.tag { background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand); border-radius: 6px;
  padding: 1px 6px; margin-left: 4px; font-size: .7rem; }

.monthnav { display: flex; align-items: center; justify-content: space-between; margin: 10px 0 20px; }
.monthnav h2 { margin: 0; font-size: 1.2rem; }
.btn-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: var(--card);
  color: var(--text); font-size: 1.5rem; box-shadow: 0 1px 2px rgba(15,23,42,.08); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 18px 0; }
.stat { background: var(--card); border-radius: var(--radius); padding: 18px 16px; display: flex; flex-direction: column; gap: 4px;
  box-shadow: 0 1px 2px rgba(15,23,42,.05); }
.stat-l { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat-v { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; }

.chart { position: relative; height: 280px; } .chart.tall { height: 340px; }
.miles { display: grid; gap: 14px; margin: 14px 0 22px; grid-template-columns: 1fr; }
.mile { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.mile-v { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; color: var(--brand); }

.seg { display: flex; background: var(--card); border-radius: 999px; padding: 4px; margin: 6px 0 18px; }
.seg a { flex: 1; text-align: center; padding: 8px; border-radius: 999px; color: var(--muted); font-weight: 600; }
.seg a.on { background: var(--brand); color: var(--brand-ink); }
.horizon { display: flex; gap: 10px; margin: 14px 0 18px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 16px; border-radius: 999px;
  font: inherit; cursor: pointer; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* forms */
.form { display: flex; flex-direction: column; gap: 18px; }
label { display: flex; flex-direction: column; gap: 8px; font-size: .9rem; color: var(--muted); }
input { font: inherit; font-size: 16px; /* 16px stops iOS zoom */ color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-height: 46px; width: 100%; }
input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
input.changed { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, var(--bg)); }
label.amt { flex-direction: row; align-items: center; gap: 14px; padding: 12px 0; color: var(--text); }
label.amt input { width: 120px; text-align: right; flex: none; }
label.amt small { display: block; }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); }
label.check input { width: 22px; height: 22px; min-height: 0; flex: none; }
.btn { display: inline-flex; justify-content: center; align-items: center; border: 0; border-radius: 12px; padding: 12px 18px;
  font: inherit; font-weight: 600; cursor: pointer; min-height: 46px; background: var(--line); color: var(--text); }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.danger { background: transparent; color: var(--neg); }
.btn.sm { min-height: 40px; padding: 8px 14px; }
.btn.block { display: flex; margin: 22px 0; }
.alert { padding: 12px 16px; border-radius: 12px; margin: 8px 0 16px; font-size: .92rem; }
.alert.err { background: var(--warn-bg); color: var(--neg); } .alert.ok { background: var(--ok-bg); color: var(--pos); }

.sticky-summary { position: sticky; bottom: calc(var(--tab-h) + 8px + env(safe-area-inset-bottom)); display: flex; align-items: center;
  gap: 10px; background: var(--card); border-radius: var(--radius); padding: 12px 14px;
  box-shadow: 0 6px 24px rgba(15,23,42,.18); }
.sticky-summary div { flex: 1; display: flex; flex-direction: column; font-size: .95rem; }
.sticky-summary small { color: var(--muted); font-size: .7rem; text-transform: uppercase; }

/* sections editor */
.sec-form { display: flex; flex-direction: column; gap: 16px; }
.sec-top { display: flex; align-items: center; gap: 10px; }
.sec-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 14px; }
.swatches { display: flex; flex-wrap: wrap; gap: 12px; }
.sw { position: relative; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; flex-direction: row; }
.sw input { position: absolute; opacity: 0; inset: 0; width: 100%; min-height: 0; cursor: pointer; }
.sw span { position: absolute; inset: -4px; border-radius: 50%; border: 2px solid transparent; }
.sw input:checked + span { border-color: var(--text); }
.actions { display: flex; gap: 8px; justify-content: space-between; }
details.add summary { cursor: pointer; font-weight: 600; color: var(--brand); list-style: none; padding: 8px 0; }
details.add[open] summary { margin-bottom: 16px; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login { width: 100%; max-width: 380px; padding: 24px; }

/* desktop */
@media (min-width: 820px) {
  .tabbar { display: none; }
  .desk-nav { display: flex; }
  .page { padding-bottom: 40px; max-width: 980px; padding-top: 22px; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  .miles { grid-template-columns: repeat(3, 1fr); }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .sticky-summary { bottom: 12px; }
  .chart { height: 320px; } .chart.tall { height: 400px; }
}

/* spending status banner */
.banner { border-radius: var(--radius); padding: 18px 20px; margin: 14px 0 18px; display: flex; flex-direction: column; gap: 6px; }
.banner strong { font-size: 1.05rem; } .banner span { font-size: .92rem; }
.banner.good { background: var(--ok-bg); color: var(--pos); }
.banner.bad { background: var(--warn-bg); color: var(--neg); }
.banner.neutral { background: var(--card); color: var(--muted); }
.banner span { color: var(--text); opacity: .85; }

/* progress rows */
.rowline { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.bar { height: 6px; background: var(--line); border-radius: 99px; margin-top: 12px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; }
.bar i.over { background: var(--neg) !important; }

/* spend form + list */
select { font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; min-height: 46px; width: 100%; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.big-input { font-size: 1.6rem; font-weight: 700; }
form.inline { margin: 0; }
.btn-x { background: none; border: 0; color: var(--muted); font-size: 1.1rem; width: 40px; height: 40px; cursor: pointer; border-radius: 50%; }
.btn-x:hover { color: var(--neg); }
@media (max-width: 420px) { .two { grid-template-columns: 1fr; } }

/* groups (e.g. Subscription) and their sections */
li.grp { border-bottom: 1px solid var(--line); list-style: none; }
li.grp summary.row { cursor: pointer; list-style: none; border-bottom: 0; }
li.grp summary::-webkit-details-marker { display: none; }
.chev { color: var(--muted); font-size: 1.3rem; transition: transform .15s; }
details[open] > summary .chev { transform: rotate(90deg); }
ul.sub { margin: 0 0 14px 6px; padding-left: 18px; border-left: 2px solid var(--line); }
ul.sub .row { padding: 12px 0; font-size: .92rem; }
.grouphead { display: flex; align-items: center; gap: 12px; padding: 18px 0 6px; border-top: 1px solid var(--line); margin-top: 12px; }
label.amt.in-group { margin-left: 14px; padding-left: 14px; border-left: 2px solid var(--line); }
.card.group { position: relative; }
.card.group > .tag { position: static; display: inline-block; margin: 0 0 18px; padding: 3px 10px; }
.card.group .child { margin: 22px 0 0 12px; padding: 22px 0 0 16px; border-left: 2px solid var(--line); border-top: 1px dashed var(--line); }
.sec-form select { margin: 0; }

/* long-term table: wide enough to read, scrolls sideways instead of squeezing */
.tscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 12px;
  /* soft shadows on the edges that still have content to scroll to */
  background:
    linear-gradient(to right, var(--card) 30%, rgba(0,0,0,0)) 0 0 / 44px 100% local no-repeat,
    linear-gradient(to left, var(--card) 30%, rgba(0,0,0,0)) 100% 0 / 44px 100% local no-repeat,
    radial-gradient(farthest-side at 0 50%, rgba(99,102,241,.35), rgba(0,0,0,0)) 0 0 / 14px 100% scroll no-repeat,
    radial-gradient(farthest-side at 100% 50%, rgba(99,102,241,.35), rgba(0,0,0,0)) 100% 0 / 14px 100% scroll no-repeat; }
.tscroll-hint { display: none; margin: 14px 0 0; font-size: .8rem; color: var(--muted); text-align: center; }
@media (max-width: 819px) { .tscroll-hint { display: block; } }
.ltable { width: 100%; min-width: 540px; border-collapse: separate; border-spacing: 0; font-size: .9rem; white-space: nowrap; }
.ltable th { text-align: right; font-weight: 600; color: var(--muted); font-size: .72rem; text-transform: uppercase;
  letter-spacing: .05em; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.ltable td { text-align: right; padding: 16px 14px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.ltable th:first-child, .ltable td:first-child { text-align: left; min-width: 150px; }
.ltable td:first-child { white-space: nowrap; }
.ltable td .dot { display: inline-block; margin-right: 10px; vertical-align: middle; }
.ltable tr.grp td { font-weight: 700; }
.ltable tr.child td:first-child { padding-left: 34px; font-weight: 400; }
.ltable tfoot td { border-top: 2px solid var(--line); border-bottom: 0; }

/* vertical rhythm: generous, consistent space between titles, banners, cards, pills */
h1 { margin: .9rem 0 1.1rem; }
h1 + p { margin: 0 0 1.8rem; }
h2 { margin: 3rem 0 1.1rem; }
h2 + p, h2 + .muted { margin: 0 0 1.6rem; }
.monthnav { margin: 16px 0 28px; }
.seg { margin: 8px 0 26px; }
.banner { margin: 20px 0 28px; }
.stats { margin: 28px 0 32px; gap: 16px; }
.btn.block { margin: 32px 0; }
.card { margin: 28px 0; }
.card h3 + p, .card h3 + .muted { margin-top: -.4rem; margin-bottom: 1.4rem; }
.horizon { margin: 22px 0 30px; gap: 12px; }
.miles { margin: 22px 0 34px; gap: 18px; }
.grid2 { gap: 0 24px; }
.alert { margin: 10px 0 24px; }
.page { padding-top: 26px; }

/* forms: more air between stacked fields (e.g. Date above Note on the Spend form) */
.form { gap: 24px; }
.two { gap: 24px 16px; }
@media (max-width: 420px) { .two { grid-template-columns: 1fr; gap: 24px; } }
.miles > .card { margin: 0; }

/* savings tab */
.hero { text-align: center; padding: 30px 20px; }
.hero-v { display: block; font-size: 2.4rem; font-weight: 800; letter-spacing: -.03em; color: var(--brand); margin: 10px 0 14px; }
.hero p { margin: .5rem 0 0; }
.sec-note { margin: 12px 0 0; line-height: 1.6; }
.seg { gap: 4px; }
