/* ============================================================
   Shared component styles (SPEC §2a primitives): fields, cards,
   buttons, figures, pills, chart frame, tooltip. Calculators reuse
   these; they never restyle from scratch.
   ============================================================ */

/* --- Cards --------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: clamp(1.25rem, 0.8rem + 1.6vw, 1.75rem);
  box-shadow: var(--shadow-sm);
}

.card__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.card__lead {
  color: var(--color-ink-2);
  font-size: var(--text-base);
}

/* --- Fields -------------------------------------------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-ink-2);
  letter-spacing: var(--tracking-snug);
}

.field__control {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: 0 var(--space-4);
  min-height: 52px;
  transition: border-color var(--dur) var(--ease-calm),
    box-shadow var(--dur) var(--ease-calm);
}

.field__control:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 4px var(--color-accent-ring);
}

.field__affix {
  color: var(--color-ink-3);
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.field__affix--prefix { margin-right: 0.1rem; }

.field__input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--text-xl);
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
  color: var(--color-ink);
  width: 100%;
  padding: var(--space-3) 0;
}
.field__input::placeholder { color: var(--color-ink-3); }

.field__hint {
  font-size: var(--text-xs);
  color: var(--color-ink-3);
  line-height: var(--leading-snug);
}

/* Segmented control (e.g. contribution frequency) */
.segmented {
  display: inline-flex;
  padding: 4px;
  gap: 2px;
  background: var(--color-surface-2);
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
}
.segmented__option {
  flex: 1;
  text-align: center;
  border-radius: var(--radius-pill);
  padding: 0.5rem 1rem;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-ink-2);
  transition: background var(--dur) var(--ease-calm), color var(--dur) var(--ease-calm);
  min-height: 40px;
  white-space: nowrap;
  line-height: 1.2;
}
.segmented__option[aria-pressed="true"] {
  background: var(--color-surface);
  color: var(--color-ink);
  box-shadow: var(--shadow-sm);
}

/* --- Buttons ------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  border-radius: var(--radius-pill);
  padding: 0.8rem 1.4rem;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  min-height: 48px;
  transition: transform var(--dur-fast) var(--ease-calm),
    background var(--dur) var(--ease-calm), color var(--dur) var(--ease-calm),
    border-color var(--dur) var(--ease-calm);
}
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--color-accent);
  color: var(--color-accent-ink);
}
.btn--primary:hover { background: var(--color-accent-strong); }

.btn--secondary {
  background: var(--color-surface-2);
  color: var(--color-ink-2);
  border: 1px solid var(--color-border);
}
.btn--secondary:hover { background: var(--color-border); color: var(--color-ink); }

.btn--ghost {
  color: var(--color-ink-2);
  border: 1px solid var(--color-border-strong);
}
.btn--ghost:hover { color: var(--color-ink); border-color: var(--color-ink-3); }

.btn--sm {
  padding: 0.4rem 0.75rem;
  font-size: var(--text-xs);
  min-height: 32px;
}

.btn--text {
  color: var(--color-accent);
  padding: 0.4rem 0;
  min-height: 0;
}
.btn--text:hover { color: var(--color-accent-strong); }

/* Compact per-field "Update profile" button used in calculators */
.promote-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-ink-3);
  padding: 0.2rem 0;
  line-height: 1;
  transition: color var(--dur) var(--ease-calm);
}
.promote-btn:hover { color: var(--color-accent); }
.promote-btn:disabled { opacity: 0.55; cursor: default; }
.promote-btn .icon { width: 0.9em; height: 0.9em; }

.field-with-promote {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.btn .icon { width: 1.1em; height: 1.1em; }

/* --- Figures / stats ----------------------------------------- */
.stat__label {
  font-size: var(--text-sm);
  color: var(--color-ink-2);
  font-weight: var(--weight-medium);
}
.stat__value {
  font-size: var(--text-3xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
  line-height: var(--leading-tight);
}
.stat__sub {
  font-size: var(--text-sm);
  color: var(--color-ink-3);
}

/* Explain-this-chart caption (SPEC-v4 §F3): one quiet plain-prose line under
   a chart stating what it shows. Doubles as accessible description. */
.chart-caption {
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--color-ink-2);
}
.chart-caption:empty { display: none; }

/* --- Pills / chips ------------------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  background: var(--color-accent-soft);
  color: var(--color-accent);
}
.pill .icon { width: 0.95em; height: 0.95em; }

/* --- Legend swatches ----------------------------------------- */
.legend { display: flex; flex-wrap: wrap; gap: var(--space-5); }
.legend__item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-ink-2);
}
.legend__swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex: none;
}
.legend__swatch--growth { background: var(--band-growth); }
.legend__swatch--contributed { background: var(--band-contributed); }

/* --- Calculator layout (shared shell for every calculator) --- */
.calc__header {
  max-width: 42rem;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.calc__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-accent);
}
.calc__title { font-size: var(--text-3xl); }
.calc__intro { color: var(--color-ink-2); font-size: var(--text-lg); }

/* Two-panel responsive grid: inputs + results/visual. */
.calc__panels {
  display: grid;
  gap: var(--space-6);
  grid-template-columns: 1fr;
  align-items: start;
}
/* Below the two-column breakpoint, answer-first: the result panel renders
   above the inputs (S9.4 — the headline figure shouldn't be buried below a
   full input stack on phone/tablet). */
@media (max-width: 899px) {
  .calc__panels .calc__result { order: -1; }
}
@media (min-width: 900px) {
  .calc__panels { grid-template-columns: minmax(300px, 0.85fr) 1.15fr; }
  .calc__panels--result-sticky .calc__result {
    position: sticky;
    top: calc(64px + var(--space-5));
  }
  /* Text-only result cards (no chart) sit in the wide 1.15fr track. With
     align-items:start (above) a short card leaves a tall blank void below
     it, matching the height of the (taller) inputs column — stretch the
     card to that row height and center its content within it, so the card
     itself fills the space instead of floating over a raw gap. Also cap
     the readable measure so the centered content doesn't stretch full
     width. Chart-bearing results (coast/growth/drawdown/rent-vs-buy/
     years-to-fi) are deliberately excluded — their charts already fill
     the column height and width on their own. */
  .calc__panels .barista-result,
  .calc__panels .cb-result,
  .calc__panels .dp-result,
  .calc__panels .ef-result,
  .calc__panels .fire-result,
  .calc__panels .la-result,
  .calc__panels .sg-result {
    max-width: 34rem;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
}
.calc__inputs { display: flex; flex-direction: column; gap: var(--space-5); }
.field-stack { display: flex; flex-direction: column; gap: var(--space-4); }

/* --- Chart frame + tooltip ----------------------------------- */
.chart {
  position: relative;
  width: 100%;
}
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }

.chart-area { stroke: none; }
/* Full opacity so the line (same colour) doesn't read as a brighter ledge
   sitting on top of a dimmer fill. */
.chart-area--growth { fill: var(--band-growth); fill-opacity: 1; }
.chart-area--contributed { fill: var(--band-contributed); fill-opacity: 0.85; }
.chart-line {
  stroke: var(--band-growth);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chart-grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart-ylabel,
.chart-xlabel {
  fill: var(--chart-axis);
  font-size: 11px;
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
}
.chart-xlabel--now {
  font-style: italic;
  font-variant-numeric: normal;
  opacity: 0.65;
}
.chart-hover { transition: opacity var(--dur-fast) var(--ease-calm); }
.chart-hover__line { stroke: var(--color-ink-3); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-hover__dot {
  fill: var(--color-surface);
  stroke: var(--band-growth);
  stroke-width: 2.5;
}

.chart__tooltip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  background: var(--color-ink);
  color: var(--color-bg);
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  line-height: 1.45;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translate(-50%, 0);
  transition: opacity var(--dur) var(--ease-calm);
  white-space: nowrap;
  z-index: 2;
}
.chart__tooltip[data-visible="true"] { opacity: 1; }
.chart__tooltip-row { display: flex; justify-content: space-between; gap: var(--space-4); }
.chart__tooltip-row dt { color: color-mix(in srgb, var(--color-bg) 65%, transparent); }
.chart__tooltip-row dd { font-variant-numeric: tabular-nums; font-weight: var(--weight-medium); }
.chart__tooltip-year { font-weight: var(--weight-semibold); margin-bottom: 0.25rem; }

/* ============================================================
   Scenario-binding UI (SPEC-ProfileBinding v2 §S2)
   Plan / Exploring / Saved-scenarios — one group-level bar,
   no per-field chips.
   ============================================================ */

/* Ghost action buttons (Reset / Save scenario… / Save to profile…) */
.reconcile-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-ink-2);
  padding: 0.2rem var(--space-2);
  border-radius: var(--radius-sm);
  min-height: 28px;
  transition: color var(--dur-fast) var(--ease-calm),
    background var(--dur-fast) var(--ease-calm);
}
.reconcile-btn:hover { color: var(--color-ink); background: var(--color-surface-2); }
.reconcile-btn .icon { width: 13px; height: 13px; }

.reconcile-btn--push { color: var(--color-accent); }
.reconcile-btn--push:hover { background: var(--color-accent-soft); color: var(--color-accent); }

@media (max-width: 640px) {
  .reconcile-btn { min-height: 44px; }
}

/* --- Scenario bar: one line in Plan view, a bar in Exploring -------- */
.scenario-bar {
  margin-bottom: var(--space-4);
}
.scenario-bar__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.scenario-bar__status {
  font-size: var(--text-sm);
  color: var(--color-ink-3);
}
.scenario-bar--exploring .scenario-bar__status {
  color: var(--color-ink-2);
}
.scenario-bar__picker {
  font-size: var(--text-xs);
  color: var(--color-ink-2);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.25rem var(--space-2);
  max-width: 60%;
}

.scenario-bar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 150ms var(--ease-out), opacity 150ms var(--ease-out),
    margin-top 150ms var(--ease-out);
}
.scenario-bar__actions--visible {
  max-height: 48px;
  opacity: 1;
  margin-top: var(--space-2);
}

/* Stack full-width on mobile instead of squeezing three labels into one row
   (three flex:1 items wrapped "Save scenario…" onto two lines). */
@media (max-width: 640px) {
  .scenario-bar__actions--visible {
    flex-direction: column;
    align-items: stretch;
    max-height: 160px;
  }
  .scenario-bar__actions--visible .reconcile-btn {
    justify-content: center;
    min-height: 44px;
  }
}

/* --- Scenario dialogs (save-scenario naming, save-to-profile diff) --- */
.scenario-dialog {
  padding: 0;
  border: none;
  margin: auto;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg, 0 20px 60px rgba(0,0,0,0.3));
  width: min(420px, 92vw);
  background: var(--color-surface);
  color: var(--color-ink);
}
.scenario-dialog::backdrop {
  background: var(--color-backdrop);
  backdrop-filter: blur(2px);
}
.scenario-dialog__inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-5);
}
.scenario-dialog__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  margin: 0;
}
.scenario-dialog__hint {
  font-size: var(--text-sm);
  color: var(--color-ink-3);
  margin: 0;
}
.scenario-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.scenario-diff-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 40vh;
  overflow-y: auto;
}
.scenario-diff-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  cursor: pointer;
}
.scenario-diff-row__label {
  flex: 1;
  color: var(--color-ink);
}
.scenario-diff-row__values {
  color: var(--color-ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
