:root {
  --bg: #ffffff;
  --side: #f4f4f5;
  --panel: #fafafa;
  --card: #ffffff;
  --line: #e4e4e7;
  --text: #18181b;
  --muted: #5b5b65;
  --mine: #18181b;
  --mine-text: #ffffff;
  --bubble: #f4f4f5;
  --accent: #f26b1d;
  --danger: #dc2626;
  --warn: #b45309;
  --ok: #15803d;
  --info: #2563eb;
  --bad-bg: #fee2e2;
  --warn-bg: #fef3c7;
  --ok-bg: #dcfce7;
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --side: #18181b;
    --panel: #151517;
    --card: #1f1f23;
    --line: #2e2e33;
    --text: #f4f4f5;
    --muted: #b8b8c1;
    --mine: #f4f4f5;
    --mine-text: #18181b;
    --bubble: #232328;
    --warn: #fbbf24;
    --danger: #f87171;
    --ok: #4ade80;
    --info: #60a5fa;
    --bad-bg: rgb(248 113 113 / .16);
    --warn-bg: rgb(251 191 36 / .14);
    --ok-bg: rgb(74 222 128 / .14);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
button.danger { color: var(--danger); }
button.wide { width: 100%; margin-top: 20px; }
button.link { border: 0; background: none; color: var(--muted); padding: 4px; }
button.icon { width: 32px; height: 32px; padding: 0; font-size: 20px; line-height: 1; }
input, select, textarea {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 9px 12px;
  width: 100%;
}
input[type="color"] { width: 44px; height: 36px; padding: 2px; }
pre { white-space: pre-wrap; word-break: break-word; margin: 0; font-size: 13px; }
code { font-size: 13px; }
h4 { margin: 18px 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { display: grid; place-items: center; height: 100%; }
.offline { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 16px; }
.row { display: flex; gap: 8px; align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* avatar: a canvas the vatarplay engine draws on (src/avatar.rs, avatar.js) */
.avatar { display: block; flex: none; touch-action: manipulation; }
.char-pick { display: flex; flex-wrap: wrap; gap: 2px; }
.char-pick button {
  padding: 0;
  border: 2px solid transparent;
  border-radius: 10px;
  background: none;
  cursor: pointer;
}
.char-pick button.on { border-color: var(--accent); }

/* auth */
.auth { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.auth-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.auth-card h1 { margin: 8px 0; font-size: 24px; }
.auth-card p { margin: 0 0 8px; text-align: center; }
.auth-card button { width: 100%; margin-top: 6px; }

/* layout */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
.side {
  background: var(--side);
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
}
.side-top { display: flex; align-items: center; gap: 8px; padding: 16px; }
.brand { font-weight: 700; font-size: 17px; flex: 1; }
.net { width: 10px; height: 10px; cursor: help; border-radius: 50%; background: var(--muted); }
.net.on { background: #22c55e; }
.new-bot { display: flex; flex-direction: column; gap: 8px; padding: 0 16px 12px; }
.new-bot .row button { flex: 1; }
.bots { flex: 1; overflow-y: auto; padding: 0 8px; }
.bot-row {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 14px;
  background: none;
  padding: 10px;
}
.bot-row:hover { background: var(--line); }
.bot-row.sel { background: var(--card); box-shadow: 0 1px 2px rgba(0, 0, 0, .06); }
.bot-meta { min-width: 0; }
.bot-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

/* chat */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 8px;
  padding: 12px;
}
.head-mid { display: flex; justify-content: center; align-items: center; gap: 8px; min-width: 0; }
.head-mid .pill { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .back, .chat-head .info { visibility: hidden; border: 0; background: none; }
.profile-top { display: none; margin: -8px 0 8px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-weight: 600;
}
.msgs {
  flex: 1;
  overflow-y: auto;
  padding: 8px max(16px, calc((100% - 880px) / 2)) 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.empty { margin: auto; }
.msg { display: flex; flex-direction: column; gap: 6px; max-width: 85%; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; align-items: flex-start; }
.bubble {
  background: var(--bubble);
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.mine .bubble { background: var(--mine); color: var(--mine-text); }
.time { font-size: 12px; color: var(--muted); padding: 0 6px; }
.caret {
  display: inline-block;
  width: 7px;
  height: 1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: currentColor;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { to { opacity: 0; } }
.choices { display: flex; flex-direction: column; gap: 6px; width: 100%; min-width: 260px; }
.choices .q { font-weight: 600; margin: 4px 2px; }
.choice {
  display: flex;
  gap: 10px;
  align-items: center;
  text-align: left;
  border-radius: 14px;
  padding: 10px 12px;
}
.letter {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  background: var(--bubble);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  flex: none;
}
.tool { font-size: 13px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.tool-name { color: var(--text); font-weight: 600; }
.tool-out { font-size: 13px; color: var(--muted); max-width: 100%; }
.tool-out.err summary { color: var(--danger); }
.tool-out pre { background: var(--bubble); padding: 8px 10px; border-radius: 10px; margin-top: 4px; max-height: 300px; overflow: auto; }
.approval {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 85%;
}
.approval-title { font-weight: 600; }
.approval pre { background: var(--bubble); padding: 8px 10px; border-radius: 10px; max-height: 240px; overflow: auto; }
.warn { color: var(--warn); font-size: 13px; }
.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--line);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin: 0 max(16px, calc((100% - 880px) / 2)) calc(16px + env(safe-area-inset-bottom));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--card);
}
.composer textarea { border: 0; resize: none; max-height: 200px; field-sizing: content; background: none; }
.composer textarea:focus { outline: none; }
.send { width: 40px; height: 40px; padding: 0; background: var(--text); color: var(--bg); border: 0; font-size: 18px; flex: none; }

/* profile */
.profile {
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 20px 16px;
  overflow-y: auto;
}
.prof-head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; }
.prof-head h2 { margin: 8px 0 0; font-size: 20px; }
.tabs { display: flex; gap: 4px; margin-top: 16px; padding: 4px; background: var(--side); border-radius: 999px; }
.tabs button { flex: 1; min-width: 0; border: 0; background: none; padding: 6px 2px; font-size: 13px; }
.tabs button.on { background: var(--text); color: var(--bg); font-weight: 600; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.screen-thumb {
  width: 64px;
  height: 44px;
  border-radius: 8px;
  background: var(--bubble);
  display: grid;
  place-items: center;
}
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  max-width: calc(100% - 32px);
  cursor: pointer;
  z-index: 30;
}

/* narrow screens (mobile.rs): the profile opens over the chat, then one pane at a time */
@media (max-width: 1100px) {
  .collapse { display: none; }
  .layout { grid-template-columns: 260px 1fr; }
  .profile { display: none; }
  .chat-head .info { visibility: visible; }
  .profile-top { display: block; }
  .layout.pane-profile .profile {
    display: block;
    position: fixed;
    z-index: 15;
    top: 0; right: 0; bottom: 0;
    width: min(380px, 100%);
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    box-shadow: -12px 0 40px rgb(0 0 0 / 0.25);
  }
}
@media (max-width: 700px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout.pane-list .chat, .layout:not(.pane-list) .side { display: none; }
  .side { border-right: 0; min-width: 0; }
  .side-bottom { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .chat-head .back { visibility: visible; }
  .chat-head { padding: 8px; }
  .layout.pane-profile .profile { width: 100%; box-shadow: none; border-left: 0; }
  .msg, .approval { max-width: 92%; }
}
/* touch screens: bigger targets; 16px inputs so iOS doesn't zoom in */
@media (pointer: coarse) {
  button.icon { width: 40px; height: 40px; }
  .bot-row { padding: 12px 10px; }
  button.link { padding: 8px; }
  input, select, textarea { font-size: 16px; }
  .send { width: 40px; height: 40px; }
}

/* M2: screens, computer, library, settings */
.or { text-align: center; }
.banner {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin: 0 16px; padding: 10px 14px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--accent);
}
.modal-bg {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  padding: 16px; background: rgb(0 0 0 / 0.45);
}
.modal {
  width: min(560px, 100%); max-height: 90vh; overflow-y: auto;
  background: var(--panel); border-radius: var(--radius); padding: 16px 20px 20px;
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.3);
}
.modal-head { margin-bottom: 8px; }
.screen-modal { width: min(1320px, 100%); }
.screen-wrap { position: relative; background: #000; border-radius: 10px; overflow: hidden; }
.screen { display: block; width: 100%; height: auto; outline: none; cursor: default; }
.screen.live { cursor: crosshair; box-shadow: inset 0 0 0 3px var(--accent); }
.screen-status {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: #e4e4e7; background: rgb(0 0 0 / 0.6); padding: 16px; text-align: center;
}
.screen-thumb.live { padding: 0; border: 0; cursor: pointer; overflow: hidden; }
.screen-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .actions { margin-top: 10px; }
.files { display: flex; flex-direction: column; gap: 4px; }
.file-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.file-row > :first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row a { color: var(--text); }
.card form.row, .invite-link { margin-top: 10px; }
.card form.row input, .invite-link input { flex: 1; min-width: 0; }
.card > .primary { margin-top: 10px; }

/* M3: system messages, routines, memory, skills, rules */
.msg.system { align-self: center; align-items: center; max-width: 92%; }
.msg.system .bubble {
  background: none; border: 1px dashed var(--line); color: var(--muted);
  font-size: 13px; white-space: pre-wrap;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack.top, .row.top { margin-top: 10px; }
.stack textarea, .stack input { width: 100%; box-sizing: border-box; }
.routines { display: flex; flex-direction: column; gap: 8px; }
.routine { display: flex; flex-direction: column; gap: 4px; }
.routine.paused { opacity: .7; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.routine .actions { flex-wrap: wrap; gap: 6px; }
.danger-text { color: var(--danger); margin-left: auto; }
.secret { margin-top: 6px; padding: 8px; border-radius: 10px; border: 1px solid var(--accent); display: flex; flex-direction: column; gap: 6px; }
.secret textarea { width: 100%; box-sizing: border-box; resize: none; }
.runs { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.run { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.run-reason { flex-basis: 100%; padding-left: 16px; }
.ok { color: #16a34a; }
.bad { color: var(--danger); }
.mem-row { display: flex; align-items: flex-start; gap: 8px; padding: 2px 0; }
.mem-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.tag {
  font-size: 11px; padding: 1px 6px; border-radius: 999px;
  background: var(--bubble); color: var(--muted); flex-shrink: 0; margin-top: 2px;
}
.link.left { text-align: left; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0; }
.skill-body { white-space: pre-wrap; font-size: 12px; background: var(--bubble); padding: 8px; border-radius: 8px; margin: 4px 0 8px; }
.rule-head { margin-top: 10px; color: var(--muted); font-weight: 600; }
.app-row { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; border-top: 1px solid var(--line); }
.app-row:first-of-type { border-top: 0; }
.app-row .row { flex-wrap: wrap; }
.mail-body { white-space: pre-wrap; font-family: inherit; font-size: 13px; margin: 8px 0 0; max-height: 300px; overflow: auto; }
details.card summary { cursor: pointer; list-style: none; }

/* Supervisor: score card, incidents, Health page */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; flex: none; }
.dot.ok { background: #16a34a; }
.dot.warn { background: var(--warn); }
.dot.fail { background: var(--danger); }
.score-sum { font-weight: 600; margin-bottom: 6px; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 13px; }
.stats > span { min-width: 0; overflow-wrap: anywhere; }
.seg { display: inline-flex; gap: 2px; }
.seg button { padding: 2px 8px; font-size: 12px; }
.seg button.on { background: var(--text); color: var(--bg); }
.incident { padding: 6px 0; border-top: 1px solid var(--line); }
.incident:first-child { border-top: 0; padding-top: 0; }
.incident .row-between { align-items: flex-start; }
.incident .row-between > span { display: flex; align-items: baseline; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.incident .dot { position: relative; top: 1px; }
.incident .muted { overflow-wrap: anywhere; }
.check { display: flex; align-items: center; gap: 8px; padding: 3px 0; flex-wrap: wrap; }
.check .muted { font-size: 13px; }

/* ---------- M6: groups, voice, pages, settings ---------- */
.faces { display: flex; flex: none; }
.faces .avatar + .avatar { margin-left: -6px; }
.prof-head .faces { justify-content: center; }
.pick { display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow: auto; }
.pick-row { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.pick-row input { width: auto; }
.who { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 6px; }
.time .read { font-size: 12px; padding: 0 4px; margin-left: 4px; opacity: .6; }
.time .read:hover { opacity: 1; }
.mic { width: 36px; height: 36px; padding: 0; flex: none; border: 0; background: none; font-size: 18px; }
.mic.on { background: var(--danger); border-radius: 50%; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.page-row { display: flex; flex-direction: column; gap: 2px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.page-row:last-child { border-bottom: 0; }
.page-row label { gap: 6px; cursor: pointer; }
.page-row input[type=checkbox] { width: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
input.short { max-width: 140px; }
.card label.row-between input[type=checkbox] { width: auto; }
.card label.row-between input[type=range] { max-width: 160px; }

/* ---------- chat UX: Markdown, tool runs, failed turns, row status ---------- */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.bubble.rich { white-space: normal; max-width: 100%; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md pre, .md blockquote, .table-wrap { margin: 0 0 8px; }
.md ul, .md ol { padding-left: 22px; }
.md li + li { margin-top: 2px; }
.md h1, .md h2, .md h3, .md h4 { font-size: 15px; margin: 12px 0 6px; color: var(--text); }
.md code { background: rgb(127 127 127 / .15); padding: 1px 5px; border-radius: 6px; }
.md pre { background: var(--bg); padding: 8px 10px; border-radius: 10px; overflow: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--muted); }
.md a { color: var(--info); }
.md hr { border: 0; border-top: 1px solid var(--line); }
.table-wrap { overflow-x: auto; max-width: 100%; }
.md table { border-collapse: collapse; font-size: 14px; }
.md th, .md td { white-space: nowrap; word-break: normal; padding: 5px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.md th { font-weight: 600; color: var(--muted); font-size: 13px; }
.md tr:last-child td { border-bottom: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; line-height: 1.5;
  padding: 0 8px; border-radius: 999px; white-space: nowrap;
  background: var(--bubble); color: var(--muted); border: 1px solid var(--line);
}
.chip.bad { background: var(--bad-bg); color: var(--danger); border-color: transparent; }
.chip.bad::before { content: "✗"; }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip.ok::before { content: "✓"; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.warn::before { content: "!"; }
.chip.idle::before { content: "–"; }
.verdict { font-weight: 600; padding: 6px 10px; border-radius: 10px; margin-bottom: 10px; }
.verdict.ok { background: var(--ok-bg); color: var(--ok); }
.verdict.warn { background: var(--warn-bg); color: var(--warn); }
.verdict.bad { background: var(--bad-bg); color: var(--danger); }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.suggestion { text-align: left; border-radius: 14px; padding: 7px 12px; font-size: 14px; border-color: var(--accent); }
.suggestion::before { content: "→ "; color: var(--accent); }
.suggestion:hover { background: var(--bubble); }

/* a run of tool calls, folded */
.tools { font-size: 13px; color: var(--muted); max-width: 100%; }
.tools > summary { cursor: pointer; display: inline-flex; gap: 8px; align-items: center; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); list-style: none; }
.tools > summary::before { content: "▸"; font-size: 11px; transition: transform .15s; }
.tools[open] > summary::before { transform: rotate(90deg); }
.tools > summary::-webkit-details-marker, .tool-call > summary::-webkit-details-marker { display: none; }
.tools-label { color: var(--text); }
.tool-list { display: flex; flex-direction: column; gap: 2px; margin: 6px 0 0 6px; padding-left: 10px; border-left: 2px solid var(--line); }
.tool-call > summary { cursor: pointer; display: flex; gap: 8px; align-items: baseline; list-style: none; padding: 2px 0; min-width: 0; }
.tool-icon { width: 14px; flex: none; text-align: center; font-weight: 700; }
.tool-icon.ok { color: var(--ok); }
.tool-icon.bad { color: var(--danger); }
.tool-name { color: var(--text); font-weight: 600; white-space: nowrap; }
.tool-args { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-raw, .tool-output { background: var(--bubble); padding: 8px 10px; border-radius: 10px; margin: 4px 0 6px 22px; max-height: 300px; overflow: auto; }
.tool-raw { font-family: ui-monospace, Consolas, monospace; }
.tool-output.err { color: var(--danger); }
.dev-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; margin-top: 4px; cursor: pointer; }
.dev-toggle input { width: auto; }

/* failed turn */
.fail-card {
  border: 1px solid var(--danger); background: var(--bad-bg);
  border-radius: var(--radius); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px; max-width: 100%;
}
.fail-head { display: flex; gap: 10px; align-items: flex-start; }
.fail-icon {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  background: var(--danger); color: #fff; font-weight: 700;
  display: grid; place-items: center; font-size: 13px;
}
.fail-title { font-weight: 600; }
.fail-why { color: var(--text); opacity: .85; }
.fail-detail { background: var(--card); padding: 8px 10px; border-radius: 10px; font-size: 12px; color: var(--muted); }

/* chat list: status badge on the avatar */
.face { position: relative; flex: none; display: inline-flex; }
.badge {
  position: absolute; right: -2px; bottom: -2px;
  min-width: 14px; height: 14px; border-radius: 999px;
  border: 2px solid var(--side); box-sizing: content-box;
  font-size: 10px; font-weight: 800; line-height: 14px; text-align: center; color: #fff;
}
.bot-row.sel .badge { border-color: var(--card); }
.badge.st-idle { background: var(--side); box-shadow: inset 0 0 0 2px var(--muted); width: 10px; min-width: 10px; height: 10px; }
.badge.st-working { background: var(--info); animation: pulse 1.2s infinite; }
.badge.st-approval { background: var(--warn); color: var(--bg); }
.badge.st-failed { background: var(--danger); color: var(--bg); }
.preview.st-failed { color: var(--danger); }
.preview.st-approval { color: var(--warn); }
.preview.st-working { color: var(--info); }

/* ---------- chat: day breaks, jump, quick prompts, Bot links ---------- */
.chat { position: relative; }
.day { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; font-weight: 600; margin: 6px 0; }
.day::before, .day::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.jump {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(128px + env(safe-area-inset-bottom)); z-index: 5;
  background: var(--text); color: var(--bg); border: 0; font-size: 13px;
  box-shadow: 0 4px 14px rgb(0 0 0 / .2);
}
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 max(16px, calc((100% - 880px) / 2)) 8px; }
.chip-btn { font-size: 13px; padding: 5px 12px; }
.chip-btn:hover { background: var(--bubble); }
.bot-link { color: inherit; font-weight: 600; text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 2px; }
.bot-link:hover { color: var(--accent); }

/* ---------- sidebar: rows, footer menu, health pill ---------- */
.bot-meta { flex: 1; }
.side-bottom { position: relative; gap: 8px; }
.menu-wrap { position: relative; }
.me { border: 0; background: none; font-weight: 600; padding: 6px 8px; border-radius: 10px; }
.me:hover { background: var(--line); }
.menu-bg { position: fixed; inset: 0; z-index: 24; }
.menu {
  position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 25; min-width: 170px;
  display: flex; flex-direction: column; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgb(0 0 0 / .2);
}
.menu.right { left: auto; right: 0; top: calc(100% + 6px); bottom: auto; }
.menu button { border: 0; border-radius: 8px; text-align: left; background: none; padding: 8px 10px; }
.menu button:hover { background: var(--bubble); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; width: 100%; }
.health-pill { display: inline-flex; align-items: center; padding: 4px 10px; font-size: 13px; }
.health-pill .dot { margin-right: 6px; }
.health-pill > .dot:not(.ok):not(.warn):not(.fail) { background: var(--muted); }

/* ---------- profile: collapse, more menu, tiles, confirm ---------- */
.profile { position: relative; }
.collapse { position: absolute; z-index: 2; top: 10px; left: 8px; border: 0; background: none; font-size: 18px; color: var(--muted); }
.prof-head { position: relative; }
.prof-more { position: absolute; z-index: 2; top: -8px; right: -4px; }
.prof-more > .icon { border: 0; background: none; font-size: 20px; }
@media (min-width: 1101px) {
  .layout.no-profile { grid-template-columns: 280px 1fr; }
  .layout.no-profile .profile { display: none; }
  .layout.no-profile .chat-head .info { visibility: visible; }
}
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 4px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; min-width: 0; }
.tile-v { font-size: 17px; font-weight: 700; line-height: 1.2; }
.tile-k { font-size: 12px; color: var(--muted); }
.tile-sub { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.tile-bad { font-size: 12px; font-weight: 600; color: var(--danger); background: var(--bad-bg); border: 0; border-radius: 999px; padding: 0 8px; margin-top: 2px; display: inline-block; }
button.tile-bad { cursor: pointer; text-decoration: underline; }
.seg button { min-width: 36px; }
.modal.confirm { width: min(420px, 100%); display: flex; flex-direction: column; gap: 8px; }
.modal.confirm ul { margin: 0; padding-left: 20px; }
.modal.confirm .lose li::marker { color: var(--danger); }
.row.end { justify-content: flex-end; margin-top: 6px; }
button.danger-fill { background: var(--danger); color: var(--bg); border-color: var(--danger); }
