/* ============================================================
   Mux-Swarm Web UI — Styles
   Dark terminal-modern aesthetic with MuxConsole color parity
   ============================================================ */

:root {
  color-scheme: dark;

  /* Surfaces */
  --bg:          #0a0e1a;
  --bg-raised:   #0f1424;
  --surface:     #141a2e;
  --surface-2:   #1a2240;
  --surface-3:   #1e2848;
  --border:      rgba(100, 180, 220, 0.08);
  --border-focus: rgba(100, 180, 220, 0.25);

  /* MuxConsole color vocabulary */
  --step:     #64B4DC;
  --success:  #78C88C;
  --warning:  #D4A054;
  --error:    #D46C6C;
  --info:     #909090;
  --muted:    #585f78;
  --accent:   #64B4DC;
  --agent:    #8FB8D4;

  /* Text */
  --text:       #c8cedf;
  --text-bright: #e4e8f4;
  --text-dim:   #6b7394;

  /* User bubble */
  --user-bg: #1c3a6e;
  --user-border: rgba(100, 180, 220, 0.15);

  /* Fonts */
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', monospace;
  --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;

  /* Sizing */
  --max-width: 840px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---- App shell ---- */
.app-shell {
  max-width: var(--max-width);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
}

/* ---- Top bar ---- */
.topbar {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.logo-mark {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a3a5c, #0f2440);
  border: 1px solid rgba(100, 180, 220, 0.2);
  border-radius: 9px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.logo-x { color: #78C88C; }

.topbar-text { min-width: 0; }
.topbar-text h1 {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-bright);
  letter-spacing: -0.01em;
}
.topbar-sub {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border: 1px solid transparent;
}
.status-dot {
  width: 6px; height: 6px; border-radius: 50%;
}
.status-badge.idle          { background: var(--surface-2); color: var(--text-dim); }
.status-badge.idle .status-dot { background: var(--text-dim); }
.status-badge.connected     { background: rgba(120,200,140,0.1); color: var(--success); border-color: rgba(120,200,140,0.15); }
.status-badge.connected .status-dot { background: var(--success); animation: pulse-dot 2s infinite; }
.status-badge.error         { background: rgba(212,108,108,0.1); color: var(--error); border-color: rgba(212,108,108,0.15); }
.status-badge.error .status-dot { background: var(--error); }
.status-badge.stopped       { background: rgba(212,160,84,0.1); color: var(--warning); border-color: rgba(212,160,84,0.15); }
.status-badge.stopped .status-dot { background: var(--warning); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Icon buttons */
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: transparent; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-dim); cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-focus); }

/* Menu dropdown */
.menu-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border-focus);
  border-radius: var(--radius);
  padding: 4px;
  z-index: 100;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.menu-dropdown.hidden { display: none; }
.menu-dropdown button {
  display: block; width: 100%;
  padding: 8px 12px;
  background: none; border: none;
  color: var(--text);
  font-size: 13px; font-family: var(--font-sans);
  text-align: left; cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.12s;
}
.menu-dropdown button:hover { background: var(--surface-2); }

/* ---- Chat log ---- */
.chat-log {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: auto;
  overscroll-behavior: contain;
}

/* Scrollbar */
.chat-log::-webkit-scrollbar { width: 5px; }
.chat-log::-webkit-scrollbar-track { background: transparent; }
.chat-log::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }

/* ---- Chat events / messages ---- */
.chat-event {
  max-width: 100%;
  animation: event-in 0.2s ease-out both;
}

@keyframes event-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* -- User message -- */
.ev-user {
  align-self: flex-end;
  max-width: min(85%, 560px);
  padding: 10px 14px;
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  border-radius: var(--radius-lg) var(--radius-lg) 6px var(--radius-lg);
  color: var(--text-bright);
  font-size: 13.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* -- Agent turn header -- */
.ev-agent-turn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  margin-bottom: 4px;
  padding: 0 2px;
}
.ev-agent-turn .agent-icon {
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(143,184,212,0.1);
  border: 1px solid rgba(143,184,212,0.15);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--agent);
}
.ev-agent-turn .agent-name {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--agent);
}

/* -- Streamed text (assistant content) -- */
.ev-stream {
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.ev-stream.streaming::after {
  content: '';
  display: inline-block;
  width: 7px; height: 15px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursor-blink 0.8s step-end infinite;
}
@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Markdown inside stream */
.ev-stream.rendered { white-space: normal; }
.ev-stream.rendered p { margin: 0 0 0.6em; }
.ev-stream.rendered p:last-child { margin-bottom: 0; }
.ev-stream.rendered code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(100,180,220,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid rgba(100,180,220,0.1);
}
.ev-stream.rendered pre {
  background: #0c111f;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  font-size: 12px;
}
.ev-stream.rendered pre code {
  background: none; border: none; padding: 0;
}
.ev-stream.rendered ul, .ev-stream.rendered ol {
  padding-left: 1.4em;
  margin: 4px 0;
}
.ev-stream.rendered blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-dim);
}
.ev-stream.rendered h1, .ev-stream.rendered h2, .ev-stream.rendered h3,
.ev-stream.rendered h4, .ev-stream.rendered h5, .ev-stream.rendered h6 {
  color: var(--text-bright);
  margin: 12px 0 4px;
  font-family: var(--font-mono);
}
.ev-stream.rendered a { color: var(--accent); text-decoration: none; }
.ev-stream.rendered a:hover { text-decoration: underline; }
.ev-stream.rendered table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12px;
}
.ev-stream.rendered th, .ev-stream.rendered td {
  border: 1px solid var(--border);
  padding: 4px 8px;
}
.ev-stream.rendered th { background: var(--surface-2); color: var(--text-bright); }

/* -- Thinking indicator -- */
.ev-thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--font-mono);
}
.thinking-dots {
  display: flex; gap: 3px;
}
.thinking-dots span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: think-bounce 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes think-bounce {
  0%, 60%, 100% { opacity: 0.2; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}
.thinking-status { color: var(--text-dim); }

/* -- Event cards (delegation, tool call, tool result, task complete) -- */
.ev-card {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--font-mono);
  border-left: 3px solid var(--border);
  margin: 2px 0;
  background: rgba(255,255,255,0.015);
}

.ev-card .card-icon {
  flex-shrink: 0;
  font-size: 13px;
  line-height: 1.4;
  opacity: 0.8;
}

.ev-card .card-body {
  min-width: 0;
  flex: 1;
}

.ev-card .card-label {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 1px;
}

.ev-card .card-text {
  color: var(--text-dim);
  word-break: break-word;
  line-height: 1.5;
}

/* Card variants */
.ev-card.delegation { border-left-color: var(--accent); }
.ev-card.delegation .card-label { color: var(--accent); }

.ev-card.tool-call { border-left-color: #7c8ec8; }
.ev-card.tool-call .card-label { color: #7c8ec8; }

.ev-card.tool-result { border-left-color: var(--muted); }
.ev-card.tool-result .card-label { color: var(--info); }

.ev-card.task-complete { border-left-color: var(--success); background: rgba(120,200,140,0.03); }
.ev-card.task-complete .card-label { color: var(--success); }

/* -- Status messages (success, warning, error, info, debug) -- */
.ev-status {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 5px 14px;
  font-size: 12px;
  font-family: var(--font-mono);
}
.ev-status .status-icon { flex-shrink: 0; font-size: 12px; line-height: 1.6; }
.ev-status .status-text { word-break: break-word; line-height: 1.6; }

.ev-status.success .status-icon { color: var(--success); }
.ev-status.success .status-text { color: var(--success); }
.ev-status.warning .status-icon { color: var(--warning); }
.ev-status.warning .status-text { color: var(--warning); }
.ev-status.error .status-icon { color: var(--error); }
.ev-status.error .status-text { color: var(--error); }
.ev-status.info .status-text { color: var(--info); }
.ev-status.info .status-icon { color: var(--info); }
.ev-status.debug .status-text { color: var(--muted); }
.ev-status.debug .status-icon { color: var(--muted); }

/* -- Banner -- */
.ev-banner {
  text-align: center;
  padding: 14px 16px;
  margin: 8px 0;
  border: 1px solid rgba(100,180,220,0.12);
  border-radius: var(--radius);
  background: rgba(100,180,220,0.04);
}
.ev-banner .banner-title {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* -- Rule -- */
.ev-rule {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
  color: var(--muted);
  font-size: 11px;
  font-family: var(--font-mono);
}
.ev-rule::before, .ev-rule::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.ev-rule:empty::after { display: block; }

/* -- Step -- */
.ev-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  margin: 8px 0 2px;
  background: rgba(100,180,220,0.04);
  border: 1px solid rgba(100,180,220,0.08);
  border-radius: var(--radius-sm);
}
.ev-step .step-num {
  flex-shrink: 0;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(100,180,220,0.12);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--step);
}
.ev-step .step-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

/* -- Panel -- */
.ev-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 4px 0;
  overflow: hidden;
}
.ev-panel .panel-header {
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--step);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.ev-panel .panel-body {
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* -- Table -- */
.ev-table {
  margin: 6px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.ev-table .table-title {
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--step);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.ev-table table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
}
.ev-table td {
  padding: 5px 12px;
  border-bottom: 1px solid var(--border);
}
.ev-table tr:last-child td { border-bottom: none; }
.ev-table td:first-child { color: var(--info); width: 40%; }
.ev-table td:last-child { color: var(--text); }

/* -- Interactive prompts -- */
.ev-prompt {
  padding: 10px 14px;
  margin: 4px 0;
  border: 1px solid var(--border-focus);
  border-radius: var(--radius);
  background: var(--surface);
}
.ev-prompt .prompt-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 8px;
}
.ev-prompt input[type="text"],
.ev-prompt input[type="password"] {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-bright);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
.ev-prompt input:focus { border-color: var(--accent); }
.ev-prompt .prompt-default {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}
.ev-prompt .prompt-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ev-prompt .choice-btn {
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.12s;
}
.ev-prompt .choice-btn:hover {
  background: var(--surface-3);
  border-color: var(--accent);
  color: var(--text-bright);
}
.ev-prompt .choice-btn.selected {
  background: rgba(100,180,220,0.12);
  border-color: var(--accent);
  color: var(--accent);
}
.ev-prompt .confirm-row {
  display: flex; gap: 8px; margin-top: 4px;
}
.ev-prompt .confirm-btn {
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
}
.ev-prompt .confirm-btn.yes {
  background: rgba(120,200,140,0.15);
  color: var(--success);
  border-color: rgba(120,200,140,0.2);
}
.ev-prompt .confirm-btn.no {
  background: var(--surface-2);
  color: var(--text-dim);
  border-color: var(--border);
}
.ev-prompt .confirm-btn:hover { filter: brightness(1.15); }
.ev-prompt .submit-btn {
  margin-top: 8px;
  padding: 6px 16px;
  background: rgba(100,180,220,0.12);
  border: 1px solid rgba(100,180,220,0.2);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
}
.ev-prompt .submit-btn:hover { background: rgba(100,180,220,0.2); }
.ev-prompt.answered { opacity: 0.5; pointer-events: none; }

/* -- Raw / system -- */
.ev-raw {
  padding: 4px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.ev-system {
  padding: 5px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

/* ---- Composer ---- */
.composer {
  flex-shrink: 0;
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom, 0));
}

.composer-inner { max-width: var(--max-width); margin: 0 auto; }

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

.input-row textarea {
  flex: 1;
  min-height: 38px;
  max-height: 140px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-bright);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  resize: none;
  outline: none;
  overflow-y: auto;
  transition: border-color 0.15s;
}
.input-row textarea:focus { border-color: var(--border-focus); }
.input-row textarea::placeholder { color: var(--text-dim); }

.send-btn {
  flex-shrink: 0;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  transition: all 0.15s;
}
.send-btn:hover { filter: brightness(1.15); transform: scale(1.04); }
.send-btn:active { transform: scale(0.96); }

/* Hint pills */
.composer-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}
.hint-pill {
  padding: 3px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.12s;
  user-select: none;
}
.hint-pill:hover {
  background: var(--surface-2);
  border-color: var(--border-focus);
  color: var(--text);
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
  .topbar { padding: 8px 12px; }
  .topbar-text h1 { font-size: 14px; }
  .logo-mark { width: 30px; height: 30px; font-size: 12px; }
  .chat-log { padding: 12px 10px 20px; }
  .composer { padding: 8px 10px; }
  .ev-user { max-width: 90%; }
  .composer-hints { gap: 4px; }
  .hint-pill { font-size: 9px; padding: 2px 6px; }
}

@media (max-width: 380px) {
  .status-label { display: none; }
  .hint-pill { font-size: 9px; }
}

/* ---- Desktop: fullscreen ---- */
@media (min-width: 768px) {
  .app-shell {
    max-width: 100%;
  }

  body { font-size: 15px; }

  .topbar { padding: 12px 32px; }
  .topbar-text h1 { font-size: 16px; }
  .logo-mark { width: 38px; height: 38px; font-size: 15px; border-radius: 10px; }

  .chat-log { padding: 24px 48px 32px; gap: 3px; }
  .chat-log::-webkit-scrollbar { width: 6px; }

  .ev-user { max-width: min(65%, 700px); font-size: 14px; padding: 12px 16px; }
  .ev-stream { padding: 12px 48px 12px 16px; font-size: 13.5px; }
  .ev-stream.rendered pre { padding: 14px 16px; font-size: 13px; }
  .ev-card { padding: 8px 14px; font-size: 12.5px; }
  .ev-agent-turn { padding: 0 2px; }

  .composer { padding: 12px 32px; }
  .composer-inner { max-width: 100%; }
  .input-row textarea { min-height: 42px; font-size: 14px; padding: 10px 14px; }
  .send-btn { width: 42px; height: 42px; }
  .hint-pill { font-size: 11px; padding: 4px 10px; }
}

@media (min-width: 1200px) {
  .topbar { padding: 14px 48px; }
  .topbar-text h1 { font-size: 17px; }
  .topbar-sub { font-size: 12px; }
  .logo-mark { width: 40px; height: 40px; font-size: 16px; }
  .status-badge { padding: 5px 12px; font-size: 11.5px; }

  .chat-log { padding: 28px 64px 40px; gap: 4px; }

  .ev-user { max-width: min(55%, 780px); font-size: 14.5px; padding: 12px 18px; }
  .ev-agent-turn { margin-top: 20px; }
  .ev-agent-turn .agent-icon { width: 26px; height: 26px; font-size: 11px; }
  .ev-agent-turn .agent-name { font-size: 13px; }

  .ev-stream { padding: 12px 64px 12px 18px; font-size: 14px; line-height: 1.7; }
  .ev-stream.rendered pre { font-size: 13.5px; }
  .ev-stream.rendered code { font-size: 13px; }

  .ev-card { padding: 9px 16px; font-size: 13px; margin: 3px 0; }
  .ev-card .card-label { font-size: 11.5px; }

  .ev-step { padding: 10px 16px; }
  .ev-step .step-num { width: 28px; height: 28px; font-size: 13px; }
  .ev-step .step-title { font-size: 14px; }

  .ev-panel .panel-header { padding: 8px 16px; font-size: 13px; }
  .ev-panel .panel-body { padding: 12px 16px; font-size: 13px; }

  .ev-status { padding: 6px 18px; font-size: 13px; }
  .ev-banner { padding: 16px 20px; }
  .ev-banner .banner-title { font-size: 15px; }

  .composer { padding: 14px 48px; }
  .input-row textarea {
    min-height: 46px;
    max-height: 200px;
    font-size: 14.5px;
    padding: 12px 16px;
    border-radius: var(--radius);
  }
  .send-btn { width: 46px; height: 46px; border-radius: var(--radius); }
  .composer-hints { gap: 6px; margin-top: 10px; }
  .hint-pill { font-size: 11px; padding: 5px 12px; border-radius: 8px; }
}

@media (min-width: 1600px) {
  .topbar { padding: 14px 80px; }
  .chat-log { padding: 32px 96px 48px; }
  .ev-stream { padding: 12px 96px 12px 18px; font-size: 14.5px; }
  .ev-stream.rendered pre { font-size: 14px; padding: 16px 20px; }
  .composer { padding: 14px 80px; }
  .input-row textarea { font-size: 15px; }
}

/* ============================================================
   Theme System
   ============================================================ */

/* -- Theme picker in menu -- */
.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.menu-section-label {
  padding: 6px 12px 2px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px 8px 6px;
}

.theme-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.theme-swatch:hover { transform: scale(1.1); }
.theme-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.theme-swatch[data-theme="default"]   { background: linear-gradient(135deg, #0a0e1a, #1a2240); }
.theme-swatch[data-theme="midnight"]  { background: linear-gradient(135deg, #0d1117, #161b22); }
.theme-swatch[data-theme="ocean"]     { background: linear-gradient(135deg, #0a192f, #112240); }
.theme-swatch[data-theme="ember"]     { background: linear-gradient(135deg, #1a0a0a, #2d1515); }
.theme-swatch[data-theme="forest"]    { background: linear-gradient(135deg, #0a1a0f, #132e1b); }
.theme-swatch[data-theme="purple"]    { background: linear-gradient(135deg, #120e1f, #1e1536); }
.theme-swatch[data-theme="mono"]      { background: linear-gradient(135deg, #111111, #1a1a1a); }
.theme-swatch[data-theme="light"]     { background: linear-gradient(135deg, #f0f2f5, #ffffff); border-color: var(--border); }
.theme-swatch[data-theme="claude"]    { background: linear-gradient(135deg, #2b2018, #3d2e1f); }
.theme-swatch[data-theme="devin"]     { background: linear-gradient(135deg, #0a0a14, #12122a); }
.theme-swatch[data-theme="chatgpt"]   { background: linear-gradient(135deg, #1a1a2e, #212121); }
.theme-swatch[data-theme="copilot"]   { background: linear-gradient(135deg, #0e1116, #1a1f28); }
.theme-swatch[data-theme="cursor"]    { background: linear-gradient(135deg, #0a0a0a, #181818); }
.theme-swatch[data-theme="custom"]    {
  background: conic-gradient(from 0deg, #ff6b6b, #ffd93d, #6bcb77, #4d96ff, #9b59b6, #ff6b6b);
  opacity: 0.8;
}
.theme-swatch[data-theme="custom"]:hover { opacity: 1; }

/* -- Theme: Midnight (GitHub Dark) -- */
[data-theme="midnight"] {
  --bg: #0d1117;
  --bg-raised: #161b22;
  --surface: #1c2128;
  --surface-2: #242b35;
  --surface-3: #2d333b;
  --border: rgba(110, 118, 129, 0.12);
  --border-focus: rgba(110, 118, 129, 0.3);
  --step: #58a6ff;
  --success: #3fb950;
  --warning: #d29922;
  --error: #f85149;
  --info: #8b949e;
  --muted: #484f58;
  --accent: #58a6ff;
  --agent: #79c0ff;
  --text: #c9d1d9;
  --text-bright: #f0f6fc;
  --text-dim: #6e7681;
  --user-bg: #1a3050;
  --user-border: rgba(88, 166, 255, 0.15);
}

/* -- Theme: Ocean -- */
[data-theme="ocean"] {
  --bg: #0a192f;
  --bg-raised: #0f2035;
  --surface: #112240;
  --surface-2: #1a3050;
  --surface-3: #233d5e;
  --border: rgba(100, 200, 255, 0.08);
  --border-focus: rgba(100, 200, 255, 0.25);
  --step: #64ffda;
  --success: #64ffda;
  --warning: #f0c040;
  --error: #ff6b6b;
  --info: #8892b0;
  --muted: #495670;
  --accent: #64ffda;
  --agent: #88d4f0;
  --text: #a8b2d1;
  --text-bright: #ccd6f6;
  --text-dim: #607090;
  --user-bg: #1a3a5c;
  --user-border: rgba(100, 255, 218, 0.12);
}

/* -- Theme: Ember -- */
[data-theme="ember"] {
  --bg: #1a0a0a;
  --bg-raised: #1f1010;
  --surface: #2d1515;
  --surface-2: #3a1e1e;
  --surface-3: #482828;
  --border: rgba(220, 120, 80, 0.1);
  --border-focus: rgba(220, 120, 80, 0.25);
  --step: #ff8a65;
  --success: #81c784;
  --warning: #ffb74d;
  --error: #ef5350;
  --info: #a09090;
  --muted: #685050;
  --accent: #ff8a65;
  --agent: #ffab91;
  --text: #d4c0b8;
  --text-bright: #f0e4de;
  --text-dim: #806060;
  --user-bg: #3a2020;
  --user-border: rgba(255, 138, 101, 0.15);
}

/* -- Theme: Forest -- */
[data-theme="forest"] {
  --bg: #0a1a0f;
  --bg-raised: #0f2015;
  --surface: #132e1b;
  --surface-2: #1a3d24;
  --surface-3: #224a2e;
  --border: rgba(80, 200, 120, 0.08);
  --border-focus: rgba(80, 200, 120, 0.25);
  --step: #66bb6a;
  --success: #81c784;
  --warning: #dce775;
  --error: #ef5350;
  --info: #90a090;
  --muted: #506050;
  --accent: #66bb6a;
  --agent: #a5d6a7;
  --text: #c0d4c0;
  --text-bright: #e0f0e0;
  --text-dim: #608060;
  --user-bg: #1a3a20;
  --user-border: rgba(102, 187, 106, 0.15);
}

/* -- Theme: Purple -- */
[data-theme="purple"] {
  --bg: #120e1f;
  --bg-raised: #181430;
  --surface: #1e1536;
  --surface-2: #2a2048;
  --surface-3: #352a5a;
  --border: rgba(160, 120, 255, 0.08);
  --border-focus: rgba(160, 120, 255, 0.25);
  --step: #b388ff;
  --success: #80cbc4;
  --warning: #ffe082;
  --error: #f48fb1;
  --info: #9090a8;
  --muted: #585068;
  --accent: #b388ff;
  --agent: #ce93d8;
  --text: #c8c0df;
  --text-bright: #e8e0f8;
  --text-dim: #706894;
  --user-bg: #2a1a50;
  --user-border: rgba(179, 136, 255, 0.15);
}

/* -- Theme: Mono -- */
[data-theme="mono"] {
  --bg: #111111;
  --bg-raised: #1a1a1a;
  --surface: #222222;
  --surface-2: #2a2a2a;
  --surface-3: #333333;
  --border: rgba(255, 255, 255, 0.06);
  --border-focus: rgba(255, 255, 255, 0.15);
  --step: #a0a0a0;
  --success: #90c090;
  --warning: #c0a060;
  --error: #c06060;
  --info: #808080;
  --muted: #555555;
  --accent: #b0b0b0;
  --agent: #c0c0c0;
  --text: #b0b0b0;
  --text-bright: #e0e0e0;
  --text-dim: #606060;
  --user-bg: #2a2a2a;
  --user-border: rgba(255, 255, 255, 0.08);
}

/* -- Theme: Light -- */
[data-theme="light"] {
  --bg: #f5f6f8;
  --bg-raised: #ffffff;
  --surface: #ebedf0;
  --surface-2: #e0e3e8;
  --surface-3: #d4d8de;
  --border: rgba(0, 0, 0, 0.08);
  --border-focus: rgba(0, 0, 0, 0.2);
  --step: #2563eb;
  --success: #16a34a;
  --warning: #ca8a04;
  --error: #dc2626;
  --info: #6b7280;
  --muted: #9ca3af;
  --accent: #2563eb;
  --agent: #3b82f6;
  --text: #374151;
  --text-bright: #111827;
  --text-dim: #9ca3af;
  --user-bg: #dbeafe;
  --user-border: rgba(37, 99, 235, 0.15);
}
[data-theme="light"] .logo-mark {
  background: linear-gradient(135deg, #dbeafe, #bfdbfe);
  border-color: rgba(37, 99, 235, 0.2);
}
[data-theme="light"] .logo-x { color: var(--success); }
[data-theme="light"] .ev-stream.rendered pre {
  background: #f0f2f5;
}

/* -- Theme: Claude -- */
[data-theme="claude"] {
  --bg: #2b2018;
  --bg-raised: #352820;
  --surface: #3d2e1f;
  --surface-2: #4a3828;
  --surface-3: #564232;
  --border: rgba(217, 169, 124, 0.1);
  --border-focus: rgba(217, 169, 124, 0.25);
  --step: #d9a97c;
  --success: #8fbc8f;
  --warning: #daa520;
  --error: #cd5c5c;
  --info: #a0907c;
  --muted: #6b5c4e;
  --accent: #d9a97c;
  --agent: #e8c49e;
  --text: #d4c8b8;
  --text-bright: #f0e8dc;
  --text-dim: #8a7a68;
  --user-bg: #4a3520;
  --user-border: rgba(217, 169, 124, 0.15);
}
[data-theme="claude"] .logo-mark {
  background: linear-gradient(135deg, #4a3828, #352820);
  border-color: rgba(217, 169, 124, 0.2);
}
[data-theme="claude"] .logo-x { color: #8fbc8f; }

/* -- Theme: Devin -- */
[data-theme="devin"] {
  --bg: #0a0a14;
  --bg-raised: #10101e;
  --surface: #161628;
  --surface-2: #1e1e35;
  --surface-3: #262642;
  --border: rgba(100, 100, 255, 0.08);
  --border-focus: rgba(100, 100, 255, 0.2);
  --step: #7c7cff;
  --success: #50d890;
  --warning: #f0c050;
  --error: #ff5c5c;
  --info: #8080a0;
  --muted: #4a4a6a;
  --accent: #7c7cff;
  --agent: #a0a0ff;
  --text: #c0c0e0;
  --text-bright: #e0e0ff;
  --text-dim: #606080;
  --user-bg: #1a1a40;
  --user-border: rgba(124, 124, 255, 0.15);
}
[data-theme="devin"] .logo-mark {
  background: linear-gradient(135deg, #1e1e35, #10101e);
  border-color: rgba(124, 124, 255, 0.2);
}
[data-theme="devin"] .logo-x { color: #50d890; }

/* -- Theme: ChatGPT -- */
[data-theme="chatgpt"] {
  --bg: #1a1a2e;
  --bg-raised: #212121;
  --surface: #2a2a3e;
  --surface-2: #333348;
  --surface-3: #3c3c52;
  --border: rgba(180, 180, 200, 0.08);
  --border-focus: rgba(180, 180, 200, 0.2);
  --step: #10a37f;
  --success: #10a37f;
  --warning: #f5a623;
  --error: #ef4444;
  --info: #8e8ea0;
  --muted: #565670;
  --accent: #10a37f;
  --agent: #19c99a;
  --text: #c5c5d2;
  --text-bright: #ececf1;
  --text-dim: #6e6e80;
  --user-bg: #2a3a3a;
  --user-border: rgba(16, 163, 127, 0.15);
}
[data-theme="chatgpt"] .logo-mark {
  background: linear-gradient(135deg, #1a3a32, #0f2820);
  border-color: rgba(16, 163, 127, 0.25);
}
[data-theme="chatgpt"] .logo-x { color: #10a37f; }

/* -- Theme: Copilot -- */
[data-theme="copilot"] {
  --bg: #0e1116;
  --bg-raised: #151b23;
  --surface: #1a222c;
  --surface-2: #222c38;
  --surface-3: #2a3644;
  --border: rgba(130, 180, 240, 0.08);
  --border-focus: rgba(130, 180, 240, 0.2);
  --step: #79b8ff;
  --success: #56d364;
  --warning: #e3b341;
  --error: #f85149;
  --info: #8b949e;
  --muted: #484f58;
  --accent: #79b8ff;
  --agent: #a5d6ff;
  --text: #c9d1d9;
  --text-bright: #f0f6fc;
  --text-dim: #606872;
  --user-bg: #1a2a44;
  --user-border: rgba(121, 184, 255, 0.12);
}
[data-theme="copilot"] .logo-mark {
  background: linear-gradient(135deg, #1a2a44, #151b23);
  border-color: rgba(121, 184, 255, 0.2);
}
[data-theme="copilot"] .logo-x { color: #56d364; }

/* -- Theme: Cursor -- */
[data-theme="cursor"] {
  --bg: #0a0a0a;
  --bg-raised: #141414;
  --surface: #1a1a1a;
  --surface-2: #242424;
  --surface-3: #2e2e2e;
  --border: rgba(255, 255, 255, 0.06);
  --border-focus: rgba(255, 255, 255, 0.12);
  --step: #22d3ee;
  --success: #4ade80;
  --warning: #fbbf24;
  --error: #f87171;
  --info: #71717a;
  --muted: #3f3f46;
  --accent: #22d3ee;
  --agent: #67e8f9;
  --text: #a1a1aa;
  --text-bright: #e4e4e7;
  --text-dim: #52525b;
  --user-bg: #0f2a30;
  --user-border: rgba(34, 211, 238, 0.12);
}
[data-theme="cursor"] .logo-mark {
  background: linear-gradient(135deg, #0f2a30, #0a0a0a);
  border-color: rgba(34, 211, 238, 0.2);
}
[data-theme="cursor"] .logo-x { color: #4ade80; }

/* ============================================================
   Custom Theme Editor
   ============================================================ */
.theme-editor-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 0.15s ease-out;
}
.theme-editor-overlay.hidden { display: none; }

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.theme-editor {
  width: 360px;
  max-width: 95vw;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg-raised);
  border: 1px solid var(--border-focus);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  animation: editor-in 0.2s ease-out;
}
@keyframes editor-in {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.theme-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.theme-editor-header h3 {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
}
.theme-editor-close {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-dim);
  cursor: pointer; font-size: 16px;
  transition: all 0.12s;
}
.theme-editor-close:hover { background: var(--surface-2); color: var(--text); }

.theme-editor-body {
  padding: 12px 16px 16px;
}

.te-section {
  margin-bottom: 14px;
}
.te-section-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.te-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.te-row label {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
}
.te-row input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 32px; height: 24px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: none;
  cursor: pointer;
  padding: 0;
}
.te-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 1px; }
.te-row input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 3px;
}
.te-row .te-hex {
  width: 72px;
  padding: 4px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  text-align: center;
  outline: none;
}
.te-row .te-hex:focus { border-color: var(--accent); }

.te-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.te-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
  text-align: center;
}
.te-btn.primary {
  background: rgba(100, 180, 220, 0.15);
  color: var(--accent);
  border-color: rgba(100, 180, 220, 0.2);
}
.te-btn.primary:hover { background: rgba(100, 180, 220, 0.25); }
.te-btn.secondary {
  background: var(--surface-2);
  color: var(--text-dim);
  border-color: var(--border);
}
.te-btn.secondary:hover { background: var(--surface-3); color: var(--text); }
.te-btn.danger {
  background: rgba(212, 108, 108, 0.1);
  color: var(--error);
  border-color: rgba(212, 108, 108, 0.15);
}
.te-btn.danger:hover { background: rgba(212, 108, 108, 0.2); }

/* ---- Login overlay ---- */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 340px;
  padding: 40px 32px 32px;
  text-align: center;
}

.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-bright);
  margin-bottom: 16px;
}

.login-logo-x {
  color: var(--accent);
}

.login-title {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 4px;
}

.login-sub {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 28px;
}

.login-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.login-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-bright);
  font-family: var(--font-mono);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.login-input:focus {
  border-color: var(--border-focus);
}

.login-input::placeholder {
  color: var(--text-dim);
}

.login-btn {
  width: 100%;
  padding: 10px 0;
  background: var(--accent);
  color: var(--bg);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.15s;
}

.login-btn:hover {
  opacity: 0.9;
}

.login-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.login-error {
  margin-top: 12px;
  font-size: 13px;
  color: var(--error);
}

/* ---- Menu user info ---- */
.menu-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  font-family: var(--font-mono);
}

.menu-user-icon {
  color: var(--success);
  font-size: 8px;
}

/* ---- Utility ---- */
.hidden { display: none !important; }
