/* ═══════════════════════════════════════════════════════════════
   AXIOM FORGE — Autonomous Design Convergence Engine
   Complete styles: header, viewport, metrics, sparkline, orb,
   mini-log, result overlay, comparison grid, insight panel,
   credit bar, constraint pips, transitions, glass morphism.
   ═══════════════════════════════════════════════════════════════ */

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --af-bg-primary: #0a0c10;
  --af-bg-secondary: #12151b;
  --af-bg-glass: rgba(14, 16, 20, 0.95);
  --af-bg-card: rgba(27, 29, 33, 0.75);
  --af-bg-insight: rgba(20, 22, 28, 0.92);
  --af-text-primary: #e8eaed;
  --af-text-secondary: #9aa0a6;
  --af-text-dim: #5f6368;
  --af-accent-purple: #7c4dff;
  --af-accent-blue: #448aff;
  --af-green: #34a853;
  --af-amber: #fbbc04;
  --af-red: #ea4335;
  --af-glow-purple: rgba(124, 77, 255, 0.4);
  --af-font-mono: 'JetBrains Mono', monospace;
  --af-font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --af-header-h: 60px;
  --af-command-h: 160px;
  --af-blur-heavy: blur(20px);
  --af-blur-medium: blur(12px);
  --af-blur-light: blur(8px);
  --af-transition-fast: 200ms ease;
  --af-transition-mid: 300ms ease;
  --af-transition-slow: 400ms ease;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--af-bg-primary);
  color: var(--af-text-primary);
  font-family: var(--af-font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Header Band (60px, fixed top) ─────────────────────────── */
.af-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--af-header-h);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--af-bg-glass);
  backdrop-filter: var(--af-blur-heavy);
  -webkit-backdrop-filter: var(--af-blur-heavy);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.af-header-left, .af-header-center, .af-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.af-header-left { flex: 0 0 auto; }
.af-header-center { flex: 1; justify-content: center; }
.af-header-right { flex: 0 0 auto; }

.af-logo {
  font-family: var(--af-font-mono);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--af-text-primary);
  text-transform: uppercase;
}

.af-cem {
  font-family: var(--af-font-mono);
  font-size: 12px;
  color: var(--af-accent-purple);
  background: rgba(124, 77, 255, 0.12);
  padding: 2px 8px;
  border-radius: 4px;
}

.af-iter {
  font-family: var(--af-font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--af-text-primary);
  letter-spacing: 1px;
}

/* Credit Bar */
.af-credit-bar {
  width: 200px;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
}

.af-credit-fill {
  height: 100%;
  width: 100%;
  background: var(--af-green);
  border-radius: 2px;
  transition: width 600ms ease, background-color 400ms ease;
}

.af-credit-fill.amber { background: var(--af-amber); }
.af-credit-fill.red { background: var(--af-red); }

/* Health Dot */
.af-health {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--af-green);
  flex-shrink: 0;
}

.af-health.degraded { background: var(--af-amber); }
.af-health.offline { background: var(--af-red); }

/* Stop Button */
.af-stop {
  font-family: var(--af-font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: #fff;
  background: var(--af-red);
  border: none;
  padding: 6px 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity var(--af-transition-fast);
}

.af-stop:hover { opacity: 0.85; }

/* KILN Link */
.af-link {
  font-size: 12px;
  color: var(--af-text-secondary);
  text-decoration: none;
  transition: color var(--af-transition-fast);
}

.af-link:hover { color: var(--af-text-primary); }

/* ── I2D Pipeline Stage Indicator ─────────────────────────── */
.af-pipeline {
  position: fixed;
  top: var(--af-header-h);
  left: 0; right: 0;
  height: 28px;
  z-index: 99;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: rgba(10, 12, 16, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(124, 77, 255, 0.1);
  padding: 0 40px;
  overflow: hidden;
}

.af-pipe-seg {
  flex: 1;
  max-width: 120px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  position: relative;
  transition: all 0.4s ease;
}

.af-pipe-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
  transition: all 0.4s ease;
}

.af-pipe-label {
  font-family: var(--af-font-mono);
  font-size: 9px;
  letter-spacing: 1.5px;
  color: rgba(255, 255, 255, 0.15);
  transition: color 0.4s ease;
}

/* Completed phase */
.af-pipe-seg.done .af-pipe-dot {
  background: var(--af-green);
  box-shadow: 0 0 6px rgba(52, 168, 83, 0.5);
}
.af-pipe-seg.done .af-pipe-label {
  color: var(--af-green);
}

/* Active phase */
.af-pipe-seg.active .af-pipe-dot {
  background: var(--af-accent-purple);
  box-shadow: 0 0 10px var(--af-glow-purple), 0 0 20px rgba(124, 77, 255, 0.3);
  animation: pipeDotPulse 1.2s ease-in-out infinite;
}
.af-pipe-seg.active .af-pipe-label {
  color: var(--af-accent-purple);
  text-shadow: 0 0 8px rgba(124, 77, 255, 0.4);
}
.af-pipe-seg.active {
  background: rgba(124, 77, 255, 0.06);
}

@keyframes pipeDotPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 6px var(--af-glow-purple); }
  50% { transform: scale(1.4); box-shadow: 0 0 14px var(--af-glow-purple), 0 0 28px rgba(124, 77, 255, 0.2); }
}

/* Failed phase */
.af-pipe-seg.error .af-pipe-dot {
  background: var(--af-red);
  box-shadow: 0 0 6px rgba(234, 67, 53, 0.5);
}
.af-pipe-seg.error .af-pipe-label {
  color: var(--af-red);
}

/* Scanning beam animation across the active segment */
.af-pipe-scan {
  position: absolute;
  top: 0;
  left: 0;
  width: 60px;
  height: 100%;
  background: linear-gradient(90deg, transparent 0%, rgba(124, 77, 255, 0.15) 50%, transparent 100%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.af-pipeline.scanning .af-pipe-scan {
  opacity: 1;
  animation: pipeScan 2s ease-in-out infinite;
}

@keyframes pipeScan {
  0% { transform: translateX(-60px); }
  100% { transform: translateX(calc(100vw)); }
}

/* Connection lines between segments */
.af-pipe-seg::after {
  content: '';
  position: absolute;
  right: -2px;
  top: 50%;
  width: 4px;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  z-index: 1;
}
.af-pipe-seg:last-of-type::after { display: none; }
.af-pipe-seg.done::after { background: rgba(52, 168, 83, 0.4); }
.af-pipe-seg.active::after { background: rgba(124, 77, 255, 0.4); }

/* Viewport offset when pipeline is visible */
.state-iterating .af-viewport,
.state-paused .af-viewport {
  top: calc(var(--af-header-h) + 28px);
}

/* ── Viewport Band (72vh) ──────────────────────────────────── */
.af-viewport {
  position: fixed;
  top: var(--af-header-h);
  left: 0; right: 0;
  height: calc(100vh - var(--af-header-h) - var(--af-command-h));
  background: linear-gradient(180deg, #0a0c10 0%, #12151b 100%);
  overflow: hidden;
}

#af-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
}

/* ── Floating Metric Cards ─────────────────────────────────── */
.af-metrics {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 10;
}

.af-metric-card {
  position: absolute;
  width: 80px;
  height: 56px;
  background: var(--af-bg-card);
  backdrop-filter: var(--af-blur-medium);
  -webkit-backdrop-filter: var(--af-blur-medium);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  pointer-events: auto;
  transition: border-color var(--af-transition-mid), box-shadow var(--af-transition-mid);
}

.af-metric-card.constraint-green { border-color: rgba(52, 168, 83, 0.5); }
.af-metric-card.constraint-amber { border-color: rgba(251, 188, 4, 0.5); }
.af-metric-card.constraint-red { border-color: rgba(234, 67, 53, 0.5); }

.af-metric-card.pulse {
  animation: metricPulse 2s ease-in-out infinite;
}

@keyframes metricPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(234, 67, 53, 0); }
  50% { box-shadow: 0 0 12px 4px rgba(234, 67, 53, 0.3); }
}

.af-metric-tl { top: 20px; left: 20px; }
.af-metric-tr { top: 20px; right: 20px; }
.af-metric-bl { bottom: 60px; left: 20px; }
.af-metric-br { bottom: 60px; right: 20px; }

.af-metric-label {
  font-family: var(--af-font-sans);
  font-size: 9px;
  font-weight: 500;
  color: var(--af-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.af-metric-value {
  font-family: var(--af-font-mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--af-text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.af-metric-delta {
  font-family: var(--af-font-mono);
  font-size: 10px;
  font-weight: 500;
  line-height: 1;
}

.af-metric-delta.positive { color: var(--af-green); }
.af-metric-delta.negative { color: var(--af-red); }
.af-metric-delta.neutral { color: var(--af-amber); }

/* Dynamic metric cards added by JS */
.af-metric-card.af-metric-dynamic {
  width: 80px;
  height: 56px;
}

/* ── Convergence Sparkline ─────────────────────────────────── */
.af-sparkline {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 40px;
  opacity: 0.6;
  z-index: 5;
  pointer-events: none;
}

/* ── Constraint Pips ───────────────────────────────────────── */
.af-constraints {
  position: absolute;
  bottom: 48px;
  right: 20px;
  display: flex;
  gap: 6px;
  z-index: 10;
}

.af-pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--af-text-dim);
  cursor: help;
  transition: background-color var(--af-transition-fast);
}

.af-pip.green { background: var(--af-green); }
.af-pip.amber { background: var(--af-amber); }
.af-pip.red { background: var(--af-red); }

/* ── Morph Overlay (crossfade container) ───────────────────── */
.af-morph-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

/* ── Command Band (160px) ──────────────────────────────────── */
.af-command {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--af-command-h);
  background: var(--af-bg-glass);
  backdrop-filter: var(--af-blur-heavy);
  -webkit-backdrop-filter: var(--af-blur-heavy);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 24px;
  z-index: 100;
}

/* Glow Line */
.af-glow {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--af-accent-purple) 30%,
    var(--af-accent-blue) 70%,
    transparent 100%
  );
  opacity: 0.5;
  transition: opacity var(--af-transition-mid);
}

.af-command.iterating .af-glow {
  animation: glowPulse 3s ease-in-out infinite;
}

@keyframes glowPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.8; }
}

.af-command.paused .af-glow { opacity: 0.15; }

/* Objective Label */
.af-objective {
  font-family: var(--af-font-mono);
  font-size: 13px;
  color: var(--af-accent-purple);
  letter-spacing: 0.5px;
  text-align: center;
  max-width: 800px;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 18px;
  padding: 4px 12px;
  line-height: 1.4;
}

/* Voice Orb Row */
.af-orb-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  width: 100%;
  max-width: 700px;
  justify-content: center;
}

.af-last-msg {
  font-size: 14px;
  color: var(--af-text-primary);
  width: 100%;
  max-width: 700px;
  text-align: center;
  opacity: 1;
  transition: opacity 3s ease;
  line-height: 1.5;
  padding: 4px 16px;
  min-height: 22px;
}

.af-last-msg:empty { display: none; }
.af-last-msg.fading { opacity: 0; }

/* Voice Orb */
.af-voice-orb {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--af-accent-purple);
  background: rgba(124, 77, 255, 0.1);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--af-transition-fast), background var(--af-transition-fast), box-shadow var(--af-transition-fast);
}

.af-voice-orb:hover {
  background: rgba(124, 77, 255, 0.2);
  box-shadow: 0 0 20px var(--af-glow-purple);
}

/* Orb States */
.af-voice-orb.idle {
  animation: orbBreathe 4s ease-in-out infinite;
}

@keyframes orbBreathe {
  0%, 100% {
    box-shadow: 0 0 8px rgba(124, 77, 255, 0.2);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 24px rgba(124, 77, 255, 0.4);
    transform: scale(1.04);
  }
}

.af-voice-orb.listening {
  border-color: var(--af-green);
  background: rgba(52, 168, 83, 0.15);
  animation: orbListening 1.5s ease-in-out infinite;
}

@keyframes orbListening {
  0%, 100% {
    box-shadow: 0 0 10px rgba(52, 168, 83, 0.3);
  }
  50% {
    box-shadow: 0 0 30px rgba(52, 168, 83, 0.6);
  }
}

.af-voice-orb.processing {
  border-color: var(--af-accent-blue);
  background: rgba(68, 138, 255, 0.15);
  animation: orbProcessing 1s linear infinite;
}

@keyframes orbProcessing {
  0% { box-shadow: 0 0 10px rgba(68, 138, 255, 0.3); }
  25% { box-shadow: 0 0 20px rgba(68, 138, 255, 0.5); }
  50% { box-shadow: 0 0 10px rgba(68, 138, 255, 0.3); }
  75% { box-shadow: 0 0 20px rgba(68, 138, 255, 0.5); }
  100% { box-shadow: 0 0 10px rgba(68, 138, 255, 0.3); }
}

.af-voice-orb.speaking {
  border-color: var(--af-accent-purple);
  background: rgba(124, 77, 255, 0.2);
  animation: orbSpeaking 0.8s ease-in-out infinite;
}

@keyframes orbSpeaking {
  0%, 100% {
    box-shadow: 0 0 12px rgba(124, 77, 255, 0.3);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 28px rgba(124, 77, 255, 0.6);
    transform: scale(1.06);
  }
}

/* Mic icon inside orb */
.af-mic-icon {
  color: var(--af-accent-purple);
  z-index: 2;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.af-voice-orb.listening .af-mic-icon,
.af-voice-orb.processing .af-mic-icon,
.af-voice-orb.speaking .af-mic-icon { opacity: 0; }

.af-voice-orb.listening .af-mic-icon { color: var(--af-green); opacity: 1; }

.af-waveform {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.af-voice-orb.listening .af-waveform,
.af-voice-orb.processing .af-waveform,
.af-voice-orb.speaking .af-waveform { opacity: 1; }

.af-waveform-base {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

/* Voice state indicator text below orb */
.af-voice-state {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--af-font-mono);
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--af-text-dim);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.af-voice-orb.listening .af-voice-state,
.af-voice-orb.processing .af-voice-state { opacity: 1; }
.af-voice-orb.listening .af-voice-state { color: var(--af-green); }
.af-voice-orb.processing .af-voice-state { color: var(--af-accent-blue); }

/* Text Input */
.af-input {
  flex: 1;
  height: 40px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 0 20px;
  font-family: var(--af-font-sans);
  font-size: 13px;
  color: var(--af-text-primary);
  outline: none;
  transition: border-color var(--af-transition-fast);
}

.af-input::placeholder { color: var(--af-text-dim); }
.af-input:focus { border-color: rgba(124, 77, 255, 0.4); }

/* ── Iteration Mini-Log ────────────────────────────────────── */
.af-minilog {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  padding: 4px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.af-minilog::-webkit-scrollbar { height: 3px; }
.af-minilog::-webkit-scrollbar-track { background: transparent; }
.af-minilog::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.af-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  font-family: var(--af-font-mono);
  font-size: 11px;
  color: var(--af-text-secondary);
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color var(--af-transition-fast), background var(--af-transition-fast);
}

.af-pill:hover {
  background: rgba(255, 255, 255, 0.08);
}

.af-pill.current {
  border-color: var(--af-accent-purple);
  color: var(--af-text-primary);
  box-shadow: 0 0 8px var(--af-glow-purple);
}

.af-pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.af-pill-dot.green { background: var(--af-green); }
.af-pill-dot.amber { background: var(--af-amber); }
.af-pill-dot.red { background: var(--af-red); }

/* ── Result Overlay (CONVERGED) ────────────────────────────── */
.af-result-overlay {
  position: absolute;
  top: 0;
  right: 0;
  width: 40%;
  height: 100%;
  background: var(--af-bg-insight);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 20;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transform: translateX(100%);
  transition: transform var(--af-transition-mid);
  overflow-y: auto;
}

.af-result-overlay.visible {
  transform: translateX(0);
  display: flex;
}

.af-result-title {
  font-family: var(--af-font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--af-green);
  letter-spacing: 2px;
}

.af-result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.af-result-label {
  font-size: 13px;
  color: var(--af-text-secondary);
}

.af-result-value {
  font-family: var(--af-font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--af-text-primary);
}

.af-result-value .check { color: var(--af-green); }
.af-result-value .fail { color: var(--af-red); }

.af-result-articles {
  font-family: var(--af-font-mono);
  font-size: 12px;
  color: var(--af-green);
  padding: 8px 12px;
  background: rgba(52, 168, 83, 0.08);
  border-radius: 6px;
  text-align: center;
}

.af-result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: auto;
}

.af-result-btn {
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: var(--af-text-primary);
  font-family: var(--af-font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: background var(--af-transition-fast), border-color var(--af-transition-fast);
}

.af-result-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.af-result-btn.primary {
  background: var(--af-accent-purple);
  border-color: var(--af-accent-purple);
  color: #fff;
}

.af-result-btn.primary:hover {
  background: #6a3de8;
}

.af-result-warning {
  background: rgba(251, 188, 4, 0.1);
  border: 1px solid rgba(251, 188, 4, 0.3);
  color: var(--af-amber);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin: 4px 0;
}

/* ── Genesis Review Overlay ───────────────────────────────── */
.af-review-header {
  font-family: var(--af-font-mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--af-green);
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.af-review-section {
  margin-bottom: 4px;
}

.af-review-label {
  font-family: var(--af-font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--af-text-dim);
  margin-bottom: 6px;
}

.af-review-objective {
  font-size: 15px;
  color: var(--af-text-primary);
  line-height: 1.4;
  padding: 8px 12px;
  border-left: 3px solid var(--af-accent-purple);
  background: rgba(124, 77, 255, 0.05);
  border-radius: 0 6px 6px 0;
}

.af-review-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.af-review-selected {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(124, 77, 255, 0.08);
  border: 1px solid rgba(124, 77, 255, 0.25);
  border-radius: 8px;
}

.af-review-selected-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--af-accent-purple);
}

.af-review-selected-mat {
  font-family: var(--af-font-mono);
  font-size: 12px;
  color: var(--af-text-secondary);
}

.af-review-tag {
  font-family: var(--af-font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 2px 8px;
  border-radius: 3px;
  background: rgba(52, 168, 83, 0.15);
  color: var(--af-green);
  margin-left: auto;
}

.af-review-concepts {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.af-review-concept {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 13px;
}

.af-review-concept.preferred {
  background: rgba(124, 77, 255, 0.08);
  border: 1px solid rgba(124, 77, 255, 0.2);
}

.af-review-concept.eliminated {
  opacity: 0.35;
}

.af-review-concept.eliminated .af-review-concept-name {
  text-decoration: line-through;
}

.af-review-concept-name {
  color: var(--af-text-primary);
  font-weight: 500;
}

.af-review-concept-mat {
  color: var(--af-text-secondary);
  font-family: var(--af-font-mono);
  font-size: 11px;
}

.af-review-badge {
  font-family: var(--af-font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(124, 77, 255, 0.2);
  color: var(--af-accent-purple);
  margin-left: auto;
}

.af-review-badge.elim {
  background: rgba(234, 67, 53, 0.12);
  color: var(--af-red);
}

.af-review-bom {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.af-review-bom-row {
  display: flex;
  gap: 12px;
  padding: 4px 0;
  font-size: 12px;
  color: var(--af-text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.af-review-bom-row span:first-child {
  font-family: var(--af-font-mono);
  font-size: 11px;
  color: var(--af-text-dim);
  min-width: 60px;
}

.af-review-plan {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.af-review-plan-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
  color: var(--af-text-secondary);
}

.af-review-plan-row span:last-child {
  font-family: var(--af-font-mono);
  color: var(--af-text-primary);
}

.af-review-actions {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.af-review-dim {
  color: var(--af-text-dim);
  font-size: 12px;
  font-style: italic;
}

/* ── Comparison Grid ───────────────────────────────────────── */
.af-comparison {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 60% 40%;
  gap: 2px;
  background: rgba(0, 0, 0, 0.9);
}

.af-comparison.three-col { grid-template-columns: 1fr 1fr 1fr; }
.af-comparison.four-col { grid-template-columns: 1fr 1fr 1fr 1fr; }

.af-comp-viewport {
  position: relative;
  background: linear-gradient(180deg, #0a0c10, #12151b);
  overflow: hidden;
}

.af-comp-viewport canvas {
  width: 100%;
  height: 100%;
}

.af-comp-label {
  position: absolute;
  top: 8px;
  left: 12px;
  font-family: var(--af-font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--af-text-primary);
  background: rgba(0, 0, 0, 0.6);
  padding: 2px 8px;
  border-radius: 4px;
}

.af-comp-table {
  grid-column: 1 / -1;
  background: var(--af-bg-glass);
  backdrop-filter: var(--af-blur-heavy);
  padding: 16px 24px;
  overflow-y: auto;
}

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

.af-comp-table th {
  font-family: var(--af-font-mono);
  font-weight: 600;
  color: var(--af-text-secondary);
  text-align: center;
  padding: 6px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.af-comp-table th:first-child { text-align: left; }

.af-comp-table td {
  font-family: var(--af-font-mono);
  font-size: 13px;
  text-align: center;
  padding: 6px 12px;
  color: var(--af-text-primary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.af-comp-table td:first-child {
  text-align: left;
  color: var(--af-text-secondary);
}

.af-comp-table td.best { color: var(--af-green); font-weight: 600; }
.af-comp-table td.violated { color: var(--af-red); }

.af-comp-back {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 25;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.6);
  color: var(--af-text-primary);
  font-size: 12px;
  cursor: pointer;
}

.af-comp-back:hover { background: rgba(255, 255, 255, 0.1); }

/* Spider Chart Container */
.af-comp-spider {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200px;
  height: 200px;
  z-index: 22;
  pointer-events: none;
}

/* ── Floating Insight Panel ────────────────────────────────── */
.af-insight {
  position: absolute;
  top: 0;
  right: 0;
  width: 40%;
  height: 100%;
  background: var(--af-bg-insight);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 30;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--af-transition-mid);
}

.af-insight.visible {
  transform: translateX(0);
  display: flex;
}

.af-insight-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.af-insight-title {
  font-family: var(--af-font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--af-text-primary);
  text-transform: uppercase;
}

.af-insight-close {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  background: transparent;
  color: var(--af-text-secondary);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--af-transition-fast);
}

.af-insight-close:hover { background: rgba(255, 255, 255, 0.08); }

.af-insight-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

/* ── CEM Picker ────────────────────────────────────────────── */
.af-cem-picker {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 480px;
  max-height: 400px;
  background: var(--af-bg-insight);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 24px;
  z-index: 40;
  overflow-y: auto;
}

.af-cem-picker h3 {
  font-family: var(--af-font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--af-text-primary);
  margin-bottom: 16px;
  letter-spacing: 1px;
}

.af-cem-picker p {
  font-size: 13px;
  color: var(--af-text-secondary);
  margin-bottom: 16px;
}

.af-cem-option {
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background var(--af-transition-fast), border-color var(--af-transition-fast);
}

.af-cem-option:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--af-accent-purple);
}

.af-cem-option-name {
  font-family: var(--af-font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--af-text-primary);
}

.af-cem-option-desc {
  font-size: 12px;
  color: var(--af-text-dim);
  margin-top: 4px;
}

.af-cem-skip {
  width: 100%;
  padding: 10px;
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: transparent;
  color: var(--af-text-secondary);
  font-size: 12px;
  cursor: pointer;
  margin-top: 8px;
}

.af-cem-skip:hover { background: rgba(255, 255, 255, 0.02); }

/* ── Banner ────────────────────────────────────────────────── */
.af-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 12px;
  font-family: var(--af-font-sans);
}

.af-banner.amber {
  background: rgba(251, 188, 4, 0.15);
  border: 1px solid rgba(251, 188, 4, 0.3);
  color: var(--af-amber);
}

.af-banner.red {
  background: rgba(234, 67, 53, 0.15);
  border: 1px solid rgba(234, 67, 53, 0.3);
  color: var(--af-red);
}

/* ── Connection Error Screen ───────────────────────────────── */
.af-connection-error {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1000;
  background: var(--af-bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.af-connection-error h2 {
  font-family: var(--af-font-mono);
  font-size: 18px;
  color: var(--af-red);
}

.af-connection-error p {
  font-size: 14px;
  color: var(--af-text-secondary);
}

body.af-offline .af-header,
body.af-offline .af-viewport,
body.af-offline .af-command { display: none; }

/* ── Ambient Effects (ITERATING state) ─────────────────────── */
body.state-iterating .af-metric-card {
  border-color: rgba(255, 255, 255, 0.12);
  animation: cardShimmer 4s ease-in-out infinite;
}

@keyframes cardShimmer {
  0%, 100% { border-color: rgba(255, 255, 255, 0.08); }
  50% { border-color: rgba(255, 255, 255, 0.15); }
}

/* ITERATING state ambient energy */
.state-iterating .af-metric-card {
  animation: metricShimmer 4s ease-in-out infinite;
}
@keyframes metricShimmer {
  0%, 100% { box-shadow: 0 0 0 1px rgba(124, 77, 255, 0.05); }
  50% { box-shadow: 0 0 0 1px rgba(124, 77, 255, 0.15); }
}

.state-iterating .af-glow {
  animation: glowPulse 3s ease-in-out infinite;
}

/* ── CONVERGED State Hero Lighting ─────────────────────────── */
body.state-converged .af-viewport {
  background: linear-gradient(180deg, #0c0e14 0%, #161a22 100%);
}

/* ── Genesis State ─────────────────────────────────────────── */
.af-genesis-particles {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 3;
  pointer-events: none;
}

.af-genesis-brief {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  background: var(--af-bg-card);
  backdrop-filter: var(--af-blur-medium);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 24px 32px;
  max-width: 400px;
  text-align: center;
  opacity: 0;
  transition: opacity var(--af-transition-mid);
}

.af-genesis-brief.visible { opacity: 1; }

.af-genesis-brief h4 {
  font-family: var(--af-font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--af-text-primary);
  margin-bottom: 12px;
}

.af-constraint-pill {
  display: inline-block;
  padding: 3px 10px;
  margin: 3px;
  border-radius: 10px;
  font-family: var(--af-font-mono);
  font-size: 11px;
}

.af-constraint-pill.hard {
  background: rgba(52, 168, 83, 0.12);
  color: var(--af-green);
  border: 1px solid rgba(52, 168, 83, 0.3);
}

.af-constraint-pill.soft {
  background: rgba(251, 188, 4, 0.12);
  color: var(--af-amber);
  border: 1px solid rgba(251, 188, 4, 0.3);
}

/* Concept Cards */
.af-concept-row {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  gap: 12px;
  z-index: 4;
}

.af-concept-card {
  width: 140px;
  padding: 16px;
  background: var(--af-bg-card);
  backdrop-filter: var(--af-blur-medium);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  text-align: center;
  transition: opacity var(--af-transition-mid), transform var(--af-transition-mid);
}

.af-concept-card.eliminated {
  opacity: 0.25;
  transform: scale(0.92);
}

.af-concept-card.preferred {
  border-color: var(--af-accent-purple);
  box-shadow: 0 0 16px var(--af-glow-purple);
}

.af-concept-name {
  font-family: var(--af-font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--af-text-primary);
  margin-bottom: 6px;
}

.af-concept-material {
  font-size: 11px;
  color: var(--af-text-secondary);
}

/* Loading Ring */
.af-loading-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 60px;
  height: 60px;
  transform: translate(-50%, -50%);
  z-index: 4;
}

.af-loading-ring::after {
  content: '';
  display: block;
  width: 48px;
  height: 48px;
  margin: 6px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--af-accent-purple);
  border-right-color: var(--af-accent-blue);
  animation: loadingRingSpin 1s linear infinite;
}

@keyframes loadingRingSpin {
  to { transform: rotate(360deg); }
}

/* ── Genesis Progress Panel ───────────────────────────────── */
.af-genesis-progress {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 10;
  background: rgba(14, 16, 20, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(124, 77, 255, 0.15);
  border-radius: 12px;
  padding: 20px 24px;
  width: 300px;
  text-align: left;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.af-genesis-title {
  font-family: var(--af-font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--af-accent-purple);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.af-genesis-steps {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.af-genesis-step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-family: var(--af-font-sans);
  font-size: 12px;
  color: var(--af-text-dim);
  transition: color 0.3s ease, opacity 0.3s ease;
}

.af-genesis-step.active {
  color: var(--af-text-primary);
}

.af-genesis-step.done {
  color: var(--af-green);
}

.af-genesis-step.error {
  color: var(--af-red);
}

.af-genesis-step-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

.af-genesis-step.active .af-genesis-step-icon::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--af-accent-purple);
  animation: genesisPulse 1s ease-in-out infinite;
}

@keyframes genesisPulse {
  0%, 100% { opacity: 0.4; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

.af-genesis-step.done .af-genesis-step-icon::after {
  content: '\2713';
  color: var(--af-green);
  font-size: 14px;
}

.af-genesis-step-label {
  flex: 1;
}

.af-genesis-step-timer {
  font-family: var(--af-font-mono);
  font-size: 10px;
  color: var(--af-text-dim);
  min-width: 55px;
  text-align: right;
  flex-shrink: 0;
  transition: color 0.3s ease;
}

.af-genesis-step.active .af-genesis-step-timer {
  color: var(--af-accent-purple);
}

.af-genesis-step-detail {
  font-family: var(--af-font-mono);
  font-size: 10px;
  color: var(--af-text-dim);
  max-width: 90px;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.af-genesis-step.done .af-genesis-step-detail {
  color: var(--af-text-secondary);
}

.af-genesis-status {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-family: var(--af-font-mono);
  font-size: 12px;
  color: var(--af-text-secondary);
  text-align: center;
  min-height: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* Overall progress bar */
.af-genesis-bar-track {
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
}

.af-genesis-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--af-accent-purple), var(--af-accent-blue));
  border-radius: 2px;
  transition: width 0.5s ease;
}

#af-genesis-eta {
  font-size: 11px;
  color: var(--af-text-dim);
  letter-spacing: 0.3px;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .af-result-overlay,
  .af-insight { width: 85%; }

  .af-comparison { grid-template-columns: 1fr; grid-template-rows: repeat(auto-fill, 200px) auto; }
  .af-comparison.three-col,
  .af-comparison.four-col { grid-template-columns: 1fr 1fr; }

  .af-metric-card { width: 70px; height: 48px; }
  .af-metric-value { font-size: 16px; }

  .af-orb-row { max-width: 100%; }

  .af-cem-picker { width: 90%; }
}

@media (max-width: 480px) {
  .af-header { padding: 0 12px; }
  .af-credit-bar { width: 100px; }
  .af-logo { font-size: 12px; }
  .af-link { display: none; }

  .af-voice-orb { width: 48px; height: 48px; }

  .af-result-overlay,
  .af-insight { width: 100%; }
}
