:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5f6b7a;
  --line: #dfe3e8;
  --accent: #2563eb;
  --good: #15803d;
  --bad: #b91c1c;
  --series-a: #2563eb;
  --series-b: #d97706;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --card: #1b2129;
    --text: #e6eaef;
    --muted: #9aa5b3;
    --line: #2d3540;
    --accent: #60a5fa;
    --good: #4ade80;
    --bad: #f87171;
    --series-a: #60a5fa;
    --series-b: #fbbf24;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
.card h3:first-child { margin-top: 0; }

/* ───────────── Menu bar ───────────── */
.top {
  display: flex; align-items: center; gap: 8px 20px;
  padding: 10px 24px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.bar { display: flex; align-items: center; gap: 12px; }
.brand { white-space: nowrap; }
.current-page, .menu-toggle { display: none; }
.menu { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.tabs { display: flex; gap: 2px; }
.data-actions { margin-left: auto; display: flex; gap: 2px; padding-left: 12px; border-left: 1px solid var(--line); }
.tab, .menu-action {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: none; border: none; color: var(--muted); padding: 8px 10px; border-radius: 6px;
  cursor: pointer; font: inherit; font-size: 14px; margin: 0;
}
.tab:hover, .menu-action:hover { background: var(--bg); color: var(--text); }
.tab.active { background: var(--bg); color: var(--text); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
.ico { font-size: 15px; line-height: 1; }

/* Narrow screens: the menu folds into a "☰ Menu" button with a dropdown list. */
@media (max-width: 1180px) {
  .top { flex-direction: column; align-items: stretch; padding: 10px 16px; }
  .bar { justify-content: space-between; }
  .current-page { display: block; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--muted); font-size: 14px; }
  .menu-toggle { display: inline-flex; gap: 6px; align-items: center; }
  .menu { display: none; flex-direction: column; align-items: stretch; gap: 0; padding: 6px 0 4px; }
  .top.open .menu { display: flex; }
  .tabs { flex-direction: column; gap: 2px; }
  .data-actions { margin: 6px 0 0; padding: 6px 0 0; border-left: none; border-top: 1px solid var(--line); flex-direction: column; gap: 2px; }
  .tab, .menu-action { width: 100%; padding: 11px 12px; font-size: 15px; }
  .tab.active { box-shadow: inset 3px 0 0 var(--accent); }
}

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.panel { display: none; }
.panel.active { display: block; }

.grid.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 860px) { .grid.two { grid-template-columns: minmax(0, 1fr); } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 16px;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.disclaimer {
  background: var(--card); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 6px; margin: 0 0 16px;
}

label { display: block; margin-bottom: 10px; font-size: 14px; }
label small { color: var(--muted); }
label.inline { display: flex; gap: 8px; align-items: center; margin: 0; }
input, select {
  display: block; width: 100%; margin-top: 4px; padding: 7px 9px; font: inherit;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text);
}
label.inline select { width: auto; margin: 0; }
input[hidden] { display: none; }
.file-btn { display: inline-block; margin: 0; font-size: 15px; }
button, .file-btn {
  font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; cursor: pointer;
}
button.ghost, .file-btn { background: transparent; color: var(--text); border-color: var(--line); }
button.icon { background: none; border: none; color: var(--muted); padding: 4px 8px; }
button.icon:hover { color: var(--bad); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.debts input { margin: 0; padding: 5px 7px; min-width: 70px; }
table.debts { margin-bottom: 10px; }
.table-scroll { overflow-x: auto; max-height: 480px; overflow-y: auto; }
.table-scroll thead th { position: sticky; top: 0; background: var(--card); }

.result-big { font-size: 28px; font-weight: 700; margin: 4px 0 2px; }
.result-big.good { color: var(--good); }
.result-big.bad { color: var(--bad); }
dl.breakdown { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin: 12px 0 0; font-size: 14px; }
dl.breakdown dt { color: var(--muted); }
dl.breakdown dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
dl.breakdown .total { font-weight: 600; color: var(--text); border-top: 1px solid var(--line); padding-top: 4px; }

.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.strategy { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.strategy.best { border-color: var(--good); }
.strategy h4 { margin: 0 0 4px; font-size: 14px; }
.strategy .date { font-size: 20px; font-weight: 700; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
.warn { color: var(--bad); }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack button { margin-top: 4px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--line); }
.progress-bar { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; margin: 8px 0 16px; }
.progress-bar > div { height: 100%; background: var(--good); }

/* ───────────── Guided steps ───────────── */
.wizard { max-width: 760px; margin: 0 auto; }
.wizard .step { display: none; }
.wizard .step.current { display: block; }
.wizard .step.card h2 { font-size: 22px; }

.stepper { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 16px; }
.stepper li { flex: 1 1 0; min-width: 0; }
.stepper button {
  width: 100%; background: none; border: none; border-top: 4px solid var(--line); border-radius: 0;
  padding: 6px 2px 0; color: var(--muted); font-size: 12px; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 900px) {
  .stepper button { font-size: 0; }
  .stepper .current { flex: 3 1 0; }
  .stepper .current button { font-size: 13px; }
}
.stepper .done button { border-top-color: var(--good); color: var(--text); }
.stepper .current button { border-top-color: var(--accent); color: var(--text); font-weight: 600; }

.wizard-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 4px; }
.wizard-nav button { padding: 10px 20px; font-size: 16px; }
.wizard-nav [hidden] { display: none; }

.choices { display: grid; gap: 8px; margin: 12px 0; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; margin: 0; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer; background: var(--bg);
}
.choice:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.choice input { width: auto; margin: 3px 0 0; flex: none; }
.choice span { color: var(--muted); font-size: 14px; }
.choice strong { display: block; color: var(--text); font-size: 15px; }
.choices.compact .choice { padding: 8px 12px; }

.hint { margin: -4px 0 14px; font-size: 13px; color: var(--muted); background: var(--bg); padding: 8px 10px; border-radius: 6px; }
.checklist li, .explain li { margin-bottom: 8px; }
.explain { padding-left: 22px; }
.explain li span { display: block; color: var(--muted); font-size: 14px; }

details { margin: 10px 0; }
details > summary { cursor: pointer; color: var(--accent); font-weight: 500; padding: 4px 0; }
details[open] > summary { margin-bottom: 8px; }
details.card > summary { color: var(--text); font-weight: 600; }

.glossary { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 18px 0 0; font-size: 13px; }
.glossary dt { font-weight: 600; }
.glossary dd { margin: 0; color: var(--muted); }
@media (max-width: 560px) { .glossary { grid-template-columns: 1fr; } .glossary dd { margin-bottom: 6px; } }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 12px 0; }
.tile { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.tile .label { color: var(--muted); font-size: 13px; }
.tile .result-big { font-size: 26px; }
.lead { font-size: 17px; }
.budget-line { font-weight: 500; }
.intro p { margin-bottom: 0; }

/* ───────────── Debt-free banner ───────────── */
.freedom {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px;
  max-width: 760px; margin: 0 auto 18px; padding: 16px 20px; border-radius: 12px;
  background: var(--good); color: #fff;
}
.freedom[hidden] { display: none; }
.freedom-main { display: flex; flex-direction: column; }
.freedom-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.9; }
.freedom-date { font-size: 34px; font-weight: 800; line-height: 1.1; }
.freedom-meta { display: flex; flex-direction: column; gap: 2px; font-size: 14px; flex: 1 1 220px; }
.freedom-paid { font-weight: 600; }
.freedom button { margin-left: auto; background: rgba(255, 255, 255, 0.15); color: #fff; border-color: rgba(255, 255, 255, 0.6); }
.freedom.stuck { background: var(--bad); }
.freedom.done { background: linear-gradient(120deg, var(--good), var(--accent)); }
@media (prefers-color-scheme: dark) {
  .freedom { color: #0b1a10; }
  .freedom button { color: #0b1a10; border-color: rgba(0, 0, 0, 0.35); background: rgba(255, 255, 255, 0.25); }
}

/* ───────────── What-if slider, refund button ───────────── */
.whatif h3 { margin: 0; }
.whatif-amount { font-size: 20px; color: var(--accent); }
.whatif input[type="range"] { padding: 0; border: none; background: none; accent-color: var(--accent); height: 28px; margin: 10px 0 4px; }
.good-note { background: var(--bg); border-left: 4px solid var(--good); padding: 8px 12px; border-radius: 6px; }
.refund-cta {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  margin: 18px 0 6px; padding: 14px 16px; border-radius: 10px; border: 2px solid var(--good); background: var(--bg);
}
.refund-cta span { display: block; color: var(--muted); font-size: 14px; }
.refund-cta button { background: var(--good); border-color: var(--good); }

/* ───────────── Savings cushion, buttons ───────────── */
label.check { display: flex; gap: 10px; align-items: center; font-weight: 500; }
label.check input { width: auto; margin: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.two-col[hidden] { display: none; }
@media (max-width: 560px) { .two-col { grid-template-columns: 1fr; } }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ───────────── Printable summary ───────────── */
#print-summary { display: none; }
@media print {
  .top, main { display: none !important; }
  body { background: #fff; color: #000; font-size: 12px; }
  #print-summary { display: block; padding: 0; }
  #print-summary h1 { font-size: 20px; margin: 0 0 2px; }
  #print-summary h2 { font-size: 15px; margin: 16px 0 6px; border-bottom: 2px solid #000; padding-bottom: 2px; }
  #print-summary .big { font-size: 26px; font-weight: 800; }
  #print-summary table { font-size: 11px; }
  #print-summary th, #print-summary td { border: 1px solid #999; padding: 3px 6px; color: #000; }
  #print-summary .box { display: inline-block; width: 12px; height: 12px; border: 1.5px solid #000; }
  #print-summary .muted { color: #444; }
  #print-summary section { break-inside: avoid; }
}
.whatif-amount { display: flex; align-items: center; gap: 4px; margin: 0; font-weight: 700; }
.whatif-amount input { width: 9em; margin: 0; font-size: 18px; font-weight: 700; color: var(--accent); text-align: right; }

/* ───────────── Subscriptions ───────────── */
table.subs select { margin: 0; padding: 5px 7px; width: auto; }
table.subs input[data-f="name"] { min-width: 120px; }
table.subs input[data-f="cost"] { width: 90px; }
table.subs tr.sub-cancel td:first-child input { border-color: var(--series-b); }
table.subs tr.sub-canceled input { text-decoration: line-through; color: var(--muted); }
ul.soon { padding-left: 18px; margin: 6px 0 12px; }
ul.soon li { margin-bottom: 4px; }
button[disabled] { opacity: 0.45; cursor: not-allowed; }
.af-message { background: var(--bg); border-left: 4px solid var(--accent); padding: 8px 12px; border-radius: 6px; }
table.found select { margin: 0; padding: 4px 6px; width: auto; }
table.found input[type="checkbox"] { width: auto; margin: 0; }
table.debts input.due { width: 70px; min-width: 60px; }

/* ───────────── Payments tab ───────────── */
ol.payoff { list-style: none; padding: 0; margin: 12px 0; }
ol.payoff li { margin-bottom: 4px; }
.payoff-row { display: flex; align-items: center; gap: 12px; }
.payoff-num { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--bg); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 13px; font-weight: 600; }
.payoff-name, .payoff-when { display: flex; flex-direction: column; }
.payoff-name { flex: 1; min-width: 0; }
.payoff-when { text-align: right; }
ol.payoff .progress-bar { margin: 6px 0 12px 38px; }
.pm-label { min-width: 130px; text-align: center; }
table.pay-cal tr.past td { color: var(--muted); }
table.pay-cal tfoot td { border-bottom: none; border-top: 2px solid var(--line); }
table.pay-cal td:nth-child(2) { white-space: normal; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line); }
.pill.debt { color: var(--series-a); border-color: var(--series-a); }
.pill.sub { color: var(--series-b); border-color: var(--series-b); }
.pill.save { color: var(--good); border-color: var(--good); }

/* ───────────── Demo banner ───────────── */
.demo-banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px;
  background: var(--card); border: 2px dashed var(--series-b); border-radius: 10px; padding: 12px 16px; margin-bottom: 16px;
}
.demo-banner span { display: block; color: var(--muted); font-size: 14px; }
.demo-exit { color: var(--accent); font-size: 14px; }
@media print { .demo-banner { display: none; } }

/* ───────────── Accounts ───────────── */
.account-dialog {
  width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto;
  border: 1px solid var(--line); border-radius: 12px; padding: 22px; background: var(--card); color: var(--text);
}
.account-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.acct-close { position: absolute; top: 10px; right: 10px; font-size: 16px; }
.acct-tabs { display: flex; gap: 4px; margin: 0 0 16px; border-bottom: 1px solid var(--line); }
.acct-tabs button { background: none; border: none; color: var(--muted); border-radius: 0; padding: 8px 12px; margin-bottom: -1px; }
.acct-tabs button.active { color: var(--text); font-weight: 600; border-bottom: 2px solid var(--accent); }
.account-dialog button[type=submit] { width: 100%; padding: 10px; font-size: 16px; }
button.link { background: none; border: none; color: var(--accent); padding: 4px 0; text-decoration: underline; }
button.danger { background: var(--bad); border-color: var(--bad); }
.acct-danger { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
.acct-danger summary { color: var(--bad); cursor: pointer; font-size: 14px; }
.acct-status { font-size: 14px; margin: 4px 0 10px; }
.acct-status.saved { color: var(--good); }
.acct-status.offline, .acct-status.error { color: var(--bad); }
.acct-dot { width: 8px; height: 8px; border-radius: 50%; display: none; }
.account-btn[data-status="saved"] .acct-dot { display: inline-block; background: var(--good); }
.account-btn[data-status="saving"] .acct-dot { display: inline-block; background: var(--series-b); }
.account-btn[data-status="offline"] .acct-dot, .account-btn[data-status="error"] .acct-dot { display: inline-block; background: var(--bad); }
.demo-note { background: var(--bg); border: 1px dashed var(--series-b); border-radius: 8px; padding: 8px 12px; font-size: 14px; }
