:root {
  --bg: #0e0f11; --rail: #0a0b0c; --panel: #16181b; --bubble: #1f2226; --bubble-2: #262a2f;
  --line: #2a2e33; --fg: #eceef0; --muted: #8c939b; --faint: #5d646c;
  --me: #f2f3f4; --me-fg: #111315; --accent: #7aa2ff; --ok: #4ade80; --warn: #fbbf24; --err: #f87171;
  --radius: 18px; --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: light) {
  body[data-theme="auto"] {
    --bg: #f6f6f7; --rail: #ececee; --panel: #ffffff; --bubble: #ffffff; --bubble-2: #f1f1f3;
    --line: #e2e3e6; --fg: #15171a; --muted: #6b7178; --faint: #9aa0a6; --me: #15171a; --me-fg: #fff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
.boot { display: grid; place-items: center; height: 100dvh; color: var(--muted); }

.app { display: flex; height: 100dvh; }

/* ---- rail of bots ---- */
.rail { width: 76px; flex: none; background: var(--rail); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; padding: 14px 0 12px; gap: 6px; overflow-y: auto; }
.rail .brand { font-weight: 700; font-size: 13px; letter-spacing: .02em; color: var(--muted); margin-bottom: 8px; }
.botbtn { position: relative; width: 56px; height: 56px; border-radius: 16px; border: 0; background: transparent;
  display: grid; place-items: center; padding: 0; }
.botbtn:hover { background: var(--bubble); }
.botbtn.active { background: var(--bubble-2); }
.botbtn .dot { position: absolute; right: 6px; top: 6px; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--rail); }
.dot.working { background: var(--ok); }
.dot.needs { background: var(--warn); }
.rail .spacer { flex: 1; }
.iconbtn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: transparent;
  display: grid; place-items: center; color: var(--muted); }
.iconbtn:hover { color: var(--fg); background: var(--bubble); }
.whoami { width: 34px; height: 34px; border-radius: 50%; background: var(--bubble-2); display: grid; place-items: center;
  font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; margin-top: 8px; }

/* ---- chat ---- */
.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); min-height: 64px; }
.head .who { flex: 1; min-width: 0; }
.head .name { font-weight: 650; font-size: 16px; display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; }
.head .name span.n { overflow: hidden; text-overflow: ellipsis; }
.head > button, .head > canvas, .bar > canvas, .botbtn canvas { flex: none; }
.pill { flex: none; }
.head .role { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 12px; font-weight: 550; padding: 2px 9px; border-radius: 999px; background: var(--bubble-2); color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px; }
.pill i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
.pill.working { color: var(--ok); } .pill.needs { color: var(--warn); } .pill.control { color: var(--accent); }
.menu-back { display: none; }

.log { flex: 1; overflow-y: auto; padding: 20px 16px 8px; }
.col { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; }
.row.me { justify-content: flex-end; }
.bubble { max-width: min(78%, 620px); padding: 10px 14px; border-radius: var(--radius); background: var(--bubble);
  white-space: pre-wrap; word-wrap: break-word; }
.row.me .bubble { background: var(--me); color: var(--me-fg); border-bottom-right-radius: 6px; }
.row.bot .bubble { border-bottom-left-radius: 6px; }
.bubble code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: rgba(127,127,127,.18); padding: 1px 5px; border-radius: 6px; }
.bubble a { color: var(--accent); }
.bubble.err { color: var(--err); background: transparent; border: 1px solid var(--line); }
.sys { align-self: center; color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.sys b { color: var(--fg); font-weight: 550; }
.meta { align-self: flex-start; color: var(--faint); font-size: 12px; padding-left: 4px; }

.activity { align-self: flex-start; width: min(78%, 620px); background: var(--bubble); border-radius: var(--radius);
  border-bottom-left-radius: 6px; padding: 8px 6px; }
.act { display: flex; align-items: flex-start; gap: 8px; padding: 3px 8px; border-radius: 8px; font-size: 13.5px; }
.act:hover { background: var(--bubble-2); cursor: pointer; }
.act .ic { width: 18px; flex: none; text-align: center; color: var(--ok); }
.act.err .ic { color: var(--err); }
.act .txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act.open .txt { white-space: normal; }
.act code { font: 12.5px ui-monospace, Menlo, monospace; }
.out { margin: 2px 8px 6px 34px; padding: 8px 10px; background: var(--bg); border-radius: 10px; font: 12px/1.45 ui-monospace, Menlo, monospace;
  color: var(--muted); white-space: pre-wrap; max-height: 260px; overflow: auto; }
.more { font-size: 12.5px; color: var(--muted); padding: 3px 34px; background: none; border: 0; }
.thumb { display: block; margin: 6px 8px 2px; width: calc(100% - 16px); max-width: 420px; border-radius: 12px;
  border: 1px solid var(--line); cursor: zoom-in; }

.takeover { align-self: stretch; background: linear-gradient(0deg, rgba(251,191,36,.06), rgba(251,191,36,.06)), var(--bubble);
  border: 1px solid rgba(251,191,36,.35); border-radius: var(--radius); padding: 14px 16px; }
.takeover h4 { margin: 0 0 4px; font-size: 14px; display: flex; align-items: center; gap: 8px; color: var(--warn); }
.takeover p { margin: 0 0 12px; white-space: pre-wrap; }
.takeover .btns { display: flex; gap: 8px; flex-wrap: wrap; }
.takeover.done { opacity: .6; border-color: var(--line); background: var(--bubble); }

.thinking { align-self: flex-start; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 4px 6px; }

.composer { padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); }
.composer .box { display: flex; align-items: flex-end; gap: 8px; background: var(--bubble);
  border: 1px solid var(--line); border-radius: 24px; padding: 5px 16px; min-height: 46px; align-items: center; }
.composer textarea { flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--fg); font: inherit;
  padding: 8px 0; max-height: 200px; min-height: 24px; }
.composer-row { max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px; }
.send { width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--bubble); color: var(--fg);
  display: grid; place-items: center; flex: none; font-size: 18px; font-weight: 600; }
.send:not(:disabled):not(.stop) { color: var(--accent); }
.send.stop { color: #fdba74; font-size: 14px; }
.beam-btn { flex: none; border-radius: 50%; }
.send:disabled { opacity: .35; cursor: default; }
.btn { border: 1px solid var(--line); background: var(--bubble-2); border-radius: 999px; padding: 7px 14px; font-size: 13.5px; font-weight: 550; }
.btn.primary { background: var(--me); color: var(--me-fg); border-color: transparent; }
.btn.danger { color: var(--err); }
.btn:hover { filter: brightness(1.08); }

/* ---- computer panel ---- */
.screen { width: min(50vw, 880px); flex: none; border-left: 1px solid var(--line); display: flex; flex-direction: column; background: var(--rail); }
.screen .bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.screen .bar .t { flex: 1; font-weight: 600; font-size: 14px; }
.screen iframe { flex: 1; border: 0; width: 100%; background: #111; }
/* border-beam wrappers: size them like the element they wrap */
.beam-box { flex: 1; min-width: 0; border-radius: 24px; }
.composer .box { max-width: none; }
.beam-takeover { align-self: stretch; border-radius: var(--radius); }
.beam-screen { flex: 1; min-height: 0; display: flex; margin: 0 8px 8px; border-radius: 14px; }
.screen-frame { flex: 1; display: flex; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); background: #111; }

/* ---- dialog ---- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 20; padding: 16px; }
.dialog { width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 20px; }
.dialog h3 { margin: 0 0 14px; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.field input, .field textarea { font: inherit; font-size: 14.5px; color: var(--fg); background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 12px; outline: 0; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.avatars { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
.avatars button { height: 56px; border-radius: 14px; border: 1px solid transparent; background: var(--bg); display: grid; place-items: center; padding: 0; }
.avatars button.sel { border-color: var(--accent); background: var(--bubble-2); }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button { border: 0; background: transparent; color: var(--muted); padding: 6px 10px; border-radius: 999px; font-weight: 550; }
.tabs button.on { background: var(--bubble-2); color: var(--fg); }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.actions .grow { flex: 1; }
.hint { color: var(--faint); font-size: 12px; }

@media (max-width: 820px) {
  .rail { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .app.rail-open .rail { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .menu-back { display: grid; }
  .head { gap: 8px; padding: 8px 10px; }
  .head .role { display: none; }
  .screen { position: fixed; inset: 0; width: auto; z-index: 15; }
  .bubble, .activity { max-width: 88%; width: auto; }
  .activity { width: 88%; }
}
