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

/* ── Modern Scrollbars (hover-to-reveal) ─────────────── */
.messages,
.trace-panel,
.pipeline,
.scenarios {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
  transition: scrollbar-color 0.3s;
}
.messages:hover,
.trace-panel:hover,
.pipeline:hover,
.scenarios:hover {
  scrollbar-color: rgba(136, 136, 160, 0.35) transparent;
}

/* Webkit (Chrome, Safari, Edge) */
.messages::-webkit-scrollbar,
.trace-panel::-webkit-scrollbar,
.pipeline::-webkit-scrollbar,
.scenarios::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.messages::-webkit-scrollbar-track,
.trace-panel::-webkit-scrollbar-track,
.pipeline::-webkit-scrollbar-track,
.scenarios::-webkit-scrollbar-track {
  background: transparent;
}
.messages::-webkit-scrollbar-thumb,
.trace-panel::-webkit-scrollbar-thumb,
.pipeline::-webkit-scrollbar-thumb,
.scenarios::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 3px;
  transition: background 0.3s;
}
.messages:hover::-webkit-scrollbar-thumb,
.trace-panel:hover::-webkit-scrollbar-thumb,
.pipeline:hover::-webkit-scrollbar-thumb,
.scenarios:hover::-webkit-scrollbar-thumb {
  background: rgba(136, 136, 160, 0.35);
}
.messages:hover::-webkit-scrollbar-thumb:hover,
.trace-panel:hover::-webkit-scrollbar-thumb:hover,
.pipeline:hover::-webkit-scrollbar-thumb:hover,
.scenarios:hover::-webkit-scrollbar-thumb:hover {
  background: rgba(136, 136, 160, 0.55);
}

:root {
  --bg: #07070f;
  --surface: #0e0e1a;
  --border: #1a1a2e;
  --text: #e2e2ee;
  --text-dim: #8888a0;
  --accent: #6366f1;
  --accent-dim: #4f46e5;
  --green: #22c55e;
  --amber: #f59e0b;
  --rose: #f43f5e;
  --cyan: #06b6d4;
  --emerald: #10b981;
  --purple: #a78bfa;
  --radius: 8px;
}

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

/* ── Header ──────────────────────────────────────────── */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

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

.logo-mark {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.06);
}
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.3px; color: var(--text); }

.badge {
  font-size: 11px; font-weight: 600;
  background: var(--accent); color: white;
  padding: 2px 8px; border-radius: 100px;
  text-transform: uppercase; letter-spacing: 0.5px;
}

.api-badge { font-size: 12px; color: var(--text-dim); }
.api-badge code {
  background: var(--bg); padding: 2px 6px;
  border-radius: 4px; font-size: 11px; color: var(--cyan);
}

.source-link {
  font-size: 12px; color: var(--accent);
  text-decoration: none; border: 1px solid var(--accent-dim);
  padding: 4px 12px; border-radius: 100px;
  transition: background 0.2s;
}
.source-link:hover { background: var(--accent-dim); color: white; }

/* ── Main Layout ─────────────────────────────────────── */
main {
  flex: 1; display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1px; background: var(--border);
  min-height: 0; overflow: hidden;
}

/* ── Chat Panel ──────────────────────────────────────── */
.chat-panel {
  background: var(--bg);
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0;
}

.chat-header {
  display: flex; justify-content: space-between;
  align-items: center; padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header h2 { font-size: 14px; font-weight: 600; }

.clear-btn {
  font-size: 12px; background: none;
  border: 1px solid var(--border); color: var(--text-dim);
  padding: 4px 12px; border-radius: var(--radius);
  cursor: pointer; transition: all 0.2s;
}
.clear-btn:hover { border-color: var(--rose); color: var(--rose); }

/* Scenarios */
.scenarios {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-bottom: 1px solid var(--border);
  overflow-x: auto; flex-shrink: 0;
}
.scenarios-label { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

.chip {
  font-size: 12px; background: var(--surface);
  border: 1px solid var(--border); color: var(--text);
  padding: 5px 12px; border-radius: 100px;
  cursor: pointer; white-space: nowrap; transition: all 0.2s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* Messages */
.messages {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
}

.message {
  max-width: 80%; padding: 10px 14px;
  border-radius: 12px; font-size: 14px;
  line-height: 1.5; animation: fadeIn 0.2s ease;
  white-space: pre-wrap; word-break: break-word;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.message.user {
  align-self: flex-end; background: var(--accent);
  color: white; border-bottom-right-radius: 4px;
}
.message.assistant {
  align-self: flex-start; background: var(--surface);
  border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
.message.assistant.streaming { border-color: var(--accent-dim); }

.cursor {
  display: inline-block; width: 2px; height: 14px;
  background: var(--accent); margin-left: 2px;
  vertical-align: text-bottom; animation: blink 0.8s infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* Welcome message */
.welcome-message {
  display: flex !important; align-items: flex-start; gap: 12px;
  background: linear-gradient(135deg, rgba(99,102,241,0.08), rgba(168,85,247,0.06)) !important;
  border: 1px solid rgba(99,102,241,0.15) !important;
  border-radius: 16px !important; padding: 16px !important;
  max-width: 90% !important; animation: fadeIn 0.4s ease;
}
.welcome-avatar {
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.welcome-content { display: flex; flex-direction: column; gap: 4px; }
.welcome-name {
  font-size: 13px; font-weight: 700;
  background: linear-gradient(to right, #FBBF24, #F43F5E, #A855F7, #10B981);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.welcome-content span { font-size: 14px; color: var(--text); line-height: 1.5; }

/* Typing indicator */
.typing-indicator {
  display: flex; align-items: center; gap: 4px;
  padding: 14px 18px !important;
}
.typing-indicator .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-dim); animation: typing-bounce 1.4s infinite ease-in-out;
}
.typing-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Action-aware typing indicator (replaces dots during tool calls) */
.typing-indicator.typing-action {
  gap: 8px; padding: 12px 16px !important;
}
.typing-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.typing-label {
  font-size: 13px; color: var(--text-dim);
  animation: fade-pulse 2s ease-in-out infinite;
}
@keyframes fade-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Inline action spinner (shown inside message bubble during tool calls) */
.inline-action {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* Input bar */
.input-bar {
  display: flex; gap: 8px; padding: 12px 20px;
  border-top: 1px solid var(--border); background: var(--surface);
  flex-shrink: 0;
}
.input-bar input {
  flex: 1; background: var(--bg);
  border: 1px solid var(--border); color: var(--text);
  padding: 10px 14px; border-radius: var(--radius);
  font-size: 14px; outline: none; transition: border-color 0.2s;
}
.input-bar input:focus { border-color: var(--accent); }
.input-bar input:disabled { opacity: 0.5; }

.input-bar button {
  background: var(--accent); color: white; border: none;
  padding: 10px 20px; border-radius: var(--radius);
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background 0.2s;
}
.input-bar button:hover { background: var(--accent-dim); }
.input-bar button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Trace Panel ─────────────────────────────────────── */
.trace-panel {
  background: var(--bg);
  overflow-y: auto;
  display: flex; flex-direction: column;
  min-height: 0;
}

.trace-header {
  display: flex; justify-content: space-between;
  align-items: center; padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.trace-header h2 { font-size: 14px; font-weight: 600; }

.trace-status {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim);
}
.trace-status.connecting { color: var(--amber); }
.trace-status.active { color: var(--green); }
.trace-status.done { color: var(--cyan); }
.trace-status.error { color: var(--rose); }

.trace-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.trace-section h3 {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim); margin-bottom: 8px;
}

/* Pipeline steps */
.pipeline {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 200px; overflow-y: auto;
}
.pipeline-step {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; padding: 5px 10px;
  border-radius: 6px; background: var(--surface);
  border: 1px solid var(--border);
  animation: fadeIn 0.2s ease;
}
.pipeline-step.active { border-color: var(--accent-dim); }
.pipeline-step.done { border-color: var(--green); }
.pipeline-step.done .step-dot { background: var(--green); }

.step-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
}
.pipeline-step.active .step-dot { animation: pulse-dot 1s infinite; }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.step-label { color: var(--text-dim); }
.pipeline-step.active .step-label { color: var(--text); }
.pipeline-step.done .step-label { color: var(--green); }

/* Actions list */
.actions-list {
  display: flex; flex-direction: column; gap: 4px;
}
.empty-state { font-size: 12px; color: var(--text-dim); font-style: italic; }

.action-item {
  font-size: 12px; background: var(--surface);
  border: 1px solid var(--border); padding: 6px 10px;
  border-radius: 6px; display: flex;
  align-items: center; gap: 8px;
  animation: fadeIn 0.3s ease;
}

.action-type {
  font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 4px;
  text-transform: uppercase; letter-spacing: 0.3px;
}
.action-type.webhook { background: rgba(245, 158, 11, 0.15); color: var(--amber); }
.action-type.knowledge_base { background: rgba(6, 182, 212, 0.15); color: var(--cyan); }
.action-type.handoff { background: rgba(244, 63, 94, 0.15); color: var(--rose); }

.action-name { flex: 1; color: var(--text); }

.action-status {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}
.action-status.pending { background: var(--amber); animation: pulse-dot 1s infinite; }
.action-status.success { background: var(--green); }
.action-status.failed { background: var(--rose); }

/* Detection grid */
.detection-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.det-item {
  background: var(--surface); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 6px;
}
.det-label {
  font-size: 10px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.3px;
  display: block;
}
.det-value {
  font-size: 13px; font-weight: 700; color: var(--emerald);
  text-transform: uppercase;
}

/* Mood-specific colors */
.det-value.mood-frustrated { color: var(--rose); }
.det-value.mood-angry { color: var(--rose); }
.det-value.mood-urgent { color: var(--amber); }
.det-value.mood-happy { color: var(--green); }
.det-value.mood-confused { color: var(--cyan); }
.det-value.mood-neutral { color: var(--emerald); }

/* Stats grid */
.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 6px;
}
.stat-label {
  font-size: 10px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.3px;
  display: block;
}
.stat-value {
  font-size: 14px; font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-trace { font-size: 11px; font-family: 'SF Mono', monospace; color: var(--purple); }
.stat-latency { color: var(--amber); font-variant-numeric: tabular-nums; }
.stat-latency.timer-active { animation: pulse-dot 1s infinite; }
.stat-cost { color: var(--green); }

/* Hint */
.hint-section { }
.hint-text { font-size: 12px; color: var(--text-dim); line-height: 1.6; margin-bottom: 6px; }
.hint-text strong { color: var(--text); }
.hint-orders {
  font-size: 12px; color: var(--text-dim);
  background: var(--surface); padding: 6px 10px;
  border-radius: 6px; border: 1px solid var(--border);
}
.hint-orders strong { color: var(--purple); }

/* ── Footer ──────────────────────────────────────────── */
footer {
  display: flex; justify-content: center;
  align-items: center; gap: 16px;
  padding: 10px 24px; border-top: 1px solid var(--border);
  background: var(--surface); font-size: 11px;
  color: var(--text-dim); flex-wrap: wrap;
  flex-shrink: 0;
}
.footer-brand { display: flex; align-items: center; gap: 6px; }
.footer-brand strong {
  background: linear-gradient(to right, #FBBF24, #F43F5E, #A855F7, #10B981);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; font-weight: 700;
}
.footer-cta {
  font-size: 11px; font-weight: 600;
  background: var(--accent); color: white;
  padding: 4px 14px; border-radius: 100px;
  text-decoration: none; text-transform: uppercase;
  letter-spacing: 0.5px; transition: background 0.2s;
}
.footer-cta:hover { background: var(--accent-dim); }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 800px) {
  main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .trace-panel { max-height: 300px; border-top: 1px solid var(--border); }
  .header-right { display: none; }
}
