/* chat.css — Lori 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;
  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 {
  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 ────────────────────────────────────────*/
.wss-chat__panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 61;
  height: min(42svh, 380px);
  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;
  color: var(--gold-light);
}
.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.72);
  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 ────────────────────────────────────────────────────────────*/
.wss-chat__body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--sand);
}
.wss-chat__msg {
  max-width: 82%;
  padding: 12px 15px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.5;
}
.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;
}
.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;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--card);
}
.wss-chat__input {
  flex: 1;
  min-width: 0;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: inherit;
  font-size: 14px;
  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;
    color: var(--gold-light);
  }
  .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;
  }
}
