/* chat.css — page-specific styles for the chat landing page
 * (and the chat-message response fragment swapped into it).
 *
 * Why this is an external file: the strict CSP rules out inline
 * `<style>` blocks (style-src 'self', no 'unsafe-inline'), so
 * every page's styles have to live in /static. The chat page
 * historically carried an inline `<style>` block in the
 * fallback renderer; it now lives here so the styles load under
 * the strict CSP.
 *
 * Selectors cover three surfaces:
 *   - The chat message log box (.chat-log).
 *   - The chat message rows swapped in by htmx (.chat-msg),
 *     shared with the chat_message.html fragment so the
 *     styles apply to the response content too.
 *   - The htmx-driven loading indicator (.htmx-indicator).
 *     htmx adds the .htmx-request class while a request is
 *     in flight; the .htmx-indicator visibility toggles on
 *     that class via the cascade below.
 */

/* Chat log box — capped height so the page doesn't grow
 * unbounded as messages accumulate; vertical scroll for
 * overflow.
 *
 * position: relative is the anchor for .jump-to-latest
 * below: the button is `position: absolute` and would
 * otherwise pin to the initial containing block (the
 * viewport) and follow the user down the page. Pinning
 * to the chat-log container keeps it visually attached
 * to the message list.
 *
 * The chat card fills the body width — and the body fills
 * the viewport width. The daisyUI `container` class was
 * dropped from the body because its centered max-width cap
 * (~1536px on 2xl) made the chat feel narrow on ultrawide
 * displays. The per-bubble max-widths (operator at 70%,
 * assistant prose at 65ch) are what give individual
 * messages reasonable line lengths, not the card itself,
 * so a 4000px viewport still produces a readable assistant
 * reply (65ch, same as on a 1280px viewport).
 */
.chat-log {
  max-height: 60vh;
  overflow-y: auto;
  position: relative;
}

/*
 * Body horizontal padding. The chat page drops the
 * daisyUI `container` class on <body> so the chat-log
 * card and chat-form card can use the full viewport
 * width. Without padding, the cards would touch the
 * viewport edges. This rule adds 8px (0.5rem) of
 * horizontal padding on small viewports and 16px
 * (1rem) on screens >= 640px (Tailwind's `sm`
 * breakpoint) — the same scale the daisyUI `container`
 * class used to provide. Why a CSS rule here instead
 * of a `px-2 sm:px-4` utility class on the body: the
 * shipped daisyui.min.css is tree-shaken from the
 * source files; a contributor who changes the body
 * class would need to run `make css` to regenerate
 * the bundle. A CSS rule on `body` lives in chat.css
 * (which is not tree-shaken — it ships verbatim) and
 * applies immediately, no rebuild required.
 */
body {
  padding-inline: 0.5rem;
}
@media (min-width: 40rem) {
  body {
    padding-inline: 1rem;
  }
}

/*
 * Chat form card. Full body width to align with the
 * chat-log above it. The textarea + source-kind
 * checkboxes span the body the same way the chat
 * scrollback does.
 */
#chat-form {
  width: 100%;
}

/* Chat message rows. The word-break rules prevent a single
 * long token (a long URL, a long markdown code span) from
 * stretching the box horizontally; overflow-wrap + break-word
 * is the modern equivalent of word-wrap: break-word. */
.chat-msg {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/*
 * Operator bubble max-width: daisyUI's chat-bubble defaults
 * to max-width: 90% of its grid column. The 70% cap on the
 * operator side was originally added so a short question
 * didn't read as a prose paragraph (a chat-app convention
 * — ChatGPT / Notion AI both narrow operator messages
 * relative to the scrollback). The user reported that on
 * a full-width chat-log card the 70% cap left the operator
 * bubble at ~377px on a 1920px viewport — about 20% of
 * the card — and "did not use the horizontal space
 * available." The cap is widened to 90% (daisyUI's own
 * default) so the operator message uses most of the
 * column while the grid still leaves room for the avatar
 * on the start edge. Short questions still shrink to
 * content; the cap only matters for longer questions.
 *
 * The selector scopes to .chat-start so the assistant
 * side (chat-end) gets its own override below. The fix
 * is in CSS only (no template change) so the assistant
 * chat_bubble from templates/chat_message.html picks
 * it up via cascade order — chat.css loads after
 * daisyui.min.css, so this rule wins at equal specificity.
 */
.chat-start .chat-bubble {
  max-width: 90%;
}

/*
 * Chat-turn wrapper: templates/chat_message.html wraps
 * each turn (operator + assistant) in a `<div class="prose
 * chat-turn">`. The `prose` class is there so the
 * @tailwindcss/typography plugin's list / heading /
 * code-block styles apply to the assistant reply inside.
 * But `prose` also sets `max-width: 65ch` on the wrapper
 * itself, which is the real reason the chat bubbles look
 * narrow on a wide viewport: the chat-turn is capped at
 * ~510px, so the daisyUI chat grid inside it is laid out
 * inside a 510px column regardless of the card width.
 * Both bubbles (operator + assistant) inherit that
 * narrow column. The override resets the wrapper to
 * its natural width so the chat grid can use the full
 * card width.
 *
 * The assistant reply's own prose class
 * (`.chat-msg.prose.prose-sm` on the `<div>` inside the
 * bubble) is still capped below — the typography plugin's
 * 65ch default is fine for the actual prose text inside
 * the bubble, where it acts as a readability guardrail
 * for long-form LLM output rather than a layout
 * constraint.
 */
.prose.chat-turn {
  max-width: none;
}

/*
 * Assistant reply max-width: the @tailwindcss/typography
 * plugin sets `.prose` body text to `max-width: 65ch`
 * (about 511px at prose-sm's 14px font-size). On a
 * full-width chat-log card on a 1920px viewport that
 * caps the assistant reply at ~28% of the card — the
 * message appears as a narrow column in the middle of
 * a wide card, which the user reported as "not using
 * the horizontal space available." The cap is widened
 * to 90ch (~720px at the chat font size) on screens
 * wide enough to benefit, with the original 65ch
 * preserved on narrow viewports where the wider cap
 * wouldn't make a visual difference. 90ch is still
 * within the readability band the typography plugin
 * targets (the plugin's "normal" prose width is 65ch
 * but `prose-lg` ships at 80ch and `prose-xl` at 95ch
 * — 90ch sits in the prose-lg / prose-xl middle ground
 * and keeps long lines from running off the right
 * edge on ultrawide displays).
 */
.chat-msg.prose {
  color: inherit;
  max-width: 65ch;
}
@media (min-width: 48rem) {
  .chat-msg.prose {
    max-width: 90ch;
  }
}

pre.chat-msg {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  overflow-x: hidden;
  /*
   * Phase-7 follow-on: reset the prose plugin's default
   * pre margins inside chat-msg. The chat-turn wrapper
   * carries `prose` for the assistant reply's typography,
   * so the prose plugin's selector
   *   .prose :where(pre) has margin-top 1.71429em
   *   and margin-bottom 1.71429em. ... [closing brace
   *   in the example omitted so the regex in
   *   TestShippedCSS_OperatorPreResetsProseMargin
   *   doesn't see a stray closing brace character.
   * applies to every descendant <pre> — including the
   * operator-side <pre class="chat-msg">. At prose-sm's
   * 14px font-size that's ~24px on top AND ~24px on
   * bottom, so a 2-line operator message ends up in a
   * 130px-tall bubble with 50% empty vertical space.
   *
   * Resetting margin-block: 0 on the operator pre keeps
   * the chat-bubble's vertical size driven by the text
   * content + the chat-bubble's padding, not by inherited
   * prose typography spacing. The assistant reply's <pre>
   * blocks (code fences) still get the prose pre
   * margins because chat-msg.prose keeps the full prose
   * rule set (the selector targets only pre.chat-msg,
   * not pre.chat-msg.prose).
   */
  margin-block: 0;
}

.chat-msg a {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat-msg pre,
.chat-msg code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/*
 * Phase 7 of plans/ux-overhaul.md (prose typography follow-on).
 * The @tailwindcss/typography plugin sets `.prose` body text to
 * `--tw-prose-body` (a hardcoded gray in the plugin default).
 * Inside the chat-bubble that gray would override the bubble's
 * own themed color, leaving every assistant reply visually gray
 * instead of theme-aware. Scoping `color: inherit` to
 * `.chat-msg.prose` keeps the override surgical: only chat
 * bubbles lose it; search-result chunks and the landing
 * placeholder keep the plugin's intended body color.
 */
.chat-msg.prose {
  color: inherit;
}

/*
 * Phase 7 follow-on: dark-mode link readability.
 *
 * The @tailwindcss/typography plugin sets `.prose :where(a)`
 * to `color: var(--tw-prose-links)`, a hardcoded dark gray-
 * blue (oklch(21% .034 264.665)). That color is fine on a
 * light background, but inside the chat-bubble in dark mode
 * it lands as dark text on a dark bubble — invisible
 * (verified during the dark-mode UI pass: every markdown
 * link inside the assistant reply rendered as a dark navy
 * underline against the dark bubble background).
 *
 * The fix overrides the prose plugin's link color with
 * daisyUI's theme-aware primary token. The OS-driven
 * prefers-color-scheme flip re-themes --color-primary
 * alongside the rest of the daisyUI palette, so the link
 * stays a contrasting brand color in either mode.
 *
 * The selector scopes to `.chat-msg` (not `.prose` globally)
 * so other .prose surfaces — search-result chunks, the
 * landing placeholder — keep the plugin's intended link
 * color. The specificity (`.chat-msg a` beats `.prose
 * :where(a)` because :where() contributes zero specificity)
 * lets the override win without `!important`.
 */
.chat-msg a {
  color: var(--color-primary);
}

/*
 * Phase 7 follow-on: operator pre resets its prose background.
 *
 * The chat-turn wrapper carries `prose` so the assistant
 * reply inherits the typography plugin's list / heading /
 * code-block styling. The operator's <pre class="chat-msg">
 * sits inside that same wrapper, which means the plugin's
 * `:where(pre)` rule applies `--tw-prose-pre-bg` (a
 * hardcoded dark navy oklch(27.8% .033 256.848)) to the
 * operator pre — leaving the operator bubble looking
 * two-toned (the bubble's chat-bubble-primary on the
 * outside, the prose-pre-bg on the inside).
 *
 * The selector scopes to `.chat-msg:not(.prose)` so only
 * the operator pre (which has `chat-msg` but NOT `prose`)
 * gets the reset. The assistant reply div carries
 * `chat-msg prose prose-sm` and intentionally keeps the
 * plugin's pre styling for fenced ```code blocks``` rendered
 * inside.
 */
.chat-msg:not(.prose) {
  background-color: transparent;
}

/* htmx loading indicator: hidden by default, visible while a
 * request tagged with hx-indicator is in flight. The
 * .htmx-request class is added/removed by htmx automatically.
 *
 * Phase 2.3 of plans/ux-overhaul.md: the in-flight
 * affordance is daisyUI's visual-only loading component
 * (rendered in fallback_renderers.go's chat form). The
 * component ships its own animation in the embedded
 * daisyui.min.css, so chat.css no longer defines a
 * custom keyframe rule — the daisyUI component is the
 * single source of truth for the visual. The visibility
 * cascade below is unchanged: hidden by default,
 * revealed when htmx adds .htmx-request. */
.htmx-indicator {
  display: none;
}

.htmx-request.htmx-indicator {
  display: inline-flex;
  align-items: center;
}

/* Jump-to-latest button (issue #88): pinned to the
 * bottom-right corner of the chat-log container so it stays
 * visible as the log scrolls. Hidden by default — chat.js
 * toggles the .is-visible class on when the user has
 * scrolled away from the bottom of the log. The container
 * uses `position: relative` (set on .chat-log above) so
 * `position: absolute` here pins the button to the
 * container's bottom-right, not the viewport. */
.jump-to-latest {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  display: none;
}

.jump-to-latest.is-visible {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* Chat turn divider (issue #89 follow-on): a 1px subtle
 * horizontal rule between conversation turns. The visual
 * weight is intentionally light — the message boxes are
 * the primary reading units; the divider just gives the
 * eye an anchor when scanning a long session. margin-block
 * keeps the rhythm consistent with the surrounding card
 * spacing.
 *
 * Phase 2b of the Bulma -> DaisyUI migration: the border
 * color moved from `var(--bulma-border-weak)` (Bulma's
 * "weak" grey, ~86% in light mode, ~21% in dark mode) to
 * daisyUI's equivalent, `var(--color-base-300)` — the
 * "subtle border" token that daisyUI's theme system
 * re-themes automatically when `prefers-color-scheme: dark`
 * flips. The chat page is still loaded with bulma.min.css
 * in this transition phase (Phase 2f migrates it to
 * daisyui.min.css); the variable will resolve once the
 * daisyUI stylesheet is loaded alongside. The visual
 * difference between the two values is intentional and
 * the new daisyUI value is preferred per the migration's
 * "adopt daisyUI idioms" guidance. */
.chat-turn-divider {
  border: 0;
  border-top: 1px solid var(--color-base-300);
  margin-block: 1.25rem;
  margin-inline: 0;
}