:root {
  color-scheme: light;
  --bg: #f4f6f3; --card: #ffffff; --ink: #14201b; --muted: #5f6f67; --line: #dfe6e1;
  --brand: #0f5c4d; --brand-2: #0b4539; --brand-soft: #e3f0ec;
  --in: #1f8a6b; --out: #d0674f; --saved: #e2b33c;
  --good: #1f8a6b; --good-bg: #e6f4ee; --watch: #b7791f; --watch-bg: #fbf3e2; --act: #b8432f; --act-bg: #fbeae6;
  --seg-essential: #0f5c4d; --seg-lifestyle: #d0674f; --seg-business: #5470c6; --seg-other: #a7b3ad;
  --shadow: 0 6px 22px rgba(20, 45, 36, .07);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1513; --card: #18211e; --ink: #e8efeb; --muted: #9aaba3; --line: #2a3632;
    --brand: #4fb89a; --brand-2: #7fd1b8; --brand-soft: #1d2d28;
    --in: #4fb89a; --out: #ec8a72; --saved: #eec35a;
    --good: #5fc7a6; --good-bg: #16302a; --watch: #e7b04f; --watch-bg: #33291a; --act: #f08a75; --act-bg: #3a211c;
    --seg-essential: #4fb89a; --seg-lifestyle: #ec8a72; --seg-business: #8aa2ec; --seg-other: #5d6a64;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1513; --card: #18211e; --ink: #e8efeb; --muted: #9aaba3; --line: #2a3632;
  --brand: #4fb89a; --brand-2: #7fd1b8; --brand-soft: #1d2d28;
  --in: #4fb89a; --out: #ec8a72; --saved: #eec35a;
  --good: #5fc7a6; --good-bg: #16302a; --watch: #e7b04f; --watch-bg: #33291a; --act: #f08a75; --act-bg: #3a211c;
  --seg-essential: #4fb89a; --seg-lifestyle: #ec8a72; --seg-business: #8aa2ec; --seg-other: #5d6a64;
  --shadow: none;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: var(--brand); }
.num, td.num, .kpi-value { font-variant-numeric: tabular-nums; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--brand); color: #fff; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .topbar { background: #12302a; } }
:root[data-theme="dark"] .topbar { background: #12302a; }
.topbar-inner { max-width: 1040px; margin: 0 auto; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 800; font-size: 1.05rem; white-space: nowrap; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: rgba(255,255,255,.16); display: grid; place-items: center; font-size: 1rem; }
.topnav { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a { color: #fff; opacity: .86; text-decoration: none; padding: 7px 11px; border-radius: 8px; font-size: .88rem; white-space: nowrap; }
.topnav a.active { background: rgba(255,255,255,.18); opacity: 1; font-weight: 700; }
.sync-pill { font-size: .75rem; opacity: .8; white-space: nowrap; color: #fff; text-decoration: none; }

/* bottom tabs on phones */
.tabbar { display: none; }
@media (max-width: 760px) {
  .topnav { display: none; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; background: var(--card); border-top: 1px solid var(--line);
            padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .tabbar a { flex: 1; text-align: center; color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600; padding: 4px 0; }
  .tabbar a .ico { display: block; font-size: 1.15rem; line-height: 1.3; }
  .tabbar a.active { color: var(--brand); }
  .shell { padding-bottom: 96px !important; }
  .sync-pill { margin-left: auto; }
}

.shell { max-width: 1040px; margin: 0 auto; padding: 22px 16px 60px; }
h1 { font-size: 1.6rem; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 0 0 6px; }
.lede { color: var(--muted); margin: 0 0 18px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
.grid > .card { margin-bottom: 0; }

/* period picker */
.periods { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.periods::-webkit-scrollbar { display: none; }
.periods a { white-space: nowrap; text-decoration: none; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: .82rem; }
.periods a.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .periods a.active { color: #0f1513; } }
:root[data-theme="dark"] .periods a.active { color: #0f1513; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
@media (max-width: 760px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi-label { color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.kpi-value { font-size: 1.5rem; font-weight: 800; margin: 2px 0; letter-spacing: -.01em; }
.kpi-sub { font-size: .78rem; color: var(--muted); }
.kpi.hero { background: var(--brand); color: #fff; border-color: var(--brand); }
.kpi.hero .kpi-label, .kpi.hero .kpi-sub { color: rgba(255,255,255,.82); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .kpi.hero { background: #12302a; border-color: #1f4a40; } }
:root[data-theme="dark"] .kpi.hero { background: #12302a; border-color: #1f4a40; }
.up { color: var(--act); } .down { color: var(--good); }
.pos { color: var(--good); } .neg { color: var(--act); }
.kpi.hero .up, .kpi.hero .down, .kpi.hero .pos, .kpi.hero .neg { color: #fff; }

/* insights */
.insight { border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; border-left: 4px solid; display: block; text-decoration: none; color: var(--ink); }
.insight.good { background: var(--good-bg); border-color: var(--good); }
.insight.watch { background: var(--watch-bg); border-color: var(--watch); }
.insight.act { background: var(--act-bg); border-color: var(--act); }
.insight strong { display: block; font-size: .93rem; }
.insight span { font-size: .84rem; color: var(--muted); }
.tag { display: inline-block; font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; padding: 1px 7px; border-radius: 999px; margin-bottom: 4px; }
.tag.good { background: var(--good); color: #fff; } .tag.watch { background: var(--watch); color: #fff; } .tag.act { background: var(--act); color: #fff; }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .bar-in { fill: var(--in); } .chart .bar-out { fill: var(--out); } .chart .bar-saved { fill: var(--saved); }
.chart .faded { opacity: .45; }
.chart a { cursor: pointer; }
.chart a:hover .bar-out { opacity: .75; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.splitbar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--line); margin: 8px 0; }
.splitbar span { display: block; height: 100%; }
.seg-essential { background: var(--seg-essential); } .seg-lifestyle { background: var(--seg-lifestyle); }
.seg-business { background: var(--seg-business); } .seg-other { background: var(--seg-other); }

/* category rows */
.cat-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 9px 0; border-top: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.cat-row:first-child { border-top: 0; }
.cat-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-amt { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.meter { grid-column: 1 / -1; height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.meter.over span { background: var(--act); }
.cat-meta { grid-column: 1 / -1; font-size: .76rem; color: var(--muted); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { text-align: left; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.tx-desc { max-width: 380px; overflow-wrap: anywhere; }
.pill { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-2); white-space: nowrap; }
.pill.internal { background: var(--line); color: var(--muted); }
.list { display: grid; gap: 0; }
.list-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }

/* forms */
input, select, button { font: inherit; color: var(--ink); }
input, select { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
button, .btn { background: var(--brand); color: #fff; border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 700; cursor: pointer; text-decoration: none; display: inline-block; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) button, :root:not([data-theme="light"]) .btn { color: #0f1513; } }
:root[data-theme="dark"] button, :root[data-theme="dark"] .btn { color: #0f1513; }
button.ghost, .btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--act); border: 1px solid var(--line); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { flex: 1 1 200px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
details summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.month-group { border-top: 1px solid var(--line); padding: 10px 0; }
.month-group:first-of-type { border-top: 0; padding-top: 0; }
.progress { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.progress span { display: block; height: 100%; background: var(--in); }
.notice { background: var(--brand-soft); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; font-size: .9rem; }
.notice.bad { background: var(--act-bg); }
code { background: var(--brand-soft); padding: 1px 5px; border-radius: 5px; font-size: .85em; overflow-wrap: anywhere; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 12px; }

/* login */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(380px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 26px; box-shadow: var(--shadow); }
.auth-card label { display: block; font-size: .82rem; font-weight: 700; margin: 12px 0 4px; }
.auth-card input { width: 100%; }
.auth-card button { width: 100%; margin-top: 18px; }
.error { color: var(--act); font-weight: 600; }

/* personal / business switch */
.scope { display: inline-flex; float: right; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px; margin: 0 0 8px 12px; }
.scope button { background: transparent; color: var(--muted); border-radius: 999px; padding: 5px 11px; font-size: .78rem; font-weight: 700; }
.scope button.on { background: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .scope button.on { color: #0f1513; } :root:not([data-theme="light"]) .scope button:not(.on) { color: var(--muted); } }
:root[data-theme="dark"] .scope button.on { color: #0f1513; }
@media (max-width: 760px) { .scope { float: none; display: flex; width: 100%; margin: 0 0 12px; } .scope button { flex: 1; } }
.insight span.tag { color: #fff; font-size: .68rem; }
a.list-row { text-decoration: none; color: var(--ink); }

/* safe to spend */
.safe { border-left: 5px solid var(--good); }
.safe.fast { border-left-color: var(--watch); }
.safe.over { border-left-color: var(--act); }
.pace { position: relative; height: 12px; background: var(--line); border-radius: 999px; margin: 12px 0 6px; overflow: visible; }
.pace .spent { display: block; height: 100%; border-radius: 999px; background: var(--good); }
.safe.fast .pace .spent { background: var(--watch); } .safe.over .pace .spent { background: var(--act); }
.pace i { position: absolute; top: -4px; width: 2px; height: 20px; background: var(--ink); border-radius: 2px; }
.breakdown .list-row span:last-child { font-variant-numeric: tabular-nums; }
.breakdown .total { font-weight: 800; border-top: 2px solid var(--line); }
.chart .line-a { fill: none; stroke: var(--out); stroke-width: 2.5; }
.chart .line-b { fill: none; stroke: var(--in); stroke-width: 2.5; }
@media (max-width: 760px) { .safe .page-head > div:last-child { text-align: left !important; } }

/* roadmap */
.roadcard { border-left: 5px solid var(--brand); }
.ladder { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.rung { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.rung i { display: block; height: 100%; background: var(--seg-other); }
.rung.done i { background: var(--good); } .rung.now i { background: var(--brand); }
.rung.now { outline: 2px solid var(--brand); outline-offset: 2px; }
.step { display: grid; grid-template-columns: 34px 1fr; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.step:first-child { border-top: 0; }
.step-n { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--line); color: var(--muted); }
.step.done .step-n { background: var(--good); color: #fff; } .step.now .step-n { background: var(--brand); color: #fff; }
.score { font-size: 3rem; font-weight: 800; line-height: 1; }
.streak { font-size: 2rem; font-weight: 800; }
.chart .floorline { stroke: var(--watch); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .dot-in { fill: var(--in); } .chart .dot-out { fill: var(--out); }
.verdict { font-size: 1.35rem; font-weight: 800; margin: 2px 0 6px; }
.verdict.good { color: var(--good); } .verdict.watch { color: var(--watch); } .verdict.act { color: var(--act); }
.afford-form { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.afford-form label { font-size: .82rem; font-weight: 700; display: grid; gap: 4px; }
.afford-form .full { grid-column: 1 / -1; }
@media (max-width: 760px) { .afford-form { grid-template-columns: minmax(0, 1fr); } }

/* a hero figure that's gone negative turns red, in both themes */
.kpi.hero.bad, :root:not([data-theme="light"]) .kpi.hero.bad, :root[data-theme="dark"] .kpi.hero.bad { background: var(--act); border-color: var(--act); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .kpi.hero.bad { background: #6b2a1f; border-color: #8a3a2b; } }
:root[data-theme="dark"] .kpi.hero.bad { background: #6b2a1f; border-color: #8a3a2b; }
tr.tap { cursor: pointer; }
tr.tap:hover td { background: var(--brand-soft); }
a.kpi-link { text-decoration: none; color: inherit; display: block; transition: transform .1s; }
a.kpi-link:active { transform: scale(.98); }
a.kpi.hero.kpi-link { color: #fff; }
.small-btn { padding: 5px 9px; font-size: .78rem; white-space: nowrap; }
.anchor { scroll-margin-top: 80px; }
.anchor:target { outline: 2px solid var(--brand); outline-offset: 2px; }
html { scroll-behavior: smooth; }

img.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: none; display: block; box-shadow: 0 0 0 1px rgba(255,255,255,.18); }

/* Tap-to-open sections (fold.js): a card's heading becomes a one-line headline */
details.fold-panel { padding: 0; }
details.fold-panel > summary { display: flex; align-items: center; gap: 10px; padding: 15px 18px; cursor: pointer; list-style: none; color: var(--ink); font-weight: inherit; -webkit-tap-highlight-color: transparent; }
details.fold-panel > summary::-webkit-details-marker { display: none; }
details.fold-panel > summary > :first-child { flex: 1; min-width: 0; }
details.fold-panel > summary h2 { margin: 0; overflow-wrap: anywhere; }
details.fold-panel > summary .pill, details.fold-panel > summary .tag { flex: none; margin: 0; }
details.fold-panel[open] > summary { border-bottom: 1px solid var(--line); }
details.fold-panel > .section-body { padding: 14px 18px 18px; min-width: 0; }
details.fold-panel > .section-body > .page-head:first-child { justify-content: flex-end; margin: 0 0 10px !important; }
.section-chevron { flex: none; font-size: 1.45rem; line-height: 1; color: var(--brand); transition: transform .15s; }
details.fold-panel[open] > summary .section-chevron { transform: rotate(90deg); }
details.fold-panel > summary:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; border-radius: 16px; }
.grid > details.fold-panel:not([open]), .grid > .fold-form { align-self: start; }
.grid > .fold-form > .card { margin-bottom: 0; }
@media (max-width: 760px) { details.fold-panel > summary { padding: 13px 16px; } details.fold-panel > .section-body { padding: 12px 16px 16px; } }
@media print { .section-chevron { display: none; } }
/* long unbroken text (e.g. a sync error in the Log) wraps instead of widening the page */
.list-row > span:first-child { min-width: 0; overflow-wrap: anywhere; }
