/* ===========================================================================
   app.css — component styles for the FE Probability Solver web demo
   Consumes styles/tokens.css ONLY (never hard-code colors/sizes here).

   NOTE TO OTHER MODULE AUTHORS: this file is shared across js/* modules per the
   interface lock. Sections are fenced by an owning module so edits don't collide.
   Append new sections; do not reorder. Imported once from index.html after
   tokens.css.
   =========================================================================== */

/* ===========================================================================
   [shared] — a11y + reset primitives used across modules
   =========================================================================== */

/* Visually-hidden but screen-reader-available (chart data-table fallback notes,
   off-screen labels). Standard "sr-only" pattern. */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===========================================================================
   [results.js] — KPI rail (C-17) + result charts (C-18/C-19)
   =========================================================================== */

/* --- KPI rail (R3.b) ------------------------------------------------------ */
.kpi-rail {
  display: grid;
  gap: var(--gap-grid-tight);
  grid-template-columns: repeat(auto-fill, minmax(var(--kpi-min), 1fr));
  align-items: stretch;
}

.kpi-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-height: var(--kpi-min-h, 4.5rem);   /* reserve height → no layout shift */
  padding: var(--pad-card);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  transition: var(--transition-colors);
}

.kpi-card__caption {
  font-family: var(--font-sans);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
  line-height: var(--lh-snug);
}

.kpi-card__value {
  font-family: var(--font-mono);
  font-size: var(--fs-xl);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  color: var(--color-text-body);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

.kpi-card__context {
  font-family: var(--font-sans);
  font-size: var(--fs-2xs);
  line-height: var(--lh-snug);
  color: var(--color-text-subtle);
}

/* Tone accents — color is an enhancement; the caption/value text still carries
   the meaning, so this never relies on color alone (a11y color-independence).
   Left border + a muted background tint signal status. */
.kpi-card--ok {
  border-left-color: var(--color-success);
  background: var(--color-success-bg);
}
.kpi-card--ok .kpi-card__value { color: var(--color-success); }

.kpi-card--warn {
  border-left-color: var(--color-warning);
  background: var(--color-warning-bg);
}
.kpi-card--warn .kpi-card__value { color: var(--color-warning); }

.kpi-card--bad {
  border-left-color: var(--color-danger);
  background: var(--color-danger-bg);
}
.kpi-card--bad .kpi-card__value { color: var(--color-danger); }

/* --- Result charts (R3.c / R3.d) ------------------------------------------ */
.result-chart {
  position: relative;
  width: 100%;
  min-height: var(--chart-min-h);          /* reserve box up front */
  background: var(--color-surface);
  /* Frame as an inset shadow, not a border: a border-box border shrinks the
     content box 2px below the fixed-height Plotly host, and overflow:hidden then
     clips the bottom (x) axis title. The inset shadow draws the same 1px frame
     without shrinking the content box. */
  box-shadow: var(--shadow-xs), inset 0 0 0 1px var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.result-chart__plot {
  width: 100%;
  min-height: var(--chart-min-h);
}

/* Plotly-unavailable / no-data placeholder text. */
.result-chart__missing {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: var(--chart-min-h);
  margin: 0;
  padding: var(--pad-card-lg);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  text-align: center;
}

/* ===========================================================================
   [app.js] — FRONTEND SHELL: reset/base, shell grid, header, geometry bar,
   param column (run panel + accordion + fields + live-curve boxes), results
   status strip + progress, chart-card chrome, 3D hazard card, overlays
   (modal/toast/tooltip), and the 4 responsive breakpoints.
   Owns everything EXCEPT the [results.js] KPI-rail/.kpi-card/.result-chart
   selectors above — those are not redefined here. Tokens-only.
   =========================================================================== */

/* ---- 0. reset / base ---------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh;
  background: var(--color-bg); color: var(--color-text-body);
  font-family: var(--font-sans); font-size: var(--fs-base); line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; font-family: var(--font-heading); font-weight: var(--fw-semibold); line-height: var(--lh-tight); }
p { margin: 0; }
button { font-family: inherit; }

.skip-link {
  position: absolute; left: var(--space-2); top: var(--space-2); transform: translateY(-200%);
  background: var(--color-primary); color: var(--color-text-on-primary);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  z-index: var(--z-toast); transition: transform var(--dur-fast) var(--ease-out);
}
.skip-link:focus { transform: translateY(0); }

.spin { animation: spin 0.9s linear infinite; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- 1. app shell grid -------------------------------------------------- */
.app-shell {
  display: grid; grid-template-rows: var(--header-h) var(--geo-selector-h) 1fr;
  min-height: 100vh; max-width: var(--layout-max); margin-inline: auto;
}
.app-body { display: grid; grid-template-columns: 1fr; gap: var(--gap-grid); min-height: 0; padding: var(--gap-grid); }
@media (min-width: 1024px) {
  .app-body {
    grid-template-columns: var(--param-col-w) minmax(var(--results-min-w), 1fr);
    /* Natural page scrolling: the body grows with content (columns no longer scroll
       internally); align-items:stretch (default) keeps the param column as tall as the
       results so the sticky Run button stays pinned while scrolling. */
  }
}
@media (min-width: 1440px) {
  .app-body { grid-template-columns: var(--param-col-w-wide) minmax(var(--results-min-w), 1fr); }
}

/* ---- 2. header ---------------------------------------------------------- */
.app-header {
  position: sticky; top: 0; z-index: var(--z-raised); height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding-inline: var(--space-4); background: var(--color-surface); border-bottom: 1px solid var(--color-border);
}
.app-header__brand { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.app-header__mark { color: var(--color-primary); display: inline-flex; }
.app-header__titles { display: flex; flex-direction: column; min-width: 0; }
.app-header__title {
  font-family: var(--font-heading); font-weight: var(--fw-bold); font-size: var(--fs-md);
  color: var(--color-text); letter-spacing: var(--ls-tight); line-height: var(--lh-tight);
}
.app-header__tagline {
  font-size: var(--fs-2xs); color: var(--color-text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-header__actions { display: flex; align-items: center; gap: var(--space-1); }

.btn-ghost {
  display: inline-flex; align-items: center; gap: var(--space-1);
  height: var(--row-h-input); padding-inline: var(--space-2);
  font-size: var(--fs-sm); color: var(--color-text-muted);
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-md);
  cursor: pointer; text-decoration: none; transition: var(--transition-colors);
}
.btn-ghost:hover { color: var(--color-text); background: var(--color-surface-2); }
.btn-ghost__icon { color: currentColor; }
.btn-icon { width: var(--row-h-input); justify-content: center; padding-inline: 0; }

.theme-toggle__moon { display: none; }
:root[data-theme="dark"] .theme-toggle__sun { display: none; }
:root[data-theme="dark"] .theme-toggle__moon { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) .theme-toggle__sun { display: none; }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .theme-toggle__moon { display: inline; }
}

/* ---- 3. geometry selector bar ------------------------------------------- */
.geo-bar {
  position: sticky; top: var(--header-h); z-index: var(--z-raised); height: var(--geo-selector-h);
  display: flex; align-items: center; gap: var(--space-4); padding-inline: var(--space-4);
  background: var(--color-surface); border-bottom: 1px solid var(--color-border);
  overflow-x: auto; overflow-y: hidden; scrollbar-width: thin;
}
.geo-bar__group { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.geo-bar__label {
  font-size: var(--fs-2xs); font-weight: var(--fw-semibold); text-transform: uppercase;
  letter-spacing: var(--ls-wide); color: var(--color-text-muted);
}
.geo-bar__meta { gap: var(--space-2); margin-left: auto; }
.segmented {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-md);
}
.segmented__btn {
  height: calc(var(--row-h-input) - 4px); padding-inline: var(--space-3);
  font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--color-text-muted);
  background: transparent; border: none; border-radius: var(--radius-sm);
  cursor: pointer; transition: var(--transition-colors); white-space: nowrap;
}
.segmented__btn:hover { color: var(--color-text); }
.segmented__btn[aria-checked="true"] { background: var(--color-primary); color: var(--color-text-on-primary); box-shadow: var(--shadow-xs); }
.geo-thumb {
  width: 1.75rem; height: 1.75rem; display: inline-flex; align-items: center; justify-content: center;
  color: var(--color-text-muted); background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-sm);
}
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-2xs); font-weight: var(--fw-semibold);
  padding: 2px var(--space-2); border-radius: var(--radius-pill);
  background: var(--color-surface-2); color: var(--color-text-muted); border: 1px solid var(--color-border); white-space: nowrap;
}
.badge--ip .badge__num { font-size: var(--fs-xs); color: var(--color-text-body); font-family: var(--font-mono); }
.badge--ip .badge__unit { color: var(--color-text-subtle); text-transform: uppercase; letter-spacing: var(--ls-wide); }
.geo-bar__fetch { display: inline-flex; color: var(--color-secondary); }
/* Inspect/download-input-CSV button: a compact outlined ghost button so it reads
   as a control (not a header link) within the geo-bar meta cluster. */
.geo-bar__csv-btn { border-color: var(--color-border); font-size: var(--fs-sm); }
.geo-bar__csv-btn:hover:not(:disabled) { border-color: var(--color-border-strong); }
.geo-bar__csv-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.geo-warn {
  display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0;
  font-size: var(--fs-xs); color: var(--color-warning); background: var(--color-warning-bg);
  border: 1px solid var(--color-warning); border-radius: var(--radius-md); padding: 4px var(--space-2);
}
.geo-warn[hidden] { display: none; }
.geo-warn__icon { flex-shrink: 0; }

/* Symmetry-factor control in the geo-bar. Lays the label/input row on top with a
   muted note + (reserved-height) error beneath, so an out-of-range entry doesn't
   shift the bar. Reuses .field__input / .field__help (tokens-only). */
.geo-bar__group--symmetry { flex-direction: column; align-items: flex-start; gap: 2px; }
.geo-bar__symmetry-control { display: inline-flex; align-items: center; gap: var(--space-1); }
.geo-bar__symmetry-input { width: 4.5rem; }
.geo-bar__group--symmetry[data-invalid="true"] .geo-bar__symmetry-input { border-color: var(--color-danger); background: var(--color-danger-bg); }
.geo-bar__group--symmetry[data-warn="true"] .geo-bar__symmetry-input { border-color: var(--color-warning); }
.geo-bar__symmetry-note { font-size: var(--fs-2xs); color: var(--color-text-subtle); line-height: var(--lh-snug); white-space: nowrap; }
.geo-bar__symmetry-err {
  min-height: var(--fs-2xs); line-height: var(--lh-snug);
  font-size: var(--fs-2xs); color: var(--color-danger); visibility: hidden;
}
.geo-bar__group--symmetry[data-invalid="true"] .geo-bar__symmetry-err { visibility: visible; }
.geo-bar__group--symmetry[data-invalid="true"] .geo-bar__symmetry-note { display: none; }

/* ---- 4. left — param column --------------------------------------------- */
.param-col { display: flex; flex-direction: column; gap: var(--gap-stack); min-height: 0; }
/* param column scrolls with the whole page now — no internal scroll */

/* Run CTA, pinned at the very top of the param column. Sticky on desktop so the
   Run button stays reachable while the collapsible panels below scroll. */
.run-cta { display: flex; flex-direction: column; }
.run-cta .run-actions { margin-top: 0; }
@media (min-width: 1024px) {
  .run-cta {
    position: sticky; top: calc(var(--header-h) + var(--geo-selector-h)); z-index: var(--z-sticky);
    background: var(--color-bg); padding-top: var(--space-2); padding-bottom: var(--space-2);
  }
}

.build-strip, .var-panel { border-top: 1px solid var(--color-border); padding-top: var(--space-2); }
.build-strip__summary, .var-panel__summary, .subgroup__summary {
  display: flex; align-items: center; gap: var(--space-1); cursor: pointer; list-style: none;
  font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--color-text-muted); user-select: none;
}
.build-strip__summary::-webkit-details-marker,
.var-panel__summary::-webkit-details-marker,
.subgroup__summary::-webkit-details-marker { display: none; }
.chev { transition: transform var(--dur-base) var(--ease-standard); flex-shrink: 0; }
details[open] > summary .chev { transform: rotate(180deg); }
.build-strip__list { margin: var(--space-2) 0 0; display: grid; grid-template-columns: auto 1fr; gap: 2px var(--space-2); }
.build-strip__list dt { font-size: var(--fs-2xs); color: var(--color-text-muted); }
.build-strip__list dd { margin: 0; font-family: var(--font-mono); font-size: var(--fs-2xs); color: var(--color-text-body); }
.var-panel > .field-grid { margin-top: var(--space-2); }

.run-actions { display: flex; flex-direction: column; gap: var(--space-1); margin-top: var(--space-1); }
.btn-run {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 2.5rem; padding-inline: var(--space-4);
  font-family: var(--font-heading); font-size: var(--fs-md); font-weight: var(--fw-semibold);
  color: var(--color-text-on-accent); background: var(--color-accent);
  border: 1px solid var(--color-accent-active); border-radius: var(--radius-md);
  cursor: pointer; transition: var(--transition-colors);
}
.btn-run:hover:not(:disabled) { background: var(--color-accent-hover); }
.btn-run:active:not(:disabled) { background: var(--color-accent-active); }
.btn-run:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-run__icon { display: none; color: currentColor; }
.btn-run[data-run-state="idle"]      .btn-run__icon--play { display: inline; }
.btn-run[data-run-state="results"]   .btn-run__icon--play { display: inline; }
.btn-run[data-run-state="error"]     .btn-run__icon--play { display: inline; }
.btn-run[data-run-state="cancelled"] .btn-run__icon--play { display: inline; }
.btn-run[data-run-state="submitting"] .btn-run__icon--spin { display: inline; }
.btn-run[data-run-state="running"] {
  background: var(--color-surface-2); color: var(--color-text); border-color: var(--color-border-strong);
}
.btn-run[data-run-state="running"] .btn-run__icon--stop { display: inline; color: var(--color-danger); }
.run-hint { font-size: var(--fs-2xs); color: var(--color-text-subtle); }

.accordion { display: flex; flex-direction: column; gap: var(--gap-stack); }
.acc-item { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; }
.acc-header { margin: 0; }
.acc-trigger {
  width: 100%; min-height: 2.75rem; display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--pad-card); background: transparent; border: none; cursor: pointer;
  text-align: left; transition: var(--transition-colors);
}
.acc-trigger:hover { background: var(--color-surface-2); }
.acc-trigger__chev { color: var(--color-text-muted); transition: transform var(--dur-base) var(--ease-standard); flex-shrink: 0; }
.acc-trigger[aria-expanded="true"] .acc-trigger__chev { transform: rotate(180deg); }
.acc-trigger[aria-expanded="true"] { background: var(--color-surface-2); border-bottom: 1px solid var(--color-border); }
.acc-trigger__title { flex: 1; font-family: var(--font-heading); font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--color-text); }
.acc-panel { padding: var(--pad-card); display: flex; flex-direction: column; gap: var(--space-3); }
.acc-panel[hidden] { display: none; }

.badge--curve { text-transform: uppercase; letter-spacing: var(--ls-wide); }
.badge--curve[data-status="live"] { color: var(--color-success); background: var(--color-success-bg); border-color: var(--color-success); }
.badge--curve[data-status="warn"] { color: var(--color-warning); background: var(--color-warning-bg); border-color: var(--color-warning); }
.badge--inactive { color: var(--color-text-subtle); font-style: italic; }

.subgroup { display: flex; flex-direction: column; gap: var(--space-2); }
.subgroup__title {
  font-size: var(--fs-2xs); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: var(--ls-wide);
  color: var(--color-text-muted); padding-bottom: 2px; border-bottom: 1px solid var(--color-border);
}
.subgroup--adv { border-top: 1px dashed var(--color-border); padding-top: var(--space-2); }
.subgroup--adv > .field-grid { margin-top: var(--space-2); }

.field-grid { display: flex; flex-direction: column; gap: var(--space-2); }
.field { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px var(--space-2); }
.field__label { grid-column: 1 / 2; font-size: var(--fs-sm); color: var(--color-text-muted); display: inline-flex; align-items: center; gap: var(--space-1); }
.field__control { grid-column: 2 / 3; display: inline-flex; align-items: center; gap: var(--space-1); height: var(--row-h-input); }
.field__input {
  width: 6.5rem; height: var(--row-h-input); padding: 0 var(--pad-input-x); text-align: right;
  font-family: var(--font-mono); font-size: var(--fs-base); color: var(--color-text-body);
  background: var(--color-surface); border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm); transition: var(--transition-colors);
}
.field__input:hover { border-color: var(--color-secondary); }
select.field__input { text-align: left; cursor: pointer; }
.field__unit { font-size: var(--fs-2xs); color: var(--color-text-subtle); min-width: 2.5rem; }
.field__error {
  grid-column: 1 / 3; min-height: var(--fs-2xs); line-height: var(--lh-snug);
  font-size: var(--fs-2xs); color: var(--color-danger); visibility: hidden;
}
.field[data-invalid="true"] .field__input { border-color: var(--color-danger); background: var(--color-danger-bg); }
.field[data-invalid="true"] .field__error { visibility: visible; }
.field[data-warn="true"] .field__input { border-color: var(--color-warning); }

.field--toggle { grid-template-columns: auto 1fr auto; }
.field__label--toggle { grid-column: auto; }
.switch { width: 2.25rem; height: 1.25rem; padding: 0; flex-shrink: 0; background: transparent; border: none; cursor: pointer; }
.switch__track {
  display: block; width: 100%; height: 100%; border-radius: var(--radius-pill);
  background: var(--color-surface-3); border: 1px solid var(--color-border-strong); position: relative; transition: var(--transition-colors);
}
.switch__thumb {
  position: absolute; top: 1px; left: 1px; width: 1rem; height: 1rem; border-radius: var(--radius-pill);
  background: var(--color-surface); box-shadow: var(--shadow-sm); transition: transform var(--dur-base) var(--ease-standard);
}
.switch[aria-checked="true"] .switch__track { background: var(--color-primary); border-color: var(--color-primary); }
.switch[aria-checked="true"] .switch__thumb { transform: translateX(1rem); }
.field--toggle[data-disabled="true"] { opacity: 0.5; }
.field--toggle[data-disabled="true"] .switch { cursor: not-allowed; }

.select {
  height: var(--row-h-input); padding: 0 var(--pad-input-x);
  font-family: var(--font-sans); font-size: var(--fs-base); color: var(--color-text-body);
  background: var(--color-surface); border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition-colors);
}

.curve-figure { margin: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.curve-figure__cap { font-size: var(--fs-2xs); color: var(--color-text-muted); font-family: var(--font-heading); }
.curve-canvas {
  width: 100%; height: 180px; background: var(--color-surface-2);
  /* inset-shadow frame (not a border) so the content box keeps the full 180px
     and Plotly's bottom x-axis title isn't clipped at the edge. */
  box-shadow: inset 0 0 0 1px var(--color-border); border-radius: var(--radius-sm);
}

/* ---- 5. right — results ------------------------------------------------- */
.results { display: flex; flex-direction: column; gap: var(--gap-grid); min-height: 0; }
/* results column scrolls with the whole page now — no internal scroll */

.status-strip {
  display: flex; flex-direction: column; gap: var(--space-2); padding: var(--pad-card);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-border-strong); border-radius: var(--radius-md);
}
.status-strip[data-state="running"]   { border-left-color: var(--color-secondary); }
.status-strip[data-state="results"]   { border-left-color: var(--color-success); }
.status-strip[data-state="error"]     { border-left-color: var(--color-danger); background: var(--color-danger-bg); }
.status-strip[data-state="cancelled"] { border-left-color: var(--color-warning); }
.status-strip__main { display: flex; align-items: center; gap: var(--space-2); }
.status-strip__icon { display: inline-flex; flex-shrink: 0; color: var(--color-text-muted); }
.status-strip[data-state="running"] .status-strip__icon { color: var(--color-secondary); }
.status-strip[data-state="results"] .status-strip__icon { color: var(--color-success); }
.status-strip[data-state="error"]   .status-strip__icon { color: var(--color-danger); }
.status-strip__text { flex: 1; font-size: var(--fs-sm); color: var(--color-text); }
.status-strip__time { font-size: var(--fs-xs); color: var(--color-text-muted); font-family: var(--font-mono); }

.progress { display: flex; align-items: center; gap: var(--space-2); min-height: 1.25rem; }
.progress[hidden] { display: none; }
.progress__track { flex: 1; height: 6px; background: var(--color-surface-3); border-radius: var(--radius-pill); overflow: hidden; }
.progress__fill { height: 100%; width: 0%; background: var(--color-secondary); border-radius: var(--radius-pill); transition: width var(--dur-base) var(--ease-out); }
.progress[data-indeterminate="true"] .progress__fill { width: 35%; animation: progress-indeterminate 1.1s var(--ease-standard) infinite; }
@keyframes progress-indeterminate { 0% { transform: translateX(-120%); } 100% { transform: translateX(320%); } }
.progress__counter { font-size: var(--fs-2xs); color: var(--color-text-muted); min-width: 5rem; text-align: right; font-family: var(--font-mono); }

/* KPI skeleton (results.js owns .kpi-card/.kpi-rail; app.js renders the pre-run
   skeleton state and reserves the value height). */
.kpi-card__skeleton {
  display: inline-block; width: 70%; height: calc(var(--fs-xl) * 0.8);
  background: var(--color-surface-3); border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.4s var(--ease-standard) infinite;
}
@keyframes skeleton-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

/* chart-card chrome (head + toolbar + reserved plot box). The inner #chart-*
   nodes are populated by results.js/hazard3d.js. */
.chart-card, .hazard-card {
  display: flex; flex-direction: column;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-xs); overflow: hidden;
}
.chart-card__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  padding: var(--space-2) var(--pad-card); border-bottom: 1px solid var(--color-border);
}
.chart-card__title { font-size: var(--fs-sm); color: var(--color-text); }
.chart-toolbar { display: inline-flex; gap: 2px; }
.chart-toolbar__btn {
  width: 1.75rem; height: 1.75rem; display: inline-flex; align-items: center; justify-content: center;
  color: var(--color-text-muted); background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition-colors);
}
.chart-toolbar__btn:hover { color: var(--color-text); background: var(--color-surface-2); border-color: var(--color-border); }
.chart-plot { width: 100%; min-height: var(--chart-min-h); height: var(--chart-min-h); }

.hazard-plot { width: 100%; min-height: var(--hazard-min-h); height: var(--hazard-min-h); }
.hazard-disclosure__btn {
  display: none; width: 100%; min-height: 2.75rem; align-items: center; justify-content: center; gap: var(--space-2);
  font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--color-text);
  background: var(--color-surface-2); border: none; cursor: pointer;
}
.hazard-disclosure__btn:not([hidden]) { display: flex; }
.hazard-disclosure[data-collapsed="true"] .hazard-plot { display: none; }

/* ---- 6. overlays — modal / toast / tooltip ------------------------------ */
.modal-root { position: fixed; inset: 0; z-index: var(--z-modal); display: flex; align-items: center; justify-content: center; }
.modal-root[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.55); animation: fade-in var(--dur-fast) var(--ease-out); }
.modal {
  position: relative; z-index: 1; width: min(30rem, calc(100vw - 2 * var(--space-4)));
  max-height: calc(100vh - 2 * var(--space-6)); overflow: auto;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: var(--space-5);
  animation: modal-pop var(--dur-base) var(--ease-out);
}
.modal__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.modal__title { font-size: var(--fs-lg); color: var(--color-text); display: flex; align-items: center; gap: var(--space-2); }
.modal__title-icon { flex-shrink: 0; }
.modal--warning .modal__title-icon { color: var(--color-warning); }
.modal--error .modal__title-icon { color: var(--color-danger); }
.modal__close {
  width: 1.75rem; height: 1.75rem; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  color: var(--color-text-muted); background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition-colors);
}
.modal__close:hover { color: var(--color-text); background: var(--color-surface-2); }
.modal__body { font-size: var(--fs-base); color: var(--color-text); line-height: var(--lh-normal); }
.modal__body p + p { margin-top: var(--space-2); }
.modal__body code { font-family: var(--font-mono); font-size: var(--fs-sm); background: var(--color-surface-2); padding: 1px 4px; border-radius: var(--radius-xs); }
.modal__actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-4); }
.modal__btn {
  min-height: 2.25rem; padding-inline: var(--space-4); font-size: var(--fs-base); font-weight: var(--fw-medium);
  border-radius: var(--radius-md); cursor: pointer; transition: var(--transition-colors);
}
.modal__btn--primary { color: var(--color-text-on-accent); background: var(--color-accent); border: 1px solid var(--color-accent-active); }
.modal__btn--primary:hover { background: var(--color-accent-hover); }
.modal__btn--ghost { color: var(--color-text); background: var(--color-surface); border: 1px solid var(--color-border-strong); }
.modal__btn--ghost:hover { background: var(--color-surface-2); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* Input-CSV preview modal: a wider shell + a scrollable monospace table. The
   wider width applies only when the modal actually hosts the CSV table (:has). */
.modal:has(.csv-modal__table-wrap) { width: min(52rem, calc(100vw - 2 * var(--space-4))); }
.csv-modal__sub { color: var(--color-text-muted); font-size: var(--fs-sm); }
.csv-modal__meta { color: var(--color-text-muted); font-size: var(--fs-sm); margin-top: var(--space-1); }
.csv-modal__status { color: var(--color-text-muted); font-size: var(--fs-sm); margin-top: var(--space-2); }
.csv-modal__table-wrap {
  margin-top: var(--space-3); max-height: 22rem; overflow: auto;
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
}
.csv-modal__table {
  border-collapse: collapse; width: 100%;
  font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--color-text);
}
.csv-modal__table th, .csv-modal__table td {
  padding: 2px var(--space-2); text-align: right; white-space: nowrap;
  border-bottom: 1px solid var(--color-border);
}
.csv-modal__table thead th {
  position: sticky; top: 0; z-index: 1; text-align: right;
  background: var(--color-surface-2); color: var(--color-text-muted); font-weight: var(--fw-medium);
}
.csv-modal__table tbody tr:nth-child(even) { background: var(--color-surface-2); }

.toast-host {
  position: fixed; right: var(--space-4); bottom: var(--space-4); z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--space-2); max-width: min(22rem, calc(100vw - 2 * var(--space-4)));
}
.toast {
  display: flex; align-items: flex-start; gap: var(--space-2); padding: var(--space-2) var(--space-3);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-secondary); border-radius: var(--radius-md);
  box-shadow: var(--shadow-md); font-size: var(--fs-sm); color: var(--color-text);
  animation: toast-in var(--dur-base) var(--ease-out);
}
.toast--warning { border-left-color: var(--color-warning); }
.toast--error { border-left-color: var(--color-danger); }
.toast__icon { flex-shrink: 0; color: var(--color-text-muted); margin-top: 1px; }
.toast[data-leaving="true"] { animation: toast-out var(--dur-fast) var(--ease-in) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

.tooltip {
  position: fixed; z-index: var(--z-tooltip); max-width: 18rem; padding: var(--space-2) var(--space-3);
  background: var(--color-text-body); color: var(--color-surface);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  font-size: var(--fs-xs); line-height: var(--lh-snug); pointer-events: none;
}
.tooltip[hidden] { display: none; }
.field__help {
  display: inline-flex; width: 1rem; height: 1rem; align-items: center; justify-content: center;
  color: var(--color-text-subtle); background: transparent; border: none; cursor: help; padding: 0;
}
.field__help:hover { color: var(--color-secondary); }

.results[data-stale="true"] .kpi-rail,
.results[data-stale="true"] .chart-card,
.results[data-stale="true"] .hazard-card { opacity: 0.55; transition: opacity var(--dur-base) var(--ease-standard); }

/* ---- 7. responsive ------------------------------------------------------ */
@media (max-width: 767px) {
  .app-shell { grid-template-rows: var(--header-h) auto 1fr; }
  .app-header__tagline { display: none; }
  .field { grid-template-columns: 1fr; }
  .field__label { grid-column: 1; }
  .field__control { grid-column: 1; justify-content: flex-start; }
  .field__input { width: 100%; max-width: 9rem; }
  .field__error { grid-column: 1; }
}
@media (min-width: 768px) and (max-width: 1023px) { .field__input { width: 7rem; } }
@media (min-width: 1440px) {
  .results { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap-grid); align-content: start; }
  .status-strip, .kpi-rail, .hazard-card { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  .progress[data-indeterminate="true"] .progress__fill { animation: none; width: 100%;
    background: repeating-linear-gradient(45deg, var(--color-secondary), var(--color-secondary) 6px, transparent 6px, transparent 12px); }
  .kpi-card__skeleton { animation: none; }
  .spin { animation: none; }
}
