/*
 * 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 "light" preset, i.e. exactly what webdesk 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.
 *
 * Keep this list in step with service/Themes.TOKENS (the server) and
 * webdesk/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: #f7f7f8;
  --panel: #f0f0f1;
  --panel-selected: #ffffff;
  --outline: #e0e0e0;
  --outline-selected: #9aa0ab;
  /* a FILLED error surface; distinct from --destructive (controls that destroy)
     and from --danger-bg (the soft tint behind an error message) */
  --error-surface: #b00020;
  --destructive: #b00020;
  --danger-bg: #fdecea;
  --accent: #2563eb;
  --action: #2563eb;
  /* text */
  --fg: #1a1a1a;
  --muted: #666666;
  --on-accent: #ffffff;
  --highlighted-text: #ffffff;
  /* the red WORD of a destructive control (000019BB); the fill/border of the same
     control is --destructive. Same value as --destructive in every preset, so the
     default look is unchanged — the point is that they can be tuned apart. */
  --danger-text: #b00020;
  /* status */
  --status-ok: #1b6b45;
  --status-busy: #d97706;
  --status-error: #b00020;
  /* 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: #2563eb;
  --user-bubble-border: #2563eb;
  --agent-bubble: #ffffff;
  --agent-bubble-border: #e0e0e0;
  --tool-outline: #e0e0e0;
  --tool-failure-outline: #880000;
  --code-bg: #f7f7f8;
}

/* webdesk — desktop chat. Plain, no animations, no transitions. */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--fg);
  background: var(--bg);
}

#app { display: flex; height: 100vh; }

/* ── sidebar ─────────────────────────────────────────────── */

#sidebar {
  width: 260px;
  flex: 0 0 260px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--outline);
  background: var(--panel);
}

/* Row: app identity on the left, the voiceover link on the right. The foot is
   too narrow at 260px for a third button, and a switch between frontends is not
   a setting — it belongs in the head, always one click away. */
.side-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--outline);
}

/* "Kairos v1.0.24" — filled by loadVersion(). Replaces the old
   "webdesk" caption. :empty keeps the head from collapsing oddly before the
   fetch lands. */
.app-line {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-line:empty { display: none; }

/* margin-left:auto, not a flex spacer: when the app line is empty it is
   display:none, and the link still has to sit on the right. */
.side-link {
  margin-left: auto;
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
}
.side-link:hover { color: var(--fg); text-decoration: underline; }

.side-new { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--outline); }
.side-new button { white-space: nowrap; }

/* The agent picker: a native <select> dressed as one of our own controls. It
   used to be a bare UA widget — grey platform chrome in a themed sidebar — so
   it now takes the same border, radius, padding and surface as the buttons
   beside it and the form fields in settings.

   min-width:0 is load-bearing at both levels: this wrapper is a flex item of
   .side-new (default min-width:auto would refuse to shrink) and the select is a
   block inside it. Without them a long agent name widens the row and the "new
   chat" button wraps — the same 260px constraint that decided the placement in
   00001574. */
.agent-pick {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: block;
}

/* The right padding is the arrow's room, not decoration: the glyph is drawn on
   top of the control, so without it a long name runs underneath. */
.agent-pick select {
  width: 100%;
  min-width: 0;
  padding: 8px 30px 8px 10px;
  border: 1px solid var(--outline);
  border-radius: 6px;
  font: inherit;
  color: var(--fg);
  background: var(--panel-selected);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  text-overflow: ellipsis;
}

/* Keyboard focus only. Themed, so it survives a palette change; the UA ring is
   the platform's blue and would be the one thing in the sidebar that ignores
   the theme. */
.agent-pick select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* The chevron. A select cannot render a pseudo-element, so this is a sibling
   laid over it: pointer-events:none keeps every click going to the select. */
.agent-pick-arrow {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  font-size: 12px;
  line-height: 1;
  color: var(--muted);
  pointer-events: none;
}

/* ── quick links (sidebar) ──────────────────────────────────── */

/*
 * One chip per preset agent, between "new chat" and the conversation list.
 *
 * These are secondary to #btn-create, so they are chips rather than buttons, and
 * unlike the pin strip they MAY wrap onto several lines: the sidebar is the only
 * thing they can grow, and a horizontal scroller in a 260px column hides most of
 * the entries. Wrapping also cannot push anything else out of place here — the
 * list below is the flex member that absorbs the slack.
 *
 * Absent entirely when nothing is preset: no empty box, no heading.
 */
#quicklinks {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--outline);
}
#quicklinks[hidden] { display: none; }

.quick-link {
  padding: 4px 8px;
  border: 1px solid var(--outline);
  border-radius: 12px;
  background: var(--panel-selected);
  font-size: 12px;
  color: var(--fg);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quick-link:hover { border-color: var(--accent); color: var(--accent); }

/*
 * A quick link whose agent was deleted (0000198D).
 *
 * Muted and dashed, not red: nothing failed here — the agent behind the shortcut
 * is simply gone, and the row is KEPT on purpose so its caption, first message and
 * default folder survive. It is disabled, so a click cannot turn into a 404; the
 * way to repair it is Settings > Agents > Quick links, which the tooltip says.
 */
.quick-link.missing {
  color: var(--muted);
  border-style: dashed;
  cursor: default;
}
.quick-link.missing:hover { border-color: var(--outline); color: var(--muted); }

/* ── folders (drawer headings) ─────────────────────────────── */

/* One thin row above the list holding the only folder action there is. The
   headings themselves live inside #convlist (see the .folder rules below): one
   scroll container, one ordering, no second list to keep in step. */
#folders-bar {
  display: flex;
  /* Right-aligned since 000019C5: the row holds exactly one control now, and a
     single caption pinned to the left read as a heading for the list. */
  justify-content: flex-end;
  gap: 8px;
  padding: 0 12px 6px;
}

/* A text-weight button, because making a folder is a small, occasional act and
   should not compete with "new chat" for attention. */
.link-btn {
  padding: 2px 0;
  border: none;
  background: none;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.link-btn:hover { color: var(--accent); }

#convlist { flex: 1; overflow-y: auto; margin: 0; padding: 8px; list-style: none; }

/*
 * A folder heading. It is a conversation row's sibling, not its parent — the DOM
 * stays one flat <ul>, which is what keeps one scrollbar and lets a heading sit
 * between two groups of rows without nested lists.
 *
 * No hover wash and no cursor: a heading is not openable. Only its chevron (the
 * whole toggle button) and its ⋮ do anything.
 */
#convlist li.folder {
  display: flex;
  /*
   * stretch, and NO vertical padding (000019D1). The heading used to carry
   * `padding: 6px 10px 2px` with an `align-items:center` toggle inside, so of the
   * row's 46px only 17px was the actual button — the other 29px looked like a
   * heading and did nothing. Measured: toggle h=17 in an li h=46. The vertical
   * breathing room now lives INSIDE the toggle (below), which makes the whole
   * heading clickable except the ⋮.
   */
  align-items: stretch;
  gap: 4px;
  padding: 0 10px;
  cursor: default;
}
#convlist li.folder:hover { background: none; }

.folder-toggle {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  /* The heading's own spacing, moved off the li so it belongs to the click target. */
  padding: 6px 0 2px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  color: var(--muted);
}

/* A text glyph, not an image: no icon font, no CDN, no licence. */
.folder-chevron { flex: 0 0 auto; font-size: 10px; line-height: 1; color: var(--muted); }

.folder-name {
  min-width: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The count is a quiet badge, not a number to read — it says "there is something
   in here" while the folder is folded. */
.folder-count { flex: 0 0 auto; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Rows inside a folder are indented so the heading reads as their owner. A class
   rather than DOM nesting — see the .folder comment. */
#convlist li.in-folder { padding-left: 22px; }

#convlist li {
  display: flex;
  /*
   * stretch, and the row's vertical padding moved INTO .conv-open (000019D1).
   *
   * With `align-items:center` plus `padding: 8px 10px`, the hover wash covered a
   * box whose top and bottom 8px were not the open button — so the wash lit up
   * while the pointer was still in the gap, which is the "cursor does not line up
   * with the graphics" report. Measured: li h=55, .conv-open h=39. Now the painted
   * row IS the clickable row.
   */
  align-items: stretch;
  gap: 4px;
  padding: 0 10px;
  border-radius: 6px;
  cursor: pointer;
}
#convlist li.active { background: var(--outline); }
/* The hover wash is the line colour thinned into the panel, so it reads as
   "slightly lifted" on any palette. The plain declaration first is the fallback
   for a browser without color-mix: it is the old, slightly-too-strong wash. */
#convlist li:hover { background: var(--outline); }
#convlist li:hover { background: color-mix(in srgb, var(--outline) 55%, var(--panel)); }

/*
 * The pinned copies at the top of the list (00001981).
 *
 * Same row, same controls, one difference: a tint so it reads as "this one is
 * pinned" without becoming a different kind of widget. A tint of --accent into
 * --panel rather than a new token — the sidebar is --panel, so a --line wash would
 * be all but invisible against it, while a --panel-2 card would fight the active row.
 *
 * Declared AFTER the generic row and hover rules on purpose. `li.pinned` carries the
 * same specificity as `li:hover`, and `li.pinned:hover` / `li.pinned.active` carry
 * one class more — so the tint survives both a pointer passing over it and being the
 * open conversation, with no !important anywhere. The plain declaration comes first
 * as the fallback for a browser without color-mix.
 *
 * It carries no left border and no badge: the row is a shortcut, and an icon per row
 * in a 260px column is clutter for a fact the position already states.
 */
#convlist li.pinned { background: var(--outline); }
#convlist li.pinned { background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }
#convlist li.pinned.active { background: var(--outline); }
#convlist li.pinned.active { background: color-mix(in srgb, var(--accent) 26%, var(--panel)); }
#convlist li.pinned:hover { background: var(--outline); }
#convlist li.pinned:hover { background: color-mix(in srgb, var(--accent) 22%, var(--panel)); }

/* min-width:0 is load-bearing: .conv-open is a flex item inside #convlist li,
   and a flex item defaults to min-width:auto — it refuses to shrink below its
   content, so the ellipsis below would never fire. */
/*
 * The open button fills the row (000019D1): `align-self: stretch` from the li's
 * align-items, its own vertical padding instead of the li's, and a column so the two
 * lines stay centred. Its box is now the row's box, so the hover wash cannot extend
 * past the thing that responds to a click.
 */
.conv-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 0;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
}
.conv-open .t {
  display: block;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-open .p {
  display: block;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-open .empty { color: var(--muted); font-style: italic; }

/*
 * The ⋮ trigger (000019D1).
 *
 * It used to inherit the global `button { padding: 8px 14px }`, which made it a
 * 43x38 INVISIBLE slab: it inflated every row it sat in (measured: a folder heading
 * 46px tall for 17px of content, a conversation row 55px for 39px) and it gave the
 * glyph a click area five times its own size, so a click aimed at the text next to
 * it landed on the menu instead. Now it is a real 26px square, centred in the row.
 */
.more {
  flex: 0 0 auto;
  align-self: center;
  width: 26px;
  height: 26px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 4px;
  background: none;
  font-size: 16px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.more:hover { background: var(--outline); }

/* Mini status bar on the freshest conversation rows: a narrow vertical strip
   of three segments — busy, llm, tool — with the context strip to their LEFT
   (000019D8; it sat on the right between 00001982 and then). Segment 1 reads idle
   (green, --ok), working (amber, --warn), failed (solid red, --rec);
   llm/tool light with the accent. These mirror the
   main status bar's own cells exactly so the two bars never disagree. Amber and
   red are far enough apart to tell on a 6px strip, which is the whole point of
   not sharing one colour.

   The OFF state is --bg, not --line (00001982): the conversation surface and the
   composer's text area are --bg, so a dark segment on a 6px strip would read as
   data rather than as an empty track. --bg recedes into the sidebar and leaves the
   lit segments as the only thing with weight. Tinted surfaces follow the palette,
   so a custom sidebar colour moves this with it. */
.mini {
  flex: 0 0 6px;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 0;
}
.mini-seg { flex: 1; border-radius: 2px; background: var(--bg); }
.mini-seg.on { background: var(--accent); }
.mini-busy.idle { background: var(--status-ok); }
.mini-busy.busy { background: var(--status-busy); }
.mini-busy.err { background: var(--status-error); }

/* Context load, to the LEFT of those three segments (000019D8 — mirrored back, it
   spent a while on the right at 00001982): the same narrow column so the two read as
   one widget, filled TOP-DOWN, against the model's own context window.

   `justify-content: flex-start` is the whole of "fills top-down": the box is a flex
   column and the fill is a percentage HEIGHT, so the fill grows away from whichever
   end the column packs it to. `flex-end` was bottom-up; this is the mirror of it.
   Keep the fill a height on an inline style — `paintMiniCtx()` writes that, and it
   is what the browser test reads.

   Colours are the header bar's, token for token (.mini-ctx-fill reuses --accent /
   --warn / --rec and the 70 / 90 thresholds in app.js), so the two bars cannot
   disagree about what "getting tight" looks like.

   No transition: webdesk has none anywhere else, and this changes once per turn. */
.mini-ctx {
  flex: 0 0 6px;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 2px 0;
  border-radius: 2px;
  background: var(--bg);
  overflow: hidden;
}

/* Unknown window, or a total the server has not measured yet: NO track at all.
   An empty track would read as "no context used", and inventing a denominator to
   avoid that would be worse — the header bar takes the same line. */
.mini-ctx.unknown { background: none; }

.mini-ctx-fill {
  width: 100%;
  height: 0;
  border-radius: 2px;
  background: var(--progress-default);
}
/* Same five steps, same thresholds, same tokens as the header bar (00001983). */
.mini-ctx-fill.p-panic { background: var(--progress-panic); }
.mini-ctx-fill.p-danger { background: var(--progress-danger); }
.mini-ctx-fill.p-warning { background: var(--progress-warning); }
.mini-ctx-fill.p-alert { background: var(--progress-alert); }
.mini-ctx-fill.p-default { background: var(--progress-default); }

.side-foot { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--outline); }
.side-foot button { flex: 1; }

/* ── main ────────────────────────────────────────────────── */

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

/*
 * The panel is TWO HALVES (00001979).
 *
 *   ┌───────────────────────────────┬───────────────────────────────┐
 *   │ #panel-left                   │ #panel-right                  │
 *   │   title / agent / avatar      │   pinned chats (0000197D)     │
 *   │   busy send llm tool recv     │                               │
 *   │   ▂▂▂▂▂▂ context bar          │                               │
 *   └───────────────────────────────┴───────────────────────────────┘
 *
 * `flex: 1 1 0` on both halves rather than `0 0 50%`: the gap then comes out of
 * the halves instead of pushing the row past 100%, and `min-width: 0` lets them
 * shrink — the two traps a fixed 50% walks into.
 *
 * The right half draws NOTHING of its own. It is a container, not a card: no
 * background, no border, no heading, no placeholder text. An empty box is
 * still a box, and the user asked for an empty HALF.
 */
#topbar {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--outline);
  background: var(--panel-selected);
}

/* The status section: title on line 1, agent on line 2, the pills under them,
   the context bar under those. voiceover puts its status bar ABOVE the title;
   webdesk wants it below. */
#panel-left {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

#panel-right {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

/*
 * Below 800px the two halves STACK and each takes the whole panel — the user's own
 * "50% or whole panel".
 *
 * The number is measured, not guessed: five pills with their own padding need
 * ~236px, and a row layout gives the left half (viewport - 260px sidebar - 40px
 * padding - 16px gap) / 2. At 800px that is 242px — the last width where the
 * pills fit. Narrower than that and the pills clip, which is why a phone keeps
 * the shape it always had: status section first, pinned chats in a row under it.
 *
 * 900px deliberately stays in ROW mode (it is above this breakpoint), so the
 * two-half layout is what a laptop actually shows.
 */
@media (max-width: 800px) {
  #topbar { flex-direction: column; gap: 10px; }
  #panel-left, #panel-right { flex: 0 0 auto; }
}

/* Row now: avatar, then the two text lines stacked. The avatar slot collapses to
   nothing when it is empty (`:empty`), so a conversation with no agent open costs
   no gutter. */
#titlebar { display: flex; align-items: center; gap: 10px; min-width: 0; }
#conv-avatar { flex: 0 0 auto; display: flex; }
#conv-avatar:empty { display: none; }
#titletext { display: flex; flex-direction: column; min-width: 0; }

/* ── avatars (00001592) ───────────────────────────────────── */

/*
 * Two shapes, one rule: a real image or a monogram, always 32px in a row and 26px
 * beside a bubble. Round, decided once and used everywhere — a square image next to
 * a round monogram would make the two states look like different features.
 *
 * The monogram's hue is set per agent by app.js (--mono-hue), so it is stable across
 * renders and themes: it reads as that agent's colour, not as a random tint.
 */
.avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: cover;
  background: var(--outline);
}

.avatar.mono {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--on-accent);
  /* color-mix over a per-agent hue, with the plain declaration first as the
     fallback for a browser without it. */
  background: var(--accent);
  background: hsl(var(--mono-hue, 220) 55% 45%);
}

/*
 * Header size.
 */
.avatar-head { width: 34px; height: 34px; }

/*
 * The size beside a bubble (000019BB — back after 1.1.36 removed the per-bubble
 * avatars by mistake). Smaller than the header's on purpose: it sits next to a line
 * of body text, not next to a title, and it must not compete with the words.
 */
.avatar-msg { width: 26px; height: 26px; font-size: 11px; }

/*
 * The wrapper that lets an avatar sit BESIDE a bubble rather than inside it.
 *
 * A child of `.msg` would eat the bubble's padding and inherit its `pre-wrap`, which
 * is exactly the bug 00001592 avoided by using a sibling — so the bubble and its
 * avatar are two items in a flex row.
 *
 * `align-items: flex-end` puts the bead on the LAST line of the bubble, which is
 * where a chat avatar belongs and where it stays put whether the message is three
 * words or thirty lines.
 *
 * The avatar sits on the OUTER edge of its row: before the agent's bubble, AFTER
 * yours (append order in renderMessages, not a CSS `order` property — the two orders
 * are then the same thing rather than two things that must be kept in step). So the
 * row never puts a picture between a bubble and the middle of the conversation, and
 * `.own` packs the pair to the right with no reversal.
 */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 12px;
}
.msg-row.own { justify-content: flex-end; }

/* The row carries the spacing now, so the bubble must not add a second gap. */
.msg-row .msg { margin-bottom: 0; }

/*
 * `.msg.user` pushes itself to the right with `margin-left: auto`, which it needs
 * when it stands alone. Inside the row that auto margin would fight the row's own
 * `justify-content` and squeeze the avatar out of the line, so it is neutralised
 * here — three classes beat `.msg.user`'s two, no !important needed.
 */
.msg-row.own .msg { margin-left: 0; }

/* ── message author line (00001995) ───────────────────────── */

/*
 * Author + time, first child inside a user or assistant bubble:
 *
 *   Angelica | (a day ago, 01 Oct 1969 21:37)
 *
 * Reads as a caption, not as prose: smaller, bold, muted, and separated from the
 * text by a hair of margin rather than a border. No extra padding — the bubble's
 * own is the frame, and the user asked for "just enough to see it's not text".
 *
 * white-space: normal is mandatory: `.msg` is pre-wrap for plain text, and
 * without this the line inherits it and doubles its own spacing.
 */
.msg-meta {
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--muted);
  white-space: normal;
}

/* On the user bubble the page's muted grey is unreadable, so it is the bubble's
   own contrast colour dimmed — the same treatment the ⋮ gets there. */
.msg.user .msg-meta { color: var(--on-accent); }
.msg.user .msg-meta { color: color-mix(in srgb, var(--on-accent) 78%, transparent); }

/* Both lines get the full width now, so both need the ellipsis treatment. */
#conv-title {
  margin: 0;
  font-size: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#conv-agent {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/*
 * The pills keep the exact look they had: same cells, same gap, same row. What
 * changed (00001979) is only where they sit — inside the left half, ABOVE the
 * context bar. The 10px was #statusrow's margin-top, i.e. the space between the
 * title and the pills; it belongs here now that there is no wrapper row.
 */
#statusbar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-top: 10px;
}

/*
 * The context bar, directly under the pills. `margin-top: 4px` IS the "very small
 * padding between pills and the bar" the request asked for — a few pixels, not a
 * row gap. It is a column of its own so the bar and its label stay one block, and
 * it no longer shares a flex row with #statusbar (that row is gone).
 */
#contextbox {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-top: 4px;
}

/* ── status bar cells ────────────────────────────────────── */

#cells { display: flex; gap: 4px; }

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

.cell.on { background: var(--accent); color: var(--on-accent); }
/* Idle was a pale green block with dark green text. Kept as a tint of --ok rather
   than a filled chip, because a filled --ok on a dark palette is a slab of
   saturated green in the corner of the eye. */
.cell.idle { background: var(--status-ok); color: var(--highlighted-text); }
.cell.idle { background: color-mix(in srgb, var(--status-ok) 18%, var(--panel-selected)); color: var(--status-ok); }
/* Busy is amber, not red: red is the error colour, and a state that is merely
   working must not read as a failure. --warn already exists (it drives the
   context bar's "getting tight" fill), so this is a remap, not a new token. The
   coupling is deliberate — both mean "attention" — which is why the palette
   editor labels warn "warning / busy".

   The text stays --on-accent, i.e. white. That is 3.18:1 on the default amber,
   weak for 11px bold but no worse than the 3.24:1 the red chip had, so this is
   not a regression. A pale custom amber would be a real problem and the honest
   fix is an onWarn token; that is an 18th token (server TOKENS + three presets +
   theme.js + this file + the editor) and was deliberately deferred (000016A6). */
.cell.busy { background: var(--status-busy); color: var(--on-accent); }
.cell.err { background: var(--danger-bg); color: var(--status-error); }

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

/* A real-height bar with the number printed under it, unlike voiceover's 3px
   strip: there is room on a desktop. The track is always drawn; only the fill
   and the label change, so an unknown window leaves an empty track rather than
   a bar that pops in and out.

   The track is --bg (00001982), the same surface the conversation and the composer
   use, so the two context bars agree on what an unfilled track looks like. On the
   default light preset that is #f7f7f8 on a #ffffff topbar — a very quiet track, and
   deliberately so: the fill is the thing that carries the information. */
#context-bar {
  width: 100%;
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}

#context-bar-fill { width: 0; height: 100%; background: var(--progress-default); }

/* The five-step ramp (00001983). Thresholds are LOWER BOUNDS and live in app.js
   (PROGRESS_STEPS, mirrored from service/Themes.PROGRESS_STEPS): 0 default,
   66 alert, 80 warning, 90 danger, 99 panic. Declared highest-first in the CSS so
   the order here reads the same way the ramp does.

   These are the same five classes the sidebar's mini context strip uses, so a bar
   in the header and a bar in the list 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); }

#context-label {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── pinned chats (tab strip) ─────────────────────────────── */

/*
 * One row, in the RIGHT HALF of the panel (0000197D — it used to be a row under the
 * whole header). No wrap: an overflowing strip scrolls sideways, because letting it
 * wrap would push #messages down and shrink the conversation — the exact trap
 * 0000154D and 00001553 documented for the shell.
 *
 * `margin-top: 0` because the offset is no longer "below the status bar": the strip
 * starts at the top of its own half, level with the title. Below the panel's 800px
 * breakpoint the halves stack, and there it does read as a row under the status
 * section — the spacing for THAT comes from the stacked #topbar's own gap, so this
 * rule needs no media query.
 *
 * Each pin is two buttons in one pill: the title (opens) and a small ✕ (unpins).
 * Two siblings, not a button inside a button — nesting a button in a button is
 * invalid HTML and steals the inner click.
 */
#pins {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  margin-top: 0;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
#pins[hidden] { display: none; }

.pin {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  border: 1px solid var(--outline);
  border-radius: 6px;
  background: var(--panel-selected);
  overflow: hidden;
}
.pin.active { border-color: var(--accent); }

.pin-open {
  min-width: 0;
  max-width: 180px;
  padding: 4px 8px;
  border: none;
  border-radius: 0;
  background: none;
  font-size: 13px;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pin.active .pin-open { color: var(--accent); font-weight: 600; }
.pin-open:hover { background: var(--outline); }

.pin-x {
  padding: 4px 6px;
  border: none;
  border-left: 1px solid var(--outline);
  border-radius: 0;
  background: none;
  font-size: 12px;
  line-height: 1;
  color: var(--muted);
}
.pin-x:hover { background: var(--outline); }

#messages { flex: 1; overflow-y: auto; padding: 20px; }

.msg {
  position: relative;
  max-width: 70%;
  margin: 0 0 12px;
  /* padding-right reserves the ⋮ corner. Without it the button sat on top of
     the first line of text. */
  padding: 10px 38px 10px 14px;
  border-radius: 8px;
  white-space: pre-wrap;
  word-wrap: break-word;
  /* A giant unbroken token (a base64 blob, a minified stack trace) must wrap
     instead of stretching the bubble past its 70%. Text is never truncated: it
     wraps. word-wrap above stays as the older spelling of the weaker rule. */
  overflow-wrap: anywhere;
}
/*
 * The user bubble takes its OWN border token (--user-bubble-border), which existed
 * since 00001983 and was never used: the bubble was fill-only, so its edge against
 * the page rested on a fill-versus-fill comparison. In the light preset that is
 * #2563eb on #f7f7f8 — readable, but any neighbouring tweak in the theme editor
 * swung how the bubble read, because nothing else defined its boundary.
 */
.msg.user {
  margin-left: auto;
  background: var(--user-bubble);
  border: 1px solid var(--user-bubble-border);
  color: var(--on-accent);
}
/* The agent's bubble takes its own two tokens (00001983): the same values as
   --panel-selected / --outline in every preset, but configurable separately, so a
   palette can make the agent's side of the conversation stand out without moving
   every panel in the app. */
.msg.assistant { background: var(--agent-bubble); border: 1px solid var(--agent-bubble-border); }
.msg.tool { background: var(--bg); border: 1px dashed var(--tool-outline); color: var(--muted); font-size: 13px; }
/* Tool outcome: a tint of the status colour mixed into the tool outline, so it
   follows the palette instead of pinning a green that would be wrong on a dark theme. */
/*
 * A tool row's outline is SET from a token, never mixed (1.1.39).
 *
 * These two rules used to be `color-mix(in srgb, var(--status-ok) 40%, var(--tool-outline))`
 * and the same with statusError — so a successful call came out as a wash of the
 * old green over the outline, and a failed one as whatever red and grey averaged
 * to. The user's report was exactly that: "they seem to blend with the old, green
 * color".
 *
 * Now: ok keeps the plain outline (a successful call needs no colour), and a
 * FAILED call takes its own `--tool-failure-outline` token, which is editable in
 * the theme editor like everything else.
 */
.msg.tool.ok { border-color: var(--tool-outline); }
.msg.tool.err { border-color: var(--tool-failure-outline); }
.msg.error { background: var(--danger-bg); border: 1px solid var(--status-error); color: var(--status-error); }
.msg.error { border-color: color-mix(in srgb, var(--status-error) 30%, var(--danger-bg)); }
.msg.pending { opacity: 0.6; }

.msg-author { font-weight: 600; margin-bottom: 4px; }

/* A tool row with its arguments: name + raw JSON on one line. The bubble is
   already exactly 70% wide and the row must not grow it — the room is the space
   the name leaves free.

   The name is the important half: it says WHAT was called, so it keeps its full
   width and never ellipsizes. The args shrink instead — and min-width:0 is
   load-bearing, because a flex item defaults to min-width:auto and refuses to
   shrink below its content, so the ellipsis would never fire and the JSON would
   widen the bubble instead.

   The separator is a hairline, not a glyph: a middle dot next to a leading brace
   reads as noise. */
.msg-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

/* The call's position in the conversation. Muted and narrow so it reads as an
   index rather than part of the name; tabular-nums keeps 9 and 10 the same width,
   so the name does not shift by a character when the count crosses ten. */
.msg-tool-seq {
  flex: 0 0 auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.msg-tool-name {
  flex: 0 0 auto;
  color: var(--fg);
  white-space: nowrap;
}

/* nowrap is mandatory: .msg is pre-wrap, which would otherwise wrap the args and
   grow the bubble — exactly what this feature must not do. */
/* A call still in flight is a placeholder, not a settled row — it keeps the dim
   colour and the italic the old text-only pending row had. */
.msg.tool.pending .msg-tool-name {
  color: var(--muted);
  font-style: italic;
}

.msg-tool-args {
  flex: 1 1 0;
  min-width: 0;
  padding-left: 8px;
  border-left: 1px solid var(--outline);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── folded task groups (00001541) ─────────────────────────── */

/* A run of consecutive tool calls, collapsed to one bubble. The group has no ⋮ of
   its own (one menu for N calls could not name a target), so the space the single
   row reserves for it is not needed here. */
.msg.tool.group { padding: 6px 10px 6px 14px; }

/* The disclosure. A real button, so it is focusable and announces its state; the
   whole line is the target because the folded bubble exists to be opened. */
.msg-group-summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  text-align: left;
  cursor: pointer;
  /* Folding and unfolding by accidental text selection is maddening. */
  user-select: none;
}
.msg-group-summary:hover .msg-group-names { color: var(--accent); }

.msg-group-chevron { flex: 0 0 auto; font-size: 10px; line-height: 1; color: var(--muted); }

/* min-width:0 again, same reason as .msg-tool-args: a flex item refuses to shrink
   below its content, so without it the ellipsis never fires and a long run widens
   the bubble instead of clipping. */
.msg-group-names {
  flex: 1 1 0;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* How many calls are folded in here — a quiet badge, not a number to read. */
.msg-group-count {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.msg-group-tasks { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }

/* Each unfolded call, with its own menu at the end of the line. The menu is static
   rather than absolute: it belongs to its line, and .msg-menu-btn's absolute corner
   would put every one of them on top of the group. */
.msg-group-tasks .msg-line { padding-right: 0; }

.msg-line-menu {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: none;
  font-size: 16px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.msg-line-menu:hover { background: var(--outline); }

/* ── 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 — every
   blank line would come out twice as tall. */
.msg .md { white-space: normal; }

/* No gap above the first block and none below the last: 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: 4px;
}

/* 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: 8px;
}

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

/* The ⋮ trigger. It used to be opacity .45 with no colour and no size, so on a
   white bubble it was a grey smudge and on a blue one it was invisible. Now it
   is a real 30px target with a readable glyph, and the colour is set per role
   because a single colour cannot work on both the panel and the user bubble. */
.msg-menu-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.msg-menu-btn:hover { background: var(--outline); }
/* On the user bubble: the contrast colour, dimmed, and a wash of itself. */
.msg.user .msg-menu-btn { color: var(--on-accent); }
.msg.user .msg-menu-btn { color: color-mix(in srgb, var(--on-accent) 80%, transparent); }
.msg.user .msg-menu-btn:hover { background: color-mix(in srgb, var(--on-accent) 18%, transparent); }

/* ── composer ────────────────────────────────────────────── */

/*
 * The composer's top edge is a DRAG HANDLE (000019DB), which is why the border that
 * used to sit on #composer lives here: the strip you can grab is the strip you can
 * see, the same rule 000019D1 applied to the drawer's rows.
 *
 * A real element rather than a pseudo-element, because a browser test has to be able
 * to point at it.
 *
 * `touch-action: none` is not decoration: without it a drag on a touchscreen is
 * claimed by the page scroller and the handle never sees a pointermove.
 */
#composer-resize {
  flex: 0 0 6px;
  border-top: 1px solid var(--outline);
  background: none;
  cursor: ns-resize;
  touch-action: none;
}
/* A wash on hover and while dragging, so the affordance is findable at all — a 6px
   strip with no feedback reads as the divider it used to be. */
#composer-resize:hover,
#composer-resize.dragging { background: var(--outline); }
#composer-resize:hover,
#composer-resize.dragging { background: color-mix(in srgb, var(--outline) 55%, var(--panel-selected)); }

/* align-items:flex-end keeps the send button its own height instead of
   stretching it to the textarea's four rows. */
#composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px 20px; background: var(--panel-selected); }
/* The height is set by JS in px (000019DB) and overrides the rows="4" intrinsic
   height. resize:none keeps the native grip out of the way — two resize mechanisms
   arguing over one box is worse than none. */
#textinput {
  flex: 1;
  resize: none;
  padding: 10px 12px;
  border: 1px solid var(--outline);
  border-radius: 6px;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
}
#composer button { padding: 10px 20px; }

/* The send button is also the stop button (00001901). Same three states as
   voiceover's: idle "send", filled "stop" while a turn runs, muted "stopping…"
   from the click until the server reports idle.

   The fill is the SOFT danger surface, not the saturated one (000019BB, user
   request): stopping a turn does not destroy anything, it throws a generation
   away, so the control is destructive INTENT rather than a filled alarm. The
   border and the word carry that intent — `destructive` and `dangerText` — while
   the button itself stays quiet enough to sit next to a textarea. A filled
   `destructive` slab in the composer read as a warning banner, which is the
   thing voiceover's own stop button already avoids. */
#btn-send.stop {
  background: var(--danger-bg);
  border-color: var(--destructive);
  color: var(--danger-text);
}
#btn-send.stopping { color: var(--muted); }

/* ── overlays ─────────────────────────────────────────────── */

#settings, #login, #archive {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 40;
  display: flex;
}
#settings[hidden], #login[hidden], #archive[hidden] { display: none; }

/* ── archive browser (000019C5) ────────────────────────────── */

/*
 * A full-window view, shaped like settings: it takes over the app rather than
 * squeezing into the 260px drawer, because the archive is a place you go to and
 * come back from. Settings and this never coexist — opening one closes the other.
 *
 * The list is the MAIN component: column layout, the head pinned on top and the
 * rows taking the remaining height with their own scrollbar.
 */
#archive { flex-direction: column; padding: 16px 20px; }

.archive-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

/* Lowercase on purpose: the title is a place, not a shout. */
.archive-head h2 { margin: 0; font-size: 16px; }

/* "12 chats" — the one number worth stating, and it is the server's list length. */
.archive-count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

#archive-list {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: 900px;
}

/*
 * One archived chat. The row is NOT a conversation row: it cannot be opened, so
 * there is no hover-brightening title and no ⋮ — only the two buttons the user
 * asked for, and they are always visible rather than behind a menu, because a
 * menu with exactly two items is a menu you open twice.
 */
.archive-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--outline);
  border-radius: 6px;
  margin-bottom: 6px;
  background: var(--panel-selected);
}

/* min-width:0 again, or a long title refuses to shrink and pushes the buttons
   off the row. */
.archive-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.archive-text .t {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* agent · folder · date, in the same shape as a drawer row's second line. */
.archive-text .p {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.archive-row .sub, .archive-row .del { white-space: nowrap; }

/* An empty archive says so out loud — a blank window reads as a broken view. */
.archive-empty { margin: 0; color: var(--muted); }

#settings-nav { width: 240px; flex: 0 0 240px; border-right: 1px solid var(--outline); padding: 16px; overflow-y: auto; }
#settings-page { flex: 1; padding: 16px; overflow-y: auto; }

.set-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.set-head h2 { margin: 0; font-size: 16px; }
.set-head .add { margin-left: auto; }

#settings-sections { list-style: none; margin: 0; padding: 0; }
.nav-cat-title { font-size: 12px; color: var(--muted); margin: 14px 0 4px; text-transform: uppercase; }
.nav-row button {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 6px 8px;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
}
.nav-row button:hover { background: var(--panel); }
.nav-count { color: var(--muted); }

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

.login-inner { margin: auto; width: 320px; }
.login-version { color: var(--muted); font-size: 12px; }

/* ── forms (settings, login) ──────────────────────────────── */

.fld { display: block; margin-bottom: 12px; }
.fld-label { display: block; margin-bottom: 4px; font-size: 13px; 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 8px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; }
.fld input, .fld select, .fld textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--outline);
  border-radius: 6px;
  font: inherit;
  color: var(--fg);
  background: var(--panel-selected);
}

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

/* Consecutive colour fields share one grid row — a theme is read in fours, and
   seventeen pickers stacked in one column is a wall. Fixed four columns rather
   than auto-fill on purpose: auto-fill would reflow the groups differently at
   every window width, so the same palette would never look the same twice. */
.fld-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px 12px;
  margin-bottom: 12px;
}
/* The grid's gap is the spacing; the field's own bottom margin would double it. */
.fld-grid .fld { margin-bottom: 0; }

/* Swatch + hex box. The swatch is the canonical input, the box is the readable
   indicator and can be typed into. */
.fld-color-row { display: flex; align-items: center; gap: 6px; }
.fld-color-row input[type='color'] { flex: 0 0 44px; }
/* min-width:0 is load-bearing: a flex item defaults to min-width:auto and would
   refuse to shrink below the hex string, pushing the swatch out of the cell. */
.fld-color-hex {
  flex: 1 1 0;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

/* Narrow window: two per row. Four cells of a swatch plus six characters need
   roughly 110px each, and the settings page loses 240px to the nav. */
@media (max-width: 900px) {
  .fld-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 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: 4px;
  overflow: hidden;
}
.theme-swatch span { display: block; width: 14px; height: 20px; }

.login-error { color: var(--status-error); font-size: 13px; margin-bottom: 8px; }

.set-form-page, .set-list { display: flex; flex-direction: column; gap: 8px; }
.set-list { list-style: none; margin: 0; padding: 0; }
.set-row { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--outline); border-radius: 6px; }
.set-row .item, .set-row .item-static { flex: 1; text-align: left; }
.item { background: none; border: none; cursor: pointer; text-align: left; padding: 0; }
.item-static { color: var(--fg); }
.badge { font-size: 11px; color: var(--muted); border: 1px solid var(--outline); border-radius: 4px; padding: 0 6px; }
.sub, .del { background: none; border: 1px solid var(--outline); border-radius: 4px; cursor: pointer; padding: 4px 8px; }
/* Avatar upload row in the agent form: preview, file picker, upload, remove. The
   file input is the only flex item allowed to shrink, so a long filename cannot
   push the buttons off the row. */
.avatar-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.avatar-row input[type='file'] { flex: 1 1 140px; min-width: 0; font-size: 12px; }
.avatar-preview { display: flex; flex: 0 0 auto; }

.fld-actions { display: flex; gap: 8px; }
.muted { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); }
.tools-box { border: 1px solid var(--outline); border-radius: 6px; padding: 8px; margin: 8px 0; }
.tool-check { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.tool-row { padding: 8px; border-bottom: 1px solid var(--outline); }
.tool-group { font-size: 12px; color: var(--muted); text-transform: uppercase; padding: 8px 0 4px; }
.secret-wrap { display: flex; gap: 4px; }
.secret-wrap input { flex: 1; }
.secret-toggle { white-space: nowrap; }
.menu-wrap { position: relative; }
.menu-btn { background: none; border: none; cursor: pointer; }
.menu { position: absolute; right: 0; background: var(--panel-selected); border: 1px solid var(--outline); border-radius: 6px; padding: 4px; z-index: 10; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.menu[hidden] { display: none; }

/* ── shared popup menu / toast ────────────────────────────── */

#menu { position: fixed; z-index: 60; background: var(--panel-selected); border: 1px solid var(--outline); border-radius: 6px; padding: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
#menu[hidden] { display: none; }
.menu-item { display: block; width: 100%; text-align: left; padding: 6px 10px; background: none; border: none; border-radius: 4px; cursor: pointer; }

/*
 * Hover wash (0000199E). Without one a popup gave no feedback at all — nothing
 * said which row the pointer was on, while the conversation list has always washed
 * its rows.
 *
 * Same recipe as `#convlist li:hover`: the line colour thinned into the surface,
 * with the plain declaration first as the fallback for a browser without
 * color-mix. The surface here is --panel-selected (the popup's own background),
 * not --panel.
 *
 * It is deliberately on `.menu-item` alone, so it also paints settings' own
 * inline menus (`.menu .menu-item`) — those are the same class and had the same
 * gap.
 */
.menu-item:hover { background: var(--outline); }
.menu-item:hover { background: color-mix(in srgb, var(--outline) 55%, var(--panel-selected)); }

/* A destructive item keeps its red label on hover. The wash above only changes
   the background, but a red word on a grey slab reads differently enough that the
   colour is restated: this item must never look like the safe ones. `dangerText`
   (000019BB), not `destructive`: this is a word, not a fill. */
.menu-item.danger:hover { color: var(--danger-text); }

/*
 * Inverted on purpose: the text colour as the slab, the page colour as the text.
 * That is the old dark toast on a light palette and a light toast on a dark one,
 * with no token of its own.
 *
 * A row since 00001980, because a toast may now carry a `details` button. `gap`
 * plus `align-items: center` is the whole of the layout: the message is a span and
 * the button sits beside it, so a one-word toast is exactly as tall as before.
 */
#toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(640px, calc(100% - 32px));
  background: var(--fg);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 6px;
  z-index: 80;
}
#toast[hidden] { display: none; }

/*
 * The `details` affordance on an error toast. Painted from the toast's own
 * inverted pair — `--bg` text on the `--fg` slab — rather than from the button
 * tokens, because a themed `panel-selected` slab inside the toast would be a light
 * rectangle on a dark strip on half the palettes.
 *
 * The border is the text colour at full strength, so it reads as a small button
 * without becoming a second slab.
 */
#toast .toast-action {
  flex: 0 0 auto;
  padding: 2px 8px;
  border: 1px solid var(--bg);
  border-radius: 4px;
  background: none;
  font-size: 12px;
  color: var(--bg);
  text-decoration: underline;
  cursor: pointer;
}
#toast .toast-action:hover { background: var(--bg); color: var(--fg); }

/* ── modal dialog (rename, delete confirm) ────────────────── */

/* z-index 70: above #menu (60), below #toast (80). */
#dialog {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .35);
  z-index: 70;
}
#dialog[hidden] { display: none; }

.dialog-inner {
  width: 100%;
  max-width: 420px;
  margin: 16px;
  padding: 18px 20px;
  background: var(--panel-selected);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .25);
}
.dialog-inner h2 { margin: 0 0 10px; font-size: 16px; }

#dialog-message { margin: 0 0 12px; color: var(--fg); }
#dialog-message[hidden] { display: none; }

#dialog-input {
  width: 100%;
  margin-bottom: 14px;
  padding: 8px 10px;
  border: 1px solid var(--outline);
  border-radius: 6px;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
}
/* Confirm-style use hides the input; the UA [hidden] rule loses to the
   display-less rule above only if something sets display, so restate it. */
#dialog-input[hidden] { display: none; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

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

/* z-index 65: above #menu (60), below #dialog (70) — a delete confirm opened
   from the message menu must sit on top of this card, not under it. */
#msg-detail {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .35);
  z-index: 65;
}
#msg-detail[hidden] { display: none; }

/*
 * The error card (00001980): the same shape as the tool card — a centered card
 * with a scrolling body — because it is the same kind of thing, a blob of text
 * you read and copy.
 *
 * z-index 66, i.e. one above #msg-detail and still below #dialog (70). They can
 * never both be open (the toast that opens this one is under the other's
 * backdrop), so the number is only there to keep the ordering meaningful rather
 * than accidental.
 *
 * The body can be a whole stack trace, hence `pre-wrap` on `.detail-value`
 * which it inherits: a trace is line-based, and collapsing its whitespace would
 * destroy the one thing that makes it readable.
 */
#error-detail {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .35);
  z-index: 66;
}
#error-detail[hidden] { display: none; }

/* A trace is wide as well as tall: let the values scroll sideways rather than
   force a bubble to re-wrap long package names. */
#error-detail .detail-value { overflow-x: auto; }

.detail-inner {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  margin: 16px;
  background: var(--panel-selected);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .25);
}

.detail-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--outline);
}
.detail-head h2 { margin: 0; font-size: 16px; }
.detail-head button { margin-left: auto; }

/* A tool result can be a whole log file, so the body scrolls instead of
   growing the card past the viewport. */
#msg-detail-body { padding: 14px 18px; overflow-y: auto; }

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

.detail-label {
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
}

.detail-value {
  padding: 8px 10px;
  background: var(--code-bg);
  border: 1px solid var(--outline);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* ── buttons ─────────────────────────────────────────────── */

button {
  font: inherit;
  padding: 8px 14px;
  border: 1px solid var(--outline);
  border-radius: 6px;
  background: var(--panel-selected);
  color: var(--fg);
  cursor: pointer;
}
button.primary { background: var(--action); color: var(--on-accent); border-color: var(--action); }
/*
 * Destructive, not "error" (00001983). These are the controls whose whole job is
 * to destroy something — a delete item, a delete button, the confirm that commits
 * it, the ✕ that unpins, the stop button. They are painted with `destructive` and
 * not with `statusError`, because an error REPORT and an invitation to cause one
 * are different facts that happen to look similar in the default palettes.
 *
 * The WORD and the SLAB are two different tokens since 000019BB. A menu item or a
 * 🗑 glyph wants a readable red on the normal surface it sits on, so it takes
 * `dangerText` ("danger zone" in the editor). Only a FILLED control — the commit
 * button of a delete confirm — takes `destructive` as a background, and it keeps
 * `onAccent` as its label, because white-on-red is the point of a slab.
 */
button.danger { color: var(--danger-text); }
.del { color: var(--danger-text); }
.menu-item.danger { color: var(--danger-text); }
#dialog-save.danger { background: var(--destructive); border-color: var(--destructive); color: var(--on-accent); }
.pin-x:hover { background: var(--outline); color: var(--danger-text); }
