/*
 * Phase 6a baseline styles for the Synesis P_success frontend.
 *
 * Card-based layout with progressive disclosure. Sections start hidden
 * (via the `hidden` HTML attribute) and main.js reveals them as the user
 * advances through the flow: setup → research → parameters / scenarios /
 * benchmarks / Monte Carlo. The full theme port from
 * `../SynesisLabs Platform/psuccess-platform.html` is still deferred —
 * this pass is the structural rework, with the visual upgrade staying
 * intentionally light so the markup is what we're committing to, not
 * the colours.
 */

/* === Tokens =============================================================== */
/*  Single source of truth for the colour palette. Tweak here, not at        */
/*  per-component sites. The hex values stay close to the legacy brand       */
/*  so a future dark-theme port stays a colour swap, not a layout fight.    */

:root,
[data-theme="light"] {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-muted: #f7fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e0;
  --text: #1a202c;
  --text-muted: #4a5568;
  --text-subtle: #718096;
  --accent: #2b6cb0;
  --accent-strong: #1e3a5f;
  --accent-soft: rgba(43, 108, 176, 0.08);
  --good: #2f855a;
  --good-soft: #d1fae5;
  --warn: #b7791f;
  --warn-soft: #fef3c7;
  --bad: #c53030;
  --bad-soft: #fee2e2;
  --orange: #f97316;
  --modal-backdrop: rgba(15, 23, 42, 0.45);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
}

/*  Dark-theme token overrides. Same variable names, different values —
 *  every component reads via `var(--*)` so swapping the attribute on
 *  `<html>` swaps the whole UI without touching any per-component CSS.
 *  Soft variants use rgba alpha so coloured backgrounds blend onto the
 *  dark surfaces correctly; light mode's pastel solids would look
 *  garish on a dark card.
 */
[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #131c30;
  --surface-muted: #1c2740;
  --border: #2a3656;
  --border-strong: #475569;
  --text: #e7ecf3;
  --text-muted: #cbd5e0;
  --text-subtle: #8c9ab2;
  --accent: #38bdf8;
  --accent-strong: #7dd3fc;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --good: #34d399;
  --good-soft: rgba(52, 211, 153, 0.18);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.18);
  --bad: #f87171;
  --bad-soft: rgba(248, 113, 113, 0.18);
  --orange: #fb923c;
  --modal-backdrop: rgba(0, 0, 0, 0.6);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.5);
}

/*  Smooth-but-not-distracting transition when the user toggles. Picks
 *  the properties that actually change so the page doesn't animate
 *  unrelated layout shifts.
 */
html {
  transition: background-color 0.15s linear;
}

body {
  transition: background-color 0.15s linear, color 0.15s linear;
}

/* === Page-level ========================================================== */
/*  Constrained reading column, neutral background, consistent type ramp.    */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

/* === App header ========================================================== */
/*  Sticks to the top of the page (no scroll detach). Title on the left,    */
/*  account chip on the right; the chip is hidden when no session exists.   */

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.app-title .title-accent {
  color: var(--accent);
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.account-chip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* The signed-in email in the header. It's a <button> that opens Clerk's
 * account-management modal, so reset the button chrome to keep the quiet
 * text look, then add a link-like hover/focus affordance so it reads as
 * clickable ("manage your account"). */
.account-email {
  font-size: 0.85rem;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  padding: 0;
  font-family: inherit;
  cursor: pointer;
}

.account-email:hover,
.account-email:focus-visible {
  color: var(--accent);
  text-decoration: underline;
  outline: none;
}

/* Theme toggle button. Both icons live in the same button; CSS reveals
 * whichever icon represents the NEXT action (so a moon shows in light
 * mode meaning "switch to dark"). Padding gives the icon room without
 * making the button a chunky target.
 */
.theme-toggle {
  background: transparent;
  border: 0;
  padding: 0.4rem;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.12s, color 0.12s;
}

.theme-toggle:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-icon {
  display: block;
  pointer-events: none;
}

/*  Default (light theme): show moon glyph, hide sun. Dark theme flips. */
.theme-icon-sun { display: none; }
[data-theme="dark"] .theme-icon-moon { display: none; }
[data-theme="dark"] .theme-icon-sun  { display: block; }

/* === Card system ========================================================= */
/*  Every major section sits inside a .card. The visible heading is in
    .card-header > .card-title, with optional .card-subtitle copy. Actions
    live in .card-footer at the bottom. Cards stack vertically with
    consistent spacing so the page reads as a top-down checklist. */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.card-header {
  margin-bottom: 1rem;
}

.card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-strong);
}

.card-subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.card-footer {
  margin-top: 1rem;
}

.section-subtitle {
  margin: 1rem 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-subtle);
  font-weight: 700;
}

.prose {
  line-height: 1.55;
  color: var(--text);
}

.prose strong {
  color: var(--accent-strong);
}

/* === Form controls ======================================================= */
/*  Inputs span the card width by default. Labels stack above inputs.       */

label {
  display: block;
  margin: 0.85rem 0 0.3rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

label .label-hint {
  font-weight: 400;
  color: var(--text-subtle);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  font-size: 0.95rem;
  font-family: inherit;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  box-sizing: border-box;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 5rem;
  font-family: inherit;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
  font-weight: 500;
  font-size: 0.9rem;
}

.checkbox-label input {
  width: auto;
  margin: 0;
}

/*  Settings disclosure ─ collapsed reveal for the API config in the
    setup card. <summary> styled as a tappable header. */
.settings-disclosure {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.85rem;
  background: var(--surface-muted);
}

.settings-disclosure > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent);
  outline: none;
  user-select: none;
}

.settings-disclosure[open] > summary {
  margin-bottom: 0.6rem;
}

.settings-grid label {
  margin-top: 0.7rem;
}

/* === Buttons ============================================================= */
/*  Three visual roles: primary (the headline action — RUN MODEL, Log in),  */
/*  secondary (RUN scenarios / RUN benchmarks / Run MC), ghost (Log out,    */
/*  modal close, anything that shouldn't compete for attention).            */

button {
  font-family: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 6px;
  font-weight: 600;
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  transition: filter 0.12s, background-color 0.12s;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.btn-secondary {
  background: var(--surface-muted);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: #edf2f7;
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 0.35rem 0.65rem;
  font-weight: 500;
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-muted);
}

.btn-large {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

.btn-small {
  padding: 0.3rem 0.55rem;
  font-size: 0.85rem;
}

/* Horizontal group of buttons inside a card-footer (e.g. Export + Generate
   report). Wraps on narrow screens; the gap keeps them from touching. */
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

/* The "Import saved project" affordance sits just under the Project card
   header, visually separated from the name/description fields below it. */
.setup-import {
  margin: 0 0 1rem;
}

/* Per-control explanation shown beneath a button that has been disabled
   because it cannot run on the current question (app/unavailable.js). Sits in
   a .card-footer, either directly under its button or under the .button-row
   wrapping it, so it shares the top margin of .status-line / .error above.
   Deliberately muted rather than red: the control is not broken, it is
   inapplicable, and .error already owns the "something failed" register. */
.unavailable-note {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* === Status + error lines ================================================ */
/*  Status line uses the spinner cycle from app/status-cycle.js — monospace */
/*  keeps the leading braille glyph at fixed width.                          */

.status-line {
  margin: 0.6rem 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92rem;
  color: var(--accent);
}

.error {
  color: var(--bad);
  margin: 0.5rem 0 0;
}

.meta-status {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  margin: 1rem 0;
}

/* === Sign-in (Clerk) ===================================================== */

/*
 * The sign-in screen is just a centering wrapper around Clerk's own card — we
 * intentionally don't wrap it in our .card (that produced a redundant outer box
 * the Clerk card overflowed). Clerk is themed to our palette via clerkAppearance()
 * in app/clerk.js.
 */
.login-wrap {
  display: flex;
  justify-content: center;
  margin: 3rem auto;
  padding: 0 1rem;
}

.card-title {
  margin: 0;
}

/* === Upload zone ========================================================= */

.upload-zone {
  border: 1.5px dashed var(--border-strong);
  border-radius: 6px;
  padding: 1rem 0.75rem;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
  background: var(--surface-muted);
  transition: border-color 0.12s, color 0.12s, background-color 0.12s;
}

.upload-zone:hover,
.upload-zone:focus {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

.upload-zone.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.upload-hint {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-subtle);
}

.file-list {
  margin-top: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.55rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
}

.file-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-badge {
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--border);
  color: var(--text-muted);
}

.file-badge-parsing { background: var(--border); color: var(--text-muted); }
.file-badge-ok      { background: var(--good-soft); color: var(--good); }
.file-badge-unsupported { background: var(--warn-soft); color: var(--warn); }
.file-badge-error   { background: var(--bad-soft); color: var(--bad); }

.file-remove {
  background: transparent;
  color: var(--text-subtle);
  border: 0;
  padding: 0 0.4rem;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  font-weight: 700;
}

.file-remove:hover {
  color: var(--bad);
}

/* === Sliders + result strip ============================================== */
/*  Section headings ("Internal factors", "Elasticities") are injected by   */
/*  sliders.js between the slider groups.                                    */

#slidersSection h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 1.25rem 0 0.5rem;
  color: var(--text-subtle);
  font-weight: 700;
}

.slider-row {
  display: grid;
  grid-template-columns: 11rem 1fr 4rem;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
}

.slider-row label {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
}

.slider-row input[type="range"] {
  width: 100%;
}

.slider-row .slider-value {
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-size: 0.88rem;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, monospace;
}

/*  Empty state for the slider region — rendered by `renderSlidersUnavailable`
 *  in sliders.js when a question has no parameters (pre-flight-gated run, or
 *  an imported project with no research). The heading follows the established
 *  micro-label idiom (.result-label, #slidersSection h2): small, uppercase,
 *  subtle, bold. The body matches .card-subtitle so the note reads as card
 *  prose rather than as a warning — a settled question is a normal outcome,
 *  not an error. Colours are var(--*) only; the stylesheet has no
 *  prefers-color-scheme query (themes swap by attribute on <html>), so a
 *  literal here would simply fail to invert in dark mode.
 */

.params-unavailable {
  padding: 1.25rem 0 0.5rem;
}

.params-unavailable h3 {
  margin: 0 0 0.4rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
  font-weight: 700;
}

.params-unavailable p {
  margin: 0;
  /* Caps the measure at a comfortable reading length; the card itself is far
     wider than this three-line paragraph wants to be. */
  max-width: 62ch;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.result-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.85rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 1rem;
}

.result-strip .result-cell {
  flex: 1 1 6rem;
  min-width: 6rem;
}

.result-strip .result-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
  font-weight: 700;
}

.result-strip .result-value {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.result-strip.calculating {
  opacity: 0.55;
}

/*  The `observed` qualifier under a gated run's two probability cells.
 *  Lower-case and un-tracked on purpose: `.result-label` above the value is
 *  already the uppercase micro-label, so an uppercase note here would
 *  compete with it instead of reading as the annotation it is.
 */
.result-strip .result-note {
  margin-top: 0.15rem;
  font-size: 0.68rem;
  color: var(--text-subtle);
}

/*  Sign colouring for the `Δ vs baseline` cell. Same --good / --bad pairing
 *  as the three existing precedents (.scenario-delta, .drawer-outcome-value,
 *  .drawer-param-delta) so the strip's verdict can never read differently
 *  from the scenario row badge it is derived from.
 */
.result-strip .result-value.pos { color: var(--good); }
.result-strip .result-value.neg { color: var(--bad); }

/* === Source badges ======================================================= */
/*  Inline chips above the research summary: "web research used" /          */
/*  "N documents".                                                          */

.source-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.source-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  background: var(--border);
  color: var(--text-muted);
}

.source-badge.active {
  background: var(--good-soft);
  color: var(--good);
}

.source-badge.inactive {
  background: var(--surface-muted);
  color: var(--text-subtle);
}

/* === Pre-flight gate banner ============================================== */
/*  Shown inside #researchResult when the triage settled the question       */
/*  (status "not_scored"): already resolved, or already foreclosed. States  */
/*  the resolution, the observed probability and the as-of date.            */
/*                                                                          */
/*  Left-rule callout, same idiom as .terms-consent-banner (:1231) and      */
/*  .terms-stale-banner (:1217), so it reads as a standing notice about the */
/*  run rather than as an error line.                                       */
/*                                                                          */
/*  ACCENT, deliberately not --good / --bad. Colouring the banner by the    */
/*  verdict — green for resolved_yes, red for resolved_no — would           */
/*  editorialise the outcome, implying the platform welcomes one result and */
/*  regrets the other. The banner is reporting a fact about the question,   */
/*  not a judgement about it: the question is not scoreable, which is       */
/*  neither good news nor bad. Accent is the neutral "notice" colour        */
/*  already established for exactly that job elsewhere in this sheet.       */
/*                                                                          */
/*  No `display` property: the banner is toggled with the `hidden` attribute */
/*  from research-result.js, and declaring display here would override the   */
/*  UA's `[hidden] { display: none }` and pin it permanently open.           */

.gate-banner {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  padding: 0.7rem 0.85rem;
  /* Zero margins on purpose: .card-header above already contributes its
     1rem bottom margin, and the "Summary" .section-subtitle below
     contributes its 1rem top margin. Adding our own would double the gaps. */
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text);
}

/* === Scenarios list ====================================================== */

.scenarios-list {
  margin-top: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.scenario-row {
  padding: 0.65rem 0.85rem;
  background: var(--surface-muted);
  border-left: 3px solid var(--border-strong);
  border-radius: 5px;
  /* The whole row is a click-to-apply toggle. */
  cursor: pointer;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.scenario-row:hover {
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--border-strong) inset;
}
.scenario-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.scenario-row.scenario-up   { border-left-color: var(--good); }
.scenario-row.scenario-down { border-left-color: var(--bad); }

/* Active (applied) scenario: accent-tinted highlight so the user can see at a
   glance which scenario is currently driving the sliders. */
.scenario-row.active {
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.scenario-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
}

/* Name takes the slack so the Δpp badge sits flush right. */
.scenario-name {
  flex: 1;
}

/* Projected P_success change vs baseline (filled async from /score/batch). */
.scenario-delta {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}
.scenario-delta.pos { color: var(--good); }
.scenario-delta.neg { color: var(--bad); }

/* Toolbar above the scenario list: Summary heading on the left, Reset right. */
.scenarios-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.scenarios-toolbar .section-subtitle {
  margin: 1rem 0 0.5rem;
}

.scenarios-hint {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  color: var(--text-subtle);
  font-style: italic;
}

/* === Scenario detail drawer (opens inside the active row) =============== */

.scenario-drawer {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border-strong);
  cursor: auto; /* the row is a pointer; the drawer is informational */
}

/* Outcome row: P_success / Δ vs baseline / P_failure. */
.drawer-outcomes {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem;
  margin-bottom: 0.7rem;
}
.drawer-outcome-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
}
.drawer-outcome-value {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}
.drawer-outcome-value.primary { color: var(--accent-strong); }
.drawer-outcome-value.pos { color: var(--good); }
.drawer-outcome-value.neg { color: var(--bad); }

/* Compact 14-parameter grid. */
.drawer-params {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.3rem 0.8rem;
}
.drawer-param {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  font-size: 0.8rem;
  padding: 0.15rem 0.3rem;
  border-radius: 3px;
}
.drawer-param-label {
  color: var(--text-muted);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drawer-param-value {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-weight: 600;
  color: var(--text);
}
/* Parameters this scenario changed: tinted background + the delta. */
.drawer-param.changed {
  background: var(--accent-soft);
}
.drawer-param.changed .drawer-param-label {
  color: var(--text);
  font-weight: 600;
}
.drawer-param-delta {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.72rem;
  font-weight: 700;
}
.drawer-param-delta.pos { color: var(--good); }
.drawer-param-delta.neg { color: var(--bad); }

.scenario-id {
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--accent);
}

.scenario-up .scenario-arrow   { color: var(--good); }
.scenario-down .scenario-arrow { color: var(--bad); }

.scenario-rationale {
  margin: 0.4rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.scenario-shifts {
  margin-top: 0.4rem;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.8rem;
  color: var(--text);
}

/* === Benchmarks list ===================================================== */

.peers-list {
  margin-top: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.peer-row {
  display: grid;
  grid-template-columns: 3rem 1fr 5rem;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.9rem;
}

.peer-rank {
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--text-subtle);
}

.peer-name {
  cursor: help;
  font-weight: 600;
  color: var(--text);
}

.peer-score {
  font-family: ui-monospace, SFMono-Regular, monospace;
  text-align: right;
  font-weight: 700;
  color: var(--accent);
}

/* === Monte Carlo trigger + modal ========================================= */
/*  Trigger button gets the brand-accent treatment to read as the lone      */
/*  flagship action inside the Parameters card.                              */

.mc-trigger {
  background: linear-gradient(135deg, #f97316, #dc2626) !important;
  color: #fff !important;
  border: 0 !important;
  font-weight: 700;
}

.mc-trigger:hover:not(:disabled) {
  filter: brightness(1.05);
}

#monteCarloModal {
  max-width: 760px;
  width: 92%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  color: var(--text);
  margin: auto;
}

#monteCarloModal::backdrop {
  background: var(--modal-backdrop);
}

#monteCarloModal h3 {
  margin: 0 0 0.25rem;
  font-size: 1.15rem;
  color: var(--accent-strong);
}

.modal-subtitle {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

#monteCarloModal label span {
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--accent);
  font-weight: 700;
  margin-left: 0.25rem;
}

#monteCarloModal input[type="range"] {
  width: 100%;
}

.mc-status {
  margin: 0.6rem 0 0;
  font-style: italic;
  color: var(--accent);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.mc-results {
  margin-top: 1rem;
}

.mc-chart {
  width: 100%;
  max-height: 220px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* SVG marker styling — extracted from inline SVG attributes into CSS
 * classes so the chart adapts to the theme. Bars keep their semantic
 * red/amber/green inline-fills (those convey meaning, not theming);
 * markers and axis labels follow the theme's text colour.
 */
.mc-marker {
  stroke: var(--text);
  stroke-width: 1.2;
  stroke-dasharray: 3 3;
}

.mc-marker-label {
  fill: var(--text);
  font-size: 10px;
  font-family: ui-monospace, SFMono-Regular, monospace;
}

.mc-axis-label {
  fill: var(--text-muted);
  font-size: 10px;
  font-family: ui-monospace, SFMono-Regular, monospace;
}

.mc-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
  margin: 0.85rem 0 0.5rem;
}

.mc-stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
  font-weight: 700;
}

.mc-stat-value {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.mc-stat-value.mc-stat-low  { color: var(--bad); }
.mc-stat-value.mc-stat-high { color: var(--good); }
.mc-stat-value.mc-stat-mean { color: var(--accent); }

.mc-band {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.mc-verdict {
  margin-top: 0.85rem;
  padding: 0.75rem 0.9rem;
  background: rgba(249, 115, 22, 0.08);
  border-left: 3px solid var(--orange);
  border-radius: 4px;
}

.mc-verdict-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #c2410c;
  font-weight: 700;
}

.mc-verdict-text {
  margin-top: 0.25rem;
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.45;
}

/* === Model clarification modal ========================================== */

#modelClarificationModal {
  max-width: 560px;
  width: 90%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  color: var(--text);
  background: var(--surface);
  margin: auto;
}

#modelClarificationModal::backdrop {
  background: var(--modal-backdrop);
}

#modelClarificationModal h3 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
  color: var(--accent-strong);
}

#modelClarificationModal .modal-body {
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 0.95rem;
  color: var(--text);
  max-height: 60vh;
  overflow-y: auto;
  padding: 0.75rem 0.85rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* === Responsive tweaks =================================================== */

@media (max-width: 600px) {
  .slider-row {
    grid-template-columns: 8rem 1fr 3.5rem;
  }
  .mc-stats {
    grid-template-columns: repeat(2, 1fr);
  }
  main {
    padding: 1rem 0.85rem 3rem;
  }
}

/* === Phase 6d: API-settings + Terms modals ============================== */

/* Web-search toggle row, sitting just above the RUN MODEL button in the Setup
   card. A little breathing room separates it from the upload zone above and
   the primary action below. */
/* Prompt-template selector sits between the upload zone and the run-mode
   group; a little bottom margin separates it from the group below. */
.prompt-template-select {
  margin-bottom: 0.5rem;
}

/* Run-mode radio group (web search / offline / reproducible) above RUN MODEL.
   A borderless fieldset so it reads as a labelled cluster of options without
   the heavy default browser chrome. */
.run-mode-group {
  margin: 0.75rem 0 0.25rem;
  padding: 0;
  border: 0;
}

.run-mode-group legend {
  /* Match the weight/size of the other field labels (see the `label` rule)
     so the group header doesn't stand out as a different control family. */
  padding: 0;
  margin-bottom: 0.3rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

/* One option row: the radio and its (possibly two-line) label, top-aligned so
   a wrapped hint stays tidy next to the control. */
.radio-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.3rem 0 0;
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
}

.radio-label input {
  width: auto;
  margin: 0;
  /* Nudge the control onto the text baseline of the first label line. */
  margin-top: 0.15rem;
}

/* Shared form layout used inside the API-settings modal: stacked
   label/control pairs with comfortable spacing. */
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0.5rem 0 0;
}
.settings-grid label:not(.checkbox-label) {
  font-weight: 600;
  font-size: 0.9rem;
}
.settings-grid input[type="password"],
.settings-grid select {
  width: 100%;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
  font-weight: 500;
  cursor: pointer;
}

/* Status line tones for the "Test connection" result. Base `.status-line`
   already sets layout/colour; these override the colour by outcome. */
.status-ok {
  color: var(--good);
}
.status-bad {
  color: var(--bad);
}

#apiSettingsModal {
  max-width: 520px;
  width: 92%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  color: var(--text);
  margin: auto;
}
#apiSettingsModal::backdrop {
  background: var(--modal-backdrop);
}
#apiSettingsModal h3 {
  margin: 0 0 0.25rem;
  font-size: 1.15rem;
  color: var(--accent-strong);
}

/* Terms modal: tall, scrollable body with a pinned header banner + footer.
   Flex layout is scoped to [open] so the dialog's closed (display:none)
   state from the UA stylesheet still applies. */
#termsModal {
  max-width: 760px;
  width: 92%;
  max-height: 85vh;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  color: var(--text);
  margin: auto;
}
#termsModal[open] {
  display: flex;
  flex-direction: column;
}
#termsModal::backdrop {
  background: var(--modal-backdrop);
}
#termsModal h3 {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.4px;
}
.terms-tag {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-left: 0.6rem;
  padding-left: 0.6rem;
  border-left: 1px solid var(--border-strong);
}

/* Amber "out of date" notice — pinned above the scrollable body. */
.terms-stale-banner {
  background: var(--warn-soft);
  border-left: 3px solid var(--warn);
  border-radius: 5px;
  padding: 0.7rem 0.85rem;
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  line-height: 1.5;
}
.terms-stale-banner strong {
  color: var(--warn);
}

/* Blue consent banner — shown only in gate mode. */
.terms-consent-banner {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  padding: 0.7rem 0.85rem;
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  line-height: 1.5;
}

/* The scrollable legal text. flex:1 lets it take the remaining height
   between the banners and the footer; overflow-y makes it scroll. */
.terms-body {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-size: 0.82rem;
  line-height: 1.55;
}
.terms-body h4 {
  color: var(--accent-strong);
  font-size: 0.9rem;
  margin: 1rem 0 0.35rem;
}
.terms-body h4:first-of-type {
  margin-top: 0.25rem;
}
.terms-body ul {
  padding-left: 1.3rem;
  margin: 0.35rem 0;
}
.terms-body a {
  color: var(--accent);
}
.terms-effective,
.terms-footnote {
  color: var(--text-muted);
  font-size: 0.75rem;
}
.terms-footnote {
  margin-top: 1.2rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
}

/* === Per-parameter ⓘ rationale popover (slider rows) =================== */

/* The ⓘ trigger sits inline after each slider's label text. position:relative
   makes it the anchor for the absolutely-positioned popover. */
.slider-info {
  position: relative;
  display: inline-block;
  margin-left: 0.35rem;
  color: var(--accent);
  cursor: help;
  font-size: 0.85rem;
  line-height: 1;
  font-weight: 700;
}
.slider-info:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* The popover. Hidden until the trigger is hovered or focused. Wider than the
   label column, so it overlays the slider area (high z-index). Scrolls
   internally if a rationale + long source list overflow the max height. */
.rationale-tip {
  display: none;
  position: absolute;
  top: 1.5em;
  left: 0;
  z-index: 50;
  width: 300px;
  max-width: 78vw;
  max-height: 320px;
  overflow-y: auto;
  padding: 0.7rem 0.85rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.5;
  text-align: left;
  white-space: normal;
  cursor: auto;
}
.slider-info:hover .rationale-tip,
.slider-info:focus .rationale-tip,
.slider-info:focus-within .rationale-tip {
  display: block;
}
.rationale-tip > strong {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--accent-strong);
}
.rationale-tip .rt-info {
  color: var(--text-muted);
}
.rationale-tip .rt-model {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.rationale-tip .rt-proposed {
  margin-bottom: 0.25rem;
}
.rationale-tip .rt-text {
  margin-bottom: 0.4rem;
}
.rationale-tip .src {
  font-size: 0.74rem;
  color: var(--text-muted);
}
.rationale-tip .src-heading {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.2rem;
}
.rationale-tip .src ul {
  margin: 0;
  padding-left: 1.1rem;
}
.rationale-tip .src li {
  margin: 0.15rem 0;
  word-break: break-word;
}
.rationale-tip .src a {
  color: var(--accent);
}
