/*
 * 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;
}

.account-email {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* 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;
}

/* === 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;
}

/* === Login card ========================================================== */

.login-card {
  max-width: 380px;
  margin: 3rem auto;
}

.card-title {
  margin: 0;
}

.login-card .card-title {
  margin-bottom: 0.75rem;
}

#loginForm button[type="submit"] {
  width: 100%;
  margin-top: 1rem;
}

/* === 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;
}

.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;
}

/* === 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);
}

/* === 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;
}

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

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

.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;
  }
}
