/* ══════════════════════════════════════════════════════════════════════════
   chat-v3.css — chat-ui-v3 layer (loaded AFTER blocks.css)

   Everything the 2026-08 chat redesign adds: the live execution timeline
   (tool cards, terminal panes, approval cards, recap), the code_result card,
   code-fence chrome, Prism token mapping, and typography/spacing refinement.

   Rules of this sheet (same contract as tokens.css):
   - tokens only — no raw hex (the terminal + Prism colors come from tokens);
   - logical properties only (margin-inline-*, inset-inline-*), so Arabic RTL
     is correct by construction; code/terminal content is LTR-pinned;
   - both themes come free via tokens; no html.light forks unless a value
     genuinely cannot be expressed as a token;
   - chat-scoped selectors only — style.css is shared by 13 pages and is NOT
     edited by this layer.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Icon primitives ──────────────────────────────────────────────────────── */
.ci-icon {
  width: 14px;
  height: 14px;
  flex: none;
}
.ci-spin {
  width: 14px;
  height: 14px;
  animation: ci-rotate 0.9s linear infinite;
}
@keyframes ci-rotate {
  to { transform: rotate(360deg); }
}
details[open] > summary .ci-chevron,
.tt-terminal:not(.is-collapsed) .tt-terminal-head .ci-chevron,
.code-fence:not(.is-collapsed) .code-fence-toggle .ci-chevron {
  transform: rotate(180deg);
}
.ci-chevron {
  transition: transform 0.15s ease;
}

/* ── Chat column: prose measure + typography ─────────────────────────────── */
.chat-messages-inner {
  max-width: var(--measure-prose);
}
.msg-bubble.is-md,
.streaming-content.is-md {
  line-height: var(--leading-normal);
}
.msg-bubble.is-md p + p {
  margin-block-start: var(--space-3);
}
.msg-bubble code,
.streaming-content code,
.bcr-terminal,
.tt-terminal-body,
.tt-elapsed,
.bcr-duration,
.bcr-exit {
  font-family: var(--font-mono);
}

/* ── Streaming bubble ─────────────────────────────────────────────────────── */
.stream-status-note {
  font-style: italic;
  opacity: 0.8;
}
.stream-caret {
  display: inline-block;
  inline-size: 7px;
  block-size: 1.05em;
  margin-inline-start: 2px;
  vertical-align: text-bottom;
  border-radius: 2px;
  background: var(--accent);
  animation: stream-caret-blink 1.1s steps(2, start) infinite;
}
.msg-bubble:not([data-streaming]) .stream-caret,
.msg-bubble.is-error .stream-caret {
  display: none;
}
@keyframes stream-caret-blink {
  50% { opacity: 0; }
}

/* ── Turn timeline (live execution state) ─────────────────────────────────── */
.turn-timeline {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-block: var(--space-2);
  padding-inline-start: var(--space-1);
}
.turn-timeline.is-summary {
  margin-block: var(--space-2) 0;
}
.tt-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--muted);
}
.tt-item.tt-tool {
  border: 1px solid transparent;
}
.tt-item.is-running {
  color: var(--text);
  background: var(--accent-soft);
  border-color: rgba(var(--accent-rgb), 0.25);
}
.tt-item.is-done .tt-icon { color: var(--ok); }
.tt-item.is-error .tt-icon { color: var(--danger); }
.tt-item.is-soft .tt-icon { color: var(--warn); }
.tt-item.is-running .tt-icon { color: var(--accent); }
.tt-icon {
  display: inline-flex;
  align-items: center;
  margin-block-start: 2px;
}
.tt-main {
  min-inline-size: 0;
  flex: 1;
}
.tt-title {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.tt-tool-name {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text);
}
.tt-sub {
  font-size: var(--text-xs);
  color: var(--muted);
}
.tt-elapsed {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-block-start: 3px;
  font-variant-numeric: tabular-nums;
}
.tt-delegate .tt-icon { color: var(--info); }
.tt-detail {
  font-size: var(--text-xs);
  color: var(--muted);
  unicode-bidi: plaintext;
}
.tt-tool-label {
  font-size: var(--text-sm);
  color: var(--text);
}
.tt-tool-name.is-secondary {
  font-size: var(--text-xs);
  color: var(--muted);
  opacity: 0.8;
}

/* ── "Now doing" ticker (ephemeral, always the last timeline row) ─────────── */
.tt-ticker {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  color: var(--muted);
  font-style: italic;
}
/* display:flex above outweighs the UA's [hidden]{display:none} — restate it,
   or the ticker renders while its hidden attribute says otherwise. */
.tt-ticker[hidden] { display: none; }
.tt-ticker-dot {
  inline-size: 7px;
  block-size: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: tt-ticker-pulse 1.4s ease-in-out infinite;
}
@keyframes tt-ticker-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .tt-ticker-dot { animation: none; opacity: 0.7; }
}

/* ── Narration rows (the model's live progress prose) ─────────────────────── */
.tt-item.tt-narrate {
  padding-block: 2px;
}
.tt-narrate .tt-icon { color: var(--muted); }
.tt-narrate-text {
  font-size: var(--text-sm);
  color: var(--text);
  line-height: var(--leading-normal);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  unicode-bidi: plaintext;
}
.tt-narrate-text.is-typing::after {
  content: "";
  display: inline-block;
  inline-size: 6px;
  block-size: 1em;
  margin-inline-start: 2px;
  vertical-align: text-bottom;
  border-radius: 2px;
  background: var(--accent);
  animation: stream-caret-blink 1.1s steps(2, start) infinite;
}

/* ── Live plan card ───────────────────────────────────────────────────────── */
.tt-item.tt-plan {
  display: block;
  border: 1px solid var(--card-b);
  background: var(--card);
  padding: var(--space-2) var(--space-3);
}
.tt-plan-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
}
.tt-plan-count {
  margin-inline-start: auto;
  font-variant-numeric: tabular-nums;
}
.tt-plan-items {
  list-style: none;
  margin: var(--space-2) 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.tt-plan-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--muted);
}
.tt-plan-glyph {
  display: inline-flex;
  align-items: center;
  inline-size: 14px;
  block-size: 1.2em;
  flex: none;
}
/* Pending items get a quiet dot instead of an icon. */
.tt-plan-item.is-pending .tt-plan-glyph::before {
  content: "";
  inline-size: 5px;
  block-size: 5px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.5;
  margin: auto;
}
.tt-plan-item.is-in_progress { color: var(--text); }
.tt-plan-item.is-in_progress .tt-plan-glyph { color: var(--accent); }
.tt-plan-item.is-done .tt-plan-glyph { color: var(--ok); }
.tt-plan-item.is-failed .tt-plan-glyph { color: var(--danger); }
.tt-plan-item.is-blocked .tt-plan-glyph { color: var(--warn); }
.tt-plan-reason {
  font-size: var(--text-xs);
  color: var(--warn);
  margin-inline-start: var(--space-2);
}

/* ── Live terminal pane ───────────────────────────────────────────────────── */
.tt-terminal {
  margin-block-start: var(--space-2);
  border: 1px solid var(--term-b);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--term-bg);
}
.tt-terminal-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  inline-size: 100%;
  padding: var(--space-1) var(--space-2);
  background: transparent;
  border: 0;
  color: var(--term-dim);
  font-size: var(--text-xs);
  cursor: pointer;
  text-align: start;
}
.tt-terminal-head:hover { color: var(--term-fg); }
.tt-terminal-label { font-weight: 600; }
.tt-terminal-lines { margin-inline-start: auto; font-variant-numeric: tabular-nums; }
.tt-terminal-body {
  max-block-size: 240px;
  overflow: auto;
  padding: var(--space-2) var(--space-3);
  color: var(--term-fg);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  direction: ltr;
  text-align: left; /* terminal content is LTR by nature */
  unicode-bidi: plaintext;
}
.tt-terminal-body .is-stderr { color: var(--term-stderr); }
.tt-terminal-trim {
  color: var(--term-dim);
  font-style: italic;
  padding-block: var(--space-1);
}
.tt-terminal.is-collapsed .tt-terminal-body { display: none; }
.tt-terminal.is-done .tt-terminal-head { color: var(--term-dim); }

/* ── Inline approval card ─────────────────────────────────────────────────── */
.tt-item.tt-approval {
  border: 1px solid var(--warn);
  background: var(--warn-soft);
  color: var(--text);
  padding: var(--space-3);
}
.tt-approval .tt-icon { color: var(--warn); }
.tt-approval.is-approved {
  border-color: var(--ok);
  background: var(--ok-soft);
}
.tt-approval.is-approved .tt-icon { color: var(--ok); }
.tt-approval.is-denied {
  border-color: var(--danger);
  background: var(--danger-soft);
}
.tt-approval.is-denied .tt-icon { color: var(--danger); }
.tt-approval-body {
  margin-block-start: var(--space-1);
  font-size: var(--text-sm);
  color: var(--muted);
}
.tt-actions {
  display: flex;
  gap: var(--space-2);
  margin-block-start: var(--space-3);
}
.tt-btn {
  padding: var(--space-1) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}
.tt-btn:focus-visible { box-shadow: var(--focus-ring); outline: none; }
.tt-btn-approve {
  background: var(--accent);
  color: var(--accent-contrast, #14172E);
}
.tt-btn-approve:hover { filter: brightness(1.08); }
.tt-btn-deny {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.tt-btn-deny:hover { background: var(--danger-soft); }
.tt-approval-verdict {
  margin-block-start: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* ── Turn recap (transplanted into the final message) ────────────────────── */
.turn-summary {
  margin-block-end: var(--space-2);
  border: 1px solid var(--card-b);
  border-radius: var(--radius-md);
  background: var(--card);
  max-inline-size: var(--measure-prose);
}
.turn-summary-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.turn-summary-head::-webkit-details-marker { display: none; }
.turn-summary-head:hover { color: var(--text); }
.turn-summary-head .ci-chevron { margin-inline-start: auto; }
.turn-summary .turn-timeline {
  padding: 0 var(--space-2) var(--space-2);
  margin-block: 0;
}

/* ── code_result card ─────────────────────────────────────────────────────── */
.block-code-result {
  margin-block: var(--space-3);
  border: 1px solid var(--card-b);
  border-radius: var(--radius-lg);
  background: var(--card);
  overflow: hidden;
}
.block-code-result.is-error { border-color: rgba(239, 68, 68, 0.4); }
.bcr-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-block-end: 1px solid var(--card-b);
  color: var(--muted);
}
.bcr-lang {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text);
}
.bcr-status {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 1px var(--space-2);
  border-radius: var(--radius-full);
}
.is-ok > .bcr-head .bcr-status { color: var(--ok); background: var(--ok-soft); }
.is-error > .bcr-head .bcr-status { color: var(--danger); background: var(--danger-soft); }
.is-timeout > .bcr-head .bcr-status { color: var(--warn); background: var(--warn-soft); }
.bcr-duration,
.bcr-exit {
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}
.bcr-spacer { flex: 1; }
.bcr-copy,
.code-fence-copy {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border: 1px solid var(--btn-b, var(--card-b));
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: var(--text-xs);
  cursor: pointer;
}
.bcr-copy:hover,
.code-fence-copy:hover { color: var(--text); border-color: var(--muted); }
.bcr-copy.is-copied,
.code-fence-copy.is-copied { color: var(--ok); border-color: var(--ok); }
.bcr-code { border-block-end: 1px solid var(--card-b); }
.bcr-code-summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.bcr-code-summary::-webkit-details-marker { display: none; }
.bcr-code-summary:hover { color: var(--text); }
.bcr-code-summary .ci-chevron { margin-inline-start: auto; }
.bcr-pre {
  margin: 0;
  padding: var(--space-3);
  overflow-x: auto;
  background: var(--code-theme-bg);
  color: var(--code-theme-fg);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  direction: ltr;
  text-align: left;
}
.bcr-output-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: var(--muted);
}
.bcr-output-note { font-style: italic; }
.bcr-terminal {
  margin: 0 var(--space-3) var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--term-b);
  background: var(--term-bg);
  color: var(--term-fg);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-block-size: 320px;
  overflow: auto;
  text-align: left;
  unicode-bidi: plaintext;
}
.bcr-terminal .is-stderr { color: var(--term-stderr); }
.bcr-files {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: 0 var(--space-3) var(--space-3);
}
.bcr-file-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border: 1px solid var(--card-b);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  color: var(--muted);
}

/* ── Markdown code fences (CodeEnhance chrome) ───────────────────────────── */
.code-fence {
  position: relative;
  margin-block: var(--space-3);
  border: 1px solid var(--card-b);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--code-theme-bg);
}
.code-fence-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2) var(--space-1) var(--space-3);
  border-block-end: 1px solid var(--card-b);
  background: var(--card);
}
.code-fence-lang {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
}
.code-fence-spacer { flex: 1; }
.code-fence > pre {
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  direction: ltr;
  text-align: left;
}
.code-fence.is-collapsible.is-collapsed > pre {
  max-block-size: 16em;
  overflow: hidden;
}
.code-fence.is-collapsible.is-collapsed::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  inset-block-end: 2.2em;
  block-size: 4em;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, var(--code-theme-bg));
}
.code-fence-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  inline-size: 100%;
  padding: var(--space-1);
  border: 0;
  border-block-start: 1px solid var(--card-b);
  background: var(--card);
  color: var(--muted);
  font-size: var(--text-xs);
  cursor: pointer;
}
.code-fence-toggle:hover { color: var(--text); }

/* ── Prism token mapping → the 14 user-selectable code themes ────────────── */
.token.comment, .token.prolog, .token.doctype, .token.cdata { color: var(--code-theme-comment); }
.token.string, .token.char, .token.attr-value, .token.regex { color: var(--code-theme-string); }
.token.number, .token.boolean, .token.constant { color: var(--code-theme-number); }
.token.keyword, .token.atrule, .token.important { color: var(--code-theme-keyword); }
.token.function, .token.class-name, .token.builtin, .token.selector { color: var(--code-theme-attr); }
.token.tag, .token.symbol, .token.deleted { color: var(--code-theme-tag); }
.token.attr-name, .token.property, .token.variable, .token.entity { color: var(--code-theme-attr); }
.token.punctuation, .token.operator, .token.url { color: var(--code-theme-punct); }
.token.bold, .token.important { font-weight: 600; }
.token.italic { font-style: italic; }

/* ── Tables: sticky header inside message scroll wraps ───────────────────── */
.msg-bubble .result-table-wrap,
.block-table.result-table-wrap {
  max-block-size: 420px;
  overflow: auto;
}
.msg-bubble .result-table-wrap thead th,
.block-table.result-table-wrap thead th {
  position: sticky;
  inset-block-start: 0;
  background: var(--card);
  z-index: 1;
}

/* ── Artifact file card polish ────────────────────────────────────────────── */
.msg-artifact-card {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.msg-artifact-card:hover {
  box-shadow: var(--shadow-md);
  border-color: rgba(var(--accent-rgb), 0.4);
}

/* ── Reduced motion ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .ci-spin { animation: none; }
  .stream-caret { animation: none; opacity: 0.7; }
  .ci-chevron { transition: none; }
  .msg-artifact-card { transition: none; }
}

/* ── Small screens ───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .tt-terminal-body { max-block-size: 180px; }
  .bcr-terminal { max-block-size: 220px; }
  .bcr-copy > span, .code-fence-copy > span { display: none; } /* icon-only */
}

/* A connector tool refused by the SYSTEM's permissions (per-user connector
   identity, layer 2): a note with the remedy, where a connect link would sit. */
.tt-identity-note {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted, inherit);
}


/* The scheduled-report dialog's honesty line: what the report will NOT carry.
   A caution, not an error — the action is still the right one to take. */
.msg-sched-note {
  margin: 6px 0 0;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text);
  background: color-mix(in srgb, var(--warn, #d97706) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn, #d97706) 32%, transparent);
  text-align: match-parent;
}
/* The same line when it is reassurance rather than a caveat: the report DOES
   carry the agent. Accent, not warning — nothing here needs acting on. */
.msg-sched-note.is-ok {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}
