/* Shared design system for the agent web console (index.html + sse.html).
   Neutral-minimal: flat surfaces, hairline borders, one cyan accent, system
   font stacks. Theme is chosen by html[data-theme]; default (no attribute)
   is dark, "light" opts into the light palette. Every color lives in the
   token blocks below so a theme switch only swaps variable values. */

:root {
  color-scheme: dark;
  /* surfaces */
  --bg: #0c0e12;
  --surface: #12151a;        /* sidebar, footer, chrome bars */
  --surface-2: #171b21;      /* bubbles, cards */
  --surface-3: #1f242c;      /* inputs, chips, pressed states */
  --hover: rgba(255, 255, 255, 0.05);
  --composer: #1a1f27;
  --bubble-ai: var(--surface-2);
  --bubble-user: rgba(56, 189, 211, 0.13);
  --code-bg: #0a0d12;
  --backdrop: rgba(3, 5, 9, 0.55);
  /* lines */
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  /* text */
  --ink: #e7eaef;
  --soft: #b4bbc6;           /* secondary body text */
  --dim: #7e8691;            /* meta, labels, placeholders */
  --log: #7a8390;            /* log bodies, lowest readable tier */
  /* accent + semantic */
  --accent: #38bdd3;
  --accent-ink: #052830;     /* text on solid accent */
  --accent-hover: #4cc9de;
  --accent-soft: rgba(56, 189, 211, 0.12);
  --accent-border: rgba(56, 189, 211, 0.38);
  --focus: rgba(56, 189, 211, 0.22);
  --violet: #a78bfa;         /* tool-call category color */
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.09);
  --red-border: rgba(248, 113, 113, 0.35);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.08);
  --amber-border: rgba(251, 191, 36, 0.32);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.09);
  --green-border: rgba(52, 211, 153, 0.32);
  /* shadows: dark theme lifts with borders, not shadows */
  --shadow-soft: none;
  --shadow-pop: 0 8px 24px rgba(0, 0, 0, 0.45);
  /* type */
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --maxw: 880px;             /* centered content column width */
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --surface-3: #e8ecf1;
  --hover: rgba(15, 23, 42, 0.05);
  --composer: #ffffff;
  --bubble-ai: #ffffff;
  --bubble-user: rgba(14, 116, 144, 0.08);
  --code-bg: #f6f8fa;
  --backdrop: rgba(23, 32, 56, 0.3);
  --border: rgba(15, 23, 42, 0.09);
  --border-strong: rgba(15, 23, 42, 0.16);
  --ink: #1a2330;
  --soft: #424c5e;
  --dim: #707a8b;
  --log: #5d6675;
  --accent: #0e7490;
  --accent-ink: #ffffff;
  --accent-hover: #0b5d74;
  --accent-soft: rgba(14, 116, 144, 0.08);
  --accent-border: rgba(14, 116, 144, 0.32);
  --focus: rgba(14, 116, 144, 0.18);
  --violet: #7c3aed;
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.06);
  --red-border: rgba(220, 38, 38, 0.3);
  --amber: #b45309;
  --amber-soft: rgba(180, 83, 9, 0.07);
  --amber-border: rgba(180, 83, 9, 0.32);
  --green: #047857;
  --green-soft: rgba(4, 120, 87, 0.07);
  --green-border: rgba(4, 120, 87, 0.3);
  --shadow-soft: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-pop: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 28px rgba(16, 24, 40, 0.1);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--ink);
  height: 100vh;
  display: flex;
  flex-direction: row;
}
::selection { background: var(--accent-soft); }
button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Sidebar: connection controls, quick actions, session list ---- */
.sidebar {
  width: 264px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 2;
}
/* header row: title left, theme toggle pinned to the top-right corner */
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sidebar h1 {
  font-size: 13px;
  margin: 0;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 9px;
}
/* logo mark: a small rotated accent square */
.sidebar h1::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
  transform: rotate(45deg);
}
.nav-link {
  align-self: flex-start;
  font-size: 11.5px;
  font-family: var(--mono);
  color: var(--dim);
  text-decoration: none;
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  transition: color 0.15s, border-color 0.15s;
}
.nav-link:hover { color: var(--accent); border-color: var(--accent-border); }
.sidebar input[type="text"],
.sidebar input[type="password"] {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12.5px;
  font-family: var(--mono);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.sidebar input[type="text"]:focus,
.sidebar input[type="password"]:focus {
  outline: none;
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--focus);
}
#session {
  align-self: flex-start;
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.04em;
  color: var(--dim);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
#session.has-id { color: var(--accent); border-color: var(--accent-border); }
.side-btns { display: flex; gap: 8px; }
.side-btns button { flex: 1; }
.side-label {
  margin-top: 10px;
  font-size: 10.5px;
  color: var(--dim);
  font-family: var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
/* quick slash-command actions: quiet bordered buttons */
.side-cmd {
  text-align: left;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--soft);
  font-weight: 500;
  font-size: 12.5px;
}
.side-cmd:hover {
  background: var(--hover);
  border-color: var(--border-strong);
  color: var(--ink);
}
#sessionList { display: flex; flex-direction: column; gap: 6px; }
#sessionList:empty::before {
  content: "连接后自动加载，或点「刷新会话」";
  color: var(--dim);
  font-size: 11px;
  font-family: var(--mono);
  text-align: center;
  padding: 12px 8px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
}
.session-row {
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.session-row:hover { border-color: var(--border-strong); background: var(--hover); }
.session-head {
  font-size: 10.5px;
  color: var(--dim);
  font-family: var(--mono);
  letter-spacing: 0.03em;
}
.session-preview {
  font-size: 12px;
  color: var(--ink);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-del {
  float: right;
  border: none;
  background: none;
  color: var(--dim);
  font-size: 11px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.session-row:hover .session-del { opacity: 1; }
.session-del:hover { color: var(--red); }

/* ---- Right column: message log, trace/attach bars, composer, ctx bar ---- */
.right {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
/* mobile-only top bar with the drawer toggle; hidden on desktop */
.mobile-bar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
#menuBtn {
  width: 34px;
  height: 34px;
  padding: 0;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 15px;
}
#menuBtn:hover { background: var(--hover); }
.mobile-title {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
}
/* dim overlay behind the open drawer on mobile */
.side-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  z-index: 55;
}

/* ---- Buttons ---- */
button {
  padding: 7px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
button:hover { background: var(--accent-hover); }
button:disabled {
  background: var(--surface-3);
  color: var(--dim);
  cursor: not-allowed;
}
button.danger {
  background: transparent;
  border: 1px solid var(--red-border);
  color: var(--red);
}
button.danger:hover { background: var(--red-soft); }
button.danger:disabled {
  border-color: var(--border);
  color: var(--dim);
  background: transparent;
}

/* status pill with a state-colored beacon dot */
#status {
  align-self: flex-start;
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.06em;
  padding: 4px 11px 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--dim);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
#status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dim);
}
#status.connected {
  color: var(--green);
  border-color: var(--green-border);
  background: var(--green-soft);
}
#status.connected::before { background: var(--green); }
#status.connecting {
  color: var(--amber);
  border-color: var(--amber-border);
  background: var(--amber-soft);
}
#status.connecting::before {
  background: var(--amber);
  animation: pulse 1s ease-in-out infinite;
}

main {
  flex: 1;
  overflow-y: auto;
  /* center the chat column without touching the DOM: bubbles keep their
     left/right alignment inside an 880px measure */
  padding: 26px max(18px, calc((100% - var(--maxw)) / 2)) 34px;
  scroll-behavior: smooth;
}
/* empty-state placeholder, visible before the first message; the text itself
   is set per page (WebSocket vs SSE) in a small inline style block */
main:empty {
  display: flex;
  align-items: center;
  justify-content: center;
}
main:empty::before {
  color: var(--dim);
  font-size: 12.5px;
  font-family: var(--mono);
  letter-spacing: 0.08em;
  padding: 11px 22px;
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
}
main::-webkit-scrollbar, .msg .md pre::-webkit-scrollbar, .event .ev-pre::-webkit-scrollbar { width: 8px; height: 8px; }
main::-webkit-scrollbar-track, .msg .md pre::-webkit-scrollbar-track, .event .ev-pre::-webkit-scrollbar-track { background: transparent; }
main::-webkit-scrollbar-thumb, .msg .md pre::-webkit-scrollbar-thumb, .event .ev-pre::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
main::-webkit-scrollbar-thumb:hover { background: var(--dim); }

/* ---- Messages ---- */
.msg {
  max-width: 82%;
  margin: 12px 0;
  padding: 11px 15px;
  border-radius: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  animation: rise 0.22s cubic-bezier(0.2, 0.7, 0.3, 1);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
}
.msg.user {
  margin-left: auto;
  background: var(--bubble-user);
  color: var(--ink);
  border-bottom-right-radius: 5px;
}
.msg.assistant {
  margin-right: auto;
  background: var(--bubble-ai);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-soft);
}
/* system notices are plain centered text, no box */
.msg.system {
  margin: 12px auto;
  color: var(--dim);
  font-size: 12.5px;
  font-family: var(--mono);
  white-space: normal;
  text-align: center;
}
.msg.error {
  margin: 12px auto;
  background: var(--red-soft);
  border: 1px solid var(--red-border);
  color: var(--red);
  text-align: center;
  font-size: 13px;
}
.msg .meta {
  font-size: 11px;
  color: var(--dim);
  margin-bottom: 4px;
  font-family: var(--mono);
  letter-spacing: 0.03em;
}
.msg img, .msg .md img { max-width: 100%; border-radius: 10px; margin-top: 8px; display: block; }

/* Markdown body for assistant messages. .msg uses pre-wrap for plain text;
   rendered HTML needs normal white-space, with <pre> opting back into pre. */
.msg .md { white-space: normal; font-size: 14px; line-height: 1.6; }
.msg .md > :first-child { margin-top: 0; }
.msg .md > :last-child { margin-bottom: 0; }
.msg .md p { margin: 0 0 8px; }
.msg .md h1, .msg .md h2, .msg .md h3, .msg .md h4, .msg .md h5, .msg .md h6 {
  margin: 14px 0 6px; line-height: 1.3; font-weight: 600;
}
.msg .md h1 { font-size: 1.35em; }
.msg .md h2 { font-size: 1.2em; }
.msg .md h3 { font-size: 1.08em; }
.msg .md h4 { font-size: 1em; }
.msg .md ul, .msg .md ol { margin: 6px 0; padding-left: 22px; }
.msg .md li { margin: 2px 0; }
.msg .md li > ul, .msg .md li > ol { margin: 2px 0; }
.msg .md code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
}
.msg .md pre {
  margin: 10px 0;
  padding: 12px 14px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: 10px;
  overflow-x: auto;
  white-space: pre;
}
.msg .md pre code { background: none; border: none; padding: 0; color: inherit; font-size: 0.88em; }
.msg .md blockquote {
  margin: 8px 0; padding: 2px 14px;
  border-left: 2px solid var(--border-strong); color: var(--dim);
}
.msg .md a { color: var(--accent); text-decoration: none; }
.msg .md a:hover { text-decoration: underline; }
.msg .md hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.msg .md table { border-collapse: collapse; margin: 10px 0; display: block; overflow-x: auto; }
.msg .md th, .msg .md td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.msg .md th { background: var(--surface-2); }

/* ---- Grouped LLM/tool call logs ---- */
.call-group {
  margin: 7px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-family: var(--mono);
  animation: rise 0.22s cubic-bezier(0.2, 0.7, 0.3, 1);
}
.call-group.error { border-color: var(--red-border); }
.call-group-head {
  width: 100%; min-height: 36px; padding: 8px 12px;
  display: flex; align-items: center; gap: 9px;
  border: 0; border-radius: 0; background: transparent;
  color: var(--soft); font: inherit; cursor: pointer; text-align: left;
}
.call-group-head:hover { background: var(--hover); }
.call-group-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.call-group-title { font-size: 12px; font-weight: 600; }
.call-group-meta { margin-left: auto; color: var(--dim); font-size: 11px; white-space: nowrap; }
.call-group-arrow { color: var(--dim); transition: transform 0.15s; }
.call-group.open .call-group-arrow { transform: rotate(90deg); }
.call-group-body { display: none; border-top: 1px solid var(--border); }
.call-group.open .call-group-body { display: block; }

/* Each call is an unframed log row inside the single outer group. */
.event {
  margin: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  font-size: 12px;
  font-family: var(--mono);
  overflow: hidden;
}
.event + .event { border-top: 1px solid var(--border); }
.event.llm .ev-head { box-shadow: inset 2px 0 var(--accent); }
.event.tool .ev-head { box-shadow: inset 2px 0 var(--violet); }
.event.error .ev-head { box-shadow: inset 2px 0 var(--red); }
.event .ev-head {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; cursor: pointer; user-select: none; color: var(--soft);
  transition: background 0.15s;
}
.event .ev-head:hover { background: var(--hover); }
.event .ev-icon { font-style: normal; }
.event.llm .ev-icon { color: var(--accent); }
.event.tool .ev-icon { color: var(--violet); }
.event.error .ev-icon, .event.error .ev-title { color: var(--red); }
.event .ev-title { font-weight: 600; letter-spacing: 0.02em; }
.event .ev-meta { color: var(--dim); margin-left: auto; font-size: 11px; }
.event .ev-arrow { color: var(--dim); transition: transform 0.15s; }
.event.open .ev-arrow { transform: rotate(90deg); }
.event .ev-body {
  display: none; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--surface-2);
}
.event.open .ev-body { display: block; }
.event .ev-sec { margin-bottom: 8px; }
.event .ev-sec:last-child { margin-bottom: 0; }
.event .ev-label { color: var(--dim); font-size: 10.5px; margin-bottom: 3px; letter-spacing: 0.08em; }
.event .ev-pre {
  white-space: pre-wrap; word-break: break-word; color: var(--log);
  max-height: 320px; overflow: auto;
}
.event .ev-trunc { color: var(--amber); font-size: 11px; margin-bottom: 6px; }
.event .ev-err { color: var(--red); }

.msg .dl {
  margin-top: 8px; font-size: 12px; font-family: var(--mono);
  color: var(--accent); cursor: pointer; user-select: none;
}
.msg .dl:hover { text-decoration: underline; }
/* Produced-file attachments: images render inline (click to open full-size),
   other files render as download links. Used in assistant bubbles and event cards. */
.artifacts { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.artifact-img { max-width: 100%; max-height: 360px; border-radius: 10px; cursor: zoom-in; display: block; }
.artifact-file { font-size: 12px; font-family: var(--mono); color: var(--accent); text-decoration: none; }
.artifact-file:hover { text-decoration: underline; }

/* ---- Shell-command confirm card ---- */
.msg.confirm {
  margin: 12px 0;
  background: var(--amber-soft);
  border: 1px solid var(--amber-border);
  border-radius: 12px;
  padding: 14px 18px;
}
.msg.confirm .confirm-title {
  font-weight: 600;
  color: var(--amber);
  margin-bottom: 8px;
}
.msg.confirm .confirm-cmd {
  font-family: var(--mono);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 13px;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-all;
}
.msg.confirm .confirm-buttons {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}
.msg.confirm .confirm-buttons button { flex: 1; }
.msg.confirm .confirm-buttons .deny {
  background: transparent;
  border: 1px solid var(--red-border);
  color: var(--red);
}
.msg.confirm .confirm-buttons .deny:hover { background: var(--red-soft); }
.msg.confirm.resolved .confirm-buttons { display: none; }
.msg.confirm .confirm-result {
  display: none;
  font-size: 12px;
  margin-top: 8px;
  font-weight: 600;
  font-family: var(--mono);
}
.msg.confirm.resolved .confirm-result { display: block; }
.msg.confirm.resolved.approved .confirm-result { color: var(--green); }
.msg.confirm.resolved.denied .confirm-result { color: var(--red); }

/* ---- Composer / footer / unified status bar ---- */
footer {
  position: relative;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px max(18px, calc((100% - var(--maxw)) / 2)) 14px;
}
/* unified composer: attach button, textarea and send live in one pill
   that lights up as a whole on focus */
.composer {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  background: var(--composer);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 7px 8px;
  box-shadow: var(--shadow-soft);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--focus);
}
footer textarea {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 8px 6px;
  font-size: 14px;
  line-height: 1.45;
  font-family: inherit;
  min-height: 36px;
  max-height: 120px;
}
footer textarea::placeholder { color: var(--dim); }
footer textarea:focus { outline: none; }
#attachBtn {
  width: 36px;
  height: 36px;
  padding: 0;
  flex-shrink: 0;
  border-radius: 10px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--dim);
  font-size: 16px;
}
#attachBtn:hover {
  background: var(--hover);
  color: var(--ink);
}
#send {
  height: 36px;
  padding: 0 18px;
  flex-shrink: 0;
  border-radius: 10px;
}
/* unified status bar: turn trace on the left (amber with a pulsing dot while
   a turn runs, dim counts once done), context-token usage on the right.
   Replaces the old stacked traceBar + ctxBar pair — one hairline, not two. */
#statusBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px max(18px, calc((100% - var(--maxw)) / 2)) 8px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--dim);
  font-family: var(--mono);
  letter-spacing: 0.04em;
  user-select: none;
  transition: background 0.2s, border-color 0.2s;
}
#statusBar.active {
  background: var(--amber-soft);
  border-top-color: var(--amber-border);
  color: var(--amber);
}
#tracePart { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
#tracePart .dot {
  display: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  animation: pulse 1s ease-in-out infinite;
}
#statusBar.active #tracePart .dot { display: inline-block; }
/* usage gauge: a rounded track with a gradient fill, only shown once a
   context ceiling is configured (.on) */
#ctxGauge {
  display: none;
  width: 110px;
  height: 5px;
  margin-right: 10px;
  vertical-align: middle;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
#ctxGauge.on { display: inline-block; }
#ctxFill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--green));
  transition: width 0.35s ease, background 0.35s ease;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.7); }
}

/* attachment chips above the composer (index.html) */
#attachBar {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px max(18px, calc((100% - var(--maxw)) / 2));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
#attachBar.active { display: flex; }
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--ink);
}
.attach-chip img { width: 32px; height: 32px; object-fit: cover; border-radius: 5px; }
.attach-chip .rm { cursor: pointer; color: var(--red); font-weight: 600; margin-left: 2px; }

/* ---- "/" completion menu: floats above the composer ---- */
.complete-menu {
  position: fixed;
  display: none;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  font-family: var(--mono);
  font-size: 12.5px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 50;
  padding: 4px;
}
.cm-row { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.cm-row.sel { background: var(--accent-soft); }
.cm-name { color: var(--ink); font-weight: 600; }
.cm-row.sel .cm-name { color: var(--accent); }
.cm-desc { color: var(--dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm-kind { font-size: 10px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--border); color: var(--dim); flex-shrink: 0; }
.cm-kind.cm-command { color: var(--accent); border-color: var(--accent-border); }
.cm-kind.cm-skill { color: var(--violet); border-color: var(--violet); }
.cm-kind.cm-mcp { color: var(--amber); border-color: var(--amber-border); }
.cm-kind.cm-tool { color: var(--green); border-color: var(--green-border); }

/* theme toggle: a quiet pill matching .nav-link, pinned right in .side-head */
#themeBtn {
  padding: 4px 10px;
  font-size: 11.5px;
  font-family: var(--mono);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--dim);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
#themeBtn:hover {
  color: var(--accent);
  border-color: var(--accent-border);
  background: transparent;
}

/* Mobile: the sidebar collapses into a slide-in drawer behind a ☰ button */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(280px, 84vw);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 60;
    box-shadow: none;
  }
  .sidebar.open {
    transform: none;
    box-shadow: var(--shadow-pop);
  }
  .side-backdrop.active { display: block; }
  .mobile-bar { display: flex; }
  .msg { max-width: 94%; }
}
@media (prefers-reduced-motion: reduce) {
  .msg, .call-group { animation: none; }
  #statusBar .dot, #status.connecting::before { animation: none; }
  button, .session-row, .sidebar { transition: none; }
}

/* status bar thresholds: amber at 80% usage, red once the ceiling is hit */
#statusBar .warn { color: var(--amber); }
#statusBar .danger { color: var(--red); }
#ctxFill.warn { background: var(--amber); }
#ctxFill.danger { background: var(--red); }
