:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3347;
  --accent: #4f8ef7;
  --accent-dim: #1e3a6e;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --text: #e2e8f0;
  --text-dim: #64748b;
  --text-muted: #94a3b8;
  --radius: 10px;
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

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

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

.logo {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: white;
}

header h1 { font-size: 15px; font-weight: 600; }
header p  { font-size: 11px; color: var(--text-dim); margin-top: 1px; }

.header-right { display: flex; align-items: center; gap: 8px; }

#conv-id-display {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  background: var(--surface2);
  padding: 4px 8px;
  border-radius: 6px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--accent-dim);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Main layout ─────────────────────────────────────────────────────────── */
main {
  display: grid;
  grid-template-columns: 1fr 380px;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

/* ── Chat panel ──────────────────────────────────────────────────────────── */
#chat-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.message {
  display: flex;
  gap: 10px;
  max-width: 82%;
  animation: fadeUp 0.2s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }
.message.system { align-self: center; max-width: 100%; }

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  flex-shrink: 0;
}
.message.user .avatar      { background: var(--accent); color: white; }
.message.assistant .avatar { background: var(--surface2); color: var(--accent); border: 1px solid var(--border); }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.55;
  white-space: pre-wrap;
  font-size: 14px;
}
.message.user .bubble {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 3px;
}
.message.assistant .bubble {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}
.message.system .bubble {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  padding: 6px 12px;
  border-radius: 20px;
}

.typing-indicator {
  display: flex; align-items: center; gap: 4px;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-bottom-left-radius: 3px;
  width: fit-content;
}
.dot {
  width: 6px; height: 6px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-4px); }
}

/* ── Input area ──────────────────────────────────────────────────────────── */
#input-area {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#user-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 14px;
  resize: none;
  min-height: 42px;
  max-height: 140px;
  transition: border-color 0.15s;
  outline: none;
}
#user-input:focus { border-color: var(--accent); }
#user-input::placeholder { color: var(--text-dim); }

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
}
.btn:hover { opacity: 0.85; }
.btn:active { opacity: 0.7; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: white; }
.btn-ghost   { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }
.btn-danger  { background: #7f1d1d; color: #fca5a5; border: 1px solid #991b1b; }

.quick-hints {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 10px;
}

.hint-btn {
  font-size: 11px;
  padding: 4px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.hint-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Right panel ─────────────────────────────────────────────────────────── */
#right-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}
.tab-btn {
  flex: 1;
  padding: 10px;
  font-size: 12px;
  font-weight: 600;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn:hover { color: var(--text); }

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: none;
  flex-direction: column;
  gap: 12px;
}
.panel-content.active { display: flex; }
.panel-content::-webkit-scrollbar { width: 4px; }
.panel-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── State cards ─────────────────────────────────────────────────────────── */
.state-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.state-card-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: rgba(79,142,247,0.06);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}
.state-card-body { padding: 10px 12px; }

.state-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(46,51,71,0.5);
  font-size: 12px;
}
.state-row:last-child { border-bottom: none; }
.state-key { color: var(--text-dim); flex-shrink: 0; }
.state-val { color: var(--text); font-family: var(--mono); font-size: 11px; text-align: right; word-break: break-all; }
.state-val.null { color: var(--text-dim); font-style: italic; }
.state-val.ok  { color: var(--green); }
.state-val.warn { color: var(--yellow); }

/* JSON pre blocks */
.json-block {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
  color: var(--text-muted);
}

.json-key   { color: #7dd3fc; }
.json-str   { color: #86efac; }
.json-num   { color: #fbbf24; }
.json-bool  { color: #f472b6; }
.json-null  { color: var(--text-dim); }

/* Tool result badge */
.tool-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 8px;
}
.tool-badge.success { background: rgba(34,197,94,0.15); color: var(--green); border: 1px solid rgba(34,197,94,0.3); }
.tool-badge.failure { background: rgba(239,68,68,0.15); color: var(--red);   border: 1px solid rgba(239,68,68,0.3); }
.tool-badge.none    { background: var(--surface2); color: var(--text-dim); border: 1px solid var(--border); }

/* Confidence bar */
.confidence-bar {
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  margin-top: 4px;
  overflow: hidden;
}
.confidence-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.4s ease;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px;
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
}
.empty-icon { font-size: 28px; margin-bottom: 4px; }
