/* ============================================================================
   chat.css — site chat chrome.
   ----------------------------------------------------------------------------
   Same family as the switch panel and the contact dialog: a raised night
   surface, hairline, mono labels. Tokens for colour are pinned to the night
   palette rather than --sc-surface / --sc-ink, because the service rooms
   reassign those to stone; the panel already hard-codes night for the same
   reason, so this piece of furniture does not change identity across pages.

   JS owns open/closed/blocked. This file decides what those states look like.
   The arrival veil is z-index 2147483646; the switch panel is --sc-z-chrome
   (60). The widget sits between them. On a phone the dock takes the bottom
   edge, so the FAB is parked above it. Once the sheet is open on a phone,
   the FAB goes — it sat in the keyboard — and the sheet drops onto the
   dock. Close lives in the header.

   The log is a scrollport: a turns stack, then a JS-sized spacer. The spacer
   is not a message — it is the headroom that lets the latest user bubble
   pin just under the header.
   ========================================================================== */

.chat {
  --chat-z: 80;
  --chat-surface: #1F1913;
  --chat-canvas: #14100C;
  --chat-ink: #F4ECDF;
  --chat-soft: #A79883;
  --chat-hair: color-mix(in oklab, var(--chat-ink) 14%, transparent);
  --chat-hair-strong: color-mix(in oklab, var(--chat-ink) 22%, transparent);
  --chat-accent: var(--accent-text, var(--sc-accent));
  --chat-dock: 0px;

  position: fixed;
  z-index: var(--chat-z);
  right: var(--sc-gutter);
  bottom: var(--sc-6);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--sc-3);
  max-width: calc(100vw - 2 * var(--sc-gutter));
  pointer-events: none;
}
.chat > * { pointer-events: auto; }

/* Hidden while the veil is down, and while a real modal owns the page.
   visibility, not display: the node stays in the tree so JS can close it
   without a layout jump when the blocker lifts. */
html.is-entering .chat,
html.is-leaving .chat,
html.is-contact-open .chat,
html.is-vault-open .chat {
  visibility: hidden;
  pointer-events: none;
}

.chat__launch {
  flex: none;
  width: 3rem; height: 3rem; padding: 0;
  border-radius: 50%;
  border: 0;
  background: var(--sc-accent);
  color: var(--sc-accent-ink);
  box-shadow: var(--sc-e1), inset 0 1px 0 rgba(255,255,255,.28);
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform var(--sc-d-fast) var(--sc-ease-out),
              background var(--sc-d-fast) var(--sc-ease-out);
}
.chat__launch:hover,
.chat__launch:focus-visible { background: #FFBE5A; }
.chat__launch:active { transform: scale(.97); }
.chat__launch:focus-visible {
  outline: 1px solid color-mix(in oklab, var(--sc-accent-ink) 55%, transparent);
  outline-offset: 3px;
}

/* Same energy as .cta: amber fill, dark ink glyph. The bubble is drawn in
   chat.js so this file is not carrying an SVG data URL. Open swaps it for
   a close mark without changing the button's colour. */
.chat__mark {
  position: relative;
  display: block; width: 1.35rem; height: 1.35rem;
}
.chat__mark svg {
  display: block; width: 100%; height: 100%;
  fill: currentColor;
}
.chat.is-open .chat__mark svg { visibility: hidden; }
.chat.is-open .chat__mark::before,
.chat.is-open .chat__mark::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 12px; height: 1.5px; border-radius: 1px;
  background: currentColor; translate: -50% -50%;
}
.chat.is-open .chat__mark::before { transform: rotate(45deg); }
.chat.is-open .chat__mark::after { transform: rotate(-45deg); }

.chat__panel {
  display: none;
  width: min(22.5rem, calc(100vw - 2 * var(--sc-gutter)));
  /* Hug-to-content made the open window feel like a note. Height fills
     the stack above the FAB; 42rem is the ceiling on a tall display. */
  flex: none;
  height: min(42rem, calc(100svh - 6rem - var(--chat-dock)));
  max-height: calc(100svh - 6rem - var(--chat-dock));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--chat-hair-strong);
  border-radius: var(--sc-r-lg);
  background: var(--chat-surface);
  color: var(--chat-ink);
  box-shadow: var(--sc-e2), 0 2.4rem 5rem -1rem rgba(0, 0, 0, .55);
  transform-origin: bottom right;
}
.chat.is-open .chat__panel {
  display: flex;
  animation: chat-in 260ms var(--sc-ease-out);
}
.chat__panel[hidden] { display: none; animation: none; }
@keyframes chat-in { from { opacity: 0; transform: translateY(8px) scale(.99); } }

.chat__head {
  display: flex; align-items: start; justify-content: space-between;
  gap: var(--sc-4);
  padding: var(--sc-5) var(--sc-5) var(--sc-4);
  border-bottom: 1px solid var(--chat-hair);
}
.chat__kicker {
  margin: 0;
  font-family: var(--sc-font-mono); font-size: var(--sc-t-xs);
  letter-spacing: .08em; text-transform: uppercase; color: var(--chat-soft);
}
.chat__title {
  margin: var(--sc-2) 0 0;
  font-family: var(--sc-font-display); font-weight: 600;
  font-size: var(--sc-t-lg); letter-spacing: -0.02em; line-height: var(--sc-leading-tight);
}
.chat__close {
  flex: none; cursor: pointer; background: none; color: var(--chat-soft);
  border: 1px solid var(--chat-hair-strong); border-radius: var(--sc-r-sm);
  padding: .45rem .85rem;
  font-family: var(--sc-font-mono); font-size: var(--sc-t-xs);
  letter-spacing: .08em; text-transform: uppercase;
  transition: color var(--sc-d-base) var(--sc-ease-out),
              border-color var(--sc-d-base) var(--sc-ease-out);
}
.chat__close:hover, .chat__close:focus-visible {
  color: var(--chat-ink); border-color: var(--chat-soft);
}
.chat__close:focus-visible {
  outline: 1px solid color-mix(in oklab, var(--chat-accent) 60%, transparent);
  outline-offset: 2px;
}

.chat__log {
  flex: 1 1 auto;
  min-width: 0; min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: var(--sc-5);
  display: flex; flex-direction: column;
  background: color-mix(in oklab, var(--chat-canvas) 55%, var(--chat-surface));
}
.chat__log-turns {
  flex: none;
  display: flex; flex-direction: column; gap: var(--sc-4);
  min-width: 0; width: 100%;
}
.chat__log-spacer {
  flex: none;
  width: 100%;
  height: 0;
  pointer-events: none;
}
.chat__msg {
  margin: 0;
  box-sizing: border-box;
  /* Flex items default to min-width:auto, so a long line would stretch the
     log sideways instead of wrapping. Zero the floor, cap the width, and
     keep Shift+Enter as real breaks. */
  min-width: 0;
  max-width: 92%;
  width: fit-content;
  padding: .7rem .85rem;
  border-radius: var(--sc-r-md);
  font-size: var(--sc-t-sm); line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-wrap: break-word;
}
.chat__msg--bot {
  align-self: start;
  background: color-mix(in oklab, var(--chat-ink) 6%, transparent);
  border: 1px solid var(--chat-hair);
}
.chat__msg--user {
  align-self: end;
  background: color-mix(in oklab, var(--chat-accent) 16%, transparent);
  border: 1px solid color-mix(in oklab, var(--chat-accent) 28%, transparent);
}

.chat__compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 4.5rem;
  align-items: center;
  padding: var(--sc-4) 0 var(--sc-4) var(--sc-5);
  border-top: 1px solid var(--chat-hair);
}
.chat__input {
  flex: 1 1 auto; min-width: 0;
  box-sizing: border-box;
  display: block;
  resize: none;
  overflow-y: hidden;
  line-height: 1.45;
  min-height: calc(1.45em + 1.4rem);
  /* Right pad is for Bitwarden / LastPass / 1Password icons, which sit on
     the field even when ignored — typed text must clear them. */
  padding: .7rem 2.85rem .7rem .9rem;
  border: 1px solid var(--chat-hair-strong); border-radius: var(--sc-r-sm);
  background: color-mix(in oklab, var(--chat-canvas) 60%, transparent);
  color: var(--chat-ink); font: inherit; font-size: var(--sc-t-sm);
  outline: none;
}
.chat__input::placeholder { color: var(--chat-soft); }
.chat__input:focus-visible {
  outline: 1px solid color-mix(in oklab, var(--chat-accent) 60%, transparent);
  outline-offset: 2px;
}
.chat__send {
  justify-self: center; align-self: center;
  cursor: pointer; border: 0;
  width: 2.5rem; height: 2.5rem; padding: 0;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--sc-accent); color: var(--sc-accent-ink);
  box-shadow: var(--sc-e1), inset 0 1px 0 rgba(255,255,255,.32);
  transition: background var(--sc-d-fast) var(--sc-ease-out),
              transform var(--sc-d-fast) var(--sc-ease-out);
}
.chat__send svg {
  display: block; width: 1.4rem; height: 1.4rem;
  overflow: visible;
}
.chat__send:hover { background: #FFBE5A; }
.chat__send:active { transform: scale(.97); }
.chat__send:disabled { opacity: .6; cursor: wait; }
.chat__send:focus-visible {
  outline: 1px solid color-mix(in oklab, var(--chat-accent) 60%, transparent);
  outline-offset: 2px;
}
.chat__msg--pending { color: var(--chat-soft); }

.chat__note {
  margin: 0;
  padding: 0 var(--sc-5) var(--sc-4);
  font-size: var(--sc-t-sm); color: var(--chat-accent);
}
.chat__note[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .chat.is-open .chat__panel { animation: none; }
  .chat__launch, .chat__send { transition: none; }
  .chat__send:active, .chat__launch:active { transform: none; }
}

@media (max-width: 860px) {
  .chat {
    --chat-dock: calc(5.5rem + env(safe-area-inset-bottom));
    right: var(--sc-gutter);
    bottom: var(--chat-dock);
  }
  .chat__panel {
    height: calc(100svh - var(--chat-dock) - 5.25rem);
    max-height: calc(100svh - var(--chat-dock) - 5.25rem);
  }
  /* The FAB is the close-X. On a phone it sits where the keyboard comes up,
     so hide it while the sheet is open and let the sheet occupy that stack.
     Close is the header control — scroll up to it. 5.5rem is FAB parking
     above the dock; the open sheet can sit on the dock itself. */
  .chat.is-open {
    bottom: calc(3.9rem + env(safe-area-inset-bottom));
  }
  .chat.is-open .chat__launch {
    display: none;
  }
}
