/* c3po web UI -- "control deck": a dark blueprint with a crimson accent.
 *
 * The rules the whole sheet obeys, so a later edit doesn't quietly drift:
 *
 *   1. Flat. No box-shadows on content, no frosted glass. Depth comes from a
 *      1px border and a one-step background change, nothing else. The
 *      exceptions: the command palette and the modal, which float over the
 *      page, and the one soft accent glow on "where you are" (the active
 *      sidebar link and the brand dot), as in the mockups.
 *   2. Every border is 1px of --border (semi-transparent indigo). Anything that
 *      wants emphasis uses --border-strong, never a thicker rule.
 *   3. The crimson gradient is an *accent*, not a surface: primary buttons,
 *      active indicators, progress fills, avatars, loading states. Never a
 *      page or panel background. Where a gradient cannot go -- link colour, a
 *      <mark>, a highlighted value -- the flat --accent stands in for it, and
 *      the two must read as the same colour. They did not, once: see the note
 *      on --grad below, which is the mistake this rule now exists to prevent.
 *   4. Two typefaces with a hard split. Sans (--sans) for prose a human reads
 *      in quantity: chat turns, summaries, descriptions, hints. Mono (--mono)
 *      for everything machine-shaped: paths, timestamps, scores, counts, tags,
 *      code, status. The split is the main reason the dense screens stay
 *      readable, so resist "just this once" exceptions.
 *   5. No webfont is fetched. The stacks below name Inter/JetBrains Mono first
 *      and fall through to system faces, because this UI has to work with the
 *      network down (ISSUES.md, "cannot search ... without internet").
 */

/* 2026-10-03, the control-deck refresh (the user's two mockups, Screen-1 and
   Screen-2): a deep blue-black ground with a faint 24px grid, a left sidebar,
   a muted crimson accent (#c9a227) with two pink tints for secondary series,
   and a lime/amber pair for ok/warn. It replaces the neon-red #ff3131 of
   2026-09-18 -- and, per the lesson below, the gradient moved WITH it. */
:root {
  /* surfaces */
  --bg: #050b10;
  --bg-raised: #0a151c;
  --bg-hover: #0f1e27;
  --bg-sunken: #03080c;
  --bg-sidebar: #07111a;
  /* the 24px blueprint grid behind every screen */
  --grid-line: rgba(141, 170, 180, 0.04);

  /* borders -- one hue, two strengths */
  --border: rgba(141, 170, 180, 0.2);
  --border-strong: rgba(141, 170, 180, 0.4);

  /* text */
  --text: #d3ecf0;
  --text-dim: #7ca3ad;
  --text-faint: #56757e;

  /* accent -- C-3PO brass-gold, flat and in the gradient alike (was polaris's crimson).

     THE LESSON, because it cost two rounds: --accent is the smaller half of
     what anyone sees. A dozen rules paint with --grad -- the brand, primary
     buttons, progress fills, the user avatar, selected-row rails -- and once
     --grad ran violet -> pink -> red while --accent was changed alone, which
     turned the links one colour and left the page another. A gradient stop
     is a colour decision with more surface area than the token named
     "accent", so the two move together or not at all.

     The ramp is a narrow crimson -> rose, so it reads as the flat accent at
     button size. --accent-2/-3 are the mockup's secondary series colours
     (GPU, VRAM, temperature lines), never used for state. */
  --violet: #8d6ad8;     /* chrome only -- focus ring, scrollbar. Never content. */
  --accent: #c9a227;
  --accent-bright: #e3c35a;
  --accent-2: #e3c35a;
  --accent-3: #d8b347;
  --accent-deep: #9c7a14;
  --accent-dim: rgba(201, 162, 39, 0.4);
  --accent-wash: rgba(201, 162, 39, 0.12);
  --grad: linear-gradient(135deg, #b38d1f 0%, #c9a227 50%, #dcb53e 100%);
  --grad-soft: linear-gradient(135deg, rgba(201, 162, 39, 0.12), rgba(227, 195, 90, 0.1));

  /* status. Lime and amber, as in the mockup's "connected" and "idle" -- far
     enough from the crimson that a state never reads as a highlight. */
  --ok: #a3d14a;
  --warn: #f07c3a;
  --alert: #ff6b6b;

  /* Host-unrestricted agents (M36) only. Deliberately NOT --warn/--alert
     (those already mean "degraded"/"error" everywhere else) and deliberately
     NOT --accent/--grad (the brand). Gold, so a host job is never visually
     confusable with a sandboxed one in the merged Agents tab -- the whole
     point, since one runs unconfined as root. */
  --host-accent: #e8a33a;
  --host-accent-bright: #ffc65c;
  --host-grad: linear-gradient(135deg, #d97706 0%, #e8a33a 55%, #fbbf24 100%);

  --sans: Inter, Geist, "SF Pro Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", "JetBrainsMono Nerd Font Mono", "Fira Code", ui-monospace, "SF Mono", Consolas, monospace;

  --r: 6px;
  --r-sm: 4px;
  --nav-h: 0px;
  --sidebar-w: 212px;
  --tabbar-h: 3.6rem; /* the phone app's bottom tab bar (M42) */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  /* Everything else is in rem, so this one number scales the whole UI.
     14px read as too small on both the desktop and the phone. */
  font-size: 15.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(255, 49, 49, 0.3); color: #fff; }

/* Thin, unobtrusive scrollbars -- the panels scroll a lot on this UI. */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }
*::-webkit-scrollbar-thumb:hover { background: var(--violet); }

:focus-visible {
  outline: 2px solid var(--violet);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ---------- sidebar ---------- */

body {
  background-color: var(--bg);
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
                    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 24px 24px;
}

.shell { display: flex; min-height: 100vh; }

#nav {
  position: sticky;
  top: 0;
  height: 100vh;
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1rem;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  z-index: 40;
  overflow-y: auto;
}

.brand-block { display: flex; flex-direction: column; gap: 0.25rem; }

#nav .brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.18em;
  color: var(--text);
  white-space: nowrap;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  flex-shrink: 0;
}

.brand-sub {
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  color: var(--text-faint);
  padding-left: 1rem;
}

#nav nav {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 1.5rem;
}

#nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-dim);
  text-decoration: none;
  padding: 0.6rem 0.75rem;
  border: 1px solid transparent;
  border-radius: var(--r);
  font-size: 0.85rem;
  white-space: nowrap;
}
#nav a svg { flex-shrink: 0; }

#nav a:hover { color: var(--text); background: var(--bg-hover); }

/* "Where you are": the mockups' tinted, outlined pill with a soft glow --
   rule 1's one sanctioned glow on content. */
#nav a.active {
  color: var(--accent);
  font-weight: 500;
  background: var(--accent-wash);
  border-color: var(--accent);
  box-shadow: 0 0 18px rgba(201, 162, 39, 0.12);
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* The Ctrl-K affordance: a button that looks like the shortcut it triggers,
   so the palette is discoverable without a tour. */
#palette-open {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.28rem 0.5rem;
  cursor: pointer;
}
#palette-open:hover { border-color: var(--border-strong); color: var(--text-dim); }

#nav-health {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
#nav-health.ok { color: var(--ok); }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.alert { background: var(--alert); }
.dot.live { animation: pulse 2.4s ease-in-out infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- shell ---------- */

#app {
  flex: 1;
  min-width: 0;
  max-width: 1320px;
  padding: 1.5rem 1.5rem 5rem;
}

.page-head {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  flex-wrap: wrap;
  margin-bottom: 0.25rem;
}

h1, h2, h3 { font-weight: 600; color: var(--text); }

h1 {
  font-family: var(--sans);
  font-size: 1.45rem;
  letter-spacing: -0.01em;
  margin: 0;
}

h2 {
  font-family: var(--mono);
  font-size: 0.72rem;
  margin: 1.6rem 0 0.6rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* A rule that fills the row after a section label. Purely structural. */
h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

h3 { font-size: 0.85rem; margin: 0 0 0.5rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-bright); }

p { margin: 0 0 0.6rem; }

code, pre, .mono { font-family: var(--mono); }

.hint {
  color: var(--text-dim);
  font-size: 0.8rem;
  line-height: 1.55;
  margin: 0.5rem 0;
}
.hint.mono, .hint .mono { font-family: var(--mono); font-size: 0.75rem; }

.subtle { color: var(--text-faint); }
.alert-text { color: var(--alert); }
.warn-text { color: var(--warn); }

kbd {
  display: inline-block;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.05rem 0.35rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.empty {
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 1.5rem 0;
}

.empty-card {
  border: 1px dashed var(--border);
  border-radius: var(--r);
  padding: 2rem 1.5rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ---------- controls ---------- */

input[type="text"], input[type="search"], input[type="number"],
input[type="date"], input[type="password"], select, textarea {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.65rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  border-radius: var(--r-sm);
  min-width: 0;
}

textarea { font-family: var(--sans); font-size: 0.9rem; line-height: 1.55; }

input::placeholder, textarea::placeholder { color: var(--text-faint); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

select {
  appearance: none;
  padding-right: 1.6rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 13px) 52%, calc(100% - 8px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

button {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.45rem 0.8rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  border-radius: var(--r-sm);
  cursor: pointer;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--text);
}

button:disabled { opacity: 0.45; cursor: not-allowed; }

button.primary {
  background: var(--grad);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}
button.primary:hover:not(:disabled) { filter: brightness(1.12); color: #fff; }

button.danger { color: var(--alert); }
button.danger:hover:not(:disabled) { border-color: var(--alert); color: var(--alert); }

button.ghost { background: none; border-color: transparent; }
button.ghost:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border); }

button.tiny { padding: 0.2rem 0.45rem; font-size: 0.7rem; }
.row-form { display: flex; gap: 0.5rem; margin: 0.6rem 0; }
.row-form input { flex: 1; min-width: 0; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  user-select: none;
}
.toggle:hover { border-color: var(--border-strong); color: var(--text); }
.toggle input { accent-color: var(--accent); margin: 0; }
.toggle.on { color: var(--text); border-color: var(--border-strong); background: var(--grad-soft); }

/* ---------- search ---------- */

.searchbar {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.search-field {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 0 0.75rem;
  min-width: 0;
}
.search-field:focus-within { border-color: var(--border-strong); }
.search-field svg { flex-shrink: 0; color: var(--text-faint); }
.search-field:focus-within svg { color: var(--accent); }

.search-field input {
  flex: 1;
  background: none;
  border: none;
  padding: 0.7rem 0;
  font-size: 0.95rem;
  color: var(--text);
}
.search-field input:focus { outline: none; background: none; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
  align-items: center;
}

.filters input, .filters select {
  font-size: 0.76rem;
  padding: 0.35rem 0.5rem;
  width: 10rem;
}
.filters select { padding-right: 1.5rem; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.chips:not(:empty) { margin-top: 0.6rem; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.2rem 0.35rem 0.2rem 0.55rem;
  border-radius: 99px;
  border: 1px solid var(--border-strong);
  background: var(--grad-soft);
  color: var(--text);
}
.chip .chip-key { color: var(--accent); }
.chip button {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0 0.15rem;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
}
.chip button:hover { color: var(--accent-bright); background: none; }

/* Past queries, offered on the empty search screen. */
.chip.recall {
  background: none;
  border-color: var(--border);
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.2rem 0.6rem;
}
.chip.recall:hover { border-color: var(--border-strong); color: var(--text); background: var(--grad-soft); }

.result-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.result-controls .meta-line {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-dim);
}
.result-controls .meta-line b { color: var(--text); font-weight: 600; }
.result-controls select { font-size: 0.74rem; padding: 0.3rem 1.5rem 0.3rem 0.5rem; }

/* ---------- result cards ---------- */

.results { margin-top: 0.9rem; display: flex; flex-direction: column; gap: 0.5rem; }

.result {
  position: relative;
  display: block;
  padding: 0.7rem 0.85rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  overflow: hidden;
}

.result:hover { background: var(--bg-hover); border-color: var(--border-strong); }
/* M9 4e: a topic summary, not a file -- marked so it is not read as one. */
.result.summary { border-left: 2px solid var(--accent); }

/* Keyboard selection gets the gradient rail; hover deliberately does not, so
   "where the arrow keys are" never looks like "where the mouse is". */
.result.selected { border-color: var(--border-strong); background: var(--bg-hover); }
.result.selected::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--grad);
}

.result .row-top {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  justify-content: space-between;
}

.result .path {
  font-family: var(--mono);
  color: var(--text);
  font-weight: 600;
  font-size: 0.86rem;
  word-break: break-all;
  min-width: 0;
}
/* The directory reads as context, the basename as the answer. */
.result .path .dir { color: var(--text-faint); font-weight: 400; }

.result .score {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-faint);
  white-space: nowrap;
  flex-shrink: 0;
}
.result .score b { color: var(--accent); font-weight: 600; }

.result .meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0.4rem 0;
}

.result .snippet {
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.55;
}

.result .snippet mark {
  background: rgba(255, 49, 49, 0.14);
  color: var(--accent-bright);
  font-weight: 600;
  border-radius: 2px;
  padding: 0 1px;
}

.result .snippet.secondary {
  color: var(--text-faint);
  font-size: 0.8rem;
  margin-top: 0.35rem;
  padding-left: 0.6rem;
  border-left: 1px solid var(--border);
}

.result .actions {
  margin-top: 0.6rem;
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* ---------- tags ---------- */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.03em;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  background: var(--bg-sunken);
  white-space: nowrap;
}

.tag.available { border-color: rgba(52, 211, 153, 0.35); color: var(--ok); }
.tag.unreachable { border-color: rgba(245, 165, 36, 0.35); color: var(--warn); }
.tag.alert { border-color: rgba(255, 82, 82, 0.45); color: var(--alert); }
.tag.topic { border-color: var(--border-strong); color: var(--accent); }
.tag.mime { text-transform: uppercase; font-size: 0.64rem; color: var(--text-faint); }
.tag.accent { border-color: transparent; background: var(--grad); color: #fff; font-weight: 600; }
.tag.old-version { border-color: var(--border-strong); color: var(--text-faint); font-style: italic; }

/* Older versions of a document (ROADMAP item 18): the mark flow. */
.marking-banner {
  border: 1px dashed var(--border-strong);
  border-radius: var(--r);
  padding: 0.6rem 0.9rem;
  margin: 0.6rem 0;
  font-size: 0.82rem;
  color: var(--text-dim);
}
.mark-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
  align-items: center;
}
.mark-form input { font-size: 0.8rem; flex: 1 1 16rem; min-width: 0; }

/* ---------- tables ---------- */

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 1rem;
}

table { border-collapse: collapse; width: 100%; }

td, th {
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.8rem;
  font-family: var(--mono);
}

th {
  color: var(--text-faint);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--bg-sunken);
}

tbody tr:last-child td, table tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-hover); }

/* A two-column "field / value" table, used for metadata blocks. */
table.kv th {
  width: 9.5rem;
  background: none;
  text-transform: none;
  letter-spacing: 0.02em;
  font-size: 0.74rem;
  color: var(--text-dim);
  vertical-align: top;
}
table.kv td { word-break: break-all; color: var(--text); }
table.kv tbody tr:hover td { background: none; }

.row-click { cursor: pointer; }

/* ---------- stat cards & progress ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.6rem;
  margin: 0.9rem 0 1rem;
}

.stat-card {
  position: relative;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 0.8rem 0.9rem;
  overflow: hidden;
}

/* A gradient hairline across the top of each tile -- the dashboard's only
   decoration, and it doubles as a column separator when tiles wrap. */
.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: var(--grad);
  opacity: 0.55;
}

.stat-card .value {
  font-family: var(--mono);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.2;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stat-card .label {
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 0.2rem;
}

.stat-card .sub { color: var(--text-dim); font-size: 0.72rem; font-family: var(--mono); margin-top: 0.3rem; }

/* Some tiles hold a word rather than a count -- a scope name, a node mode.
   At the numeric size those overflow a 170px tile. */
.stat-card .value.text { font-size: 0.95rem; word-break: break-all; }

.progress-bar {
  height: 5px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 99px;
  overflow: hidden;
  width: 100%;
  margin: 0.35rem 0 0.8rem;
}

.progress-bar > div {
  height: 100%;
  background: var(--grad);
  transition: width 0.4s ease;
}

.metric-line {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-dim);
}
.metric-line b { color: var(--text); font-weight: 600; }

/* ---------- panels & prose blocks ---------- */

.panel {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}

pre.block {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--text-dim);
  margin: 0;
  overflow: auto;
}

pre.block.tall { max-height: 55vh; }

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.4rem;
}

/* A RAPTOR summary is 200-400 words of prose, not a snippet -- it wants a
   readable measure and the sans face, unlike everything else on the screen. */
.prose {
  font-family: var(--sans);
  font-size: 0.9rem;
  line-height: 1.65;
  max-width: 72ch;
  color: var(--text);
  white-space: pre-wrap;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.76rem;
}
.back-link:hover { color: var(--accent-bright); }

.preview-img {
  max-width: 100%;
  max-height: 60vh;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg-sunken);
  display: block;
}

/* ---------- topics ---------- */

.topic-node { border-left: 1px solid transparent; }
.topic-node .topic-node { border-left-color: var(--border); }

details.tree > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
details.tree > summary::-webkit-details-marker { display: none; }

.caret {
  display: inline-block;
  width: 0.8rem;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 0.7rem;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
details[open] > summary .caret { transform: rotate(90deg); }

/* ---------- chat ---------- */

.chat-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 1.1rem;
  align-items: start;
  margin-top: 1rem;
}

.chat-sidebar {
  position: sticky;
  top: calc(var(--nav-h) + 1rem);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.chat-sidebar .new-chat,
.chat-sidebar .new-private-chat { width: 100%; }
.chat-sidebar .delete-all-chats { align-self: flex-start; color: var(--text-faint); }
.chat-sidebar .delete-all-chats:hover { color: var(--alert); }

/* 2026-11-05: says, the whole time, that this conversation is not kept. */
.chat-private {
  padding: 0.45rem 0.7rem;
  margin-bottom: 0.6rem;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.chat-private[hidden] { display: none; }

/* .search-field is flex:1 so it fills the search bar's row. The sidebar is a
   flex column, where that same rule would stretch it into a tall empty box. */
.chat-sidebar .search-field { flex: none; padding: 0 0.55rem; }
.chat-sidebar .search-field input { font-size: 0.8rem; padding: 0.4rem 0; }

.chat-sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 58vh;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.chat-sidebar-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.45rem 0.6rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 0.8rem;
  overflow: hidden;
  /* overflow:hidden makes a flex item's minimum height 0, so in the
     max-height list the items SHRANK to fit instead of overflowing it: every
     past chat squashed into a sliver and the scrollbar never appeared. */
  flex-shrink: 0;
}

.chat-sidebar-item:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.chat-sidebar-item.active { border-color: var(--border-strong); background: var(--bg-hover); }
.chat-sidebar-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--grad);
}

.chat-sidebar-item .title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.chat-sidebar-item .snippet {
  font-size: 0.72rem;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-sidebar-item .stack { display: flex; flex-direction: column; min-width: 0; gap: 0.1rem; }

.chat-sidebar-item .delete-conversation {
  background: none;
  border: none;
  color: var(--text-faint);
  padding: 0 0.2rem;
  font-size: 0.9rem;
  flex-shrink: 0;
  opacity: 0;
}
.chat-sidebar-item:hover .delete-conversation { opacity: 1; }
.chat-sidebar-item .delete-conversation:hover { color: var(--alert); background: none; }

.chat-main { min-width: 0; display: flex; flex-direction: column; }

.chat-model-status {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.6rem;
}

/* The model picker (2026-09-18). Sits in the status row rather than in a
   settings page: which model is answering is a property of the conversation
   you are having, and the row already carries the model's name and its Stop
   button. `margin-left: auto` pushes it to the right so the tag/name/Stop
   cluster on the left keeps the shape it had before the picker existed. */
.model-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.model-picker select {
  font: inherit;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0.15rem 0.35rem;
}

.chat-history {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 42vh;
  max-height: 62vh;
  overflow-y: auto;
  padding: 0.2rem 0.4rem 0.2rem 0;
  scroll-behavior: smooth;
}
/* Same trap as .chat-sidebar-item: a turn must overflow the transcript, never
   be squeezed to fit it. */
.chat-history > * { flex-shrink: 0; }

.chat-turn { display: flex; gap: 0.6rem; align-items: flex-start; }
.chat-turn.chat-user { flex-direction: row-reverse; }

/* The avatar is where the guidelines' gradient lands in the chat: the user's
   is the gradient itself, the assistant's is outlined, so the two sides are
   distinguishable at a glance without colouring the bubbles. */
.avatar {
  width: 26px;
  height: 26px;
  border-radius: var(--r-sm);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-top: 0.1rem;
}
.avatar.user { background: var(--grad); color: #fff; }
.avatar.assistant { border: 1px solid var(--accent-dim); color: var(--accent); background: var(--bg-raised); }

.bubble {
  min-width: 0;
  max-width: 80%;
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 0.6rem 0.8rem;
  background: var(--bg-raised);
}
.chat-user .bubble { background: var(--grad-soft); border-color: var(--border-strong); }
.chat-assistant .bubble { max-width: 92%; background: var(--bg-raised); }

.chat-role {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.35rem;
}
/* tok/s readout: a unit, so not shouted like the role name beside it */
.chat-role .tps { text-transform: none; letter-spacing: 0; }
.chat-role .turn-actions { margin-left: auto; display: flex; gap: 0.2rem; opacity: 0; }
.chat-turn:hover .turn-actions { opacity: 1; }

.chat-content {
  font-family: var(--sans);
  font-size: 0.9rem;
  line-height: 1.65;
  overflow-wrap: anywhere;
  min-width: 0;
}
.chat-content > *:first-child { margin-top: 0; }
.chat-content > *:last-child { margin-bottom: 0; }
.chat-content p { margin: 0 0 0.6rem; }
.chat-content ul, .chat-content ol { margin: 0 0 0.6rem; padding-left: 1.2rem; }
.chat-content li { margin-bottom: 0.2rem; }
.chat-content h3, .chat-content h4, .chat-content h5, .chat-content h6 { margin: 0.9rem 0 0.4rem; color: var(--text); line-height: 1.35; }
.chat-content h3 { font-size: 1.08rem; }
.chat-content h4 { font-size: 0.98rem; }
.chat-content h5 { font-size: 0.9rem; }
.chat-content h6 { font-size: 0.85rem; color: var(--text-dim); }
.chat-content li > ul, .chat-content li > ol { margin: 0.2rem 0 0.2rem; }
.chat-content ol ol, .chat-content ul ol { list-style-type: lower-alpha; }
.chat-content li.task { list-style: none; margin-left: -1.1rem; }
.chat-content .task-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.95rem;
  height: 0.95rem;
  margin-right: 0.45rem;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  font-size: 0.7rem;
  vertical-align: -0.12rem;
  color: var(--ok);
}
.chat-content li.task.done { color: var(--text-dim); }
.chat-content del { color: var(--text-faint); }
.chat-content hr { border: none; border-top: 1px solid var(--border); margin: 0.9rem 0; }
.chat-content a { word-break: break-all; }

/* Formulas (KaTeX). A wide display equation scrolls inside its own box
   instead of widening the bubble -- the phone case. */
.chat-content .math-block { overflow-x: auto; overflow-y: hidden; margin: 0 0 0.7rem; padding: 0.15rem 0; }
.chat-content .math-block .katex-display { margin: 0.3rem 0; }
.chat-content .katex { font-size: 1.08em; color: var(--text); }
.chat-content .math-fallback { font-family: var(--mono); color: var(--text-dim); white-space: pre-wrap; }

/* Model tables: prose, not data -- so sans, wrapped, and scrolled sideways
   inside their own box when wider than the bubble instead of widening it. */
.md-table {
  overflow-x: auto;
  margin: 0 0 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  max-width: 100%;
}
.md-table table { width: auto; min-width: 100%; }
.md-table th, .md-table td {
  font-family: var(--sans);
  font-size: 0.84rem;
  line-height: 1.45;
  padding: 0.4rem 0.65rem;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  word-break: normal;
  overflow-wrap: anywhere;
  min-width: 5rem;
}
.md-table th {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.8rem;
  color: var(--text);
  white-space: nowrap;
}
.md-table td + td, .md-table th + th { border-left: 1px solid var(--border); }
.md-table tbody tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }
.md-table tbody tr:hover td { background: var(--bg-hover); }
.md-table code { word-break: normal; white-space: nowrap; }
.chat-content blockquote {
  margin: 0 0 0.6rem;
  padding-left: 0.7rem;
  border-left: 2px solid var(--border-strong);
  color: var(--text-dim);
}
.chat-content code {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.05em 0.3em;
  color: var(--accent-bright);
}
.chat-content pre {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0.7rem 0.8rem;
  overflow-x: auto;
  margin: 0 0 0.6rem;
}
.chat-content pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
  font-size: 0.78rem;
  line-height: 1.6;
}

.codeblock { position: relative; }
.codeblock .copy-code {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  opacity: 0;
}
.codeblock:hover .copy-code { opacity: 1; }

/* The model's <think> block: kept, never shown by default. */
details.reasoning {
  border: 1px dashed var(--border);
  border-radius: var(--r-sm);
  padding: 0.35rem 0.5rem;
  margin-bottom: 0.6rem;
}
details.reasoning summary {
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
details.reasoning .body {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: pre-wrap;
  line-height: 1.55;
}

/* Tool calls: one collapsed strip per turn instead of a wall of lines. The
   trace is the evidence for a grounded answer, so it stays reachable -- but
   it is not what the reader came for. */
details.trace {
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-sunken);
  margin-bottom: 0.6rem;
}
details.trace > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.55rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}
details.trace > summary::-webkit-details-marker { display: none; }
details.trace[open] > summary { border-bottom: 1px solid var(--border); }
details.trace .trace-body { padding: 0.35rem 0.55rem; display: flex; flex-direction: column; gap: 0.3rem; }

.chat-trace {
  font-family: var(--mono);
  font-size: 0.73rem;
  color: var(--text-dim);
  padding: 0.15rem 0 0.15rem 0.5rem;
  border-left: 2px solid var(--border-strong);
  word-break: break-word;
  line-height: 1.5;
}
.chat-trace .t-name { color: var(--accent-bright); }
.chat-trace.tool-result { border-left-color: rgba(52, 211, 153, 0.5); }
.chat-trace.chat-error { border-left-color: var(--alert); color: var(--alert); }
.chat-trace pre { margin: 0.2rem 0 0; white-space: pre-wrap; font-size: 0.72rem; color: var(--text-faint); }

/* The "working" state. A gradient sweep rather than a spinner: it reads as
   the app's own accent doing something, not as a borrowed widget. */
.thinking {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-dim);
}
.thinking .sweep {
  width: 90px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-bright), transparent);
  background-size: 200% 100%;
  animation: sweep 1.4s linear infinite;
}
@keyframes sweep { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.chat-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  margin-top: 0.7rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
}

.chat-form textarea {
  flex: 1;
  max-height: 40vh;
  resize: none;
  overflow-y: auto;
}

.chat-jump {
  position: absolute;
  right: 1rem;
  bottom: 5.5rem;
  z-index: 5;
}

.chat-main { position: relative; }

/* ---------- code tab ---------- */

.code-approval-card {
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  padding: 0.9rem 1rem;
  margin: 1rem 0;
  background: var(--bg-raised);
  position: relative;
  overflow: hidden;
}
.code-approval-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--grad);
}
.code-approval-card h3 { color: var(--accent-bright); font-family: var(--mono); letter-spacing: 0.04em; }

.code-approval-command,
.code-approval-diff {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0.6rem;
  overflow-x: auto;
  font-size: 0.76rem;
  font-family: var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 0.5rem;
}
.code-approval-diff { max-height: 300px; overflow-y: auto; }

.code-approval-actions { display: flex; gap: 0.5rem; margin-top: 0.8rem; flex-wrap: wrap; }

.code-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1rem;
  margin-top: 0.5rem;
}

.code-options .model-picker { margin-left: 0; }
.code-options input[type="number"] { width: 5.5rem; padding: 0.15rem 0.35rem; font: inherit; color: var(--text); }

.job-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--text-dim);
  margin: 0.6rem 0;
}
.job-meta span b { color: var(--text); font-weight: 600; }

/* ---------- agent tab (M36 -- host-unrestricted, amber identity) ---------- */

.agent-banner {
  border: 1px solid var(--host-accent);
  border-radius: var(--r);
  padding: 0.7rem 1rem;
  margin: 0 0 1rem;
  background: var(--bg-raised);
  color: var(--text);
  font-size: 0.82rem;
}
.agent-banner b { color: var(--host-accent-bright); }

/* Same shape as .code-approval-card (border-strong card, 2px gradient
   top-stripe, mono heading) with every color swapped from the red brand to
   --host-accent/--host-grad -- the one visual cue that has to be impossible
   to miss on this tab, since there is no sandbox under it. */
.agent-approval-card {
  border: 1px solid var(--host-accent);
  border-radius: var(--r);
  padding: 0.9rem 1rem;
  margin: 1rem 0;
  background: var(--bg-raised);
  position: relative;
  overflow: hidden;
}
.agent-approval-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--host-grad);
}
.agent-approval-card h3 { color: var(--host-accent-bright); font-family: var(--mono); letter-spacing: 0.04em; }

/* ---------- job threads (2026-10-04: a job is a conversation) ---------- */

/* Taller than the chat's history: a job's thread is the whole page. */
.job-thread { max-height: 68vh; margin-top: 0.8rem; }
.avatar.assistant.host { border-color: var(--host-accent); color: var(--host-accent-bright); }
/* What the agent says beside a tool call: quieter than a reply, louder than
   the tool strip it introduces. */
.job-narration {
  font-size: 0.84rem;
  color: var(--text-dim);
  font-style: italic;
  margin: 0 0 0.45rem;
}
.job-status-line { margin-bottom: 0.45rem; white-space: pre-wrap; }
.job-finish { margin-top: 0.5rem; }
.bubble > .chat-content + details.trace,
.bubble > .chat-content + .job-narration { margin-top: 0.6rem; }

/* ---------- toasts ---------- */

.toast-stack {
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-end;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.55rem 0.9rem;
  border-radius: var(--r);
  font-family: var(--mono);
  font-size: 0.78rem;
  max-width: 24rem;
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}
.toast.error { border-color: var(--alert); color: var(--alert); }
.toast .dot { background: var(--accent); }
.toast.error .dot { background: var(--alert); }

@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- overlay: command palette, help, modal ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 8, 0.72);
  z-index: 80;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 10vh 1rem 1rem;
}

.overlay[hidden] { display: none; }

.palette, .modal {
  width: 100%;
  max-width: 620px;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  overflow: hidden;
  /* The one place a shadow is allowed: this floats above the page. */
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

.modal { max-width: 720px; }

.palette-input-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
}
.palette-input-row input {
  flex: 1;
  background: none;
  border: none;
  font-size: 0.95rem;
  padding: 0;
  color: var(--text);
}
.palette-input-row input:focus { outline: none; background: none; }
.palette-input-row .prompt { color: var(--accent); font-family: var(--mono); }

.palette-list { max-height: 52vh; overflow-y: auto; padding: 0.35rem; }

.palette-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--r-sm);
  cursor: pointer;
  border: 1px solid transparent;
}
.palette-item .label { flex: 1; min-width: 0; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item .kind {
  font-family: var(--mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.palette-item.active { background: var(--grad-soft); border-color: var(--border-strong); }
.palette-item.active .kind { color: var(--accent); }

.palette-group {
  font-family: var(--mono);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  padding: 0.5rem 0.6rem 0.25rem;
}

.palette-foot {
  display: flex;
  gap: 0.9rem;
  padding: 0.45rem 0.9rem;
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-faint);
  flex-wrap: wrap;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.modal-body { padding: 0.9rem; max-height: 62vh; overflow-y: auto; }

.shortcut-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem 1rem;
  align-items: center;
  font-size: 0.82rem;
}
.shortcut-grid .keys { display: flex; gap: 0.25rem; justify-content: flex-end; }
.shortcut-grid .what { color: var(--text-dim); }

/* ---------- skeletons ---------- */

.skeleton {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: linear-gradient(90deg, var(--bg-raised) 25%, var(--bg-hover) 50%, var(--bg-raised) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
  height: 62px;
  margin-bottom: 0.5rem;
}
.skeleton.line { height: 12px; border: none; border-radius: 3px; margin-bottom: 0.4rem; }
.skeleton.short { width: 40%; }

@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- responsive ---------- */

/* Phone width: the sidebar folds into a top bar whose links scroll sideways. */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  #nav {
    position: sticky;
    height: auto;
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 0.8rem;
    padding: 0.5rem 0.8rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }
  .brand-sub, #nav a span { display: none; }
  /* min-width:0 lets the icon row scroll instead of pushing the health dot
     off the right edge (the whole page used to scroll sideways by ~8px). */
  #nav > div:first-child { min-width: 0; flex: 1 1 auto; }
  #nav nav { flex-direction: row; margin-top: 0; overflow-x: auto; scrollbar-width: none; gap: 0.2rem; }
  #nav nav::-webkit-scrollbar { display: none; }
  #nav a { padding: 0.45rem; }
  .sidebar-foot { flex-direction: row; align-items: center; border-top: none; padding-top: 0; margin-left: auto; }
  #palette-open { display: none; }
  #app { padding: 1.1rem 1rem 4rem; }
  .chat-layout { grid-template-columns: minmax(0, 1fr); }
  .chat-sidebar { position: static; }
  .chat-sidebar-list { flex-direction: row; overflow-x: auto; max-height: none; }
  .chat-sidebar-item { min-width: 11rem; }
  .bubble, .chat-assistant .bubble { max-width: 100%; }
  .filters input, .filters select { width: 100%; }
  .filters { display: grid; grid-template-columns: 1fr 1fr; }
  .filters .toggle { grid-column: span 2; justify-content: center; }
}

@media (max-width: 560px) {
  #nav-health span:not(.dot) { display: none; }
  .tile-grid { grid-template-columns: minmax(0, 1fr); }
  .filters { grid-template-columns: 1fr; }
  .filters .toggle { grid-column: span 1; }
  .target-switch { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- login and step-up (M34) ---------- */

/* Signed out, the header keeps only the brand and the health dot: the screen
   links would each just bounce back to the login card. */
body.signed-out #nav nav,
body.signed-out #palette-open { visibility: hidden; }

.auth-card {
  max-width: 380px;
  margin: 3rem auto 0;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin: 1.2rem 0 0.4rem;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* The six digits are the thing being read off a phone: large, spaced, mono. */
.code-input {
  font-size: 1.25rem;
  letter-spacing: 0.35em;
  text-align: center;
}

.auth-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.auth-error { margin: 0; font-size: 0.8rem; }

.auth-link {
  display: inline-block;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  word-break: break-all;
}

/* ---------- control deck (2026-10-03: Overview, Agents) ---------- */

/* The mockups' page head: a mono crumb in the accent over a sans title,
   status pill and actions on the right, then a ruled ticker line. */
.deck-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.deck-head .crumb {
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.18em;
  color: var(--accent);
  margin-bottom: 0.4rem;
}
.deck-actions { display: flex; align-items: center; gap: 0.5rem; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg-raised);
  font-size: 0.76rem;
  color: var(--text-dim);
}
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.pill.alert { color: var(--alert); }

.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem; padding: 0; }

.ticker {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 1rem 0;
  padding: 0.45rem 0;
  border-top: 1px solid var(--accent-dim);
  border-bottom: 1px solid var(--accent-dim);
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  color: var(--accent);
  text-transform: uppercase;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r);
  min-width: 0;
}
.tile.lead { border-color: var(--accent-dim); }
.tile .label {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  color: var(--text-dim);
}
.tile .value {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.75rem;
  line-height: 1.1;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile .value.c2 { color: var(--accent-2); }
.tile .value.c3 { color: var(--accent-3); }
.tile .value.plain { color: var(--text); }
.tile .value.okv { color: var(--ok); }
.tile .sub {
  font-size: 0.74rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sparklines and the telemetry chart are inline SVG drawn by app.js; these
   only give them a box and a stroke per series. */
.spark { display: block; width: 100%; height: 2rem; }
.spark polyline, .chart polyline { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.s1 { stroke: var(--accent); }
.s2 { stroke: var(--accent-2); }
.s3 { stroke: var(--accent-deep); }
.chart .gridline { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }

.meter {
  height: 0.5rem;
  border-radius: 99px;
  background: var(--bg-sunken);
  overflow: hidden;
}
.meter > div { height: 100%; border-radius: 99px; background: var(--accent); transition: width 0.4s ease; }
.meter.c2 > div { background: var(--accent-2); }
.meter.ok > div { background: var(--ok); }

.deck-row {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
  align-items: stretch;
}
.deck-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.card {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.15rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r);
  min-width: 0;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.card-title {
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.12rem 0.5rem;
  border: 1px solid var(--accent-dim);
  border-radius: var(--r-sm);
  background: var(--accent-wash);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.badge.idle { border-color: rgba(242, 179, 61, 0.45); background: rgba(242, 179, 61, 0.1); color: var(--warn); }
.badge.okb { border-color: rgba(163, 209, 74, 0.45); background: rgba(163, 209, 74, 0.08); color: var(--ok); }
.badge.host { border-color: var(--host-accent); background: rgba(232, 163, 58, 0.1); color: var(--host-accent-bright); }

.outline-btn { color: var(--accent); border-color: var(--accent); background: none; width: 100%; letter-spacing: 0.08em; }
.outline-btn:hover:not(:disabled) { color: var(--accent-bright); border-color: var(--accent-bright); background: var(--accent-wash); }

/* A list row inside a card: name + figure on top, detail line under it. */
.deck-list { display: flex; flex-direction: column; }
.deck-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.deck-item:last-child { border-bottom: none; }
.deck-item.clickable { cursor: pointer; }
.deck-item.clickable:hover .name { color: var(--accent-bright); }
.deck-item .top { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; }
.deck-item .name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.deck-item .fig { font-family: var(--mono); font-size: 0.74rem; color: var(--accent); white-space: nowrap; }
.deck-item .fig.okv { color: var(--ok); }
.deck-item .fig.idlev { color: var(--warn); }
.deck-item .fig.dim { color: var(--text-faint); }
.deck-item .detail {
  font-size: 0.7rem;
  color: var(--text-dim);
  padding-left: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.deck-sub {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  color: var(--text-faint);
  margin-top: 0.2rem;
}

.kv-rows { display: flex; flex-direction: column; gap: 0.45rem; font-size: 0.78rem; }
.kv-rows > div { display: flex; justify-content: space-between; gap: 1rem; }
.kv-rows .k { color: var(--text-dim); }
.kv-rows .v { font-family: var(--mono); color: var(--text); text-align: right; }

/* The storage donut from Screen-1, used for "how much is embedded". A conic
   gradient whose stop is set inline from the live figure. */
.donut-row { display: flex; align-items: center; gap: 1.2rem; }
.donut {
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.donut > span {
  width: 3.9rem;
  height: 3.9rem;
  border-radius: 50%;
  background: var(--bg-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.95rem;
}
.donut-caption { font-family: var(--mono); font-size: 0.82rem; }

.telemetry-body { display: grid; grid-template-columns: minmax(0, 1fr) 10rem; gap: 1rem; }
.chart {
  display: block;
  width: 100%;
  height: 10rem;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
}
.axis { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 0.62rem; color: var(--text-faint); margin-top: 0.5rem; }
.legend { display: flex; gap: 1rem; font-family: var(--mono); font-size: 0.64rem; margin-top: 0.5rem; }
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend i { width: 0.5rem; height: 0.5rem; border-radius: 50%; display: inline-block; }
.legend .l1 { color: var(--accent); } .legend .l1 i { background: var(--accent); }
.legend .l2 { color: var(--accent-2); } .legend .l2 i { background: var(--accent-2); }
.legend .l3 { color: var(--accent-deep); } .legend .l3 i { background: var(--accent-deep); }
.telemetry-side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-left: 1rem;
  border-left: 1px solid var(--border);
  font-family: var(--mono);
}
.telemetry-side .k { font-size: 0.6rem; letter-spacing: 0.1em; color: var(--text-faint); }
.telemetry-side .v { font-size: 1.05rem; color: var(--text); }
.telemetry-side .v.hot { color: var(--accent); }

/* The Overview's chat box: the same transcript and composer as the Chat tab
   (same element ids, same state), held to a fixed height. */
.quick-chat .chat-model-status { padding-bottom: 0.4rem; margin-bottom: 0; font-size: 0.74rem; }
.quick-chat .chat-history { min-height: 15rem; max-height: 22rem; }
.quick-chat .chat-form { margin-top: 0; }
.chat-wrap { position: relative; display: flex; flex-direction: column; min-width: 0; }
.chat-wrap .chat-jump { bottom: 0.5rem; }

/* Focus mode on the Chat tab: the sidebars go and the transcript takes the
   screen. Toggled from the Chat tab or the Overview's expand button. */
body.chat-focus #nav, body.chat-focus .chat-sidebar, body.chat-focus .chat-intro { display: none; }
body.chat-focus #app { max-width: none; }
body.chat-focus .chat-layout { grid-template-columns: minmax(0, 1fr); margin-top: 0.5rem; }
body.chat-focus .chat-history { max-height: calc(100vh - 13rem); min-height: calc(100vh - 13rem); }

/* Agents: the target switch is three radio cards. The host one carries the
   gold identity so "this runs as root" is visible before you type. */
.target-switch { display: flex; gap: 0.6rem; }
.target {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg);
  cursor: pointer;
  min-width: 0;
}
.target input { position: absolute; opacity: 0; pointer-events: none; }
.target .t-title { font-family: var(--mono); font-size: 0.78rem; color: var(--text); }
.target .t-desc { font-size: 0.72rem; color: var(--text-dim); }
.target:hover { border-color: var(--border-strong); }
.target.on { border-color: var(--accent); background: var(--accent-wash); }
.target.on .t-title { color: var(--accent); }
.target.host.on { border-color: var(--host-accent); background: rgba(232, 163, 58, 0.08); }
.target.host.on .t-title { color: var(--host-accent-bright); }

.opt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.6rem 1rem;
}
.opt { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.72rem; color: var(--text-dim); font-family: var(--mono); letter-spacing: 0.04em; }
.opt input, .opt select { width: 100%; }
.opt.check { flex-direction: row; align-items: center; gap: 0.45rem; align-self: end; padding-bottom: 0.5rem; }
.opt.check input { width: auto; accent-color: var(--accent); }

.form-foot { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; }
.seg button { border: none; border-radius: 0; background: none; }
.seg button.on { background: var(--accent-wash); color: var(--accent); }

.kind-tag { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.08em; }
.kind-tag.sandbox { color: var(--accent); }
.kind-tag.host { color: var(--host-accent-bright); }

.status-dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; display: inline-block; flex-shrink: 0; background: var(--text-faint); }
.status-dot.running { background: var(--ok); }
.status-dot.waiting { background: var(--warn); }
.status-dot.failed { background: var(--alert); }

/* Index screen, "what is embedded" (2026-10-03): one panel per shard. */
.breakdown-card .table-wrap { margin-bottom: 0.8rem; }
.breakdown-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 1.5rem; margin-top: 0.6rem; }
@media (max-width: 860px) { .breakdown-grid { grid-template-columns: minmax(0, 1fr); } }

/* Memory -> review (2026-10-08). One card per staged proposal; the neighbour
   the distiller found opens inline under it so a re-telling can be spotted
   without leaving the card. */
.list-toolbar { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.opt.inline { flex-direction: row; align-items: center; gap: 0.45rem; }
.opt.inline select { width: auto; }
.review-howto summary { cursor: pointer; }
.review-howto ol { margin: 0.6rem 0 0.4rem; padding-left: 1.2rem; }
.review-howto li { margin-bottom: 0.35rem; }
.review-card .review-body { white-space: pre-wrap; margin: 0.6rem 0; max-height: 22rem; overflow: auto; }
.review-update { margin: 0.5rem 0; padding-left: 0.6rem; border-left: 1px solid var(--border-strong); }
.review-near { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin: 0.4rem 0; }
.review-evidence { margin: 0.4rem 0; padding-left: 0.6rem; border-left: 2px solid var(--accent); font-style: italic; }
.review-near button.hot { border-color: rgba(255, 82, 82, 0.45); color: var(--alert); }
.review-neighbour { margin: 0.5rem 0 0; background: var(--bg-sunken); }
.review-neighbour .prose { white-space: pre-wrap; max-height: 18rem; overflow: auto; margin-top: 0.4rem; }
.review-actions { margin-top: 0.6rem; }
.review-actions .review-scope-input { width: 16rem; max-width: 100%; }
.review-card.decided { opacity: 0.6; }

/* Config -> settings (2026-10-08): every effective setting, file vs default. */
.cfg-table td.k { font-family: var(--mono); white-space: nowrap; color: var(--text); }
.cfg-table td.v { font-family: var(--mono); word-break: break-word; color: var(--text-dim); }
.cfg-table td.v pre { margin: 0; white-space: pre-wrap; font-size: 0.74rem; }
.cfg-table tr.default td.k { color: var(--text-dim); }
.unit-flags { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.2rem 1rem; font-family: var(--mono); font-size: 0.76rem; }
.unit-flags .f { color: var(--accent); }
.unit-flags .val { color: var(--text-dim); word-break: break-all; }

/* M40: devices (ESP32 bridges) */
#esp-boards, #esp-controls { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1rem; }
#esp-controls .table-wrap { overflow-x: auto; margin-bottom: 0; }
.esp-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.6rem; }
.esp-row label { display: flex; gap: 0.35rem; align-items: center; font-size: 0.78rem; color: var(--text-dim); }
.esp-row input[type="number"] { width: 6rem; }
#esp-cmd { width: 12rem; font-family: var(--mono); }
.esp-args { flex: 1; min-width: 12rem; }
.esp-code { width: 100%; font-family: var(--mono); font-size: 0.8rem; line-height: 1.5; tab-size: 4; }
.esp-pins td { vertical-align: middle; }
.esp-pin-btns { white-space: nowrap; }
.esp-pin-btns button + button { margin-left: 0.25rem; }
.esp-audit-args { max-width: 28rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#esp-audit-filter { max-width: 12rem; font-family: var(--mono); font-size: 0.75rem; }

/* M38: schedules */
.sc-row { padding: 0.6rem 0.2rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.sc-row:hover { background: rgba(255, 255, 255, 0.03); }
.sc-row-main { min-width: 0; }
/* M41 notes (Memory -> notes) */
.note-row { display: flex; gap: 0.6rem; align-items: flex-start; cursor: default; }
.note-row .sc-row-main { flex: 1 1 auto; }
.note-row .actions { flex: 0 0 auto; display: flex; gap: 0.3rem; }
.note-form { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.note-form input[name="text"] { flex: 1 1 16rem; min-width: 0; }
/* M39 approval card: one label/value line per header, then the body as sent. */
.ap-field { display: flex; gap: 0.8rem; padding: 0.2rem 0; overflow-wrap: anywhere; }
.ap-field .hint { flex: 0 0 7.5rem; margin: 0; }
.ap-body { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 28rem; overflow: auto; }
.ap-edit { display: grid; gap: 0.35rem; margin: 0.5rem 0; }
.ap-edit input, .ap-edit textarea { width: 100%; box-sizing: border-box; font: inherit; }
.sc-row:last-child { border-bottom: none; }
.sc-step { margin: 0.4rem 0 0.6rem; }
.sc-message { border-left: 3px solid var(--accent); padding: 0.4rem 0.8rem; margin: 0.6rem 0; }
.sc-run { padding: 0.45rem 0; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: baseline; }
.sc-run:last-child { border-bottom: none; }
.sc-run > div { flex-basis: 100%; }
.sc-actions { margin: 0.8rem 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.sc-actions p { flex-basis: 100%; }

/* ---------- control deck at narrow widths ----------
   These used to sit in the generic responsive block near the top of the
   file, BEFORE the .deck-row / .tile-grid / .telemetry rules they override --
   same specificity, so the later desktop rules won and a phone got the
   Overview squeezed into three or four 100px columns. */
@media (max-width: 1100px) {
  .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .deck-row, .deck-row.three { grid-template-columns: minmax(0, 1fr); }
  .telemetry-body { grid-template-columns: minmax(0, 1fr); }
  .telemetry-side { border-left: none; padding-left: 0; flex-direction: row; flex-wrap: wrap; }
}

/* ---------- Agents tab on a phone held upright (2026-10-14) ----------
   The desktop layout -- four tall tiles, a three-card target switch, a
   one-column option list and a six-column jobs table -- stacked into a very
   long, cramped page. On a phone: the tiles become one compact strip, the job
   list comes right after the form (the model card, reference only, goes
   last), the options sit two to a row, and each job is a card.
   Kept at the END of the file: it overrides control-deck rules (.deck-row,
   .opt-grid, .target) that are defined after the generic responsive block. */
.jobs-table .j-unit { display: none; }

@media (max-width: 700px) {
  .ag-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.4rem; margin-bottom: 0.8rem; }
  .ag-tiles .tile { padding: 0.55rem 0.4rem; gap: 0.25rem; align-items: center; text-align: center; }
  .ag-tiles .tile .label { font-size: 0.56rem; letter-spacing: 0.06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .ag-tiles .tile .value { font-size: 1.25rem; }
  .ag-tiles .tile .sub { display: none; }

  /* Flatten the form/model row so the jobs card can sit between them. */
  .ag-row { display: contents; }
  #app:has(.ag-row) { display: flex; flex-direction: column; }
  .ag-row > #ag-form { order: 1; margin-bottom: 1rem; }
  .ag-jobs { order: 2; }
  .ag-row > .card:not(#ag-form) { order: 3; margin-top: 1rem; }

  #ag-form { gap: 0.7rem; padding: 0.9rem; }
  #ag-form textarea { min-height: 5.5rem; font-size: 1rem; }
  .target-switch { flex-direction: row; gap: 0.35rem; }
  .target { padding: 0.5rem 0.45rem; align-items: center; text-align: center; justify-content: center; }
  .target .t-title { font-size: 0.72rem; }
  .target .t-desc { display: none; }
  .opt-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem 0.7rem; }
  #ag-repo-wrap, #ag-cwd-wrap, #ag-installs-wrap { grid-column: 1 / -1; }
  .form-foot { gap: 0.5rem; }
  .form-foot #ag-submit { flex: 1 1 100%; order: -1; padding: 0.7rem; font-size: 0.95rem; }

  .ag-jobs { padding: 0.9rem; }
  .ag-jobs .card-head { flex-wrap: wrap; gap: 0.5rem; }
  .ag-jobs .seg { width: 100%; }
  .ag-jobs .seg button { flex: 1; padding: 0.45rem 0; }

  /* Each job row becomes a card: status + where on top, the task in full,
     then model / rounds / age in one quiet line. */
  .ag-jobs .table-wrap { border: none; overflow: visible; margin-bottom: 0; }
  .jobs-table thead { display: none; }
  .jobs-table, .jobs-table tbody { display: block; }
  .jobs-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "status where where"
      "task task task"
      "model rounds updated";
    gap: 0.35rem 0.6rem;
    padding: 0.7rem 0.75rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--bg);
  }
  .jobs-table tr:active { border-color: var(--accent-dim); }
  .jobs-table td { display: block; padding: 0; border: none; background: none !important; font-size: 0.76rem; min-width: 0; }
  .jobs-table .j-status { grid-area: status; }
  .jobs-table .j-where { grid-area: where; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .jobs-table .j-task { grid-area: task; font-family: var(--sans); font-size: 0.92rem; color: var(--text); line-height: 1.4; }
  .jobs-table .j-model, .jobs-table .j-rounds, .jobs-table .j-updated { color: var(--text-faint); white-space: nowrap; }
  .jobs-table .j-model { grid-area: model; overflow: hidden; text-overflow: ellipsis; }
  .jobs-table .j-rounds { grid-area: rounds; }
  .jobs-table .j-updated { grid-area: updated; text-align: right; }
  .jobs-table .j-unit { display: inline; }

  /* A job's conversation: give the thread the screen, not a 68vh box under a
     header, and keep the composer usable with the keyboard up. */
  .job-thread { max-height: calc(100dvh - 14rem); min-height: 45dvh; }
  .job-meta { gap: 0.3rem 0.8rem; font-size: 0.74rem; }
  .code-approval-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
  .code-approval-actions button { padding: 0.6rem; }
}

/* Chat on a narrow screen: the avatars cost a fifth of the width. */
@media (max-width: 560px) {
  .chat-turn .avatar { display: none; }
  .chat-turn { gap: 0; }
  .bubble { padding: 0.55rem 0.7rem; }
  .chat-user .bubble { max-width: 88%; }
  .chat-form textarea { font-size: 1rem; } /* <16px makes iOS zoom on focus */
  .chat-history { max-height: calc(100dvh - 16rem); }
}

/* Devices on a narrow screen: drop the role column, let the pin buttons wrap. */
@media (max-width: 560px) {
  .esp-pins td:nth-child(3) { display: none; }
  .esp-pin-btns { white-space: normal; }
  .esp-pin-btns button { margin: 0.1rem 0.15rem 0.1rem 0; }
  .esp-audit-args { max-width: 9rem; }
  .esp-row input[type="number"] { width: 4.5rem; }
  #esp-cmd, .esp-args { width: 100%; flex-basis: 100%; }
  .esp-row > button.primary { width: 100%; }
}

/* M41 notes on a phone: actions under the text, the form one field per line. */
@media (max-width: 560px) {
  .note-row { flex-direction: column; }
  .note-form > * { flex: 1 1 100%; }
}

/* Chat history on a touch screen: there is no hover, so the delete button
   would stay invisible -- and still be tappable at the end of each row. */
@media (hover: none) {
  .chat-sidebar-item .delete-conversation { opacity: 1; }
}

/* ---------- the phone app (M42) ----------
   Installed from Chrome (manifest.webmanifest + sw.js) this page is the phone
   app, so at phone width it is laid out like one: a bottom tab bar with four
   tabs and a More sheet, Chat filling the screen with past chats in a drawer,
   Search with its filters folded behind a button. Kept at the END of the
   file for the cascade reason given above the control-deck block. */
.phone-only, .nav-more { display: none; }
#chat-focus-toggle { margin-left: auto; }
/* The checkbox inside a filter toggle is not a text field: the generic
   `.filters input { width: 100% }` stretched it across the row and pushed
   its label to the far edge. */
.filters .toggle input { width: auto; flex: none; }
.filters .toggle { justify-content: flex-start; }

.more-sheet {
  align-self: flex-end;
  width: 100%;
  max-width: 28rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
  padding: 0.9rem 0.9rem calc(0.9rem + env(safe-area-inset-bottom));
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--r) var(--r) 0 0;
}
.more-sheet a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.85rem 0.3rem;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: var(--r);
}
.more-sheet a svg { width: 22px; height: 22px; }
.more-sheet a.active { color: var(--accent); border-color: var(--accent); }
.more-sheet .more-logout, .more-sheet .more-push { grid-column: 1 / -1; color: var(--text-dim); }

@media (max-width: 700px) {
  .phone-only { display: inline-flex; }
  .overlay:has(.more-sheet) { padding: 0; }

  /* Bottom tab bar: Chat, Search, Agents, Approvals, More. */
  .shell { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  #nav {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    padding: 0 0 env(safe-area-inset-bottom);
    border-top: 1px solid var(--border);
    border-bottom: none;
  }
  #nav .brand-block, #nav .sidebar-foot { display: none; }
  #nav > div:first-child { flex: 1 1 auto; }
  #nav nav { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0; overflow: visible; }
  #nav nav a:not(.tab-primary) { display: none; }
  #nav nav a, #nav nav .nav-more {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.22rem;
    height: var(--tabbar-h);
    padding: 0;
    font: inherit;
    font-size: 0.66rem;
    color: var(--text-dim);
    background: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
  #nav nav a span:not(.nav-badge), #nav nav .nav-more span { display: inline; }
  #nav nav svg { width: 21px; height: 21px; }
  #nav nav a.active, #nav nav .nav-more.active { color: var(--accent); background: none; box-shadow: none; }
  #nav a[data-route="chat"] { order: 1; }
  #nav a[data-route="search"] { order: 2; }
  #nav a[data-route="agents"] { order: 3; }
  #nav a[data-route="approvals"] { order: 4; }
  #nav .nav-more { order: 5; }
  body.kbd-open #nav, body.signed-out #nav { display: none; }
  body.kbd-open .shell, body.signed-out .shell { padding-bottom: 0; }

  #app { padding: calc(0.8rem + env(safe-area-inset-top)) 0.85rem 1.5rem; }
  h1 { font-size: 1.35rem; }
  .tile { padding: 0.8rem; }
  .tile .value { font-size: 1.1rem; }

  /* Chat: the conversation gets the whole screen. */
  body[data-route="chat"] .chat-intro, body[data-route="chat"] #chat-focus-toggle { display: none; }
  body[data-route="chat"] #app { padding-top: calc(0.4rem + env(safe-area-inset-top)); padding-bottom: 0.4rem; }
  body[data-route="chat"] .chat-layout { margin-top: 0; display: block; }
  body[data-route="chat"] .chat-main {
    height: calc(100dvh - var(--tabbar-h) - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 0.8rem);
  }
  body.kbd-open[data-route="chat"] .chat-main { height: calc(100dvh - env(safe-area-inset-top) - 0.8rem); }
  body[data-route="chat"] .chat-main > .block-head { justify-content: space-between; margin: 0 0 0.3rem; }
  body[data-route="chat"] .chat-history { flex: 1 1 auto; min-height: 0; max-height: none; }
  .chat-model-status { gap: 0.35rem; padding-bottom: 0.4rem; margin-bottom: 0.4rem; font-size: 0.74rem; flex-wrap: nowrap; overflow: hidden; }
  .chat-model-status > * { flex-shrink: 0; }
  .model-picker { min-width: 0; flex-shrink: 1; }
  /* The picker already names the model; "kept loaded" is a desktop detail. */
  .chat-model-status:has(.model-picker) > .subtle { display: none; }
  .model-picker .picker-label { display: none; }
  .model-picker select { max-width: 9.5rem; }
  .chat-form { margin-top: 0.4rem; padding-top: 0.5rem; gap: 0.4rem; }
  .chat-form textarea {
    min-height: 2.9rem;
    padding: 0.7rem 0.95rem;
    font-size: 16px; /* under 16px, mobile browsers zoom in on focus */
    border-radius: 1.45rem;
  }
  .chat-form button { min-height: 2.9rem; border-radius: 1.45rem; padding: 0 1.1rem; }
  .chat-jump { bottom: 4.2rem; }

  /* Past chats: a drawer from the left, over a dimmed page (body::after,
     which app.js closes the drawer on). */
  .chat-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 70;
    width: min(86vw, 22rem);
    padding: calc(1rem + env(safe-area-inset-top)) 0.9rem 1rem;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
  }
  body.chat-drawer-open .chat-sidebar { transform: none; }
  body.chat-drawer-open::after { content: ""; position: fixed; inset: 0; z-index: 65; background: rgba(5, 5, 8, 0.6); }
  .chat-sidebar-list { flex-direction: column; overflow-x: hidden; overflow-y: visible; max-height: none; }
  .chat-sidebar-item { min-width: 0; }

  /* Search: one big field, filters behind the Filters button. */
  .searchbar { gap: 0.4rem; margin-top: 0.6rem; }
  .search-field input { font-size: 16px; padding: 0.8rem 0; }
  .searchbar button { padding: 0 0.85rem; }
  .filters.open { grid-template-columns: 1fr 1fr; }
  .filters.open .toggle { grid-column: span 1; padding: 0.55rem 0.6rem; }
  .filters input, .filters select { font-size: 16px; padding: 0.5rem 0.6rem; }
  .result { padding: 0.6rem 0.7rem; }
}

/* Fingerprint login (M42): the button above the password form, and the
   "or ..." line that separates the two ways in. */
.auth-passkey { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.8rem 0 0.4rem; }
.auth-passkey button { padding: 0.75rem; font-size: 0.95rem; }
.auth-or { text-align: center; margin: 0.2rem 0 0; }

/* ---------- the clean pass on wide screens (2026-11-07) ----------
   What made the phone app feel clean, brought to the desktop: the chat is a
   chat app (full height, a readable centred column, a real composer), the
   sidebar separates the daily screens from the System ones, decoration stays
   on the Overview, and options fold until they are needed. */

.nav-badge {
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.3rem;
  border-radius: 0.6rem;
  background: var(--accent);
  color: var(--bg);
  font-family: var(--mono);
  font-size: 0.64rem;
  font-weight: 700;
  line-height: 1.15rem;
  text-align: center;
}
/* Beats the narrow-width `#nav a span { display: none }` that hides the labels. */
#nav a .nav-badge:not([hidden]) { display: inline-block; margin-left: auto; }
.nav-badge[hidden] { display: none; }

.nav-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0.9rem 0 0.2rem;
  padding: 0.3rem 0.75rem;
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  border-radius: 0;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
}
.nav-group:hover { color: var(--text-dim); background: none; }
.nav-group .caret { transition: transform 0.15s; }
body.nav-system-folded .nav-group .caret { transform: rotate(-90deg); }
body.nav-system-folded #nav a.nav-sys:not(.active) { display: none; }

/* Folded options: Search's filters, the Agents tab's job options. */
.filters:not(.open) { display: none; }
#filters-toggle { align-items: center; justify-content: center; background: var(--bg-raised); border: 1px solid var(--border); color: var(--text-dim); }
#filters-toggle[aria-expanded="true"] { color: var(--text); border-color: var(--border-strong); }

.ag-options > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.45rem 0.1rem;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.76rem;
}
.ag-options > summary::-webkit-details-marker { display: none; }
.ag-options[open] > summary .caret { display: inline-block; transform: rotate(90deg); }
.ag-options[open] { display: flex; flex-direction: column; gap: 0.8rem; }
.ag-models-card > summary { list-style: none; cursor: pointer; }
.ag-models-card > summary::-webkit-details-marker { display: none; }
.ag-models-card[open] > summary .caret { display: inline-block; transform: rotate(90deg); }
.ag-models-card:not([open]) > summary { margin-bottom: 0; }

/* Decoration belongs to the Overview; elsewhere the title is enough. */
body:not([data-route="overview"]) .deck-head .crumb,
body:not([data-route="overview"]) .ticker { display: none; }

@media (min-width: 701px) {

  /* Chat: the main sidebar becomes an icon rail, the conversation gets the
     height of the window and a centred, readable column. */
  body[data-route="chat"] #nav { width: 64px; padding: 1rem 0.5rem; }
  body[data-route="chat"] #nav .brand-block,
  body[data-route="chat"] #nav .nav-group,
  body[data-route="chat"] #nav a span:not(.nav-badge),
  body[data-route="chat"] #nav-health span:not(.dot),
  body[data-route="chat"] #palette-open,
  body[data-route="chat"] #logout { display: none; }
  body[data-route="chat"] #nav a { justify-content: center; padding: 0.6rem; position: relative; }
  body[data-route="chat"] #nav a .nav-badge { position: absolute; top: 0.1rem; right: 0.1rem; margin: 0; }
  body[data-route="chat"] .sidebar-foot { align-items: center; }
  body.nav-system-folded[data-route="chat"] #nav a.nav-sys:not(.active) { display: flex; }

  body[data-route="chat"] #app { max-width: none; padding: 1rem 1.25rem; height: 100vh; }
  body[data-route="chat"] .chat-intro { display: none; }
  body[data-route="chat"] .chat-layout {
    grid-template-columns: 270px minmax(0, 1fr);
    height: 100%;
    margin-top: 0;
    align-items: stretch;
  }
  body[data-route="chat"] .chat-sidebar { position: static; min-height: 0; }
  body[data-route="chat"] .chat-sidebar-list { flex: 1 1 auto; max-height: none; min-height: 0; }
  body[data-route="chat"] .chat-main { min-height: 0; height: 100%; }
  body[data-route="chat"] .chat-main > .block-head { position: absolute; top: 0; left: 0; margin: 0; z-index: 2; }
  body[data-route="chat"] .chat-model-status {
    justify-content: flex-end;
    padding: 0.1rem 0 0.5rem 7rem;
    font-size: 0.76rem;
  }
  body[data-route="chat"] .chat-model-status:has(.model-picker) > .subtle { display: none; }
  body[data-route="chat"] .model-picker { margin-left: 0.4rem; }
  /* Padding, not a max-width, centres the turns: the scrollbar stays at the
     window's edge where the wheel expects it. */
  body[data-route="chat"] .chat-history {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    padding: 0.5rem max(0.5rem, calc((100% - 800px) / 2)) 1rem;
  }
  body.chat-focus[data-route="chat"] .chat-history { min-height: 0; max-height: none; }
  body[data-route="chat"] .chat-form {
    width: 100%;
    max-width: 800px;
    margin: 0.4rem auto 0;
    padding-top: 0;
    border-top: none;
  }
  body[data-route="overview"] .chat-form textarea { border-radius: 1.4rem; padding: 0.75rem 1rem; }
  body[data-route="overview"] .chat-form button { border-radius: 1.4rem; min-height: 2.8rem; padding: 0 1.2rem; }
  body[data-route="chat"] .chat-form textarea {
    min-height: 3.3rem;
    padding: 0.9rem 1.15rem;
    font-size: 1rem;
    border-radius: 1.65rem;
  }
  body[data-route="chat"] .chat-form button { min-height: 3.3rem; border-radius: 1.65rem; padding: 0 1.4rem; }
  body[data-route="chat"] .chat-jump { bottom: 5rem; }

  /* Agents: the four tiles become one quiet strip; the form spans the width
     with its options folded, so the job list is on screen without scrolling. */
  .ag-tiles { gap: 0.6rem; margin-bottom: 0.9rem; }
  .ag-tiles .tile { flex-direction: row; align-items: baseline; gap: 0.7rem; padding: 0.6rem 0.9rem; }
  .ag-tiles .tile .value { font-size: 1.35rem; order: -1; }
  .ag-tiles .tile .sub { display: none; }
  .ag-row > #ag-form textarea { min-height: 4.2rem; }
  #app:has(.ag-row) { display: flex; flex-direction: column; }
  .ag-jobs { order: 2; margin-top: 1rem; }
  .ag-row:has(.ag-models-card) { display: contents; }
  .ag-row > #ag-form { order: 1; }
  .ag-row > .ag-models-card { order: 4; margin-top: 1rem; }

  /* Recently modified: one line per file -- path, tags, age. */
  a.result { display: flex; align-items: center; gap: 0.8rem; padding: 0.5rem 0.85rem; }
  a.result .row-top { display: contents; }
  a.result .path { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  a.result .meta { order: 2; margin: 0; flex-wrap: nowrap; }
  a.result .score { order: 3; min-width: 4.5rem; text-align: right; }
  .results:has(> a.result) { gap: 0.35rem; }
}

@media (max-width: 700px) {
  #nav nav .nav-group { display: none; }
  #nav nav a { position: relative; }
  #nav nav a .nav-badge { position: absolute; top: 0.35rem; left: calc(50% + 0.35rem); margin: 0; }
}
