/* ===== Tokens ===== */
:root {
  --navy: #0F2540;
  --navy-light: #16345A;
  --paper: #F4F7F6;
  --card: #FFFFFF;
  --mint: #2ECC91;
  --mint-dark: #22A876;
  --coral: #FF7A5C;
  --amber: #FFB238;
  --blue: #4C9EEB;
  --purple: #9B7BEB;
  --slate: #8CA3BE;
  --ink: #12233B;
  --ink-soft: #5B7089;
  --line: #E3E9E6;
  --danger: #F0483E;
  --danger-bg: #FDE7E5;
  --warn: #F5A623;
  --warn-bg: #FEF3E0;
  --good: #22A876;
  --good-bg: #E4F7EF;

  --font-display: 'Baloo 2', sans-serif;
  --font-body: 'Nunito Sans', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --wrap: 1180px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
  font-size: 16px;
}

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 24px; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; margin: 0; color: var(--navy); }
a { color: var(--mint-dark); }
:focus-visible { outline: 3px solid var(--mint); outline-offset: 2px; }
.hidden { display: none !important; }

/* ===== Header ===== */
.site-header { position: sticky; top: 0; z-index: 60; background: var(--navy); }
.header-inner { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }
.logo { display: flex; align-items: center; gap: 8px; }
.logo-badge { font-size: 2.8rem; }
.logo-text { font-family: var(--font-display); font-size: 2.7rem; font-weight: 700; color: #fff; }
.logo-text em { font-style: normal; color: var(--mint); }
.btn-check {
  background: var(--mint); color: var(--navy); font-weight: 700; padding: 10px 20px; border-radius: 999px;
  text-decoration: none; font-size: 0.92rem; display: inline-flex; align-items: center; justify-content: center;
  line-height: 1.2; font-family: inherit; box-sizing: border-box; border: 1.5px solid transparent;
}
.btn-check:hover { background: #3EE0A6; }

.header-actions { display: flex; align-items: center; gap: 10px; }

/* ===== Hero ===== */
.hero { background: var(--navy); padding: 56px 0 90px; }
.hero-inner { max-width: 640px; }
.eyebrow { font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.75rem; color: var(--mint); margin: 0 0 16px; }
.hero h1 { color: #fff; font-size: clamp(2rem, 4.5vw, 3.2rem); line-height: 1.12; }
.hero-sub { color: #B9C6D6; font-size: 1.1rem; margin: 20px 0 0; max-width: 52ch; }

/* ===== Sections ===== */
.calc-section, .results-section { padding: 48px 0; }
.section-head { max-width: 60ch; margin-bottom: 26px; }
.step-label { font-family: var(--font-mono); color: var(--mint-dark); text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem; margin: 0 0 6px; }
.section-head h2 { font-size: clamp(1.5rem, 2.8vw, 2rem); }
.section-sub { color: var(--ink-soft); margin: 8px 0 0; }

.transition-banner {
  background: var(--good-bg); border-radius: var(--radius-md);
  padding: 18px 24px; display: flex; align-items: center; justify-content: space-between;
  color: var(--navy); font-weight: 700; font-family: var(--font-display); font-size: 1.05rem;
}
.transition-banner span { color: var(--mint-dark); font-size: 1.3rem; }

.step1-head-row { display: flex; align-items: center; justify-content: flex-start; flex-wrap: wrap; gap: 14px; margin-bottom: 22px; }
.step1-head-row .mode-switcher { margin-bottom: 0; }

/* ===== Mode switcher ===== */
.mode-switcher { display: flex; gap: 8px; margin-bottom: 22px; background: #fff; padding: 6px; border-radius: 999px; width: fit-content; box-shadow: 0 2px 10px rgba(15,37,64,0.08); }
.mode-btn { border: none; background: transparent; padding: 10px 22px; border-radius: 999px; font-family: var(--font-body); font-weight: 700; font-size: 0.95rem; color: var(--ink-soft); cursor: pointer; }
.mode-btn.active { background: var(--navy); color: #fff; }

/* ===== Cards ===== */
.card { background: var(--card); border-radius: var(--radius-lg); padding: 28px 30px; box-shadow: 0 4px 18px rgba(15,37,64,0.06); }
.card h3 { font-size: 1.3rem; margin-bottom: 20px; }
.card h4 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); font-family: var(--font-mono); font-weight: 600; margin: 0; }
.expense-group:first-of-type h4 { border-top: none; padding-top: 0; }

.expenses-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.clear-all-btn {
  background: none; border: 1.5px solid var(--danger); color: var(--danger); font-weight: 700;
  font-size: 0.82rem; padding: 7px 14px; border-radius: 999px; cursor: pointer;
}
.clear-all-btn:hover { background: var(--danger-bg); }

.group-head { display: flex; align-items: center; justify-content: space-between; padding-top: 18px; border-top: 1px dashed var(--line); margin-bottom: 12px; }
.expense-group:first-of-type .group-head { border-top: none; padding-top: 0; }
.clear-section-btn {
  background: none; border: none; color: var(--ink-soft); font-weight: 600; font-size: 0.78rem;
  cursor: pointer; text-decoration: underline; padding: 2px 4px;
}
.clear-section-btn:hover { color: var(--danger); }

/* ===== Calc grid ===== */
.calc-grid { display: grid; grid-template-columns: 1.25fr 0.85fr; gap: 24px; align-items: start; }
.field-row { margin-bottom: 16px; }
.field-row label { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; font-weight: 700; color: var(--navy); margin-bottom: 6px; }
.label-note { font-weight: 400; color: var(--ink-soft); font-size: 0.85em; }
.field-row-inline { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }

input[type="number"], select {
  width: 100%; font-family: var(--font-mono); font-size: 1rem; padding: 11px 13px;
  border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--paper); color: var(--ink);
}
select { font-family: var(--font-body); }
input[type="number"]:focus, select:focus { border-color: var(--mint); background: #fff; }

.input-prefix, .input-suffix { display: flex; align-items: center; border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--paper); overflow: hidden; }
.input-prefix:focus-within, .input-suffix:focus-within { border-color: var(--mint); background: #fff; }
.input-prefix span, .input-suffix span { font-family: var(--font-mono); color: var(--ink-soft); padding: 0 11px; flex-shrink: 0; }
.input-prefix input, .input-suffix input { border: none; background: transparent; flex: 1; min-width: 0; padding: 11px 8px; }
.input-prefix input:focus, .input-suffix input:focus { outline: none; }

.down-toggle-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.down-toggle-row input[type=number] { flex: 1; min-width: 90px; }
.unit-toggle { display: flex; border: 2px solid var(--line); border-radius: 999px; overflow: hidden; }
.unit-btn { border: none; background: transparent; padding: 8px 14px; font-family: var(--font-mono); font-weight: 700; font-size: 0.85rem; cursor: pointer; color: var(--ink-soft); }
.unit-btn.active { background: var(--mint); color: #fff; }
.input-combo-readout { font-family: var(--font-mono); color: var(--ink-soft); font-size: 0.88rem; }

.pill-group { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { border: 2px solid var(--line); background: var(--paper); padding: 9px 16px; border-radius: 999px; font-weight: 700; font-size: 0.88rem; cursor: pointer; color: var(--ink-soft); font-family: var(--font-body); }
.pill.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.pill:hover:not(.active) { border-color: var(--mint); }

.pmi-pill { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 14px; line-height: 1.2; }
.pmi-pill-label { font-weight: 700; }
.pmi-pill-amt { font-family: var(--font-mono); font-size: 0.72rem; font-weight: 500; opacity: 0.85; }
.pmi-pill.active .pmi-pill-amt { opacity: 1; }

.credit-band-group { display: flex; gap: 8px; flex-wrap: wrap; }
.credit-band-btn { border: 2px solid var(--line); background: var(--paper); padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer; text-align: left; font-family: var(--font-body); }
.credit-band-btn.active { border-color: var(--mint); background: var(--good-bg); }
.credit-band-btn .cb-label { display: block; font-weight: 700; font-size: 0.85rem; color: var(--navy); }
.credit-band-btn .cb-range { display: block; font-size: 0.75rem; color: var(--ink-soft); font-family: var(--font-mono); }

.field-hint { font-size: 0.82rem; color: var(--ink-soft); margin: -8px 0 16px; }
.field-hint a { color: var(--ink-soft); text-decoration: underline; }
.caution-hint { background: var(--warn-bg); color: #8A5A00; padding: 10px 14px; border-radius: var(--radius-sm); margin-top: 4px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--ink-soft); margin: 6px 0 16px; cursor: pointer; font-weight: 600; }
.checkbox-row input { width: auto; }

.advanced-toggle {
  display: flex; align-items: center; gap: 6px; background: none; border: none; color: var(--mint-dark);
  font-weight: 700; font-size: 0.9rem; cursor: pointer; padding: 6px 0; margin: 4px 0 4px;
}
.advanced-toggle .chevron { transition: transform 0.15s ease; }
.advanced-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.advanced-panel { padding-top: 12px; border-top: 1px dashed var(--line); margin-top: 8px; }

.info-btn {
  width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--ink-soft); color: var(--ink-soft);
  background: transparent; font-family: var(--font-mono); font-size: 0.7rem; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.info-btn:hover { border-color: var(--mint-dark); color: var(--mint-dark); }

.popover {
  position: relative; background: #FBFDF3; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px 34px 14px 16px; font-size: 0.85rem; color: var(--ink-soft); margin: -4px 0 16px; max-width: 60ch;
}
.popover-close {
  position: absolute; top: 8px; right: 10px; border: none; background: none; font-size: 1.1rem;
  line-height: 1; cursor: pointer; color: var(--ink-soft); padding: 2px 6px;
}
.popover-close:hover { color: var(--danger); }
.rate-source-blurb { display: inline-block; margin-top: 6px; font-family: var(--font-mono); font-size: 0.78rem; color: var(--mint-dark); }

.income-readout { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 20px; padding-top: 20px; border-top: 1px dashed var(--line); }
.readout-label { display: block; font-size: 0.8rem; color: var(--ink-soft); margin-bottom: 4px; }
.readout-value { display: block; font-family: var(--font-mono); font-size: 1.5rem; font-weight: 700; color: var(--navy); }
.readout-net { color: var(--mint-dark); }

.borrower-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--mint-dark); font-family: var(--font-mono); font-weight: 700; margin: 18px 0 12px; padding-top: 14px; border-top: 1px dashed var(--line); }
.borrower-label:first-child { border-top: none; padding-top: 0; margin-top: 0; }

.unit-toggle-mini {
  display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px;
  border-radius: 5px; border: 1.5px solid var(--mint); background: var(--good-bg); color: var(--mint-dark);
  font-family: var(--font-mono); font-size: 0.7rem; font-weight: 700; cursor: pointer; padding: 0; vertical-align: middle;
}
.unit-toggle-mini:hover { background: var(--mint); color: #fff; }

/* ===== Expenses ===== */
.expenses-card { margin-top: 20px; }
.expense-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px; }
.expense-grid .expense-group { border: 1.5px solid var(--line); border-radius: var(--radius-md); padding: 18px; }
.expense-grid .group-head { border-top: none; padding-top: 0; }
.expense-row { display: grid; grid-template-columns: 1fr 120px; align-items: center; gap: 12px; margin-bottom: 9px; }
.expense-row label { font-size: 0.9rem; color: var(--ink-soft); font-weight: 600; }
.custom-expense-row { grid-template-columns: 1fr 120px 30px; }
.custom-label-input { font-family: var(--font-body); padding: 9px 10px; border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--paper); font-size: 0.9rem; width: 100%; max-width: 190px; box-sizing: border-box; }
.remove-row-btn { width: 28px; height: 28px; border-radius: 8px; border: 1.5px solid var(--line); background: transparent; color: var(--danger); cursor: pointer; font-size: 1rem; }
.remove-row-btn:hover { background: var(--danger-bg); }
.add-field-btn {
  background: none; border: 1.5px dashed var(--line); color: var(--mint-dark); font-weight: 700;
  font-size: 0.85rem; padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer; margin-top: 4px;
}
.add-field-btn:hover { border-color: var(--mint); background: var(--good-bg); }

/* ===== Ledger tape / sticky summary ===== */
.ledger-tape {
  position: sticky; top: 100px; background: var(--navy); color: #fff; border-radius: var(--radius-lg);
  padding: 24px 22px; box-shadow: 0 12px 30px rgba(15,37,64,0.25);
}
.tape-title { font-family: var(--font-body); font-size: 0.85rem; color: #C7D4E3; margin: 0 0 6px; text-align: left; text-transform: none; letter-spacing: normal; }
.tape-row { display: flex; justify-content: space-between; gap: 10px; font-size: 0.9rem; padding: 5px 0; color: #C7D4E3; }
.tape-row span:last-child { font-weight: 700; color: #fff; font-family: var(--font-mono); }
.tape-divider { border-top: 1px solid rgba(255,255,255,0.15); margin: 10px 0; }
.tape-divider-light { border-top-style: dashed; opacity: 0.6; }
.tape-total { font-size: 1.05rem; }
.tape-total span:last-child { color: var(--mint); font-size: 1.35rem; }
.tape-meta { font-size: 0.8rem; opacity: 0.85; }
.tape-highlight span:last-child { color: var(--amber); }
.ledger-tape.wide { max-width: 400px; }

.total-payment-value {
  font-family: -apple-system, 'Segoe UI', Roboto, sans-serif; font-size: 2.6rem; font-weight: 800;
  color: var(--mint); line-height: 1.05; letter-spacing: -0.01em; margin-bottom: 16px;
}
.payment-bar { width: 100%; height: 16px; border-radius: 8px; overflow: hidden; display: flex; margin-bottom: 14px; }
.payment-bar > div { height: 100%; }
.tape-legend { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.legend-row { display: flex; align-items: center; justify-content: space-between; font-size: 0.82rem; gap: 8px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; flex-shrink: 0; }
.legend-label { display: flex; align-items: center; color: #C7D4E3; }
.legend-value { font-family: var(--font-mono); color: #fff; font-weight: 600; }

.stamp {
  margin: 18px auto 0; width: fit-content; border: 3px solid var(--good); color: var(--good);
  background: rgba(46,204,145,0.12); border-radius: 10px; padding: 8px 20px; font-family: var(--font-mono);
  font-weight: 800; letter-spacing: 0.06em; font-size: 0.95rem; transform: rotate(-4deg); text-align: center;
}
.stamp.deficit { border-color: var(--danger); color: var(--danger); background: rgba(240,72,62,0.12); }
.stamp.tight { border-color: var(--coral); color: var(--coral); background: rgba(255,122,92,0.12); }
.stamp.mid { border-color: var(--blue); color: var(--blue); background: rgba(76,158,235,0.12); }

/* ===== Sliders ===== */
.field-slider { width: 100%; margin-top: 10px; accent-color: var(--mint); height: 20px; cursor: pointer; }

/* ===== Budget layout ===== */
.budget-layout { display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: start; }
.budget-main { display: flex; flex-direction: column; gap: 20px; }
.sticky-summary-slot { position: sticky; top: 100px; }

/* ===== Results ===== */
.ratios-panel { display: flex; flex-direction: column; gap: 24px; margin-bottom: 24px; }
.ratio-block:not(:last-child) { padding-bottom: 20px; border-bottom: 1px dashed var(--line); }
.ratio-label { display: flex; justify-content: space-between; font-size: 0.92rem; font-weight: 700; margin-bottom: 8px; color: var(--navy); }
.ratio-label span:last-child { font-family: var(--font-mono); color: var(--mint-dark); }
.ratio-bar { position: relative; height: 14px; background: var(--paper); border-radius: 999px; overflow: visible; border: 1.5px solid var(--line); }
.ratio-fill { height: 100%; background: linear-gradient(90deg, var(--mint), var(--mint-dark)); border-radius: 999px; width: 0%; transition: width 0.2s ease; }
.ratio-fill.warn { background: linear-gradient(90deg, var(--amber), #E08F00); }
.ratio-fill.over { background: linear-gradient(90deg, var(--danger), #C7362D); }
.ratio-marker { position: absolute; top: -4px; width: 3px; height: 22px; background: var(--navy); opacity: 0.4; border-radius: 2px; }
.ratio-marker-label span { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); font-size: 0.68rem; font-family: var(--font-mono); color: var(--ink-soft); white-space: nowrap; }
.ratio-hint { font-size: 0.8rem; color: var(--ink-soft); margin: 8px 0 0; }

.suggestions-card ul { margin: 0; padding-left: 20px; color: var(--ink-soft); }
.suggestions-card li { margin-bottom: 10px; line-height: 1.55; }
.suggestions-card li::marker { color: var(--mint-dark); }

/* ===== Affordability box ===== */
.afford-box { border-radius: var(--radius-lg); overflow: hidden; box-shadow: 0 4px 18px rgba(15,37,64,0.06); margin-bottom: 24px; }
.afford-box-head { background: var(--navy); color: #fff; padding: 24px 30px; }
.afford-box-head h3 { color: #fff; font-size: 1.7rem; margin: 0 0 4px; }
.afford-box-head p { margin: 0; color: #B9C6D6; font-size: 0.95rem; }
.afford-box-body { background: var(--card); padding: 24px 30px 28px; }
.afford-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 20px; }
.afford-stat { background: var(--paper); border-radius: var(--radius-md); padding: 20px 22px; display: flex; flex-direction: column; gap: 6px; }
.afford-stat-highlight { background: var(--good-bg); }
.afford-stat-highlight.deficit { background: var(--danger-bg); }
.afford-stat-label { font-size: 0.92rem; color: var(--ink-soft); font-weight: 600; }
.afford-stat-value { font-family: -apple-system, 'Segoe UI', Roboto, sans-serif; font-size: 2.2rem; font-weight: 800; color: var(--navy); letter-spacing: -0.01em; line-height: 1.1; }
.afford-stat-highlight .afford-stat-value { color: var(--good); }
.afford-stat-highlight.deficit .afford-stat-value { color: var(--danger); }
.afford-stat-note { font-size: 0.8rem; color: var(--ink-soft); }
.afford-verdict { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 18px 22px; border-radius: var(--radius-md); background: var(--good-bg); }
.afford-verdict.tight { background: var(--warn-bg); }
.afford-verdict.mid { background: rgba(76,158,235,0.12); }
.afford-verdict.deficit { background: var(--danger-bg); }
.afford-verdict-icon { width: 30px; height: 30px; border-radius: 50%; border: 2.5px solid var(--good); color: var(--good); display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.95rem; flex-shrink: 0; }
.afford-verdict.tight .afford-verdict-icon { border-color: var(--warn); color: var(--warn); }
.afford-verdict.mid .afford-verdict-icon { border-color: var(--blue); color: var(--blue); }
.afford-verdict.deficit .afford-verdict-icon { border-color: var(--danger); color: var(--danger); }
.afford-verdict-title { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; color: var(--good); }
.afford-verdict.tight .afford-verdict-title { color: #A96C00; }
.afford-verdict.mid .afford-verdict-title { color: var(--blue); }
.afford-verdict.deficit .afford-verdict-title { color: var(--danger); }
.afford-verdict-text { color: var(--ink-soft); font-size: 0.95rem; flex: 1; min-width: 200px; }

/* ===== Save / Auth ===== */
.btn-save {
  background: var(--mint); color: var(--navy); font-weight: 700; padding: 10px 20px; border: 1.5px solid transparent;
  border-radius: 999px; font-size: 0.92rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  line-height: 1.2; font-family: inherit; box-sizing: border-box; appearance: none; -webkit-appearance: none;
}
.btn-save:hover { background: #3EE0A6; }
.login-link {
  background: transparent; color: var(--mint); font-weight: 700; padding: 9px 19px; border: 1.5px solid var(--mint);
  border-radius: 999px; font-size: 0.92rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  line-height: 1.2; font-family: inherit; box-sizing: border-box; appearance: none; -webkit-appearance: none;
  text-decoration: none;
}
.login-link:hover { background: rgba(46,204,145,0.12); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,37,64,0.55); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box { background: #fff; border-radius: var(--radius-lg); padding: 30px 32px; max-width: 460px; width: 100%; position: relative; max-height: 88vh; overflow-y: auto; }
.modal-close { position: absolute; top: 16px; right: 18px; border: none; background: none; font-size: 1.4rem; color: var(--ink-soft); cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--danger); }
.modal-box h3 { font-size: 1.4rem; margin-bottom: 6px; }
.modal-sub { color: var(--ink-soft); font-size: 0.9rem; margin: 0 0 20px; }

.auth-tabs { display: flex; gap: 6px; background: var(--paper); border-radius: 999px; padding: 5px; margin-bottom: 20px; }
.auth-tab { flex: 1; border: none; background: transparent; padding: 9px 12px; border-radius: 999px; font-weight: 700; font-size: 0.85rem; cursor: pointer; color: var(--ink-soft); }
.auth-tab.active { background: var(--navy); color: #fff; }

.auth-btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-primary-modal { background: var(--mint); color: #fff; font-weight: 700; padding: 11px 20px; border: none; border-radius: 8px; cursor: pointer; font-size: 0.92rem; flex: 1; }
.btn-primary-modal:hover { background: var(--mint-dark); }
.btn-ghost-modal { background: transparent; color: var(--navy); font-weight: 700; padding: 11px 20px; border: 1.5px solid var(--line); border-radius: 8px; cursor: pointer; font-size: 0.92rem; }
.btn-ghost-modal:hover { border-color: var(--navy); }
.auth-status { font-size: 0.85rem; margin-top: 10px; min-height: 1.2em; color: var(--ink-soft); }
.auth-status.error { color: var(--danger); }
.auth-status.success { color: var(--good); }

.save-current-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.save-current-row input[type="text"] { flex: 1; min-width: 180px; font-family: var(--font-body); padding: 11px 13px; border: 2px solid var(--line); border-radius: var(--radius-sm); }

.scenario-list { display: flex; flex-direction: column; gap: 8px; margin: 18px 0; max-height: 240px; overflow-y: auto; }
.scenario-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--paper); border-radius: var(--radius-sm); padding: 12px 14px; }
.scenario-row-name { font-weight: 700; color: var(--navy); font-size: 0.92rem; }
.scenario-row-date { font-size: 0.75rem; color: var(--ink-soft); }
.scenario-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.scenario-row-actions button { border: none; background: none; cursor: pointer; font-weight: 700; font-size: 0.8rem; padding: 6px 10px; border-radius: 6px; }
.scenario-load-btn { color: var(--mint-dark); }
.scenario-load-btn:hover { background: var(--good-bg); }
.scenario-delete-btn { color: var(--danger); }
.scenario-delete-btn:hover { background: var(--danger-bg); }
.scenario-empty { color: var(--ink-soft); font-size: 0.88rem; text-align: center; padding: 20px 0; }

.see-why { margin-top: 14px; text-align: center; }
.see-why p { font-size: 0.82rem; color: #C7D4E3; margin: 0 0 6px; }
.see-why-btn {
  background: none; border: none; color: var(--amber); font-weight: 700; font-size: 0.85rem;
  cursor: pointer; padding: 2px 4px; text-decoration: underline;
}
.see-why-btn:hover { color: var(--mint); }
.afford-verdict .see-why-btn { color: inherit; text-decoration: underline; font-size: 0.9rem; flex-basis: 100%; text-align: left; margin-top: 4px; }

.ratio-flash { animation: ratioFlash 1.8s ease; }
@keyframes ratioFlash {
  0% { box-shadow: 0 0 0 4px rgba(245,166,35,0.5); border-radius: var(--radius-md); }
  100% { box-shadow: 0 0 0 0 rgba(245,166,35,0); border-radius: var(--radius-md); }
}

/* ===== Back to top ===== */
.back-to-top {
  position: fixed; bottom: 26px; right: 26px; width: 48px; height: 48px; border-radius: 50%;
  background: var(--navy); color: #fff; border: none; font-size: 1.3rem; cursor: pointer;
  box-shadow: 0 6px 18px rgba(15,37,64,0.3); z-index: 70; opacity: 1; transition: opacity 0.2s ease, transform 0.15s ease;
}
.back-to-top:hover { background: var(--navy-light); transform: translateY(-2px); }
.back-to-top.hidden { opacity: 0; pointer-events: none; }

/* ===== Footer ===== */
.site-footer { border-top: 1px solid var(--line); padding: 30px 0 46px; background: var(--paper); }
.footer-inner p { font-size: 0.83rem; color: var(--ink-soft); max-width: 74ch; margin: 0 0 10px; }
.footer-refs a { color: var(--ink-soft); }
.footer-copy { opacity: 0.7; }

.export-buttons { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 14px; }

/* ===== Legal pages ===== */
.legal-hero { background: var(--navy); padding: 40px 0 44px; }
.legal-hero h1 { color: #fff; font-size: clamp(1.7rem, 3.5vw, 2.3rem); }
.legal-hero p { color: #B9C6D6; margin: 10px 0 0; font-family: var(--font-mono); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; }
.legal-hero a.back-link { color: var(--mint); text-decoration: none; font-family: var(--font-mono); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }
.legal-hero a.back-link:hover { text-decoration: underline; }
.legal-body { padding: 44px 0 70px; }
.legal-content { max-width: 76ch; }
.legal-content h2 { font-size: 1.25rem; margin: 40px 0 12px; }
.legal-content h2:first-child { margin-top: 0; }
.legal-content h3 { font-size: 1rem; margin: 22px 0 8px; color: var(--navy); }
.legal-content p { color: var(--ink); margin: 0 0 14px; line-height: 1.65; }
.legal-content ul { margin: 0 0 14px; padding-left: 22px; color: var(--ink); line-height: 1.65; }
.legal-content li { margin-bottom: 6px; }
.legal-content a { color: var(--mint-dark); }
.legal-content strong { color: var(--navy); }
.legal-callout { background: var(--good-bg); border-radius: var(--radius-md); padding: 18px 22px; margin: 0 0 24px; color: var(--navy); font-size: 0.92rem; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .field-slider { display: none; }
  .unit-toggle-mini { width: 32px; height: 32px; font-size: 0.85rem; margin-left: 4px; }
  .info-btn { width: 30px; height: 30px; font-size: 0.85rem; }
  .remove-row-btn { width: 34px; height: 34px; }
  .popover-close, .modal-close { padding: 8px; }
  .calc-grid, .budget-layout { grid-template-columns: 1fr; }
  .ledger-tape, .sticky-summary-slot { position: static; max-width: 100%; }
  .card { padding: 22px 18px; }
  .income-readout { grid-template-columns: 1fr; gap: 12px; }
  .expense-row { grid-template-columns: 1fr 100px; }
  .expense-grid { grid-template-columns: 1fr; gap: 14px; }
  .afford-grid { grid-template-columns: 1fr; }
  .afford-box-head { padding: 20px; }
  .afford-box-head h3 { font-size: 1.4rem; }
  .afford-box-body { padding: 18px 18px 22px; }
  .afford-stat-value { font-size: 1.9rem; }
  .custom-expense-row { grid-template-columns: 1fr 100px 28px !important; }
  .custom-label-input { max-width: 100%; }

  .logo-badge { font-size: 1.8rem; }
  .logo-text { font-size: 1.6rem; }
  .header-inner { padding: 10px 0; }
  .btn-check { padding: 8px 14px; font-size: 0.82rem; }
  .btn-save { padding: 8px 14px; font-size: 0.82rem; }
  .header-actions { gap: 6px; }

  .mode-switcher { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .mode-btn { padding: 9px 16px; font-size: 0.88rem; white-space: nowrap; }

  .expenses-card-head { flex-wrap: wrap; gap: 8px; }
  .group-head { flex-wrap: wrap; gap: 6px; }
  .total-payment-value { font-size: 2rem; }
  .hero h1 { font-size: 1.7rem; }
}

@media (max-width: 480px) {
  .wrap { padding: 0 16px; }
  .header-inner { flex-wrap: wrap; row-gap: 8px; }
  .header-actions { width: 100%; justify-content: flex-end; }
  .expense-row { grid-template-columns: 1fr 90px; gap: 8px; }
  .field-row-inline { grid-template-columns: 1fr; }
  input[type="number"], select { font-size: 16px; } /* prevents iOS auto-zoom on focus */
}

