:root {
  --bg: #080c18;
  --bg2: #0f1729;
  --bg3: #151e35;
  --panel: rgba(15, 23, 42, 0.84);
  --card: rgba(255,255,255,0.04);
  --card-hover: rgba(255,255,255,0.07);
  --border: rgba(255,255,255,0.08);
  --border2: rgba(255,255,255,0.14);
  --text: #e2e8f0;
  --text2: #94a3b8;
  --text3: #64748b;
  --muted: #475569;
  --accent: #06b6d4;
  --accent2: #0ea5e9;
  --good: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --code: #8b5cf6;
  --web: #3b82f6;
  --multi: #ec4899;
  --user-bg: #1d4ed8;
  --shadow: 0 12px 38px rgba(0,0,0,0.42);
  --header-h: 64px;
  --input-h: 84px;
  --sidebar-w: 286px;
  --font: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background:
    radial-gradient(circle at top left, rgba(14, 165, 233, 0.14), transparent 32rem),
    linear-gradient(180deg, #080c18 0%, #0b1020 48%, #080c18 100%);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
button, textarea, input { font-family: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 4px; }

.header {
  height: var(--header-h);
  min-height: var(--header-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: rgba(8,12,24,0.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
  z-index: 20;
}
.header-left, .header-right { display: flex; align-items: center; gap: 12px; }
.header-right { justify-content: flex-end; }
.logo-wrap {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, #1d4ed8, #06b6d4);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
  box-shadow: 0 8px 26px rgba(6,182,212,0.22);
}
.app-title { font-size: 1.04rem; font-weight: 800; color: var(--text); letter-spacing: 0; }
.app-sub { display: block; margin-top: 1px; font-size: 0.69rem; color: var(--muted); font-weight: 600; letter-spacing: 0; }
.header-center {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}
.mode-tab {
  border: 0;
  background: transparent;
  color: var(--text2);
  border-radius: 7px;
  padding: 7px 13px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}
.mode-tab.active { background: linear-gradient(135deg, #1d4ed8, #06b6d4); color: white; }
.icon-btn, .btn-reset, .mini-btn, .wide-btn, .btn-primary {
  border: 1px solid var(--border2);
  background: var(--card);
  color: var(--text2);
  cursor: pointer;
  transition: transform 0.18s, background 0.18s, border-color 0.18s, color 0.18s;
}
.icon-btn { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; }
.btn-reset { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 700; padding: 8px 13px; border-radius: 8px; }
.icon-btn:hover, .btn-reset:hover, .mini-btn:hover, .wide-btn:hover { background: var(--card-hover); color: var(--text); border-color: rgba(6,182,212,0.42); }
.status-badge { font-size: 0.72rem; font-weight: 800; padding: 5px 10px; border-radius: 999px; border: 1px solid; white-space: nowrap; }
.status-badge.ok { color: #86efac; background: rgba(16,185,129,0.13); border-color: rgba(16,185,129,0.32); }
.status-badge.error { color: #fca5a5; background: rgba(239,68,68,0.13); border-color: rgba(239,68,68,0.32); }
.status-badge.muted { color: var(--text2); background: var(--card); border-color: var(--border2); }

.layout { flex: 1; display: flex; overflow: hidden; height: calc(100vh - var(--header-h) - var(--input-h)); }
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: rgba(15,23,41,0.92);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sidebar-section { display: flex; flex-direction: column; gap: 8px; }
.sidebar-heading { font-size: 0.68rem; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); padding: 0 4px 3px; }
.prompt-chip {
  width: 100%; text-align: left;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: all 0.2s;
}
.prompt-chip:hover { background: var(--card-hover); border-color: var(--border2); transform: translateX(2px); }
.chip-header { display: flex; align-items: center; gap: 7px; }
.chip-emoji { font-size: 1rem; width: 18px; }
.chip-tool { font-size: 0.62rem; font-weight: 800; letter-spacing: 0.8px; text-transform: uppercase; }
.chip-text { font-size: 0.76rem; color: var(--text2); line-height: 1.42; }
.file { color: var(--good); }
.code { color: var(--code); }
.web { color: var(--web); }
.fn { color: var(--warn); }
.multi { color: var(--multi); }
.runtime-card { border-top: 1px solid var(--border); padding-top: 13px; }
.runtime-row { display: flex; align-items: center; justify-content: space-between; font-size: 0.76rem; color: var(--text2); padding: 7px 4px; }
.runtime-row strong { color: var(--text); font-size: 0.75rem; }

.workspace { flex: 1; overflow: hidden; min-width: 0; }
.chat-panel, .debug-panel { height: 100%; overflow: hidden; }
.messages { height: 100%; overflow-y: auto; padding: 24px 20px 18px; display: flex; flex-direction: column; gap: 18px; }
.welcome { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 40px 20px; text-align: center; }
.welcome-globe { font-size: 3.4rem; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
.welcome-title { font-size: 1.65rem; font-weight: 800; }
.welcome-sub { font-size: 0.9rem; color: var(--text2); line-height: 1.6; max-width: 520px; }
.tool-pills { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 4px; }
.tool-pill { font-size: 0.74rem; font-weight: 800; padding: 6px 12px; border-radius: 999px; border: 1px solid currentColor; background: rgba(255,255,255,0.03); }
.error-banner { margin-top: 8px; padding: 10px 16px; background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.3); border-radius: 8px; color: #fca5a5; font-size: 0.8rem; max-width: 620px; }

.message { display: flex; animation: fadeUp 0.25s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.user-message { justify-content: flex-end; }
.user-bubble { display: flex; align-items: flex-start; gap: 10px; flex-direction: row-reverse; max-width: 72%; }
.user-content { background: var(--user-bg); border-radius: 16px 4px 16px 16px; padding: 11px 15px; font-size: 0.88rem; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.agent-message { justify-content: flex-start; }
.agent-bubble { display: flex; align-items: flex-start; gap: 10px; max-width: 84%; }
.agent-card { background: var(--panel); border: 1px solid var(--border); border-radius: 4px 16px 16px 16px; padding: 14px 16px; flex: 1; backdrop-filter: blur(9px); box-shadow: 0 8px 24px rgba(0,0,0,0.18); }
.avatar { width: 32px; height: 32px; min-width: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.9rem; }
.avatar-user { background: linear-gradient(135deg, #1d4ed8, #3b82f6); }
.avatar-agent { background: linear-gradient(135deg, #0f172a, #1e293b); border: 1px solid var(--border2); }
.tool-badges { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.tool-badge { font-size: 0.65rem; font-weight: 800; letter-spacing: 0.4px; padding: 2px 9px; border-radius: 999px; border: 1px solid; display: inline-flex; align-items: center; gap: 4px; }
.status-area { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.status-text { font-size: 0.78rem; color: var(--text2); font-style: italic; }
.error-text { color: #f87171 !important; }
.typing-dots { display: flex; gap: 4px; align-items: center; }
.typing-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s ease-in-out infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-6px); opacity: 1; } }
.agent-content { font-size: 0.875rem; line-height: 1.65; color: var(--text); word-break: break-word; }
.agent-content p { margin: 0 0 8px; }
.agent-content p:last-child { margin-bottom: 0; }
.agent-content strong { color: #f8fafc; font-weight: 700; }
.agent-content em { color: var(--text2); }
.agent-content h3, .agent-content h4, .agent-content h5 { color: var(--text); margin: 12px 0 4px; font-weight: 700; }
.agent-content h3 { font-size: 1rem; }
.agent-content h4 { font-size: 0.93rem; }
.agent-content h5 { font-size: 0.87rem; }
.agent-content code { font-family: Consolas, monospace; background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 4px; font-size: 0.82em; }
.agent-content hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.agent-content ul { padding-left: 20px; margin: 4px 0 8px; }
.agent-content li { margin-bottom: 3px; }
.message-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.chart-wrapper { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.chart-img { max-width: 100%; border-radius: 10px; border: 1px solid var(--border2); transition: opacity 0.4s; }
.download-btn { font-size: 0.72rem; color: var(--accent); text-decoration: none; font-weight: 800; }

.debug-panel { overflow-y: auto; padding: 20px; }
.debug-lock { height: 100%; display: grid; place-items: center; }
.lock-card { width: min(520px, 92vw); background: rgba(15,23,42,0.9); border: 1px solid var(--border2); border-radius: 12px; padding: 26px; box-shadow: var(--shadow); text-align: center; }
.lock-icon { width: 44px; height: 44px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: 12px; background: linear-gradient(135deg, #1d4ed8, #06b6d4); font-size: 1.4rem; }
.lock-card h2 { font-size: 1.25rem; margin-bottom: 7px; }
.lock-card p { color: var(--text2); font-size: 0.86rem; line-height: 1.55; }
.password-row { display: flex; gap: 10px; margin-top: 18px; }
.password-row input, .number-input { width: 100%; background: var(--bg3); border: 1px solid var(--border2); border-radius: 9px; padding: 10px 12px; color: var(--text); outline: none; }
.password-row input:focus, .number-input:focus { border-color: var(--accent); }
.btn-primary { background: linear-gradient(135deg, #1d4ed8, #06b6d4); border: 0; border-radius: 9px; padding: 0 16px; color: white; font-weight: 800; }
.lock-error { color: #fca5a5 !important; min-height: 21px; margin-top: 10px; }
.debug-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; max-width: 1200px; margin: 0 auto; }
.debug-card { background: rgba(15,23,42,0.86); border: 1px solid var(--border); border-radius: 10px; padding: 16px; min-width: 0; }
.debug-card.span-2 { grid-column: span 2; }
.debug-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.eyebrow { font-size: 0.66rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; }
.debug-card h3 { font-size: 0.98rem; font-weight: 800; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.metric { background: var(--card); border: 1px solid var(--border); border-radius: 9px; padding: 12px; }
.metric span { display: block; color: var(--text3); font-size: 0.72rem; margin-bottom: 7px; }
.metric strong { font-size: 1rem; }
.toggle-row { display: flex; align-items: center; gap: 8px; color: var(--text2); font-size: 0.82rem; margin: 12px 0; }
.field-label { display: block; font-size: 0.68rem; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: 0.8px; margin: 10px 0 5px; }
.mini-btn { border-radius: 7px; padding: 6px 10px; font-size: 0.72rem; font-weight: 800; }
.wide-btn { width: 100%; margin-top: 12px; border-radius: 9px; padding: 10px; font-size: 0.78rem; font-weight: 800; }
.wide-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.phase-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.phase-pill { font-size: 0.72rem; font-weight: 800; padding: 6px 9px; border-radius: 999px; border: 1px solid; }
.phase-pill.ready { color: #86efac; background: rgba(16,185,129,0.1); border-color: rgba(16,185,129,0.25); }
.phase-pill.next { color: #67e8f9; background: rgba(6,182,212,0.1); border-color: rgba(6,182,212,0.25); }
.phase-pill.future { color: #c4b5fd; background: rgba(139,92,246,0.1); border-color: rgba(139,92,246,0.25); }
.json-box { max-height: 290px; overflow: auto; background: rgba(2,6,23,0.52); border: 1px solid var(--border); border-radius: 9px; padding: 12px; color: #cbd5e1; font-size: 0.78rem; line-height: 1.55; }
.muted-small { color: var(--muted); font-size: 0.72rem; font-weight: 700; }
.trace-log { max-height: 310px; overflow: auto; display: flex; flex-direction: column; gap: 7px; }
.trace-row { display: grid; grid-template-columns: 82px 128px 1fr; gap: 10px; align-items: start; background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 0.75rem; }
.trace-row span { color: var(--muted); }
.trace-row strong { color: var(--accent); }
.trace-row p { color: var(--text2); line-height: 1.4; overflow-wrap: anywhere; }
.trace-empty { color: var(--muted); font-size: 0.8rem; padding: 12px; }

.input-bar { height: var(--input-h); padding: 10px 20px 6px; background: rgba(8,12,24,0.95); border-top: 1px solid var(--border); backdrop-filter: blur(14px); }
.input-wrap { display: flex; align-items: flex-end; gap: 10px; background: var(--bg3); border: 1px solid var(--border2); border-radius: 12px; padding: 8px 10px 8px 16px; transition: border-color 0.2s; }
.input-wrap:focus-within { border-color: var(--accent); }
.chat-input { flex: 1; background: transparent; border: 0; outline: 0; color: var(--text); font-size: 0.88rem; line-height: 1.5; resize: none; max-height: 140px; }
.chat-input::placeholder { color: var(--muted); }
.btn-send { width: 36px; height: 36px; min-width: 36px; background: linear-gradient(135deg, #1d4ed8, #06b6d4); border: 0; border-radius: 9px; cursor: pointer; display: grid; place-items: center; color: #fff; transition: all 0.2s; }
.btn-send:hover:not(:disabled) { transform: scale(1.06); filter: brightness(1.1); }
.btn-send:disabled { opacity: 0.45; cursor: not-allowed; }
.input-hint { font-size: 0.65rem; color: var(--muted); padding: 3px 4px 0; text-align: right; }
.input-hint kbd { background: var(--card); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 0.65rem; font-family: var(--font); }
.input-hint span { color: var(--text3); margin: 0 6px; }

@media (max-width: 920px) {
  .header { grid-template-columns: 1fr auto; }
  .header-center { order: 3; grid-column: 1 / -1; justify-self: center; margin-bottom: -52px; transform: translateY(52px); }
  .layout { height: calc(100vh - var(--header-h) - var(--input-h)); }
  .sidebar { display: none; }
  .messages { padding-top: 56px; }
  .debug-panel { padding-top: 58px; }
  .debug-grid, .metric-grid { grid-template-columns: 1fr; }
  .debug-card.span-2 { grid-column: span 1; }
}

@media (max-width: 640px) {
  .header { padding: 0 12px; gap: 8px; }
  .app-sub { display: none; }
  .status-badge { display: none; }
  .btn-reset { font-size: 0; padding: 8px; }
  .user-bubble, .agent-bubble { max-width: 96%; }
  .messages { padding-left: 12px; padding-right: 12px; }
  .password-row { flex-direction: column; }
  .btn-primary { padding: 11px 16px; }
  .trace-row { grid-template-columns: 1fr; gap: 4px; }
}
