/* Layout: summary band across the top; debts editor (left rail) beside the results column; one column on phones. */
:root {
  --bg: #f2f5f3;
  --surface: #ffffff;
  --surface-2: #e9eeeb;
  --ink: #132019;
  --ink-2: #47554e;
  --muted: #6f7b75;
  --line: #d6ded9;
  --accent: #23408e;          /* check-ink blue */
  --accent-ink: #ffffff;
  --accent-soft: #e2e8f6;
  --good: #1d7445;
  --good-soft: #e1f1e7;
  --warn: #9a5200;
  --warn-soft: #fbeedd;
  --series-1: #2a78d6;        /* snowball */
  --series-2: #eb6834;        /* avalanche */
  --series-ref: #7c8681;      /* minimums only */
  --series-3: #1baf7a;
  --series-4: #eda100;
  --bar-min: #86b6ef;
  --bar-focus: #23408e;
  --f-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --f-body: "Public Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412; --surface: #171e1b; --surface-2: #1f2824; --ink: #e6ede9; --ink-2: #b0bbb5;
    --muted: #87938d; --line: #2b3631; --accent: #9db3f2; --accent-ink: #0f1412; --accent-soft: #1d2744;
    --good: #6fcf97; --good-soft: #15291e; --warn: #f0a85a; --warn-soft: #2e2214;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-ref: #8a9590; --bar-min: #184f95; --bar-focus: #6da7ec;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --surface: #171e1b; --surface-2: #1f2824; --ink: #e6ede9; --ink-2: #b0bbb5;
  --muted: #87938d; --line: #2b3631; --accent: #9db3f2; --accent-ink: #0f1412; --accent-soft: #1d2744;
  --good: #6fcf97; --good-soft: #15291e; --warn: #f0a85a; --warn-soft: #2e2214;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-ref: #8a9590; --bar-min: #184f95; --bar-focus: #6da7ec;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--f-body); padding: 0 16px; }
.wrap { max-width: 1240px; margin: 0 auto; padding-block: 24px 64px; display: flex; flex-direction: column; gap: 24px; }
h1, h2, h3 { font-family: var(--f-display); text-wrap: balance; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0; }
.num, td, .stat b { font-variant-numeric: tabular-nums; }
.eyebrow { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 24px; }
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.brand h1 { font-size: 1.35rem; font-weight: 700; }

/* ---------- hero ---------- */
.hero { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 24px; display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 24px; }
.hero-date { font-family: var(--f-display); font-weight: 700; font-size: clamp(2.2rem, 5.5vw, 3.6rem); line-height: 1.02; letter-spacing: -0.025em; color: var(--accent); }
.hero-date small { display: block; font-size: 0.32em; letter-spacing: 0; color: var(--ink-2); font-weight: 500; margin-bottom: 6px; }
.hero-copy { margin-top: 12px; color: var(--ink-2); max-width: 60ch; }
.hero-copy strong { color: var(--ink); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; align-self: start; }
.stat { background: var(--surface); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.stat span { font-size: 0.78rem; color: var(--muted); }
.stat b { font-size: 1.25rem; font-weight: 700; font-family: var(--f-display); }
.stat b.good { color: var(--good); }
.alert { border-radius: 8px; padding: 10px 12px; font-size: 0.9rem; background: var(--warn-soft); color: var(--ink); border-left: 3px solid var(--warn); }
.alert.good { background: var(--good-soft); border-left-color: var(--good); }

/* ---------- controls ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 16px 28px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .label { font-size: 0.78rem; font-weight: 600; color: var(--ink-2); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.extra-row { display: flex; align-items: center; gap: 12px; }
.extra-row input[type=range] { width: min(260px, 40vw); accent-color: var(--accent); }
input[type=number], input[type=text], select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; min-width: 0; width: 100%;
}
input[type=number] { font-variant-numeric: tabular-nums; }
.money { position: relative; }
.money::before { content: "$"; position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.money input { padding-left: 20px; }
.pct { position: relative; }
.pct::after { content: "%"; position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.pct input { padding-right: 24px; }
.inline { display: flex; gap: 8px; }
.inline select { width: auto; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 7px 12px; cursor: pointer; font-weight: 600; font-size: 0.88rem; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); padding: 4px 8px; }
.btn.ghost:hover { color: var(--ink); background: var(--surface-2); }
.btn.danger { color: var(--warn); }

/* ---------- main grid ---------- */
.main { display: grid; grid-template-columns: minmax(0, 400px) minmax(0, 1fr); gap: 24px; align-items: start; }
.rail { display: flex; flex-direction: column; gap: 12px; }
.results { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }

/* debt cards */
.debt { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.debt-head { display: flex; gap: 8px; align-items: center; }
.debt-head input { font-weight: 600; border-color: transparent; background: transparent; padding-left: 4px; }
.debt-head input:hover, .debt-head input:focus { border-color: var(--line); background: var(--surface); }
.debt-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.debt-grid .full { grid-column: 1 / -1; }
.debt-foot { display: flex; flex-direction: column; gap: 6px; font-size: 0.84rem; color: var(--ink-2); border-top: 1px dashed var(--line); padding-top: 8px; }
.debt-foot .warnline { color: var(--warn); font-weight: 600; }
.idr-box { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; background: var(--surface-2); border-radius: 8px; padding: 10px; }
.idr-box .full { grid-column: 1 / -1; }
.example-note { background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; font-size: 0.88rem; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th { text-align: left; font-size: 0.75rem; font-weight: 600; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.r, th.r { text-align: right; }
tr.sel td { background: var(--accent-soft); }
tr.pick { cursor: pointer; }
tr.pick:hover td { background: var(--surface-2); }
tr.sel.pick:hover td { background: var(--accent-soft); }
.key { display: inline-block; width: 16px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 8px; }
.key.dash { border-top-style: dashed; }
.pos { color: var(--good); font-weight: 600; }

/* chart */
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.85rem; color: var(--ink-2); }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font: 11px var(--f-body); font-variant-numeric: tabular-nums; }
.chart text.end { fill: var(--ink-2); font-weight: 600; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 0.82rem; box-shadow: 0 6px 18px rgb(0 0 0 / 0.14); min-width: 170px; z-index: 2; }
.tip .t { color: var(--muted); font-size: 0.75rem; margin-bottom: 4px; }
.tip .row { display: flex; align-items: center; gap: 8px; }
.tip .row b { font-variant-numeric: tabular-nums; }
.tip .row span { color: var(--muted); }

/* payoff timeline */
.tl { display: grid; grid-template-columns: minmax(0, 170px) minmax(0, 1fr); gap: 8px 14px; align-items: center; }
.tl-name { font-size: 0.86rem; font-weight: 600; min-width: 0; }
.tl-name span { display: block; font-weight: 400; color: var(--muted); font-size: 0.78rem; }
.tl-track { position: relative; height: 18px; background: var(--surface-2); border-radius: 4px; }
.tl-seg { position: absolute; top: 0; bottom: 0; }
.tl-seg.min { background: var(--bar-min); border-radius: 4px 0 0 4px; }
.tl-seg.focus { background: var(--bar-focus); border-radius: 0 4px 4px 0; }
.tl-seg.only { border-radius: 4px; }
.tl-axis { position: relative; height: 16px; font-size: 0.72rem; color: var(--muted); }
.tl-axis span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.tl-legend { display: flex; gap: 18px; font-size: 0.82rem; color: var(--ink-2); flex-wrap: wrap; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 6px; }

.miles { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.miles li { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.miles li:first-child { border-top: 0; }
.miles .when { font-family: var(--f-mono); font-size: 0.8rem; color: var(--muted); line-height: 1.35; }
.miles .when b { display: block; color: var(--ink); font-weight: 500; font-size: 0.86rem; }
.miles .what { font-size: 0.92rem; }
.miles .what p + p { color: var(--ink-2); font-size: 0.86rem; }

.whatif-lines { display: flex; flex-direction: column; gap: 6px; font-size: 0.92rem; }

details.sched summary { cursor: pointer; font-family: var(--f-display); font-weight: 700; font-size: 1.05rem; }
.sched-body { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.sched-table { max-height: 460px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.sched-table table { font-family: var(--f-mono); font-size: 0.8rem; }
.sched-table th { position: sticky; top: 0; background: var(--surface); font-family: var(--f-body); }
.sched-table tr.payoff td { background: var(--good-soft); }

.plans-list { display: flex; flex-direction: column; gap: 6px; }
.plan-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.9rem; }
.plan-row > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notes { font-size: 0.85rem; color: var(--ink-2); display: flex; flex-direction: column; gap: 6px; padding-left: 18px; margin: 0; }

@media (max-width: 900px) {
  .main { grid-template-columns: minmax(0, 1fr); }
  .hero { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
  .debt-grid, .idr-box { grid-template-columns: minmax(0, 1fr); }
  .tl { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .tl-track { margin-bottom: 8px; }
  .tl-axis-label { display: none; }
  .miles li { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .hero { padding: 18px; }
}
@media (prefers-reduced-motion: no-preference) {
  .tl-seg { transition: left .25s ease, width .25s ease; }
}

/* ---------- tabs ---------- */
.view { display: flex; flex-direction: column; gap: 24px; }
.tabs { display: inline-flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.tabs button { border: 0; background: transparent; padding: 8px 16px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--ink-2); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.topbar { align-items: center; }

/* ---------- budget inputs ---------- */
.budget-main { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
.budget-results { min-width: 0; }
.lines { display: flex; flex-direction: column; gap: 18px; }
.group { display: flex; flex-direction: column; gap: 10px; }
.group + .group { border-top: 1px solid var(--line); padding-top: 16px; }
.group-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.group-total { font-weight: 700; font-family: var(--f-display); white-space: nowrap; }
.line { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.line-top { display: flex; gap: 8px; align-items: center; }
.line-top input { font-weight: 600; border-color: transparent; background: transparent; padding-left: 4px; }
.line-top input:hover, .line-top input:focus { border-color: var(--line); background: var(--surface); }
.line-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.line-hint { font-size: 0.8rem; color: var(--muted); min-height: 0; }
.line-hint:empty { display: none; }

/* ---------- budget summary ---------- */
.big { font-family: var(--f-display); font-weight: 700; font-size: clamp(2rem, 4.5vw, 2.8rem); line-height: 1.05; letter-spacing: -0.02em; color: var(--accent); }
.big small { display: block; font-size: 0.36em; letter-spacing: 0; color: var(--ink-2); font-weight: 500; margin-bottom: 4px; }
.big.warn { color: var(--warn); }
.big.good { color: var(--good); }
.alloc-wrap { position: relative; padding-top: 4px; }
.alloc { display: flex; gap: 2px; height: 22px; border-radius: 6px; overflow: hidden; background: var(--surface); }
.alloc-seg { flex-basis: 0; min-width: 2px; }
.alloc-seg.left { background: var(--surface-2); }
.alloc-mark { position: absolute; top: 0; bottom: -18px; border-left: 2px solid var(--ink); }
.alloc-mark span { position: absolute; bottom: 0; left: 4px; font-size: 0.72rem; font-weight: 600; white-space: nowrap; }
table.cash td { padding: 7px 8px; }
table.cash td:first-child { white-space: normal; }
.ef-summary { display: flex; flex-direction: column; gap: 12px; }
.budget-notes { margin-top: 0; }
table.cash tr.strong td { font-weight: 700; }
table.cash tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
table.cash tr.neg td { color: var(--warn); }
.sw.blank { background: transparent; }
.apply { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; border-top: 1px dashed var(--line); padding-top: 14px; }
.good-text { color: var(--good); font-weight: 600; }
.ef-wrap { display: flex; flex-direction: column; gap: 4px; }
.ef-meter { position: relative; height: 14px; background: var(--surface-2); border-radius: 7px; overflow: hidden; }
.ef-fill { height: 100%; border-radius: 7px; }
.ef-fill.good { background: var(--good); }
.ef-fill.warn { background: var(--warn); }
.ef-tick { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--surface); }
.ef-marks { position: relative; height: 16px; font-size: 0.72rem; color: var(--muted); }
.ef-marks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }

@media (max-width: 900px) {
  .budget-main { grid-template-columns: minmax(0, 1fr); }
  .budget-results { order: -1; }
  table.cash td:last-child { display: none; }
  table.cash td { padding: 7px 4px; }
}
@media (max-width: 480px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .tabs { width: 100%; }
  .tabs button { flex: 1; }
}
