/* ══════════════════════════════════════════════
   DESIGN TOKENS
══════════════════════════════════════════════ */
:root {
  --bg:         #070B14;
  --surface:    #0D1424;
  --surface-2:  #111B2E;
  --border:     #1B2B44;
  --border-hi:  #253A58;

  --text:       #D4E4FF;
  --text-dim:   #5A7698;
  --text-muted: #2C4060;

  --orange:     #FF8C42;
  --green:      #00CC7A;
  --blue:       #4B7EFF;
  --purple:     #8B7CF8;

  --ff-display: 'Space Grotesk', system-ui, sans-serif;
  --ff-body:    'Inter', system-ui, sans-serif;
  --ff-mono:    'JetBrains Mono', 'Fira Code', monospace;

  --r:    8px;
  --r-lg: 12px;
}

/* ══════════════════════════════════════════════
   RESET
══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--ff-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

input, button { font-family: inherit; }

/* ══════════════════════════════════════════════
   HEADER
══════════════════════════════════════════════ */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.logo-mark {
  font-size: 26px;
  color: var(--blue);
  line-height: 1;
}

.header-titles h1 {
  font-family: var(--ff-display);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.header-titles p {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.api-key-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.api-key-group > label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  white-space: nowrap;
}

.api-key-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

#apiKeyInput {
  width: 270px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  padding: 7px 12px;
  font-size: 13px;
  font-family: var(--ff-mono);
  transition: border-color 150ms;
}

#apiKeyInput:focus {
  outline: none;
  border-color: var(--blue);
}

.api-key-hint {
  font-size: 11px;
  color: var(--text-muted);
}

/* ══════════════════════════════════════════════
   MAIN LAYOUT
══════════════════════════════════════════════ */
main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 32px 80px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 16px;
}

/* ══════════════════════════════════════════════
   INPUT PANEL
══════════════════════════════════════════════ */
.input-panel {
  padding: 24px 28px;
}

.form-row {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 2;
  min-width: 160px;
}

.field-sm {
  flex: 1;
  min-width: 120px;
}

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}

.field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  padding: 9px 14px;
  font-size: 14px;
  width: 100%;
  transition: border-color 150ms;
}

.field input:focus {
  outline: none;
  border-color: var(--blue);
}

.field input::placeholder { color: var(--text-muted); }

.run-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 22px;
  height: 42px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--r);
  font-family: var(--ff-display);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 150ms, transform 80ms;
}

.run-btn:hover  { background: #5D8FFF; }
.run-btn:active { transform: scale(0.97); }

.run-btn:disabled {
  background: var(--border-hi);
  cursor: not-allowed;
  transform: none;
}

.btn-arrow { font-size: 15px; }

.form-error {
  margin-top: 10px;
  font-size: 13px;
  color: #FF6B7A;
  min-height: 18px;
}

/* ══════════════════════════════════════════════
   PIPELINE
══════════════════════════════════════════════ */
.pipeline-panel {
  padding: 28px 28px 24px;
}

.pipeline {
  display: flex;
  align-items: stretch;
  gap: 0;
}

/* ── Node ── */
.node {
  flex: 1;
  background: linear-gradient(150deg, var(--surface-2) 0%, var(--bg) 100%);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 14px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  min-width: 100px;
  transition: border-color 300ms, box-shadow 300ms;
  cursor: default;
}

.node-top {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.node-num {
  font-family: var(--ff-mono);
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  transition: color 300ms;
}

.node-status {
  font-size: 11px;
  color: var(--text-muted);
  transition: color 300ms;
  min-width: 14px;
  text-align: right;
}

.node-icon {
  font-size: 26px;
  color: var(--text-muted);
  line-height: 1;
  margin: 2px 0;
  transition: color 300ms;
}

.node-name {
  font-family: var(--ff-display);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.3;
  transition: color 300ms;
}

.node-tag {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  margin-top: 2px;
  transition: color 300ms, border-color 300ms, background 300ms;
}

/* ── Node: Live AI ── */
.node-live { border-color: rgba(139, 124, 248, 0.2); }
.node-live .node-icon { color: rgba(139, 124, 248, 0.35); }
.node-live .node-name { color: rgba(139, 124, 248, 0.6); }

.live-tag {
  color: var(--purple) !important;
  border-color: rgba(139, 124, 248, 0.3) !important;
  background: rgba(139, 124, 248, 0.07) !important;
}

/* ── Node: Active ── */
.node.active {
  border-color: var(--orange);
  box-shadow: 0 0 0 1px rgba(255, 140, 66, 0.12), 0 0 28px rgba(255, 140, 66, 0.1);
  animation: pulse-orange 2s ease-in-out infinite;
}

.node.active .node-icon  { color: var(--orange); }
.node.active .node-name  { color: var(--text); }
.node.active .node-num   { color: var(--orange); }

@keyframes pulse-orange {
  0%, 100% { box-shadow: 0 0 0 1px rgba(255,140,66,.12), 0 0 20px rgba(255,140,66,.08); }
  50%       { box-shadow: 0 0 0 1px rgba(255,140,66,.25), 0 0 40px rgba(255,140,66,.18); }
}

/* ── Node: Active + Live ── */
.node-live.active {
  border-color: var(--purple);
  animation: pulse-purple 2s ease-in-out infinite;
}

.node-live.active .node-icon { color: var(--purple); }
.node-live.active .node-name { color: var(--purple); }
.node-live.active .node-num  { color: var(--purple); }

@keyframes pulse-purple {
  0%, 100% { box-shadow: 0 0 0 1px rgba(139,124,248,.18), 0 0 24px rgba(139,124,248,.12); }
  50%       { box-shadow: 0 0 0 1px rgba(139,124,248,.35), 0 0 48px rgba(139,124,248,.22); }
}

/* ── Node: Done ── */
.node.done {
  border-color: rgba(0, 204, 122, 0.3);
  box-shadow: 0 0 18px rgba(0, 204, 122, 0.05);
}

.node.done .node-icon   { color: var(--green); }
.node.done .node-name   { color: var(--text); }
.node.done .node-num    { color: var(--green); }
.node.done .node-status { color: var(--green); }

/* ── Connector ── */
.connector {
  width: 44px;
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
  align-self: center;
  overflow: visible;
}

.conn-line {
  width: 100%;
  height: 1px;
  background: var(--border);
  transition: background 500ms;
}

.conn-dot {
  position: absolute;
  top: 50%;
  left: -6px;
  transform: translateY(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 12px var(--orange), 0 0 24px rgba(255,140,66,.5);
  opacity: 0;
  pointer-events: none;
}

/* flowing: particle travels left → right */
.connector.flowing .conn-dot {
  animation: dot-travel 650ms cubic-bezier(.4,0,.2,1) forwards;
}

.connector.flowing .conn-line {
  background: rgba(255, 140, 66, 0.35);
}

@keyframes dot-travel {
  0%   { left: -6px;           opacity: 1; }
  100% { left: calc(100% + 6px); opacity: 0; }
}

.connector.done .conn-line {
  background: rgba(0, 204, 122, 0.35);
}

/* ── Node spinner for active state ── */
.node.active .node-status::after {
  content: '';
  display: inline-block;
  width: 9px;
  height: 9px;
  border: 1.5px solid transparent;
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 650ms linear infinite;
  vertical-align: middle;
}

.node-live.active .node-status::after {
  border-top-color: var(--purple);
}

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

/* ══════════════════════════════════════════════
   ACTIVITY LOG
══════════════════════════════════════════════ */
.activity-panel { overflow: hidden; }

.activity-idle {
  padding: 22px 28px;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
}

.activity-idle strong { color: var(--text); }

.activity-live { display: flex; flex-direction: column; }

.activity-header {
  padding: 10px 20px;
  font-family: var(--ff-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.activity-log {
  padding: 14px 20px;
  font-family: var(--ff-mono);
  font-size: 13px;
  line-height: 1.75;
  min-height: 130px;
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.activity-log::-webkit-scrollbar { width: 4px; }
.activity-log::-webkit-scrollbar-track { background: transparent; }
.activity-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.log-line {
  display: block;
  white-space: pre-wrap;
  word-break: break-all;
  opacity: 0;
  transform: translateY(3px);
  animation: line-in 80ms ease-out forwards;
  color: #7090B8;
}

@keyframes line-in {
  to { opacity: 1; transform: translateY(0); }
}

.log-line.log-success  { color: var(--green); }
.log-line.log-tool     { color: #5A7898; }
.log-line.log-response { color: #4A6A88; }
.log-line.log-data     { color: #4F6880; }
.log-line.log-stream   { color: var(--purple); }

/* ══════════════════════════════════════════════
   OUTPUT PANEL
══════════════════════════════════════════════ */
.output-panel {
  border-color: rgba(0, 204, 122, 0.18);
  overflow: hidden;
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.output-label {
  font-family: var(--ff-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--green);
}

.output-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: rgba(0, 204, 122, 0.55);
  border: 1px solid rgba(0, 204, 122, 0.2);
  border-radius: 4px;
  padding: 2px 8px;
}

.output-badge.demo-badge {
  color: rgba(139, 124, 248, 0.65);
  border-color: rgba(139, 124, 248, 0.25);
}

.output-pre {
  padding: 24px 28px;
  font-family: var(--ff-mono);
  font-size: 13px;
  line-height: 1.85;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 600px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.output-pre::-webkit-scrollbar { width: 4px; }
.output-pre::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* streaming cursor */
.output-pre.streaming::after {
  content: '▋';
  color: var(--green);
  animation: blink 700ms step-end infinite;
}

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

/* ══════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════ */
@media (max-width: 960px) {
  .node { min-width: 0; padding: 14px 10px 12px; }
  .node-icon { font-size: 22px; }
  .node-name { font-size: 11px; }
  .connector { width: 28px; }
}

@media (max-width: 780px) {
  .site-header { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px 20px; }
  .api-key-group { width: 100%; }
  #apiKeyInput { width: 100%; }
  main { padding: 20px 16px 60px; }
  .pipeline { flex-wrap: wrap; gap: 8px; justify-content: center; }
  .connector { display: none; }
  .node { min-width: 140px; flex: none; }
  .form-row { flex-direction: column; }
  .field, .field-sm { width: 100%; flex: none; min-width: unset; }
  .run-btn { width: 100%; justify-content: center; }
}

/* ══════════════════════════════════════════════
   THEME TOGGLE BUTTON
══════════════════════════════════════════════ */
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms, border-color 150ms, color 150ms, transform 100ms;
  flex-shrink: 0;
  line-height: 1;
}

.theme-toggle:hover {
  border-color: var(--blue);
  color: var(--text);
  transform: scale(1.08);
}

/* ══════════════════════════════════════════════
   LIGHT MODE OVERRIDES
══════════════════════════════════════════════ */
[data-theme="light"] {
  --bg:         #F0F4FA;
  --surface:    #FFFFFF;
  --surface-2:  #E8EEF8;
  --border:     #D0DAF0;
  --border-hi:  #B8C8E8;
  --text:       #0B1628;
  --text-dim:   #445878;
  --text-muted: #8098B8;
}

[data-theme="light"] body {
  background: var(--bg);
}

[data-theme="light"] .node {
  background: linear-gradient(150deg, #FFFFFF 0%, #F4F7FF 100%);
  box-shadow: 0 1px 4px rgba(11, 22, 40, 0.06);
}

[data-theme="light"] .run-btn {
  box-shadow: 0 2px 8px rgba(75, 126, 255, 0.25);
}

[data-theme="light"] .site-header {
  box-shadow: 0 1px 0 var(--border);
}

/* Log line colours for light mode */
[data-theme="light"] .activity-log { color: #3A5878; }
[data-theme="light"] .log-line           { color: #3A5878; }
[data-theme="light"] .log-line.log-success  { color: #007A47; }
[data-theme="light"] .log-line.log-tool     { color: #5A6E88; }
[data-theme="light"] .log-line.log-response { color: #6A7E98; }
[data-theme="light"] .log-line.log-data     { color: #7A8EA8; }
[data-theme="light"] .log-line.log-stream   { color: #6655CC; }

/* Output pre in light mode */
[data-theme="light"] .output-pre { color: #0B1628; }
[data-theme="light"] .output-panel { border-color: rgba(0, 204, 122, 0.3); }

/* Form inputs in light */
[data-theme="light"] .field input {
  background: #FFFFFF;
  border-color: var(--border);
  color: var(--text);
}

[data-theme="light"] #apiKeyInput {
  background: #FFFFFF;
  color: var(--text);
}

[data-theme="light"] .panel {
  box-shadow: 0 1px 6px rgba(11, 22, 40, 0.06);
}

/* Connector line in light mode (make visible on white) */
[data-theme="light"] .conn-line { background: #C4D0E8; }
[data-theme="light"] .connector.done .conn-line { background: rgba(0, 170, 100, 0.45); }
[data-theme="light"] .connector.flowing .conn-line { background: rgba(220, 120, 40, 0.4); }

/* Activity log header */
[data-theme="light"] .activity-header { color: var(--text-dim); }

/* Node live tag in light */
[data-theme="light"] .node-live { border-color: rgba(139, 124, 248, 0.3); }

/* Scrollbar in light mode */
[data-theme="light"] .activity-log,
[data-theme="light"] .output-pre {
  scrollbar-color: var(--border) transparent;
}
