/* paved-road-ai incident viewer. Shared ops-console tokens; accent is amber. */
:root {
  --bg: #0b0d10;
  --surface: #12161b;
  --raised: #171c23;
  --border: #232a33;
  --text: #e6e9ee;
  --muted: #8b95a3;
  --ok: #3ddc97;
  --bad: #ff6b6b;
  --warn: #f5a524;
  --accent: #f5a524;
  --accent-soft: rgba(245, 165, 36, 0.12);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;

  /* 8px grid */
  --s1: 4px;
  --s2: 8px;
  --s3: 16px;
  --s4: 24px;
  --s5: 32px;
  --s6: 48px;
  --radius: 10px;
  --rail-x: 11px; /* x position of the investigation rail line */
}

* { box-sizing: border-box; }

html, body { margin: 0; background: var(--bg); color: var(--text); }

body {
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

code, pre, .mono { font-family: var(--mono); }
h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0; }
button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.skip {
  position: absolute;
  left: var(--s3);
  top: -48px;
  background: var(--accent);
  color: var(--bg);
  padding: var(--s2) var(--s3);
  border-radius: 6px;
  z-index: 10;
}
.skip:focus { top: var(--s2); }

.muted { color: var(--muted); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- header ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; min-width: 0; }
.brand-name { font: 600 16px/1.2 var(--mono); letter-spacing: -0.01em; white-space: nowrap; }
.brand-name::before { content: "▍"; color: var(--accent); margin-right: 2px; }
.tagline { color: var(--muted); font-size: 13px; }

.mode {
  flex: none;
  font: 500 12px/1 var(--mono);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.mode[data-mode="demo"] { color: var(--accent); border-color: rgba(245, 165, 36, 0.45); background: var(--accent-soft); }
.mode[data-mode="live"]::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--ok);
  vertical-align: 1px;
}

/* ---------- layout ---------- */

.shell {
  flex: 1;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 0;
}

.rail {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.rail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: var(--s3) var(--s3) var(--s2);
}
.rail-title { font-size: 13px; color: var(--muted); font-weight: 500; }
.rail-status { font: 12px var(--mono); color: var(--muted); }
.rail-status[data-state="error"] { color: var(--bad); }

.reports {
  list-style: none;
  margin: 0;
  padding: 0 var(--s2) var(--s2);
  overflow-y: auto;
  flex: 1;
}

.report-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s1) var(--s2);
  text-align: left;
  padding: 10px 12px;
  margin-bottom: var(--s1);
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  position: relative;
}
.report-item:hover { background: var(--raised); }
.report-item[aria-current="true"] { background: var(--raised); border-color: var(--border); }
.report-item[aria-current="true"]::before {
  content: "";
  position: absolute;
  left: -1px; top: 10px; bottom: 10px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.item-alert {
  font: 600 13px/1.35 var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-meta {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: var(--s2);
  font: 12px var(--mono);
  color: var(--muted);
}
.item-ns { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-warn { color: var(--warn); }

.readonly {
  margin: 0;
  padding: var(--s3);
  border-top: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  display: flex;
  gap: var(--s2);
}
.readonly-mark {
  flex: none;
  width: 10px; height: 10px;
  margin-top: 4px;
  border: 1.5px solid var(--ok);
  border-radius: 2px;
  position: relative;
}
.readonly-mark::before {
  content: "";
  position: absolute;
  left: 1px; right: 1px; top: -6px; height: 6px;
  border: 1.5px solid var(--ok);
  border-bottom: 0;
  border-radius: 4px 4px 0 0;
}

/* ---------- confidence pill ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  font: 500 11px/1 var(--mono);
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid;
  white-space: nowrap;
  height: fit-content;
}
.pill[data-c="high"] { color: var(--ok); border-color: rgba(61, 220, 151, 0.4); background: rgba(61, 220, 151, 0.08); }
.pill[data-c="medium"] { color: var(--warn); border-color: rgba(245, 165, 36, 0.4); background: rgba(245, 165, 36, 0.08); }
.pill[data-c="low"] { color: var(--muted); border-color: rgba(255, 107, 107, 0.55); background: none; }

/* ---------- detail ---------- */

.detail {
  padding: var(--s5) var(--s5) var(--s6);
  min-width: 0;
  overflow-y: auto;
}
.detail:focus { outline: none; }
.placeholder { color: var(--muted); }

.report { max-width: 1120px; }

.report-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2) var(--s3);
}
.report-alert { font: 600 20px/1.3 var(--mono); letter-spacing: -0.01em; overflow-wrap: anywhere; }
.report-ns {
  font: 13px var(--mono);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
}
.report-meta {
  margin-top: var(--s2);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1) var(--s3);
  font: 12px var(--mono);
  color: var(--muted);
}
.report-meta b { font-weight: 500; color: var(--text); }

.stop-warn {
  margin-top: var(--s3);
  padding: 10px 12px;
  border: 1px solid rgba(245, 165, 36, 0.45);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 13px;
}
.stop-warn strong { color: var(--warn); font-weight: 600; }

.verdict {
  margin-top: var(--s4);
  padding: var(--s3) var(--s4) var(--s3) calc(var(--s4) - 2px);
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.verdict[data-c="high"] { border-left-color: var(--ok); }
.verdict[data-c="low"] { border-left-color: var(--bad); }
.verdict-label { font-size: 12px; color: var(--muted); margin-bottom: var(--s1); }
.root-cause {
  font-size: 19px;
  line-height: 1.45;
  font-weight: 500;
  max-width: 68ch;
  text-wrap: pretty;
}
.summary {
  margin-top: var(--s3);
  color: var(--muted);
  max-width: 72ch;
}

.columns {
  margin-top: var(--s5);
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  grid-template-areas: "timeline side";
  gap: var(--s5);
  align-items: start;
}
.side { grid-area: side; display: grid; gap: var(--s4); }
.timeline-card { grid-area: timeline; }

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: var(--s3) var(--s3) var(--s3);
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s2);
  margin-bottom: var(--s3);
}
.card-title { font-size: 14px; }
.card-note { font-size: 12px; color: var(--muted); }

/* next steps checklist */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.step label {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  cursor: pointer;
  padding: 6px 8px;
  margin: 0 -8px;
  border-radius: 6px;
}
.step label:hover { background: var(--raised); }
.step input {
  appearance: none;
  width: 16px; height: 16px;
  margin: 2px 0 0;
  border: 1.5px solid var(--muted);
  border-radius: 4px;
  display: grid;
  place-content: center;
  cursor: pointer;
}
.step input::before {
  content: "";
  width: 8px; height: 4px;
  border-left: 2px solid var(--bg);
  border-bottom: 2px solid var(--bg);
  transform: rotate(-45deg) translate(1px, -1px);
  opacity: 0;
}
.step input:checked { background: var(--ok); border-color: var(--ok); }
.step input:checked::before { opacity: 1; }
.step input:checked + span { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(139, 149, 163, 0.6); }
.step input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.step span { overflow-wrap: anywhere; }

/* evidence */
.evidence { display: grid; gap: var(--s3); }
.ev-group h3 { margin-bottom: 6px; }
.ev-source {
  font: 500 12px var(--mono);
  color: var(--accent);
  background: none;
  border: 0;
  padding: 2px 0;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
}
.ev-source:hover { text-decoration-color: currentColor; }
.ev-source[disabled] { color: var(--muted); cursor: default; text-decoration: none; }
.ev-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.ev-list li {
  padding-left: var(--s3);
  position: relative;
  font-size: 13px;
  overflow-wrap: anywhere;
}
.ev-list li::before {
  content: "";
  position: absolute;
  left: 2px; top: 0.65em;
  width: 6px; height: 1px;
  background: var(--muted);
}

/* ---------- investigation timeline (the showcase) ---------- */

.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before {
  content: "";
  position: absolute;
  left: var(--rail-x);
  top: 12px;
  bottom: 14px;
  width: 1px;
  background: var(--border);
}

.turn { position: relative; padding-left: 36px; padding-bottom: var(--s3); }
.turn-node {
  position: absolute;
  left: calc(var(--rail-x) - 11px);
  top: 0;
  width: 23px; height: 23px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--raised);
  display: grid;
  place-content: center;
  font: 600 11px/1 var(--mono);
  color: var(--text);
}
.turn-head {
  font-size: 12px;
  color: var(--muted);
  min-height: 23px;
  display: flex;
  align-items: center;
  margin-bottom: 6px;
}
.turn-head b { color: var(--text); font-weight: 500; }

.calls { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; position: relative; }
/* parallel calls hang off a short bracket */
.calls[data-parallel="true"]::before {
  content: "";
  position: absolute;
  left: -14px; top: 14px; bottom: 14px;
  width: 8px;
  border: 1px solid var(--border);
  border-right: 0;
  border-radius: 6px 0 0 6px;
}

.call {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.call[data-error="true"] { border-color: rgba(255, 107, 107, 0.45); }
.call[data-flash="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.call-toggle {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px var(--s2);
  padding: 8px 10px;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
  border-radius: 8px;
}
.call-toggle:hover { background: var(--surface); }
.call-line { display: flex; gap: var(--s2); align-items: baseline; min-width: 0; font: 12.5px/1.45 var(--mono); }
.call-name { color: var(--accent); font-weight: 600; flex: none; }
.call[data-error="true"] .call-name { color: var(--bad); }
.call-args { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.call-size { font: 11px var(--mono); color: var(--muted); white-space: nowrap; align-self: center; }
.call-size .err { color: var(--bad); }
.call-preview {
  grid-column: 1 / -1;
  font: 12px/1.45 var(--mono);
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.call-preview::before { content: "← " / ""; color: var(--muted); }
.call-toggle[aria-expanded="true"] .call-preview { display: none; }

.call-body { padding: 0 10px 10px; display: grid; gap: var(--s2); }
.call-body[hidden] { display: none; }
.kv { font: 12px var(--mono); color: var(--muted); }
.out {
  margin: 0;
  max-height: 320px;
  overflow: auto;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font: 12px/1.5 var(--mono);
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.out-note { font: 11px var(--mono); color: var(--muted); }

.spark { display: flex; align-items: center; gap: var(--s2); font: 11px var(--mono); color: var(--muted); }
.spark svg { display: block; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark circle { fill: var(--accent); }

.turn-end { padding-bottom: 0; }
.turn-end .turn-node { border-color: rgba(61, 220, 151, 0.5); color: var(--ok); }
.turn-end[data-stop="warn"] .turn-node { border-color: rgba(245, 165, 36, 0.6); color: var(--warn); }
.end-line { font: 12.5px var(--mono); gap: var(--s2); flex-wrap: wrap; }
.end-line .ok { color: var(--ok); font-weight: 600; }
.end-line .warn { color: var(--warn); font-weight: 600; }

.no-calls { font-size: 13px; color: var(--muted); }

/* one orchestrated moment: the investigation steps arrive in order when a report opens */
@media (prefers-reduced-motion: no-preference) {
  .report[data-enter="true"] .turn {
    animation: step-in 280ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
    animation-delay: calc(var(--i, 0) * 70ms);
  }
  @keyframes step-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------- empty / error ---------- */

.empty { max-width: 60ch; display: grid; gap: var(--s3); padding-top: var(--s4); }
.empty-title { font-size: 20px; }
.code {
  margin: 0;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font: 13px/1.6 var(--mono);
  overflow-x: auto;
}
.empty code:not(pre code) {
  font-size: 12.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--raised);
  border: 1px solid var(--border);
}
.rail-empty { padding: var(--s2) 12px; font-size: 13px; color: var(--muted); }

/* ---------- responsive ---------- */

/* Desktop: the page is fixed and the two panes scroll on their own. */
@media (min-width: 861px) {
  body { height: 100vh; overflow: hidden; }
}

@media (max-width: 1180px) {
  .columns { grid-template-columns: minmax(0, 1fr); grid-template-areas: "side" "timeline"; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { border-right: 0; border-bottom: 1px solid var(--border); }
  .reports { max-height: 36vh; flex: none; }
  .detail { padding: var(--s4) var(--s3) var(--s5); overflow: visible; }
  .top { padding: 12px var(--s3); align-items: flex-start; flex-wrap: wrap; }
  .tagline { display: block; font-size: 12px; }
  .brand { gap: 2px var(--s3); }
}

@media (max-width: 480px) {
  .root-cause { font-size: 17px; }
  .verdict { padding: 12px 14px 12px 13px; }
  .report-alert { font-size: 17px; }
  .card { padding: 12px; }
  .turn { padding-left: 32px; }
  .call-size { display: none; }
}
