/* Thread-surface half of the one --chat-* custom-property namespace the whole widget speaks. The
   system half (accent, panel, ink, lines, shadows, radii, fonts) lives in ui-kit-system/tokens.css,
   which also declares `color-scheme: light dark` plus the .light / .dark scheme classes. Every token
   is declared exactly once, and every color token that differs between schemes is one light-dark()
   pair, so a scheme is a single color-scheme flip on the widget's root wrap and the two halves can
   never drift apart. Tokens that are pure skin (radii, font stacks, type scale) carry one value.

   Everything sits at :host,:root so an extension's accent override tag, appended later at the same
   specificity, still wins by source order. */

:root,
:host {
  --chat-bg: light-dark(var(--chat-ground), var(--chat-panel));

  --chat-prompt: light-dark(var(--chat-text), #c9c1c2);
  --chat-body-settled: light-dark(var(--chat-text-2), #c2bcb9);
  --chat-action: light-dark(var(--chat-text-2), #b0a9a9);
  --chat-mono-lift: light-dark(var(--chat-text-3), #9a9391);

  --chat-trace-gutter: 18px;
  --chat-mark: calc(var(--chat-trace-gutter) / 2);
  --chat-mark-dot: calc(var(--chat-mark) / 3);
  --chat-trace-clamp: 13rem;
  --chat-trace-clamp-tall: 20rem;

  --shiki-foreground: light-dark(#26303f, #b9b2b0);
  --shiki-background: light-dark(#f7f8fa, #121115);
  --shiki-ansi-black: light-dark(#3f4650, #4a4548);
  --shiki-ansi-green: light-dark(#15803d, #6fbf8b);
  --shiki-ansi-red: light-dark(#b91c1c, #d98070);
  --shiki-ansi-blue: light-dark(#1d4ed8, #c9a86a);
  --shiki-ansi-yellow: light-dark(#a16207, #c9a86a);
  --shiki-ansi-magenta: light-dark(#9b3d6b, #c9857f);
  --shiki-ansi-cyan: light-dark(#0e7490, #8fb4b0);
  --shiki-ansi-white: light-dark(#26303f, #ded8d4);
  --shiki-ansi-bright-black: light-dark(#5b6675, #6b666b);
  --shiki-ansi-bright-green: light-dark(#16a34a, #8fd6a6);
  --shiki-ansi-bright-red: light-dark(#dc2626, #e59a8c);
  --shiki-ansi-bright-blue: light-dark(#2563eb, #d8bd8a);
  --shiki-ansi-bright-yellow: light-dark(#ca8a04, #d8bd8a);
  --shiki-ansi-bright-magenta: light-dark(#b4457c, #d89d97);
  --shiki-ansi-bright-cyan: light-dark(#0891b2, #a8ccc8);
  --shiki-ansi-bright-white: light-dark(#0b0d10, #f0ebe8);
  --shiki-token-keyword: light-dark(#9b3d6b, #c9857f);
  --shiki-token-function: light-dark(#7a4a1f, #d8b48a);
  --shiki-token-string: light-dark(#1f6b45, #8fb48c);
  --shiki-token-string-expression: light-dark(#1f6b45, #8fb48c);
  --shiki-token-constant: light-dark(#7a4a1f, #cbaa76);
  --shiki-token-parameter: light-dark(#26303f, #b9b2b0);
  --shiki-token-comment: light-dark(#5b6675, #8a8482);
  --shiki-token-punctuation: light-dark(#5b6675, #8a8588);
  --shiki-token-link: light-dark(#1d4ed8, #c9857f);
  --shiki-token-inserted: light-dark(#15803d, #6fbf8b);
  --shiki-token-deleted: light-dark(#b91c1c, #d98070);
  --shiki-token-changed: light-dark(#a16207, #c9a86a);

  --diffs-addition-color-override: var(--chat-success);
  --diffs-deletion-color-override: var(--chat-danger);
  --diffs-bg-addition-override: light-dark(color-mix(in oklch, var(--chat-success) 14%, var(--chat-bg)), #16241c);
  --diffs-bg-deletion-override: light-dark(color-mix(in oklch, var(--chat-danger) 14%, var(--chat-bg)), #2a1a18);
  --diffs-bg-addition-emphasis-override: color-mix(in oklch, var(--chat-success) 24%, transparent);
  --diffs-bg-deletion-emphasis-override: color-mix(in oklch, var(--chat-danger) 24%, transparent);

  --chat-text-xs: 0.6875rem;
  --chat-text-sm: 0.75rem;
  --chat-text-md: 0.8125rem;
  --chat-text-body: 0.875rem;
  --chat-text-lg: 1rem;
  --chat-text-micro: 0.59375rem;
  --chat-focus: 0.125rem solid var(--chat-accent);

  --chat-status-running: var(--chat-accent);
  --chat-status-waiting: var(--chat-warn);
  --chat-status-failed: var(--chat-danger);
  --chat-status-done: var(--chat-success);
  --chat-on-status: var(--chat-on-accent);

  --chat-glyph: light-dark(rgba(15, 18, 24, 0.28), #5f595d);
  --chat-target: light-dark(var(--chat-text-2), #ded8d4);
  --chat-code: light-dark(var(--chat-text-2), var(--chat-accent-hi));
  --chat-summary: light-dark(var(--chat-text-2), #c4beba);
  --chat-microlabel: light-dark(var(--chat-text-3), #6b666b);
  --chat-faint: light-dark(var(--chat-text-3), #5f5a5f);
  --chat-hint: light-dark(var(--chat-text-3), #5c575c);
  --chat-separator: light-dark(var(--chat-glyph), #454145);
  --chat-affordance: light-dark(var(--chat-text-2), #928c8c);
  --chat-queue-bg: light-dark(var(--chat-sunken), #151418);

  --chat-frame-bg: light-dark(var(--chat-sunken), #121115);
  --chat-frame-line: light-dark(var(--chat-line), #262227);
  --chat-frame-line-error: light-dark(var(--chat-danger-line), #4a2b28);
  --chat-frame-text: light-dark(var(--chat-text-2), #9a9294);
  --chat-frame-text-error: light-dark(var(--chat-danger), #d9a099);

  --chat-perm-bg: light-dark(rgba(202, 138, 4, 0.08), #1a1712);
  --chat-perm-line: light-dark(rgba(202, 138, 4, 0.35), #4a3d22);
  --chat-perm-chip-bg: light-dark(rgba(202, 138, 4, 0.14), #2a2314);
  --chat-perm-label: light-dark(#92620a, #c9a86a);
  --chat-perm-path: light-dark(var(--chat-text), #d8bd8a);

  --chat-rail-bg: light-dark(var(--chat-panel), #1b191d);
  --chat-statusbar-bg: light-dark(var(--chat-panel), #141317);

  --chat-selection-bg: light-dark(rgba(37, 99, 235, 0.25), #453739);
  --chat-perforation: light-dark(var(--chat-line), var(--chat-line-2));
}

/* Chat prose ramp: the typography preset colors headings and bold `inherit`, which flattens them onto
   the body color. Markdown output is generated markup, so its descendants are styled here rather than
   through utility variants on the prose-chat shortcut. */
.prose-chat :is(h1, h2, h3, h4, h5, h6),
.prose-chat strong {
  color: var(--chat-text-hi);
}

.prose-chat :not(pre) > code {
  background: transparent;
  color: var(--chat-code);
  padding: 0;
  font-size: 12px;
}

/* Markdown code fences: shiki renders the shared css-variables theme, so token colors resolve from
   the --shiki-* set above and follow the resolved scheme. The fence surface stays flat so it reads as
   part of the message, not as a pasted block. A fence the highlighter leaves plain (a language it has no
   grammar for, or one whose tokens have not arrived yet) takes the same surface and base text color, so it
   reads as code instead of the typography preset's pale pre text meant for a dark block. */
.shiki {
  background: transparent !important;
}

.prose-chat pre {
  background: transparent;
  color: var(--shiki-foreground);
}

.prose-chat .chat-diagram {
  margin-block: calc(var(--chat-space) * 5);
  overflow-x: auto;
}

.prose-chat .chat-diagram svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Compact markdown for one-glance excerpts: one type size taken from the container, no heading scale,
   no block spacing, and a fence reads as inline code, so a clipped excerpt keeps a fixed line height. */
.chat-markdown-compact {
  overflow-wrap: anywhere;
}

.chat-markdown-compact * {
  margin: 0;
  padding: 0;
  font-size: inherit;
  line-height: inherit;
}

.chat-markdown-compact li {
  list-style-position: inside;
}

.chat-markdown-compact pre {
  white-space: normal;
}

.chat-markdown-compact code {
  font-family: var(--chat-mono);
  color: var(--chat-code);
}

/* @pierre/diffs (tool-card code blocks) resolves its dual theme via CSS `color-scheme`, but sets
   `color-scheme: light dark` on its own shadow host inside `@layer base`, which would follow the OS
   rather than the widget. This unlayered rule beats that layered one and hands the component the
   scheme the widget resolved. */
diffs-container {
  color-scheme: inherit;
}

/* Streaming answer caret: overrides solid-streamdown's glyph caret (--sd-caret) with a solid
   block that blinks on a hard step curve, appended after the last streamed block via ::after. */
.chat-caret-live.sd-root > *:last-child::after {
  content: '';
  display: inline-block;
  inline-size: 7px;
  block-size: 13px;
  margin-inline-start: 1px;
  vertical-align: text-bottom;
  background: var(--chat-accent);
  animation: chat-caret-blink 1.05s steps(2, jump-none) infinite;
}

@keyframes chat-caret-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-caret-live.sd-root > *:last-child::after {
    animation: none;
    opacity: 1;
  }
}

@property --chat-thread-total-size {
  syntax: '<length>';
  inherits: false;
  initial-value: 0px;
}
