/**
 * Intake chat widget styles (FLNT-098 fast-follow #1).
 *
 * Served from public/ and linked ONLY from inside the flag-gated block in
 * BaseLayout.astro. That is deliberate: Astro collects a page's CSS from the module
 * graph rather than from render output, so a static `import '@/styles/chat.css'` in
 * BaseLayout would inline these rules into all 98 pages even with CHATBOT.enabled
 * false — which would break the dark-ship guarantee. A plain <link> is the only way to
 * ship truly zero bytes while dark.
 *
 * Design tokens ONLY. Every colour below is a custom property declared in
 * src/styles/tokens.css. No invented colours, no hard-coded hex, no new type scale.
 * Conventions follow the .btn / .est-* patterns already in the repo.
 */

.flnt-chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 900;
  font-family: "Inter", system-ui, sans-serif;
}

/* ---------------------------------------------------------------- launcher */

.flnt-chat-launcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-radius: 4px;
  border: 1.5px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(0, 39, 37, 0.18);
  transition: background 150ms ease, border-color 150ms ease;
}

.flnt-chat-launcher:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

.flnt-chat-launcher:focus-visible {
  outline: 2px solid var(--accent-deep);
  outline-offset: 3px;
}

.flnt-chat-launcher-icon {
  font-size: 17px;
  line-height: 1;
}

/* ------------------------------------------------------------------- panel */

/*
 * ---------------------------------------------------------------------------
 * PANEL HEIGHT BUDGET — read before adding anything to this column.
 * ---------------------------------------------------------------------------
 * The panel is a fixed-height flex column, and the transcript is the ONLY child that
 * may absorb the leftover. Everything else declares `flex: 0 0 auto`.
 *
 * That is not tidiness. Every child used to sit at the default `flex: 0 1 auto`, so
 * their flex BASE was their content height and the deficit was distributed by weighted
 * shrink. The header, composer, notice and disclaimer all have visible overflow, so
 * their automatic minimum size clamped them at min-content and they refused to give
 * anything up; the transcript, with `overflow-y: auto`, was the only child that could
 * shrink to zero, so it absorbed the ENTIRE deficit. Measured at 1280x620: 141px of a
 * 580px panel, against a 144px assistant bubble. The transcript was smaller than one
 * message, which is what "I cannot see the text" meant.
 *
 * So: chrome is fixed, the log is `flex: 1 1 0` with `min-height: 0`, and any new
 * standing element in this column is height you are taking directly off the transcript.
 */
.flnt-chat-panel {
  display: flex;
  flex-direction: column;
  width: 380px;
  max-width: calc(100vw - 32px);
  /* vh first as the fallback; dvh wins where supported. Mobile browsers report 100vh as
     the URL-bar-hidden height, which pushed the header off the top of the screen. */
  max-height: min(720px, calc(100vh - 40px));
  max-height: min(720px, calc(100dvh - 40px));
  background: var(--surface);
  border: 2px solid var(--text);
  border-radius: 4px;
  box-shadow: 0 18px 48px rgba(0, 39, 37, 0.22);
  overflow: hidden;
}

.flnt-chat-head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px 11px;
  background: var(--accent-deep);
  color: var(--on-accent);
}

.flnt-chat-title {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-weight: 500;
  font-size: 18px;
  line-height: 1.15;
  color: var(--on-accent);
}

/*
 * 11px at 0.06em tracking, down from 12px at 0.12em. At the old size this 24-character
 * label did not fit the width left over beside "START OVER" and the close button, so it
 * wrapped to a second line and the header stood at 121px.
 */
.flnt-chat-sub {
  margin: 2px 0 0;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--teal-300);
}

.flnt-chat-head-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Escape hatch for a session the server can no longer verify. */
.flnt-chat-reset {
  flex: 0 0 auto;
  border: 1.5px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--teal-300);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
  padding: 5px 6px;
  cursor: pointer;
}

.flnt-chat-reset:hover {
  border-color: var(--teal-300);
}

.flnt-chat-reset:focus-visible {
  outline: 2px solid var(--teal-300);
  outline-offset: 2px;
}

.flnt-chat-close {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 1.5px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--on-accent);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.flnt-chat-close:hover {
  border-color: var(--teal-300);
}

.flnt-chat-close:focus-visible {
  outline: 2px solid var(--teal-300);
  outline-offset: 2px;
}

/* -------------------------------------------------------------- transcript */

/*
 * The one child that flexes, and the only one allowed to shrink.
 *
 * `flex-basis` MUST stay `auto` (i.e. content height). The panel has a max-height but no
 * definite height, so its height is content-driven: with `flex-basis: 0` here the column
 * has nothing to distribute, the panel collapses to the height of its chrome, and the
 * transcript renders at 28px. Measured, after trying exactly that. Content basis is what
 * makes the panel grow with the conversation up to the cap and then let this child, and
 * only this child, absorb the overflow.
 *
 * `min-height: 0` is belt and braces beside `overflow-y: auto` (which already zeroes the
 * automatic minimum size) and states the intent for anyone who changes the overflow.
 */
.flnt-chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.flnt-chat-msg {
  margin: 0;
  padding: 12px 14px;
  border-radius: 4px;
  font-size: 15px;
  line-height: 1.55;
  max-width: 92%;
}

.flnt-chat-msg p {
  margin: 0 0 8px;
}

.flnt-chat-msg p:last-child {
  margin-bottom: 0;
}

.flnt-chat-msg-bot {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text-2);
}

.flnt-chat-msg-user {
  align-self: flex-end;
  background: var(--teal-100);
  border: 1px solid var(--accent);
  color: var(--text);
}

/*
 * Escalation turns. The urgency is carried by the left rule AND the heavier border AND
 * the sr-only "Urgent message" prefix in the markup — never by colour alone, so this
 * still reads as different in greyscale and to a screen reader.
 */
.flnt-chat-msg-urgent {
  align-self: stretch;
  max-width: 100%;
  background: var(--surface);
  border: 2px solid var(--line-strong);
  border-left-width: 6px;
  color: var(--text);
}

.flnt-chat-msg-error {
  align-self: stretch;
  max-width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-left-width: 5px;
  color: var(--text);
}

/*
 * Team preview (PLAN-chatbot-preview-v1.md §4). Two surfaces, both the harness speaking:
 * a standing notice pinned above the disclaimer for the life of the panel, and a bubble
 * inserted at the moment the assistant closes as if intake were about to call.
 *
 * The bubble is deliberately NOT shaped like an assistant bubble: full width, dashed
 * border, uppercase-tracked, and preceded by an sr-only "Test build note:" prefix in the
 * markup, so it does not read as something the bot said in greyscale or to a screen
 * reader. Tokens only, same as the rest of this file.
 */
.flnt-chat-msg-notice {
  align-self: stretch;
  max-width: 100%;
  background: var(--surface-2);
  border: 2px dashed var(--line-strong);
  color: var(--text);
  font-family: "Inter", sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.flnt-chat-preview-notice {
  flex: 0 0 auto;
  margin: 0;
  padding: 10px 16px;
  background: var(--surface-2);
  border-top: 2px dashed var(--line-strong);
  font-family: "Inter", sans-serif;
  font-size: 12px;
  line-height: 1.5;
  font-weight: 600;
  color: var(--text);
}

.flnt-chat-call {
  display: inline-flex;
  align-items: center;
  margin-top: 10px;
  padding: 12px 18px;
  border-radius: 4px;
  background: var(--accent);
  border: 1.5px solid var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
}

.flnt-chat-call:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: var(--on-accent);
}

.flnt-chat-call:focus-visible {
  outline: 2px solid var(--accent-deep);
  outline-offset: 3px;
}

/* ------------------------------------------------------- options and quick */

.flnt-chat-actions,
.flnt-chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.flnt-chat-quick {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 16px 12px;
  background: var(--bg);
}

.flnt-chat-opt {
  padding: 9px 14px;
  border-radius: 4px;
  border: 1.5px solid var(--text);
  background: transparent;
  color: var(--text);
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.flnt-chat-opt:hover {
  background: var(--text);
  color: var(--bg);
}

.flnt-chat-opt:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* --------------------------------------------------------------- typing */

.flnt-chat-typing {
  margin: 0;
  align-self: flex-start;
}

.flnt-chat-dots {
  display: inline-flex;
  gap: 5px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
}

.flnt-chat-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--slate-400);
  animation: flnt-chat-bounce 1.2s infinite ease-in-out;
}

.flnt-chat-dots i:nth-child(2) { animation-delay: 0.15s; }
.flnt-chat-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes flnt-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* ---------------------------------------------------------------- composer */

.flnt-chat-form {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

/*
 * Textarea and Send share a row. Stacked they cost 143px; side by side the row is the
 * height of the textarea alone, and the ~50px saved goes to the transcript.
 * `align-items: flex-end` keeps the button's baseline on the textarea's bottom edge, so
 * dragging the textarea's resize handle does not stretch the button with it.
 */
.flnt-chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.flnt-chat-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-family: "Inter", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  resize: vertical;
}

.flnt-chat-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.flnt-chat-send {
  flex: 0 0 auto;
  padding: 11px 18px;
  border-radius: 4px;
  border: 1.5px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}

.flnt-chat-send:hover:not(:disabled) {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

.flnt-chat-send:disabled {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--text-3);
  cursor: not-allowed;
}

.flnt-chat-send:focus-visible {
  outline: 2px solid var(--accent-deep);
  outline-offset: 3px;
}

.flnt-chat-fine {
  margin: 0;
  padding: 0 16px 14px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-3);
  background: var(--surface);
}

/*
 * The standing disclaimer, and it is the panel's last child. Fixed, never shrunk: the
 * not-legal-advice and no-attorney-client-relationship sentences come from
 * DISCLAIMERS.aiAssistantDisclaimer and are required in full, so this block is a height
 * cost the transcript pays. That is the intended trade — height was reclaimed from the
 * header and the composer instead, and this copy is not abridged to make room.
 */
.flnt-chat-panel > .flnt-chat-fine {
  flex: 0 0 auto;
}

.flnt-chat-msg-error .flnt-chat-fine {
  padding: 8px 0 0;
  background: transparent;
}

/* ------------------------------------------------------------------ mobile */

@media (max-width: 640px) {
  .flnt-chat {
    right: 12px;
    bottom: 12px;
    left: 12px;
  }

  .flnt-chat-panel {
    width: 100%;
    /* No 720px cap on mobile: the panel is the whole surface there. dvh matters most on
       this branch, because 100vh is the URL-bar-hidden height on iOS Safari and the panel
       is bottom-anchored, so the overflow lands on the header at the top of the screen. */
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }

  .flnt-chat-launcher {
    width: 100%;
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flnt-chat-dots i { animation: none; }
}
