/* ============================================================
   Chatbot — Floating widget + full-page styles
   Uses design tokens from tokens.css. Loaded from header.php.
   ============================================================ */

/* ============== FAB button ============== */
.chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9990;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--c-teal) 0%, var(--c-purple) 100%);
  box-shadow: var(--sh-3), 0 0 0 4px rgba(255, 255, 255, 0.06);
  color: #fff;
  display: grid;
  place-items: center;
  transition: transform var(--d-2) var(--ease-spring), box-shadow var(--d-2) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.chat-fab:hover { transform: scale(1.06); }
.chat-fab:focus-visible {
  outline: none;
  box-shadow: var(--sh-3), 0 0 0 4px rgba(255, 255, 255, 0.4), 0 0 0 6px var(--c-teal);
}
.chat-fab svg { width: 28px; height: 28px; }

.chat-fab.is-open {
  transform: scale(0.92);
  background: var(--c-ink);
}

/* First-appearance pulse: rings expand outward once per session. */
@keyframes chat-fab-pulse {
  0%   { box-shadow: var(--sh-3), 0 0 0 0   rgba(30, 183, 191, 0.55); }
  70%  { box-shadow: var(--sh-3), 0 0 0 24px rgba(30, 183, 191, 0); }
  100% { box-shadow: var(--sh-3), 0 0 0 0   rgba(30, 183, 191, 0); }
}
.chat-fab.has-pulse {
  animation: chat-fab-pulse 2s ease-out 3;
}

/* ============== Panel ============== */
.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 100px;
  z-index: 9991;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: min(70vh, 600px);
  max-height: calc(100vh - 140px);
  background: var(--c-bg);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: transform 280ms var(--ease-spring), opacity 220ms var(--ease-out);
}
.chat-panel.is-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* ============== Panel header ============== */
.chat-panel__header {
  flex: 0 0 auto;
  height: 72px;
  padding: 0 20px;
  background: linear-gradient(135deg, var(--c-teal) 0%, var(--c-purple) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
}
.chat-panel__title {
  font-family: var(--f-display);
  font-size: 1.15rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  flex: 1;
}
.chat-panel__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.25);
  flex: 0 0 auto;
}
.chat-panel__close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background var(--d-1) var(--ease-out), transform var(--d-2) var(--ease-spring);
}
.chat-panel__close:hover { background: rgba(255, 255, 255, 0.28); transform: rotate(90deg); }
.chat-panel__close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.chat-panel__close svg { width: 16px; height: 16px; }

/* ============== Messages area ============== */
.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  background: var(--c-bg);
}

.chat-msg {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.94rem;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: chat-msg-in 220ms var(--ease-out) both;
}
@keyframes chat-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-msg--user {
  align-self: flex-end;
  background: var(--c-purple);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg--assistant {
  align-self: flex-start;
  background: color-mix(in srgb, var(--c-teal) 12%, var(--c-bg));
  color: var(--c-ink);
  border: 1px solid color-mix(in srgb, var(--c-teal) 20%, transparent);
  border-bottom-left-radius: 4px;
}
.chat-msg--error {
  align-self: flex-start;
  background: rgba(220, 38, 38, 0.08);
  color: var(--c-error);
  border: 1px solid rgba(220, 38, 38, 0.2);
  border-radius: 14px;
  font-size: 0.88rem;
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  background: color-mix(in srgb, var(--c-teal) 12%, var(--c-bg));
  border: 1px solid color-mix(in srgb, var(--c-teal) 20%, transparent);
  padding: 12px 16px;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  display: inline-flex;
  gap: 5px;
  align-items: center;
}
.chat-typing__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c-teal);
  animation: chat-typing-bounce 1.2s var(--ease-in-out) infinite;
}
.chat-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing__dot:nth-child(3) { animation-delay: 0.30s; }
@keyframes chat-typing-bounce {
  0%, 60%, 100% { transform: translateY(0);   opacity: 0.4; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* Quick-reply chips (FAB + full-page hero) */
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 0;
  animation: chat-msg-in 280ms var(--ease-out) both;
}
.chat-chip {
  background: var(--c-bg);
  border: 1px solid var(--c-line-2);
  color: var(--c-ink);
  padding: 6px 12px;
  border-radius: var(--r-pill);
  font-size: 0.82rem;
  font-family: var(--f-body);
  cursor: pointer;
  transition: background var(--d-1) var(--ease-out), transform var(--d-1) var(--ease-out), border-color var(--d-1) var(--ease-out);
}
.chat-chip:hover {
  background: color-mix(in srgb, var(--c-teal) 12%, transparent);
  border-color: var(--c-teal);
  transform: translateY(-1px);
}
.chat-chip:focus-visible {
  outline: 2px solid var(--c-teal);
  outline-offset: 2px;
}

/* ============== Input bar ============== */
.chat-input-bar {
  flex: 0 0 auto;
  border-top: 1px solid var(--c-line);
  background: #fff;
  padding: 12px 14px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.chat-input-bar textarea {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  resize: none;
  border: 1px solid var(--c-line-2);
  border-radius: 14px;
  padding: 10px 14px;
  font-family: var(--f-body);
  font-size: 0.94rem;
  line-height: 1.4;
  background: var(--c-bg);
  color: var(--c-ink);
  outline: none;
  transition: border-color var(--d-1) var(--ease-out), background var(--d-1) var(--ease-out);
}
.chat-input-bar textarea:focus {
  border-color: var(--c-teal);
  background: #fff;
}
.chat-input-bar textarea:disabled { opacity: 0.5; }

.chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--c-teal);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background var(--d-1) var(--ease-out), transform var(--d-1) var(--ease-out);
}
.chat-send:hover { background: var(--c-teal-deep); transform: scale(1.05); }
.chat-send:disabled { background: var(--c-muted); cursor: not-allowed; transform: none; }
.chat-send:focus-visible { outline: 2px solid var(--c-teal); outline-offset: 2px; }
.chat-send svg { width: 18px; height: 18px; }

/* Disconnected footer */
.chat-disconnected {
  padding: 4px 16px 8px;
  font-size: 0.75rem;
  color: var(--c-muted);
  text-align: center;
  background: #fff;
}

/* ============== Full-page chat (/chat.php) ============== */
.chat-fullpage {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--header-h) - 220px);
  background: var(--c-bg);
}

.chat-hero {
  background: linear-gradient(135deg, var(--c-teal) 0%, var(--c-purple) 100%);
  color: #fff;
  padding: 56px 0 40px;
  text-align: center;
}
.chat-hero h1 {
  font-family: var(--f-display);
  font-size: clamp(2.2rem, 1.8rem + 1.6vw, 3.2rem);
  font-weight: 300;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}
.chat-hero p {
  font-size: 1.05rem;
  opacity: 0.92;
  max-width: 56ch;
  margin: 0 auto 24px;
}
.chat-hero__chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
}
.chat-hero__chips .chat-chip {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
  padding: 8px 16px;
  font-size: 0.88rem;
}
.chat-hero__chips .chat-chip:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.6);
  transform: translateY(-1px);
}
.chat-hero.is-hidden { display: none; }

.chat-stream {
  flex: 1 1 auto;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* Allow the messages list to grow with content; the page itself
     scrolls so the sticky hero stays visible at the top. */
}

.chat-input-bar--fullpage {
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: #fff;
  border-top: 1px solid var(--c-line);
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 14px 16px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.04);
}
.chat-input-bar--fullpage textarea { background: var(--c-bg); }

/* ============== Mobile ============== */
@media (max-width: 640px) {
  .chat-fab {
    right: 16px;
    bottom: 16px;
    width: 56px;
    height: 56px;
  }
  .chat-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 80vh;
    max-height: 100vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    transform: translateY(100%);
  }
  .chat-panel.is-open {
    transform: translateY(0);
  }
  .chat-input-bar { padding: 10px 12px; }
  .chat-msg { max-width: 86%; }
}

/* ============== Reduced motion ============== */
@media (prefers-reduced-motion: reduce) {
  .chat-fab,
  .chat-panel,
  .chat-msg,
  .chat-typing__dot,
  .chat-chip,
  .chat-send,
  .chat-panel__close { transition: none !important; animation: none !important; }
}
