/* =============================================================================
   Chat, wherever it appears: the panel on every page, the sleeve's Chat tab, and
   the chips, cards and cost lines an answer carries.

   The panel is part of the app frame, not a card floating over it. At 1024px and
   up it is the second grid column, running from the masthead to the foot of the
   viewport; the page reflows beside it and nothing is ever read through it. When
   collapsed it keeps a 48px rail, so the page still knows where chat is without
   covering any of it. Below 1024px it is a bar at the foot of the page — the page
   reserves that height, so the bar sits under the content rather than over it —
   and an opened panel becomes a full-screen sheet with its own header and the
   composer pinned above the home indicator.

   Loaded after console.css, so it inherits the console's form base and replaces
   the chat shell with a real conversation. No framework, no build.
   ============================================================================= */

:root {
  /* The panel's width is a choice, not a constant: a handle on its left edge sets --chat-w, and
     the three numbers below are the fences around that choice. The panel is a grid column, so
     widening it narrows the page's own column; it never narrows the *viewport*, and every
     breakpoint stays keyed to the viewport — a chat that demotes the data grid to the mobile
     layout is worse than no chat. That is why the ceiling is a share of the window as well as a
     number of pixels, and why the page's minimum always beats the panel's maximum. */
  --chat-w: 360px;
  --chat-min: 320px;
  --chat-max: 640px;
  --chat-rail: 48px;
  --chat-bar: 56px;
}

/* ---- One exchange: the question, the answer, what it read, what it cost. ------------------- */

.exchange {
  display: grid;
  gap: 12px;
  padding: 18px 0 16px;
  border-bottom: 1px solid var(--rule);
}
.exchange:first-of-type { padding-top: 4px; }
.exchange:last-of-type { border-bottom: 0; }
.turn { min-width: 0; }
.turn-k {
  margin: 0 0 6px;
  color: var(--muted);
  font: 500 9px/1.3 var(--mono);
  letter-spacing: 0.13em;
  text-transform: uppercase;
}
/* The question is the only thing in a box: it is the line the reader wrote, and it is the thing
   they scan back for. */
.turn-you { position: relative; }
.turn-you .turn-text {
  margin: 0;
  max-width: 62ch;
  padding: 9px 12px 9px 13px;
  border-left: 2px solid var(--rule-strong);
  border-radius: 0 4px 4px 0;
  background: color-mix(in srgb, var(--accent-soft) 55%, transparent);
  color: var(--ink);
  font: 500 13.5px/1.55 var(--sans);
  overflow-wrap: anywhere;
}
.turn-when {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font: 10px/1.4 var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.exchange:hover .turn-when,
.exchange:focus-within .turn-when { opacity: 1; }
/* No hover on touch: the time is not hidden from a reader who cannot point at it. */
@media (hover: none) {
  .turn-when { opacity: 0.75; }
}
/* The answer is prose, not a bubble: full width of its column, capped at a readable measure. */
.turn-desk { position: relative; }
.turn-answer {
  max-width: 70ch;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.62;
}
.turn-answer p { margin: 0 0 10px; overflow-wrap: anywhere; }
.turn-answer p:last-child { margin-bottom: 0; }
.turn-list { margin: 0 0 10px; padding-left: 18px; max-width: 70ch; }
.turn-list li { margin: 0 0 5px; line-height: 1.55; overflow-wrap: anywhere; }
.turn-list li:last-child { margin-bottom: 0; }

/* A date, where the calendar changes. It gives the hover times a day to belong to. */
.thread-day {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 20px 0 6px;
  color: var(--muted);
  font: 600 9.5px/1.4 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.thread-day::before,
.thread-day::after { content: ""; flex: 1 1 auto; height: 1px; background: var(--rule); }
.thread-day:first-child { margin-top: 2px; }

/* The footer is the spec's line, once per answer: model, effort, calls, tokens, money. */
.turn-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 0;
  margin: 10px 0 0;
  color: var(--muted);
  font: 10.5px/1.6 var(--mono);
  font-variant-numeric: tabular-nums;
}
.turn-foot > span + span::before { content: " · "; opacity: 0.6; }
.foot-model { color: var(--ink); font-weight: 600; }
.turn-foot .unknown { font-style: italic; }

/* ---- The trace: one resting line, expanding to the reads behind it. ------------------------- */

.trace { margin: 12px 0 0; }
.trace > summary {
  min-height: 28px;
  padding: 4px 0;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
  font: 10.5px/1.5 var(--mono);
}
.trace > summary::-webkit-details-marker { display: none; }
.trace > summary::before {
  content: "+";
  display: inline-block;
  width: 11px;
  color: var(--muted);
  font-weight: 600;
}
.trace[open] > summary::before { content: "−"; }
.trace > summary:hover { color: var(--ink); }
.trace .chips { margin-top: 6px; }

/* ---- Chips: "read 14 orders", a fold to the query and the digest of the result. ------------ */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}
.chip { min-width: 0; }
.chip-fold {
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: var(--bg);
}
.chip-fold[open] { border-radius: 9px; }
.chip-fold > summary {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  min-height: 30px;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  list-style: none;
  font: 10.5px/1.4 var(--mono);
  color: var(--ink);
  white-space: nowrap;
}
.chip-fold > summary::-webkit-details-marker { display: none; }
.chip-fold > summary::after {
  content: "+";
  color: var(--muted);
  font-weight: 600;
}
.chip-fold[open] > summary { border-bottom: 1px solid var(--rule); border-radius: 9px 9px 0 0; }
.chip-fold[open] > summary::after { content: "−"; }
.chip-fold > summary:hover { background: var(--accent-soft); }
.chip-verb { color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; font-size: 9px; }
.chip-n { color: var(--accent); font-weight: 700; }
.chip-noun { color: var(--ink); }
.chip-x { color: var(--muted); font-weight: 600; font-size: 9.5px; }
.chip-body { padding: 8px 11px 9px; }
.chip-call + .chip-call {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--rule);
}
.chip-args,
.chip-digest {
  margin: 0;
  color: var(--muted);
  font: 10px/1.55 var(--mono);
  overflow-wrap: anywhere;
}
.chip-digest { opacity: 0.8; }

/* ---- The records behind an answer, folded: the ids a reader can go and check. --------------- */

.sources { margin: 10px 0 0; }
.sources > summary {
  min-height: 28px;
  padding: 4px 0;
  color: var(--accent);
  cursor: pointer;
  font: 10.5px/1.5 var(--mono);
}
.sources ul {
  margin: 0;
  padding: 0 0 0 2px;
  list-style: none;
  display: grid;
  gap: 3px;
}
.sources li {
  color: var(--muted);
  font: 10.5px/1.5 var(--mono);
  overflow-wrap: anywhere;
}

/* ---- The thread: a scroller of its own, inside the panel. ---------------------------------- */

.chat-thread {
  min-height: 220px;
  padding: 18px 20px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--panel);
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.chat-scroll {
  flex: 1 1 auto;
  min-height: 0;
  /* The bottom padding is the gap between the last line of the thread and the composer's rule:
     the composer is a sibling, not an overlay, but a thread scrolled to its end must not end
     flush against the field's edge. 20px is a line and a half at this size. */
  padding: 16px 18px 20px;
  scroll-padding-block-end: 20px;
  border: 0;
  border-radius: 0;
  background: transparent;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.chat-scroll .exchange { padding: 14px 0 14px; }
.chat-scroll .turn-answer { font-size: 13.5px; }
.chat-scroll .chip-fold > summary { min-height: 26px; padding: 4px 9px; font-size: 10px; }
.chat-scroll .chip-verb { font-size: 8.5px; }
.chat-empty { padding: 10px 0 2px; }
/* Three starter pills replace a paragraph. That is the whole empty state. */
.chat-suggests {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.chat-suggest-form { display: contents; }
.chat-suggest {
  min-height: 38px;
  padding: 7px 14px;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
  font: 12.5px/1.3 var(--sans);
  text-align: left;
}
.chat-suggest:hover { border-color: var(--accent); background: var(--accent-soft); }
.thread-earlier {
  margin: 0 0 12px;
  padding: 7px 10px;
  border: 1px dashed var(--rule-strong);
  border-radius: 6px;
  color: var(--muted);
  font: 10.5px/1.5 var(--mono);
}
.thread-totals {
  margin: 12px 0 0;
  padding-top: 9px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font: 10.5px/1.5 var(--mono);
  font-variant-numeric: tabular-nums;
}

/* ---- The composer: one field, the send control inside it. ---------------------------------- */

.composer textarea:focus-visible { outline: none; }
.composer-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.composer-tools {
  position: absolute;
  right: 7px;
  bottom: 7px;
  display: flex;
  align-items: center;
}
.composer-send {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.composer-send:hover { background: var(--accent); }
.composer-send:disabled { background: var(--rule-strong); color: var(--panel); cursor: default; }
.composer-send[data-mode="stop"] { background: var(--accent); }
.composer-send[data-mode="stop"]:hover { background: var(--halt-ink); }
.glyph { display: block; }
.glyph-stop { display: none; }
.composer-send[data-mode="stop"] .glyph-send { display: none; }
.composer-send[data-mode="stop"] .glyph-stop { display: block; }
.composer-keys,
.composer-note,
.composer-block {
  margin: 0;
  color: var(--muted);
  font: 10.5px/1.5 var(--mono);
}
.composer-note,
.composer-block { max-width: 54ch; }

/* ---- A composer with no model behind it. ---------------------------------------------------
   A refusal is not a hint: the shell takes the halt border and the halt tint the desk already
   uses for a refused move, and the reason is set in the halt ink. The field and the send control
   are disabled in the markup, so this state is honest before and without the script. Nothing
   animates: a disabled control has nowhere to go, and motion would read as an invitation. */
.composer-blocked { border-color: var(--halt-rule); background: var(--halt-bg); }
.composer-blocked .composer-field,
.composer-blocked .composer-field:focus-within {
  border-color: var(--halt-rule);
  background: var(--panel);
  box-shadow: none;
}
.composer-blocked .composer-send,
.composer-blocked .composer-send:disabled {
  background: var(--halt-rule);
  color: var(--panel);
}
.composer-block { color: var(--halt-ink); font-weight: 600; }
.composer-blocked .composer-note { color: var(--halt-ink); }
/* The dock's composer is edge to edge: the base rule is a top border, so the state thickens that
   rule rather than drawing a box the panel does not have. Equal-plus specificity to the panel's
   own composer rule, which would otherwise strip it back to one grey pixel. */
.chat-panel .composer.composer-blocked {
  border-top: 2px solid var(--halt-rule);
  background: var(--halt-bg);
}

/* ---- The model row: provider, model, effort — the composer's one setting. -------------------
   Three quiet selects under the field, in the same micro mono as the hint above them. They are
   deliberately not a settings panel: no box, no legend, no prose. The row is a sentence you can
   change ("deepseek · deepseek-chat · medium"), so it is set like one.

   The panel is 340–400px wide, so the three share one line evenly and a long model name truncates
   in the closed control (the open list still shows every name in full). Giving the provider its
   own content width — the longest option is a variable name — would push the row onto two lines
   on every desktop, so the basis is 0 and the names ellipsis instead. Save drops to a second line
   only when it has something to do. Nothing here can grow past the panel, so the send control
   above is never pushed off the screen. */
.composer-llm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 4px 6px;
  margin: 8px 0 0;
  min-width: 0;
}
.composer-llm select {
  flex: 1 1 0;
  min-width: 0;
  max-width: 100%;
  height: 24px;
  padding: 0 18px 0 7px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font: 10.5px/1 var(--mono);
  text-overflow: ellipsis;
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease;
}
.composer-llm [data-llm-provider] { flex-grow: 1.1; }
.composer-llm [data-llm-model] { flex-grow: 1.4; }
.composer-llm select:hover { border-color: var(--rule-strong); color: var(--ink); }
.composer-llm select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  color: var(--ink);
}
/* A provider this desk holds no key for is listed and named, and cannot be chosen. Italic in the
   open list says "here, but not available" without a second colour doing the same job. */
.composer-llm option:disabled { color: var(--muted); font-style: italic; }
.composer-llm .llm-save {
  flex: 0 0 auto;
  height: 24px;
  padding: 0 9px;
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font: 600 10px/1 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.composer-llm .llm-save:hover { border-color: var(--ink); }
.composer-llm .llm-save:disabled { border-color: var(--rule); color: var(--muted); cursor: default; }
.composer-llm .llm-save[hidden] { display: none; }

/* A phone's composer is too narrow for three names on one line: 320px leaves each select about
   eight characters, which truncates every one of them to a stub. Two even columns instead —
   provider beside model, effort below at the same width — keeps every name readable and adds one
   24px line to a composer that has the room (the thread above it scrolls). The send control is in
   the field above and cannot be reached by this row at any width. */
@media (max-width: 359px) {
  .composer-llm {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    justify-content: stretch;
  }
  .composer-llm select { flex: none; width: 100%; }
  .composer-llm .llm-save { justify-self: start; }
}

.chat-thinking {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  margin: 10px 0 0;
  color: var(--ink);
  font: 11px/1.5 var(--mono);
}
.chat-thinking[hidden] { display: none; }
/* The step is the determinate part: it names what the desk is doing, rather than spinning. */
.think-step { font-weight: 600; }
.think-step::after { content: "…"; }
.think-note { color: var(--muted); font-size: 10px; }
.chat-error {
  margin: 12px 0 0;
  padding: 11px 13px;
  border: 1px solid var(--halt-rule);
  border-radius: 8px;
  background: var(--halt-bg);
  color: var(--halt-ink);
}
.chat-error p { margin: 0; font-size: 12.5px; line-height: 1.55; }
.chat-error .chat-error-k {
  margin-bottom: 4px;
  font: 600 9.5px/1.4 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
@media (prefers-reduced-motion: reduce) {
  .chat-thread, .chat-scroll { scroll-behavior: auto; }
}

/* ---- Operator spend: the desk's own bill, by purse and by model. ---------------------------- */

table.spend {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--panel);
}
table.spend th,
table.spend td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  font: 11.5px/1.45 var(--mono);
  vertical-align: top;
}
table.spend thead th {
  border-bottom: 1px solid var(--rule-strong);
  color: var(--muted);
  font-weight: 600;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}
table.spend td.num,
table.spend th.num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
table.spend tbody tr:last-child td { border-bottom: 0; }
table.spend .spend-model { font-weight: 600; overflow-wrap: anywhere; }
table.spend .spend-total { color: var(--ink); font-weight: 600; }
table.spend .spend-unpriced .spend-total { color: var(--stale); }
.spend-note {
  margin: 9px 0 0;
  color: var(--muted);
  font: 10.5px/1.55 var(--mono);
  font-variant-numeric: tabular-nums;
}
.spend-note .unknown { font-style: italic; }

/* =============================================================================
   The panel. Mobile first: it is a bar at the foot, and an opened panel is a
   sheet. The desktop column is the media query at the end of this block.
   ============================================================================= */

.chat-panel {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--rule-strong);
  background: var(--panel);
  box-shadow: 0 -14px 34px -30px rgba(0, 0, 0, 0.55);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* The closed state: one tap target, the scope, and a chevron. It is in the layout, not over it. */
.chat-open {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--chat-bar);
  padding: 0 18px;
  color: var(--ink);
  text-decoration: none;
}
.chat-open:hover { color: var(--ink); background: var(--accent-soft); }
.chat-open-k {
  color: var(--accent);
  font: 600 9.5px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.chat-open-scope {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  margin-right: auto;
  font: 600 13px/1.3 var(--mono);
  overflow-wrap: anywhere;
}
.chat-open-chev {
  width: 8px;
  height: 8px;
  border-top: 1.5px solid var(--muted);
  border-left: 1.5px solid var(--muted);
  transform: rotate(45deg) translate(1px, 1px);
}
/* The open-proposal count that used to sit on the Chat tab. It belongs beside the control that
   opens the thread now: a number on a tab nobody can open was a dead end. */
.chat-open-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 17px;
  padding: 0 5px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font: 600 9.5px/1 var(--mono);
  letter-spacing: 0;
  opacity: 0.8;
}

/* The sheet: the whole screen, its own header, the composer above the home indicator. */
.chat-panel[data-state="open"] {
  top: 0;
  border-top: 0;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35);
  padding-bottom: 0;
}
.chat-panel[data-state="open"] .chat-open { display: none; }
.chat-panel .chat-panel-in { display: none; }
.chat-panel[data-state="open"] .chat-panel-in {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding-top: env(safe-area-inset-top, 0px);
}
/* The page does not scroll behind an open sheet. */
@media (max-width: 1023px) {
  body:has(.chat-panel[data-state="open"]) { overflow: hidden; }
}

.chat-head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 12px;
  min-height: var(--chat-bar);
  padding: 10px 12px 10px 18px;
  border-bottom: 1px solid var(--rule);
}
.chat-head-id { display: flex; flex-direction: column; gap: 3px; min-width: 0; margin-right: auto; }
.chat-k {
  margin: 0;
  color: var(--accent);
  font: 600 9px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.chat-scope {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--ink);
  font: 600 13px/1.25 var(--mono);
  overflow-wrap: anywhere;
}
.chat-dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.chat-close {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--rule);
  border-radius: 9px;
  color: var(--muted);
}
.chat-close:hover { color: var(--ink); border-color: var(--rule-strong); background: var(--accent-soft); }
.chat-close-glyph { position: relative; width: 11px; height: 11px; }
.chat-close-glyph::before,
.chat-close-glyph::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 1.5px;
  background: currentColor;
  transform: rotate(45deg);
}
.chat-close-glyph::after { transform: rotate(-45deg); }

/* The one-time line: the panel followed the page to a new scope. Quiet, and not a control. */
.chat-switch {
  flex: 0 0 auto;
  margin: 0;
  padding: 8px 18px;
  border-bottom: 1px solid var(--rule);
  background: var(--accent-soft);
  color: var(--muted);
  font: 11px/1.4 var(--mono);
}

.chat-panel .composer {
  flex: 0 0 auto;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  border: 0;
  border-top: 1px solid var(--rule);
  border-radius: 0;
  background: var(--panel);
}
.chat-panel .composer textarea { font-size: 13.5px; }
.chat-panel .composer-foot { margin-top: 7px; }

/* A proposal card inside a 340px column: one column, full-width buttons. */
.chat-panel .move { padding: 12px; border-radius: 8px; }
.chat-panel .decision-form { grid-template-columns: minmax(0, 1fr); }
.chat-panel .approve-fields { grid-template-columns: minmax(0, 1fr); }
.chat-panel .actions { flex-direction: column; }
.chat-panel .actions .btn { flex-basis: auto; width: 100%; min-height: 44px; }
.chat-panel .facts { grid-template-columns: minmax(0, 1fr); gap: 8px; }
.chat-panel .move-outcome { font-size: 11.5px; }
.chat-panel .move-refused { font-size: 12px; }

/* Room for the bar, so the last line of the page is never behind it. */
@media (max-width: 1023px) {
  body { padding-bottom: calc(var(--chat-bar) + 28px + var(--safe-b)); }
}

/* ---- 1024px and up: the panel is a column of the app frame. -------------------------------- */

@media (min-width: 1024px) {
  .chat-panel {
    position: relative;
    inset: auto;
    /* The clamp is the contract: the stored width, then the panel's own ceiling, then the window's
       share — whichever is smallest. The window share is what keeps the page above its 480px
       one-column point at 1024 (45% of 1024 is 460, leaving the page 564). */
    --chat-fit: clamp(var(--chat-min), var(--chat-w), min(var(--chat-max), 45vw));
    width: var(--chat-rail);
    height: 100%;
    min-height: 0;
    padding-bottom: 0;
    border-left: 1px solid var(--rule);
    background: var(--bg);
    box-shadow: none;
  }
  .chat-open {
    flex-direction: column;
    justify-content: flex-start;
    gap: 12px;
    height: 100%;
    min-height: 0;
    padding: 16px 0 12px;
  }
  .chat-open-k { writing-mode: vertical-rl; letter-spacing: 0.2em; }
  .chat-open-scope { display: none; }
  .chat-open-chev {
    margin-top: auto;
    transform: rotate(-45deg) translate(1px, 1px);
  }
  .chat-panel[data-state="open"],
  .chat-panel[data-state="auto"] {
    width: var(--chat-fit);
    border-left: 1px solid var(--rule-strong);
    background: var(--panel);
    /* The sheet's dimming shadow belongs to the sheet. A column does not cast it. */
    box-shadow: none;
  }
  .chat-panel[data-state="open"] .chat-open { display: none; }
  .chat-panel[data-state="open"] .chat-panel-in {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    padding-top: 0;
  }
  /* `auto` at this width has not been chosen either way, so it is the rail until 1280. */
  .chat-panel[data-state="auto"] .chat-panel-in { display: none; }
  .chat-panel[data-state="auto"] .chat-open { display: flex; }
  .chat-close-glyph { transform: rotate(0deg); }
}

/* ---- The width handle: the panel's left edge, desktop only. --------------------------------
   Six pixels of hit area straddling the border, a line that appears when it is reached, and a
   grip that says what it does. Below 1024 the panel is a sheet with no width to choose, so the
   script removes the element from the document outright; `display:none` here only covers the
   frames before that runs, and keeps it out of the tab order in the meantime. */

.chat-split { display: none; }

@media (min-width: 1024px) {
  .chat-split {
    position: absolute;
    z-index: 31;
    top: 0;
    bottom: 0;
    left: -3px;
    display: block;
    width: 6px;
    border: 0;
    background: transparent;
    cursor: col-resize;
    touch-action: none;
  }
  .chat-split::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 2px;
    width: 2px;
    background: transparent;
    transition: background 0.12s ease;
  }
  .chat-split::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 1px;
    width: 4px;
    height: 30px;
    margin-top: -15px;
    border-radius: 2px;
    background: repeating-linear-gradient(
      to bottom,
      var(--rule-strong) 0 2px,
      transparent 2px 6px
    );
    opacity: 0;
    transition: opacity 0.12s ease;
  }
  .chat-split:hover::before,
  .chat-split:focus-visible::before,
  .chat-split[data-dragging="true"]::before { background: var(--accent); }
  .chat-split:hover::after,
  .chat-split:focus-visible::after,
  .chat-split[data-dragging="true"]::after { opacity: 1; }
  .chat-split:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
  }
  /* A closed panel at this width is a 48px rail: there is no width to choose until it is open,
     so the handle goes away rather than inviting a drag that would move nothing. */
  .chat-panel[data-state="closed"] .chat-split { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-split::before,
  .chat-split::after { transition: none; }
}

/* While a drag is in progress: no text selected anywhere, and the cursor stays a handle even
   where the pointer has left the strip. Set for the length of the gesture and removed after. */
body[data-chat-drag] {
  cursor: col-resize;
  user-select: none;
  -webkit-user-select: none;
}
body[data-chat-drag] * { cursor: col-resize !important; }

@media (min-width: 1280px) {
  .chat-panel[data-state="auto"] { width: var(--chat-fit); }
  .chat-panel[data-state="auto"] .chat-open { display: none; }
  .chat-panel[data-state="auto"] .chat-panel-in {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
  }
}

/* A very wide desk: the panel grows inside its 360–400px range, and the reading column keeps
   its measure. The page's own column is what gives way, never the breakpoints. */
@media (min-width: 1440px) {
  :root { --chat-w: 380px; }
}
@media (min-width: 1680px) {
  :root { --chat-w: 400px; }
}

@media (max-width: 719px) {
  .exchange { padding: 14px 0 12px; }
  .turn-you .turn-text { padding: 8px 10px 8px 11px; }
  .chip-fold > summary { min-height: 34px; }
  .chat-scroll { padding: 14px 15px 18px; }
  .composer-send { width: 40px; height: 40px; border-radius: 11px; }
  .composer-tools { right: 6px; bottom: 6px; }
  /* 16px keeps iOS from zooming the page when the composer takes focus. */
  .composer textarea { font-size: 16px; }

  /* The same rule as the desk's tables: a row becomes a card, never a sideways scroll. */
  table.spend,
  table.spend tbody { display: block; width: 100%; }
  table.spend thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  table.spend { border: 0; background: transparent; }
  table.spend tr {
    display: block;
    margin: 0 0 8px;
    padding: 2px 12px;
    border: 1px solid var(--rule);
    border-radius: 8px;
    background: var(--panel);
  }
  table.spend tr:last-child { margin-bottom: 0; }
  table.spend td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid var(--rule);
    text-align: right;
    white-space: normal;
  }
  table.spend td:last-child { border-bottom: 0; }
  table.spend td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--muted);
    font: 500 9px/1.4 var(--mono);
    letter-spacing: 0.09em;
    text-transform: uppercase;
    text-align: left;
  }
  table.spend td.spend-model {
    font-size: 13px;
    padding-top: 8px;
  }
}

/* The command bar's ⌘K control in the masthead. It is a button, not a link: it opens the panel
   and puts the caret in the field, and the panel's own open/closed choice is still a link so it
   works with the script off. */
.command-open {
  font: inherit;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--ink-soft, #5c5c56);
  background: var(--paper, transparent);
  border: 1px solid var(--rule, #d9d9d3);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}
.command-open:hover {
  color: var(--ink, #1d1d1b);
  border-color: var(--rule-strong, #b9b9b1);
}
.command-open:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* One command answer: the lead, the row or table, the buttons, one footer. No cost line, no
   token count, no record markers in the prose — the records are behind the footer's fold. */
.command-answer .command-lead {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  line-height: 1.45;
}
.command-hypo {
  margin: 0 0 0.75rem;
  font-style: italic;
  color: var(--wait, #8a6d1f);
}
.command-fields {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1rem;
  margin: 0 0 0.9rem;
}
.command-fields > div {
  display: contents;
}
.command-fields dt {
  color: var(--ink-soft, #5c5c56);
  font-size: 0.8rem;
  padding-top: 0.15rem;
}
.command-fields dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}
.command-table-wrap {
  overflow-x: auto;
  margin: 0 0 0.9rem;
}
.command-table {
  border-collapse: collapse;
  font-size: 0.85rem;
  width: 100%;
}
.command-table th,
.command-table td {
  text-align: left;
  padding: 0.3rem 0.6rem 0.3rem 0;
  border-bottom: 1px solid var(--rule, #e6e6e0);
  white-space: nowrap;
}
.command-table th {
  font-weight: 600;
  color: var(--ink-soft, #5c5c56);
  font-size: 0.75rem;
}
.command-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.25rem 0 0.9rem;
}
.command-action {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
}
.command-action button {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--rule-strong, #b9b9b1);
  background: var(--paper, #fff);
  cursor: pointer;
}
.command-action button:hover {
  border-color: var(--ink, #1d1d1b);
}
.command-effect {
  font-size: 0.75rem;
  color: var(--ink-soft, #5c5c56);
}
.command-foot {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  color: var(--ink-soft, #5c5c56);
}
.command-records ul {
  margin: 0.3rem 0 0;
  padding-left: 1rem;
}
.command-records code {
  font-size: 0.72rem;
}
