/* ==========================================================================
   ask.css: Home as a chat about the working study (web/modules/ask-chat.js,
   web/modules/ask-evidence.js; docs/ask/DESIGN.md).

   Built on the tokens of command-center.css and nothing else. A chat screen:
   the person's conversations in a rail on the left, the conversation in a
   centred reading column, the question box docked at its foot. The one distinctive device is the read
   trace: each read is a point on a thin rule that grows while a question runs,
   and the answer card keeps that rule on its left edge in the verdict's tone.
   Monospace only where the text is code or an identifier (SQL, digests).
   ========================================================================== */

/* Home with Ask: the chat screen takes the whole content area and reads top down. */
.view.is-hero.is-ask { align-content: start; max-width: none; }
.ask-home { width: 100%; display: grid; gap: var(--space-4); }
.ask-body { display: grid; gap: var(--space-5); min-width: 0; }
.ask-body > .state-block { margin: 0; }
.ask-blank { max-width: 760px; margin: 0 auto; width: 100%; }

/* ---- the status line: Home's result in one line ---- */
.ask-status {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 10px;
  padding-bottom: var(--space-3); border-bottom: 1px solid var(--border-subtle);
  font-size: var(--fs-small); color: var(--text-dim);
}
.ask-status .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; align-self: center; background: var(--brand); }
.ask-status[data-tone="warning"] .dot { background: var(--warn); }
.ask-status[data-tone="success"] .dot { background: var(--ok); }
.ask-status[data-tone="info"] .dot { background: var(--info); }
.ask-status[data-tone="neutral"] .dot { background: var(--unknown); }
.ask-status-lead { font-weight: 650; color: var(--text); }
.ask-status[data-tone="warning"] .ask-status-lead { color: var(--warn-text); }
.ask-status[data-tone="success"] .ask-status-lead { color: var(--ok-text); }
.ask-status-text { min-width: 0; }
.ask-status-action { margin-left: auto; font-weight: 600; font-size: var(--fs-small); }

/* ---- the study ---- */
.ask-title { font-size: var(--fs-h1); font-weight: 700; color: var(--text); letter-spacing: -0.015em; line-height: var(--lh-tight); }
.ask-blank { display: grid; gap: var(--space-4); justify-items: start; }
.ask-blank p { font-size: var(--fs-base); line-height: var(--lh-body); color: var(--text-dim); max-width: 62ch; }

/* ---- the screen: the rail and the conversation ---- */
/* The height the rail and an empty conversation fill: the viewport less the topbar, the page padding and the status line. */
.ask-screen {
  --ask-fill: calc(100vh - var(--topbar-h) - 44px - 56px - 52px);
  position: relative; display: grid; grid-template-columns: 260px minmax(0, 1fr); align-items: start;
  min-height: var(--ask-fill);
}
.ask-screen { grid-template-areas: "rail main"; }
.ask-screen[data-rail="closed"] { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main"; }
.ask-screen[data-rail="closed"] .ask-rail { display: none; }
/* The trace takes about a third of the width; the conversation column narrows. */
.ask-screen[data-trace="open"] { grid-template-columns: 240px minmax(0, 1fr) minmax(380px, 34%); grid-template-areas: "rail main trace"; }
.ask-screen[data-trace="open"][data-rail="closed"] { grid-template-columns: minmax(0, 1fr) minmax(400px, 38%); grid-template-areas: "main trace"; }
.ask-rail { grid-area: rail; }
.ask-main { grid-area: main; }
.ask-trace-dock { grid-area: trace; display: none; }
.ask-screen[data-trace="open"] .ask-trace-dock {
  position: sticky; top: 0; height: var(--ask-fill); display: flex; flex-direction: column; min-width: 0;
  padding-left: var(--space-5); border-left: 1px solid var(--border-subtle);
}
.ask-trace-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.ask-trace-title { font-size: var(--fs-h2); font-weight: 700; color: var(--text); }
.ask-trace-title:focus { outline: none; }
.ask-trace-for { margin: 2px 0 var(--space-3); font-size: var(--fs-small); color: var(--text-dim); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ask-trace-body { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; grid-template-columns: minmax(0, 1fr); padding-right: var(--space-2); display: grid; align-content: start; gap: var(--space-6); padding-bottom: var(--space-6); }
.ask-trace-open { position: absolute; right: var(--space-6); top: 0; z-index: 2; }
/* The answer whose trace is on the right is marked, so the two are read together. */
.ask-turn[data-traced] .ask-answer { background: linear-gradient(to right, var(--brand-tint), transparent 70%); border-radius: 0 var(--radius-md) var(--radius-md) 0; }

/* Below the docking width the trace opens under its answer; from the audit list it fills the conversation area. */
.ask-inline-trace { margin-top: var(--space-3); padding: var(--space-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); display: grid; gap: var(--space-5); }
.ask-inline-trace[hidden] { display: none; }
.ask-inline-head { display: flex; align-items: center; justify-content: space-between; }
.ask-inline-trace [data-inline-host], .ask-audit-trace { display: grid; gap: var(--space-6); }
.ask-audit-trace { max-width: 920px; }

/* ---- "Sources used" on the answer card ---- */
.ask-sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ask-sources-label { font-size: var(--fs-micro); font-weight: 600; color: var(--text-faint); margin-right: 2px; }
.ask-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 26px; padding: 2px 10px 2px 3px;
  border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--surface); cursor: pointer;
  font: 500 var(--fs-micro)/1.3 var(--font); color: var(--text-body);
}
.ask-chip:hover { border-color: var(--brand-border); color: var(--text); }
.ask-chip-n { flex: none; display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--brand-tint-2); color: var(--brand); font-weight: 700; font-size: 10.5px; }
.ask-chip[data-ok="false"] .ask-chip-n { background: var(--down-tint); color: var(--down-text); }
.ask-chip-area { font-weight: 650; color: var(--text); white-space: nowrap; }
.ask-chip-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }

/* ---- the trace ---- */
.trace-section { display: grid; gap: var(--space-3); min-width: 0; grid-template-columns: minmax(0, 1fr); }
.trace-path > li, .trace-step-btn > span { min-width: 0; }
.trace-h { font-size: var(--fs-h3); font-weight: 650; color: var(--text); }
.trace-h4 { font-size: var(--fs-small); font-weight: 650; color: var(--text); margin-top: var(--space-2); }
.trace-h5 { font-size: var(--fs-small); font-weight: 650; color: var(--text); margin: var(--space-3) 0 0; }
.trace-h5:first-child { margin-top: 0; }

/* The path: a dot per step on one rule, the question at the top and the answer at the foot. */
.trace-path { position: relative; display: grid; gap: var(--space-2); padding-left: 30px; }
.trace-path::before { content: ""; position: absolute; left: 10px; top: 10px; bottom: 10px; width: 2px; background: var(--border); border-radius: 1px; }
.trace-path > li { position: relative; }
.trace-dot {
  position: absolute; left: -30px; top: 8px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); border: 2px solid var(--brand); color: var(--brand); font: 700 10.5px/1 var(--font); z-index: 1;
}
.trace-dot-end { top: 4px; left: -25px; width: 12px; height: 12px; background: var(--text-faint); border-color: var(--surface-page); }
.trace-dot-end[data-tone="success"] { background: var(--ok); }
.trace-dot-end[data-tone="danger"] { background: var(--down); }
.trace-end > div { display: grid; gap: 2px; }
.trace-kicker { font-size: var(--fs-micro); font-weight: 600; color: var(--text-faint); }
.trace-end-text { font-size: var(--fs-small); color: var(--text); overflow-wrap: anywhere; }
.trace-repeat .trace-end-text { color: var(--text-dim); }
.trace-step-btn {
  width: 100%; display: grid; gap: 3px; text-align: left; cursor: pointer; font: inherit; color: inherit;
  padding: 8px 10px; border: 1px solid transparent; border-radius: var(--radius-md); background: none;
}
.trace-step-btn:hover { background: var(--surface); border-color: var(--border); }
.trace-step[data-open] > .trace-step-btn { background: var(--surface); border-color: var(--brand-border); }
.trace-step[data-ok="false"] .trace-dot { border-color: var(--down); color: var(--down-text); background: var(--down-tint); }
.trace-step[data-ok="false"] .trace-result { color: var(--down-text); }
.trace-step-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.trace-area { font-size: var(--fs-micro); font-weight: 650; color: var(--brand-3); }
.trace-plane { font-size: var(--fs-micro); font-weight: 600; color: var(--warn-text); }
.trace-result { margin-left: auto; font-size: var(--fs-micro); font-weight: 600; color: var(--text-dim); }
.trace-sentence { font-size: var(--fs-small); color: var(--text); line-height: var(--lh-snug); overflow-wrap: anywhere; }
.trace-why { font-size: var(--fs-micro); color: var(--text-dim); line-height: var(--lh-snug); }
.trace-rests { font-size: var(--fs-micro); color: var(--brand); }
.trace-detail { grid-template-columns: minmax(0, 1fr); margin: var(--space-2) 0 var(--space-3) 10px; padding-left: var(--space-3); border-left: 2px solid var(--brand-border); display: grid; gap: var(--space-2); min-width: 0; }
.trace-refused { font-size: var(--fs-small); color: var(--down-text); }
.trace-table td, .trace-table th { padding: 6px 10px; }
.trace-items { display: grid; gap: var(--space-2); }
.trace-items > li { padding: 8px 10px; background: var(--surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); }
.trace-pairs { display: grid; gap: 2px; margin: 0; }
.trace-pairs[data-depth="1"], .trace-pairs[data-depth="2"], .trace-pairs[data-depth="3"] { padding-left: var(--space-3); border-left: 1px solid var(--border-subtle); }
.trace-pair { display: grid; grid-template-columns: minmax(90px, 30%) minmax(0, 1fr); gap: var(--space-2); font-size: var(--fs-micro); }
.trace-pair-nest { grid-template-columns: minmax(0, 1fr); }
.trace-pair dt { font-family: var(--mono); color: var(--text-faint); overflow-wrap: anywhere; }
.trace-pair dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.trace-value { font-size: var(--fs-micro); color: var(--text); }
.trace-chain { display: grid; gap: var(--space-2); }
.trace-chain > li { padding: 8px 10px; background: var(--surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); }
.trace-chain-title { font-size: var(--fs-micro); font-weight: 650; color: var(--text); margin: 0 0 4px; }
.trace-list-label { font-size: var(--fs-micro); font-weight: 650; color: var(--text); margin: 10px 0 4px; }
.trace-chain-item { display: grid; gap: 4px; }
.trace-chain-item + .trace-chain-item { margin-top: var(--space-2); padding-top: var(--space-2); border-top: 1px solid var(--border-subtle); }
.trace-chain-name { font-size: var(--fs-small); font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.trace-digest { font-size: var(--fs-caption); color: var(--text-faint); overflow-wrap: anywhere; }
.trace-passages { display: grid; gap: var(--space-2); }
.trace-where { font-size: var(--fs-micro); color: var(--text-faint); }
.trace-passage { margin: 2px 0 0; font-size: var(--fs-small); line-height: var(--lh-body); color: var(--text-body); }
blockquote.trace-passage { padding: 6px 10px; border-left: 3px solid var(--border-strong); background: var(--surface); }
.trace-passage mark, .trace-pairs mark { background: var(--brand-tint-2); color: var(--text); border-radius: 3px; padding: 0 1px; box-shadow: 0 0 0 1px var(--brand-border); }
/* The tables read fit the trace: the name wraps, the two counts keep a narrow column each. */
.trace-tables { table-layout: fixed; width: 100%; }
.trace-tables th { white-space: normal; }
.trace-tables th:nth-child(n+2), .trace-tables td:nth-child(n+2) { width: 22%; text-align: right; }
.trace-tables td { font-size: var(--fs-micro); }
.trace-tables td:first-child { white-space: normal; overflow-wrap: anywhere; }
.trace-detail .table-wrap { max-width: 100%; }
/* In the trace a record table keeps its columns readable and scrolls in its own frame (the date pinned) rather than
   squeezing words letter by letter into the trace's width. */
.trace-detail .ask-record-group table, .ask-inline-trace .ask-record-group table, .ask-audit-trace .ask-record-group table { width: max-content; min-width: 100%; }
.trace-detail .ask-cell, .trace-detail .ask-record-group th .ask-col-name { overflow-wrap: break-word; }
.trace-sql-heading { color: var(--text); font-weight: 600; font-family: var(--mono); }
.ask-statement[data-rows="true"] .ask-code { border-left: 3px solid var(--brand); }
.ask-statement[data-rows="false"] .ask-code { color: var(--text-dim); }
.ask-statement[data-rows="false"] .trace-sql-heading { font-weight: 500; color: var(--text-dim); }
.trace-doc-steps { display: grid; gap: var(--space-2); font-size: var(--fs-small); }
.trace-filters { margin-top: 2px; }
.trace-check-summary { font-size: var(--fs-small); color: var(--text); }
.trace-logic { margin-top: var(--space-2); }
.trace-acts { display: flex; gap: var(--space-2); flex-wrap: wrap; }
/* Inside the trace the records keep the trace's own width; the chat's wide measure is for the conversation. */
.trace-detail .ask-records, .ask-inline-trace .ask-records, .ask-audit-trace .ask-records { width: auto; margin-left: 0; padding: 0; background: none; position: static; }

.ask-rail {
  position: sticky; top: 0; height: var(--ask-fill); display: flex; flex-direction: column; gap: var(--space-3);
  padding-right: var(--space-4); border-right: 1px solid var(--border-subtle); min-width: 0;
}
.ask-rail-head { display: flex; gap: var(--space-2); align-items: center; }
.ask-new { flex: 1; justify-content: flex-start; }
.ask-new::before { content: "+"; font-weight: 500; font-size: 15px; line-height: 1; margin-right: 2px; color: var(--text-faint); }
.ask-rail-scroll { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; margin-right: calc(-1 * var(--space-2)); padding-right: var(--space-2); }
.ask-rail-label { margin: var(--space-4) 0 4px 10px; font-size: var(--fs-micro); font-weight: 600; color: var(--text-faint); }
.ask-rail-label:first-child { margin-top: var(--space-1); }
.ask-rail-list { display: grid; gap: 1px; grid-template-columns: minmax(0, 1fr); }
.ask-rail-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text-body); font-size: var(--fs-small); text-decoration: none;
}
.ask-rail-item:hover { background: var(--surface-muted); color: var(--text); text-decoration: none; }
.ask-rail-item[aria-current="page"] { background: var(--surface-sunken); color: var(--text); font-weight: 600; }
.ask-rail-q { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ask-rail-mark { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--down); }
.ask-rail-mark[data-kind="not-in-sources"] { background: transparent; box-shadow: inset 0 0 0 1.5px var(--unknown); }
.ask-rail-note { padding: 8px 10px; font-size: var(--fs-small); color: var(--text-faint); }
.ask-rail-more { margin: var(--space-2) 0 0 10px; background: none; border: 0; padding: 0; cursor: pointer; font: 600 var(--fs-small)/1.4 var(--font); color: var(--brand); }
.ask-rail-foot { padding: var(--space-3) 0 0 10px; border-top: 1px solid var(--border-subtle); }
.ask-audit-link { font-size: var(--fs-micro); font-weight: 500; color: var(--text-faint); }
.ask-audit-link:hover, .ask-audit-link[aria-current="page"] { color: var(--brand); }

.ask-icon-btn {
  flex: none; display: grid; place-items: center; width: 32px; height: 32px; min-height: 32px; padding: 0;
  border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--text-faint); cursor: pointer;
}
.ask-icon-btn:hover { background: var(--surface-muted); color: var(--text); }
.ask-icon-btn svg { width: 18px; height: 18px; }
.ask-scrim { display: none; }

/* The conversation area. It is a size container, so a record table can take its whole width (100cqi). */
.ask-main { position: relative; min-width: 0; min-height: var(--ask-fill); padding: 0 var(--space-6); container-type: inline-size; display: flex; flex-direction: column; }
.ask-rail-open { position: absolute; left: 0; top: 0; z-index: 2; }
.ask-screen[data-rail="closed"] .ask-main { padding-left: 48px; }
.ask-opening { margin: var(--space-8) auto; }

/* An empty conversation: the heading, the box and the examples in the middle of the area. */
.ask-start { margin: auto; width: 100%; max-width: 720px; display: grid; gap: var(--space-5); justify-items: center; text-align: center; padding: var(--space-6) 0 12vh; }
.ask-start .ask-composer, .ask-start .ask-note { width: 100%; text-align: left; }
.ask-start .ask-note { margin-top: calc(-1 * var(--space-3)); }
.ask-start-note { max-width: 58ch; font-size: var(--fs-small); line-height: var(--lh-body); color: var(--text-faint); }
.ask-start .ask-examples { justify-content: center; }

/* An open conversation: the reading column, the box docked at its foot while the thread scrolls. */
.ask-conversation { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; }
.ask-thread { flex: 1; display: grid; align-content: start; gap: var(--space-7); padding: var(--space-4) 0 var(--space-6); }
/* Docked to the foot of the scrolling page: it reaches past the page's bottom padding (56px) so nothing shows under it. */
.ask-dock {
  position: sticky; bottom: calc(-1 * var(--space-9)); z-index: 3; padding: var(--space-4) 0 calc(var(--space-3) + var(--space-9));
  margin-bottom: calc(-1 * var(--space-9));
  background: linear-gradient(to bottom, transparent, var(--surface-page) 22%);
}
.ask-dock .ask-note { margin-top: var(--space-2); }

.ask-examples { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.ask-example {
  text-align: left; font: 500 var(--fs-sm)/1.45 var(--font); color: var(--text-body);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 9px 14px; cursor: pointer;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.ask-example:hover { border-color: var(--brand-border); color: var(--brand-3); }

.ask-turn { display: grid; gap: var(--space-3); scroll-margin: var(--space-6); }
.ask-turn:focus-visible { outline-offset: 6px; border-radius: var(--radius-sm); }
/* The person's question: a bubble on the right, in the brand's own tint. */
.ask-q-row { display: flex; justify-content: flex-end; }
.ask-question {
  max-width: min(80%, 60ch); padding: 10px 14px; border-radius: 14px 14px 4px 14px;
  background: var(--brand-tint); color: var(--text); font-size: var(--fs-base); line-height: var(--lh-snug);
  white-space: pre-wrap; overflow-wrap: anywhere;
}

/* The read trace: a rule with a point per read, growing as the reads are made. */
.ask-progress { display: grid; gap: var(--space-2); }
.ask-trace { position: relative; display: grid; gap: var(--space-3); padding-left: 22px; }
.ask-trace::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 1px; background: var(--border-strong); }
.ask-trace li { position: relative; display: grid; gap: 2px; }
.ask-trace li[data-new] { animation: ask-step-in 240ms var(--ease-out); }
.ask-trace li::before {
  content: ""; position: absolute; left: -21px; top: 6px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--surface-page); border: 2px solid var(--brand);
}
.ask-trace li[data-state="done"]::before { background: var(--brand); }
.ask-trace li[data-state="failed"]::before { border-color: var(--down); background: var(--down-tint); }
.ask-trace li[data-state="running"]::before { animation: ask-pulse 1.2s ease-in-out infinite; }
.ask-trace-title { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.ask-trace-why { font-size: var(--fs-meta); color: var(--text-dim); line-height: var(--lh-snug); max-width: 64ch; }
.ask-progress-next { padding-left: 22px; }
@keyframes ask-step-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
@keyframes ask-pulse { 50% { box-shadow: 0 0 0 4px var(--brand-ring); } }

/* The answer card: the rule stays, in the verdict's tone. */
.ask-answer {
  display: grid; gap: var(--space-3); padding: 2px 0 2px 20px;
  border-left: 2px solid var(--ok);
}
.ask-answer[data-kind="not-in-sources"], .ask-answer[data-kind="refused"] { border-left-color: var(--unknown); }
.ask-answer[data-kind="rejected"] { border-left-color: var(--down); }
.ask-badge { justify-self: start; display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-micro); font-weight: 650; padding: 3px 10px; border-radius: var(--radius-pill); }
.ask-badge[data-tone="success"] { background: var(--ok-tint); color: var(--ok-text); }
.ask-badge[data-tone="neutral"] { background: var(--surface-muted); color: var(--text-dim); }
.ask-badge[data-tone="danger"] { background: var(--down-tint); color: var(--down-text); }
.ask-answer-text { display: grid; gap: var(--space-3); font-size: var(--fs-base); line-height: var(--lh-body); color: var(--text-body); max-width: 68ch; overflow-wrap: anywhere; }
.ask-answer > p { font-size: var(--fs-sm); line-height: var(--lh-body); color: var(--text-body); }
.ask-failed-checks { display: grid; gap: var(--space-2); }
.ask-failed-checks li { display: grid; gap: 2px; padding: 8px 12px; background: var(--down-tint); border-radius: var(--radius-sm); font-size: var(--fs-small); }
.ask-failed-checks b { color: var(--down-text); font-weight: 650; }
.ask-failed-checks span { color: var(--text-body); overflow-wrap: anywhere; }
.ask-table { margin: 0; display: grid; gap: var(--space-2); }
.ask-table figcaption { font-size: var(--fs-small); font-weight: 650; color: var(--text); }
.ask-table td { overflow-wrap: anywhere; }
.ask-table-note { font-size: var(--fs-micro); color: var(--text-faint); }
.ask-glossary, .ask-glossary-ref { display: grid; gap: var(--space-2); min-width: 0; overflow-wrap: anywhere; }
.ask-glossary-ref { border-top: 1px solid var(--border-subtle); padding-top: var(--space-2); }
.ask-glossary-columns { max-height: 12rem; overflow: auto; }
.ask-limits { display: grid; gap: 4px; }
.ask-h3 { font-size: var(--fs-small); font-weight: 650; color: var(--text); }
.ask-limits ul { display: grid; gap: 2px; padding-left: 18px; list-style: disc; font-size: var(--fs-small); color: var(--text-dim); }
.ask-answer-foot { display: flex; align-items: baseline; gap: var(--space-4); font-size: var(--fs-small); color: var(--text-faint); }

.ask-notice { padding: 10px 14px; border-radius: var(--radius-md); background: var(--surface-muted); font-size: var(--fs-sm); color: var(--text-body); display: grid; gap: 4px; }
.ask-notice[data-tone="danger"] { background: var(--down-tint); }
.ask-muted { font-size: var(--fs-small); color: var(--text-faint); line-height: var(--lh-snug); }
.ask-mono { font-family: var(--mono); font-size: var(--fs-micro); overflow-wrap: anywhere; }

/* ---- the composer ---- */
.ask-composer {
  display: flex; align-items: flex-end; gap: var(--space-2);
  padding: 8px 8px 8px 14px; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.ask-composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.ask-composer textarea {
  flex: 1; min-height: 34px; max-height: 240px; resize: none; border: 0; padding: 7px 0; background: transparent;
  font: var(--fs-base)/1.5 var(--font); color: var(--text); box-shadow: none; overflow-y: auto;
}
.ask-composer textarea:focus, .ask-composer textarea:focus-visible { outline: none; box-shadow: none; }
.ask-note { font-size: var(--fs-small); color: var(--warn-text); margin-top: calc(-1 * var(--space-3)); }
.ask-note:empty { display: none; }

/* ---- the audit list, reached from the foot of the rail ---- */
.ask-audit { display: grid; gap: var(--space-4); max-width: var(--content-max); width: 100%; margin: 0 auto; }
.ask-audit [data-ask-history] { display: grid; gap: var(--space-4); }
.ask-back { justify-self: start; }
.ask-h2 { font-size: var(--fs-small); font-weight: 650; color: var(--text-dim); }
.ask-history-table td { vertical-align: middle; }
.ask-history-table td:not(:nth-child(2)) { white-space: nowrap; }
.ask-history-table td:nth-child(2) { min-width: 26ch; }
.ask-history-table .ask-badge { white-space: nowrap; }
.ask-history-open {
  background: none; border: 0; padding: 0; text-align: left; cursor: pointer; font: inherit;
  color: var(--text); font-weight: 560; max-width: 46ch;
}
.ask-history-open:hover { color: var(--brand); }
.ask-history .btn { justify-self: start; }

/* ---- source records, drawn from the data and named by the glossary ---- */
/* The records give the data back, so they take the page's content width (as History does), centred under the chat
   column, while the answer's sentences stay in the column. --ask-wide is the view's width: the content measure or the
   room beside the sidebar and the page padding, whichever is less; the block moves left by half the difference and by
   the answer's own indent (its 2px rule and 20px padding). */
.ask-records {
  /* The whole width of the conversation area (its content box: the area less its padding), whatever the rail does. */
  --ask-wide: 100cqi;
  display: grid; gap: var(--space-4);
  width: var(--ask-wide);
  margin-left: calc((min(760px, var(--ask-wide)) - var(--ask-wide)) / 2 - 22px);
  /* It lies over the answer's rule where it is wider than the column, so it carries the page's ground. */
  position: relative; z-index: 1; background: var(--surface-page); padding: var(--space-2) 0;
}
.ask-record-group figcaption { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.ask-group-title { font-size: var(--fs-small); font-weight: 650; color: var(--text); }
.ask-group-count { font-size: var(--fs-micro); color: var(--text-faint); }
.ask-group-sub { flex-basis: 100%; font-size: var(--fs-micro); font-weight: 400; color: var(--text-faint); }
.ask-record-group:not([data-described]) .ask-group-sub { color: var(--warn-text); }
/* Each column as narrow as its content: the name on one line, its glossary meaning one clamped line under it (the
   whole meaning is the header's title, and the header takes focus so it is reachable by keyboard). */
.ask-record-group th { vertical-align: bottom; white-space: normal; }
.ask-record-group th:focus-visible { outline-offset: -2px; }
/* A column is as wide as its values need, between a short minimum and about 22 characters (cells ignore max-width, so
   the cap sits on the block inside each cell and on the header's name, which may break after an underscore). */
.ask-cell { min-width: 4ch; max-width: 22ch; overflow-wrap: anywhere; }
.ask-record-group th .ask-col-name { min-width: 4ch; max-width: 22ch; white-space: normal; overflow-wrap: anywhere; }
.ask-record-group th, .ask-record-group td { padding-left: 12px; padding-right: 12px; }
.ask-record-group .ask-order-col { white-space: nowrap; font-family: var(--mono); font-size: var(--fs-micro); }
/* When a wide group still scrolls, its date stays in view. */
.ask-record-group th.ask-order-col, .ask-record-group td.ask-order-col { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: inset -1px 0 0 var(--border-subtle); }
.ask-record-group thead th.ask-order-col { background: var(--surface-header); }
.ask-col-mark { display: inline-block; width: 7px; height: 7px; margin-left: 5px; border-radius: 50%; background: var(--warn); vertical-align: middle; }
.ask-same { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--fs-small); color: var(--text-dim); }
.ask-same-pair { white-space: nowrap; }
.ask-same-name { font-family: var(--mono); font-size: var(--fs-caption); color: var(--text-faint); }
.ask-same-name[title] { text-decoration: underline dotted; text-underline-offset: 3px; cursor: help; }
.ask-col-name { display: block; text-transform: none; letter-spacing: 0; font-family: var(--mono); font-size: var(--fs-caption); color: var(--text); }
.ask-col-def { display: block; margin-top: 2px; text-transform: none; letter-spacing: 0; font-weight: 400; width: 0; min-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-faint); }
.ask-records-note { padding: 8px 12px; border-radius: var(--radius-sm); background: var(--warn-tint); color: var(--text-body); font-size: var(--fs-small); }
.ask-records-link { font-weight: 600; font-size: var(--fs-small); }

/* ---- shared by the trace: key and value lists, statements, checks ---- */
.ask-why { font-size: var(--fs-sm); color: var(--text-body); line-height: var(--lh-body); margin-bottom: var(--space-3); max-width: 70ch; }
.ask-kvs { display: grid; gap: 6px; }
.ask-kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: var(--space-3); font-size: var(--fs-small); }
.ask-kv dt { color: var(--text-faint); }
.ask-kv dd { margin: 0; color: var(--text-body); overflow-wrap: anywhere; }
.ask-digests { margin-top: var(--space-4); padding-top: var(--space-3); border-top: 1px solid var(--border-subtle); }
.ask-small-table { font-size: var(--fs-micro); margin-top: var(--space-2); }
.ask-small-table td, .ask-small-table th { padding: 6px 10px; }
.ask-small-table td:first-child { white-space: nowrap; overflow-wrap: normal; }
.ask-transactions { margin-top: var(--space-2); display: grid; gap: 2px; font-size: var(--fs-micro); color: var(--text-dim); }
.ask-statements { display: grid; gap: var(--space-3); margin: var(--space-2) 0 var(--space-3); }
.ask-statement { display: grid; gap: 6px; }
.ask-statement-head { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: var(--fs-micro); color: var(--text-faint); }
.ask-statement-head b { color: var(--text); font-weight: 700; }
.ask-failed { color: var(--down-text); font-weight: 620; }
.ask-code {
  margin: 0; padding: 10px 12px; background: var(--surface-raised); border: 1px solid var(--border-payload);
  border-radius: var(--radius-sm); font: var(--fs-micro)/1.55 var(--mono); color: var(--text-body);
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 280px; overflow: auto;
}
.ask-statement[data-failed="true"] .ask-code { border-color: var(--down-border); }
.ask-statement-meta { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: var(--space-2); font-size: var(--fs-micro); color: var(--text-faint); }
.ask-statement-meta code { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 120px; overflow: auto; color: var(--text-body); }
.ask-checks { display: grid; gap: 6px; }
.ask-checks li { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: var(--space-3); font-size: var(--fs-small); align-items: baseline; }
.ask-checks b { font-weight: 600; color: var(--text); }
.ask-checks code { margin-left: 6px; color: var(--text-faint); font-size: var(--fs-caption); }
.ask-checks small { display: block; color: var(--text-dim); font-size: var(--fs-micro); margin-top: 1px; overflow-wrap: anywhere; }
.ask-check-mark { font-size: var(--fs-micro); font-weight: 650; color: var(--ok-text); }
.ask-checks li[data-passed="false"] .ask-check-mark { color: var(--down-text); }
.ask-recheck { padding: 14px 18px; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border); display: grid; gap: var(--space-2); }
.ask-recheck:focus { outline: none; }
.ask-recheck[data-tone="success"] { border-color: var(--ok-border); box-shadow: inset 3px 0 0 var(--ok); }
.ask-recheck[data-tone="warning"] { border-color: var(--warn-border); box-shadow: inset 3px 0 0 var(--warn); }
.ask-recheck[data-tone="danger"] { border-color: var(--down-border); box-shadow: inset 3px 0 0 var(--down); }
.ask-recheck-facts { display: grid; gap: 2px; font-size: var(--fs-small); color: var(--text-body); }
.ask-muted-list { display: grid; gap: 2px; font-size: var(--fs-micro); color: var(--text-dim); }
.ask-rerun { display: grid; gap: 6px; }
.ask-rerun li { display: flex; gap: 10px; align-items: flex-start; font-size: var(--fs-small); }
.ask-rerun small { display: block; color: var(--text-dim); font-size: var(--fs-micro); }
.ask-outcome { font-weight: 650; color: var(--ok-text); }
.ask-rerun li[data-outcome="different"] .ask-outcome { color: var(--warn-text); }
.ask-rerun li[data-outcome="refused"] .ask-outcome, .ask-rerun li[data-outcome="not-run"] .ask-outcome { color: var(--down-text); }

/* ---- a repeated answer (DESIGN.md R6) ---- */
.ask-repeat { font-size: var(--fs-small); color: var(--text-dim); line-height: var(--lh-snug); max-width: 68ch; }
.ask-repeat .link-action { font-size: inherit; white-space: normal; text-align: left; }
.ask-answer-foot .ask-fresh { margin-left: auto; min-height: 28px; padding: 5px 10px; font-size: var(--fs-micro); }

/* ---- what each sentence rests on: a sentence, then the words it quotes ---- */
.ask-sentence-list { display: grid; gap: var(--space-4); counter-reset: ask-sentence; }
.ask-sentence-list > li { display: grid; gap: 6px; padding-left: 14px; border-left: 2px solid var(--border); }
.ask-sentence-list > li[data-rests="true"] { border-left-color: var(--brand); }
.ask-sentence { font-size: var(--fs-sm); line-height: var(--lh-body); color: var(--text); max-width: 72ch; }
.ask-quote { display: grid; gap: 3px; justify-items: start; }
.ask-quote-from { font-size: var(--fs-micro); white-space: normal; text-align: left; color: var(--text-faint); }
button.ask-quote-from { color: var(--brand); }
.ask-quote-text {
  display: block; max-width: 100%; padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--brand-tint); color: var(--text); font: var(--fs-micro)/1.55 var(--mono);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.ask-resting { margin-bottom: var(--space-3); }
.ask-resting ul { display: grid; gap: 4px; padding-left: 18px; list-style: disc; font-size: var(--fs-small); color: var(--text-body); }
@media (max-width: 1100px) {
  .ask-screen, .ask-screen[data-rail="closed"] { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main"; }
  .ask-screen[data-rail="open"] .ask-rail {
    position: absolute; left: 0; top: 0; z-index: 6; width: 280px; height: var(--ask-fill);
    padding: var(--space-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
  }
  .ask-screen[data-rail="open"] .ask-scrim { display: block; position: absolute; inset: 0; z-index: 5; background: rgba(15, 23, 42, 0.12); border-radius: var(--radius-lg); }
  .ask-screen .ask-main { padding-left: 48px; }
}

@media (max-width: 860px) {
  .ask-kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
}

/* One or two records: each a card of name and value pairs, flowing in as many columns as fit, the date first. */
.ask-record-card {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 20px; margin: 0;
  padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.ask-record-card + .ask-record-card { margin-top: var(--space-2); }
.ask-pair { min-width: 0; }
.ask-pair dt { display: flex; align-items: center; gap: 4px; font-family: var(--mono); font-size: var(--fs-caption); color: var(--text-faint); overflow-wrap: anywhere; }
.ask-pair dt[title] .ask-pair-name { text-decoration: underline dotted; text-underline-offset: 3px; cursor: help; }
.ask-pair dd { margin: 2px 0 0; font-size: var(--fs-small); color: var(--text); overflow-wrap: anywhere; }
.ask-pair-date dd { font-family: var(--mono); font-size: var(--fs-micro); }

.ask-read-n { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-tint-2); color: var(--brand); font: 700 10.5px/1 var(--font); }
