@charset "utf-8";

/* ==========================================================================
   Merlin — support chat widget

   A separate stylesheet on purpose: site.css is a few hundred bytes under the
   64 KB ceiling `npm run check` enforces, and this is a whole component.

   Every value here is one of the site's own tokens, so the widget follows the
   palette by both routes — the system preference and the header switch — with
   no dark block of its own to drift out of step. Nothing hard-codes a colour.

   The launcher and the panel are inert without scripting, so they follow the
   same rule as the theme switch and the documentation search: hidden until
   [data-js] confirms the script is live.
   ========================================================================== */

.chat__launcher,
.chat__panel {
  display: none;
}

[data-js] .chat__launcher {
  display: inline-flex;
}

[data-js] .chat[data-open='true'] .chat__panel {
  display: flex;
}

/* --- Launcher -------------------------------------------------------------
   A labelled pill, not a bare bubble: this is the only floating control on
   the site, and an unlabelled circle is the one thing on a page whose purpose
   a visitor has to guess. It steps aside while the panel is open — the panel
   carries its own close button, and Escape closes it too — so the label never
   says "Ask a question" over an open conversation.                         */

.chat__launcher {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 60; /* over the sticky header, which sits at 50 */
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.05rem 0.6rem 0.85rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--purple-line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: background 0.16s var(--ease), border-color 0.16s var(--ease);
}

.chat__launcher:hover {
  background: var(--bg-alt);
  border-color: var(--purple);
}

.chat__launcher svg {
  width: 19px;
  height: 19px;
  color: var(--link);
}

.chat[data-open='true'] .chat__launcher {
  display: none;
}

/* --- Panel ---------------------------------------------------------------- */

.chat__panel {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 60;
  flex-direction: column;
  width: min(23.75rem, calc(100vw - 2.5rem));
  /* Clears the sticky header rather than sitting over it. */
  height: min(37.5rem, calc(100vh - 8.5rem));
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

.chat__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--line);
}

.chat__title {
  margin: 0;
  font-size: 0.97rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.chat__sub {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--ink-muted);
}

.chat__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-body);
  cursor: pointer;
  transition: border-color 0.16s var(--ease), color 0.16s var(--ease);
}

.chat__close:hover {
  border-color: var(--purple-line);
  color: var(--ink);
}

.chat__close svg {
  width: 11px;
  height: 11px;
}

/* --- Views ---------------------------------------------------------------
   One panel, two faces. `data-phase` is written by the script, so a phase it
   has never set can never leave both showing.                              */

.chat__gate,
.chat__thread {
  display: none;
  min-height: 0;
}

.chat__panel[data-phase='gate'] .chat__gate {
  display: block;
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem;
}

.chat__panel:not([data-phase='gate']) .chat__thread {
  display: flex;
  flex: 1;
  flex-direction: column;
}

/* --- Gate ----------------------------------------------------------------- */

.chat__intro {
  margin: 0 0 0.9rem;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--ink-body);
}

/* No frame: the widget draws its own, and a second one around it clipped its
   top edge. line-height: 0 removes the descender gap under Turnstile's inline
   iframe, which left the widget sitting at the top of a box 7px taller than
   it. Collapses to nothing in invisible mode, where Turnstile renders no UI. */
.chat__turnstile:not(:empty) {
  margin-bottom: 0.9rem;
  line-height: 0;
}

.chat__error {
  margin: 0 0 0.8rem;
  font-size: 0.85rem;
  line-height: 1.5;
  font-weight: 600;
  color: var(--ink);
}

.chat__error:empty {
  display: none;
}

.chat__start {
  width: 100%;
}

.chat__start:disabled {
  opacity: 0.55;
  cursor: default;
}

.chat__fine {
  margin: 0.9rem 0 0;
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--ink-muted);
}

/* --- Conversation --------------------------------------------------------- */

.chat__log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.85rem;
  min-height: 0;
  overflow-y: auto;
  padding: 1.1rem;
  font-size: 0.9rem;
  line-height: 1.6;
}

.chat__empty {
  margin: 0;
  font-size: 0.88rem;
  color: var(--ink-muted);
}

.chat__msg--me {
  align-self: flex-end;
  max-width: 85%;
  padding: 0.45rem 0.75rem;
  background: var(--purple-tint);
  border: 1px solid var(--purple-line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat__msg--bot {
  color: var(--ink-body);
  overflow-wrap: anywhere;
}

.chat__msg--bot p {
  margin: 0 0 0.7em;
}

.chat__msg--bot > :last-child {
  margin-bottom: 0;
}

.chat__msg--bot ul {
  margin: 0 0 0.7em;
  padding-left: 1.15rem;
}

.chat__msg--bot li {
  margin-bottom: 0.25em;
}

/* Three dots while the first token is still on its way. */
.chat__typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.chat__typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-muted);
  animation: chat-pulse 1.1s var(--ease) infinite;
}

.chat__typing i:nth-child(2) {
  animation-delay: 0.15s;
}

.chat__typing i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chat-pulse {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat__typing i {
    animation: none;
    opacity: 0.6;
  }
}

/* --- Composer ------------------------------------------------------------- */

.chat__notice {
  margin: 0;
  padding: 0.6rem 1.1rem;
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--ink-body);
}

.chat__notice:empty {
  display: none;
}

.chat__composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.8rem 1.1rem 0;
  border-top: 1px solid var(--line);
}

/* Out of questions: the composer would only offer a refusal, so it goes and
   the escalation in .chat__meta is all that is left. */
.chat__panel[data-phase='limited'] .chat__composer {
  display: none;
}

.chat__input {
  width: 100%;
  max-height: 7rem;
  padding: 0.55rem 0.8rem;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  resize: none;
  -webkit-appearance: none;
  appearance: none;
}

.chat__input::placeholder {
  color: var(--ink-muted);
}

.chat__input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-color: var(--purple);
}

.chat__input:disabled {
  opacity: 0.6;
}

.chat__send {
  flex: none;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-pill);
}

.chat__send svg {
  width: 16px;
  height: 16px;
}

.chat__send:disabled {
  opacity: 0.45;
  cursor: default;
}

.chat__meta {
  margin: 0;
  padding: 0.7rem 1.1rem 0.9rem;
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--ink-muted);
}

/* With the composer gone the escalation is the whole footer, so it takes the
   rule the composer was carrying. */
.chat__panel[data-phase='limited'] .chat__meta {
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}

/* --- Small screens --------------------------------------------------------
   A sheet rather than a floating card: at this width the card would be the
   whole screen anyway, minus a margin that only costs reading room.       */

@media (max-width: 559px) {
  .chat__panel {
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
  }

  /* Clear of the home indicator on a phone that has one. */
  .chat__meta {
    padding-bottom: calc(0.9rem + env(safe-area-inset-bottom, 0px));
  }
}
