/* Pipeline Incident Explorer: dark theme (GitHub-dark palette), no web fonts. */

:root {
  /* surfaces */
  --bg: #0d1117;
  --raised: #161b22;
  --raised-2: #1c2128;
  --header: #010409;
  --border: #30363d;
  --border-soft: #21262d;
  /* text */
  --text: #c9d1d9;
  --text-strong: #e6edf3;
  --text-muted: #8b949e;
  --text-faint: #6e7681;
  /* roles */
  --accent: #1f6feb;
  --accent-fg: #58a6ff;
  --vec: #8957e5;
  --vec-fg: #d2a8ff;
  --kw: #2ea043;
  --kw-fg: #7ee787;
  --gen: #f0883e;
  --gen-fg: #ffa657;
  --search: #79c0ff;
  --ok: #3fb950;
  --warn: #d29922;
  --warn-fg: #e3b341;
  --error: #f85149;
  --mark-bg: rgba(187, 128, 9, 0.18);
  /* source palette (citation n -> --src-n) */
  --src-1: #58a6ff;
  --src-2: #d2a8ff;
  --src-3: #7ee787;
  --src-4: #ffa657;
  --src-5: #ff7b72;
  --src-6: #79c0ff;
  --src-7: #e3b341;
  --src-8: #f778ba;
  --src-9: #56d4dd;
  --src-10: #a5d6ff;
  /* refined-query palette (query index -> --q-i) */
  --q-0: #58a6ff;
  --q-1: #d2a8ff;
  --q-2: #7ee787;
  --q-3: #ffa657;
  --refine: #f778ba;
  /* spacing scale (4 px) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;
  /* shape and motion */
  --r-sm: 4px;
  --r: 6px;
  --r-lg: 8px;
  --t-fast: 120ms;
  --t: 160ms;
  --t-slow: 180ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  /* type */
  --font: Inter, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  --header-h: 52px;
  --sidebar-w: 272px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font: inherit; color: inherit; }
code, kbd, pre { font-family: var(--mono); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.spacer { flex: 1; }
.muted { color: var(--text-muted); }
mark { background: var(--mark-bg); color: var(--warn-fg); border-radius: 2px; padding: 0 1px; }

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

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-soft); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border); }
::-webkit-scrollbar-track { background: transparent; }

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

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

.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 0 var(--s-4);
  background: var(--header);
  border-bottom: 1px solid var(--border-soft);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast);
}
.icon-btn:hover { background: var(--raised); color: var(--text-strong); border-color: var(--border); }

.brand { display: flex; align-items: center; gap: var(--s-2); margin-right: var(--s-2); }
.brand h1 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-strong); letter-spacing: -0.01em; white-space: nowrap; }
.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-lg);
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--vec) 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset, 0 2px 8px rgba(31, 111, 235, 0.35);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}
.pill svg { opacity: 0.8; }
#models-text { font-family: var(--mono); font-size: 11.5px; }

.health {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: default;
  border: 1px solid transparent;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.health:hover, .health:focus-visible { border-color: var(--border); background: var(--raised); }
.health-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.health.ok .health-dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(63, 185, 80, 0.18); }
.health.bad .health-dot { background: var(--error); box-shadow: 0 0 0 3px rgba(248, 81, 73, 0.2); }
.health.bad .health-label { color: var(--error); }

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

.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: calc(100vh - var(--header-h));
  transition: grid-template-columns var(--t-slow) var(--ease);
}
body.sidebar-collapsed .app-body { grid-template-columns: 0 minmax(0, 1fr); }

.sidebar {
  overflow: hidden auto;
  border-right: 1px solid var(--border-soft);
  background: #0a0e14;
  padding: var(--s-4) var(--s-3);
  min-width: 0;
}
body.sidebar-collapsed .sidebar { padding: 0; border-right: 0; }

.sidebar-head { display: flex; align-items: center; gap: var(--s-2); padding: 0 var(--s-2) var(--s-3); }
.count {
  font-size: 11px;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--border-soft);
  color: var(--text-muted);
  text-align: center;
}
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.history-empty { margin: var(--s-2); font-size: 12.5px; color: var(--text-faint); line-height: 1.55; }

.h-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--s-2) var(--s-3);
  border: 0;
  border-left: 2px solid transparent;
  border-radius: var(--r);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast);
}
.h-item:hover { background: var(--raised); }
.h-item.active { background: rgba(31, 111, 235, 0.12); border-left-color: var(--accent-fg); }
.h-query {
  font-size: 13px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.h-item.active .h-query { color: var(--text-strong); }
.h-meta { display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: var(--text-faint); }
.h-tps { font-family: var(--mono); color: var(--text-muted); }

.main { overflow-y: auto; min-width: 0; scrollbar-gutter: stable; }
.main-inner { max-width: 1200px; margin: 0 auto; padding: var(--s-6) var(--s-8) var(--s-12); }

/* ---------- query bar ---------- */

.query-bar {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.query-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.22); }
.query-bar textarea {
  width: 100%;
  min-height: 26px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 4px 0 0;
  background: transparent;
  color: var(--text-strong);
  font: 16px/1.55 var(--font);
}
.query-bar textarea::placeholder { color: var(--text-faint); }
.query-actions { display: flex; align-items: center; gap: var(--s-3); }
.kbd-hint { flex: 1; font-size: 12px; color: var(--text-faint); }
kbd {
  display: inline-block;
  padding: 0 5px;
  font-size: 11px;
  line-height: 17px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
}

.btn, .btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 var(--s-4);
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--border-soft);
  color: var(--text-strong);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast), transform var(--t-fast);
}
.btn:hover { background: var(--border); border-color: #484f58; }
.btn-primary { background: #238636; border-color: rgba(240, 246, 252, 0.1); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #2ea043; }
.btn-primary:active, .btn:active { transform: translateY(1px); }
.btn-primary.busy { background: var(--accent); }
.btn-primary.busy svg { animation: nudge 900ms var(--ease) infinite; }
.btn-sm { height: 26px; padding: 0 10px; font-size: 12px; }
.copy-btn { color: var(--text-muted); }
.copy-btn:hover { color: var(--text-strong); }
.copy-btn.copied { color: var(--kw-fg); border-color: rgba(46, 160, 67, 0.5); }

/* ---------- summary strip ---------- */

.summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  flex-wrap: wrap;
  row-gap: var(--s-2);
  min-height: 44px;
  margin-top: var(--s-3);
  padding: 0 var(--s-1);
}
.stages { display: flex; align-items: center; list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.stages li { display: flex; align-items: center; gap: 7px; white-space: nowrap; color: var(--text-faint); transition: color var(--t) var(--ease); }
.stages li:not(:last-child)::after {
  content: "";
  width: 28px;
  height: 1px;
  margin: 0 var(--s-3) 0 5px;
  background: var(--border);
}
.stage-dot {
  position: relative;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg);
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
.stage-time { font-family: var(--mono); font-size: 11.5px; color: var(--text-muted); }
.stage-time:empty { display: none; }
.stages li.is-active { color: var(--text-strong); }
.stages li.is-active .stage-dot { border-color: var(--accent-fg); background: var(--accent-fg); }
.stages li.is-active .stage-dot::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid var(--accent-fg);
  animation: ping 1.2s var(--ease) infinite;
}
.stages li.is-done { color: var(--text); }
.stages li.is-done .stage-dot { border-color: var(--kw); background: var(--kw); }
.stages li.is-done:not(:last-child)::after { background: rgba(46, 160, 67, 0.55); }
.stages li.is-error { color: var(--error); }
.stages li.is-error .stage-dot { border-color: var(--error); background: var(--error); }
.stages li.is-warn { color: var(--warn-fg); }
.stages li.is-warn .stage-dot { border-color: var(--warn); background: var(--warn); }
.stages li.is-warn .stage-time { color: var(--warn-fg); }
.stages li.is-skipped { color: var(--text-faint); text-decoration: line-through; text-decoration-color: var(--border); }
.stages li.is-skipped .stage-dot { border-style: dashed; }
.summary.idle .stages { opacity: 0.55; }

.summary-stats { display: flex; align-items: center; gap: 0; font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }
.summary-stats .stat { padding: 0 var(--s-3); border-left: 1px solid var(--border-soft); }
.summary-stats .stat:first-child { border-left: 0; }
.summary-stats b { color: var(--text-strong); font-weight: 600; font-variant-numeric: tabular-nums; margin-right: 2px; }
/* 1280-1400 px with the sidebar open: tighten so stages and stats stay on one line. */
@media (max-width: 1400px) {
  .stages li:not(:last-child)::after { width: 14px; margin: 0 var(--s-2) 0 4px; }
  .summary-stats .stat { padding: 0 var(--s-2); }
}

/* ---------- tabs ---------- */

.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--border-soft); margin-top: var(--s-1); }
.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 10px var(--s-4);
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  border-radius: var(--r) var(--r) 0 0;
  transition: color var(--t-fast) var(--ease), background var(--t-fast);
}
.tab:hover { color: var(--text-strong); background: rgba(177, 186, 196, 0.06); }
.tab::after {
  content: "";
  position: absolute;
  left: var(--s-2);
  right: var(--s-2);
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: transparent;
  transition: background var(--t) var(--ease);
}
.tab[aria-selected="true"] { color: var(--text-strong); font-weight: 600; }
.tab[aria-selected="true"]::after { background: #f78166; }
.tab-badge {
  font-size: 11px;
  font-weight: 500;
  line-height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--border-soft);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.tab-badge:empty { display: none; }

.panel { padding-top: var(--s-5); animation: fade-in var(--t-slow) var(--ease); }

/* ---------- shared cards and states ---------- */

.card {
  background: var(--raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  margin-bottom: var(--s-4);
}
.card-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border-soft);
  font-size: 12.5px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }
.grid-2 > .card { margin-bottom: 0; }

.empty { text-align: center; padding: var(--s-12) var(--s-6); color: var(--text-muted); }
.empty-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: var(--s-2); }
.empty-body { max-width: 520px; margin: 0 auto; font-size: 13.5px; line-height: 1.6; }

.panel-loading { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-8) var(--s-2); color: var(--text-muted); font-size: 13.5px; }

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent-fg);
  animation: spin 700ms linear infinite;
  flex: none;
}
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--gen-fg); animation: blink 1s ease-in-out infinite; }

.badge {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid transparent;
}
.badge-ok { color: var(--kw-fg); background: rgba(46, 160, 67, 0.15); border-color: rgba(46, 160, 67, 0.35); }
.badge-warn { color: var(--warn-fg); background: rgba(210, 153, 34, 0.15); border-color: rgba(210, 153, 34, 0.4); }
.badge-err { color: #ff7b72; background: rgba(248, 81, 73, 0.15); border-color: rgba(248, 81, 73, 0.4); }
.badge-muted { color: var(--text-muted); background: var(--border-soft); border-color: var(--border); }

.tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--r-sm);
  font-size: 11.5px;
  font-family: var(--mono);
}
.tag-vec { background: rgba(137, 87, 229, 0.2); color: var(--vec-fg); }
.tag-kw { background: rgba(46, 160, 67, 0.2); color: var(--kw-fg); }
.tag-none { background: var(--border-soft); color: var(--text-faint); }

/* ---------- answer tab ---------- */

.intro { text-align: center; padding: var(--s-10) var(--s-6) var(--s-6); }
.intro-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: var(--r-lg);
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--vec) 100%);
  box-shadow: 0 8px 28px rgba(31, 111, 235, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}
.intro-title { margin: var(--s-5) 0 var(--s-2); font-size: 22px; font-weight: 600; color: var(--text-strong); letter-spacing: -0.01em; }
.intro-body { max-width: 580px; margin: 0 auto; color: var(--text-muted); font-size: 14px; line-height: 1.65; }
.pipeline {
  display: flex;
  justify-content: center;
  list-style: none;
  margin: var(--s-8) auto 0;
  padding: 0;
  max-width: 860px;
}
.pipeline li {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-top: 26px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.pipeline li small { font-size: 11.5px; font-weight: 400; color: var(--text-faint); }
.pipeline li::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
}
.pipeline li:first-child::before { left: 50%; }
.pipeline li:last-child::before { right: 50%; }
.pl-dot {
  position: absolute;
  top: 1px;
  left: calc(50% - 7px);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--border);
}
.pl-embed { background: var(--text-muted); }
.pl-vec { background: var(--vec); }
.pl-kw { background: var(--kw); }
.pl-fuse { background: var(--search); }
.pl-gen { background: var(--gen); }

.answer-card {
  background: var(--raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  padding: var(--s-4) var(--s-6) var(--s-5);
}
.answer-head { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-3); }
.answer-status { display: inline-flex; align-items: center; gap: var(--s-2); font-size: 12.5px; color: var(--text-muted); }

/* model reasoning (thinking models): collapsed by default, muted */
.reasoning {
  margin: 0 0 var(--s-4);
  border: 1px solid var(--border-soft);
  border-radius: var(--r);
  background: var(--bg);
  max-width: 82ch;
}
.reasoning > summary {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-muted);
  list-style: none;
  user-select: none;
}
.reasoning > summary::-webkit-details-marker { display: none; }
.reasoning > summary::before {
  content: "";
  width: 6px;
  height: 6px;
  margin: 0 2px 0 1px;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(-45deg);
  transition: transform var(--t-fast) var(--ease);
}
.reasoning[open] > summary::before { transform: rotate(45deg); }
.reasoning > summary:hover { color: var(--text); }
.reasoning > summary:focus-visible { outline: 2px solid var(--accent-fg); outline-offset: 2px; border-radius: var(--r); }
.reasoning-count { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }
.reasoning-text {
  max-height: 260px;
  overflow-y: auto;
  padding: var(--s-2) var(--s-3) var(--s-3);
  border-top: 1px solid var(--border-soft);
  font: 12.5px/1.6 var(--mono);
  color: var(--text-muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.prose { font-size: 15.5px; line-height: 1.72; color: var(--text); max-width: 82ch; overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p { margin: 0 0 var(--s-3); }
.prose strong { color: var(--text-strong); font-weight: 600; }
.prose a { color: var(--accent-fg); text-decoration: none; }
.prose a:hover { text-decoration: underline; }
.prose ul, .prose ol { margin: 0 0 var(--s-3); padding-left: var(--s-6); }
.prose li { margin: var(--s-1) 0; }
.prose li::marker { color: var(--text-muted); }
.prose h1, .prose h2, .prose h3, .prose h4 { color: var(--text-strong); font-weight: 600; line-height: 1.3; margin: var(--s-5) 0 var(--s-2); }
.prose h1 { font-size: 20px; } .prose h2 { font-size: 18px; } .prose h3 { font-size: 16px; } .prose h4 { font-size: 15px; }
.prose code { font-size: 0.86em; padding: 0.15em 0.4em; border-radius: var(--r-sm); background: rgba(110, 118, 129, 0.25); color: var(--text-strong); }
.prose pre { margin: 0 0 var(--s-3); padding: var(--s-3) var(--s-4); background: var(--bg); border: 1px solid var(--border-soft); border-radius: var(--r); overflow-x: auto; }
.prose pre code { padding: 0; background: none; font-size: 13px; line-height: 1.6; }
.prose blockquote { margin: 0 0 var(--s-3); padding: 0 var(--s-4); border-left: 3px solid var(--border); color: var(--text-muted); }
.prose table { border-collapse: collapse; margin: 0 0 var(--s-3); font-size: 14px; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 12px; }
.prose th { background: var(--bg); color: var(--text-strong); }
.prose hr { border: 0; border-top: 1px solid var(--border-soft); margin: var(--s-4) 0; }

.cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 18px;
  margin: 0 1px;
  padding: 0 5px;
  vertical-align: 2px;
  font: 600 11px/1 var(--font);
  color: var(--accent-fg);
  background: rgba(31, 111, 235, 0.16);
  border: 1px solid rgba(31, 111, 235, 0.45);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast), border-color var(--t-fast);
}
.cite:hover, .cite:focus-visible, .cite.hot { background: var(--accent); border-color: var(--accent); color: #fff; }
.cite:focus-visible { outline-offset: 1px; }

.caret {
  display: inline-block;
  width: 8px;
  height: 1.1em;
  margin-left: 2px;
  vertical-align: -0.18em;
  background: var(--accent-fg);
  border-radius: 1px;
  animation: blink 1s steps(2, start) infinite;
}

.skeleton { display: flex; flex-direction: column; gap: 10px; padding: var(--s-1) 0; }
.skeleton span {
  display: block;
  height: 12px;
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--border-soft) 0%, #2a313c 50%, var(--border-soft) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton span:nth-child(2) { width: 92%; }
.skeleton span.short { width: 58%; }

.answer-foot {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--s-2) var(--s-3);
  margin-top: var(--s-5);
  padding-top: var(--s-3);
  border-top: 1px solid var(--border-soft);
  font-size: 12.5px;
  color: var(--text-muted);
}
.foot-label { font-weight: 600; color: var(--text-muted); }
.cite-refs { grid-column: 1 / -1; grid-row: 2; display: flex; flex-wrap: wrap; gap: var(--s-2); }
.cite-ref {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  color: var(--text);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cite-swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.foot-hint { color: var(--text-faint); font-size: 12px; }

.no-match { display: flex; gap: var(--s-4); align-items: flex-start; padding: var(--s-2) 0; color: var(--text-muted); }
.no-match p { margin: 4px 0 0; font-size: 14px; }
.no-match-title { font-size: 15px; font-weight: 600; color: var(--text); }
.no-match-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--r-lg);
  background: var(--bg);
  border: 1px solid var(--border-soft);
  color: var(--text-muted);
  font-weight: 700;
}
.no-match.is-error .no-match-icon { color: var(--error); border-color: rgba(248, 81, 73, 0.4); background: rgba(248, 81, 73, 0.08); }
.no-match.is-error code { color: #ff7b72; }
.interrupted-note {
  margin-top: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r);
  border: 1px solid rgba(210, 153, 34, 0.4);
  background: rgba(210, 153, 34, 0.1);
  color: var(--warn-fg);
  font-size: 13px;
}

/* floating preview card */
.preview-card {
  position: fixed;
  z-index: 50;
  width: 440px;
  max-width: calc(100vw - 16px);
  padding: var(--s-3) var(--s-4) var(--s-3) calc(var(--s-4) + 2px);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: 0 16px 40px rgba(1, 4, 9, 0.8), 0 0 0 1px rgba(1, 4, 9, 0.4);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease);
  pointer-events: auto;
}
.preview-card.above { transform: translateY(4px); }
.preview-card.open { opacity: 1; transform: none; }
.preview-card::after {
  content: "";
  position: absolute;
  left: -1px;
  top: -1px;
  bottom: -1px;
  width: 4px;
  border-radius: var(--r-lg) 0 0 var(--r-lg);
  background: var(--stripe, var(--accent-fg));
}
.preview-card::before {
  content: "";
  position: absolute;
  top: -6px;
  left: calc(var(--arrow-x, 40px) - 5px);
  width: 10px;
  height: 10px;
  background: var(--raised);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
  transform: rotate(45deg);
}
.preview-card.above::before { top: auto; bottom: -6px; transform: rotate(225deg); }
.pc-head { display: flex; align-items: center; gap: var(--s-2); }
.pc-n {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: var(--r-sm);
  color: var(--header);
  font: 700 11.5px/1 var(--font);
}
.pc-title { font-weight: 600; color: var(--text-strong); font-size: 14px; }
.pc-sub { margin-top: 4px; font-size: 12px; color: var(--text-muted); }
.pc-date { white-space: nowrap; }
.pc-passage {
  margin: var(--s-3) 0;
  padding: var(--s-2) var(--s-3);
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--r);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text);
  overflow-wrap: anywhere;
}
.pc-foot { display: flex; align-items: center; gap: 6px; }
.pc-score { font-size: 12px; color: var(--text-muted); }
.pc-score b { font-family: var(--mono); font-weight: 500; color: var(--text-strong); }

/* ---------- retrieval tab ---------- */

.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-4); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 var(--s-3);
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-muted);
}
.chip b { color: var(--text-strong); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip-label { color: var(--text-faint); margin-right: 2px; }
.chip-terms mark { font-family: var(--mono); font-size: 12px; padding: 1px 5px; }
.chip-terms .sep { color: var(--text-faint); }
.chip-swatch { width: 8px; height: 8px; border-radius: 2px; }
.chip-vec .chip-swatch { background: var(--vec); }
.chip-kw .chip-swatch { background: var(--kw); }

.legend { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.table-card { overflow: hidden; }
.rank-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rank-table th {
  padding: var(--s-2) var(--s-3);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: rgba(1, 4, 9, 0.35);
  border-bottom: 1px solid var(--border-soft);
}
.rank-table td { padding: 10px var(--s-3); border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.rank-table tbody tr:last-child td { border-bottom: 0; }
.rank-table tr.row { cursor: pointer; transition: background var(--t-fast) var(--ease), opacity var(--t-fast); }
.rank-table tr.row:hover { background: var(--raised-2); }
.rank-table tr.row:focus-visible { outline: 2px solid var(--accent-fg); outline-offset: -2px; }
.rank-table tr.row.is-unsent { opacity: 0.5; }
.rank-table tr.row.is-unsent:hover { opacity: 0.85; }
.c-rank { width: 44px; font-family: var(--mono); color: var(--text-muted); text-align: center; }
.rank-table th:first-child { text-align: center; }
.c-note { min-width: 0; }
.note-title { color: var(--text-strong); font-weight: 600; }
.note-heading { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.c-date { width: 110px; font-family: var(--mono); font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.c-badge { width: 56px; }
.c-contrib { width: 170px; }
.c-score { width: 84px; text-align: right; font-family: var(--mono); font-size: 12.5px; color: var(--text); }
.rank-table th.c-score { font-family: var(--font); }
.c-chev { width: 32px; color: var(--text-faint); }
.c-chev svg { transition: transform var(--t) var(--ease); }
tr.row[aria-expanded="true"] .c-chev svg { transform: rotate(90deg); color: var(--text); }
tr.row[aria-expanded="true"] td { border-bottom-color: transparent; }

.rank {
  display: inline-block;
  min-width: 26px;
  padding: 2px 6px;
  border-radius: var(--r-sm);
  text-align: center;
  font: 500 12px/1.3 var(--mono);
}
.rank-vec { background: rgba(137, 87, 229, 0.22); color: var(--vec-fg); }
.rank-kw { background: rgba(46, 160, 67, 0.22); color: var(--kw-fg); }
.rank-none { background: var(--border-soft); color: var(--text-faint); }

.stack { display: flex; height: 8px; width: 100%; border-radius: 4px; overflow: hidden; background: var(--border-soft); }
.stack i { display: block; height: 100%; }
.seg-vec { background: var(--vec); }
.seg-kw { background: var(--kw); }

/* Drawn as a gradient: under border-collapse a dashed border loses to the row's solid one. */
.rank-table tr.cutoff td {
  padding: 0;
  height: 2px;
  border-bottom: 0;
  position: relative;
  background: repeating-linear-gradient(90deg, var(--error) 0 6px, transparent 6px 11px);
}
.rank-table tr.cutoff span {
  position: absolute;
  right: var(--s-3);
  top: -9px;
  padding: 0 var(--s-2);
  font-size: 11px;
  line-height: 17px;
  color: var(--error);
  background: var(--raised);
  border: 1px solid rgba(248, 81, 73, 0.45);
  border-radius: 999px;
}
.rank-table tr.detail td { padding-top: 0; }
.rank-table tr.detail.is-unsent td { opacity: 0.75; }
.chunk {
  margin: 0;
  padding: var(--s-3) var(--s-4);
  max-height: 360px;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--r);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: fade-in var(--t) var(--ease);
}
.chunk-path { margin-top: 6px; font: 11.5px var(--mono); color: var(--text-faint); }

/* ---------- prompt tab ---------- */

.prompt-summary { display: grid; grid-template-columns: 1fr 1fr; }
.prompt-summary > div { display: flex; flex-direction: column; gap: 6px; padding: var(--s-3) var(--s-4); }
.ps-fit { border-left: 1px solid var(--border-soft); }
.ps-numbers { font-size: 13px; color: var(--text-muted); }
.ps-numbers b { font-size: 18px; color: var(--text-strong); font-weight: 600; font-variant-numeric: tabular-nums; }
.mini-gauge { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.mini-gauge i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--vec)); border-radius: 3px; }
.ps-fit .muted { font-size: 12.5px; }
.src-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.src-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: var(--r-sm);
  font: 600 12px/1 var(--mono);
  color: var(--c);
  background: color-mix(in srgb, var(--c) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 55%, transparent);
}
.role {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 var(--s-2);
  border-radius: var(--r-sm);
  font: 600 12px/1 var(--mono);
}
.role-system { color: var(--gen-fg); background: rgba(240, 136, 62, 0.15); }
.role-user { color: var(--accent-fg); background: rgba(31, 111, 235, 0.15); }
.msg {
  margin: 0;
  padding: var(--s-4);
  font: 12.5px/1.65 var(--mono);
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-user { display: flex; flex-direction: column; gap: var(--s-2); }
.src-block {
  padding: var(--s-2) var(--s-3);
  border-left: 3px solid var(--c);
  border-radius: 0 var(--r) var(--r) 0;
  background: color-mix(in srgb, var(--c) 8%, transparent);
}
.plain-block { padding: var(--s-2) var(--s-3); }
.question-block {
  padding: var(--s-2) var(--s-3);
  border: 1px dashed var(--border);
  border-radius: var(--r);
  color: var(--text-strong);
}

/* ---------- metrics tab ---------- */

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-4); margin-bottom: var(--s-4); }
.kpis-ops { grid-template-columns: repeat(3, 1fr); }
.kpi {
  padding: var(--s-4);
  background: var(--raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
}
.kpi-value { font-size: 28px; font-weight: 600; line-height: 1.15; color: var(--text-strong); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.kpi-label { margin-top: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.kpi-sub { margin-top: var(--s-2); font-size: 12px; color: var(--text-faint); }

.waterfall {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr) 76px;
  gap: 10px var(--s-4);
  align-items: center;
  padding: var(--s-4) var(--s-4) var(--s-3);
}
.wf-label { font-size: 13px; color: var(--text); white-space: nowrap; }
.wf-ms { font: 12.5px var(--mono); color: var(--text-strong); text-align: right; font-variant-numeric: tabular-nums; }
.wf-track {
  position: relative;
  height: 14px;
  border-radius: var(--r-sm);
  background-color: var(--bg);
  background-image: linear-gradient(to right, var(--border-soft) 1px, transparent 1px);
  background-size: 25% 100%;
}
.wf-bar { position: absolute; top: 2px; bottom: 2px; min-width: 3px; border-radius: 3px; transition: width var(--t-slow) var(--ease); }
.wf-embed_ms { background: var(--vec-fg); }
.wf-search_ms { background: var(--search); }
.wf-prompt_build_ms { background: var(--text-muted); }
.wf-load_ms { background: var(--warn-fg); }
.wf-refine_ms { background: var(--refine); }
.wf-prompt_eval_ms { background: var(--gen-fg); }
.wf-generate_ms { background: var(--gen); }
.wf-axis { position: relative; height: 16px; }
.tick { position: absolute; top: 0; font: 11px var(--mono); color: var(--text-faint); white-space: nowrap; }
.tick span { position: relative; left: -50%; }
.tick:first-child span { left: 0; }
.tick:last-child span { left: -100%; }

.budget { padding: var(--s-4); }
.budget-numbers { display: flex; align-items: baseline; gap: 4px; color: var(--text-muted); font-size: 13px; }
.budget-numbers b { font-size: 22px; color: var(--text-strong); font-weight: 600; font-variant-numeric: tabular-nums; }
.budget-pct { font: 13px var(--mono); color: var(--text); }
.gauge { height: 12px; margin: var(--s-3) 0; border-radius: 6px; background: var(--bg); border: 1px solid var(--border-soft); overflow: hidden; }
.gauge i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--vec)); border-radius: 6px; }
.budget-fit { font-size: 13px; color: var(--text-muted); }
.budget-fit b { color: var(--text-strong); }

.details { display: grid; grid-template-columns: 120px 1fr; gap: var(--s-2) var(--s-4); margin: 0; padding: var(--s-4) var(--s-4) var(--s-2); font-size: 13px; }
.details dt { color: var(--text-muted); }
.details dd { margin: 0; color: var(--text-strong); }
.details code { font-size: 12.5px; }
.trace-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: var(--s-2) var(--s-4) var(--s-4);
  height: 30px;
  padding: 0 var(--s-3);
  border-radius: var(--r);
  border: 1px solid rgba(31, 111, 235, 0.5);
  background: rgba(31, 111, 235, 0.12);
  color: var(--accent-fg);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast);
}
.trace-link:hover { background: rgba(31, 111, 235, 0.22); border-color: var(--accent-fg); }

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

.pill-sec { color: var(--kw-fg); }

/* Five stages when refining: shorter connectors keep the stages and stats on one line. */
.stages:has(li[data-stage="refining"]:not([hidden])) li:not(:last-child)::after { width: 14px; margin: 0 var(--s-2) 0 4px; }

/* ---------- query bar pickers ---------- */

.picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg);
  font-size: 12.5px;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast);
}
.picker:hover { border-color: #484f58; }
.picker:focus-within { border-color: var(--accent-fg); }
.picker-label { padding: 0 2px 0 10px; color: var(--text-faint); white-space: nowrap; }
.picker select {
  -webkit-appearance: none;
  appearance: none;
  height: 100%;
  padding: 0 26px 0 6px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-strong);
  font: 500 12.5px var(--font);
  cursor: pointer;
}
.picker select option { background: var(--raised); color: var(--text-strong); }
.picker::after {
  content: "";
  position: absolute;
  right: 11px;
  top: 12px;
  width: 5px;
  height: 5px;
  border: solid var(--text-muted);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
  pointer-events: none;
}

/* ---------- system tabs (Quality, Ops) ---------- */

.tabs-divider { flex: 1; }
.tab-system svg { opacity: 0.75; }
.tab-system[aria-selected="true"] svg { opacity: 1; color: var(--accent-fg); }

.sys-head { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-4); }
.sys-title { margin: 0; font-size: 18px; font-weight: 600; color: var(--text-strong); letter-spacing: -0.01em; }
.sys-sub { margin: 4px 0 0; font-size: 13px; color: var(--text-muted); }
.sys-sub b { color: var(--text); font-weight: 600; }
.sys-sub code { font-size: 12px; color: var(--text); }
.sys-link { margin: 0; }
.panel.is-refreshing { opacity: 0.6; transition: opacity var(--t) var(--ease); }

.kpi-good .kpi-value { color: var(--kw-fg); }
.kpi-warn .kpi-value { color: var(--warn-fg); }
.kpi-bad .kpi-value { color: #ff7b72; }
.kpi .thumb { font-size: 20px; margin-right: 6px; vertical-align: 2px; }
.kpi .thumb-down { margin-left: 18px; }

.seg { display: inline-flex; padding: 2px; border: 1px solid var(--border); border-radius: var(--r); background: var(--bg); }
.seg-btn {
  height: 24px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 12.5px;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast);
}
.seg-btn:hover { color: var(--text-strong); }
.seg-btn[aria-pressed="true"] { background: var(--border); color: var(--text-strong); font-weight: 600; }

/* scorecard and ops tables */
.q-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.q-table th {
  padding: var(--s-2) var(--s-3);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: rgba(1, 4, 9, 0.35);
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
.q-table td { padding: 9px var(--s-3); border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.q-table tbody tr:last-child td { border-bottom: 0; }
.q-table tbody tr:hover td { background: rgba(177, 186, 196, 0.03); }
.q-table tr.group-start td { border-top: 1px solid var(--border); }
.q-table .q-num { text-align: right; font-variant-numeric: tabular-nums; }
.q-group { font-weight: 600; color: var(--text-strong); width: 110px; }
.q-refine { color: var(--text); white-space: nowrap; }
.q-refine .badge { margin-left: 6px; }
.q-val { display: inline-block; padding: 0 6px; border-radius: var(--r-sm); font: 500 13px var(--mono); color: var(--text); }
.q-ms .q-val, td.q-ms { font: 12.5px var(--mono); color: var(--text-muted); }
.q-bar { display: block; height: 3px; margin: 4px 0 0 auto; width: 56px; border-radius: 2px; background: var(--border-soft); overflow: hidden; }
.q-bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.q-bar-muted i { background: var(--text-faint); }
.q-num.is-best .q-val {
  color: var(--kw-fg);
  font-weight: 600;
  background: rgba(46, 160, 67, 0.16);
  box-shadow: 0 0 0 1px rgba(46, 160, 67, 0.4) inset;
}
.q-num.is-best .q-bar i { background: var(--kw); }
.q-warn {
  margin-bottom: var(--s-4);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r);
  border: 1px solid rgba(210, 153, 34, 0.4);
  background: rgba(210, 153, 34, 0.08);
  color: var(--warn-fg);
  font-size: 13px;
}
.q-warn code { font-size: 12px; color: var(--text); }
.q-note { margin: 0; padding: var(--s-4); font-size: 13px; color: var(--text-muted); }
.q-transcripts .kpis { padding: var(--s-4) var(--s-4) 0; }
.q-table tr.is-current td { background: rgba(56, 139, 253, 0.07); }
.legend-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--s-3) var(--s-6); margin: 0; padding: var(--s-4); }
.legend-grid dt { font-size: 12.5px; font-weight: 600; color: var(--text-strong); }
.legend-grid dd { margin: 2px 0 0; font-size: 12.5px; line-height: 1.55; color: var(--text-muted); }
.cmd {
  display: inline-block;
  margin: var(--s-5) auto 0;
  padding: var(--s-3) var(--s-5);
  text-align: left;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-strong);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--r);
}

/* ops */
.ops-grid { margin-bottom: var(--s-4); }
.runs-table .r-time { width: 90px; font: 12px var(--mono); color: var(--text-muted); white-space: nowrap; }
.runs-table .r-query { max-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.runs-table .r-query a { color: var(--text-strong); text-decoration: none; }
.runs-table .r-query a:hover { color: var(--accent-fg); text-decoration: underline; }
.runs-table .r-mode { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.runs-table .r-fb { text-align: center; width: 64px; }
.runs-table .r-flags { white-space: nowrap; width: 1%; }
.runs-table .r-flags .badge + .badge { margin-left: 4px; }

.sec-stats { display: grid; grid-template-columns: repeat(5, 1fr); border-bottom: 1px solid var(--border-soft); }
.sec-stat { display: flex; flex-direction: column; gap: 2px; padding: var(--s-3) var(--s-4); border-left: 1px solid var(--border-soft); }
.sec-stat:first-child { border-left: 0; }
.sec-stat b { font-size: 22px; font-weight: 600; line-height: 1.2; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.sec-stat span { font-size: 11.5px; color: var(--text-muted); line-height: 1.35; }
.sec-stat.is-good b { color: var(--kw-fg); }
.sec-stat.is-warn b { color: var(--warn-fg); }
.sec-stat.is-bad b { color: #ff7b72; }
.sec-section { padding: var(--s-3) var(--s-4) 0; }
.sec-label { margin-bottom: var(--s-2); font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.sec-type { display: grid; grid-template-columns: 150px 1fr 40px; align-items: center; gap: var(--s-3); padding: 3px 0; font-size: 13px; }
.sec-type b { text-align: right; font: 500 12.5px var(--mono); color: var(--text-strong); }
.sec-bar { height: 8px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.sec-bar i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--kw), var(--kw-fg)); }
.sec-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-2); }
.sec-list li { padding: var(--s-2) var(--s-3); border: 1px solid rgba(210, 153, 34, 0.3); border-radius: var(--r); background: rgba(210, 153, 34, 0.06); }
.sec-note { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); font-size: 13px; }
.sec-note-name { font-weight: 600; color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sec-note .muted { font-size: 12px; white-space: nowrap; }
.sec-flags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.flag-chip { padding: 1px 7px; border-radius: 999px; font-size: 11.5px; color: var(--warn-fg); background: rgba(210, 153, 34, 0.14); border: 1px solid rgba(210, 153, 34, 0.35); }
.sec-empty { margin: 0; font-size: 13px; color: var(--text-faint); }
.sec-foot { margin: var(--s-3) var(--s-4) var(--s-4); padding-top: var(--s-3); border-top: 1px solid var(--border-soft); font-size: 12px; line-height: 1.55; color: var(--text-faint); }

/* ---------- answer tab additions ---------- */

.canary-alert {
  display: flex;
  gap: var(--s-3);
  align-items: flex-start;
  margin-bottom: var(--s-4);
  padding: var(--s-3) var(--s-4);
  border: 1px solid rgba(248, 81, 73, 0.55);
  border-left: 4px solid var(--error);
  border-radius: var(--r-lg);
  background: linear-gradient(90deg, rgba(248, 81, 73, 0.16), rgba(248, 81, 73, 0.06));
  animation: fade-in var(--t-slow) var(--ease);
}
.canary-icon { color: var(--error); margin-top: 2px; }
.canary-title { font-weight: 600; color: #ffa198; font-size: 14px; }
.canary-alert p { margin: 2px 0 0; font-size: 13px; line-height: 1.55; color: var(--text); }

.answer-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-4);
  margin-top: var(--s-4);
  padding-top: var(--s-3);
  border-top: 1px solid var(--border-soft);
}
.quarantine-note {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 4px 10px;
  border-radius: var(--r);
  border: 1px solid rgba(210, 153, 34, 0.45);
  background: rgba(210, 153, 34, 0.1);
  color: var(--warn-fg);
  font-size: 12.5px;
}
.quarantine-note span { color: var(--text); }
.quarantine-note b { font-weight: 600; color: var(--warn-fg); }
.feedback { display: inline-flex; align-items: center; gap: var(--s-2); }
.feedback-label { font-size: 12.5px; color: var(--text-muted); margin-right: 2px; }
.vote {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 12.5px;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast), color var(--t-fast);
}
.vote:hover:not(:disabled) { border-color: #484f58; color: var(--text-strong); background: var(--raised-2); }
.vote-emoji { font-size: 14px; line-height: 1; }
.vote:disabled { cursor: default; opacity: 0.45; }
.vote.is-pending { opacity: 0.8; }
.vote.is-selected, .vote.is-selected:disabled { opacity: 1; color: var(--text-strong); border-color: var(--accent-fg); background: rgba(31, 111, 235, 0.18); }
.vote.is-selected[data-value="-1"] { border-color: rgba(248, 81, 73, 0.6); background: rgba(248, 81, 73, 0.12); }

/* ---------- retrieval tab additions ---------- */

.mono { font-family: var(--mono); font-size: 12px; }
.badge-accent { color: var(--accent-fg); background: rgba(31, 111, 235, 0.15); border-color: rgba(31, 111, 235, 0.45); }
.queries-card .card-head .muted:last-child { font-size: 12px; }
.query-list { list-style: none; margin: 0; padding: var(--s-3) var(--s-4); display: flex; flex-direction: column; gap: 8px; }
.query-list li { display: grid; grid-template-columns: 22px 92px minmax(0, 1fr); align-items: baseline; gap: var(--s-2); font-size: 13.5px; }
.q-kind { font-size: 11.5px; color: var(--text-faint); white-space: nowrap; }
.q-text { color: var(--text-strong); overflow-wrap: anywhere; }
.query-list li.is-passage, .query-list li.is-hyde-q { grid-template-columns: 22px 210px minmax(0, 1fr); }
.query-list li.is-passage .q-text { font-size: 13px; line-height: 1.6; color: var(--text); font-style: italic; }
.q-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font: 700 10.5px/1 var(--font);
  color: var(--header);
  background: var(--c);
  flex: none;
}
.c-found { width: 92px; white-space: nowrap; }
.c-found .q-dot { width: 16px; height: 16px; font-size: 10px; margin-right: 3px; }
.refine-error { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-4); font-size: 13px; color: var(--warn-fg); }
.refine-error code { font-size: 12px; color: var(--text); }

.chip-quarantine { color: #ffa198; border-color: rgba(248, 81, 73, 0.5); background: rgba(248, 81, 73, 0.1); }
.chip-quarantine b { color: #ffa198; }
.rank-table tr.row.is-quarantined { background: rgba(248, 81, 73, 0.07); box-shadow: inset 3px 0 0 var(--error); }
.rank-table tr.row.is-quarantined:hover { background: rgba(248, 81, 73, 0.11); }
.rank-table tr.row.is-quarantined .note-title { color: #ffa198; }
.rank-table tr.row.is-quarantined .stack { opacity: 0.45; }
.q-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  padding: 1px 8px 1px 6px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  color: #ffa198;
  background: rgba(248, 81, 73, 0.14);
  border: 1px solid rgba(248, 81, 73, 0.5);
  cursor: help;
}
.q-badge::after {
  content: attr(data-tip);
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 20;
  width: max-content;
  max-width: 360px;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r);
  background: var(--raised-2);
  border: 1px solid var(--border);
  box-shadow: 0 12px 28px rgba(1, 4, 9, 0.7);
  color: var(--text);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  white-space: normal;
  opacity: 0;
  transform: translateY(-3px);
  pointer-events: none;
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease);
}
.q-badge:hover::after, .q-badge:focus-visible::after { opacity: 1; transform: none; }
.table-card:has(.q-badge) { overflow: visible; }
.q-badge-soft { color: var(--warn-fg); background: rgba(210, 153, 34, 0.1); border-color: rgba(210, 153, 34, 0.4); }
.chunk-flags { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-2); font-size: 12.5px; color: #ffa198; }
.chunk-flags b { font-weight: 600; }
.rank-table tr.detail.is-quarantined .chunk { border-color: rgba(248, 81, 73, 0.4); }

/* ---------- prompt tab additions ---------- */

.src-tag { color: color-mix(in srgb, var(--c) 65%, var(--text-faint)); }
.canary-mark { padding: 0 4px; border-radius: var(--r-sm); color: var(--warn-fg); background: rgba(210, 153, 34, 0.14); border: 1px dashed rgba(210, 153, 34, 0.5); cursor: help; }

.canary-mark { white-space: nowrap; }
.prose .canary-mark { font-family: var(--mono); font-size: 0.86em; }
.warn-text { color: var(--warn-fg); }

.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin-bottom: var(--s-4);
  border-radius: var(--r-lg);
  color: var(--accent-fg);
  background: rgba(31, 111, 235, 0.12);
  border: 1px solid rgba(31, 111, 235, 0.35);
}

/* ops: outcomes card and full-width security panel */
.outcomes { padding: var(--s-4); }
.o-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--bg); border: 1px solid var(--border-soft); }
.o-bar i { display: block; height: 100%; }
.o-bar i + i { box-shadow: -1px 0 0 var(--raised); }
.o-bar-thin { height: 8px; }
.o-ok { background: var(--kw); }
.o-muted { background: var(--text-faint); }
.o-warn { background: var(--warn); }
.o-err { background: var(--error); }
.o-legends { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); margin-top: var(--s-2); }
.o-legend { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-muted); }
.o-legend i { width: 8px; height: 8px; border-radius: 2px; }
.o-legend b { color: var(--text-strong); font-weight: 600; font-variant-numeric: tabular-nums; }
.o-sub { margin-top: var(--s-5); }
.sec-cols { display: grid; grid-template-columns: 1fr 1fr; }
.sec-cols > .sec-section + .sec-section { border-left: 1px solid var(--border-soft); }
.sec-cols > .sec-section { padding-bottom: var(--s-2); }
.q-table td.q-num { white-space: nowrap; }

/* ---------- history additions ---------- */

.h-mode { margin-left: 6px; padding: 0 5px; border-radius: var(--r-sm); background: var(--border-soft); color: var(--text-muted); }

/* ---------- error modal ---------- */

.modal {
  width: 480px;
  max-width: calc(100vw - 32px);
  padding: 0;
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: 0 24px 64px rgba(1, 4, 9, 0.85);
}
.modal[open] { animation: pop-in var(--t-slow) var(--ease); }
.modal::backdrop { background: rgba(1, 4, 9, 0.7); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--border-soft); }
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-strong); }
.modal-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--r-lg);
  color: var(--error);
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid rgba(248, 81, 73, 0.35);
}
.modal-body { padding: var(--s-4) var(--s-5); }
.modal-code { display: flex; align-items: center; gap: var(--s-3); }
.modal-code code { font-size: 12.5px; padding: 2px 8px; border-radius: var(--r-sm); color: #ff7b72; background: rgba(248, 81, 73, 0.1); }
.modal-detail { margin: var(--s-3) 0 0; font-size: 13.5px; line-height: 1.6; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.modal-foot { display: flex; justify-content: flex-end; padding: var(--s-3) var(--s-5) var(--s-4); }

/* ---------- motion ---------- */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes ping { 0% { transform: scale(0.6); opacity: 0.9; } 100% { transform: scale(1.4); opacity: 0; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes fade-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes nudge { 50% { transform: translateX(2px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

/* Ops ingest panel and Summary passages in the preview card */
.ingest-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ingest-table td, .ingest-table th { padding: 4px 8px; text-align: left; }
.ingest-table th { color: var(--text-muted); font-weight: 600; }
.ingest-bad { color: var(--err, #f85149); }
.pc-summary { margin: 0; padding-left: 18px; }

/* Transcripts tab */
.t-row { cursor: pointer; }
.transcript { padding: var(--s-3); }
.seg { margin: .35rem 0; }
.seg.dropped { opacity: .45; text-decoration: line-through; }
.seg-reason { font-size: .8em; margin-left: .5rem; }
mark.fix { background: var(--mark-bg); }
mark.fix.review { outline: 1px dashed currentColor; }
.link { border-bottom: 1px dotted currentColor; }
.review-row { display: flex; gap: .5rem; align-items: center; margin: .3rem 0; padding: 0 var(--s-3); }

/* Graph tab (Cytoscape styling lives in graph.js; these classes serve the legend and the plain-list fallback) */
.kind-incident { --kind: #58a6ff; } .kind-operator { --kind: #d2a8ff; } .kind-facility { --kind: #7ee787; }
.kind-county { --kind: #ffa657; } .kind-state { --kind: #e3b341; } .kind-cause { --kind: #ff7b72; }
.kind-commodity { --kind: #56d4dd; } .kind-transcript { --kind: #f778ba; }
.graph-card { padding: var(--s-3); }
.graph-search { display: flex; gap: var(--s-2); }
.graph-search input { flex: 1; min-width: 0; }
.graph-results { list-style: none; margin: var(--s-2) 0 0; padding: 0; }
.graph-result { cursor: pointer; padding: 4px 6px; border-radius: 4px; }
.graph-result:hover, .graph-result:focus { background: var(--raised-2); outline: none; }
.graph-main { display: flex; gap: var(--s-3); align-items: flex-start; }
.graph-canvas-card { flex: 1; min-width: 0; }
.graph-canvas { height: 520px; }
.graph-msg { padding: var(--s-3); }
.graph-plain { padding: var(--s-3); overflow: auto; height: 100%; }
.graph-plain h4 { margin: var(--s-2) 0 var(--s-1); }
.graph-details { width: 300px; flex: none; padding: var(--s-3); max-height: 560px; overflow: auto; }
.graph-legend { display: flex; flex-wrap: wrap; gap: var(--s-3); padding: var(--s-2) var(--s-3); font-size: 12px; color: var(--text-muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; display: inline-block; border-radius: 50%; background: var(--kind); }
.legend-item .kind-operator { border-radius: 2px; }
.legend-item .kind-facility { border-radius: 3px; }
.legend-item .kind-county, .legend-item .kind-state { transform: rotate(45deg); border-radius: 0; }
.legend-item .kind-cause { clip-path: polygon(50% 0, 100% 100%, 0 100%); border-radius: 0; }
.legend-item .kind-transcript { border-radius: 0 50% 50% 0; }
@media (max-width: 900px) { .graph-main { flex-direction: column; } .graph-details { width: auto; max-height: none; } }

/* ---------- voice ---------- */
.query-input { display: flex; align-items: flex-start; gap: var(--s-2); }
.query-input textarea { flex: 1; }
.voice-help-btn {
  width: 22px; height: 22px; margin-top: 4px; padding: 0;
  border: 1px solid var(--border); border-radius: 50%;
  background: transparent; color: var(--text-faint); cursor: pointer;
  font: 600 12px/1 var(--font);
  transition: color var(--t) var(--ease), border-color var(--t) var(--ease);
}
.voice-help-btn:hover { color: var(--text-strong); border-color: #484f58; }
/* Positioned under the ? by main.js; the top layer keeps it above everything. */
.voice-help {
  position: fixed; inset: auto; margin: 0;
  width: 360px; max-width: calc(100vw - 16px);
  padding: var(--s-3) var(--s-4);
  background: var(--raised); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: 0 16px 40px rgba(1, 4, 9, 0.8), 0 0 0 1px rgba(1, 4, 9, 0.4);
  font-size: 13px; line-height: 1.5;
}
.voice-help h2 { margin: 0 0 var(--s-2); font-size: 14px; color: var(--text-strong); }
.voice-help h3 { margin: var(--s-3) 0 2px; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.voice-help p { margin: 0; }
.voice-help ul { margin: 0; padding-left: 18px; }
.mic-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: 999px;
  background: transparent; color: var(--text-muted); cursor: pointer;
  transition: color var(--t) var(--ease), border-color var(--t) var(--ease), background var(--t) var(--ease);
}
.mic-btn:hover:not(:disabled) { color: var(--text-strong); border-color: #484f58; }
.mic-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.mic-btn[data-state="recording"] { color: #fff; background: var(--error); border-color: var(--error); animation: mic-pulse 1.2s ease-in-out infinite; }
.mic-btn[data-state="transcribing"] { color: var(--accent-fg); }
.mic-btn[data-state="transcribing"] svg { animation: blink 1s step-start infinite; }
.mic-timer { font: 12px/1 var(--mono, ui-monospace, monospace); font-variant-numeric: tabular-nums; }
.mic-note { margin: 0; font-size: 12px; color: var(--warn-fg); }
.speak-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); cursor: pointer; white-space: nowrap; }
.speak-toggle input { accent-color: var(--accent); }
.speak-toggle:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }
@keyframes mic-pulse { 50% { box-shadow: 0 0 0 4px rgba(248, 81, 73, 0.25); } }
