/*
 * The theme tokens. These twenty-nine are the ONLY colours in this file — a
 * hardcoded hex below this block is a bug, because it would survive a theme
 * change and leave one element in the old palette.
 *
 * The values are the "dark" preset, i.e. exactly what the app looked like before
 * themes existed. That is deliberate: theme.js overwrites them from GET /themes
 * at runtime, so a failed fetch, a slow network or a first paint all fall back to
 * a palette that is known to be readable rather than to nothing.
 *
 * EVERY property theme.js writes must be declared here, and vice versa. That is
 * not a style rule, it is what makes the fallback a palette at all: a var()
 * pointing at an undeclared custom property resolves to nothing, so the rule
 * falls back to its INITIAL value — a transparent background, a border-width of
 * none. This block was left on the old vocabulary (--panel-2, --line, --on-ok,
 * --ok, --warn, --rec, --user-bg, --user-line) when the rules below were renamed
 * in 1.1.32, so until theme.js painted, and forever on a failed fetch, and on the
 * LOGIN page (which is shown before enterApp() fetches the palette), voiceover had
 * no readable palette at all. ThemeTokenWiringTest now pins the two lists together.
 *
 * Keep this list in step with service/Themes.TOKENS (the server) and
 * voiceover/theme.js (the applier). ADR 0004 forbids a shared module, so the
 * names are duplicated on purpose; the values are not.
 *
 * Shadows and modal backdrops stay literal below: they are not theme colours, and
 * a shadow mixed from a palette is a shadow that changes weight with the theme.
 */
:root {
  /* surfaces — what things are painted ON */
  --bg: #0e0f13;
  --panel: #171922;
  --panel-selected: #1e2130;
  --outline: #2a2e3f;
  --outline-selected: #3f4661;
  /* a FILLED error surface; distinct from --destructive (controls that destroy)
     and from --danger-bg (the soft tint behind an error message). Created and
     deliberately unwired — "will use it later" (00001983). */
  --error-surface: #7a2230;
  --destructive: #ff4d5e;
  --danger-bg: #4a1c22;
  --accent: #7c5cff;
  --action: #3d7bff;
  /* text */
  --fg: #e8eaf2;
  --muted: #8b90a6;
  --on-accent: #ffffff;
  --highlighted-text: #062a1c;
  /* the red WORD of a destructive control (000019BB). Declared because
     ThemeTokenWiringTest pins this block to the server's token list; voiceover does
     not USE it yet — its danger labels keep --destructive, out of scope on purpose. */
  --danger-text: #ff4d5e;
  /* status */
  --status-ok: #3ddc97;
  --status-busy: #ffb347;
  --status-error: #ff4d5e;
  /* progress bars — the five-step ramp, identical in every preset and chosen by
     the thresholds in app.js: 0 / 66 / 80 / 90 / 99 */
  --progress-default: #008800;
  --progress-alert: #448800;
  --progress-warning: #888800;
  --progress-danger: #884400;
  --progress-panic: #ff0000;
  /* chat */
  --user-bubble: #2a2350;
  --user-bubble-border: #3b3170;
  --agent-bubble: #1e2130;
  --agent-bubble-border: #2a2e3f;
  --tool-outline: #2a2e3f;
  --tool-failure-outline: #880000;
  --code-bg: #12141c;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  /* Geometry shared by the status row and the title row, so the single bead
     below can be the SAME width as the seven cells above without either row
     knowing the other's pixel widths. --cell-count must match the number of
     .cell elements inside #cells; the media query below narrows the gap. */
  --cell-gap: 4px;
  --cell-count: 7;
}

* { box-sizing: border-box; }

/* #drawer, #player and #recinfo each set `display`, which beats the UA
   [hidden] rule on specificity — so restate it. */
[hidden] { display: none !important; }

/* The document is NEVER a scroller. The shell is a fixed-height flex column and
   #messages is the only thing that scrolls. Letting the document scroll too
   created a second scroller whose range was exactly the browser chrome, and a
   gesture that ran past the end of #messages chained into it and panned the
   header off the top of the screen (0000154D). */
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  /* dvh is the LAYOUT viewport: on a phone it INCLUDES the strip the browser
     chrome covers, so the shell was taller than what the user can see and the
     composer landed below the visible edge. svh is the SMALLEST viewport
     (chrome at its largest), so the shell always fits on screen. dvh stays
     first as the fallback for browsers that do not know svh. */
  height: 100dvh;
  height: 100svh;
  padding-top: var(--safe-t);
}

button {
  font: inherit;
  color: inherit;
  background: var(--panel-selected);
  border: 1px solid var(--outline);
  border-radius: 12px;
  cursor: pointer;
}

button:disabled { opacity: .35; cursor: default; }

/* ── status bar (top half of the header's right-hand cell) ──── */

#statusbar {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 4px 6px;
  font-size: 12px;
}

#cells { display: flex; gap: var(--cell-gap); }

.cell {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px 3px;
  border-radius: 8px;
  background: var(--outline);
  color: var(--muted);
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  transition: background .15s, color .15s;
}

/* Seven cells next to a square menu button (as wide as the bar is tall) is
   tight on a 360px phone. Shrink the labels instead of letting them wrap or
   clip. */
/* Narrowing the gap is a custom-property change, not a #cells change: the title
   row's bead derives its width from the same two numbers, and it must stay
   exactly as wide as the cells above it at every screen size. */
@media (max-width: 420px) {
  :root { --cell-gap: 3px; }
  .cell { padding: 5px 2px; font-size: 10px; letter-spacing: 0; }
}

.cell.on {
  background: var(--accent);
  color: var(--on-accent);
}

.cell.idle {
  background: var(--status-ok);
  color: var(--highlighted-text);
}

.cell.busy {
  background: var(--status-busy);
  color: var(--on-accent);
}

.cell.err {
  background: var(--danger-bg);
  color: var(--status-error);
}

/* ── top bar ────────────────────────────────────────────────── */

/* Row: [ menu button: full height, square ][ right-hand cell: the rest ].
   The right-hand cell is a COLUMN — status bar on top, title at the bottom.
   Nothing is side by side inside it. */
#topbar {
  display: flex;
  align-items: stretch;
  background: var(--panel);
  border-bottom: 1px solid var(--outline);
}

/* Square, not a slab. The height comes from the stretched row (as it always
   did); aspect-ratio makes the width follow it instead of a fixed 44px. Note
   the failure mode is benign: if aspect-ratio did not resolve, the width falls
   back to the .icon min-width of 44px, i.e. exactly the old behaviour. */
#btn-drawer {
  flex: 0 0 auto;
  aspect-ratio: 1 / 1;
  align-self: stretch;
  border: none;
  border-right: 1px solid var(--outline);
  border-radius: 0;
  background: transparent;
}

#topright {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Title row: the title takes what is left, the bead keeps its share. The row's
   horizontal padding matches #statusbar's (6px), which is what makes the bead's
   100% the same 100% the cells above are laid out in. */
#titlerow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 6px 6px;
}

#conv-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0 0 0 2px;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The one bead in the title row (00001587). Width is derived, not guessed:
   seven flex:1 cells separated by six gaps each come out as this exact value,
   and the bead is `flex: 0 0 auto` so it keeps it instead of growing. The plain
   44px above it is the fallback if calc() or the custom properties do not
   resolve — the bead then looks slightly off but still fits. */
#cell-audio {
  flex: 0 0 auto;
  width: 44px;
  width: calc((100% - (var(--cell-count) - 1) * var(--cell-gap)) / var(--cell-count));
  /* A .cell is a span above; this one is a button, so the platform chrome,
     the font and the focus ring have to be dealt with explicitly. */
  border: none;
  appearance: none;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
}

/* Lit = message audio is ON, i.e. the next turn will be spoken. That is the
   state the user asked to see at a glance, and it is the SAME class the cells
   above use — one meaning for "on" in this header, not two. aria-pressed says
   the same thing to a screen reader. */

/* Green, not accent: "something is coming out of the speaker right now" is a
   different fact from "audio will be generated", and the bead has to be able
   to say both. An id rule beats .cell.on, so no !important is needed. */
#cell-audio.playing {
  background: var(--status-ok);
  color: var(--highlighted-text);
}

.icon {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

/* ── context usage bar ──────────────────────────────────────── */

/* Sits between the title bar and the conversation panel. The 3px is always
   reserved (flex-basis), so showing or emptying the fill never shifts the
   layout below it. */
#context-bar {
  flex: 0 0 3px;
  width: 100%;
  height: 3px;
  background: var(--outline);
  overflow: hidden;
}

#context-bar-fill {
  width: 0;
  height: 100%;
  background: var(--progress-default);
  transition: width .25s ease, background .25s ease;
}

/* The five-step ramp (00001983): 0 default, 66 alert, 80 warning, 90 danger,
   99 panic. Lower bounds, and the numbers live in app.js — this is only the
   paint. Same five tokens as webdesk's two context bars, so the fronts cannot
   disagree about what "nearly full" looks like. */
#context-bar-fill.p-panic { background: var(--progress-panic); }
#context-bar-fill.p-danger { background: var(--progress-danger); }
#context-bar-fill.p-warning { background: var(--progress-warning); }
#context-bar-fill.p-alert { background: var(--progress-alert); }
#context-bar-fill.p-default { background: var(--progress-default); }

/* ── panel B: messages ──────────────────────────────────────── */

#messages {
  flex: 1;
  overflow-y: auto;
  /* Belt and braces next to the html/body overflow:hidden above: a gesture that
     reaches the end of this list must not chain to any ancestor scroller. */
  overscroll-behavior: contain;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  position: relative;
  max-width: 85%;
  padding: 8px 12px;
  /* Room for the ⋮ button in the top-right corner. Costs text width on every
     bubble — the price of a real tap target on a phone. */
  padding-right: 44px;
  border-radius: 14px;
  background: var(--panel-selected);
  border: 1px solid var(--outline);
  white-space: pre-wrap;
  word-break: break-word;
  /* A giant unbroken token (a base64 blob, a minified stack trace) must wrap
     instead of stretching the bubble past the viewport. Text is never
     truncated: it wraps, and the panel scrolls. */
  overflow-wrap: anywhere;
}

.msg.user      { align-self: flex-end; background: var(--user-bubble); border-color: var(--user-bubble-border); }
/* The agent's own two tokens (00001983): same values as --panel-selected /
   --outline in every preset, configurable separately, so a palette can lift the
   agent's side of the conversation without moving every panel in the app. */
.msg.assistant { align-self: flex-start; background: var(--agent-bubble); border-color: var(--agent-bubble-border); }
.msg.tool      { align-self: flex-start; font-size: 13px; color: var(--muted); background: transparent; border-color: var(--tool-outline); }
/* Tool outcome: slight green on success, slight red on failure. Muted on
   purpose — this is a hint, not an alarm. The tint is the accent colour at
   reduced opacity, so it follows the theme instead of pinning a green. */
.msg.tool.ok   { color: var(--status-ok); opacity: .8; }
.msg.tool.err  { color: var(--status-error); opacity: .8; }

/* A tool call that has fired but not returned yet. Same geometry as a settled
   tool row — only the opacity moves — so the row does not jump when the result
   lands. */
.msg.tool.pending {
  font-style: italic;
  animation: tool-pulse 1.4s ease-in-out infinite;
}

@keyframes tool-pulse {
  0%, 100% { opacity: .4; }
  50%      { opacity: .85; }
}
.msg.system    { align-self: center; font-size: 13px; color: var(--muted); background: transparent; }

/* A failed turn, persisted as a message. Full width and tinted red so it reads
   as an event in the conversation, not as a reply. Never selectable, no audio. */
.msg.error {
  align-self: stretch;
  max-width: 100%;
  /* Derived from --rec rather than a stored tint: an 8% wash has to be an 8%
     wash of THIS palette's red, or a light theme gets a pink block. */
  background: color-mix(in srgb, var(--status-error) 8%, transparent);
  border-color: color-mix(in srgb, var(--status-error) 40%, transparent);
  border-left: 3px solid var(--status-error);
}

.msg.error .msg-author {
  margin-bottom: 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

.msg .empty-note { font-style: italic; color: var(--muted); }

/* ── markdown inside a message bubble ──────────────────────── */

/* .msg is pre-wrap for plain text. A rendered bubble is built from block
   elements with explicit <br>s, so pre-wrap would double every newline. */
.msg .md { white-space: normal; }

/* No leading gap above the first block, no trailing gap below the last one —
   the bubble's own padding is the frame. */
.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: 12px 0 6px;
  line-height: 1.25;
  font-weight: 700;
}
.msg .md h1 { font-size: 19px; }
.msg .md h2 { font-size: 17px; }
.msg .md h3 { font-size: 16px; }
.msg .md h4, .msg .md h5, .msg .md h6 { font-size: 15px; }

.msg .md ul, .msg .md ol { margin: 0 0 8px; padding-left: 22px; }
.msg .md li { margin: 2px 0; }

.msg .md blockquote {
  margin: 0 0 8px;
  padding: 2px 0 2px 10px;
  border-left: 3px solid var(--outline);
  color: var(--muted);
}

.msg .md hr {
  margin: 10px 0;
  border: none;
  border-top: 1px solid var(--outline);
}

.msg .md a { color: var(--accent); text-decoration: underline; }

.msg .md code {
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--code-bg);
  border-radius: 5px;
}

/* A fenced block scrolls sideways instead of wrapping: code that reflows is
   code you cannot read. */
.msg .md pre {
  margin: 0 0 8px;
  padding: 10px 12px;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--outline);
  border-radius: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg .md pre code {
  padding: 0;
  background: none;
  border-radius: 0;
  white-space: pre;
  /* The .msg overflow-wrap: anywhere rule must not break code lines. */
  overflow-wrap: normal;
}

.msg .play-mini {
  margin-top: 6px;
  padding: 8px 14px;
  font-size: 14px;
  border-radius: 999px;
  min-height: 40px;
}

.msg.selectable { cursor: pointer; }

.msg.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* ── per-message menu ──────────────────────────────────────── */

/* The trigger lives inside the bubble so it scrolls with the row. */
.msg-menu-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--muted);
}

.msg-menu-btn:active { background: var(--panel); }

/* One shared popup, positioned by JS on open. Used by the per-message ⋮ and by
   the drawer row's ⋮. */
#menu {
  position: fixed;
  min-width: 190px;
  padding: 4px;
  background: var(--panel-selected);
  border: 1px solid var(--outline);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .55);
  z-index: 25;
}

/* ── tool call details ─────────────────────────────────────── */

/* A centered modal, not a bottom sheet. The tool result is something you read
   and dismiss, not something you swipe up from the edge — and centering keeps
   it clear of the composer and the safe area. */
#msg-detail {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .6);
  z-index: 32;
}

.detail-inner {
  /* 12px gutter on each side on a phone, 640px cap on a wide screen. */
  width: min(calc(100% - 24px), 640px);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--outline);
  border-radius: 16px;
}

#msg-detail-body {
  overflow-y: auto;
  padding: 12px;
  -webkit-overflow-scrolling: touch;
}

.detail-field { margin-bottom: 12px; }
.detail-field:last-child { margin-bottom: 0; }

.detail-label {
  margin-bottom: 2px;
  font-size: 12px;
  color: var(--muted);
}

.detail-value {
  padding: 8px 10px;
  font-size: 13px;
  background: var(--panel-selected);
  border: 1px solid var(--outline);
  border-radius: 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ── quick panel ───────────────────────────────────────────── */

/* Opened from the drawer head, so it has to cover the drawer (20) and the
   shared #menu (25), and stay under settings (30). The drawer is left open
   behind it on purpose: closing the card puts you back in the list, not at the
   top of the app. */
#quick {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .6);
  z-index: 28;
}

.quick-inner {
  width: min(calc(100% - 24px), 420px);
  background: var(--panel);
  border: 1px solid var(--outline);
  border-radius: 16px;
  overflow: hidden;
}

.quick-body { padding: 12px; }

/* A row is a button (the toggle) or an anchor (webdesk), so both get the same
   box and the same reset. */
.quick-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 0 14px;
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  color: var(--fg);
  background: var(--panel-selected);
  border: 1px solid var(--outline);
  border-radius: 12px;
}

.quick-row:last-child { margin-bottom: 0; }
.quick-row:active { background: var(--panel); }

/* The state is a word, not a colour alone: "on"/"off" needs no legend. */
.quick-state { font-size: 14px; font-weight: 400; color: var(--muted); }
.quick-row[aria-pressed='true'] .quick-state { color: var(--status-ok); }

/* ── landing ──────────────────────────────────────────────── */

#landing {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.landing-inner {
  text-align: center;
  max-width: 340px;
  width: 100%;
}

.landing-inner h2 { margin: 0 0 8px; font-size: 24px; }

.landing-inner p { color: var(--muted); margin: 0 0 20px; }

.landing-btn {
  width: 100%;
  min-height: 56px;
  padding: 0 24px;
  font-size: 16px;
  font-weight: 600;
  background: var(--action);
  border-color: var(--action);
  color: var(--on-accent);
}

/* ── panel C: playback ──────────────────────────────────────── */

#player {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--outline);
  background: var(--panel);
}

#player audio { display: none; }

#nowplaying {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#transport { display: flex; gap: 8px; }
#transport .icon { flex: 1; min-height: 56px; font-size: 22px; }

/* ── panel A: controls ──────────────────────────────────────── */

#controls {
  padding: 10px 12px calc(10px + var(--safe-b));
  border-top: 1px solid var(--outline);
  background: var(--panel);
}

#recinfo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

#reclen { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 44px; }
#recplay { flex: 1; height: 34px; }

#btnrow { display: flex; gap: 10px; }

.big {
  flex: 1;
  height: 76px;
  font-size: 30px;
  border-radius: 18px;
}

.big.rec { color: var(--status-error); }

/* OK / send / discard — clearly visible (bluish) when enabled. The tint is the
   action colour mixed into the panel, so it follows the theme; if color-mix is
   unavailable the declaration is dropped and the button keeps its plain
   background, which is a readable fallback rather than a broken one. */
.big.action:not(:disabled) {
  background: color-mix(in srgb, var(--action) 22%, var(--panel-selected));
  border-color: var(--action);
  color: var(--fg);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--action) 40%, transparent);
}

/* The send button becomes a stop button while a turn runs. Same element, same
   slot — no layout shift. The ID selector beats .big.action:not(:disabled), so
   no !important is needed. */
#btn-send.stop:not(:disabled) {
  background: var(--danger-bg);
  border-color: var(--destructive);
  color: var(--fg);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--destructive) 40%, transparent);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .02em;
}

/* "stopping…" is a word, not a glyph, so it needs a smaller size to fit the
   button. Disabled, so the bluish action rule does not apply. */
#btn-send.stopping {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
}

#textform { display: flex; gap: 8px; margin-top: 10px; }

#textinput {
  flex: 1;
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  color: var(--fg);
  background: var(--panel-selected);
  border: 1px solid var(--outline);
  border-radius: 12px;
}

#textform button { padding: 0 16px; }

/* ── panel D: drawer ────────────────────────────────────────── */

#drawer {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(88vw, 380px);
  background: var(--panel);
  border-right: 1px solid var(--outline);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
  z-index: 20;
  box-shadow: 0 0 40px rgba(0, 0, 0, .6);
}

.drawer-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--outline);
}

/* The head's text column: app name + version above the "Menu" caption. */
.drawer-title { flex: 1; min-width: 0; }

.drawer-head h2 { margin: 0; font-size: 15px; }

/* "Kairos v1.0.24" — filled by loadVersion(). :empty keeps the caption
   from shifting when the fetch has not landed (or failed). */
.app-line {
  margin: 0 0 2px;
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-line:empty { display: none; }

.drawer-head .icon { min-width: 56px; min-height: 56px; font-size: 22px; }

/* The drawer head's sliders button. Hand-rolled inline SVG: no icon font, no
   CDN, no licence to read. Two rails with offset knobs — three rails would read
   as the ≡ that already sits in the topbar. */
.ico-sliders { width: 18px; height: 18px; display: block; }
.ico-sliders line { stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.ico-sliders circle { fill: currentColor; }

.drawer-new { display: flex; gap: 8px; padding: 10px 12px; }

#btn-create { min-height: 56px; padding: 0 20px; font-size: 16px; font-weight: 600; }

#agent-select {
  flex: 1;
  min-height: 44px;
  padding: 0 10px;
  font: inherit;
  color: var(--fg);
  background: var(--panel-selected);
  border: 1px solid var(--outline);
  border-radius: 12px;
}

#convlist {
  list-style: none;
  margin: 0;
  padding: 0 12px calc(12px + var(--safe-b));
  overflow-y: auto;
  flex: 1;
}

#convlist li { display: flex; gap: 6px; align-items: stretch; margin-bottom: 8px; }

/* min-width: 0 is load-bearing: this button is a flex item, and a flex item
   defaults to min-width: auto — it refuses to shrink below its content, so a
   long nowrap title stretched the whole row past the drawer instead of
   ellipsizing. webdesk carries the same rule on .conv-open. */
#convlist li > button:first-child {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  text-align: left;
}

#convlist li.active > button:first-child { border-color: var(--accent); }

#convlist .t {
  font-weight: 600;
  font-size: 15px;
  display: block;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#convlist .t.empty { font-style: italic; color: var(--muted); font-weight: 400; }
#convlist .p { font-size: 12px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* The row's ⋮ — the only thing between the name and the edge of the drawer. */
#convlist .more {
  width: 44px;
  flex: 0 0 44px;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: none;
}

#convlist .more:active { background: var(--panel-selected); }

/* Inline rename: the input takes the name button's place, the ⋮ stays put. */
#convlist .rename {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 10px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  background: var(--panel-selected);
  border: 1px solid var(--accent);
  border-radius: 12px;
  outline: none;
}

/* ── settings ──────────────────────────────────────────────── */

#settings {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
}

#settings-nav,
#settings-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.set-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--outline);
}

.set-head h2 {
  flex: 1;
  margin: 0;
  font-size: 15px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.set-head .add {
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

/* nav index */

#settings-sections {
  list-style: none;
  margin: 0;
  padding: 12px;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#settings-sections .nav-cat-title {
  list-style: none;
  margin: 4px 0 8px;
  padding: 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

#settings-sections .nav-row { margin-bottom: 8px; }

#settings-sections .nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--outline);
  border-radius: 12px;
  text-align: left;
  font-size: 15px;
  font-weight: 600;
}

#settings-sections .nav-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#settings-sections .nav-count {
  color: var(--muted);
  font-weight: 400;
  font-size: 13px;
  flex-shrink: 0;
}

/* page body */

#page-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  -webkit-overflow-scrolling: touch;
}

.set-list { list-style: none; margin: 0; padding: 0; }

.set-list .set-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}

.set-list .item {
  flex: 1;
  text-align: left;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--outline);
  border-radius: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.set-list .sub {
  padding: 12px 14px;
  color: var(--accent);
  border-color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.set-list .del { width: 44px; min-height: 44px; }

.menu-wrap { position: relative; flex-shrink: 0; }

.menu-btn {
  width: 44px;
  min-height: 44px;
  font-size: 20px;
  line-height: 1;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 190px;
  background: var(--panel-selected);
  border: 1px solid var(--outline);
  border-radius: 12px;
  padding: 4px;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .55);
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  background: transparent;
  border: none;
  border-radius: 8px;
  font-size: 14px;
}

.menu-item:active { background: var(--panel); }

/* Destructive entry (delete). Painted with --destructive, not with the status red
   (00001983): an item that destroys something is not an error report. */
.menu-item.danger { color: var(--destructive); }

.set-list .item-static {
  flex: 1;
  padding: 12px 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.set-list .tool-row {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--outline);
  border-radius: 12px;
}
.set-list .t { font-weight: 600; font-size: 14px; }
.set-list .p { font-size: 12px; color: var(--muted); }

/* Group heading inside a list (e.g. inbuilt vs server tools). */
.set-list .tool-group {
  margin: 12px 0 8px;
  padding: 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.set-list .tool-group:first-child { margin-top: 0; }

/* Read-only marker on a row (the inbuilt tool server). */
.set-list .badge {
  flex-shrink: 0;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--outline);
  background: var(--panel-selected);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* form page */

.set-form-page { display: flex; flex-direction: column; }

.fld { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.fld-label { font-size: 12px; color: var(--muted); }

/* Group heading inside a form (e.g. connect vs request timeouts). Rendered by
   the 'group' pseudo-field type in renderForm. */
.fld-group {
  margin: 4px 0 10px;
  padding: 0 2px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.fld-group:first-child { margin-top: 0; }

.fld input, .fld select, .fld textarea {
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  color: var(--fg);
  background: var(--panel-selected);
  border: 1px solid var(--outline);
  border-radius: 10px;
}

.fld textarea { padding: 10px 12px; resize: vertical; }

/* A colour input is a swatch, not a text box: the shared 44px min-height and the
   12px horizontal padding would squeeze the swatch down to a sliver. */
.fld input[type='color'] {
  padding: 2px 4px;
  cursor: pointer;
}

/* Palette preview on a theme row: four chips of the colours that matter at a
   glance. Decorative, so it carries no text and is not focusable. */
.theme-swatch {
  display: flex;
  flex-shrink: 0;
  border: 1px solid var(--outline);
  border-radius: 6px;
  overflow: hidden;
}
.theme-swatch span { display: block; width: 14px; height: 22px; }

.secret-wrap { display: flex; gap: 6px; }
.secret-wrap input { flex: 1; min-width: 0; }
.secret-toggle { padding: 0 12px; min-height: 44px; font-size: 13px; white-space: nowrap; }

.fld-actions { display: flex; gap: 8px; margin-top: 4px; }
.fld-actions button { flex: 1; min-height: 44px; }

.fld-actions .primary {
  background: var(--action);
  border-color: var(--action);
  color: var(--on-accent);
  font-weight: 600;
}

.tools-box { border: 1px solid var(--outline); border-radius: 10px; padding: 8px 10px; margin-bottom: 12px; }
.tools-box legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.tool-check { display: flex; gap: 8px; align-items: center; font-size: 13px; padding: 3px 0; }

.muted { color: var(--muted); font-size: 12px; display: block; margin: -4px 0 8px; }

/* ── login ──────────────────────────────────────────────────── */

#login {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: var(--safe-t);
}

.login-inner {
  width: 100%;
  max-width: 340px;
}

.login-inner h2 { margin: 0 0 8px; font-size: 24px; text-align: center; }
.login-inner p { color: var(--muted); margin: 0 0 20px; text-align: center; }
.login-inner .login-version { margin: -4px 0 16px; font-size: 13px; letter-spacing: .04em; }
.login-inner .login-version:empty { display: none; }

#login-form { display: flex; flex-direction: column; }

#login-form .primary {
  min-height: 56px;
  font-size: 16px;
  font-weight: 600;
  background: var(--action);
  border-color: var(--action);
  color: var(--on-accent);
}

.login-error {
  color: var(--status-error);
  font-size: 13px;
  margin: -4px 0 12px;
}

.reset-link {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
}

/* ── settings footer (danger actions) ─────────────────────── */

.set-foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--outline);
}

.set-foot .danger {
  min-height: 48px;
  background: var(--danger-bg);
  border: 1px solid var(--destructive);
  color: var(--fg);
  font-weight: 600;
}

/* ── toast ──────────────────────────────────────────────────── */

#toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-b));
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--danger-bg);
  border: 1px solid var(--status-error);
  color: var(--fg);
  font-size: 14px;
  z-index: 40;
}
