:root {
  --bg: #0b1020;
  --bg2: #121a33;
  --panel: #1a2340;
  --me: #2f6df6;
  --them: #212a48;
  --text: #e8ecf4;
  --muted: #93a0bd;
  --accent: #5b8cff;
  --ok: #37d67a;
  --warn: #ffb020;
  --line: #263153;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow-x: clip; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
#app { display: flex; flex-direction: column; height: 100dvh; }

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(180deg, var(--bg2), var(--bg));
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.brand-name { letter-spacing: .3px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); transition: background .3s; }
.dot.live { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.off { background: #d64550; }
.ghost {
  background: transparent; color: var(--accent); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 999px; font-size: 13px;
}

/* workspace switcher — only shown once >1 agent is enrolled in this browser */
.ws-switcher {
  display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.ws-switcher::-webkit-scrollbar { display: none; }
.ws-chip {
  flex: 0 0 auto; background: var(--panel); color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.ws-chip.active { background: var(--me); color: #fff; border-color: var(--me); }

/* persistent turn-status banner — survives reconnect (server-backed, not the
   ephemeral typing dot). "Still working…" while a long task runs, "⏸ Waiting on
   you" when it needs a decision; both offer a Cancel to free a jammed queue. */
.status-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; font-size: 13.5px; font-weight: 600;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 4;
}
.status-banner.working { background: #16223f; color: var(--accent); }
.status-banner.waiting { background: #3a2c12; color: var(--warn); }
.status-banner .status-text { flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-banner .status-icon { width: 8px; height: 8px; border-radius: 50%;
  flex: 0 0 auto; background: currentColor; }
.status-banner.working .status-icon { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .35; } 50% { opacity: 1; } }
.status-cancel {
  flex: 0 0 auto; background: transparent; color: inherit;
  border: 1px solid currentColor; border-radius: 999px;
  padding: 4px 12px; font-size: 12px; font-weight: 600;
}
.status-cancel:disabled { opacity: .5; }

#thread {
  flex: 1; overflow-y: auto; padding: 14px 12px 6px;
  display: flex; flex-direction: column; gap: 8px;
}
.msg { max-width: 82%; padding: 10px 13px; border-radius: 18px; white-space: pre-wrap;
  word-wrap: break-word; animation: pop .18s ease; }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }
.msg.me { align-self: flex-end; background: var(--me); border-bottom-right-radius: 5px; }
.msg.them { align-self: flex-start; background: var(--them); border-bottom-left-radius: 5px; }
.msg.escalation { align-self: flex-start; background: #3a2c12; border: 1px solid var(--warn);
  border-bottom-left-radius: 5px; }
.msg small { display: block; color: var(--muted); font-size: 11px; margin-bottom: 3px; }

/* interactive prompt card */
.prompt { align-self: flex-start; max-width: 88%; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.prompt .q { font-weight: 600; margin-bottom: 4px; }
.prompt .hdr { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.opt {
  display: block; width: 100%; text-align: left; margin: 6px 0;
  background: var(--them); color: var(--text); border: 1px solid var(--line);
  padding: 11px 13px; border-radius: 12px; font-size: 15px;
}
.opt.sel { background: var(--me); border-color: var(--accent); }
.opt:active { transform: scale(.98); }
.prompt .row { display: flex; gap: 8px; margin-top: 8px; }
.prompt .row button { flex: 1; padding: 12px; border-radius: 12px; border: none; font-weight: 600; }
.btn-allow { background: var(--ok); color: #06210f; }
.btn-deny { background: #d64550; color: #fff; }
.btn-done { background: var(--accent); color: #06122e; }
.other-wrap { display: flex; gap: 6px; margin-top: 8px; }
.other-wrap input { flex: 1; background: var(--bg2); border: 1px solid var(--line);
  color: var(--text); border-radius: 10px; padding: 10px; }
.tool-input { color: var(--muted); font-size: 12px; margin: 6px 0 2px;
  font-family: ui-monospace, monospace; word-break: break-all; }
.resolved { opacity: .7; }
.resolved .opt, .resolved .row button, .resolved .other-wrap { pointer-events: none; }

.typing { display: flex; align-items: center; gap: 8px; padding: 4px 20px 10px; }
.typing .dots { display: flex; gap: 5px; }
.typing .dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite; }
.typing .dots span:nth-child(2) { animation-delay: .2s; }
.typing .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100% { opacity: .3; } 30% { opacity: 1; } }
.typing .note { font-size: 12px; color: var(--muted); }

#composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg2);
}
#input {
  flex: 1; resize: none; max-height: 140px; background: var(--panel);
  color: var(--text); border: 1px solid var(--line); border-radius: 20px;
  padding: 11px 15px; font-size: 16px; line-height: 1.35;
}
#input:focus { outline: none; border-color: var(--accent); }
#send { background: var(--me); color: #fff; border: none; width: 44px; height: 44px;
  border-radius: 50%; display: grid; place-items: center; flex: 0 0 auto; }
#send:active { transform: scale(.94); }

#attach-btn {
  background: transparent; color: var(--muted); border: none; width: 40px; height: 44px;
  display: grid; place-items: center; flex: 0 0 auto;
}
#attach-btn:active { transform: scale(.9); color: var(--accent); }

/* pending attachments — staged above the composer before send */
.pending-attachments {
  display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px 0;
  -webkit-overflow-scrolling: touch;
}
.pending-chip {
  position: relative; flex: 0 0 auto; width: 56px; height: 56px; border-radius: 12px;
  overflow: hidden; background: var(--panel); border: 1px solid var(--line);
  display: grid; place-items: center;
}
.pending-chip img { width: 100%; height: 100%; object-fit: cover; }
.pending-chip .doc-label { font-size: 10px; color: var(--muted); text-align: center;
  padding: 0 4px; word-break: break-all; }
.pending-chip .remove {
  position: absolute; top: -4px; right: -4px; width: 18px; height: 18px; border-radius: 50%;
  background: #d64550; color: #fff; border: none; font-size: 12px; line-height: 1;
  display: grid; place-items: center;
}
.pending-chip .uploading { position: absolute; inset: 0; background: rgba(0,0,0,.5);
  display: grid; place-items: center; color: var(--muted); font-size: 10px; }

/* attachments rendered inside a sent/received message bubble */
.msg-attachments { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.msg-attachments img {
  max-width: 160px; max-height: 160px; border-radius: 10px; display: block;
}
.msg-attachments .doc-chip {
  display: flex; align-items: center; gap: 6px; background: rgba(0,0,0,.15);
  border-radius: 10px; padding: 8px 10px; font-size: 13px;
}

.overlay { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center;
  z-index: 20; padding: 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 24px; max-width: 360px; width: 100%; text-align: center; }
.card .logo { font-size: 26px; font-weight: 700; margin-bottom: 12px; }
.card p { color: var(--muted); }
.card input { width: 100%; margin: 10px 0; padding: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text); }
.card button { width: 100%; padding: 12px; border-radius: 12px; border: none;
  background: var(--me); color: #fff; font-weight: 600; }
[hidden] { display: none !important; }
