/* ============================================
   ON-SITE CHAT ASSISTANT
   Floating launcher + panel. Brand-matched:
   pop-orange launcher, charcoal header, bone log.
   ============================================ */

.chat {
  position: fixed;
  right: clamp(16px, 3vw, 28px);
  bottom: clamp(16px, 3vw, 28px);
  z-index: 90;
  font-family: var(--f-body);
}

/* ─── Launcher ─────────────────────────────── */
.chat-fab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0;
  width: 60px;
  height: 60px;
  border-radius: var(--r-pill);
  background: var(--c-pop);
  color: #fff;
  box-shadow: var(--shadow-lift);
  cursor: pointer;
  transition: background var(--d-fast) var(--ease-out),
              transform var(--d-fast) var(--ease-out),
              width var(--d-normal) var(--ease-out);
  overflow: hidden;
  justify-content: center;
}
.chat-fab:hover { background: var(--c-pop-hover); transform: translateY(-2px); }

.chat-fab__ring {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid var(--c-pop);
  animation: chat-pulse 2.6s var(--ease-out) infinite;
  pointer-events: none;
}
@keyframes chat-pulse {
  0%   { transform: scale(1);   opacity: 0.6; }
  70%  { transform: scale(1.5); opacity: 0; }
  100% { transform: scale(1.5); opacity: 0; }
}

.chat-fab__icon {
  width: 26px;
  height: 26px;
  transition: opacity var(--d-fast) var(--ease-out),
              transform var(--d-fast) var(--ease-out);
}
.chat-fab__icon--close { position: absolute; opacity: 0; transform: rotate(-45deg); }
.chat-fab.is-active .chat-fab__icon--open  { opacity: 0; transform: rotate(45deg); }
.chat-fab.is-active .chat-fab__icon--close { opacity: 1; transform: rotate(0); }
.chat-fab.is-active .chat-fab__ring { display: none; }

.chat-fab__pill {
  position: absolute;
  right: 72px;
  white-space: nowrap;
  background: var(--c-charcoal);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-card);
  opacity: 0;
  transform: translateX(8px);
  transition: opacity var(--d-fast) var(--ease-out), transform var(--d-fast) var(--ease-out);
  pointer-events: none;
}
.chat-fab:hover .chat-fab__pill { opacity: 1; transform: translateX(0); }
.chat-fab.is-active .chat-fab__pill { display: none; }

/* ─── Panel ────────────────────────────────── */
.chat-panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 120px));
  padding-block: 0; /* override global `section` padding-block (would squash the flex layout) */
  display: flex;
  flex-direction: column;
  background: var(--c-bone-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lift);
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  transition: opacity var(--d-normal) var(--ease-out),
              transform var(--d-normal) var(--ease-out);
}
.chat-panel.is-open { opacity: 1; transform: translateY(0) scale(1); }

/* When closed, the `hidden` attribute must truly remove the panel — otherwise
   `display: flex` above keeps it laid out (just opacity:0) and it swallows taps,
   which on mobile blankets most of the screen and blocks every button. */
.chat-panel[hidden] { display: none !important; }

.chat-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--c-charcoal);
  color: #fff;
}
.chat-panel__id { display: flex; align-items: center; gap: var(--sp-3); }
.chat-panel__badge { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.chat-panel__name {
  font-family: var(--f-display);
  font-weight: 800;
  font-size: 15px;
  line-height: 1.1;
}
.chat-panel__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 2px;
}
.chat-panel__dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #36d399;
  box-shadow: 0 0 0 0 rgba(54, 211, 153, 0.6);
  animation: chat-dot 2s ease-out infinite;
}
@keyframes chat-dot {
  0%   { box-shadow: 0 0 0 0 rgba(54, 211, 153, 0.6); }
  70%  { box-shadow: 0 0 0 6px rgba(54, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(54, 211, 153, 0); }
}
.chat-panel__close {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  transition: background var(--d-fast) var(--ease-out), color var(--d-fast) var(--ease-out);
}
.chat-panel__close svg { width: 18px; height: 18px; }
.chat-panel__close:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }

/* ─── Message log ──────────────────────────── */
.chat-log {
  flex: 1 1 auto;
  min-height: 0; /* allow the log to shrink & scroll instead of pushing siblings out */
  overflow-y: auto;
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  scroll-behavior: smooth;
}
.chat-panel__head,
.chat-chips,
.chat-input,
.chat-human { flex-shrink: 0; }
.chat-msg { display: flex; }
.chat-msg--bot  { justify-content: flex-start; }
.chat-msg--user { justify-content: flex-end; }

.chat-bubble {
  max-width: 84%;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.45;
  border-radius: 16px;
  animation: chat-pop var(--d-normal) var(--ease-out) both;
}
@keyframes chat-pop {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-msg--bot .chat-bubble {
  background: #fff;
  color: var(--c-mute-2);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-card);
}
.chat-msg--user .chat-bubble {
  background: var(--c-pop);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.chat-typing { display: inline-flex; gap: 4px; padding: 14px; }
.chat-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--c-mute);
  animation: chat-bounce 1.2s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* ─── Quick-reply chips ────────────────────── */
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: 0 var(--sp-4) var(--sp-3);
  overflow: hidden;
  transition: opacity var(--d-fast) var(--ease-out),
              max-height var(--d-normal) var(--ease-out),
              padding var(--d-normal) var(--ease-out);
  max-height: 240px;
}
.chat-chips.is-hidden {
  opacity: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
}
.chat-chip {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--c-mute-2);
  background: #fff;
  border: 1px solid var(--c-line);
  border-radius: var(--r-pill);
  padding: 7px 12px;
  cursor: pointer;
  transition: border-color var(--d-fast) var(--ease-out),
              color var(--d-fast) var(--ease-out),
              transform var(--d-fast) var(--ease-out);
}
.chat-chip:hover {
  border-color: var(--c-pop);
  color: var(--c-pop);
  transform: translateY(-1px);
}

/* ─── Text input ───────────────────────────── */
.chat-input {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--c-line);
  background: #fff;
}
.chat-input__field {
  flex: 1;
  font-family: var(--f-body);
  font-size: 14px;
  color: var(--c-ink);
  padding: 10px 4px;
  border: none;
  background: transparent;
}
.chat-input__field:focus { outline: none; }
.chat-input__field::placeholder { color: var(--c-mute); }
.chat-input__send {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  flex: none;
  border-radius: 50%;
  background: var(--c-pop);
  color: #fff;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease-out), transform var(--d-fast) var(--ease-out);
}
.chat-input__send svg { width: 18px; height: 18px; }
.chat-input__send:hover { background: var(--c-pop-hover); transform: scale(1.06); }

/* ─── Human handoff ────────────────────────── */
.chat-human {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 13px var(--sp-4);
  background: #1fa04f;
  color: #fff;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: background var(--d-fast) var(--ease-out);
}
.chat-human:hover { background: #1c8f47; }
.chat-human__icon { width: 20px; height: 20px; }
.chat-human.is-flash { animation: chat-flash 1.1s var(--ease-out) 2; }
@keyframes chat-flash {
  0%, 100% { background: #1fa04f; }
  50%      { background: #25c65f; }
}

/* ─── Mobile ───────────────────────────────── */
@media (max-width: 520px) {
  .chat { right: 14px; bottom: 14px; }
  .chat-panel {
    bottom: 72px;
    width: calc(100vw - 28px);
    height: min(70vh, calc(100vh - 110px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-fab__ring,
  .chat-panel__dot,
  .chat-human.is-flash { animation: none; }
  .chat-panel { transition: opacity var(--d-fast) linear; transform: none; }
}
