/* chat.css — Ellie, the White Sand concierge. Scoped under .wss-chat so the whole file is inert
 * until src/js/chat.js mounts into [data-chat-root]. Two layouts share one
 * message DOM (see chat.js): a mobile bottom "peek" sheet (< 1024px) and a
 * desktop docked right sidebar (>= 1024px). Consumes tokens.css.
 *
 * State is driven by a single .is-open class on the .wss-chat root, toggled
 * synchronously in JS (no requestAnimationFrame dependency) so it works in the
 * vendored headless Chrome the e2e suite uses. Transitions animate in real
 * browsers and collapse to instant under prefers-reduced-motion (tokens.css).
 */

:root {
  --wss-chat-w: 384px;
}

.wss-chat {
  display: contents;
}

/* ── Avatar (script "L" on a gold gradient), shared by fab + head ───────────── */
.wss-chat__fab-av,
.wss-chat__av {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--gold-light), var(--gold));
  color: #fff;
  font-family: var(--script);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
}

/* ── Mobile launcher pill ────────────────────────────────────────────────────*/
.wss-chat__fab {
  position: fixed;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 45;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px 8px 8px;
  background: rgba(255, 255, 255, 0.94);
  -webkit-backdrop-filter: saturate(150%) blur(16px);
  backdrop-filter: saturate(150%) blur(16px);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  /* 16px gutter each side. On a 320px-class phone the uppercase, letter-spaced
   * label would otherwise push the pill under the opposite edge. */
  max-width: calc(100vw - 32px);
  transition: transform var(--dur-slow) var(--ease), opacity var(--dur) var(--ease);
}
.wss-chat__fab-av {
  width: 40px;
  height: 40px;
  font-size: 1.5rem;
}
.wss-chat__fab-tx {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-100);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
}
.wss-chat.is-open .wss-chat__fab {
  opacity: 0;
  pointer-events: none;
  transform: translateY(40%);
}

/* ── Desktop edge tab (hidden on mobile) ─────────────────────────────────────*/
.wss-chat__tab {
  display: none;
}

/* ── Scrim (mobile only) ─────────────────────────────────────────────────────*/
.wss-chat__scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 15, 15, 0.34);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}
.wss-chat.is-open .wss-chat__scrim {
  opacity: 1;
  pointer-events: auto;
}

/* ── Panel — mobile bottom peek sheet ────────────────────────────────────────*/
/* THE OWNER'S BUG (iPhone): "the bot is too wide for the phone so I have to
 * toggle the square box back-and-forth left and right."
 *
 * The panel itself was never too wide — it is left:0/right:0, i.e. exactly the
 * viewport. What panned was the MESSAGE LIST inside it. Per CSS overflow, when
 * one axis is not `visible` the other computes to `auto`, so .wss-chat__body's
 * `overflow-y: auto` silently made it horizontally scrollable too — and the
 * assistant's replies contain long unbreakable URLs (the Phorest booking link,
 * the Salon Interactive store link) which blow straight past the 82% bubble
 * width with no break opportunity in them. Result: a sideways-scrolling list
 * that reads exactly like a widget that is too wide for the screen.
 *
 * The fix is three-part and all of it is here: the panel is explicitly clamped
 * to the viewport (belt for any engine that resolves left/right oddly), the
 * body's horizontal axis is pinned shut, and long tokens are given permission
 * to break. Asserted at 390x844 and 375x667 in test/chat.e2e.js. */
.wss-chat__panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 61;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  height: min(46svh, 420px);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 -20px 60px -18px rgba(9, 30, 35, 0.4);
  transform: translateY(100%);
  visibility: hidden;
  transition: transform var(--dur-slow) var(--ease), visibility 0s linear var(--dur-slow);
}
.wss-chat.is-open .wss-chat__panel {
  transform: translateY(0);
  visibility: visible;
  transition: transform var(--dur-slow) var(--ease), visibility 0s linear 0s;
}

/* ── Header (black, gold accents) ────────────────────────────────────────────*/
.wss-chat__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--ink);
  color: #fff;
  border-radius: 22px 22px 0 0;
}
.wss-chat__av {
  width: 42px;
  height: 42px;
  font-size: 1.6rem;
  flex: 0 0 auto;
}
.wss-chat__id {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-right: auto; /* pushes the close/collapse control to the far edge */
}
.wss-chat__name {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: var(--fw-medium);
  line-height: 1.05;
  color: #fff;
}
.wss-chat__status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 11px;
  letter-spacing: 0.08em;
  /* THE OWNER'S NOTE: "there's a black bubble and it has gold writing. If you
   * could make white writing on black bubble and then black writing on white
   * bubble." This line and the desktop edge tab were the gold-on-black. Gold on
   * --ink measured 11.5:1, so this is not an AA fix — it is her call, and at
   * 11px letter-spaced the near-white (17.8:1) is plainly easier to read. */
  color: #f7f7f5;
}
.wss-chat__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5fae7a;
  animation: wss-chat-pulse 2s infinite;
}
@keyframes wss-chat-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(95, 174, 122, 0.5);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(95, 174, 122, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(95, 174, 122, 0);
  }
}
.wss-chat__close,
.wss-chat__collapse {
  padding: 4px 8px;
  font-size: 22px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.85);
  background: none;
  border: 0;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease);
}
.wss-chat__close:hover,
.wss-chat__collapse:hover {
  color: #fff;
}
/* The collapse chevron is a desktop affordance; the × owns mobile. */
.wss-chat__collapse {
  display: none;
}

/* ── Message list ────────────────────────────────────────────────────────────
 * THE OWNER'S BIGGEST PAIN (desktop): with the sidebar open she could not scroll
 * Ellie's long answer — the wheel moved the PAGE behind the panel instead. She
 * fought it on camera for a minute.
 *
 * This element was already the right overflow container (flex:1 + min-height:0
 * inside the column-flex panel; measured scrollHeight 1070 vs clientHeight 714 at
 * 1440x900, so it genuinely had somewhere to go). Nothing here was the bug — see
 * chat.js's mount() for the actual cause (Lenis eats the wheel event before the
 * browser can scroll anything) and the data-lenis-prevent that fixes it.
 *
 * What IS load-bearing here is `overscroll-behavior: contain`: without it,
 * reaching the top or bottom of the transcript chains the remaining scroll to the
 * page, so the site lurches the moment she reads to the end of a reply. */
.wss-chat__body {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  /* Explicit, and load-bearing: `overflow-y: auto` alone computes overflow-x to
   * `auto` as well, which is what let the message list pan sideways. */
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--sand);
}
.wss-chat__msg {
  max-width: 82%;
  min-width: 0;
  padding: 12px 15px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.5;
  /* A pasted booking URL is one ~55-character word with no break opportunity.
   * `anywhere` (not `break-word`) is what makes it count toward min-content, so
   * the bubble actually shrinks to fit instead of overflowing its own max-width. */
  overflow-wrap: anywhere;
  word-break: break-word;
}
/* ── Bubble contrast (the owner's "white writing on black, black on white") ──
 * Ellie's bubble: BLACK type on a white bubble  — #0f0f0f on #ffffff, 18.9:1.
 * The guest's bubble: WHITE type on a black bubble — #ffffff on #0f0f0f, 18.9:1.
 * Gold survives only where she can read it: emphasis and links inside the white
 * bubble use --gold-deep (#7a5e29, 6.07:1), and a link that ever lands inside the
 * black bubble flips to --gold-light (#dcc389, 11.5:1) rather than going invisible. */
.wss-chat__msg--bot {
  align-self: flex-start;
  background: var(--paper);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  color: var(--ink);
}
.wss-chat__msg--me {
  align-self: flex-end;
  background: var(--ink);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.wss-chat__msg--bot strong {
  color: var(--gold-deep);
}
.wss-chat__link {
  color: var(--gold-deep);
  text-decoration: underline;
  overflow-wrap: anywhere;
}
.wss-chat__msg--me .wss-chat__link,
.wss-chat__msg--me strong {
  color: var(--gold-light);
}
.wss-chat__typing {
  display: inline-flex;
  gap: 4px;
}
.wss-chat__typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-soft);
  animation: wss-chat-blink 1.2s infinite both;
}
.wss-chat__typing i:nth-child(2) {
  animation-delay: 0.2s;
}
.wss-chat__typing i:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes wss-chat-blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* ── Composer ────────────────────────────────────────────────────────────────*/
.wss-chat__foot {
  display: flex;
  gap: 8px;
  min-width: 0;
  /* flex-shrink: 0 is the "does not steal composer space" guarantee — the fine
   * print below is what gives, and before it the message list is. */
  flex: 0 0 auto;
  padding: 12px 14px 10px;
  border-top: 1px solid var(--line);
  background: var(--card);
}

/* ── Blanket privacy / AI disclosure — permanently pinned under the composer ──
 * The always-visible layer of the liability stack: AI disclosure, don't-rely,
 * no-sensitive-information, and purpose-limited consent by continued use. It is
 * deliberately unobtrusive (10px, muted, tight leading) and deliberately NOT
 * dismissible — a disclosure the guest can close is not a disclosure. It sits
 * OUTSIDE .wss-chat__body so it cannot be scrolled away with the transcript.
 * The safe-area inset lives here rather than on the composer because this is now
 * the panel's last row on iOS. */
.wss-chat__fineprint {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 14px calc(9px + env(safe-area-inset-bottom));
  background: var(--card);
  color: var(--ink-soft);
  font-size: 9.5px;
  line-height: 1.3;
  letter-spacing: 0.005em;
  text-align: center;
  /* Still fine print, but 0.92 instead of 0.78 — with --ink-soft now #2e2e2e that
   * resolves to ~#434343 on --card, 9.7:1. Muted, not faint. */
  opacity: 0.92;
  overflow-wrap: anywhere;
}
/* THE OWNER'S OTHER iPhone BUG: "too wide on phone — have to slide left after
 * typing to reach send."
 *
 * Root cause is not width, it is iOS Safari's auto-zoom: focusing an input whose
 * computed font-size is under 16px makes Safari zoom the PAGE in to that field,
 * and it does not zoom back out on blur. The viewport is then wider than the
 * screen, so the composer's send button sits off to the right and you have to pan
 * to reach it — which is exactly what she described.
 *
 * 16px is the documented threshold and it is the whole fix. Deliberately NOT
 * done with maximum-scale/user-scalable=no on the viewport meta: that would stop
 * the zoom by banning pinch-zoom for everyone, which is a WCAG 1.4.4 failure.
 * 16px is the only focusable field in the widget; asserted in test/chat.e2e.js. */
.wss-chat__input {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: inherit;
  font-size: 16px;
  background: var(--paper);
  color: var(--ink);
}
.wss-chat__input:focus {
  outline: none;
  border-color: var(--gold);
}
.wss-chat__send {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 16px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}
.wss-chat__send:hover {
  background: var(--gold-deep);
}

/* ── Desktop: docked right sidebar (>= 1024px) ───────────────────────────────*/
@media (min-width: 1024px) {
  .wss-chat__fab,
  .wss-chat__scrim {
    display: none;
  }

  /* Edge tab launcher, hidden while the sidebar is open. */
  .wss-chat__tab {
    position: fixed;
    right: 0;
    top: 50%;
    z-index: 45;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 10px;
    transform: translateY(-50%);
    background: var(--ink);
    color: #fff;
    border: 0;
    border-radius: 12px 0 0 12px;
    box-shadow: var(--shadow-soft);
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease), padding-right var(--dur-fast) var(--ease);
  }
  .wss-chat__tab span {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-size: var(--fs-100);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    /* Same call as .wss-chat__status: white writing on the black tab. */
    color: #f7f7f5;
  }
  .wss-chat__tab:hover {
    padding-right: 14px;
  }
  .wss-chat.is-open .wss-chat__tab {
    display: none;
  }

  /* Panel becomes a full-height docked sidebar on the right edge. */
  .wss-chat__panel {
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: var(--wss-chat-w);
    height: 100%;
    border-radius: 0;
    border-top: 0;
    border-left: 1px solid var(--line);
    box-shadow: -22px 0 60px -34px rgba(9, 30, 35, 0.5);
    transform: translateX(100%);
    transition: transform var(--dur-slow) var(--ease), visibility 0s linear var(--dur-slow);
  }
  .wss-chat.is-open .wss-chat__panel {
    transform: translateX(0);
    transition: transform var(--dur-slow) var(--ease), visibility 0s linear 0s;
  }
  .wss-chat__head {
    border-radius: 0;
  }
  /* On desktop the chevron collapses the sidebar; the × is redundant. */
  .wss-chat__collapse {
    display: inline-flex;
  }
  .wss-chat__close {
    display: none;
  }

  /* Shift the whole page (header/main/footer are static/sticky flow) so the
   * open sidebar never overlaps content. The fixed panel/tab ignore the pad. */
  body.wss-chat-open {
    padding-right: var(--wss-chat-w);
    transition: padding-right var(--dur-slow) var(--ease);
  }
}

/* ── Reduced motion: no slide/pop; the panel simply appears ──────────────────*/
@media (prefers-reduced-motion: reduce) {
  .wss-chat__fab,
  .wss-chat__scrim,
  .wss-chat__panel,
  body.wss-chat-open {
    transition-duration: 0.001ms !important;
  }
  .wss-chat__dot,
  .wss-chat__typing i {
    animation: none !important;
  }
}
