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

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2128;
  --border: #30363d;
  --border-light: #21262d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent-blue: #58a6ff;
  --accent-green: #3fb950;
  --accent-purple: #bc8cff;
  --accent-orange: #d29922;
  --accent-red: #f85149;
  --font-mono: "Berkeley Mono", "SF Mono", "Cascadia Code", "Menlo", monospace;
}

body {
  font-family: var(--font-mono);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Setup overlay ────────────────────────────────────────── */

#setup-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#setup-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 460px;
  text-align: center;
}

#setup-banner {
  font-size: 14px;
  color: var(--accent-green);
  margin-bottom: 8px;
  line-height: 1.3;
  text-align: left;
  display: inline-block;
}

#setup-card .subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.key-section {
  text-align: left;
  margin-bottom: 16px;
}

.key-row {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.key-row label {
  width: 80px;
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
  text-align: right;
}

.key-row input {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
}

.key-row input:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.key-hint {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: center;
}

#boot-btn {
  width: 100%;
  background: var(--accent-green);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity 0.2s;
}

#boot-btn:hover { opacity: 0.9; }
#boot-btn:disabled { background: var(--text-muted); cursor: not-allowed; }

#boot-status {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-secondary);
  min-height: 20px;
}

/* ── Workspace layout ─────────────────────────────────────── */

#workspace {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#split {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ── Main agent pane (left 70%) ───────────────────────────── */

#main-pane {
  flex: 7;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.main-agent-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  font-size: 11px;
}

#main-stream {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  font-size: 13px;
  line-height: 1.6;
}

#input-row {
  display: flex;
  align-items: center;
  padding: 10px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  gap: 8px;
}

.prompt-sigil {
  color: var(--accent-blue);
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
  transition: color 0.2s;
}

.prompt-sigil.running {
  color: var(--accent-orange);
}

#prompt {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
}

#prompt::placeholder {
  color: var(--text-muted);
}

#prompt:disabled {
  opacity: 0.5;
}

/* ── Sub-agent pane (right 30%) ───────────────────────────── */

#sub-pane {
  flex: 3;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.member-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  min-height: 0;
}

.member-panel:last-child {
  border-bottom: none;
}

.member-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  font-size: 11px;
}

.agent-name {
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 10px;
}

#panel-planner .agent-name { color: var(--accent-blue); }
#panel-coder .agent-name { color: var(--accent-green); }
#panel-reviewer .agent-name { color: var(--accent-purple); }

#panel-planner { background: #0d1520; }
#panel-planner .member-panel-header { background: #111d2d; }
#panel-coder { background: #0d1710; }
#panel-coder .member-panel-header { background: #112211; }
#panel-reviewer { background: #150d17; }
#panel-reviewer .member-panel-header { background: #1f1122; }

.agent-model {
  color: var(--text-muted);
  font-size: 10px;
}

.agent-status {
  font-size: 10px;
  margin-left: auto;
  color: var(--text-muted);
  transition: color 0.2s;
}

.agent-status.thinking { color: var(--accent-orange); }
.agent-status.tool-use { color: var(--accent-green); }
.agent-status.error { color: var(--accent-red); }

.member-panel-stream {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  font-size: 11px;
  line-height: 1.5;
}

/* ── Stream rendering (shared main + sub) ─────────────────── */

.stream-entry {
  margin-bottom: 8px;
}

.stream-user {
  color: var(--accent-blue);
  font-weight: 600;
}

.stream-user::before {
  content: "\276F ";
}

.stream-text {
  color: var(--text-primary);
}

.stream-text p { margin-bottom: 6px; }
.stream-text p:last-child { margin-bottom: 0; }
.stream-text code {
  background: var(--bg-tertiary);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.stream-text pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 6px 0;
  overflow-x: auto;
}
.stream-text pre code {
  background: none;
  padding: 0;
  font-size: 12px;
}
.stream-text ul, .stream-text ol { padding-left: 20px; margin: 6px 0; }
.stream-text li { margin-bottom: 2px; }
.stream-text strong { color: var(--text-primary); }
.stream-text table { border-collapse: collapse; width: 100%; margin: 6px 0; font-size: 11px; }
.stream-text th, .stream-text td { border: 1px solid var(--border); padding: 3px 8px; text-align: left; }
.stream-text th { background: var(--bg-tertiary); font-weight: 600; }

/* Tool cards */
.stream-tool {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  overflow: hidden;
}

.stream-tool-header {
  padding: 5px 10px;
  font-size: 11px;
  color: var(--accent-green);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.stream-tool-header:hover { background: var(--bg-tertiary); }

.stream-tool-header::before {
  content: "\25B8";
  font-size: 10px;
  transition: transform 0.15s;
  display: inline-block;
}

.stream-tool.expanded .stream-tool-header::before {
  transform: rotate(90deg);
}

.stream-tool-name {
  color: var(--text-primary);
  font-weight: 600;
}

.stream-tool-args {
  color: var(--text-muted);
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}

.stream-tool-spinner {
  margin-left: auto;
}

.stream-tool-spinner::after {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid var(--text-muted);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.5s linear infinite;
}

.stream-tool-body {
  display: none;
  border-top: 1px solid var(--border-light);
  padding: 6px 10px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
}

.stream-tool.expanded .stream-tool-body { display: block; }
.stream-tool-body.is-error { color: var(--accent-red); }

.stream-error {
  color: var(--accent-red);
  font-size: 12px;
}

.stream-error::before {
  content: "\2717 ";
  font-weight: 700;
}

.stream-status {
  color: var(--accent-orange);
  font-size: 11px;
}

.stream-status::before {
  content: "\25CF ";
}

/* ── Banner ───────────────────────────────────────────────── */

.stream-banner {
  color: var(--accent-green);
  margin-bottom: 16px;
  line-height: 1.3;
  white-space: pre;
}

.stream-intro {
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 16px;
  line-height: 1.6;
}

.stream-intro .model-tag {
  display: inline-block;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  margin: 0 2px;
}

/* ── Hidden terminal host (off-screen for xterm init) ─────── */

#terminal-host {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 200px;
  height: 100px;
  overflow: hidden;
}

/* ── Scrollbar ────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Animations ───────────────────────────────────────────── */

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