/**
 * AgentVerse UI Styles
 *
 * Colours come from ../../common/css/theme.css (shared light / dark tokens) plus the role
 * tokens below: light in :root, dark in :root[data-theme="dark"] (the original look).
 */

/* ─── Role tokens ──────────────────────────────────────────────────────────── */
:root {
  --primary: var(--accent);
  --primary-light: var(--accent-text);
  --success: var(--green);
  --warning: var(--orange);
  --error: var(--red);
  --bg-dark: var(--bg-inset);        /* wells inside cards */
  --bg-card: var(--bg-secondary);

  --strip-bg: #ffffff;               /* status bar on the page background */
  --strip-ring: inset 0 0 0 1px #e0dfd9;
  --btn-disabled-bg: #e4e3de;
  --btn-disabled-fg: #7a7d85;
  --btn-secondary-hover: #efefeb;
  --tab-bg: #ffffff;
  --tab-bg-hover: #efefeb;
  --tab-badge-bg: rgba(26, 28, 33, 0.08);
  --stage-active-glow: 0 0 0 3px #e9eef6;
  --badge-running-bg: #e9eef6;  --badge-running-fg: #1f3a68;
  --badge-complete-bg: #e8f3ec; --badge-complete-fg: #1d7a3e;
  --badge-error-bg: #fbeae8;    --badge-error-fg: #b42318;
  --feedback-bg: #f1f4f9;
  --feedback-border: #c3cfe2;
  --legend-chip-bg: #ffffff;
  --empty-icon-filter: grayscale(1) opacity(0.4);

  /* Topology diagram: agent colours (validated, light, adjacent pairs; nodes are also labelled) */
  --topo-bg: #ffffff;
  --topo-header-bg: #fafaf8;
  --topo-edge: #b9b8b0;
  --topo-arrow: #8f9098;
  --topo-active: #1f3a68;
  --topo-active-ring: #1f3a68;
  --topo-active-glow: rgba(31, 58, 104, 0.35);
  --topo-node-fill-opacity: 0.16;
  --topo-node-ink: #1a1c21;
  --agent-1: #256abf;
  --agent-2: #d95926;
  --agent-3: #199e70;
  --agent-4: #c98500;
  --agent-5: #d55181;
  --agent-6: #008300;
  --agent-7: #4a3aa7;

  /* LLM-call stages (flow graph edges / nodes; validated, light, adjacent pairs) */
  --stage-recruitment: #256abf;
  --stage-decision: #d95926;
  --stage-execution: #199e70;
  --stage-evaluation: #4a3aa7;
  --stage-synthesis: #c98500;
  --stage-unknown: #6c707a;
  --flow-node-fill: #ffffff;           /* light: ringed nodes, dark number */
  --flow-node-stroke: currentColor;
  --flow-node-ink: #1a1c21;
  --flow-arrow: #6c707a;               /* arrowheads (marker fill: currentColor) */
  --stage-badge-recruitment-bg: #e7eef8; --stage-badge-recruitment-fg: #1c4f8f;
  --stage-badge-decision-bg: #fbece4;    --stage-badge-decision-fg: #9c3c17;
  --stage-badge-execution-bg: #e2f2eb;   --stage-badge-execution-fg: #11654a;
  --stage-badge-evaluation-bg: #ecebf6;  --stage-badge-evaluation-fg: #3d318a;
  --stage-badge-synthesis-bg: #f7efdb;   --stage-badge-synthesis-fg: #7d5400;
}

:root[data-theme="dark"] {
  --primary: #2563eb;
  --primary-light: #3b82f6;
  --success: #16a34a;
  --warning: #ca8a04;
  --error: #dc2626;
  --bg-dark: #0f172a;
  --bg-card: #1e293b;

  --strip-bg: #0f172a;
  --strip-ring: none;
  --btn-disabled-bg: #475569;
  --btn-disabled-fg: #ffffff;
  --btn-secondary-hover: #0f172a;
  --tab-bg: rgba(255, 255, 255, 0.08);
  --tab-bg-hover: rgba(255, 255, 255, 0.12);
  --tab-badge-bg: rgba(255, 255, 255, 0.2);
  --stage-active-glow: 0 0 20px rgba(37, 99, 235, 0.2);
  --badge-running-bg: #2563eb;  --badge-running-fg: #ffffff;
  --badge-complete-bg: #16a34a; --badge-complete-fg: #ffffff;
  --badge-error-bg: #dc2626;    --badge-error-fg: #ffffff;
  --feedback-bg: rgba(99, 102, 241, 0.12);
  --feedback-border: rgba(99, 102, 241, 0.3);
  --legend-chip-bg: rgba(15, 23, 42, 0.9);
  --empty-icon-filter: none;

  --topo-bg: #0f172a;
  --topo-header-bg: rgba(255, 255, 255, 0.02);
  --topo-edge: #334155;
  --topo-arrow: #475569;
  --topo-active: #3b82f6;
  --topo-active-ring: #ffffff;
  --topo-active-glow: #3b82f6;
  --topo-node-fill-opacity: 0.85;
  --topo-node-ink: #ffffff;
  --agent-1: #3b82f6;
  --agent-2: #14b8a6;
  --agent-3: #a855f7;
  --agent-4: #f59e0b;
  --agent-5: #ef4444;
  --agent-6: #ec4899;
  --agent-7: #06b6d4;

  --stage-recruitment: #1e40af;
  --stage-decision: #4c1d95;
  --stage-execution: #166534;
  --stage-evaluation: #9a3412;
  --stage-synthesis: #0e7490;
  --stage-unknown: #6366f1;
  --flow-node-fill: currentColor;
  --flow-node-stroke: #0f172a;
  --flow-node-ink: #f1f5f9;
  --flow-arrow: #f1f5f9;
  --stage-badge-recruitment-bg: #1e40af; --stage-badge-recruitment-fg: #93c5fd;
  --stage-badge-decision-bg: #4c1d95;    --stage-badge-decision-fg: #c4b5fd;
  --stage-badge-execution-bg: #166534;   --stage-badge-execution-fg: #86efac;
  --stage-badge-evaluation-bg: #9a3412;  --stage-badge-evaluation-fg: #fdba74;
  --stage-badge-synthesis-bg: #0e7490;   --stage-badge-synthesis-fg: #67e8f9;
}

/* ─── Topology Diagram ─────────────────────────────────────────────────────── */
.topo-diagram {
  margin: 12px 0 8px;
  background: var(--topo-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.topo-diagram-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--topo-header-bg);
  color: var(--text-secondary);
}

.topo-diagram-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.topo-diagram-svg {
  display: block;
  width: 100%;
  max-height: 228px;
}

.topo-diagram-svg .topo-edge { stroke: var(--topo-edge); }
.topo-diagram-svg .topo-arrowhead { fill: var(--topo-arrow); }
.topo-diagram-svg .topo-node circle {
  fill: var(--agent);
  fill-opacity: var(--topo-node-fill-opacity);
  stroke: var(--agent);
  stroke-width: 1.5;
}
.topo-diagram-svg .topo-node-id { fill: var(--topo-node-ink); }
.topo-diagram-svg .topo-node-role { fill: var(--text-secondary); }

/* Live traffic: flashTopologyForRequest() bolds the edge of each LLM call as it lands */
.topo-diagram-svg .topo-edge {
  transition: stroke 0.15s, stroke-width 0.15s, opacity 0.15s;
}

.topo-diagram-svg .topo-edge.topo-active {
  stroke: var(--topo-active);
  stroke-width: 4;
  opacity: 1;
  stroke-dasharray: 10 6;
  animation: topo-flow 0.8s linear infinite;
}

.topo-diagram-svg .topo-node.topo-active circle {
  stroke: var(--topo-active-ring);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 6px var(--topo-active-glow));
}

@keyframes topo-flow {
  from { stroke-dashoffset: 16; }
  to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .topo-diagram-svg .topo-edge.topo-active {
    animation: none;
    stroke-dasharray: none;
  }
}

* { box-sizing: border-box; }

body {
  font-family: var(--font-sans);
  margin: 0;
  padding: 0;
  background: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
}

/* Header */
.header {
  background: var(--header-bg-brand);
  border-bottom: 1px solid var(--header-border);
  color: var(--header-fg);
  padding: 20px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
}

.header h1 {
  margin: 0;
  font-size: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

/* Links rendered by ../common/js/nav.js (incl. the Docs menu button; its panel is styled by
   common/css/site.css) */
.header-links a,
.header-links .site-menu__button {
  color: var(--header-link-fg);
  text-decoration: none;
  padding: 8px 16px;
  border: 0;
  border-radius: 6px;
  background: var(--header-link-bg);
  font: inherit;
  transition: background 0.2s;
}

.header-links a:hover,
.header-links .site-menu__button:hover,
.header-links .site-menu__button[aria-expanded="true"] {
  background: var(--header-link-bg-hover);
  color: var(--header-link-fg);
}

.header-end {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}

@media (max-width: 720px) {
  /* title + theme toggle on the first row, the links below */
  .header { padding: 14px 16px; }
  .header h1 { flex: 1 1 0; min-width: 0; font-size: 21px; }
  .header-end { display: contents; }
  .header .theme-toggle { order: 2; }
  .header-links { order: 3; flex-basis: 100%; gap: 6px; }
  .header-links a,
  .header-links .site-menu__button { padding: 5px 9px; font-size: 14px; }
}

/* Layout */
.container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
}

.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
}

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

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
}

.card h2 {
  margin: 0 0 16px 0;
  font-size: 18px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Form Elements */
button, input, select, textarea { font-family: inherit; }

label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  margin-bottom: 12px;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-glow);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

/* Buttons */
button {
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: var(--on-accent);
}

.btn-primary:hover {
  background: var(--primary-light);
}

.btn-primary:disabled {
  background: var(--btn-disabled-bg);
  color: var(--btn-disabled-fg);
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--btn-secondary-hover);
}

.button-row {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.btn-cancel {
  color: var(--error);
  border-color: var(--error);
}

.btn-cancel:hover {
  background: rgba(220, 38, 38, 0.15);
}

/* Workflow Visualization */
.workflow-panel--cancelled {
  opacity: 0.65;
  pointer-events: none;
}

.workflow-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.workflow-stage {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
  transition: all 0.3s;
}

.workflow-stage.active {
  border-color: var(--primary);
  box-shadow: var(--stage-active-glow);
}

.workflow-stage.completed {
  border-color: var(--success);
}

.workflow-stage.error {
  border-color: var(--error);
}

.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--overlay-1);
  cursor: pointer;
}

.stage-header:hover {
  background: var(--overlay-2);
}

.stage-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 16px;
}

.stage-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.workflow-stage.active .stage-number {
  background: var(--primary);
  color: var(--on-accent);
}

.workflow-stage.completed .stage-number {
  background: var(--success);
  color: #ffffff;
}

.stage-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.stage-status .badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-pending { background: var(--border); color: var(--text-secondary); }
.badge-running { background: var(--badge-running-bg); color: var(--badge-running-fg); }
.badge-complete { background: var(--badge-complete-bg); color: var(--badge-complete-fg); }
.badge-error { background: var(--badge-error-bg); color: var(--badge-error-fg); }

.stage-content {
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: all 0.3s;
}

.stage-content.expanded {
  padding: 20px;
  max-height: 2000px;
}

.stage-details {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Expert Cards */
.expert-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.expert-card {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
}

.expert-role {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
  text-transform: capitalize;
}

.expert-responsibilities {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Discussion Rounds */
.discussion-round {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-dark);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--primary);
}

.round-header {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--primary-light);
}

.round-response {
  margin-top: 8px;
  padding: 8px;
  background: var(--overlay-1);
  border-radius: 6px;
}

.round-response .role {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.round-response .content {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  max-height: 150px;
  overflow-y: auto;
}

/* Execution Results */
.execution-result {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-dark);
  border-radius: var(--radius-md);
}

.execution-result.success {
  border-left: 3px solid var(--success);
}

.execution-result.failure {
  border-left: 3px solid var(--error);
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.result-expert {
  font-weight: 600;
  font-size: 14px;
}

.result-output {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
  font-family: var(--font-mono);
}

/* Evaluation */
.evaluation-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.eval-metric {
  background: var(--bg-dark);
  padding: 16px;
  border-radius: var(--radius-md);
  text-align: center;
}

.eval-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary-light);
}

.eval-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Criteria Breakdown */
.criteria-breakdown {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.criteria-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.criteria-label {
  min-width: 120px;
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
}

.criteria-bar {
  flex: 1;
  position: relative;
  height: 24px;
  background: var(--bg-dark);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
}

.criteria-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  transition: width 0.3s ease;
  opacity: 0.3;
}

.criteria-value {
  position: relative;
  z-index: 1;
  font-size: 13px;
  font-weight: 600;
  padding: 0 8px;
  min-width: 35px;
  text-align: right;
}

/* Final Output */
.final-output {
  background: var(--bg-dark);
  padding: 20px;
  border-radius: var(--radius-md);
  margin-top: 16px;
  border: 1px solid var(--success);
}

.final-output h3 {
  margin: 0 0 12px 0;
  color: var(--success);
  font-size: 16px;
}

.final-output-content {
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
}

.final-output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.final-output-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.final-output-tabs {
  display: flex;
  gap: 4px;
}

.final-output-tab {
  padding: 4px 10px;
  font-size: 12px;
  background: var(--tab-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.final-output-tab:hover {
  background: var(--tab-bg-hover);
  color: var(--text-primary);
}

.final-output-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-accent);
}

.final-output-view-raw {
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.final-output-copy-btn {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
}

/* Progress Indicator */
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin: 16px 0;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s;
}

/* Iteration History Container */
.iteration-history-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Score Progression */
.score-progression {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}

.score-progression-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.score-progression-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.score-progression-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
}

.score-progression-chart {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 120px;
  padding: 8px 0;
}

.score-bar-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.2s;
  padding: 4px;
  border-radius: 4px;
}

.score-bar-container:hover {
  background: var(--accent-tint);
}

.score-bar-container.selected {
  background: var(--accent-tint-2);
}

.score-bar-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.score-bar {
  width: 100%;
  min-height: 8px;
  border-radius: 4px 4px 0 0;
  transition: all 0.3s;
  position: relative;
}

.score-value {
  position: absolute;
  top: -20px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.score-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.score-change {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 4px;
  border-radius: 3px;
}

.score-change.improved {
  color: var(--success);
}

.score-change.worsened {
  color: var(--error);
}

.score-change.unchanged {
  color: var(--text-secondary);
}

/* Iteration Tabs */
.iteration-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.iteration-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.iteration-tab:hover {
  border-color: var(--primary);
  background: var(--accent-tint);
}

.iteration-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-accent);
}

.iteration-tab-icon {
  font-size: 14px;
}

.iteration-tab-number {
  font-weight: 600;
}

.iteration-tab-score {
  font-weight: 500;
  font-size: 12px;
}

.iteration-tab-badge {
  font-size: 10px;
  padding: 2px 6px;
  background: var(--tab-badge-bg);
  border-radius: 3px;
}

/* Iteration Details */
.iteration-details-container {
  position: relative;
  min-height: 200px;
}

.iteration-details {
  display: none;
  animation: fadeIn 0.3s;
}

.iteration-details.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.iteration-header {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}

.iteration-header-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.iteration-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.iteration-score-large {
  font-size: 32px;
  font-weight: 700;
}

.iteration-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

.goal-badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--success);
  color: #ffffff;
}

.goal-badge.failed {
  background: var(--error);
}

/* Iteration Changes */
.iteration-changes {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}

.changes-header {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.changes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.change-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  background: var(--overlay-1);
  border-radius: 6px;
  border-left: 3px solid var(--border);
}

.change-item.improved {
  border-left-color: var(--success);
}

.change-item.worsened {
  border-left-color: var(--error);
}

.change-item.changed {
  border-left-color: var(--warning);
}

.change-label {
  font-weight: 500;
  font-size: 13px;
  color: var(--text-primary);
  flex-shrink: 0;
}

.change-value {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
}

.change-from,
.change-to {
  color: var(--text-secondary);
  overflow-wrap: break-word;
  word-break: break-word;
}

.change-arrow {
  color: var(--text-secondary);
}

.change-indicator {
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 600;
  font-size: 11px;
}

.change-item.improved .change-indicator {
  background: var(--success);
  color: #ffffff;
}

.change-item.worsened .change-indicator {
  background: var(--error);
  color: #ffffff;
}

.change-item.changed .change-indicator {
  background: var(--warning);
  color: #ffffff;
}

.no-changes {
  padding: 12px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  font-style: italic;
}

/* Iteration Evaluation */
.iteration-evaluation {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}

.evaluation-header {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.evaluation-rationale {
  margin-bottom: 16px;
}

.iteration-feedback-section {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--feedback-bg);
  border: 1px solid var(--feedback-border);
  border-radius: var(--radius-md);
}

.iteration-feedback-label {
  font-weight: 600;
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 8px;
}

.iteration-feedback-content {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.6;
}

.iteration-feedback-hint {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 8px;
  font-style: italic;
}

.evaluation-label {
  font-weight: 500;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.evaluation-content {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.6;
  padding: 10px;
  background: var(--overlay-1);
  border-radius: 6px;
}

.evaluation-criteria {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.criteria-item-detailed {
  display: flex;
  align-items: center;
  gap: 12px;
}

.criteria-label-detailed {
  min-width: 120px;
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
}

.criteria-bar-detailed {
  flex: 1;
  position: relative;
  height: 24px;
  background: var(--overlay-2);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
}

.criteria-bar-fill-detailed {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  transition: width 0.3s ease;
  opacity: 0.6;
}

.criteria-value-detailed {
  position: relative;
  z-index: 1;
  font-size: 13px;
  font-weight: 600;
  padding: 0 8px;
  min-width: 35px;
  text-align: right;
}

.criteria-change {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  min-width: 30px;
  text-align: center;
}

.criteria-change.improved {
  background: var(--success);
  color: #ffffff;
}

.criteria-change.worsened {
  background: var(--error);
  color: #ffffff;
}

.criteria-change.unchanged {
  color: var(--text-secondary);
}

/* Iteration Stages */
.iteration-stages {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.stages-header {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.stage-summary {
  margin-bottom: 12px;
  padding: 12px;
  background: var(--overlay-1);
  border-radius: 6px;
  border-left: 3px solid var(--primary);
}

.stage-summary:last-child {
  margin-bottom: 0;
}

.stage-summary-header {
  margin-bottom: 8px;
}

.stage-summary-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
}

.stage-summary-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.stage-summary-content strong {
  color: var(--text-primary);
}

/* Status Bar */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  overflow-wrap: anywhere;
  padding: 12px;
  background: var(--strip-bg);
  box-shadow: var(--strip-ring);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--border);
}

.status-indicator.running {
  background: var(--primary);
  animation: pulse 1.5s infinite;
}

.status-indicator.complete {
  background: var(--success);
}

.status-indicator.error {
  background: var(--error);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.status-text {
  font-size: 14px;
}

.status-time {
  margin-left: auto;
  font-size: 13px;
  color: var(--text-secondary);
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--error);
  color: #ffffff;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.live-badge .live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffffff;
  animation: pulse 1.5s infinite;
}

/* Collapsible Sections */
.collapsible-header {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.collapsible-header .arrow {
  transition: transform 0.2s;
}

.collapsible-header.expanded .arrow {
  transform: rotate(90deg);
}

/* Raw JSON Toggle */
.raw-toggle {
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  margin-top: 12px;
}

.raw-json {
  margin-top: 8px;
  padding: 12px;
  background: var(--bg-dark);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
  display: none;
}

.raw-json.visible {
  display: block;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  filter: var(--empty-icon-filter);
}

/* Detailed Flow Table */
.detailed-flow-content {
  margin-top: 12px;
}

.flow-view-toggle {
  display: inline-flex;
  border-radius: 999px;
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 12px;
  background: var(--bg-dark);
}

.flow-view-toggle button {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  border-radius: 0;
  min-width: 80px;
}

.flow-view-toggle button.active {
  background: var(--primary);
  color: var(--on-accent);
}

.flow-view-toggle button:not(.active):hover {
  background: var(--overlay-1);
}

.flow-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.flow-table th,
.flow-table td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

.flow-table th {
  background: var(--overlay-2);
  font-weight: 600;
  color: var(--text-primary);
}

.flow-table tbody tr {
  cursor: pointer;
  transition: background 0.2s;
}

.flow-table tbody tr:hover {
  background: var(--accent-tint);
}

.flow-table tbody tr.expanded {
  background: var(--accent-tint);
}

.flow-table .seq-col { width: 50px; }
.flow-table .stage-col { width: 100px; }
.flow-table .label-col { width: 180px; }
.flow-table .source-col { width: 90px; }
.flow-table .role-col { width: 90px; }
.flow-table .start-time-col { width: 180px; font-size: 12px; white-space: nowrap; }
.flow-table .duration-col { width: 90px; text-align: right; white-space: nowrap; }
.flow-table .preview-col { min-width: 200px; }

.flow-detail-row td {
  background: var(--bg-dark) !important;
  padding: 0;
  border-top: none;
}

.flow-detail-cell {
  padding: 16px !important;
}

.flow-detail-section {
  margin-bottom: 16px;
}

.flow-detail-section:last-child {
  margin-bottom: 0;
}

.flow-detail-label {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.flow-detail-content {
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  background: var(--overlay-2);
  padding: 12px;
  border-radius: 6px;
}

.flow-detail-json {
  display: block;
  margin: 0;
  font-size: 11px;
  max-height: 400px;
  font-family: var(--font-mono);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
}

.flow-stage-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

.flow-stage-recruitment { background: var(--stage-badge-recruitment-bg); color: var(--stage-badge-recruitment-fg); }
.flow-stage-decision { background: var(--stage-badge-decision-bg); color: var(--stage-badge-decision-fg); }
.flow-stage-execution { background: var(--stage-badge-execution-bg); color: var(--stage-badge-execution-fg); }
.flow-stage-evaluation { background: var(--stage-badge-evaluation-bg); color: var(--stage-badge-evaluation-fg); }
.flow-stage-synthesis { background: var(--stage-badge-synthesis-bg); color: var(--stage-badge-synthesis-fg); }

/* Flow Graph */
.flow-graph-container {
  background: var(--bg-dark);
  border-radius: var(--radius-md);
  padding: 12px;
  border: 1px solid var(--border);
  overflow: auto;
  margin-bottom: 12px;
}

.flow-graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.flow-graph-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--legend-chip-bg);
  border: 1px solid var(--border);
}

.flow-graph-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.flow-graph-svg {
  min-height: 260px;
  width: 100%;
  color: var(--flow-arrow);
}

.flow-graph-lane {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.flow-graph-lane-label {
  fill: var(--text-secondary);
  font-size: 11px;
  dominant-baseline: middle;
}

.flow-graph-edge {
  stroke-width: 2;
  fill: none;
  opacity: 0.9;
}

.flow-graph-node {
  fill: var(--flow-node-fill);
  stroke: var(--flow-node-stroke);
  stroke-width: 1;
}

.flow-graph-node-label {
  fill: var(--flow-node-ink);
  font-size: 10px;
  pointer-events: none;
}

.flow-graph-tooltip {
  position: fixed;
  z-index: 10000;
  padding: 8px 12px;
  background: var(--tooltip-bg);
  color: var(--text-primary);
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--tooltip-border);
  box-shadow: var(--tooltip-shadow);
  pointer-events: none;
  max-width: 400px;
  white-space: normal;
}

.flow-graph-tooltip[aria-hidden="true"] {
  display: none;
}

.flow-graph-tooltip[aria-hidden="false"] {
  display: block;
}

/* Request History */
.request-history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.request-history-item {
  padding: 12px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.request-history-item:hover {
  border-color: var(--primary);
  background: var(--accent-tint);
}

.request-history-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 8px;
}

.request-history-title {
  font-weight: 500;
  font-size: 13px;
  color: var(--text-primary);
  flex: 1;
  line-height: 1.4;
}

.request-history-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.request-history-score {
  font-weight: 600;
  font-size: 12px;
}

.request-history-goal {
  font-size: 14px;
  color: var(--text-secondary);
}

.request-history-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.request-history-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
}

.request-history-experts {
  font-size: 11px;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 4px;
}

.request-history-item--cancelled {
  opacity: 0.8;
  border-left: 3px solid var(--text-secondary);
}

.request-history-item--cancelled .request-history-score {
  font-style: italic;
}

/* Run analysis: the finished run's charts, collapsed under the final output (js/run-analysis.js).
   Chart roles and furniture (tiles, svg.viz, tooltip) come from common/css/charts.css. */
.run-analysis { margin-top: 24px; }
.run-analysis-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  cursor: pointer;
}
.run-analysis-summary h2 { margin: 0; }
.run-analysis-hint { color: var(--text-secondary); font-size: 13px; }
.run-analysis[open] .run-analysis-summary { margin-bottom: 16px; }
.run-analysis-body { min-width: 0; }
.run-analysis-body .loading, .run-analysis-body .placeholder { color: var(--text-secondary); font-size: 14px; }
.run-analysis-source { color: var(--text-muted); font-size: 12px; margin-top: 12px; overflow-wrap: anywhere; }
.run-analysis .callout--flag { border-left-color: var(--orange); }
