:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f5;
  --bg-side: #f2f2ef;
  --text: #1a1a19;
  --text-dim: #6b6b66;
  --border: #e3e3df;
  --accent: #c96442;
  --accent-soft: #f6ede9;
  --tool-bg: #f7f7f5;
  --code-bg: #f4f4f1;
  --danger: #b4453a;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b19;
    --bg-soft: #232320;
    --bg-side: #161614;
    --text: #ececea;
    --text-dim: #9a9a94;
    --border: #33332f;
    --accent: #d97757;
    --accent-soft: #2e2621;
    --tool-bg: #232320;
    --code-bg: #232320;
    --danger: #e08a7e;
  }
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  font-size: 15px; -webkit-font-smoothing: antialiased;
}
#app { display: flex; height: 100vh; height: 100dvh; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 264px; flex: 0 0 264px; background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 12px 10px;
  transition: margin-left .22s ease;
}
#sidebar.collapsed { margin-left: -264px; }
.brand {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px 14px; font-size: 14px; letter-spacing: .2px;
}
.brand b { font-weight: 600; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.new-chat {
  display: flex; align-items: center; gap: 6px; justify-content: center;
  width: 100%; padding: 9px 12px; margin-bottom: 10px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 13.5px; font-weight: 500; cursor: pointer;
  transition: background .15s;
}
.new-chat:hover { background: var(--accent-soft); border-color: var(--accent); }
#session-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
#session-list::-webkit-scrollbar { width: 6px; }
#session-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sess {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  font-size: 13.5px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden;
}
.sess:hover { background: var(--bg-soft); color: var(--text); }
.sess.active { background: var(--bg); color: var(--text); font-weight: 500; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.sess .t { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.sess .spin {
  width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px;
  background: var(--accent); animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }
.sess .del {
  opacity: 0; border: 0; background: none; color: var(--text-dim);
  cursor: pointer; font-size: 15px; padding: 0 2px; line-height: 1;
}
.sess:hover .del { opacity: .6; }
.sess .del:hover { opacity: 1; color: var(--danger); }
.sidebar-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 8px 2px; border-top: 1px solid var(--border); margin-top: 8px;
  font-size: 11px; color: var(--text-dim);
}
.conn::before {
  content: ""; display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: #999; margin-right: 5px; vertical-align: 1px;
}
.conn.on::before { background: #4a9e5c; }
.conn.off::before { background: var(--danger); }
.badge {
  font-family: var(--mono); font-size: 10px; padding: 2px 6px;
  border: 1px solid var(--border); border-radius: 5px;
}

/* ---------- main ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  min-height: 52px;
}
#chat-title { flex: 1; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  font-size: 13px; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--bg-soft); }
.pill {
  font-size: 11px; padding: 3px 9px; border-radius: 20px;
  border: 1px solid var(--border); color: var(--text-dim);
}
.pill.working { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.pill.working::before {
  content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); margin-right: 5px; animation: pulse 1.2s infinite;
}
.hidden { display: none !important; }

#transcript { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
#transcript::-webkit-scrollbar { width: 8px; }
#transcript::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
#messages { max-width: 780px; margin: 0 auto; padding: 24px 24px 8px; }
#empty-state { max-width: 620px; margin: 14vh auto 0; padding: 0 24px; text-align: center; }
#empty-state h1 { font-size: 26px; font-weight: 600; margin: 0 0 10px; letter-spacing: -.3px; }
#empty-state p { color: var(--text-dim); line-height: 1.6; font-size: 14.5px; margin: 0; }

/* ---------- messages ---------- */
.msg { margin-bottom: 22px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: var(--bg-soft); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: 14px 14px 4px 14px;
  max-width: 85%; white-space: pre-wrap; word-break: break-word;
}
.msg.assistant .body { line-height: 1.65; word-break: break-word; }
.msg.assistant .body > *:first-child { margin-top: 0; }
.msg.assistant .body > *:last-child { margin-bottom: 0; }
.msg.assistant .body p { margin: 0 0 12px; }
.msg.assistant .body ul, .msg.assistant .body ol { margin: 0 0 12px; padding-left: 22px; }
.msg.assistant .body li { margin: 4px 0; }
.msg.assistant .body h1, .msg.assistant .body h2, .msg.assistant .body h3 {
  margin: 18px 0 8px; font-weight: 600; line-height: 1.3;
}
.msg.assistant .body h1 { font-size: 20px; }
.msg.assistant .body h2 { font-size: 17px; }
.msg.assistant .body h3 { font-size: 15.5px; }
.msg.assistant .body a { color: var(--accent); }
.msg.assistant .body code {
  font-family: var(--mono); font-size: 12.8px;
  background: var(--code-bg); padding: 2px 5px; border-radius: 4px;
}
.msg.assistant .body pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 0 0 12px;
}
.msg.assistant .body pre code { background: none; padding: 0; font-size: 12.8px; line-height: 1.55; }
.msg.assistant .body blockquote {
  margin: 0 0 12px; padding-left: 14px; border-left: 3px solid var(--border); color: var(--text-dim);
}
.msg.assistant .body table { border-collapse: collapse; margin: 0 0 12px; font-size: 13.5px; }
.msg.assistant .body th, .msg.assistant .body td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.msg.assistant .body th { background: var(--bg-soft); }
.thinking {
  font-size: 13px; color: var(--text-dim); font-style: italic;
  border-left: 2px solid var(--border); padding: 2px 0 2px 12px; margin: 0 0 12px;
  white-space: pre-wrap;
}

/* ---------- tool cards ---------- */
.tool {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--tool-bg); margin: 0 0 12px; overflow: hidden;
  font-size: 13px;
}
.tool-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; cursor: pointer; user-select: none;
}
.tool-head:hover { background: var(--bg-soft); }
.tool-name { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.tool-summary {
  flex: 1; font-family: var(--mono); font-size: 11.5px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool-chev { color: var(--text-dim); font-size: 10px; transition: transform .15s; }
.tool.open .tool-chev { transform: rotate(90deg); }
.tool-status { font-size: 10px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); color: var(--text-dim); }
.tool-status.err { color: var(--danger); border-color: var(--danger); }
.tool-body { display: none; border-top: 1px solid var(--border); padding: 10px 12px; }
.tool.open .tool-body { display: block; }
.tool-body pre {
  margin: 0 0 8px; font-family: var(--mono); font-size: 11.8px;
  white-space: pre-wrap; word-break: break-word; max-height: 340px; overflow-y: auto;
}
.tool-body .label { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); margin-bottom: 4px; }
.tool-body pre:last-child { margin-bottom: 0; }

/* ---------- composer ---------- */
#composer-wrap { padding: 8px 24px 16px; }
#composer {
  max-width: 780px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 16px; padding: 8px 8px 8px 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,.04);
}
#composer:focus-within { border-color: var(--accent); }
#input {
  flex: 1; border: 0; outline: 0; resize: none; background: transparent;
  color: var(--text); font-family: inherit; font-size: 15px; line-height: 1.5;
  max-height: 220px; padding: 6px 0;
}
.send {
  flex: 0 0 32px; width: 32px; height: 32px; border-radius: 9px;
  border: 0; background: var(--accent); color: #fff;
  font-size: 16px; cursor: pointer; display: grid; place-items: center;
  transition: opacity .15s;
}
.send:disabled { opacity: .35; cursor: default; }
#composer-hint {
  max-width: 780px; margin: 6px auto 0; text-align: center;
  font-size: 10.5px; color: var(--text-dim); font-family: var(--mono);
}

/* ---------- login ---------- */
#login {
  position: fixed; inset: 0; background: var(--bg);
  display: grid; place-items: center; z-index: 50;
}
#login form {
  width: 320px; display: flex; flex-direction: column; gap: 10px;
  padding: 28px; border: 1px solid var(--border); border-radius: 16px;
  background: var(--bg-soft);
}
#login h2 { margin: 0; font-size: 19px; }
#login p { margin: 0 0 4px; color: var(--text-dim); font-size: 13px; }
#login input {
  padding: 10px 12px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; outline: 0;
}
#login input:focus { border-color: var(--accent); }
#login button {
  padding: 10px; border-radius: 9px; border: 0; background: var(--accent);
  color: #fff; font-size: 14px; font-weight: 500; cursor: pointer;
}
#login-error { color: var(--danger); font-size: 12px; min-height: 16px; }

@media (max-width: 760px) {
  #sidebar { position: absolute; z-index: 20; height: 100%; box-shadow: 4px 0 20px rgba(0,0,0,.1); }
  #sidebar.collapsed { margin-left: -264px; }
  #messages, #composer-wrap { padding-left: 14px; padding-right: 14px; }
}

/* ---------- mode switch ---------- */
.mode-switch {
  display: flex; gap: 2px; margin-bottom: 10px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 9px; padding: 2px;
}
.mode {
  flex: 1; padding: 6px 8px; border: 0; border-radius: 7px;
  background: transparent; color: var(--text-dim);
  font-size: 12.5px; font-weight: 500; cursor: pointer;
}
.mode.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

/* ---------- orchestrator ---------- */
#orch-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#orch-topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border); min-height: 52px;
}
#orch-title { flex: 1; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#orch-body { flex: 1; overflow-y: auto; }
#orch-empty { max-width: 620px; margin: 10vh auto 0; padding: 0 24px; }
#orch-empty h1 { font-size: 26px; font-weight: 600; margin: 0 0 10px; letter-spacing: -.3px; }
#orch-empty p { color: var(--text-dim); line-height: 1.6; font-size: 14.5px; margin: 0 0 24px; }
#orch-form { display: flex; flex-direction: column; gap: 10px; }
#orch-form label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .6px; }
#orch-objective {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-family: inherit; font-size: 14.5px;
  line-height: 1.5; resize: vertical; outline: 0;
}
#orch-objective:focus { border-color: var(--accent); }
.orch-controls { display: flex; align-items: center; gap: 10px; }
#orch-agents {
  width: 64px; padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 14px; outline: 0;
}
.primary {
  margin-left: auto; padding: 9px 18px; border-radius: 9px; border: 0;
  background: var(--accent); color: #fff; font-size: 14px;
  font-weight: 500; cursor: pointer;
}
.primary:disabled { opacity: .5; cursor: default; }

#orch-run { max-width: 900px; margin: 0 auto; padding: 20px 24px 40px; }
#orch-agents-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px; margin-bottom: 20px;
}
.agent-card {
  border: 1px solid var(--border); border-radius: 11px;
  padding: 11px 13px; background: var(--bg-soft);
}
.agent-card.working { border-color: var(--accent); background: var(--accent-soft); }
.agent-card.done { opacity: .75; }
.agent-card.failed { border-color: var(--danger); }
.agent-head { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; }
.agent-id { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.agent-state { margin-left: auto; font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); }
.agent-card.working .agent-state { color: var(--accent); }
.agent-meta { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }
.agent-task { font-size: 11.5px; color: var(--text-dim); margin-top: 6px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

#orch-feed { display: flex; flex-direction: column; gap: 6px; }
.feed-item {
  display: flex; gap: 10px; padding: 7px 11px; border-radius: 9px;
  font-size: 12.5px; line-height: 1.5; border: 1px solid transparent;
}
.feed-item .who {
  flex: 0 0 42px; font-family: var(--mono); font-size: 10.5px;
  color: var(--text-dim); padding-top: 2px;
}
.feed-item .what { flex: 1; min-width: 0; word-break: break-word; }
.feed-item.overseer { background: var(--accent-soft); border-color: var(--accent); }
.feed-item.overseer .who { color: var(--accent); font-weight: 600; }
.feed-item.round { background: var(--bg-soft); border-color: var(--border); font-weight: 600; }
.feed-item.tool .what { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); }
.feed-item.thought .what { white-space: pre-wrap; }
.feed-item.error { background: var(--accent-soft); border-color: var(--danger); }
.feed-item pre {
  margin: 4px 0 0; font-family: var(--mono); font-size: 11px;
  white-space: pre-wrap; word-break: break-word; max-height: 200px; overflow-y: auto;
  color: var(--text-dim);
}

#orch-files { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 14px; }
.files-toggle {
  border: 0; background: none; color: var(--text-dim); cursor: pointer;
  font-size: 12.5px; padding: 0;
}
#orch-files-body { margin-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.file-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 9px;
  border-radius: 7px; cursor: pointer; font-size: 12px;
  font-family: var(--mono); color: var(--text-dim);
}
.file-row:hover { background: var(--bg-soft); color: var(--text); }
.file-viewer {
  margin-top: 10px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--tool-bg); padding: 12px 14px; max-height: 460px; overflow: auto;
}
.file-viewer pre {
  margin: 0; font-family: var(--mono); font-size: 11.5px;
  white-space: pre-wrap; word-break: break-word;
}
.orch-panel { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 12px; }
#orch-memory-body { margin-top: 10px; }
#orch-memory-body pre {
  margin: 8px 0 0; font-family: var(--mono); font-size: 11.5px;
  white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow-y: auto;
  color: var(--text-dim);
}

/* Keep team status visible while the feed scrolls. */
#orch-agents-grid {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg); padding: 10px 0 12px;
  margin-top: -10px;
}
