/* Chat-specific styles: markdown rendering (streamdown output) and the
 * streaming/thinking animations. */

/* Answers are read at length, so their ink sits further from the page than
 * the theme's UI text: pulled toward black on a light scheme and toward white
 * on a dark one, from whatever ink the theme (or an org palette) supplies. */
.chat-ink {
  --chat-ink: light-dark(
    color-mix(in oklab, var(--theme-app, #000) 60%, black),
    color-mix(in oklab, var(--theme-app, #fff) 75%, white)
  );
  color: var(--chat-ink);
  --tw-prose-body: var(--chat-ink);
  --tw-prose-headings: var(--chat-ink);
  --tw-prose-bold: var(--chat-ink);
  --tw-prose-code: var(--chat-ink);
}

/* Links */
.markdown a {
  color: var(--theme-link, #428bca);
  text-decoration: none;
}
.markdown a:hover {
  text-decoration: underline;
}

/* Lists hang their markers in the gutter so a wrapped line lines up with the
 * text above it, not with the number. Streamdown sets them inside. */
.markdown ol,
.markdown ul {
  list-style-position: outside;
  padding-left: 1.625em;
}
.markdown li {
  padding-left: 0.25em;
}

/* Horizontal rules */
.markdown hr {
  display: block;
  height: 0;
  border: 0;
  border-top: 1px solid var(--theme-border, #e5e7eb);
  margin: 1.5em 0;
  padding: 0;
}

/* Inline code; a fenced block is a CodeBlock, which styles itself. A tint of
 * the ink and no border: a hard outline turns every identifier into a keycap. */
.markdown code {
  /* rem, not em: a table cell or list already sized down would size it twice. */
  font-size: 0.875rem;
  font-family: var(--font-mono, ui-monospace, monospace);
  padding: 0.125em 0.375em;
  background-color: color-mix(in oklab, var(--theme-app, #000) 8%, transparent);
  border-radius: 0.25rem;
  /* Identifiers carry a color of their own so they read as code at a glance
   * without the weight the plugin gives them: the theme's link blue, which
   * every palette already keeps legible on its surfaces. */
  color: var(--theme-link, #2f6fa8);
  font-weight: 400;
}
/* Reset inline code styles when inside a pre (code block) */
.markdown pre code {
  padding: 0;
  background-color: transparent;
  border: none;
  border-radius: 0;
  font-size: inherit;
  color: inherit;
}

/* KaTeX overrides. Its own sheet loads with the markdown renderer, after
 * this one, so these need the extra class to win. A wide display formula
 * scrolls instead of widening the answer. */
.markdown .katex-display {
  margin: 1em 0;
  overflow-x: auto;
  overflow-y: hidden;
}
.markdown .katex {
  font-size: 1.1em;
}

/* Subscript and superscript */
.markdown sub,
.markdown sup {
  font-size: 75%;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}
.markdown sup {
  top: -0.5em;
}
.markdown sub {
  bottom: -0.25em;
}

/* Images */
.markdown img {
  border: 0;
  max-width: 100%;
  height: auto;
  vertical-align: middle;
  border-radius: 0.5rem;
}

/* Streamdown tables: the body's own type, open rows on hairlines at a tenth
 * of the ink under a firmer rule for the header (no frame, no fill, so a
 * table reads as part of the answer rather than a widget dropped into it),
 * and the copy/download controls only while the pointer is over the table. */
.markdown [data-streamdown="table-wrapper"] {
  --table-line: color-mix(in oklab, var(--theme-app, #000) 10%, transparent);
  position: relative;
  display: block;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0.75rem 0;
}
.markdown [data-streamdown="table-wrapper"] > div:first-child {
  position: absolute;
  top: 0.375rem;
  right: 0.375rem;
  z-index: 1;
  gap: 0.125rem;
  padding: 0.125rem;
  border-radius: 0.375rem;
  background: var(--theme-panel-bg, #fff);
  border: 1px solid var(--table-line);
  opacity: 0;
  transition: opacity 150ms ease-out;
}
.markdown [data-streamdown="table-wrapper"]:hover > div:first-child,
.markdown [data-streamdown="table-wrapper"]:focus-within > div:first-child {
  opacity: 1;
}
.markdown [data-streamdown="table-wrapper"] > div:last-child {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.markdown [data-streamdown="table-wrapper"] table {
  margin: 0;
  font-size: 1rem;
  line-height: 1.5;
}
.markdown [data-streamdown="table"] th {
  padding: 0.4375rem 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: inherit;
  background: transparent;
  border-bottom: 1px solid color-mix(in oklab, var(--theme-app, #000) 28%, transparent);
}
.markdown [data-streamdown="table"] td {
  padding: 0.4375rem 0.75rem;
  /* Streamdown sizes cells down with its own class; the table is body type. */
  font-size: 1rem;
  line-height: 1.5;
  vertical-align: top;
  color: inherit;
  /* A prose column keeps enough room to read; a wide table scrolls instead. */
  min-width: 9rem;
}
.markdown [data-streamdown="table"] thead {
  background: transparent;
}
/* Unframed, the outer columns line up with the prose around the table. */
.markdown [data-streamdown="table"] :is(th, td):first-child {
  padding-left: 0;
}
.markdown [data-streamdown="table"] :is(th, td):last-child {
  padding-right: 0;
}
.markdown [data-streamdown="table"] tbody tr {
  border-bottom: 1px solid var(--table-line);
}
.markdown [data-streamdown="table"] tbody tr:last-child {
  border-bottom: 0;
}
/* Markdown set inside other UI, such as a step's summary, reads at the page's
 * text size, its headings a step above it rather than at a document's sizes. */
.markdown-compact {
  font-size: 0.875rem;
  line-height: 1.5;
}
.markdown-compact :is(h1, h2, h3, h4, h5, h6) {
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 600;
}
.markdown-compact :is(h1, h2) {
  font-size: 1rem;
  line-height: 1.5rem;
}
.markdown-compact [data-streamdown="table-wrapper"] table,
.markdown-compact [data-streamdown="table"] :is(th, td) {
  font-size: 0.875rem;
  line-height: 1.25rem;
}
/* A summary's tables are mostly a few short columns of counts: they hug their
 * content so each number sits by its label, and a phone fits them unscrolled. */
.markdown-compact table[data-streamdown="table"] {
  width: auto;
  min-width: min(100%, 20rem);
}
.markdown-compact [data-streamdown="table"] :is(th, td) {
  min-width: 0;
  padding-inline-end: 2rem;
  font-variant-numeric: tabular-nums;
}
.markdown-compact [data-streamdown="table"] th {
  font-weight: 500;
  color: var(--theme-muted-text-color);
}
.markdown-compact :not(pre) > code {
  font-size: 0.8125rem;
}
@media (prefers-reduced-motion: reduce) {
  .markdown [data-streamdown="table-wrapper"] > div:first-child {
    transition: none;
  }
}

/* Remove prose backtick pseudo-elements on inline code */
.markdown code::before,
.markdown code::after {
  /* biome-ignore lint/complexity/noImportantStyles: the typography styles add these with a more specific selector */
  content: none !important;
}

/* Task lists (checkboxes) */
.markdown input[type="checkbox"] {
  margin-right: 0.5em;
  vertical-align: middle;
}
.markdown li:has(> input[type="checkbox"]) {
  list-style: none;
  margin-left: -1.5em;
}

/* Touch device: always show chat actions */
@media (hover: none) {
  .chat-actions,
  .chat-meta {
    /* biome-ignore lint/complexity/noImportantStyles: must win over the utility classes that hide these until hover */
    opacity: 1 !important;
    /* biome-ignore lint/complexity/noImportantStyles: must win over the utility classes that hide these until hover */
    pointer-events: auto !important;
  }
}

/* Long finished replies clamp with a bottom fade; mask keeps the fade
 * background-agnostic across themes. */
.chat-message-clamp {
  max-height: 600px;
  overflow: hidden;
  mask-image: linear-gradient(to bottom, black calc(100% - 96px), transparent);
  -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 96px), transparent);
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

@utility animate-shimmer {
  animation: shimmer 1.75s linear infinite;
  background-size: 200% 100%;
}

@utility text-shimmer {
  background-image: linear-gradient(
    90deg,
    var(--theme-muted-text-color, #6a7282) 0%,
    var(--theme-accent, #06354f) 20%,
    var(--theme-muted-text-color, #6a7282) 40%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* The shimmer sweeps forever, so under reduced motion it holds still: the
 * text drawn plainly in the accent, the color the sweep passes through. */
@media (prefers-reduced-motion: reduce) {
  .animate-shimmer {
    animation: none;
  }
  .text-shimmer {
    background-image: none;
    color: var(--theme-accent, #06354f);
  }
}

/* Entrance animation for chat messages (CSS replacement for a JS motion lib).
 * Only `from` is defined so elements settle at their natural styles (queued
 * messages render at reduced opacity). */
@keyframes chat-fade-in-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@utility animate-chat-enter {
  animation: chat-fade-in-up 0.25s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .animate-chat-enter {
    animation: none;
  }
}

/* Tints of the ink for controls that sit on the panel: the theme's hover is a
 * shade off another surface and would not read as a highlight here. */
@utility chat-tint {
  background-color: color-mix(in oklab, var(--theme-app, #000) 6%, transparent);
}
@utility chat-tint-strong {
  background-color: color-mix(in oklab, var(--theme-app, #000) 10%, transparent);
}

/* The composer is one surface lifted off the page: a hairline of the ink for
 * its edge, and a short, soft shadow that deepens while it has focus. The
 * shadow is black on every scheme; an ink-colored one would glow on dark. */
.chat-composer {
  box-shadow:
    0 0 0 1px color-mix(in oklab, var(--theme-app, #000) 12%, transparent),
    0 1px 2px rgb(0 0 0 / 0.04),
    0 6px 16px -8px rgb(0 0 0 / 0.12);
  transition: box-shadow 200ms cubic-bezier(0.16, 1, 0.3, 1);
}
.chat-composer:focus-within {
  box-shadow:
    0 0 0 1px color-mix(in oklab, var(--theme-app, #000) 22%, transparent),
    0 1px 2px rgb(0 0 0 / 0.05),
    0 10px 24px -10px rgb(0 0 0 / 0.18);
}
/* A `!` command takes a terminal's shell-mode magenta as the box's accent: its
 * edge, its caret and its focus ring. */
.chat-composer.chat-composer-shell {
  --chat-accent: var(--theme-ansi-magenta);
  box-shadow:
    0 0 0 1px var(--theme-ansi-magenta),
    0 1px 2px rgb(0 0 0 / 0.04),
    0 6px 16px -8px rgb(0 0 0 / 0.12);
}

/* The thread scrolls under the dock and the jump pill, so they must hide it
 * even when a theme makes the panel color translucent: a second layer of the
 * same color leaves the thread at most a hundredth visible. */
.chat-composer-dock,
.chat-jump {
  background:
    linear-gradient(var(--theme-panel-bg, #fff), var(--theme-panel-bg, #fff)),
    var(--theme-panel-bg, #fff);
}

.chat-jump:hover {
  background:
    linear-gradient(var(--theme-muted-panel-bg, #f3f4f6), var(--theme-muted-panel-bg, #f3f4f6)),
    var(--theme-muted-panel-bg, #f3f4f6);
}

/* The prompt of the turn in view, pinned once it scrolls out of sight. It
 * floats on the thread like the jump pill, with the composer's edge, shadow
 * and focus ring (.chat-composer). Its wash is laid on the panel so it hides
 * the lines scrolling under it. The transparent outline shows only in forced
 * colors, where the ring's shadow is dropped. */
.chat-prompt-pin {
  animation: chat-pin-enter 180ms cubic-bezier(0.16, 1, 0.3, 1);
}
.chat-prompt-pin button {
  --chat-pin-wash: color-mix(
    in oklab,
    var(--theme-accent, #06354f) 9%,
    var(--theme-panel-bg, #fff)
  );
  background:
    linear-gradient(var(--chat-pin-wash), var(--chat-pin-wash)), var(--theme-panel-bg, #fff);
}
.chat-prompt-pin button:hover {
  --chat-pin-wash: color-mix(
    in oklab,
    var(--theme-accent, #06354f) 16%,
    var(--theme-panel-bg, #fff)
  );
}
.chat-prompt-pin button:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
}

@keyframes chat-pin-enter {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-prompt-pin {
    animation: none;
  }
}

/* The thread runs under the docked composer and fades out above it, so the
 * last lines dissolve rather than cut off at the dock's edge. */
.chat-composer-dock::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: 100%;
  height: 1.5rem;
  background: linear-gradient(to top, var(--theme-panel-bg, #fff), transparent);
  pointer-events: none;
}

/* On the stage the composer scrolls with the page and nothing runs under it,
 * so the dock paints nothing: its second layer of a translucent panel color
 * would show as a band across the page. */
.chat-stage .chat-composer-dock {
  background: none;
}
.chat-stage .chat-composer-dock::before {
  content: none;
}

@media (prefers-reduced-motion: reduce) {
  .chat-composer {
    transition: none;
  }
}

/* The tail of the reasoning while it streams fades in from the top, so the
 * lines scrolling out read as more above rather than as cut off. */
.chat-reasoning-tail {
  mask-image: linear-gradient(to bottom, transparent, black 1.25rem);
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 1.25rem);
}

/* An edge drawn from the ink rather than the theme's border, so a card reads
 * the same on the panel and on a tinted bubble. */
.chat-hairline {
  box-shadow: 0 0 0 1px color-mix(in oklab, var(--theme-app, #000) 10%, transparent);
}

/* A bubble carrying pastes would shrink to its shortest line and squeeze
 * its cards and blocks into a column; give it room for them to read. */
.chat-bubble-roomy {
  min-width: min(100%, 24rem);
}

/* ---- Accent ---------------------------------------------------------------
 * The host's accent is the chat's signature: the send button, the caret, the
 * focus ring, the thinking shimmer and the tint on what the reader wrote. Everything else stays ink, so the accent always means "this is the
 * conversation's own voice or the reader's next move". */
.chat-thread,
.chat-composer,
.chat-empty,
.chat-reasoning-body {
  --chat-accent: var(--theme-accent, var(--theme-accent, #06354f));
}

/* What the reader wrote carries a wash of the accent: theirs, not the
 * assistant's, at a glance. */
.chat-bubble-user {
  background-color: color-mix(
    in oklab,
    var(--theme-accent, #06354f) 9%,
    var(--theme-panel-bg, #fff)
  );
}

/* The reader's next move is the accent: the caret in the box, its ring on
 * focus, and (in ChatInput) the filled send button. */
.chat-composer textarea {
  caret-color: var(--chat-accent);
}
.chat-composer:focus-within {
  box-shadow:
    0 0 0 1px color-mix(in oklab, var(--chat-accent) 55%, transparent),
    0 0 0 4px color-mix(in oklab, var(--chat-accent) 12%, transparent),
    0 10px 24px -10px rgb(0 0 0 / 0.18);
}
@utility chat-send-idle {
  background-color: color-mix(in oklab, var(--theme-accent, #06354f) 14%, transparent);
  color: color-mix(in oklab, var(--theme-accent, #06354f) 70%, var(--theme-panel-bg, #fff));
}

/* The reply being written ends in the accent's caret. Matched by a class, not by the inline style
   that sets the caret: a rule reaching past an element its style attribute selects makes every
   inline style change anywhere on the page restyle that element's whole subtree. */
.chat-thread .markdown-streaming > :last-child::after {
  color: var(--chat-accent);
}

/* A list's caret follows its last item's text rather than sitting on a line
   of its own under the list. */
.markdown-streaming > :is(ul, ol):last-child:not([data-sd-caret-hidden])::after {
  content: none;
}
.markdown-streaming > :is(ul, ol):last-child > li:last-child::after {
  display: inline;
  vertical-align: baseline;
  content: var(--streamdown-caret);
}
.chat-thread .markdown-streaming > :is(ul, ol):last-child > li:last-child::after {
  color: var(--chat-accent);
}

/* A thought hangs off a line of the accent rather than a gray rule. */
.chat-reasoning-body {
  border-left: 1px solid color-mix(in oklab, var(--theme-accent, #06354f) 35%, transparent);
}

/* A paste in the reader's bubble is a code block like the assistant's, set on
 * the panel so it stands off the bubble's tint, with the bubble's spacing
 * rather than the answer's. */
.chat-paste-code .markdown [data-code-block] {
  margin: 0;
  background: var(--theme-panel-bg, #fff);
  white-space: normal;
}

/* A queued message is written but not yet sent: its own outline, dashed,
 * where a sent one has its fill, so it reads as pending without the text
 * losing contrast. */
.chat-queued .chat-bubble-user {
  background: transparent;
  outline: 1px dashed color-mix(in oklab, var(--theme-app, #000) 30%, transparent);
  outline-offset: -1px;
}

/* Find in the transcript, painted with the CSS Custom Highlight API: every
 * match washed in the accent, and the one the reader is on filled with it. */
::highlight(transcript-find) {
  background-color: color-mix(in oklab, var(--theme-accent, #06354f) 28%, transparent);
}
::highlight(transcript-find-current) {
  background-color: var(--theme-accent, #06354f);
  color: var(--theme-accent-text, #fff);
}

/* The effort slider's scale turns from the theme's accent: one way round the
 * hue circle for faster, the other way and a little deeper for smarter. Each
 * stop takes a set lightness per scheme, so the fill reads on the panel
 * whatever the accent's own lightness, and a gray accent keeps a gray scale
 * rather than inventing a hue. */
.effort-scale {
  --effort-fast: light-dark(
    oklch(from var(--theme-accent, #06354f) 0.6 min(calc(c * 2), 0.15) calc(h - 70)),
    oklch(from var(--theme-accent, #5b9ccf) 0.75 min(calc(c * 2), 0.15) calc(h - 70))
  );
  --effort-mid: light-dark(
    oklch(from var(--theme-accent, #06354f) 0.56 min(calc(c * 2), 0.15) h),
    oklch(from var(--theme-accent, #5b9ccf) 0.72 min(calc(c * 2), 0.15) h)
  );
  --effort-smart: light-dark(
    oklch(from var(--theme-accent, #06354f) 0.52 min(calc(c * 2), 0.15) calc(h + 50)),
    oklch(from var(--theme-accent, #5b9ccf) 0.7 min(calc(c * 2), 0.15) calc(h + 50))
  );
  /* Light in either scheme, so the thumb stands off the fill under it. */
  --effort-thumb: light-dark(var(--theme-panel-bg, #fcfeff), var(--theme-app, #e9f1fa));
}

.effort-scale-fill {
  background: linear-gradient(
    to right in oklch,
    var(--effort-fast),
    var(--effort-mid),
    var(--effort-smart)
  );
}
