:root {
  --bg: #0b0d10;
  --panel: #12161c;
  --panel-2: #0d1116;
  --line: #2a3340;
  --text: #e6edf3;
  --muted: #8b9aab;
  --accent: #d4a017;
  --fail: #e85d4c;
  --run: #4aa3ff;
  --queue: #c9a227;
  --ok: #3cb371;
  --rec: #7dd3a8;
  --nav-h: 56px;
  --run-bar-h: 0px;
}
body.run-active { --run-bar-h: 40px; }

* { box-sizing: border-box; }

/* The UA rule for [hidden] is display:none at specificity (0,1,0), so any class
   selector that sets display -- .toolbar, .masthead, .token -- silently beats
   it. Without this, hiding the demo-token field or a section by setting
   el.hidden has no visible effect at all. */
[hidden] { display: none !important; }

html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.55 "Instrument Sans", ui-sans-serif, system-ui, sans-serif; }
code, pre, table, .token input, .mono { font-family: "IBM Plex Mono", ui-monospace, monospace; }
a { color: var(--accent); }

.masthead, section, .toolbar, .page-footer { max-width: 1280px; margin: 0 auto; padding: 20px 24px; }
.masthead, section, .toolbar, .page-footer, .query-panel { scroll-margin-top: calc(var(--nav-h) + var(--run-bar-h) + 10px); }

/* ------------------------------------------------------------- page nav */

.page-nav {
  position: sticky; top: 0; z-index: 40;
  background: rgba(11, 13, 16, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
/* Inner container on the same 1280px grid as the page, so the brand lines up
   with the section headings instead of floating out at the window edge. */
.nav-inner {
  max-width: 1280px; margin: 0 auto; padding: 0 24px;
  min-height: var(--nav-h);
  display: flex; align-items: center; gap: 20px; flex-wrap: nowrap;
}
.nav-brand {
  color: var(--accent); text-decoration: none; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase; font-size: 12px;
  flex: none;
}
/* Grows to absorb the free space, which keeps the run chips and the live pill
   pinned right without either needing an auto margin that would fight. */
.nav-links {
  list-style: none; margin: 0; padding: 0;
  display: flex; gap: 2px; flex: 1 1 auto; flex-wrap: nowrap; min-width: 0;
  overflow: hidden;
}
.nav-links a {
  display: block; color: var(--muted); text-decoration: none; font-size: 12.5px;
  padding: 7px 9px; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.nav-links a:hover { color: var(--text); }
.nav-links a.active { color: var(--text); border-bottom-color: var(--accent); }
.run-bar {
  position: sticky; top: var(--nav-h); z-index: 39;
  background: rgba(11, 13, 16, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.run-bar-inner {
  max-width: 1280px; margin: 0 auto; padding: 0 24px;
  min-height: 40px;
  display: flex; align-items: center; gap: 12px;
}
.run-elapsed { font-family: "IBM Plex Mono", monospace; color: var(--accent); font-size: 12px; flex: none; }
.run-status {
  color: var(--muted); font-size: 12.5px; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto;
}
.run-bar .cost-meter { flex: none; font-size: 12px; }
.run-stepper {
  list-style: none; margin: 0; padding: 0; display: flex; gap: 5px; flex: none;
}
.run-stepper li {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em;
  border: 1px solid var(--line); padding: 3px 7px; color: var(--muted);
  white-space: nowrap;
}
.run-stepper li.active { color: var(--text); border-color: var(--run); }
.run-stepper li.done { color: var(--rec); border-color: #1f4a35; }
/* The pill is the one thing allowed to truncate; the nav links never wrap. */
.page-nav .live-pill { padding: 6px 12px; font-size: 12px; min-width: 0; overflow: hidden; }
.page-nav #live-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.back-top {
  position: fixed; right: 22px; bottom: 22px; z-index: 30;
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  padding: 8px 12px; font-size: 12px; font-weight: 600;
}
.back-top:hover { border-color: var(--accent); }

/* ------------------------------------------------------------- masthead */

.masthead {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 24px;
  border-bottom: 1px solid var(--line); padding-top: 30px;
}
.eyebrow { margin: 0; color: var(--accent); letter-spacing: 0.14em; text-transform: uppercase; font-size: 11px; font-weight: 600; }
h1 { margin: 8px 0 0; font-size: 34px; font-weight: 600; letter-spacing: -0.03em; max-width: 20ch; line-height: 1.12; }
.lede { margin: 12px 0 0; color: var(--muted); max-width: 62ch; }
.meta { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
h2 { margin: 0 0 10px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600; }
h3 { margin: 22px 0 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.panel-lead, .waste-lead { margin: 0 0 12px; color: var(--muted); max-width: 92ch; }
.empty { color: var(--muted); font-style: italic; }
.dim { color: var(--muted); }
.small { font-size: 12px; }

.live-pill {
  display: flex; align-items: center; gap: 10px; white-space: nowrap;
  border: 1px solid var(--line); background: var(--panel-2); padding: 9px 14px;
  font-size: 13px; color: var(--muted); border-radius: 999px;
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.live-pill[data-state="live"] { border-color: #1f4a35; color: var(--text); }
.live-pill[data-state="live"] .live-dot { background: var(--ok); animation: pulse 2.4s ease-in-out infinite; }
.live-pill[data-state="off"] .live-dot { background: var(--fail); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ---------------------------------------------------------- scale strip */

.scale-strip {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1px;
  background: var(--line); border-bottom: 1px solid var(--line);
  max-width: none; padding: 0;
}
.scale-item { background: var(--bg); padding: 16px 24px; display: flex; flex-direction: column; gap: 2px; }
.scale-value { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; font-family: "IBM Plex Mono", monospace; }
.scale-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

/* ---------------------------------------------------------------- hero */

.hero { border-bottom: 1px solid var(--line); padding-bottom: 28px; }
.hero-head { display: flex; justify-content: space-between; gap: 32px; align-items: flex-start; flex-wrap: wrap; }
.hero-numbers { display: flex; gap: 28px; flex-wrap: wrap; }
.hero-stat { display: flex; flex-direction: column; gap: 2px; min-width: 120px; }
.hero-value { font-size: 44px; font-weight: 600; line-height: 1; letter-spacing: -0.04em; font-family: "IBM Plex Mono", monospace; }
.hero-stat.risk .hero-value { color: var(--fail); }
.hero-stat.save .hero-value { color: var(--rec); }
.hero-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; max-width: 22ch; }

.shot-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; margin-top: 22px; }
.shot-card { border: 1px solid var(--line); background: var(--panel-2); padding: 14px 16px; border-left-width: 3px; }
.shot-card.recoverable { border-left-color: var(--rec); }
.shot-card.lost { border-left-color: var(--fail); }
.shot-card header { display: flex; align-items: baseline; gap: 8px; }
.shot-show { font-weight: 600; letter-spacing: 0.04em; }
.shot-id { font-family: "IBM Plex Mono", monospace; color: var(--muted); }
.shot-priority { margin-left: auto; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); border: 1px solid var(--line); padding: 2px 6px; }
.shot-priority.hero { color: var(--accent); border-color: #4a3c10; }
.shot-countdown { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.shot-countdown strong { color: var(--text); font-size: 17px; font-family: "IBM Plex Mono", monospace; }
.shot-facts { display: flex; gap: 18px; margin: 12px 0 0; }
.shot-facts div { display: flex; flex-direction: column; gap: 1px; }
.shot-facts dt { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.shot-facts dd { margin: 0; font-family: "IBM Plex Mono", monospace; font-size: 15px; }
.shot-facts dd.bad { color: var(--fail); }
.shot-facts dd.good { color: var(--rec); }
.shot-verdict { margin: 12px 0 0; font-size: 12.5px; color: var(--muted); }

/* ------------------------------------------------------------- toolbar */

.toolbar { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
#status { color: var(--muted); }
button {
  background: var(--accent); color: #111; border: 0; padding: 10px 18px;
  font: inherit; font-weight: 600; cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: wait; }
.token { color: var(--muted); display: flex; gap: 8px; align-items: center; font-size: 13px; }
.token input { background: var(--panel); color: var(--text); border: 1px solid var(--line); padding: 8px 10px; width: 16rem; font-size: 13px; }
.cost-meter {
  margin-left: auto; font-size: 12.5px; color: var(--muted);
  border: 1px solid var(--line); background: var(--panel-2); padding: 7px 12px;
}
.cost-meter strong { color: var(--accent); }

/* ------------------------------------------------------------- impact */

.dashboard { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; }
.card { border: 1px solid var(--line); background: var(--panel); padding: 18px 20px; }
.impact-hero { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.impact-label { margin: 0; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }
.impact-usd { margin: 6px 0 0; font-size: 40px; font-weight: 600; line-height: 1; letter-spacing: -0.04em; color: var(--fail); font-family: "IBM Plex Mono", monospace; }
.impact-usd.after { color: var(--rec); }
.impact-sub { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); }
.impact-history { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.impact-history-usd { margin: 6px 0 0; font-size: 26px; font-weight: 600; letter-spacing: -0.03em; font-family: "IBM Plex Mono", monospace; }
.impact-history-unit { font-size: 13px; color: var(--muted); font-family: "Instrument Sans", sans-serif; font-weight: 400; }
.impact-note { margin: 16px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.5; }

.waste-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.waste-chip {
  display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: inherit;
  border: 1px solid var(--line); padding: 12px; background: var(--panel-2);
}
.waste-chip:hover { border-color: var(--accent); }
.waste-count { font-size: 28px; font-weight: 600; line-height: 1; letter-spacing: -0.03em; font-family: "IBM Plex Mono", monospace; }
.waste-name { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.waste-usd { font-size: 13px; color: var(--fail); margin-top: 4px; }
.waste-total { font-size: 11px; color: var(--muted); }

/* ------------------------------------------------------------ timeline */

.agent-timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline-empty { color: var(--muted); font-style: italic; }
.timeline-step { border: 1px solid var(--line); background: var(--panel-2); padding: 14px 16px; border-left-width: 3px; }
.timeline-step.sentinel { border-left-color: var(--run); }
.timeline-step.orchestrator { border-left-color: var(--accent); }
.timeline-step.action { border-left-color: var(--rec); }
.step-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.step-role { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); border: 1px solid var(--line); padding: 2px 7px; }
.step-agent { font-weight: 600; }
.step-pass { font-size: 11px; color: var(--muted); margin-left: auto; }
.step-text { margin: 10px 0 0; font-size: 14px; }
.step-text p { margin: 0 0 8px; }
.step-text ul { margin: 8px 0; padding-left: 20px; }
.step-text li { margin-bottom: 6px; }
.step-text code { background: #1a2230; padding: 1px 5px; font-size: 12.5px; }
.step-text strong { color: var(--text); }
.step-jobs { margin: 10px 0 0; display: flex; gap: 6px; flex-wrap: wrap; }
.step-jobs code { background: #1a2230; padding: 2px 7px; font-size: 12px; }
.pass-fold { margin-top: 8px; }
.pass-fold summary { cursor: pointer; font-size: 12.5px; color: var(--muted); }
.pass-fold[open] summary { margin-bottom: 8px; }

.mcp-evidence { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 18px; }
#mcp-calls { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#mcp-calls li { border: 1px solid var(--line); background: var(--panel-2); }
#mcp-calls summary {
  display: flex; gap: 12px; align-items: baseline; padding: 9px 14px;
  font-size: 12px; cursor: pointer;
}
#mcp-calls details[open] summary { border-bottom: 1px solid var(--line); }
.mcp-agent { font-weight: 600; white-space: nowrap; }
.mcp-preview {
  flex: 1; color: #cfe3f5; font-family: "IBM Plex Mono", monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mcp-tool { color: var(--muted); font-family: "IBM Plex Mono", monospace; white-space: nowrap; }

/* --------------------------------------------------------------- panels */

pre { margin: 0; overflow-x: auto; background: var(--panel-2); padding: 14px 16px; font-size: 12.5px; line-height: 1.5; border: 0; }
pre code { color: #cfe3f5; }
.query-panel { border: 1px solid var(--line); background: var(--panel); margin-bottom: 14px; }
.query-panel > header { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.query-panel > header h3 { margin: 0; font-size: 13px; color: var(--text); text-transform: none; letter-spacing: 0; }
.query-count { font-size: 11px; color: var(--muted); font-family: "IBM Plex Mono", monospace; }
.query-panel .panel-lead { padding: 12px 16px 0; margin-bottom: 10px; }
.stat-badge { color: var(--accent); font-family: "IBM Plex Mono", monospace; font-size: 11.5px; }

.sql-drop { margin-top: 14px; border: 1px solid var(--line); background: var(--panel-2); }
.sql-drop summary { padding: 10px 16px; cursor: pointer; font-size: 12.5px; color: var(--muted); display: flex; gap: 12px; align-items: baseline; }
.sql-drop summary::marker { color: var(--muted); }
.sql-drop[open] summary { border-bottom: 1px solid var(--line); }

/* --------------------------------------------------------------- recall */

.recall-form { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.recall-form input {
  flex: 1 1 480px; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); padding: 10px 12px; font-size: 14px;
}
.recall-results { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.recall-item { display: flex; gap: 16px; border: 1px solid var(--line); background: var(--panel-2); padding: 12px 16px; }
.recall-score { font-family: "IBM Plex Mono", monospace; font-size: 18px; font-weight: 600; color: var(--accent); min-width: 62px; }
.recall-text { margin: 0; font-size: 13.5px; }
.recall-fix { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.recall-tag { text-transform: uppercase; font-size: 10px; letter-spacing: 0.08em; border: 1px solid var(--line); padding: 1px 6px; margin-right: 8px; color: var(--accent); }

/* --------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); }
.table-wrap.table-scroll { max-height: 420px; overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.07em; background: var(--panel-2); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.hit { background: rgba(212, 160, 23, 0.08); }
/* Evidence is the only column that can wrap, so it is the one that yields when
   the row would otherwise push the Approve/Reject buttons past the edge. */
td.reason { white-space: normal; min-width: 200px; max-width: 380px; color: var(--muted); }
/* Not display:flex -- a flex table cell leaves the column with no measured
   width, so the second button gets clipped at the table edge. */
td.decide { white-space: nowrap; }
td.decide button { padding: 4px 10px; font-size: 11px; }
td.decide button + button { margin-left: 6px; }
button.reject { background: transparent; color: var(--muted); border: 1px solid var(--line); }

.pill { display: inline-block; padding: 2px 8px; font-size: 11px; border: 1px solid var(--line); text-transform: uppercase; letter-spacing: 0.05em; }
.pill.failed { color: var(--fail); border-color: #4a2320; }
.pill.running { color: var(--run); border-color: #1d3a54; }
.pill.queued { color: var(--queue); border-color: #45390f; }
.pill.completed { color: var(--muted); }
.pill.waste { color: var(--accent); border-color: #4a3c10; }
.pill.action { color: var(--rec); border-color: #1f4a35; }
.pill.pending { color: var(--queue); border-color: #45390f; }
.pill.approved { color: var(--rec); border-color: #1f4a35; }
.pill.rejected { color: var(--muted); }
.vram { font-family: "IBM Plex Mono", monospace; font-weight: 600; }
.vram.critical { color: var(--fail); }

.farm-spark { color: var(--run); margin-bottom: 14px; }
.farm-spark svg { width: 100%; height: 90px; display: block; }

.page-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; margin-top: 20px; }

@media (max-width: 1150px) {
  .nav-links { display: none; }
  .nav-brand { margin-right: auto; }
}
@media (max-width: 900px) {
  .run-status { display: none; }
}
@media (max-width: 700px) {
  .run-bar .cost-meter { display: none; }
}
@media (max-width: 1000px) {
  .dashboard, .impact-hero { grid-template-columns: 1fr; }
  .scale-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  h1 { font-size: 26px; }
  .masthead { flex-direction: column; align-items: flex-start; }
  .hero-value { font-size: 34px; }
}
@media (max-width: 620px) {
  .scale-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
