:root {
  --bg: #0f1115; --panel: #151820; --panel-2: #1b1f29; --line: #262b36;
  --text: #e6e8ec; --muted: #8b93a3; --accent: #8ab4f8; --accent-ink: #0f1115;
  --ok: #5fd08a; --warn: #e8b85c; --bad: #ef7a7a; --idle: #59606e;
  --radius: 10px; --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; font-size: 13px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 8px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0 0 8px; }
.login-card label { font-size: 13px; color: var(--muted); }
input, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; width: 100%; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }
button[type=submit], #send { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px;
  padding: 9px 16px; font-weight: 600; }
button:disabled { opacity: .45; cursor: not-allowed; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; }
.link-btn { background: none; border: 0; color: var(--muted); padding: 4px 0; }
.link-btn:hover { color: var(--text); }
.icon-btn { background: none; border: 0; font-size: 20px; width: 40px; height: 40px; border-radius: 8px; }
.icon-btn:hover { background: var(--panel-2); }

/* layout: mobile first */
.app { height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
.app > * { min-height: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px;
  border-bottom: 1px solid var(--line); background: var(--panel); padding-top: max(4px, env(safe-area-inset-top)); }
.topbar-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.pane { position: fixed; top: 0; bottom: 0; width: min(86vw, 320px); background: var(--panel); z-index: 20;
  display: flex; flex-direction: column; transition: transform .18s ease; border-color: var(--line); }
.agents { left: 0; transform: translateX(-102%); border-right: 1px solid var(--line); }
.activity { right: 0; transform: translateX(102%); border-left: 1px solid var(--line); }
.app.show-agents .agents, .app.show-activity .activity { transform: none; }
.scrim { position: fixed; inset: 0; background: #0009; z-index: 10; }
.pane-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px;
  font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.pane-foot { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--line); }

.agent-list { overflow-y: auto; overflow-x: hidden; padding: 4px 8px; }
.agent { width: 100%; display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  text-align: left; background: none; border: 0; border-radius: 8px; padding: 10px; }
.agent:hover { background: var(--panel-2); }
.agent.active { background: var(--panel-2); box-shadow: inset 2px 0 0 var(--accent); }
.agent.planned .agent-name { color: var(--muted); }
.agent-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 11px; border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; color: var(--muted); }
.badge.busy { color: var(--warn); border-color: #5a4a25; }
.badge.lock { color: var(--accent); border-color: #2c3d5a; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); display: inline-block; }
.dot.online { background: var(--ok); } .dot.offline { background: var(--bad); } .dot.busy { background: var(--warn); }
.dot.planned { background: transparent; border: 1px dashed var(--idle); }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
.pane { min-height: 0; }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); }
.chat-head h2 { margin: 0; font-size: 16px; }
.chip { font-size: 12px; border-radius: 999px; padding: 2px 9px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.online { color: var(--ok); border-color: #24452f; } .chip.offline { color: var(--bad); border-color: #4a2626; }
.chip.busy { color: var(--warn); border-color: #5a4a25; }
.note { margin: 10px 16px 0; padding: 9px 12px; border-radius: 8px; background: var(--panel-2); color: var(--muted);
  font-size: 13px; border: 1px solid var(--line); }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.empty { margin: auto; color: var(--muted); text-align: center; max-width: 320px; font-size: 14px; }
.msg { max-width: min(680px, 92%); display: flex; flex-direction: column; gap: 4px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 9px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user .bubble { background: #233149; border-bottom-right-radius: 4px; }
.msg.agent .bubble { background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.agent.failed .bubble, .msg.agent.timeout .bubble, .msg.agent.interrupted .bubble { border-color: #4a2626; }
.meta { font-size: 11.5px; color: var(--muted); }
.meta .err { color: var(--bad); }
.steps { font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; padding-left: 2px; }
.step { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.step code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: #b9c1cf; }
.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.composer { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
  padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--bg); }
.composer textarea { resize: none; max-height: 40vh; min-height: 42px; }
.composer-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.composer-actions #counter { margin-right: auto; }

.activity-body { overflow-y: auto; padding: 0 16px 16px; font-size: 13px; }
.act-sec { padding: 10px 0; border-bottom: 1px solid var(--line); }
.act-sec:last-child { border-bottom: 0; }
.act-sec h3 { margin: 0 0 6px; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.task { padding: 6px 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; }
.task .t-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task .t-sub { grid-column: 2; color: var(--muted); font-size: 12px; }
.st { font-size: 11px; border-radius: 4px; padding: 0 5px; border: 1px solid var(--line); color: var(--muted); align-self: start; }
.st.running { color: var(--warn); border-color: #5a4a25; } .st.done { color: var(--ok); border-color: #24452f; }
.st.blocked, .st.failed { color: var(--bad); border-color: #4a2626; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.close-only { font-size: 22px; }

@media (min-width: 760px) {
  .app { grid-template-columns: 260px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .topbar { display: none; }
  .agents { position: static; transform: none; width: auto; }
  .app.show-activity .activity { transform: none; }
  .chat-head { padding: 14px 20px; }
  #chat-state { cursor: pointer; }
}
@media (min-width: 1100px) {
  .app { grid-template-columns: 260px minmax(0, 1fr) 310px; }
  .activity { position: static; transform: none; width: auto; }
  .close-only { display: none; }
  .scrim { display: none !important; }
}
