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

:root {
  --bg: #0b0d14;
  --bg-panel: #10121c;
  --bg-card: #161928;
  --bg-card-hover: #1c2035;
  --bg-input: #0e1120;
  --border: #1e2340;
  --border-focus: #3b4280;
  --text: #e2e4f0;
  --text-muted: #6b7199;
  --text-dim: #3d4266;
  --purple: #7c3aed;
  --purple-light: #a78bfa;
  --blue: #2563eb;
  --blue-light: #60a5fa;
  --cyan: #06b6d4;
  --cyan-light: #67e8f9;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --glow-purple: 0 0 16px rgba(124,58,237,0.25);
  --glow-blue: 0 0 16px rgba(37,99,235,0.25);
  --transition: 0.2s ease;
}

[data-theme="light"] {
  --bg: #f0f2f8;
  --bg-panel: #e8eaf4;
  --bg-card: #ffffff;
  --bg-card-hover: #f5f6fc;
  --bg-input: #ffffff;
  --border: #d1d5f0;
  --border-focus: #7c3aed;
  --text: #1a1c2e;
  --text-muted: #5c6080;
  --text-dim: #9ba0c0;
}

html { font-size: 14px; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

/* ─── Header ──────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.header-left { display: flex; align-items: center; gap: 16px; }
.header-right { display: flex; align-items: center; gap: 10px; }

.logo { display: flex; align-items: center; gap: 8px; }
.logo-text { font-size: 15px; font-weight: 700; letter-spacing: -0.3px; color: var(--text); }

.powered-by { font-size: 11px; color: var(--text-muted); }
.gemini-badge {
  background: linear-gradient(90deg, #7c3aed, #2563eb);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 600;
}

.health-indicator {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background var(--transition), box-shadow var(--transition);
}
.health-indicator.ok { background: var(--green); box-shadow: 0 0 6px var(--green); }
.health-indicator.error { background: var(--red); box-shadow: 0 0 6px var(--red); }

.health-label { font-size: 11px; color: var(--text-muted); }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.btn-icon:hover { color: var(--text); background: var(--bg-card); }

/* ─── Error Banner ────────────────────────────────────────────────────────── */
.error-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(239,68,68,0.12);
  border-bottom: 1px solid rgba(239,68,68,0.35);
  color: #fca5a5;
  font-size: 12px;
  padding: 8px 20px;
  flex-shrink: 0;
  animation: slide-in 0.2s ease;
}
.error-banner-icon { font-size: 14px; flex-shrink: 0; }
.error-banner span:nth-child(2) { flex: 1; line-height: 1.4; }
.error-banner-close {
  background: none;
  border: none;
  color: #fca5a5;
  cursor: pointer;
  font-size: 13px;
  padding: 0 4px;
  opacity: 0.7;
  flex-shrink: 0;
}
.error-banner-close:hover { opacity: 1; }

/* ─── Main Layout ─────────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr 260px;
  grid-template-rows: 1fr;
  gap: 0;
  flex: 1;
  min-height: 0;
  height: 0;        /* forces grid rows to respect flex parent height */
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-panel);
}

.panel-left {
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.panel-center {
  background: var(--bg);
  overflow-y: auto;
  padding: 16px;
  gap: 12px;
  display: flex;
  flex-direction: column;
}

.panel-right {
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

/* ─── Section Titles ──────────────────────────────────────────────────────── */
.section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-header .section-title { margin-bottom: 0; }

/* ─── Left Panel: Input ───────────────────────────────────────────────────── */
.input-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.textarea-wrapper {
  position: relative;
  margin-bottom: 12px;
}

textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.55;
  padding: 10px 12px;
  padding-bottom: 22px;
  resize: none;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.1);
}
textarea::placeholder { color: var(--text-dim); }

.char-count {
  position: absolute;
  bottom: 6px;
  right: 10px;
  font-size: 10px;
  color: var(--text-dim);
  pointer-events: none;
}

.sample-tasks { margin-bottom: 14px; }
.label-small {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.chips { display: flex; flex-direction: column; gap: 4px; }
.chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  padding: 5px 9px;
  text-align: left;
  transition: all var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip:hover {
  border-color: var(--purple);
  color: var(--purple-light);
  background: rgba(124,58,237,0.08);
}

.submit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  user-select: none;
}
.toggle-row input { display: none; }
.toggle-track {
  width: 30px;
  height: 16px;
  background: var(--border);
  border-radius: 99px;
  position: relative;
  transition: background var(--transition);
  flex-shrink: 0;
}
.toggle-thumb {
  position: absolute;
  width: 12px;
  height: 12px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: left var(--transition);
}
.toggle-row input:checked ~ .toggle-track { background: var(--purple); }
.toggle-row input:checked ~ .toggle-track .toggle-thumb { left: 16px; }

.btn-primary {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--purple);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  transition: all var(--transition);
  flex-shrink: 0;
}
.btn-primary:hover { background: #6d28d9; box-shadow: var(--glow-purple); }
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-icon-arrow { flex-shrink: 0; }

/* ─── Left Panel: History ─────────────────────────────────────────────────── */
.history-section { padding: 16px; flex: 1; overflow-y: auto; min-height: 0; }

.task-history { display: flex; flex-direction: column; gap: 6px; }

.history-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 8px 10px;
  transition: all var(--transition);
}
.history-item:hover { border-color: var(--purple); background: var(--bg-card-hover); }
.history-item .hi-task {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}
.history-item .hi-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--text-dim);
}
.hi-status {
  padding: 1px 5px;
  border-radius: 99px;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.hi-status.completed { background: rgba(16,185,129,0.15); color: var(--green); }
.hi-status.failed { background: rgba(239,68,68,0.15); color: var(--red); }
.hi-status.running { background: rgba(124,58,237,0.15); color: var(--purple-light); }

.empty-state {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 20px 0;
}

/* ─── Center: Cards ───────────────────────────────────────────────────────── */
.workflow-card, .plan-card, .output-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.status-badge.planning { background: rgba(37,99,235,0.15); color: var(--blue-light); border-color: rgba(37,99,235,0.3); }
.status-badge.executing { background: rgba(124,58,237,0.15); color: var(--purple-light); border-color: rgba(124,58,237,0.3); }
.status-badge.reflecting { background: rgba(245,158,11,0.15); color: var(--amber); border-color: rgba(245,158,11,0.3); }
.status-badge.completed { background: rgba(16,185,129,0.15); color: var(--green); border-color: rgba(16,185,129,0.3); }
.status-badge.failed { background: rgba(239,68,68,0.15); color: var(--red); border-color: rgba(239,68,68,0.3); }

/* ─── Agent Graph ─────────────────────────────────────────────────────────── */
.agent-graph { padding: 16px; overflow-x: auto; }

.graph-track {
  display: flex;
  align-items: center;
  gap: 0;
  min-width: max-content;
  margin: 0 auto;
}

.agent-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  min-width: 88px;
  width: 88px;
  transition: all var(--transition);
  cursor: default;
}
.agent-node.active,
.agent-node.running {
  border-color: var(--purple);
  background: rgba(124,58,237,0.1);
  box-shadow: var(--glow-purple);
}
.agent-node.active .node-icon,
.agent-node.running .node-icon { animation: pulse-icon 1s ease-in-out infinite; }
.agent-node.done {
  border-color: var(--green);
  background: rgba(16,185,129,0.06);
}
.agent-node.error,
.agent-node.failed {
  border-color: var(--red);
  background: rgba(239,68,68,0.06);
}

.node-icon { font-size: 20px; line-height: 1; }
.node-label { font-size: 11px; font-weight: 700; color: var(--text); }
.node-sub { font-size: 10px; color: var(--text-dim); }

.node-state {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 99px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.node-state.idle { background: var(--bg-card); color: var(--text-dim); }
.node-state.running { background: rgba(124,58,237,0.2); color: var(--purple-light); animation: blink 1s step-start infinite; }
.node-state.done { background: rgba(16,185,129,0.2); color: var(--green); }
.node-state.error { background: rgba(239,68,68,0.2); color: var(--red); }

.graph-arrow {
  width: 28px;
  height: 2px;
  background: linear-gradient(90deg, var(--border), var(--border-focus));
  flex-shrink: 0;
  position: relative;
}
.graph-arrow::after {
  content: '';
  position: absolute;
  right: -4px;
  top: -3px;
  border: 4px solid transparent;
  border-left-color: var(--border-focus);
}

/* ─── Plan Steps ──────────────────────────────────────────────────────────── */
.plan-steps { padding: 12px 16px; display: flex; flex-direction: column; gap: 6px; }
.plan-progress { font-size: 11px; color: var(--text-muted); }

.step-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.step-item.running { border-color: var(--purple); background: rgba(124,58,237,0.05); }
.step-item.done { border-color: rgba(16,185,129,0.3); opacity: 0.7; }
.step-item.failed { border-color: rgba(239,68,68,0.3); }

.step-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
  color: var(--text-muted);
  margin-top: 1px;
}
.step-item.done .step-num { background: var(--green); color: white; }
.step-item.running .step-num { background: var(--purple); color: white; }
.step-item.failed .step-num { background: var(--red); color: white; }

.step-body { flex: 1; min-width: 0; }
.step-title { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.step-desc { font-size: 11px; color: var(--text-muted); line-height: 1.4; }
.step-tool {
  display: inline-block;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(6,182,212,0.15);
  color: var(--cyan);
  margin-top: 3px;
}

/* ─── Output Card ─────────────────────────────────────────────────────────── */
.output-actions { display: flex; align-items: center; gap: 8px; }

.quality-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
}

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  padding: 3px 9px;
  transition: all var(--transition);
}
.btn-ghost:hover { border-color: var(--purple); color: var(--purple-light); }

.output-content {
  padding: 16px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 80px;
  max-height: 600px;
  overflow-y: auto;
}

/* ─── Right Panel: Events ─────────────────────────────────────────────────── */
.events-section {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 200px;
  max-height: 45vh;
}

.btn-ghost-sm {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.btn-ghost-sm:hover { color: var(--text-muted); background: var(--bg-card); }

.event-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

.event-item {
  padding: 7px 9px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--border);
  animation: slide-in 0.2s ease;
}
.event-item.memory { border-left-color: var(--blue); }
.event-item.planner { border-left-color: var(--purple); }
.event-item.executor { border-left-color: var(--cyan); }
.event-item.critic { border-left-color: var(--amber); }
.event-item.error { border-left-color: var(--red); }

.event-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}
.event-agent {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.event-time { font-size: 9px; color: var(--text-dim); }
.event-msg { font-size: 11px; color: var(--text-muted); line-height: 1.4; }

/* ─── Right Panel: Metrics ────────────────────────────────────────────────── */
.metrics-section { padding: 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: border-color var(--transition);
}
.metric-card:hover { border-color: var(--border-focus); }
.metric-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1;
}
.metric-label { font-size: 9px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }

/* ─── Right Panel: Tools ──────────────────────────────────────────────────── */
.tools-section { padding: 14px; flex-shrink: 0; }

.tool-list { display: flex; flex-direction: column; gap: 3px; }
.tool-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 3px 0;
}
.tool-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--cyan);
  flex-shrink: 0;
}

/* ─── Animations ──────────────────────────────────────────────────────────── */
@keyframes pulse-icon {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.8; }
}

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

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

/* ─── Loading Spinner ─────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

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

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .layout { grid-template-columns: 240px 1fr 220px; }
  .agent-node { min-width: 78px; width: 78px; }
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 220px 1fr; }
  .panel-right { display: none; }
}
@media (max-width: 680px) {
  .layout { grid-template-columns: 1fr; }
  .panel-left { display: none; }
  body { overflow: auto; }
  .panel-center { min-height: 100vh; }
}
