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

:root {
  --bg:        #111318;
  --surface:   #1c2028;
  --surface2:  #242b35;
  --border:    #2e3848;
  --border-hi: #404e64;

  --analyst-color: #7aaad4;
  --coach-color:   #c0a060;
  --critic-color:  #c05868;
  --engine-color:  #5ac8f0;

  --accent:      #5a90c8;
  --accent-dim:  rgba(90, 144, 200, 0.12);
  --accent-glow: rgba(90, 144, 200, 0.30);

  --neutral-color: #6878a0;
  --success-color: #50b890;
  --debug-green:   #40cc90;

  --text:       #e8ecf4;
  --text-dim:   #7888a8;
  --text-faint: #4a5570;

  --radius: 10px;
  --font-mono: 'Courier New', Courier, monospace;
}

html, body {
  height: 100%;
  background-color: var(--bg);
  background-image: repeating-conic-gradient(
    rgba(255,255,255,0.018) 0% 25%, transparent 0% 50%
  );
  background-size: 48px 48px;
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── App grid ──────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-rows: auto auto 1fr;   /* topbar | pipeline | content */
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px;
  gap: 10px;
}

/* ── Top bar ───────────────────────────────────────────────── */
#topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 20px;
  height: 52px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-shrink: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 20px;
  color: var(--accent);
}

.brand-name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--text);
}

.topbar-nav {
  display: flex;
  gap: 2px;
}

.nav-link {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--text-faint);
  text-decoration: none;
  transition: all 0.2s;
}

.nav-link:hover  { color: var(--text); background: var(--surface2); }
.nav-link.active { color: var(--accent); background: var(--accent-dim); }

.topbar-status {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
}

#status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--neutral-color);
  transition: background 0.3s;
}
#status-dot.active {
  background: var(--success-color);
  animation: pulse 1.5s infinite;
}
#status-dot.error { background: var(--critic-color); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(80, 184, 144, 0.5); }
  50%       { box-shadow: 0 0 0 5px rgba(80, 184, 144, 0); }
}

/* ── Pipeline ──────────────────────────────────────────────── */
#pipeline {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  position: relative;
}

.agent-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 26px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 140px;
  transition: all 0.35s ease;
  opacity: 0.35;
  background: var(--surface2);
  position: relative;
}

.agent-node .face {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  transition: opacity 0.35s ease;
}

.agent-node.active .face   { opacity: 1; }
.agent-node.complete .face { opacity: 0.75; }

.agent-node .face svg {
  animation: sprite-bob 3.5s ease-in-out infinite;
}

@keyframes sprite-bob {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-3px); }
}

.agent-node .label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-faint);
  transition: color 0.3s;
}

.agent-node .status-badge {
  font-size: 10px;
  color: var(--text-faint);
  min-height: 14px;
}

.agent-node.analyst { --node-color: var(--analyst-color); }
.agent-node.engine  { --node-color: var(--engine-color); }
.agent-node.coach   { --node-color: var(--coach-color); }
.agent-node.critic  { --node-color: var(--critic-color); }

.agent-node.engine.skipped { opacity: 0.2; }
.agent-node.engine.skipped .status-badge { font-style: italic; }

.agent-node.active {
  border-color: var(--node-color);
  opacity: 1;
  transform: scale(1.05);
  background: color-mix(in srgb, var(--node-color) 6%, var(--surface2));
  box-shadow: 0 0 28px color-mix(in srgb, var(--node-color) 25%, transparent),
              inset 0 1px 0 color-mix(in srgb, var(--node-color) 20%, transparent);
}

.agent-node.active .label        { color: var(--node-color); }
.agent-node.active .status-badge { color: var(--node-color); opacity: 0.7; }

.agent-node.complete {
  border-color: var(--success-color);
  opacity: 0.7;
}

/* ── Pipeline arrows ────────────────────────────────────────── */
.pipe-arrow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0 12px;
}

.pipe-arrow .arrow-line {
  width: 72px;
  height: 2px;
  background: var(--border);
  position: relative;
  overflow: hidden;
  border-radius: 1px;
}

.pipe-arrow.active .arrow-line::after {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, var(--accent));
  animation: flow 0.8s linear infinite;
}

.pipe-arrow .arrow-head { font-size: 12px; color: var(--border-hi); }
.pipe-arrow.active .arrow-head { color: var(--accent); }

@keyframes flow { to { left: 100%; } }

.feedback-label {
  position: absolute;
  bottom: 8px;
  right: 28px;
  font-size: 10px;
  color: var(--critic-color);
  opacity: 0;
  transition: opacity 0.3s;
  font-style: italic;
}
.feedback-label.visible { opacity: 1; }

/* ── Content split ──────────────────────────────────────────── */
#content {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 10px;
  min-height: 0;
}

/* ── Shared panel ───────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 2px 16px rgba(0,0,0,0.35);
}

.panel-header {
  padding: 9px 16px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
}

.panel-header.with-meter {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.elapsed {
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  opacity: 0.7;
}

.elapsed.running {
  color: var(--text-faint);
  opacity: 1;
}

/* ── Output panel ───────────────────────────────────────────── */
#output-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  font-size: 13px;
  line-height: 1.8;
}

#output-body:empty::after {
  content: 'Agent output will appear here as they work...';
  color: var(--text-faint);
  font-style: italic;
}

.output-block { margin-bottom: 22px; }

.output-block .agent-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 8px;
  padding: 3px 10px;
  border-radius: 4px;
  display: inline-block;
}

.output-block.analyst .agent-tag { background: color-mix(in srgb, var(--analyst-color) 15%, transparent); color: var(--analyst-color); border: 1px solid color-mix(in srgb, var(--analyst-color) 30%, transparent); }
.output-block.coach   .agent-tag { background: color-mix(in srgb, var(--coach-color)   15%, transparent); color: var(--coach-color);   border: 1px solid color-mix(in srgb, var(--coach-color)   30%, transparent); }
.output-block.critic  .agent-tag { background: color-mix(in srgb, var(--critic-color)  15%, transparent); color: var(--critic-color);  border: 1px solid color-mix(in srgb, var(--critic-color)  30%, transparent); }

.output-block .agent-text { white-space: pre-wrap; word-break: break-word; }
.output-block .agent-text h2 { font-size: 15px; font-weight: 700; margin: 14px 0 5px; }
.output-block .agent-text h3 { font-size: 13px; font-weight: 600; margin: 10px 0 4px; color: var(--text-dim); }

/* ── Right column ───────────────────────────────────────────── */
#right-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

/* interaction panel: height determined by content */
#interaction-panel { flex-shrink: 0; }

#interaction-body { padding: 18px; }

/* Setup form */
#setup-form { display: flex; flex-direction: column; gap: 14px; }

.form-row { display: flex; flex-direction: column; gap: 5px; }

.form-row-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-row label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-dim);
}

input[type="text"], input[type="number"], select, textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

select option { background: var(--surface2); }

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.5;
  transition: border-color 0.2s, color 0.2s;
}
.checkbox-row:hover { border-color: var(--accent); color: var(--text); }
.checkbox-row input {
  width: auto;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.checkbox-row strong { color: var(--text); font-weight: 600; }

/* ── Question card ──────────────────────────────────────────── */
#question-card { display: none; flex-direction: column; gap: 12px; }
#question-card.visible { display: flex; }

.coach-question-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--coach-color);
  letter-spacing: 0.5px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.coach-question-header .crown { font-size: 16px; }

#question-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
}

#question-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  background: var(--surface2);
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

#answer-input { resize: none; height: 64px; }

/* ── Report complete card ───────────────────────────────────── */
#complete-card { display: none; flex-direction: column; gap: 10px; }
#complete-card.visible { display: flex; }

#complete-card .complete-msg {
  font-size: 13px;
  color: var(--success-color);
  font-weight: 600;
  padding: 12px;
  background: rgba(80, 184, 144, 0.08);
  border: 1px solid rgba(80, 184, 144, 0.2);
  border-radius: 6px;
  text-align: center;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  padding: 10px 18px;
  border: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.3px;
}

.btn-full { width: 100%; }

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 8px var(--accent-glow);
}
.btn-primary:hover {
  background: color-mix(in srgb, var(--accent) 82%, white);
  box-shadow: 0 4px 16px var(--accent-glow);
  transform: translateY(-1px);
}
.btn-primary:active  { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }

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

/* ── Debug panel ────────────────────────────────────────────── */
#debug-panel { flex: 1; min-height: 0; }

#debug-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--debug-green);
  background: #0a0d14;
  min-height: 0;
}

.debug-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 2px 0;
  line-height: 1.4;
}

.debug-icon { flex-shrink: 0; }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }
