/* ===========================================================================
 * DupTrace — investigation workspace
 *
 * A calm, precise instrument for evidence-first incident investigation. Three
 * panes: a compact rail of recent investigations, the central conversation and
 * its evidence (the priority), and a collapsible context inspector.
 *
 * Design language, specific to DupTrace:
 *   • a neutral spine (true-neutral grays) carries structure;
 *   • ONE restrained blue marks interactive emphasis and selection;
 *   • red marks a genuine error, ochre marks uncertainty — never color alone,
 *     always paired with text and/or shape;
 *   • the "trace spine" threads the investigation steps like a signal trace;
 *   • monospace is reserved for identifiers, tool names, timestamps and raw JSON.
 *
 * No framework, no build step, no web fonts — a coherent system stack. Genuine
 * light + dark themes via semantic tokens on :root[data-theme].
 * ========================================================================= */

/* ---------------------------------------------------------------------------
 * Tokens — light (default + explicit light)
 * ------------------------------------------------------------------------- */
:root {
  --bg: #ffffff;
  --bg-rail: #f7f8fa;
  --bg-inspector: #fbfbfc;
  --surface: #f5f6f8;
  --surface-2: #eceef2;
  --surface-3: #e3e6ec;

  --fg: #15171c;
  --fg-strong: #0a0c10;
  --muted: #596073;
  --faint: #878d9d;

  --line: #e7e9ef;
  --line-strong: #d7dbe3;

  --accent: #2f61e6;
  --accent-hover: #2a55cc;
  --accent-weak: #eef2fe;
  --accent-weak-border: #d4ddfb;
  --accent-contrast: #ffffff;

  --danger: #c23b2e;
  --danger-weak: #fcecea;
  --danger-border: #f1c6c0;

  --caution: #875600;
  --caution-mark: #bb8514;
  --caution-weak: #fbf3df;

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(16, 18, 24, 0.05);
  --shadow-pop: 0 14px 38px -10px rgba(16, 18, 24, 0.26);

  --rail-w: 260px;
  --inspector-w: 300px;
  --measure: 47rem;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  --ease: cubic-bezier(0.33, 0.1, 0.25, 1);
  color-scheme: light;
}

/* Dark — explicit choice always wins. */
:root[data-theme="dark"] {
  --bg: #0e1014;
  --bg-rail: #0a0b0e;
  --bg-inspector: #0b0d11;
  --surface: #15181e;
  --surface-2: #1c2027;
  --surface-3: #242a34;

  --fg: #e7eaef;
  --fg-strong: #f5f6f9;
  --muted: #9aa1b1;
  --faint: #697083;

  --line: #23272f;
  --line-strong: #343a46;

  --accent: #5c86ff;
  --accent-hover: #789bff;
  --accent-weak: #15203a;
  --accent-weak-border: #294063;
  --accent-contrast: #0a1226;

  --danger: #ef6a5c;
  --danger-weak: #2a1512;
  --danger-border: #512721;

  --caution: #e0ad51;
  --caution-mark: #e0ad51;
  --caution-weak: #241d0c;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-pop: 0 18px 46px -10px rgba(0, 0, 0, 0.66);

  color-scheme: dark;
}

/* System dark, when no explicit choice is stored (JS-off fallback; the inline
   head script normally sets the attribute before paint). Explicit light wins. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #0e1014;
    --bg-rail: #0a0b0e;
    --bg-inspector: #0b0d11;
    --surface: #15181e;
    --surface-2: #1c2027;
    --surface-3: #242a34;

    --fg: #e7eaef;
    --fg-strong: #f5f6f9;
    --muted: #9aa1b1;
    --faint: #697083;

    --line: #23272f;
    --line-strong: #343a46;

    --accent: #5c86ff;
    --accent-hover: #789bff;
    --accent-weak: #15203a;
    --accent-weak-border: #294063;
    --accent-contrast: #0a1226;

    --danger: #ef6a5c;
    --danger-weak: #2a1512;
    --danger-border: #512721;

    --caution: #e0ad51;
    --caution-mark: #e0ad51;
    --caution-weak: #241d0c;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-pop: 0 18px 46px -10px rgba(0, 0, 0, 0.66);

    color-scheme: dark;
  }
}

/* ---------------------------------------------------------------------------
 * Reset + base
 * ------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------------------
 * Icons + icon buttons (one coherent stroke family; glyphs injected by app.js)
 * ------------------------------------------------------------------------- */
.icon {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 140ms var(--ease), color 140ms var(--ease),
    border-color 140ms var(--ease);
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--fg);
}

.icon-btn .icon {
  width: 19px;
  height: 19px;
}

/* ---------------------------------------------------------------------------
 * App shell — three panes
 * ------------------------------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--inspector-w);
  height: 100dvh;
  overflow: hidden;
}

.app--inspector-collapsed {
  grid-template-columns: var(--rail-w) minmax(0, 1fr) 0;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(10, 12, 18, 0.44);
  border: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none; /* invisible + inert unless a drawer is open */
  transition: opacity 180ms var(--ease);
}

/* ---------------------------------------------------------------------------
 * Rail (left) — brand, new investigation, recent list, theme toggle
 * ------------------------------------------------------------------------- */
.rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-rail);
  border-right: 1px solid var(--line);
}

.rail__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 14px 14px 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  color: var(--fg-strong);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

.brand__name {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.012em;
  color: var(--fg-strong);
}

.rail__close {
  display: none;
}

.rail__new {
  padding: 2px 14px 12px;
}

.newbtn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  cursor: pointer;
  transition: border-color 140ms var(--ease), background-color 140ms var(--ease),
    box-shadow 140ms var(--ease);
}

.newbtn:hover {
  border-color: var(--accent);
  background: var(--bg);
  box-shadow: var(--shadow-sm);
}

.newbtn__icon {
  display: inline-flex;
  color: var(--accent);
}

.newbtn__icon .icon {
  width: 17px;
  height: 17px;
  stroke-width: 2;
}

.rail__nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 10px 10px;
}

.rail__eyebrow {
  margin: 8px 8px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.invlist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.invlist__item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  position: relative;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
  transition: background-color 130ms var(--ease), color 130ms var(--ease);
}

.invlist__item:hover {
  background: var(--surface-2);
  color: var(--fg);
}

.invlist__dot {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
  transition: background-color 130ms var(--ease);
}

.invlist__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Selected investigation: a restrained neutral surface + a thin accent marker and
   dot — clear without an oversized blue highlight. State is also carried by weight. */
.invlist__item[aria-current="true"] {
  background: var(--surface-2);
  color: var(--fg-strong);
  font-weight: 550;
}

.invlist__item[aria-current="true"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  bottom: 7px;
  width: 2.5px;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
}

.invlist__item[aria-current="true"] .invlist__dot {
  background: var(--accent);
}

.invlist__empty {
  margin: 6px 10px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

.rail__foot {
  display: flex;
  align-items: center;
  padding: 10px 10px 12px;
  border-top: 1px solid var(--line);
}

/* Theme toggle — a compact, quiet icon button in the rail footer. It reuses
   .icon-btn (subtle hover surface, focus ring, 36px hit target); only the inner
   icon wrapper is theme-specific. No label, border, or accent — visually quiet. */
.theme-toggle__icon {
  display: inline-flex;
}

/* ---------------------------------------------------------------------------
 * Workspace (center) — topbar / conversation / composer
 * ------------------------------------------------------------------------- */
.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.1) blur(6px);
}

.topbar__menu,
.topbar__inspector {
  flex: none;
}

.topbar__menu {
  display: none;
}

.topbar__title {
  flex: 1;
  min-width: 0;
}

.topbar__name {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__sub {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  font-size: 12.5px;
  color: var(--muted);
}

/* Status: shape + motion carry meaning (ready solid · busy pulsing · offline
   hollow · error red). The label repeats it in text — never color alone. */
.status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg);
  transition: background-color 160ms var(--ease), box-shadow 160ms var(--ease);
}

.status__dot[data-state="ready"] {
  background: var(--fg);
}
.status__dot[data-state="busy"] {
  background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}
.status__dot[data-state="error"] {
  background: var(--danger);
}
.status__dot[data-state="offline"] {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--faint);
}

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

/* Conversation */
.conversation {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 26px 24px 30px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  scroll-behavior: smooth;
  outline: none;
}

.conversation > * {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
}

.noscript {
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
}

/* ---------------------------------------------------------------------------
 * Empty state
 * ------------------------------------------------------------------------- */
.empty {
  margin: auto auto;
  text-align: center;
  padding: 24px 8px;
  max-width: 34rem;
}

.empty__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  margin-bottom: 18px;
  color: var(--fg-strong);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
}

.empty__mark .icon {
  width: 26px;
  height: 26px;
  stroke-width: 1.9;
}

.empty__eyebrow {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
}

.empty__title {
  margin: 0 0 7px;
  font-size: 21px;
  font-weight: 680;
  letter-spacing: -0.02em;
  color: var(--fg-strong);
}

.empty__hint {
  margin: 0 auto 22px;
  max-width: 40ch;
  color: var(--muted);
  font-size: 14px;
}

.empty__try {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.empty__examples {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.empty__example {
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  cursor: pointer;
  width: 100%;
  max-width: 22rem;
  transition: border-color 140ms var(--ease), background-color 140ms var(--ease),
    box-shadow 140ms var(--ease);
}

.empty__example:hover {
  border-color: var(--accent);
  background: var(--bg);
  box-shadow: var(--shadow-sm);
}

/* ---------------------------------------------------------------------------
 * Messages
 * ------------------------------------------------------------------------- */
.msg {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg__role {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.msg__body {
  font-size: 15px;
}

.answer__eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.answer__text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.answer__text + .answer__text {
  margin-top: 10px;
}

.answer__text--muted {
  color: var(--muted);
  font-style: italic;
}

/* User: a quiet self-contained card — a legitimate grouping boundary. */
.msg--user {
  align-items: flex-start;
}

.msg--user .msg__body {
  align-self: flex-start;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 11px 15px;
}

/* Assistant: a left rule anchors the whole turn (answer + evidence). */
.msg--assistant .msg__body,
.msg--loading .msg__body {
  border-left: 2px solid var(--line-strong);
  padding: 1px 0 1px 16px;
}

.msg--error .msg__body {
  border-left: 2px solid var(--danger);
  padding: 1px 0 1px 16px;
}

.msg--partial .msg__body {
  border-left: 2px solid var(--caution);
  padding: 1px 0 1px 16px;
}

.msg--assistant .answer__text {
  font-size: 15.5px;
  color: var(--fg);
}

.turn-divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 18px 0 16px;
}

/* ---------------------------------------------------------------------------
 * Investigation panel — the evidence trail, threaded by a trace spine
 * ------------------------------------------------------------------------- */
.investigation {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.investigation__head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: transparent;
}

.investigation__title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.investigation__title .icon {
  width: 14px;
  height: 14px;
  color: var(--muted);
}

.investigation__summary {
  margin: 7px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 5px 14px;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.investigation__stat {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.investigation__stat + .investigation__stat::before {
  content: "";
  position: absolute;
  left: -8px;
  width: 1px;
  height: 11px;
  background: var(--line-strong);
}

.investigation__stat--error {
  color: var(--danger);
}

.investigation__list {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
}

/* The trace spine: a hairline threading the step nodes top to bottom. */
.investigation__list::before {
  content: "";
  position: absolute;
  left: 28px;
  top: 20px;
  bottom: 18px;
  width: 1px;
  background: var(--line-strong);
}

.check {
  border-top: 1px solid var(--line);
}
.check:first-child {
  border-top: none;
}

.check__details[open] {
  background: var(--bg);
}

.check__summary {
  position: relative;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 11px 14px 11px 52px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.check__summary::-webkit-details-marker {
  display: none;
}

/* Step node sitting on the spine — carries the step number (or a dot when the
   API gave none). The one bead per step; opaque so the spine reads as threaded. */
.check__node {
  position: absolute;
  left: 16px;
  top: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 25px;
  height: 25px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.check__details[open] .check__node {
  background: var(--surface);
}

.check__node--dot {
  color: transparent;
}
.check__node--dot::after {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--faint);
}

.check__node--error {
  color: var(--danger);
  border-color: var(--danger);
}

.check__node--correlation {
  color: var(--caution);
  border-color: var(--caution-mark);
}

.check__labels {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.check__label {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
}

.check__tool {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* Classification tags: text + colour together (never colour alone). "Observed"
   (the default) carries no tag — the "Observed evidence" header frames it. */
.check__tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: var(--radius-xs);
  padding: 1px 7px;
}

.check__tag--error {
  color: var(--danger);
  background: var(--danger-weak);
  border: 1px solid var(--danger-border);
}

.check__tag--correlation {
  color: var(--caution);
  background: var(--caution-weak);
  border: 1px solid color-mix(in srgb, var(--caution-mark) 42%, transparent);
}

.check__tag--confirmed {
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
}

.check__tag--empty {
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
}

.check__context {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 1px 9px;
  white-space: nowrap;
}

.check__chevron {
  order: 5;
  margin-left: auto;
  display: inline-flex;
  color: var(--muted);
  transition: transform 150ms var(--ease);
}

.check__chevron .icon {
  width: 15px;
  height: 15px;
}

.check__details[open] .check__chevron {
  transform: rotate(90deg);
}

/* Expanded check body — aligned to the right of the spine. */
.check__body {
  padding: 2px 16px 16px 52px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.check__section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.check__flag {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
  color: var(--danger);
}

.check__none {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
}

.check__preview {
  margin: 0 0 8px;
  font-size: 13.5px;
  color: var(--fg);
  overflow-wrap: anywhere;
}

/* Readable evidence fields from a result's structured content. */
.facts {
  display: grid;
  grid-template-columns: minmax(0, 11rem) minmax(0, 1fr);
  gap: 4px 12px;
  margin: 0 0 8px;
  font-size: 13px;
}

.fact__key {
  margin: 0;
  color: var(--muted);
}

.fact__value {
  margin: 0;
  color: var(--fg);
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

/* Uncertainty caveat drawn from the data itself — ochre marker + text, kept
   visually distinct from confirmed observations. */
.check__note {
  position: relative;
  margin: 0 0 8px;
  padding-left: 18px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--caution);
}

.check__note::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--caution-mark);
}

.check__pre,
.raw__pre {
  margin: 0;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
}

.check__details[open] .check__pre,
.check__details[open] .raw__pre {
  background: var(--surface-2);
}

.raw {
  margin-top: 2px;
}

.raw__summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}

.raw__summary::-webkit-details-marker {
  display: none;
}

.raw__summary::before {
  content: "+";
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
}

.raw[open] .raw__summary::before {
  content: "−";
}

.raw__pre {
  margin-top: 8px;
}

.raw__truncated {
  color: var(--muted);
}

/* ---------------------------------------------------------------------------
 * Follow-ups
 * ------------------------------------------------------------------------- */
.followups {
  margin-top: 16px;
}

.followups__label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.followups__row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.followup {
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 6px 13px;
  cursor: pointer;
  transition: border-color 140ms var(--ease), background-color 140ms var(--ease),
    color 140ms var(--ease);
}

.followup:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-weak);
}

/* ---------------------------------------------------------------------------
 * Loading + error
 * ------------------------------------------------------------------------- */
.loading__line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  color: var(--fg);
}

.loading__dots {
  display: inline-flex;
  gap: 3px;
}

.loading__dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--faint);
  animation: bounce 1.2s ease-in-out infinite;
}
.loading__dot:nth-child(2) {
  animation-delay: 0.15s;
}
.loading__dot:nth-child(3) {
  animation-delay: 0.3s;
}

.loading__sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.error {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

/* Shared header row for error + partial states: title and a machine-readable
   code chip side by side (honest, developer-facing — never internal detail). */
.state__head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.state__code {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
}

.msg--error .state__code {
  color: var(--danger);
  background: var(--danger-weak);
  border: 1px solid var(--danger-border);
}

.msg--partial .state__code {
  color: var(--caution);
  background: var(--caution-weak);
  border: 1px solid color-mix(in srgb, var(--caution-mark) 42%, transparent);
}

.error__title {
  margin: 0;
  font-weight: 600;
  color: var(--danger);
}

.error__detail {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

/* Partial result — real evidence streamed, then interrupted. */
.partial {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.partial__title {
  margin: 0;
  font-weight: 600;
  color: var(--caution);
}

.partial__detail {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.error__retry {
  margin-top: 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 13.5px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  cursor: pointer;
  transition: border-color 140ms var(--ease), background-color 140ms var(--ease);
}

.error__retry:hover {
  border-color: var(--accent);
  background: var(--surface);
}

.error__retry .icon {
  width: 15px;
  height: 15px;
}

/* ---------------------------------------------------------------------------
 * Composer
 * ------------------------------------------------------------------------- */
.composer {
  position: relative;
  padding: 10px 24px 18px;
  background: var(--bg);
}

/* The conversation dissolves into the composer through a short scrim as it
   scrolls under — the input reads as the natural end of the surface. */
.composer::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -26px;
  height: 26px;
  pointer-events: none;
  background: linear-gradient(to top, var(--bg), transparent);
}

.composer__label,
.composer__hint {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.composer__field {
  position: relative;
  max-width: var(--measure);
  margin-inline: auto;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}

.composer__field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak), var(--shadow-sm);
}

.composer__input {
  display: block;
  width: 100%;
  min-height: 24px;
  max-height: 200px;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font: inherit;
  font-size: 15px;
  line-height: 1.55;
  color: var(--fg);
  caret-color: var(--accent);
  padding: 12px 54px 12px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.composer__input::placeholder {
  color: var(--muted);
}

/* Send — the primary interactive action: the one blue disc in the surface. */
.composer__send {
  position: absolute;
  right: 7px;
  bottom: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--accent-contrast);
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 140ms var(--ease), box-shadow 140ms var(--ease),
    transform 120ms var(--ease);
}

.composer__send-icon {
  display: block;
  width: 18px;
  height: 18px;
}

.composer__send:hover:not(:disabled) {
  background: var(--accent-hover);
}

.composer__send:active:not(:disabled) {
  transform: scale(0.92);
}

/* Nothing to send yet: a quiet, defined token — fill + contrast + a hairline
   edge, so it reads as intentionally inactive, never broken. */
.composer__send:disabled {
  background: var(--surface-2);
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  cursor: not-allowed;
}

/* Busy: the arrow gives way to a spinner on the accent disc — the control never
   resizes or shifts the layout. Declared after :disabled so it wins. */
.composer__spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in srgb, var(--accent-contrast) 45%, transparent);
  border-top-color: var(--accent-contrast);
  border-radius: 50%;
  animation: composer-spin 0.7s linear infinite;
}

.composer__send[aria-busy="true"] {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: none;
  cursor: default;
}

.composer__send[aria-busy="true"] .composer__send-icon {
  display: none;
}

.composer__send[aria-busy="true"] .composer__spinner {
  display: block;
}

@keyframes composer-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------------------------------------------------------------------------
 * Inspector (right) — real, derived investigation context
 * ------------------------------------------------------------------------- */
.inspector {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-inspector);
  border-left: 1px solid var(--line);
  overflow: hidden;
}

.app--inspector-collapsed .inspector {
  border-left: 0;
}

.inspector__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 15px 12px 13px 18px;
  border-bottom: 1px solid var(--line);
}

.inspector__eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.inspector__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 24px;
}

.insp-section + .insp-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.insp-section__title {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.insp-kv {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  gap: 7px 12px;
  font-size: 13px;
}

.insp-kv__key {
  color: var(--muted);
}

.insp-kv__value {
  color: var(--fg);
  text-align: right;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.insp-kv__value--mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.insp-kv__value--accent {
  color: var(--accent);
  font-weight: 550;
}

/* Evidence counts as a quiet, divider-separated stat row — not bordered tiles. */
.insp-metrics {
  display: flex;
  gap: 0;
}

.insp-metric {
  position: relative;
  flex: 1;
  padding: 2px 0;
}

.insp-metric + .insp-metric {
  margin-left: 16px;
  padding-left: 16px;
}

.insp-metric + .insp-metric::before {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  bottom: 2px;
  width: 1px;
  background: var(--line);
}

.insp-metric__num {
  font-size: 19px;
  font-weight: 650;
  color: var(--fg-strong);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.insp-metric__num--error {
  color: var(--danger);
}

.insp-metric__label {
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
}

.insp-caption {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}

.insp-tools {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.insp-tool {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.insp-tool__name {
  color: var(--fg);
}

.insp-tool__id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  overflow-wrap: anywhere;
  text-align: right;
}

/* Methodological provenance note — standing, honest, always visible. */
.insp-note {
  position: relative;
  padding-left: 20px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

.insp-note + .insp-note {
  margin-top: 10px;
}

.insp-note__icon {
  position: absolute;
  left: 0;
  top: 1px;
  color: var(--muted);
}

.insp-note__icon .icon {
  width: 14px;
  height: 14px;
}

.insp-note--caution {
  color: var(--caution);
}

.insp-note--caution .insp-note__icon {
  color: var(--caution-mark);
}

.insp-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

/* ---------------------------------------------------------------------------
 * Focus, motion, responsive
 * ------------------------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.invlist__item:focus-visible,
.empty__example:focus-visible,
.followup:focus-visible,
.newbtn:focus-visible,
.theme-toggle:focus-visible,
.error__retry:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.check__summary:focus-visible,
.raw__summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}

.composer__send:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@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;
  }
}

/* --- Inspector overlay breakpoint: below 1120px it becomes a right drawer --- */
@media (max-width: 1119px) {
  .app,
  .app--inspector-collapsed {
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
  }

  .inspector {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 40;
    width: min(var(--inspector-w), 86vw);
    height: 100dvh;
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow-pop);
    transform: translateX(100%);
    transition: transform 220ms var(--ease);
  }

  .app--inspector-open .inspector {
    transform: translateX(0);
  }

  .app--inspector-open .scrim {
    opacity: 1;
    pointer-events: auto;
  }
}

/* --- Rail overlay breakpoint: below 760px it becomes a left drawer --- */
@media (max-width: 759px) {
  .app,
  .app--inspector-collapsed {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 40;
    width: min(var(--rail-w), 84vw);
    height: 100dvh;
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow-pop);
    transform: translateX(-100%);
    transition: transform 220ms var(--ease);
  }

  .app--rail-open .rail {
    transform: translateX(0);
  }

  .app--rail-open .scrim {
    opacity: 1;
    pointer-events: auto;
  }

  .rail__close {
    display: inline-flex;
  }

  .topbar__menu {
    display: inline-flex;
  }

  .topbar {
    padding: 11px 14px;
    gap: 10px;
  }

  .conversation {
    padding: 20px 16px 24px;
    gap: 22px;
  }

  .composer {
    padding: 8px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .composer__input {
    font-size: 16px; /* ≥16px stops iOS zoom-on-focus */
    padding: 14px 58px 14px 16px;
  }

  .composer__send {
    width: 42px;
    height: 42px;
  }

  .composer__send-icon {
    width: 20px;
    height: 20px;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
  }

  .status__label {
    display: none;
  }

  .check__summary {
    padding-right: 12px;
  }
}

/* Keep the inspector drawer comfortably wide, and both drawers full-bleed-ish,
   on very narrow phones. */
@media (max-width: 759px) {
  .inspector {
    width: min(360px, 90vw);
  }
}

/* ---------------------------------------------------------------------------
 * Markdown — rendered assistant answers (.answer__md). Themed via tokens, so it
 * reads correctly in both dark and light. All nodes are built by app.js with
 * textContent; nothing here renders raw HTML.
 * ------------------------------------------------------------------------- */
.answer__md {
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--fg);
  overflow-wrap: anywhere;
}

.answer__md > :first-child {
  margin-top: 0;
}
.answer__md > :last-child {
  margin-bottom: 0;
}

.answer__md .md-p {
  margin: 0 0 10px;
}

.answer__md h1,
.answer__md h2,
.answer__md h3,
.answer__md h4,
.answer__md h5,
.answer__md h6 {
  margin: 18px 0 8px;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--fg-strong);
}
.answer__md h1 {
  font-size: 20px;
}
.answer__md h2 {
  font-size: 18px;
}
.answer__md h3 {
  font-size: 16px;
}
.answer__md h4,
.answer__md h5,
.answer__md h6 {
  font-size: 14.5px;
}

.answer__md strong {
  font-weight: 650;
  color: var(--fg-strong);
}
.answer__md em {
  font-style: italic;
}

.answer__md a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}
.answer__md a:hover {
  text-decoration-thickness: 2px;
}

.answer__md .md-list {
  margin: 0 0 10px;
  padding-left: 1.4em;
}
.answer__md ul.md-list {
  list-style: disc;
}
.answer__md ol.md-list {
  list-style: decimal;
}
.answer__md .md-list li {
  margin: 3px 0;
}

/* Inline code + fenced blocks: mono family on a subtle surface. */
.answer__md .md-code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.answer__md p .md-code,
.answer__md li .md-code,
.answer__md td .md-code,
.answer__md th .md-code {
  padding: 0.1em 0.4em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
}
.answer__md .md-pre {
  margin: 0 0 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.answer__md .md-pre .md-code {
  display: block;
  padding: 0;
  background: none;
  border: 0;
  white-space: pre;
  line-height: 1.5;
  color: var(--fg);
}

/* Tables: readable header, subtle borders, horizontal scroll when too wide. */
.answer__md .md-table-wrap {
  margin: 0 0 12px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  -webkit-overflow-scrolling: touch;
}
.answer__md .md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.answer__md .md-table th,
.answer__md .md-table td {
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
.answer__md .md-table th {
  white-space: nowrap;
}
.answer__md .md-table th:last-child,
.answer__md .md-table td:last-child {
  border-right: 0;
}
.answer__md .md-table thead th {
  background: var(--surface);
  color: var(--fg-strong);
  font-weight: 600;
}
.answer__md .md-table tbody tr:last-child td {
  border-bottom: 0;
}
.answer__md .md-table tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--surface) 45%, transparent);
}
