:root {
  --bg: #eef2f5;
  --surface: #fff;
  --soft: #f7f9fb;
  --line: #d7dee6;
  --text: #17212b;
  --muted: #5f6f7f;
  --rail: #20313c;
  --brand: #116a7b;
  --brand-dark: #0a4d5a;
  --ok: #227a4d;
  --warn: #a15c07;
  --danger: #b42318;
  --shadow: 0 14px 32px rgba(23, 33, 43, 0.08);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: Arial, Helvetica, sans-serif; }
button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }

.app-shell { display: grid; grid-template-columns: 320px minmax(0, 1fr); min-height: 100vh; }
.scenario-rail { background: var(--rail); color: #f8fbfd; padding: 24px 18px; overflow-y: auto; }
.brand-block h1, .topbar h2, .debrief-panel h3 { margin: 0; }
.brand-block h1 { font-size: 1.4rem; line-height: 1.25; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0; }
.scenario-rail .eyebrow { color: #a8c3cf; }

.library-picker, .search-box { display: grid; gap: 8px; color: #cfe2ea; font-size: .82rem; font-weight: 800; }
.library-picker { margin: 26px 0 14px; }
.search-box { margin: 0 0 18px; }
.library-picker select, .search-box input, .controls-band input, .time-grid input, .time-grid select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); padding: 10px 12px;
}
.library-picker select { border-color: #7fb4c2; background: #eef7fb; font-weight: 800; }
.search-box input { border-color: #4d6674; background: #172733; color: #fff; }

.scenario-list { display: grid; gap: 8px; }
.scenario-item, .empty-library {
  display: grid; gap: 4px; width: 100%; border: 1px solid transparent; border-radius: 8px;
  background: rgba(255,255,255,.06); color: #eef7fb; padding: 12px; text-align: left;
}
.scenario-item:hover, .scenario-item.active { border-color: #7fb4c2; background: rgba(255,255,255,.13); }
.scenario-item span, .empty-library span { color: #bfd2db; font-size: .78rem; }
.empty-library { border-style: dashed; }

.workspace { padding: 24px; overflow: auto; }
.topbar, .summary-grid, .controls-band, .debrief-panel { margin-bottom: 18px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.topbar h2 { font-size: 1.8rem; line-height: 1.2; }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; }
.user-badge { font-size: .82rem; font-weight: 800; color: var(--muted); white-space: nowrap; padding: 0 4px; }
.primary, .secondary, .status-btn, .small-action { border-radius: 6px; min-height: 38px; padding: 9px 12px; font-weight: 800; }
.primary { background: var(--brand); color: #fff; }
.secondary, .small-action { border: 1px solid var(--line); background: #fff; color: var(--text); }

.summary-grid { display: grid; grid-template-columns: minmax(220px,.7fr) minmax(360px,1.4fr) minmax(240px,.8fr); gap: 14px; }
.score-panel, .meta-panel, .risk-panel, .controls-band, .prp-card, .debrief-panel {
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow);
}
.score-panel, .meta-panel, .risk-panel { padding: 16px; }
.score-panel strong { display: block; font-size: 2.4rem; line-height: 1; }
meter { width: 100%; height: 12px; margin: 14px 0 8px; }
.meta-panel dl { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px 14px; margin: 0; }
.meta-panel dt { color: var(--muted); font-size: .72rem; font-weight: 800; text-transform: uppercase; }
.meta-panel dd { margin: 2px 0 0; font-size: .9rem; }
.risk-panel ul { margin: 0; display: grid; gap: 8px; padding-left: 18px; }
.risk-panel li { color: var(--danger); font-size: .88rem; }

.controls-band { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; padding: 14px; }
.controls-band label { display: grid; gap: 6px; color: var(--muted); font-size: .78rem; font-weight: 800; text-transform: uppercase; }
.prp-tabs { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; padding-bottom: 4px; }
.prp-tab { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--text); padding: 9px 12px; font-weight: 800; }
.prp-tab.active { border-color: var(--brand); background: var(--brand); color: #fff; }

.prp-card { overflow: hidden; }
.prp-header { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 18px; padding: 18px; background: var(--soft); border-bottom: 1px solid var(--line); }
.prp-header h3 { margin: 0 0 10px; font-size: 1.25rem; }
.cue-grid { display: grid; gap: 10px; }
.cue-grid p { margin: 0; color: var(--muted); line-height: 1.45; }
.prp-score { min-width: 150px; text-align: right; }
.prp-score strong { display: block; color: var(--brand-dark); font-size: 2rem; }

.trajectory-panel, .timing-metrics, .prp-comment-panel { border-bottom: 1px solid var(--line); padding: 18px; }
.trajectory-header { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.trajectory-header h4 { margin: 0; font-size: 1rem; }
.trajectory-legend { display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); font-size: .78rem; font-weight: 800; }
.trajectory-legend span { display: inline-flex; align-items: center; gap: 5px; }
.trajectory-legend b { display: inline-block; width: 22px; height: 4px; border-radius: 999px; }
.legend-full { background: var(--ok); } .legend-partial { background: var(--warn); } .legend-failed { background: var(--danger); }
.chart-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.trajectory-chart { display: block; min-width: 880px; width: 100%; height: auto; }
.axis { stroke: #657789; stroke-width: 1.5; }
.gridline { stroke: #dce3ea; stroke-width: 1; }
.axis-label, .trajectory-label { fill: var(--muted); font-size: 12px; }
.trajectory-line { fill: none; stroke: var(--brand); stroke-width: 2; stroke-dasharray: 5 4; }
.expected-window { stroke: #9aa9b6; stroke-width: 4; stroke-linecap: round; opacity: .45; }
.trajectory-segment { stroke: var(--ok); stroke-width: 9; stroke-linecap: round; fill: var(--danger); }
.trajectory-segment.partial { stroke: var(--warn); }
.trajectory-segment.failed, .trajectory-segment.omitted, .trajectory-segment.unsafe { stroke: var(--danger); }
.trajectory-marker { fill: #fff; font-size: 12px; font-weight: 800; }

.timing-metrics { display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); gap: 10px; background: var(--soft); }
.timing-metrics > div { border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 10px; }
.timing-metrics strong { display: block; font-size: 1rem; }
.component { padding: 18px; border-top: 1px solid var(--line); }
.component:first-of-type { border-top: 0; }
.component-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.component-header h4 { margin: 0; font-size: 1rem; }
.component-score { color: var(--brand-dark); font-weight: 800; }
.behavior-list { display: grid; gap: 10px; }
.behavior-row { display: grid; grid-template-columns: 1fr; gap: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fff; }
.behavior-main { display: grid; gap: 8px; min-width: 0; }
.behavior-main > strong { display: block; max-width: 100%; line-height: 1.4; overflow-wrap: anywhere; }
.behavior-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { border-radius: 999px; background: #ecf1f4; color: var(--muted); padding: 4px 8px; font-size: .72rem; font-weight: 800; }
.pill.critical { background: #fde8e7; color: var(--danger); }
.pill.major { background: #fff0d9; color: var(--warn); }
.pill.minor { background: #e8f4ee; color: var(--ok); }
.time-grid { display: grid; grid-template-columns: repeat(4,minmax(120px,1fr)); gap: 8px; margin-top: 4px; }
.time-grid label { display: grid; gap: 4px; color: var(--muted); font-size: .72rem; font-weight: 800; text-transform: uppercase; }
.time-grid input, .time-grid select { min-height: 36px; padding: 8px 9px; font-size: .85rem; }
.time-grid input:required:placeholder-shown { border-color: #df9d45; background: #fff9ef; }
.time-hint { margin: 0; color: var(--muted); font-size: .78rem; }
.status-group { display: grid; grid-template-columns: repeat(4,minmax(96px,1fr)); gap: 8px; align-content: start; width: 100%; }
.status-btn { border: 1px solid var(--line); background: #f8fafb; color: var(--text); padding: 8px 6px; font-size: .78rem; white-space: nowrap; }
.status-btn.active[data-status="FULL"] { border-color: var(--ok); background: #e8f4ee; color: #155c38; }
.status-btn.active[data-status="PARTIAL"] { border-color: var(--warn); background: #fff0d9; color: #7a4303; }
.status-btn.active[data-status="FAILED"], .status-btn.active[data-status="OMITTED"] { border-color: var(--danger); background: #fde8e7; color: #8f1d14; }
.condition-list { margin: 14px 0 0; padding: 12px; border-top: 1px solid var(--line); background: var(--soft); }
.condition-list h4 { margin: 0 0 8px; }
.condition-list ul { margin: 0; padding-left: 18px; color: var(--muted); }
.prp-comment-panel { display: grid; gap: 10px; background: #fff; }
.prp-comment-panel h4 { margin: 0; }
.prp-comment-panel textarea { min-height: 96px; resize: vertical; }
.debrief-panel { display: grid; gap: 12px; padding: 18px; }
.generated-debrief { display: grid; gap: 8px; color: var(--muted); font-size: .92rem; }
.generated-debrief p { margin: 0; }

.report-modal {
  position: fixed; inset: 0; z-index: 20; display: none; background: rgba(23,33,43,.56);
  padding: 24px; overflow: auto;
}
.report-modal.open { display: block; }
.report-shell {
  max-width: 1120px; margin: 0 auto; border-radius: 8px; background: #fff; box-shadow: 0 24px 60px rgba(0,0,0,.24);
}
.report-toolbar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 18px; border-bottom: 1px solid var(--line); background: #fff; border-radius: 8px 8px 0 0;
}
.report-toolbar h2 { margin: 0; }
.report-content { padding: 22px; }
.simulation-report { display: grid; gap: 18px; color: var(--text); }
.report-hero {
  display: flex; justify-content: space-between; gap: 18px; align-items: flex-start;
  padding-bottom: 14px; border-bottom: 2px solid var(--brand);
}
.report-hero h1 { margin: 0; font-size: 1.75rem; }
.report-score { min-width: 150px; text-align: right; }
.report-score span { display: block; color: var(--muted); font-size: .78rem; font-weight: 800; text-transform: uppercase; }
.report-score strong { display: block; color: var(--brand-dark); font-size: 2rem; }
.report-section {
  border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 14px; break-inside: avoid;
}
.report-section h3 { margin: 0 0 12px; }
.report-fields {
  display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px 14px; margin: 0;
}
.report-fields dt, .report-metric-grid span, .report-kpis span {
  color: var(--muted); font-size: .72rem; font-weight: 800; text-transform: uppercase;
}
.report-fields dd { margin: 2px 0 0; }
.report-kpis, .report-metric-grid {
  display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 10px;
}
.report-kpis div, .report-metric-grid div {
  border: 1px solid var(--line); border-radius: 8px; background: var(--soft); padding: 10px;
}
.report-kpis strong, .report-metric-grid strong { display: block; margin-top: 3px; font-size: 1.05rem; }
.report-prp { display: grid; gap: 12px; }
.report-prp-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.report-prp-header h3 { margin: 0; }
.report-prp-header > strong { color: var(--brand-dark); }
.report-graph {
  width: 100%; max-height: 170px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.report-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.report-table th, .report-table td { border-bottom: 1px solid var(--line); padding: 8px; text-align: left; vertical-align: top; }
.report-table th { color: var(--muted); font-size: .72rem; text-transform: uppercase; }
.report-comment-block h4 { margin: 0 0 6px; }
.report-comment {
  margin: 0; min-height: 38px; white-space: pre-wrap; color: var(--text); background: var(--soft);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px;
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .scenario-rail { max-height: 360px; }
  .summary-grid, .behavior-row { grid-template-columns: 1fr; }
  .timing-metrics { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 720px) {
  .workspace, .scenario-rail { padding: 16px; }
  .topbar, .prp-header, .component-header, .trajectory-header { display: grid; align-items: stretch; }
  .topbar-actions { justify-content: stretch; }
  .topbar-actions > * { flex: 1 1 auto; }
  .controls-band, .meta-panel dl, .status-group, .time-grid, .timing-metrics { grid-template-columns: 1fr; }
  .report-fields, .report-kpis, .report-metric-grid { grid-template-columns: 1fr; }
  .report-toolbar, .report-hero, .report-prp-header { display: grid; }
  .report-score { text-align: left; }
  .prp-header { grid-template-columns: 1fr; }
  .prp-score { text-align: left; }
}

/* ── Pages dropdown menu ──────────────────────────────────────────── */
.pages-menu { position: relative; display: inline-block; }
.pages-menu-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 50;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 28px rgba(23,33,43,.14); min-width: 190px; overflow: hidden;
}
.pages-menu-section {
  padding: 8px 14px 3px; color: var(--muted);
  font-size: .66rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
}
.pages-menu-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 14px; text-decoration: none; color: var(--text);
  font-size: .86rem; font-weight: 600;
}
.pages-menu-item:hover { background: var(--soft); }
.pages-menu-divider { border: none; border-top: 1px solid var(--line); margin: 4px 0; }
.pages-menu-badge {
  background: #e53935; color: #fff; border-radius: 999px;
  padding: 1px 7px; font-size: .68rem; font-weight: 800; line-height: 1.6; flex-shrink: 0;
}

@media print {
  body:has(.report-modal.open) .app-shell { display: none; }
  body:has(.report-modal.open) .report-modal { position: static; display: block; background: #fff; padding: 0; overflow: visible; }
  body:has(.report-modal.open) .report-shell { max-width: none; margin: 0; box-shadow: none; border-radius: 0; }
  body:has(.report-modal.open) .report-toolbar { position: static; padding: 0 0 12px; }
  body:has(.report-modal.open) .report-toolbar .topbar-actions { display: none; }
  body:has(.report-modal.open) .report-content { padding: 0; }
  .report-section { break-inside: avoid; }
}
