/* Tool call pipeline (v3 causal pair workbench) */

:root {
  --bg: #F3F5F8;
  --surface: #FFFFFF;
  --well: #F8FAFC;
  --ink: #0B1220;
  --muted: #475569;
  --border: #CBD5E1;
  --hairline: #E2E8F0;
  --accent: #1D4ED8;
  --accent-tint: #DCE6FF;
  --on-ink: #FFFFFF;
  --on-ink-muted: #A9B4C6;
  --on-ink-border: #334155;

  --emerald: #047857;
  --emerald-bg: #D1FAE5;
  --amber: #9A4706;
  --amber-bg: #FEF3C7;
  --crimson: #BE123C;
  --crimson-bg: #FFE4E6;

  --font-ui: "Space Grotesk", system-ui, sans-serif;
  --font-code: "JetBrains Mono", ui-monospace, monospace;
  --text-brand: 1.375rem;
  --text-heading: 1.125rem;
  --text-body: 0.9375rem;
  --text-sm: 0.8125rem;
  --code-lh: 1.6;

  --r-ctl: 6px;
  --r-pane: 10px;
  --pad: 24px;
  --gap: 16px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --t-fast: 140ms;
  --t-med: 220ms;
  --focus: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
  --focus-ink: 0 0 0 2px var(--ink), 0 0 0 4px var(--on-ink);
}

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

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-body);
  font-weight: 500;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

body.is-workbench {
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: 56px 56px 76px minmax(0, 1fr);
}

body.is-workbench > * {
  min-width: 0;
}

body.is-compare {
  min-height: 100dvh;
  height: auto;
  overflow-y: auto;
  display: block;
}

button,
input,
textarea {
  font-family: var(--font-ui);
  font-size: var(--text-body);
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

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

.ico {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: block;
}

/* =========================================================================
   Top bar (56px, ink edge-to-edge)
   ========================================================================= */
.topbar {
  background-color: var(--ink);
  color: var(--on-ink);
  width: 100%;
  min-height: 56px;
}

.topbar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 var(--pad);
  height: 56px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.topbar-row-primary {
  display: contents;
}

.wordmark {
  margin: 0;
  font-size: var(--text-brand);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--on-ink);
  white-space: nowrap;
  order: 1;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  order: 2;
}

.topnav {
  display: flex;
  align-items: stretch;
  gap: 20px;
  height: 56px;
  margin-left: 8px;
  order: 3;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  height: 100%;
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.005em;
  color: var(--on-ink-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  padding-top: 2px;
  white-space: nowrap;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

.nav-link:hover {
  color: var(--on-ink);
  text-decoration: none;
}

.nav-link.is-active {
  color: var(--on-ink);
  border-bottom-color: var(--on-ink);
}

.topbar :focus-visible {
  box-shadow: var(--focus-ink);
}

/* =========================================================================
   Segmented radiogroup controls (never cobalt)
   ========================================================================= */
.seg {
  display: inline-flex;
  align-items: stretch;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--r-ctl);
  overflow: hidden;
  background-color: var(--surface);
  flex-shrink: 0;
}

.seg button {
  border: 0;
  background-color: transparent;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.005em;
  padding: 0 11px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  transition: color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}

.seg button + button {
  border-left: 1px solid var(--border);
}

.seg button:hover {
  color: var(--ink);
  background-color: var(--well);
}

.seg button[aria-checked="true"] {
  background-color: var(--ink);
  color: var(--on-ink);
}

.seg-ink {
  border-color: var(--on-ink-border);
  background-color: transparent;
}

.seg-ink button {
  color: var(--on-ink-muted);
}

.seg-ink button + button {
  border-left-color: var(--on-ink-border);
}

.seg-ink button:hover {
  color: var(--on-ink);
  background-color: var(--on-ink-border);
}

.seg-ink button[aria-checked="true"] {
  background-color: var(--on-ink);
  color: var(--ink);
}

/* =========================================================================
   Model rail (56px, 8 curated 2-line tabs + More (5) popover + cobalt underline)
   ========================================================================= */
.model-rail {
  position: relative;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 56px;
  width: 100%;
}

.rail-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 var(--pad);
  height: 100%;
}

.rail-scroll {
  position: relative;
  display: flex;
  align-items: stretch;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}

.rail-scroll::-webkit-scrollbar {
  display: none;
}

.rail-tab {
  position: relative;
  border: 0;
  background-color: transparent;
  color: var(--muted);
  font-size: var(--text-body);
  font-weight: 500;
  padding: 0 12px;
  height: 55px;
  white-space: nowrap;
  flex-shrink: 0;
  scroll-snap-align: start;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  text-align: left;
  transition: color var(--t-fast) var(--ease);
}

.rail-name {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  font-size: var(--text-body);
  font-weight: 500;
  line-height: 1.2;
  color: var(--muted);
  transition: color var(--t-fast) var(--ease);
}

.rail-name::after {
  content: attr(data-label);
  font-weight: 600;
  height: 0;
  visibility: hidden;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
}

.rail-sub {
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.2;
  color: var(--muted);
  transition: color var(--t-fast) var(--ease);
}

.rail-tab:hover .rail-name {
  color: var(--ink);
}

.rail-tab[aria-selected="true"] .rail-name,
.rail-more.is-active .rail-name {
  color: var(--ink);
  font-weight: 600;
}

.rail-tab[aria-selected="true"] .rail-sub,
.rail-more.is-active .rail-sub {
  color: var(--accent);
}

.rail-more {
  margin-left: auto;
}

.rail-indicator {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 1px;
  background-color: var(--accent);
  transform-origin: left center;
  transform: translateX(0) scaleX(0);
  transition: transform var(--t-med) var(--ease);
  pointer-events: none;
}

.more-menu {
  position: fixed;
  z-index: 30;
  min-width: 280px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pane);
  padding: 6px;
  box-shadow: 0 10px 28px rgba(11, 18, 32, 0.12);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.more-item {
  width: 100%;
  border: 0;
  background-color: transparent;
  border-radius: var(--r-ctl);
  padding: 8px 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  text-align: left;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.more-item:hover {
  background-color: var(--well);
}

.more-item.is-current {
  background-color: var(--accent-tint);
}

.more-item-name {
  font-size: var(--text-body);
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
}

.more-item.is-current .more-item-name {
  color: var(--accent);
  font-weight: 600;
}

.more-item-sub {
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--muted);
  white-space: nowrap;
}

/* =========================================================================
   Pipeline track (76px = 10px top/bottom padding around 56px 2-line steps)
   ========================================================================= */
.track-bar {
  background-color: var(--bg);
  height: 76px;
  width: 100%;
}

.track-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 10px var(--pad);
  height: 100%;
}

.track-list {
  list-style: none;
  margin: 0;
  padding: 0;
  height: 56px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22px minmax(0, 1fr) 22px minmax(0, 1fr) 22px minmax(0, 1fr) 22px minmax(0, 1fr);
  align-items: center;
}

.track-item {
  min-width: 0;
  height: 56px;
  display: flex;
}

.track-btn {
  width: 100%;
  min-width: 0;
  height: 56px;
  border: 0;
  border-radius: var(--r-ctl);
  background-color: transparent;
  padding: 6px 12px;
  text-align: left;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.track-btn:hover {
  background-color: var(--surface);
}

.track-label {
  display: block;
  max-width: 100%;
  font-size: var(--text-body);
  font-weight: 600;
  line-height: 1.3;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-num {
  display: inline;
}

.track-sig {
  display: block;
  max-width: 100%;
  font-family: var(--font-code);
  font-size: var(--text-sm);
  font-weight: 400;
  line-height: 1.35;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-btn.is-visited .track-label {
  color: var(--ink);
}

.track-btn[aria-selected="true"] {
  background-color: var(--accent);
}

.track-btn[aria-selected="true"] .track-label,
.track-btn[aria-selected="true"] .track-sig {
  color: var(--on-ink);
}

.track-sep {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--border);
}

.track-sep svg {
  width: 18px;
  height: 12px;
  display: block;
}

/* =========================================================================
   Workbench stage (minmax(0, 1fr) with internal scrolling panes + 64px footer)
   ========================================================================= */
.workbench {
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--pad);
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 64px;
}

.workbench[hidden],
.compare-view[hidden] {
  display: none;
}

.stage-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px minmax(0, 1fr);
  align-items: stretch;
}

.gutter {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.gutter-arrow {
  width: 24px;
  height: 24px;
  display: block;
}

/* =========================================================================
   Panes (the ONLY bordered container in the stage)
   ========================================================================= */
.pane {
  min-width: 0;
  min-height: 0;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pane);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pane-head {
  min-height: 48px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  background-color: var(--surface);
}

.pane-head-text {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.pane-title {
  margin: 0;
  font-size: var(--text-heading);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
  color: var(--ink);
}

.model-identity {
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0.005em;
  color: var(--muted);
  white-space: nowrap;
}

.pane-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.pane-subrow {
  height: 36px;
  padding: 0 16px;
  border-bottom: 1px solid var(--hairline);
  background-color: var(--surface);
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.pane-subrow[hidden] {
  display: none;
}

.subtabs {
  display: flex;
  align-items: stretch;
  gap: 4px;
  height: 100%;
}

.subtab {
  border: 0;
  border-bottom: 2px solid transparent;
  background-color: transparent;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0.005em;
  padding: 0 10px;
  height: 100%;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

.subtab:hover {
  color: var(--ink);
}

.subtab[aria-selected="true"] {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.text-action {
  border: 0;
  background-color: transparent;
  color: var(--accent);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.005em;
  padding: 4px 6px;
  border-radius: var(--r-ctl);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}

.text-action:hover {
  background-color: var(--well);
}

.text-action.is-muted {
  color: var(--muted);
}

.text-action.is-muted:hover {
  color: var(--ink);
}

.icon-btn {
  border: 1px solid var(--border);
  background-color: var(--surface);
  color: var(--muted);
  height: 32px;
  padding: 0 10px;
  border-radius: var(--r-ctl);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.005em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

.icon-btn:hover {
  color: var(--ink);
  background-color: var(--well);
}

.pane-body {
  flex: 1 1 0;
  min-height: 0;
  overflow: auto;
  background-color: var(--well);
  position: relative;
}

.pane-body.is-split {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.pane-body.enter-fwd {
  animation: pane-fwd 180ms var(--ease) both;
}

.pane-body.enter-back {
  animation: pane-back 180ms var(--ease) both;
}

@keyframes pane-fwd {
  from { opacity: 0; transform: translateX(8px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pane-back {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

/* =========================================================================
   Split regions inside Stage 1 right pane & Stage 5 left pane
   ========================================================================= */
.split-top {
  flex: 0 0 42%;
  min-height: 0;
  overflow: auto;
}

.split-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 20px;
  background-color: var(--surface);
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}

.split-bar-title {
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.005em;
  color: var(--ink);
}

.split-bottom {
  flex: 1 1 58%;
  min-height: 0;
  overflow: auto;
}

.split-half-top {
  flex: 1 1 50%;
  min-height: 0;
  overflow: auto;
}

.split-half-bottom {
  flex: 1 1 50%;
  min-height: 0;
  overflow: auto;
}

/* =========================================================================
   Code surfaces, JSON editor, line numbers, provenance trace
   ========================================================================= */
.code-well {
  margin: 0;
  padding: 16px 20px;
  font-family: var(--font-code);
  font-size: var(--text-sm);
  font-weight: 400;
  line-height: var(--code-lh);
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
}

.editor-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.json-editor {
  flex: 1 1 0;
  min-height: 0;
  overflow: auto;
  outline: none;
  margin: 0;
  padding: 16px 20px;
  font-family: var(--font-code);
  font-size: var(--text-sm);
  font-weight: 400;
  line-height: var(--code-lh);
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
}

.json-editor:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.editor-err {
  padding: 8px 20px;
  border-top: 1px solid var(--hairline);
  background-color: var(--surface);
  color: var(--crimson);
  font-size: var(--text-sm);
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.editor-err[hidden] {
  display: none;
}

/* JSON syntax coloring: ink (keys), muted (punctuation), accent (strings) */
.jk { color: var(--ink); font-weight: 500; }
.jp { color: var(--muted); }
.js { color: var(--accent); }
.jn { color: var(--ink); }
.jc { color: var(--muted); }
.jd { color: var(--accent); font-weight: 500; }

/* Semantic spans inside prompt / tokens / response */
.tok {
  color: var(--amber);
  background-color: var(--amber-bg);
  border-radius: 3px;
  padding: 0 3px;
  font-weight: 500;
}

.tok-call {
  color: var(--emerald);
  background-color: var(--emerald-bg);
  border-radius: 3px;
  padding: 0 3px;
  font-weight: 600;
}

.tok-stop {
  color: var(--amber);
  background-color: var(--amber-bg);
  border-radius: 3px;
  padding: 0 3px;
  font-weight: 600;
}

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

.tok-marker {
  color: var(--emerald);
  font-weight: 500;
}

.tok-arg {
  color: var(--emerald);
  background-color: var(--emerald-bg);
  border-radius: 3px;
  padding: 0 2px;
}

.tok-drop {
  color: var(--crimson);
  background-color: var(--crimson-bg);
  text-decoration: line-through;
  border-radius: 3px;
  padding: 0 2px;
}

.tok-arrive {
  animation: tok-fade 160ms var(--ease) both;
}

@keyframes tok-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Unified 4-role semantic tool-text coloring (Stage 1 + Prompt regions) */
.r-name { color: var(--accent); font-weight: 600; }
.r-param { color: var(--ink); font-weight: 600; }
.r-desc { color: var(--accent); font-weight: 400; }
.r-cons { color: var(--emerald); font-weight: 500; }
.r-key { color: var(--muted); font-weight: 400; }
.r-env { color: var(--ink); font-weight: 400; }
.r-scaf { color: var(--muted); }
.r-xml { color: var(--emerald); font-weight: 500; }

/* Interactive provenance spans */
.tr-span {
  border-radius: 2px;
  transition: background-color var(--t-fast) var(--ease);
}

.tr-span[data-path] {
  cursor: pointer;
}

.tr-span.is-lit {
  background-color: var(--accent-tint);
  color: var(--ink);
  box-shadow: inset 2px 0 0 0 var(--accent);
}

.tr-span.is-dropped {
  background-color: var(--crimson-bg);
  color: var(--crimson);
  text-decoration: line-through;
}

/* Line-numbered source code (templates & engine parsers) */
.code-lines {
  padding: 12px 0;
  font-family: var(--font-code);
  font-size: var(--text-sm);
  font-weight: 400;
  line-height: var(--code-lh);
}

.cl {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  padding: 0 20px 0 0;
  position: relative;
}

.cl-n {
  user-select: none;
  text-align: right;
  padding-right: 14px;
  color: var(--muted);
}

.cl-t {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--ink);
}

.cl.hl {
  background-color: var(--accent-tint);
}

.cl.hl .cl-n {
  color: var(--accent);
  font-weight: 600;
}

.diff-flash {
  position: relative;
}

.diff-flash::before {
  content: "";
  position: absolute;
  inset: 0;
  background-color: var(--accent-tint);
  pointer-events: none;
  animation: line-flash 600ms var(--ease) forwards;
}

@keyframes line-flash {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* =========================================================================
   Annotated prompt regions & fields drawer
   ========================================================================= */
.region {
  padding: 12px 20px;
  border-bottom: 1px solid var(--hairline);
}

.region:last-child {
  border-bottom: 0;
}

.region-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.region-label {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.005em;
  color: var(--muted);
}

.region-sub {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--muted);
}

.region-code {
  margin: 0;
  font-family: var(--font-code);
  font-size: var(--text-sm);
  font-weight: 400;
  line-height: var(--code-lh);
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.pane-drawer {
  border-bottom: 1px solid var(--hairline);
  background-color: var(--surface);
  max-height: 210px;
  overflow: auto;
  flex-shrink: 0;
}

.pane-drawer[hidden] {
  display: none;
}

.fields-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.fields-table th,
.fields-table td {
  text-align: left;
  padding: 7px 16px;
  border-bottom: 1px solid var(--hairline);
  vertical-align: top;
}

.fields-table th {
  font-weight: 600;
  color: var(--muted);
  background-color: var(--well);
  position: sticky;
  top: 0;
}

.fields-table tr:last-child td {
  border-bottom: 0;
}

.fields-row {
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease);
}

.fields-row:hover {
  background-color: var(--well);
}

.fields-row.is-lit {
  background-color: var(--accent-tint);
}

.field-path {
  font-family: var(--font-code);
  color: var(--ink);
}

.st-kept {
  color: var(--emerald);
  font-weight: 600;
}

.st-rewritten {
  color: var(--amber);
  font-weight: 600;
}

.st-dropped {
  color: var(--crimson);
  font-weight: 600;
}

/* =========================================================================
   Stage 3 verdict & Stage 4 engine parser excerpts / parse steps
   ========================================================================= */
.verdict-bar {
  border-top: 1px solid var(--hairline);
  background-color: var(--surface);
  padding: 12px 20px;
  font-size: var(--text-sm);
  color: var(--ink);
  line-height: 1.5;
  flex-shrink: 0;
}

.verdict-bar code {
  font-family: var(--font-code);
  font-size: var(--text-sm);
}

.excerpt-block {
  border-bottom: 1px solid var(--hairline);
}

.excerpt-block:last-child {
  border-bottom: 0;
}

.excerpt-head {
  padding: 12px 20px 8px;
  background-color: var(--surface);
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.excerpt-link {
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}

a.excerpt-link {
  color: var(--accent);
}

.excerpt-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.excerpt-lines {
  font-family: var(--font-code);
  font-size: var(--text-sm);
  color: var(--muted);
}

.excerpt-note {
  margin: 0;
  padding: 8px 20px 0;
  font-size: var(--text-sm);
  color: var(--muted);
}

.steps-section {
  padding: 14px 20px 16px;
  background-color: var(--surface);
  border-top: 1px solid var(--hairline);
}

.steps-heading {
  margin: 0 0 8px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink);
}

.parse-steps {
  margin: 0;
  padding-left: 20px;
  font-size: var(--text-sm);
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.parse-steps code {
  font-family: var(--font-code);
  font-size: var(--text-sm);
  color: var(--ink);
}

.plain-note {
  margin: 0;
  padding: 20px;
  font-size: var(--text-body);
  color: var(--muted);
  max-width: 65ch;
}

.pane-foot-meta {
  padding: 12px 20px;
  border-top: 1px solid var(--hairline);
  background-color: var(--surface);
  font-size: var(--text-sm);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.pane-foot-meta a {
  color: var(--muted);
  text-decoration: underline;
}

.pane-foot-meta a:hover {
  color: var(--accent);
}

/* =========================================================================
   Stage footer (64px, single .cta button)
   ========================================================================= */
.stage-footer {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.footer-summary {
  margin: 0;
  font-size: var(--text-body);
  font-weight: 500;
  color: var(--ink);
  max-width: 90ch;
  line-height: 1.4;
}

.footer-summary code {
  font-family: var(--font-code);
  font-size: var(--text-sm);
}

.footer-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.btn-back {
  border: 0;
  background-color: transparent;
  color: var(--muted);
  font-size: var(--text-body);
  font-weight: 600;
  padding: 8px 10px;
  border-radius: var(--r-ctl);
  transition: color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}

.btn-back:hover {
  color: var(--ink);
  background-color: var(--surface);
}

.btn-back[hidden] {
  display: none;
}

.cta {
  height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--r-ctl);
  background-color: var(--accent);
  color: var(--on-ink);
  font-size: var(--text-body);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  transition: background-color var(--t-fast) var(--ease);
}

.cta:hover {
  background-color: var(--ink);
}

/* =========================================================================
   Compare models view (native page scroll)
   ========================================================================= */
.compare-view {
  width: 100%;
  padding: var(--pad);
}

.compare-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.compare-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.compare-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.compare-title {
  margin: 0;
  font-size: var(--text-heading);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
  color: var(--ink);
}

.compare-table-wrap {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pane);
  overflow-x: auto;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.compare-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.compare-table tbody tr {
  border-bottom: 1px solid var(--hairline);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease);
}

.compare-table tbody tr:last-child {
  border-bottom: 0;
}

.compare-table tbody tr:hover {
  background-color: var(--well);
}

.compare-table tbody tr.is-current {
  background-color: var(--accent-tint);
}

.compare-table td {
  padding: 12px 16px;
  vertical-align: top;
  min-height: 56px;
}

.cmp-model-name {
  display: block;
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.cmp-model-sub {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

.cmp-code {
  margin: 0;
  font-family: var(--font-code);
  font-size: var(--text-sm);
  font-weight: 400;
  line-height: 1.45;
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-width: 38ch;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cmp-stop {
  font-family: var(--font-code);
  font-size: var(--text-sm);
  color: var(--amber);
  background-color: var(--amber-bg);
  border-radius: 3px;
  padding: 1px 5px;
  white-space: nowrap;
}

.cmp-status-ok {
  font-size: var(--text-body);
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
}

.cmp-status-drop {
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--crimson);
  white-space: nowrap;
}

.cmp-dropped-list {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--crimson);
  margin-top: 2px;
}

.repo-footer {
  font-size: var(--text-sm);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 4px 0 16px;
}

.repo-footer a {
  color: var(--muted);
  text-decoration: underline;
}

.repo-footer a:hover {
  color: var(--accent);
}

@media (max-width: 1140px) {
  .topbar-inner {
    gap: 12px;
  }

  .topbar-controls {
    gap: 8px;
  }

  .topnav {
    gap: 14px;
    margin-left: 4px;
  }

  .seg button {
    padding: 0 9px;
  }
}

/* =========================================================================
   Responsive: < 1024px (native scroll, stacked panes, two-row topbar)
   ========================================================================= */
@media (max-width: 1023px) {
  :root {
    --pad: 16px;
  }

  body.is-workbench {
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
    display: block;
  }

  .topbar-inner {
    height: auto;
    padding: 0 var(--pad);
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }

  .topbar-row-primary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    gap: 12px;
  }

  .topnav {
    height: 48px;
    margin-left: 0;
  }

  .topbar-controls {
    margin-left: 0;
    height: 48px;
    border-top: 1px solid var(--on-ink-border);
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .topbar-controls::-webkit-scrollbar {
    display: none;
  }

  .workbench {
    display: block;
    padding-bottom: 16px;
  }

  .stage-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .gutter {
    height: 32px;
  }

  .gutter-arrow {
    transform: rotate(90deg);
  }

  .pane-body {
    flex: 0 1 auto;
    max-height: 55dvh;
  }

  .pane-body.is-split {
    flex: 0 1 auto;
    height: 56dvh;
    max-height: 60dvh;
  }

  .editor-wrap {
    height: auto;
    max-height: 55dvh;
  }

  .json-editor {
    flex: 0 1 auto;
    min-height: 220px;
    max-height: 48dvh;
  }

  .stage-footer {
    height: auto;
    padding: 16px 0 8px;
    flex-wrap: wrap;
  }
}

/* =========================================================================
   Responsive: < 640px (390x844 mobile)
   ========================================================================= */
@media (max-width: 639px) {
  .topbar-controls {
    gap: 6px;
  }

  .seg button {
    padding: 0 7px;
  }

  .track-bar {
    height: auto;
  }

  .track-inner {
    padding: 8px var(--pad);
  }

  .track-list {
    height: auto;
    display: flex;
    align-items: stretch;
    gap: 4px;
  }

  .track-sep {
    display: none;
  }

  .track-item {
    height: 48px;
    flex: 0 0 auto;
  }

  .track-item.is-active {
    flex: 1 1 0;
    min-width: 0;
  }

  .track-btn {
    height: 48px;
    min-width: 36px;
    padding: 6px 10px;
    align-items: center;
    justify-content: center;
  }

  .track-item.is-active .track-btn {
    align-items: flex-start;
  }

  .track-item:not(.is-active) .track-text,
  .track-item:not(.is-active) .track-sig {
    display: none;
  }

  .pane-head {
    flex-wrap: wrap;
    padding: 10px 12px;
  }

  .stage-footer {
    position: sticky;
    bottom: 0;
    z-index: 5;
    background-color: var(--surface);
    border-top: 1px solid var(--border);
    margin: 12px calc(var(--pad) * -1) -16px;
    padding: 12px var(--pad);
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .footer-actions {
    width: 100%;
  }

  .cta {
    flex: 1 1 auto;
    width: 100%;
  }

  .compare-view {
    padding: 16px;
  }
}

/* =========================================================================
   Reduced motion kill-switch
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
