/* ==========================================================================
   chat.css — the "Ask the standard" showcase, and the surface sub-plan D builds on.

   DESIGN §7.9 calls this band the centrepiece: two windows side by side, always,
   because the contrast between a grounded answer and a confident refusal *is* the
   product's argument. Styling consequences that are not decoration:

     * the refusal bubble is warm (--brand-warmDark), never error red — a boundary
       drawn confidently, not a malfunction;
     * both states share every other treatment, so neither reads as the "broken" one;
     * a citation chip is monospace and tappable-looking, because a citation that
       cannot be followed is a decoration.

   Split from site.css by the §II 30 KB file cap; loaded by base.html on every page
   so D can render inside any of them.
   ========================================================================== */

.chat-showcase {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  align-items: stretch;
}

.chat-case {
  display: flex;
  flex-direction: column;
}

.case-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  color: var(--brand-ochreLight);
  font-size: var(--text-micro);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.case-label__tag {
  font-family: ui-monospace, "SFMono-Regular", "Cascadia Mono", monospace;
  font-size: var(--text-nano);
  font-weight: 400;
  letter-spacing: 0;
  opacity: 0.8;
}

.chat {
  display: flex;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 0.1);
  border-radius: var(--radius-md);
  background-color: var(--brand-forestDark);
  box-shadow: var(--shadow-window);
}

.chat__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgb(255 255 255 / 0.05);
  background-color: var(--brand-forestDeep);
}

.chat__title {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: rgb(var(--brand-cream-rgb) / 0.9);
  font-size: var(--text-xs);
  font-weight: 500;
}

.chat__dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: var(--radius-pill);
  background-color: var(--brand-ochre);
}

.state-badge {
  padding: 0.125rem 0.5rem;
  border: 1px solid rgb(var(--brand-ochre-rgb) / 0.35);
  border-radius: var(--radius-xs);
  background-color: var(--brand-forestDeep);
  color: var(--brand-ochreLight);
  font-size: var(--text-nano);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.chat__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.5rem;
}

.chat__row {
  display: flex;
  justify-content: flex-start;
}

.chat__row--user {
  justify-content: flex-end;
}

.chat__bubble {
  max-width: 90%;
  padding: 1rem;
  border: 1px solid rgb(255 255 255 / 0.1);
  border-radius: var(--radius-lg);
  border-top-left-radius: 0;
  font-size: var(--text-xs);
  line-height: var(--leading-body);
}

.chat__bubble p {
  margin: 0;
}

.chat__bubble p + p {
  margin-top: 0.75rem;
}

.chat__bubble--user {
  max-width: 85%;
  padding: 0.625rem 1rem;
  border-top-right-radius: 0;
  border-top-left-radius: var(--radius-lg);
  background-color: rgb(var(--brand-moss-rgb) / 0.8);
  color: #fff;
}

/* The answered state sits a shade lighter than the terminal, so it reads as a reply
   rather than as chrome. */
.chat__bubble--answer {
  background-color: rgb(var(--brand-forest-rgb) / 0.75);
  color: rgb(var(--brand-cream-rgb) / 0.9);
}

/* Warm, never red (DESIGN §7.9). `--brand-warmDark` is the prototype's off-palette
   #2B2319, promoted into the palette for exactly this use. */
.chat__bubble--refusal {
  background-color: rgb(43 35 25 / 0.9);
  border-color: rgb(var(--brand-ochreDark-rgb) / 0.4);
  color: rgb(var(--brand-ochreLight-rgb) / 0.92);
}

.chat__bubble strong {
  color: #fff;
  font-weight: 600;
}

.chat__bubble--refusal strong {
  color: var(--brand-ochreLight);
}

.cite-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-top: 0.75rem;
}

.cite {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border: 1px solid rgb(var(--brand-ochre-rgb) / 0.25);
  border-radius: var(--radius-xs);
  background-color: var(--brand-forestDeep);
  color: var(--brand-ochreLight);
  font-family: ui-monospace, "SFMono-Regular", "Cascadia Mono", monospace;
  font-size: var(--text-nano);
}

.chat__followup {
  padding-top: 0.25rem;
}

.chat__link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--brand-ochreLight);
  font-size: var(--text-micro);
  font-weight: 600;
  text-decoration: underline;
}

.chat__link:hover {
  color: #fff;
}

@media (min-width: 1024px) {
  .chat-showcase {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ==========================================================================
   The real surface at /ask/ (sub-plan D).

   The showcase above illustrates two states; this is the working window. It keeps
   the same ground, bubble and citation vocabulary so a visitor who saw the home
   page recognises the product, and adds only what a live exchange needs: a scrolling
   thread, a form, and a citation a reader can open.

   Mobile-first: the base rules are the phone, and the two-column desktop layout is
   the enhancement. The thread scrolls independently so the last answer is reachable
   when the keyboard is open; the form stays in normal flow below it.
   ========================================================================== */

.chat-page {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2.5rem;
  align-items: start;
}

.chat--page {
  min-height: 32rem;
}

.chat__body--thread {
  max-height: 26rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-margin-bottom: 30vh;
}

.chat__empty {
  margin: 0;
  color: rgb(var(--brand-cream-rgb) / 0.72);
  font-size: var(--text-xs);
  line-height: var(--leading-body);
}

/* A live answer is longer than a showcase bubble. The base `.chat__bubble` caps at
   90%; a citation block needs the room and must not become a horizontal scroller. */
.chat__bubble--answer,
.chat__bubble--refusal {
  overflow-wrap: anywhere;
}

.chat-form {
  display: grid;
  gap: 0.75rem;
  padding: 1rem 1.5rem 1.5rem;
  border-top: 1px solid rgb(255 255 255 / 0.08);
  background-color: var(--brand-forestDeep);
}

.chat-form__input {
  width: 100%;
  min-height: 5rem;
  padding: 0.875rem 1rem;
  border: 1px solid rgb(var(--brand-cream-rgb) / 0.18);
  border-radius: var(--radius-sm);
  background-color: var(--brand-forestDark);
  color: var(--brand-cream);
  font-family: inherit;
  font-size: var(--text-base);
  line-height: var(--leading-body);
  resize: vertical;
  scroll-margin-bottom: 30vh;
}

.chat-form__input::placeholder {
  color: rgb(var(--brand-cream-rgb) / 0.45);
}

.chat-form__input:focus-visible {
  outline: 2px solid var(--brand-ochre);
  outline-offset: 2px;
}

.chat__send {
  justify-self: start;
  min-height: 44px;
}

/* Enter sends, Shift+Enter inserts a newline; say so, because a textarea's default
   is the opposite and a visitor cannot discover the shortcut by looking at it. */
.chat-form__hint {
  margin: 0;
  color: rgb(var(--brand-cream-rgb) / 0.55);
  font-size: var(--text-xs);
}

/* HTMX's request indicator: dim the button, never hide it. A control that vanishes
   mid-request reads as a broken page on a slow connection. */
.htmx-request.chat__send,
.chat__send.htmx-request {
  opacity: 0.6;
}

/* --- Citations a reader can open ----------------------------------------- */

.cite-detail {
  display: block;
  flex-basis: 100%;
}

/* The summary is the control, so it clears the 44px target rule. The chip keeps the
   monospace look of the showcase's `.cite`. */
.cite--reference {
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  list-style: none;
}

.cite--reference::-webkit-details-marker {
  display: none;
}

.cite--reference::after {
  content: " +";
  font-weight: 700;
}

.cite-detail[open] .cite--reference::after {
  content: " −";
}

.cite-quote {
  margin: 0.5rem 0 0;
  padding: 0.75rem 1rem;
  border-left: 2px solid var(--brand-ochre);
  background-color: rgb(var(--brand-forest-rgb) / 0.55);
  color: rgb(var(--brand-cream-rgb) / 0.92);
  font-size: var(--text-xs);
  line-height: var(--leading-body);
}

.cite-source {
  margin: 0.5rem 0 0;
  color: var(--brand-ochreLight);
  font-size: var(--text-nano);
}

/* --- The explanation beside the window ----------------------------------- */

.chat-aside {
  padding: 1.25rem 1.5rem;
  border: 1px solid rgb(255 255 255 / 0.1);
  border-radius: var(--radius-md);
  background-color: rgb(var(--brand-forest-rgb) / 0.45);
  color: rgb(var(--brand-cream-rgb) / 0.86);
}

.chat-aside__title {
  margin: 0 0 0.75rem;
  color: var(--brand-cream);
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 400;
}

.chat-aside__list {
  display: grid;
  gap: 0.875rem;
  margin: 0;
  padding-left: 1.1rem;
  font-size: var(--text-xs);
  line-height: var(--leading-body);
}

.chat-aside__list strong {
  color: var(--brand-cream);
  font-weight: 600;
}

.chat-aside__note {
  margin: 1.25rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid rgb(255 255 255 / 0.1);
  color: rgb(var(--brand-cream-rgb) / 0.68);
  font-size: var(--text-micro);
  line-height: var(--leading-body);
}

@media (min-width: 1024px) {
  .chat-page {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  }

  .chat__body--thread {
    max-height: 34rem;
  }
}

/* The home band's link into the real surface. The generic `.link-more` is tuned for
   a cream ground; on the one dark band it needs the light accent. */
.section__more--dark .link-more--dark {
  color: var(--brand-ochreLight);
}

.section__more--dark .link-more--dark:hover {
  color: #fff;
}

/* `scrollIntoView` after a swap must clear the sticky header, or the first line of
   the answer lands underneath it. */
.chat__body--thread {
  scroll-margin-top: 5.5rem;
}
