/* ═══════════════════════════════════════════════════════════════════════════
   Calculator Suite : /calculators.html hub + /calculators/*.html
   Mobile-first; consumes the css/styles.css token layer.
   Charts are pure DOM/CSS bars : no libraries, no canvas.

   THE WORKSHEET IS LIGHT IN BOTH THEMES, ON PURPOSE.
   A calculator is a worksheet people read, print and email to themselves, and
   its charts (css/calc-viz.css) carry a categorical series palette that was
   picked and contrast-validated against white. Re-validating that palette for
   a dark card would be a second set of numbers to keep true, so the frame
   commits to paper instead of half converting.

   The commitment is made in ONE place: .calc-frame and .calc-viz re-declare
   the core tokens with their light values, so every rule inside them (theirs
   and the site's) resolves to paper without a single dark-mode override. That
   includes --focus: the dark ring is #8fd0ff, which measures 1.6:1 on white,
   so pinning it back to the light ring is what keeps keyboard focus visible
   inside the worksheet.

   Everything OUTSIDE the frame (page, hub cards, disclaimer, hero) follows
   the theme normally, and the frame's own hairline plus its shadow are what
   make it read as a deliberate inset sheet on a dark page.
   ═══════════════════════════════════════════════════════════════════════════ */

.calc-frame,
.calc-viz {
  --surface: #ffffff;
  --surface-2: #f4f7fb;
  --surface-3: #e4ebf4;
  --ink: #1f2933;
  --muted: #5b6675;
  --border: #d9e1ec;
  --control-border: #7d8797;
  --link: #1565c0;
  --link-hover: #0d47a1;
  --primary: #1565c0;
  --primary-dark: #0d47a1;
  --primary-soft: rgba(21, 101, 192, 0.08);
  --success: #2e7d32;
  --success-soft: #eaf6ec;
  --error: #b91c1c;
  --error-soft: #fdecec;
  --warning: #92400e;
  --warning-soft: #fffbeb;
  --accent-violet: #7c3aed;
  --accent-cyan: #0e7490;
  --focus: #0d47a1;
  --on-gold: #7a5400;
  --dark: #1f2933;
  --light: #f4f7fb;
  /* Ring drawn where the sheet meets the page; white in light, still white in
     dark, because it is part of the sheet rather than part of the page. */
  --paper-edge: #ffffff;
  color: var(--ink);
}

/* ── Chart series palette: ONE source for every calculator visual ──
   js/calc-viz.js (the live SVG), the legacy CSS bars that remain as the no-JS
   and viz-failure fallback, and the hub-card previews all paint from these
   slots, so a category is the same colour wherever it appears. Two charts of
   the same numbers once disagreed (legacy Income green vs chart Income
   orange); sharing the tokens is what keeps that from coming back.
   Validated on #ffffff (and on --viz-paper for the hub previews): s1 4.65:1,
   s2 3.20:1, s3 2.82:1, s4 2.17:1, cov 4.76:1, gap 6.47:1. White text on s1
   measures 4.65:1 and on gap 6.47:1; see css/calc-viz.css for label inks. */
.calc-frame,
.calc-viz,
.calc-hub-grid {
  --viz-s1: #2874d2; /* blue   : slot 1 */
  --viz-s2: #eb6834; /* orange : slot 2 */
  --viz-s3: #1baf7a; /* aqua   : slot 3 */
  --viz-s4: #eda100; /* yellow : slot 4 */
  --viz-cov: #64748b; /* neutral: existing coverage / not selected */
  --viz-gap: #b91c1c; /* status: estimated shortfall (site error red) */
  --viz-paper: #f4f7fb; /* preview panel ground, light in both themes */
  --viz-axis: #c3cedd;
}

/* ── Shared card frame ── */
.calc-frame {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg, 12px);
  padding: 20px;
  margin: 24px 0;
  /* A worksheet on a dark page needs a real edge, not a 6% drop shadow. The
     tints are NOT re-declared above, so they stay on the page's theme: the
     shadow belongs to the page the sheet is lying on, not to the sheet. */
  box-shadow:
    0 0 0 1px var(--shadow-tint-1),
    0 2px 12px var(--shadow-tint-2);
}

.calc-inputs {
  display: grid;
  gap: 16px;
  margin-bottom: 20px;
}
@media (min-width: 720px) {
  .calc-inputs.calc-inputs-2col {
    grid-template-columns: 1fr 1fr;
  }
}

.calc-inputs label {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
}
.calc-inputs input[type='number'],
.calc-inputs select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--surface);
  color: var(--dark);
}
.calc-inputs input[type='range'] {
  display: block;
  width: 100%;
  margin-top: 10px;
  accent-color: var(--primary, #1565c0);
}
.calc-hint {
  display: block;
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

.calc-fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 16px;
}
.calc-fieldset legend {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 8px;
}
.calc-radio-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}
.calc-radio-row label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  cursor: pointer;
}

/* ── Figure citation chips ── */
.fig-chip {
  display: inline-flex;
  gap: 4px;
  align-items: baseline;
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--light);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  margin-left: 6px;
  white-space: nowrap;
  vertical-align: middle;
}
.fig-chip a {
  color: var(--link);
  text-decoration: underline;
}

.calc-figures-error {
  background: var(--error-soft);
  border: 1px solid var(--error);
  border-radius: 8px;
  color: var(--error);
  padding: 12px 16px;
  margin: 16px 0;
  font-size: 0.95rem;
}

/* ── Results panel ── */
.calc-results {
  background: var(--light);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin-top: 12px;
}
.calc-results .calc-kpi {
  font-weight: 800;
  color: var(--link-hover);
  font-variant-numeric: tabular-nums;
}

/* ── KPI count-up layers (js/calculators.js setKpiText) ──
   While a figure counts up, the element's real text (.calc-kpi-val) stays
   in the accessibility tree and in textContent but is clipped off screen,
   and an aria-hidden sibling paints the intermediate figures from a data
   attribute. The digits therefore never touch the aria-live region's text.
   The clip pattern is the standard visually-hidden recipe, scoped here. */
.calc-kpi-counting {
  position: relative;
}
.calc-kpi-val-clipped {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.calc-kpi-anim::after {
  content: attr(data-kpi-anim);
}
.calc-result-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}
.calc-result-row:last-of-type {
  border-bottom: 0;
}
.calc-verdict {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 600;
}
.calc-verdict-ok {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
}
.calc-verdict-warn {
  border-color: var(--error);
  background: var(--error-soft);
  color: var(--error);
}

/* ── Generic horizontal bar chart ── */
.calc-bar-chart {
  display: grid;
  gap: 12px;
  margin: 16px 0;
}
.calc-bar-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}
@media (min-width: 600px) {
  .calc-bar-row {
    grid-template-columns: 200px 1fr auto;
    align-items: center;
    gap: 12px;
  }
}
.calc-bar-label {
  font-size: 0.9rem;
  font-weight: 600;
}
.calc-bar-track {
  background: var(--light);
  border: 1px solid var(--border);
  border-radius: 999px;
  height: 22px;
  overflow: hidden;
}
.calc-bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--primary);
  transition: width 0.6s ease;
}
.calc-bar-fill.calc-bar-alt {
  background: var(--secondary);
}
.calc-bar-value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
}
/* Series fills for bars that share categories with the live chart: each
   carries the same slot colour as its calc-viz line or segment. */
.calc-bar-fill.viz-bar-s1 { background: var(--viz-s1); }
.calc-bar-fill.viz-bar-s2 { background: var(--viz-s2); }
.calc-bar-fill.viz-bar-s3 { background: var(--viz-s3); }
/* LTC: the selected state is the chart's slot-1 line, the VA nursing
   benchmark is its slot-2 line, the other states are neutral context. */
.calc-bar-fill.ltc-bar-state { background: var(--viz-cov); }
.ltc-row-active .calc-bar-label {
  color: var(--link-hover);
}
.ltc-row-active .calc-bar-fill.ltc-bar-state {
  background: var(--viz-s1);
}

/* ── IRMAA income track ── */
.irmaa-track-wrap {
  margin: 28px 0 8px;
}
.irmaa-track {
  position: relative;
  height: 26px;
  border-radius: 999px;
  background: var(--light);
  border: 1px solid var(--border);
}
.irmaa-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--success), var(--secondary) 85%);
  transition: width 0.6s ease;
}
.irmaa-dot {
  position: absolute;
  top: 50%;
  left: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary-dark);
  border: 3px solid var(--paper-edge);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -50%);
  transition: left 0.4s ease;
  z-index: 2;
}
.irmaa-cliff {
  position: absolute;
  top: -8px;
  bottom: -8px;
  width: 3px;
  background: var(--error);
  transform: translateX(-50%);
  z-index: 1;
}
.irmaa-cliff::after {
  content: '⚠';
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85rem;
}
.irmaa-cliff-label {
  margin-top: 14px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--error);
}

/* ── DIME stacked bar ── */
.dime-stack {
  display: flex;
  height: 34px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--light);
  margin: 16px 0 8px;
}
.dime-seg {
  height: 100%;
  width: 0;
  transition: width 0.6s ease;
}
.dime-seg-d { background: var(--viz-s1); }
.dime-seg-i { background: var(--viz-s2); }
.dime-seg-m { background: var(--viz-s3); }
.dime-seg-e { background: var(--viz-s4); }

.dime-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}
.dime-legend .swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: -1px;
}

/* ── Legacy visuals yield to the live chart ──
   js/calc-viz.js sets [hidden] on these once its SVG mounts. The attribute
   alone did NOT hide .dime-stack or .dime-legend: the user-agent rule
   [hidden] { display: none } loses to any author display declaration, and
   both carry display: flex above, so the page showed two charts of the same
   numbers. This rule outranks those (two selectors' worth of specificity)
   so [hidden] means hidden again. With JS off, or if calc-viz.js fails, the
   attribute is never set and the fallback stays. */
.dime-stack[hidden],
.dime-legend[hidden],
.irmaa-track-wrap[hidden] {
  display: none;
}

/* One line under every chart, visible with or without JS. */
.calc-chart-note {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 6px 0 12px;
}

/* ── Email-my-results form ── */
.calc-email-form {
  margin-top: 20px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.calc-email-form h3 {
  margin-bottom: 8px;
}
.calc-email-fields {
  display: grid;
  gap: 12px;
  margin: 12px 0;
}
@media (min-width: 600px) {
  .calc-email-fields {
    grid-template-columns: 1fr 1.4fr auto;
    align-items: end;
  }
}
.calc-email-form input[type='text'],
.calc-email-form input[type='email'] {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}
.calc-consent {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 10px 0;
}
.calc-consent input {
  margin-top: 3px;
  flex: none;
}
.calc-email-status {
  min-height: 1.4em;
  margin-top: 8px;
  font-weight: 600;
  font-size: 0.9rem;
}
.calc-email-ok { color: var(--success); }
.calc-email-err { color: var(--error); }

/* The four calculator pages carry an inline <style> that paints
   .calc-email-capture white. The form sits outside .calc-frame, so its text
   follows the page ink: near-white on that white card in dark mode (1.16:1).
   The element-qualified selector outranks the inline block and hands the
   card back to the surface token (white in light, unchanged). */
form.calc-email-capture {
  background: var(--surface);
}

/* ── Disclaimer block ── */
.calc-disclaimer {
  font-size: 0.85rem;
  color: var(--muted);
  border-left: 3px solid var(--secondary);
  padding: 10px 14px;
  background: var(--light);
  border-radius: 0 8px 8px 0;
  margin: 24px 0;
  /* The home page's mini-calculator styles a same-named .calc-disclaimer
     centred with a dashed top rule (css/styles.css); on these pages that
     leaked in as a centred paragraph beside a left rule. */
  text-align: left;
  border-top: 0;
}

/* The page-level educational note lives INSIDE the page container, directly
   under the tool disclaimer, instead of as a full-bleed grey strip between
   the CTA band and the footer. Same words, same role="note". */
.section .edu-disclaimer {
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--surface-2);
  border-left: 3px solid var(--border);
  border-radius: 0 8px 8px 0;
  padding: 10px 14px;
  margin: -12px 0 24px;
}

/* One CTA band per page. ui.js appends a generic .content-cta-strip at the
   end of <main>; these pages already carry an authored .page-cta, so the
   generic band is dropped. The sitewide rule in css/styles.css uses :has();
   this sibling form covers the same case where :has() is unsupported. */
.page-cta ~ .content-cta-strip {
  display: none;
}

/* ── Hub cards ── */
.calc-hub-grid {
  display: grid;
  gap: 20px;
  margin: 24px 0;
}
@media (min-width: 720px) {
  .calc-hub-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
.calc-hub-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  color: var(--dark);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.calc-hub-card:hover,
.calc-hub-card:focus-visible {
  box-shadow: 0 6px 24px rgba(21, 101, 192, 0.14);
  transform: translateY(-2px);
}
/* Decorative preview (js/calculators.js initHubPreviews): an illustrative
   shape of what the tool draws, not real figures. aria-hidden; the card's
   heading and paragraph stay the accessible content. With JS off the card is
   simply its text, with no empty box. The panel is paper in both themes,
   like the worksheet, because the series colours were validated on it. */
.calc-hub-card {
  display: flex;
  flex-direction: column;
}
.calc-hub-preview {
  display: block;
  background: var(--viz-paper);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
}
.calc-hub-preview svg {
  display: block;
  width: 100%;
  height: auto;
}
.calc-hub-preview .pv-axis { stroke: var(--viz-axis); stroke-width: 1; }
.calc-hub-preview .pv-guide {
  stroke: var(--viz-gap);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0.55;
}
.calc-hub-preview .pv-marker { stroke: var(--viz-cov); stroke-width: 1; }
.calc-hub-preview .pv-f-s1 { fill: var(--viz-s1); }
.calc-hub-preview .pv-f-s2 { fill: var(--viz-s2); }
.calc-hub-preview .pv-f-s3 { fill: var(--viz-s3); }
.calc-hub-preview .pv-f-s4 { fill: var(--viz-s4); }
.calc-hub-preview .pv-f-cov { fill: var(--viz-cov); }
.calc-hub-preview .pv-f-gap { fill: var(--viz-gap); }
.calc-hub-preview .pv-wash-ok { fill: var(--viz-s3); opacity: 0.12; }
.calc-hub-preview .pv-wash-over { fill: var(--viz-gap); opacity: 0.08; }
.calc-hub-preview .pv-area { fill: var(--viz-s1); opacity: 0.12; }
.calc-hub-preview .pv-line {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.calc-hub-preview .pv-l-s1 { stroke: var(--viz-s1); }
.calc-hub-preview .pv-l-s2 { stroke: var(--viz-s2); }
.calc-hub-preview .pv-l-s3 { stroke: var(--viz-s3); }
.calc-hub-preview .pv-l-gap { stroke: var(--viz-gap); stroke-width: 3; }
.calc-hub-preview .pv-dot { stroke: var(--viz-paper); stroke-width: 2; }
.calc-hub-card h3 {
  color: var(--link-hover);
  margin-bottom: 6px;
}
.calc-hub-card p {
  font-size: 0.95rem;
  color: var(--muted);
}

/* ── Reduced motion: everything static ── */
@media (prefers-reduced-motion: reduce) {
  .calc-bar-fill,
  .irmaa-fill,
  .irmaa-dot,
  .dime-seg,
  .calc-hub-card {
    transition: none !important;
  }
  .calc-hub-card:hover {
    transform: none;
  }
}
