/* Retirement Calculator — sandbox layout. Sliders left, projection right.
 *
 * Topbar / icon-button / .hidden / body-background styling is owned by
 * the shared stylesheets (supercala-app-tokens.css + supercala-topbar.css)
 * — this file used to duplicate .topbar, .btn.icon-only, .brand etc.
 * with slightly different padding / borders / no background, which left
 * the icons looking lighter than every other studio app and the topbar
 * without its translucent backdrop blur. Removed those rules; the
 * shared CSS now drives the entire topbar look. */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Background + foreground colours come from supercala-app-tokens.css
     (html,body { background: var(--bg-fade), var(--bg) }). Don't set a
     solid background here — that would paint over the azure-tinted
     gradient the rest of the studio uses. */
  color: var(--fg);
  min-height: 100vh;
}

/* Brand text — sits inside .topbar (whose layout is shared) but the
   per-product wordmark / subtitle styling is product-local. Matches
   the shared topbar's existing rules in the other studio apps. */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--fg);
  font-weight: 700;
  font-size: 15px;
}
.brand-mark { width: 28px; height: 28px; display: block; border-radius: 6px; }
.brand-stack { display: inline-flex; flex-direction: column; line-height: 1.05; }
.brand-text { font-weight: 600; font-size: 16px; }
.brand-studio {
  font-weight: 400; font-size: 9.5px; letter-spacing: 0.4px;
  color: var(--fg-faint); text-transform: uppercase; margin-top: 1px;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 24px;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  /* Fill the viewport below the topbar so the year-by-year table on the
     right has room to grow into. The 56px subtraction is the shared
     topbar (8px top pad + 28px brand mark + 8px bottom pad + 1px border
     ≈ 53–56px) — small over-estimate is fine, undershoot would force
     the page to scroll. The 48 covers the .main-grid's own top+bottom
     padding (24+24). */
  min-height: calc(100vh - 56px - 48px);
}

/* Phone breakpoint — narrower than the 900px stack point. Tightens
   the chrome that surrounds the summary cards so the three Bear /
   Base / Bull tiles have room to sit side-by-side without spilling
   past the viewport edge. The grid columns themselves are already
   minmax(0, 1fr) so they CAN shrink; this just gives them more total
   space to divide. */
@media (max-width: 600px) {
  .main-grid { padding: 14px; gap: 14px; }
  .inputs, .output { padding: 12px; }
  .summary-cards { gap: 8px; margin-bottom: 14px; }
  .summary-card { padding: 10px; }
  .card-value { font-size: 17px; }
  .card-label { font-size: 10px; }
  .card-sub { font-size: 11px; }
}

@media (max-width: 900px) {
  .main-grid { grid-template-columns: 1fr; }
  /* In the stacked mobile layout .inputs and .output sit in separate
     rows of a single-column grid — the "cap output to inputs height"
     constraint doesn't apply because they're not in the same row.
     Drop the overflow:hidden + flex-grow chain so the page can scroll
     normally and the drilldown sizes to its own content. */
  .output {
    overflow: visible;
    /* JS clears the inline max-height it sets on desktop — see
       calculator.js → syncOutputHeight — but pin overflow here as
       a belt-and-braces in case the resize observer fires while the
       viewport is mid-transition. */
  }
  .drilldown[open] { flex: initial; }
  .drilldown[open] .table-wrap { max-height: 360px; }
}

.inputs, .output {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
/* Flex column so the open drilldown can flex-grow into the remaining
   vertical space. min-height:0 lets a flex child overflow / scroll
   internally instead of forcing the parent to grow indefinitely.
   overflow:hidden clips any content that exceeds the JS-pinned height
   (see calculator.js → syncOutputHeight). We tried contain:size first
   and it failed in practice: per the spec, a contain:size element
   with no explicit height lays out internally as if its height were
   ZERO, so the table-wrap's flex:1 had nothing to flex against and
   the table just rendered at full intrinsic height past the panel's
   bottom. JS-pinned max-height is more verbose but actually works. */
.output {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.inputs h2 { margin: 0 0 14px; font-size: 16px; }
.inputs h3 {
  margin: 22px 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
}

/* "Populate from MyNetWorth" button — sits directly under the
   "Current balances" header and prefills the four balance fields
   from a signed-in user's MyNetWorth holdings. Full-width inside the
   inputs panel; styled as a soft-accent CTA so it reads as a power-
   feature without competing with the slider rows. The icon is a
   plain emoji (matches the rest of the studio's section icons)
   rather than an SVG to keep the markup small. */
.btn-import-mnw {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 14px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 8px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, transform 60ms ease;
}
.btn-import-mnw:hover:not(:disabled) {
  background: var(--accent);
  color: var(--accent-fg);
}
.btn-import-mnw:active:not(:disabled) {
  transform: translateY(1px);
}
.btn-import-mnw:disabled {
  opacity: 0.6;
  cursor: progress;
}
.btn-import-mnw-icon { font-size: 15px; line-height: 1; }

/* Connected state — status pill rather than CTA. Soft-green fill so
   the user reads it as 'something good is happening' rather than 'I
   need to click this'. Still clickable for a manual refresh; hover
   reinforces that. We use literal greens (not a token) because none
   of the existing tokens carry a soft-green variant; if we end up
   wanting one in another tool we can promote --success-soft into
   supercala-app-tokens.css. */
.btn-import-mnw.connected {
  background: rgba(63, 185, 80, 0.12);
  border-color: rgba(63, 185, 80, 0.55);
  color: #2d8a3c;
  font-weight: 500;
}
.btn-import-mnw.connected:hover:not(:disabled) {
  background: rgba(63, 185, 80, 0.22);
  color: #2d8a3c;
}

.input-row {
  margin-bottom: 14px;
}
/* Current-age row when a birthday is on file: the slider + number input
   are disabled (age is derived) and this hint explains why. Muted +
   small so it reads as helper text, not an error. */
.age-auto-hint {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--fg-faint);
}
.input-row.auto-tracked input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.input-row.auto-tracked input[type=range]:disabled { cursor: not-allowed; }
.input-row label {
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
  color: var(--fg-dim);
}
.input-row .ctrl {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 8px;
}
/* Native range inputs — explicit track + thumb styling rather than
   relying solely on `accent-color` + `color-scheme`. Some Chromium
   builds keep their dark default groove even after the page declares
   `color-scheme: light` (shipped on RetirementCalculator after the
   light pin; the filled portion + thumb were accent-blue but the
   UNFILLED track stayed dark gray). Painting the track + thumb
   ourselves with the studio's token colors makes it cascade with
   light/dark mode automatically: --bg-elev-3 resolves to #dde3ea in
   light, #2a313c in dark, and the thumb's border picks up --bg so
   it reads as a coloured pill on whichever background. */
.input-row input[type=range] {
  width: 100%;
  height: 18px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  accent-color: var(--accent);
  /* Belt-and-braces: even though body[data-theme=light] already sets
     color-scheme:light at the document level, declaring it on the
     control itself overrides any inherited dark scheme on Safari/
     older Edge that don't propagate it cleanly to native widgets. */
  color-scheme: light;
}
.input-row input[type=range]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--slider-track);
  border-radius: 999px;
  border: none;
}
.input-row input[type=range]::-moz-range-track {
  height: 4px;
  background: var(--slider-track);
  border-radius: 999px;
  border: none;
}
.input-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-elev);
  /* Centers the 14px thumb on the 4px track; (4 - 14) / 2 = -5. */
  margin-top: -5px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  cursor: pointer;
}
.input-row input[type=range]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-elev);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  cursor: pointer;
}
.input-row input[type=range]:focus { outline: none; }
.input-row input[type=range]:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input-row input[type=range]:focus::-moz-range-thumb {
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input-row .num {
  width: 96px;
  padding: 4px 6px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  text-align: right;
}
.input-row .num:focus {
  outline: none;
  border-color: var(--accent);
}
.input-row .num::-webkit-inner-spin-button,
.input-row .num::-webkit-outer-spin-button {
  opacity: 0.5;
}
.input-row .unit {
  font-size: 12px;
  color: var(--fg-dim);
  min-width: 16px;
}

.summary-cards {
  display: grid;
  /* minmax(0, 1fr) rather than plain 1fr: a grid item's default min-
     size is auto, which resolves to min-content — and the card's
     min-content is the $X.XXM number at 22px (~85-100px). On a phone
     with main-grid + panel + card paddings stacked, the three cards
     can want more horizontal space than the panel actually has, and
     plain 1fr won't let them shrink past min-content. Result: the
     grid overflows to the right and the Bull card clips off-screen.
     minmax(0,1fr) explicitly allows shrinking below the min-content
     hint, letting the columns equally divide whatever space is
     available. The card content then absorbs the squeeze (the font-
     variant-numeric:tabular-nums on .card-value keeps the digits
     looking right even at a tighter column). */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  background: var(--bg-elev-2);
  /* min-width:0 lets the grid column shrink past the card's intrinsic
     min-content (the dollar value). Pairs with the minmax(0, 1fr) on
     .summary-cards above — both are needed to let a narrow phone
     viewport actually divide the row equally. overflow:hidden is the
     belt-and-braces: even if an out-of-range bull-case value (e.g.
     decades of compound growth in the bull scenario) outgrows the
     adaptive fmtMoney truncation, it clips at the card border instead
     of visibly spilling past — the 'M slightly out of the box' bug. */
  min-width: 0;
  overflow: hidden;
}
.summary-card.bear { border-left: 3px solid var(--red); }
.summary-card.base { border-left: 3px solid var(--accent); }
.summary-card.bull { border-left: 3px solid var(--green); }

/* The cards are <button> toggles now (show/hide that scenario). Reset the
   UA button styling so they render exactly as the divs did, add the
   affordances, and dim the toggled-off state. */
button.summary-card {
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  display: block;
  width: 100%;
  transition: opacity 0.15s, border-color 0.15s, transform 0.05s;
}
button.summary-card:hover { border-color: var(--fg-dim); }
button.summary-card:active { transform: scale(0.99); }
.summary-card .card-label,
.summary-card .card-value,
.summary-card .card-sub { display: block; }
.summary-card.off { opacity: 0.4; filter: saturate(0.35); }

.card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
}
.card-value {
  font-size: 22px;
  font-weight: 600;
  margin: 4px 0 2px;
  font-variant-numeric: tabular-nums;
}
.card-sub {
  font-size: 12px;
  color: var(--fg-dim);
}

.chart-wrap {
  position: relative;
  width: 100%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 18px;
}
.chart-wrap canvas {
  width: 100%;
  height: auto;
  display: block;
}

.drilldown summary {
  cursor: pointer;
  padding: 8px 0;
  color: var(--fg-dim);
  font-size: 13px;
}
/* Only flex-grow the drilldown when it's actually open — otherwise a
   closed <details> would still claim the rest of the panel and leave
   an empty gap below the chart. When open, the drilldown takes the
   remaining vertical space and its child .table-wrap scrolls inside. */
.drilldown[open] {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.table-wrap {
  /* When the drilldown is closed (or below the panel ever runs short),
     fall back to the 360px cap. When open and flex-laid-out, max-height
     gets overridden by the [open] rule below so the table fills. */
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.drilldown[open] .table-wrap {
  flex: 1;
  min-height: 0;
  /* max-height is set in JS (syncOutputHeight) to the available pixel
     height inside the JS-pinned .output box. We deliberately do NOT
     reset to max-height:none here — that would leave the table-wrap
     uncapped and overflow:auto wouldn't scroll until JS fires, briefly
     showing the table extending past the panel bottom with no
     scrollbar (the user-reported bug). The base 360px fallback keeps
     the panel scrollable from the first paint; JS expands it to fill
     the column on the next layout tick. */
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
th, td {
  padding: 6px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
th:first-child, td:first-child { text-align: left; }
th {
  position: sticky;
  top: 0;
  background: var(--bg-elev-3);
  color: var(--fg-dim);
  font-weight: 500;
}

/* --- Settings popover -------------------------------------------------
 *
 * The popover shell + rows come from the shared supercala-topbar.css
 * (.popover, .popover-row, .popover-email). The shared .popover-row is
 * a clickable button row (pointer cursor + hover fill); our rows hold
 * form controls instead, so .settings-row neutralises the click
 * affordance and lets the <select>/<input> own the interaction. */
.popover-row.settings-row {
  cursor: default;
  gap: 12px;
}
.popover-row.settings-row:hover { background: transparent; }

/* Theme select + birthday picker — themed to match the panel inputs so
   they read as part of the studio surface in both light and dark. */
.settings-select,
.settings-date {
  background: var(--bg-elev-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  padding: 4px 6px;
  color-scheme: light dark;  /* native dropdown/calendar follows --theme */
}
.settings-select:focus,
.settings-date:focus {
  outline: none;
  border-color: var(--accent);
}

/* Helper line under the birthday row. */
.popover-hint {
  padding: 4px 12px 8px;
  font-size: 11px;
  color: var(--fg-faint);
  max-width: 220px;
}

/* ---- MyNetWorth Pro upsell modal ----------------------------------------
   Centered overlay on the shared design tokens (no native dialogs). RetCalc
   has no generic .modal of its own, so these are scoped .rc-modal classes. */
.rc-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 6500;
  padding: 16px;
}
.rc-modal.hidden { display: none; }
.rc-modal-card {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.rc-modal-card h2 { margin: 0 0 8px; font-size: 18px; color: var(--fg); }
.rc-modal-card p { margin: 0 0 16px; color: var(--fg-dim); font-size: 14px; line-height: 1.5; }
.rc-modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--fg-dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.rc-modal-close:hover { background: var(--bg-elev-2); color: var(--fg); }
.rc-up-row { margin-bottom: 8px; }
.rc-up-btn {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--fg);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.rc-up-btn:hover { border-color: var(--accent); }
.rc-up-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
.rc-up-btn.primary:hover { filter: brightness(1.12); }
.rc-up-btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--fg-dim);
  font-weight: 500;
  margin-top: 4px;
}
.rc-up-btn.ghost:hover { color: var(--fg); border-color: transparent; }

/* ---- Decumulation strategy (Buy · Borrow · Die mode) ---- */
.strategy-seg {
  display: flex; background: var(--bg-elev, var(--bg)); border: 1px solid var(--border);
  border-radius: 10px; padding: 3px; gap: 2px; margin: 0 0 10px;
}
.strategy-btn {
  flex: 1; background: transparent; border: none; border-radius: 8px;
  color: var(--fg-dim); cursor: pointer; font: inherit; font-size: 0.85rem;
  font-weight: 600; padding: 0.4rem 0.5rem; white-space: nowrap;
}
.strategy-btn:hover { color: var(--fg); }
.strategy-btn.active { background: var(--accent, #00a2e8); color: #fff; }
.strategy-hint {
  font-size: 0.78rem; color: var(--fg-dim); line-height: 1.45; margin: 0 0 10px;
}

/* ---- Retirement Coach voice widget ---- */
/* The widget injects .vc-pill into <body>. Hidden until the app says the user
   is signed in; locked (greyed) until they're on Pro — clicks in that state
   are routed to the upgrade modal by a capture-phase gate. */
.vc-pill { display: none !important; }
.vc-toast { display: none !important; }
body.rc-voice-visible .vc-pill { display: flex !important; }
body.rc-voice-visible .vc-toast { display: block !important; }
body.rc-voice-locked #supercala-voice-btn { filter: grayscale(0.6) brightness(0.9); }
