/* IncidentPilot UI.
   Built like an on-call tool: grey surfaces, hairlines, and one amber accent that means "a human is needed".
   Colour is kept for meaning: green = backed by evidence or recovered, red = not backed, blocked or failed.
   The signature detail is the evidence tag (E1, E2 ...): a small keycap that links a claim to its proof.
   Every value sits on a 4px grid. Every colour is a token, so dark mode only redefines the tokens. */

:root {
  color-scheme: light;
  --bg: #fafafa;
  --side: #f4f4f5;
  --card: #ffffff;
  --raised: #f4f4f5;
  --hover: #ebebec;
  --text: #171717;
  --text-2: #525252;
  --text-3: #737373;
  --line: rgba(23, 23, 23, 0.08);
  --line-strong: rgba(23, 23, 23, 0.14);
  --accent: #f5a524;
  --accent-ink: #9a5b06;      /* the accent as text on a light surface */
  --on-accent: #1f1503;
  --pos: #16a34a;
  --neg: #dc2626;
  --neg-bg: rgba(220, 38, 38, 0.06);
  --btn-bg: #171717;
  --btn-ink: #ffffff;
  --font: "Geist", -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141415;
    --side: #0f0f10;
    --card: #19191b;
    --raised: #232325;
    --hover: #2b2b2e;
    --text: #ededed;
    --text-2: #a1a1a6;
    --text-3: #85858b;
    --line: rgba(237, 237, 237, 0.08);
    --line-strong: rgba(237, 237, 237, 0.14);
    --accent-ink: #f5a524;
    --pos: #4cc38a;
    --neg: #e5484d;
    --neg-bg: rgba(229, 72, 77, 0.08);
    --btn-bg: #ededed;
    --btn-ink: #141415;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 20px;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }

.icon { width: 16px; height: 16px; flex: none; }

/* ---------- app shell ---------- */

.app {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 20px 12px;
  background: var(--side);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  height: 32px;
  padding: 0 8px;
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
}

.side h2,
.model label {
  padding: 0 8px;
  margin-bottom: 8px;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  color: var(--text-3);
}

.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }

.nav-row {
  width: 100%;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  text-align: left;
  cursor: pointer;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.nav-row:hover { background: var(--hover); color: var(--text); }
.nav-row.active { background: var(--card); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }
.nav-row:disabled { opacity: 0.5; cursor: default; }
.nav-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-row .meta { font-family: var(--mono); font-size: 12px; line-height: 16px; color: var(--text-3); }
.nav-row .icon { color: var(--text-3); opacity: 0; transition: opacity 150ms var(--ease); }
.nav-row:hover .icon { opacity: 1; }

.quiet { padding: 0 8px; font-size: 13px; color: var(--text-3); }

.model { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.model label { margin-bottom: 0; }
.own-key { display: flex; flex-direction: column; gap: 8px; }
.note { padding: 0 8px; font-size: 12px; line-height: 16px; color: var(--text-3); }
.note a { color: var(--text-2); }

select, input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--card);
}
input::placeholder { color: var(--text-3); }
input:focus, select:focus, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- status dot ---------- */

.dot { width: 8px; height: 8px; border-radius: 4px; flex: none; background: var(--text-3); }
.dot.running { background: var(--text); animation: live 1.6s var(--ease) infinite; }
.dot.waiting_approval { background: var(--accent); }
.dot.resolved { background: var(--pos); }
.dot.error { background: var(--neg); }
.dot.escalated { background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-3); }
@keyframes live { 50% { opacity: 0.3; } }

/* ---------- main column ---------- */

.main { min-width: 0; max-width: 1336px; padding: 32px; }

.head { display: flex; flex-direction: column; gap: 8px; max-width: 760px; margin-bottom: 24px; }
.head h1 { font-size: 28px; line-height: 36px; font-weight: 500; letter-spacing: -0.01em; }
.lede { font-size: 15px; line-height: 24px; color: var(--text-2); }

.meta-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 16px;
  color: var(--text-3);
}
.meta-line .state { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.meta-line a { color: var(--text-2); }

/* the five steps, as one segmented line */
.steps {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}
.step { display: flex; flex-direction: column; gap: 4px; padding-top: 12px; border-top: 2px solid var(--line-strong); }
.step b { display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 500; color: var(--text-3); }
.step span { font-size: 12px; line-height: 16px; color: var(--text-3); }
.step.done { border-top-color: var(--text-2); }
.step.done b, .step.now b, .step.wait b { color: var(--text); }
.step.now { border-top-color: var(--text); }
.step.wait { border-top-color: var(--accent); }
.step.fail { border-top-color: var(--neg); }
.step.fail b { color: var(--neg); }
.step .icon { width: 14px; height: 14px; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.panel { padding: 20px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.panel h2 { font-size: 15px; line-height: 20px; font-weight: 500; }
.panel-head .meta { font-family: var(--mono); font-size: 12px; line-height: 16px; color: var(--text-3); }
.empty { color: var(--text-3); font-size: 13px; }

/* ---------- what is happening now ---------- */

.status { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
.status-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 500; }
.status p { color: var(--text-2); }
.status.waiting { border-color: var(--line-strong); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06); }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-top: 1px solid var(--line); }
.rows .k { color: var(--text-2); }
.rows .v { font-family: var(--mono); font-size: 13px; text-align: right; overflow-wrap: anywhere; }
.rows .v.ok { color: var(--pos); }
.rows .v.bad { color: var(--neg); }

.decide { display: grid; grid-template-columns: 180px minmax(0, 1fr) auto auto; gap: 8px; }

.btn {
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--raised);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 150ms var(--ease), transform 120ms var(--ease);
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--btn-bg); color: var(--btn-ink); border-color: transparent; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12); }
.btn.primary:hover { background: var(--btn-bg); opacity: 0.88; }

/* ---------- the root cause and its proof ---------- */

.root { margin-bottom: 20px; font-size: 20px; line-height: 28px; font-weight: 500; }
.root.unsure { color: var(--text-2); }

.figures { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.figure-label { font-size: 12px; line-height: 16px; color: var(--text-3); }
.figure-num { margin-top: 4px; font-size: 28px; line-height: 32px; font-weight: 500; }
.figure-num small { font-size: 15px; font-weight: 400; color: var(--text-3); }
.figure-sub { margin-top: 4px; font-family: var(--mono); font-size: 12px; line-height: 16px; color: var(--text-3); }

.proofbar { display: flex; gap: 4px; margin-bottom: 8px; }
.proofbar i { flex: 1; height: 8px; border-radius: 4px; background: var(--pos); }
.proofbar i.no { background: var(--neg); }

.claims { list-style: none; margin: 0; padding: 0; }
.claims li {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.claims .icon { margin-top: 2px; color: var(--pos); }
.claims li.no .icon { color: var(--neg); }
.missing { display: block; margin-top: 4px; font-size: 13px; color: var(--neg); }
.explain { margin-top: 12px; font-size: 13px; color: var(--text-3); }

/* the signature: evidence tags */
.tags { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.tag {
  min-width: 28px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--raised);
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.tag:hover { background: var(--hover); color: var(--text); }
span.tag { display: inline-flex; align-items: center; justify-content: center; cursor: default; }

/* ---------- evidence ---------- */

.evidence { list-style: none; margin: 0; padding: 0; }
.ev {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  margin: 0 -12px;
  border-radius: 8px;
  scroll-margin: 96px;
  transition: background-color 300ms var(--ease);
}
.ev + .ev { border-top: 1px solid var(--line); border-radius: 0; }
.ev.lit { background: var(--raised); border-radius: 8px; }
.ev.lit .tag { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.ev-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ev-tool { font-family: var(--mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-src { margin-left: auto; font-size: 12px; line-height: 16px; color: var(--text-3); white-space: nowrap; }
.ev-sum { font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; }
.flag { font-size: 12px; line-height: 16px; color: var(--neg); }

.quarantine { padding: 8px 12px; border-radius: 8px; background: var(--neg-bg); font-size: 13px; }
.quarantine b { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--neg); }
.quarantine code { display: block; margin-top: 4px; font-family: var(--mono); font-size: 12px; line-height: 16px; color: var(--text-2); overflow-wrap: anywhere; }

details summary { list-style: none; cursor: pointer; }
details summary::-webkit-details-marker { display: none; }
details .chev { transition: transform 150ms var(--ease); color: var(--text-3); }
details[open] > summary .chev { transform: rotate(90deg); }
.raw summary { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; line-height: 16px; color: var(--text-3); }
.raw summary .icon { width: 14px; height: 14px; }
pre {
  margin: 8px 0 0;
  padding: 12px;
  max-height: 320px;
  overflow: auto;
  border-radius: 8px;
  background: var(--side);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 16px;
}

/* ---------- agent log ---------- */

.log-panel > summary { display: flex; align-items: center; gap: 8px; }
.log-panel > summary h2 { flex: 1; }
.log-panel > summary .meta { font-family: var(--mono); font-size: 12px; line-height: 16px; color: var(--text-3); }
.log { list-style: none; margin: 12px 0 0; padding: 0; }
.log li {
  display: grid;
  grid-template-columns: 64px 80px minmax(0, 1fr);
  gap: 12px;
  padding: 4px 0;
  font-size: 13px;
}
.log .when, .log .what { font-family: var(--mono); font-size: 12px; color: var(--text-3); }
.log .msg { color: var(--text-2); overflow-wrap: anywhere; }

/* ---------- start page ---------- */

.runs { list-style: none; margin: 0; padding: 0; }
.run {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 16px 0;
  border-top: 1px solid var(--line);
}
.run:first-child { border-top: 0; padding-top: 4px; }
.run-service { font-family: var(--mono); font-size: 13px; color: var(--text-2); }
.run-title { display: block; font-weight: 500; }
.run-tests { display: block; margin-top: 4px; font-size: 13px; color: var(--text-2); }

.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: flex; flex-direction: column; gap: 4px; padding: 12px 0; border-top: 1px solid var(--line); }
.checks li:first-child { border-top: 0; padding-top: 4px; }
.checks b { font-weight: 500; }
.checks span { font-size: 13px; color: var(--text-2); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--btn-ink);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  animation: rise 300ms var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- smaller screens ---------- */

@media (max-width: 1240px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; padding: 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side-group.scenarios { display: none; }          /* the start page lists them, with a Run button each */
  .recent .nav li:nth-child(n+4) { display: none; }
  .main { padding: 24px 16px; }
  .head h1 { font-size: 24px; line-height: 32px; }
  .steps span, .step .icon { display: none; }
  .step b { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .decide { grid-template-columns: minmax(0, 1fr); }
  .root { font-size: 18px; line-height: 26px; }
  .claims li { grid-template-columns: 16px minmax(0, 1fr); }
  .claims .tags { grid-column: 2; justify-content: flex-start; }
  .run { grid-template-columns: minmax(0, 1fr) auto; }
  .run-service { grid-column: 1 / -1; }
  .log li { grid-template-columns: 64px minmax(0, 1fr); }
  .log .what { display: none; }
}
