/* ==========================================================================
   Floating chatbot (assets/js/chat-widget.js), on index.html and support.html.
   Button = THBT coin from Figma (node 10:25511). Hover/focus shows a speech bubble to its left.
   ========================================================================== */

.chat-fab-wrap {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.875rem;
}

/* ---------- Coin button ---------- */
.chat-fab {
  position: relative;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chat-fab img {
  display: block;
  width: 64px;
  height: auto; /* keeps the coin's 51 × 53 proportions */
  filter: drop-shadow(0 8px 14px rgba(236, 0, 0, 0.28));
  transition: transform 250ms var(--ease-out);
  animation: chat-bob 3.2s ease-in-out infinite;
}

.chat-fab:hover img,
.chat-fab:focus-visible img {
  transform: scale(1.08) rotate(-8deg);
  animation-play-state: paused;
}

.chat-fab:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: 2px;
}

/* "?" help badge on the coin's top-left, so it reads as help, not as a crypto coin. */
.chat-fab-help {
  position: absolute;
  top: 2px;
  left: 2px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-navy);
  color: #fff;
  box-shadow: 0 0 0 2.5px #fff, 0 4px 10px rgba(18, 26, 51, 0.3);
  transition: transform 250ms var(--ease-out);
  animation: chat-bob 3.2s ease-in-out infinite;
}

.chat-fab:hover .chat-fab-help,
.chat-fab:focus-visible .chat-fab-help {
  transform: scale(1.1);
  animation-play-state: paused;
}

@keyframes chat-bob {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -4px;
  }
}

/* ---------- Speech bubble: "Need Help? Start A Chat With THBT" ---------- */
.chat-tip {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  padding: 0.75rem 1.125rem;
  border-radius: 999px;
  background: var(--color-card);
  color: var(--color-ink);
  box-shadow: 0 10px 30px rgba(22, 22, 26, 0.16), 0 0 0 1px rgba(22, 22, 26, 0.05);
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(8px, -50%) scale(0.96);
  transform-origin: right center;
  transition: opacity 200ms var(--ease-out), transform 250ms var(--ease-out);
}

/* Little tail pointing at the coin. */
.chat-tip::after {
  content: "";
  position: absolute;
  right: -5px;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: inherit;
  transform: translateY(-50%) rotate(45deg);
}

.chat-fab:hover .chat-tip,
.chat-fab:focus-visible .chat-tip {
  opacity: 1;
  transform: translate(0, -50%) scale(1);
}

/* Hide the bubble while the chat is open. */
.chat-fab-wrap.is-open .chat-tip {
  display: none;
}

/* ---------- Panel ---------- */
.chat-panel {
  display: flex;
  flex-direction: column;
  width: min(400px, 100vw - 40px);
  height: min(640px, 100svh - 140px);
  overflow: hidden;
  border-radius: 20px;
  background: var(--color-card);
  box-shadow: 0 24px 60px rgba(22, 22, 26, 0.22);
  transform-origin: bottom right;
  animation: chat-in 220ms var(--ease-out);
}

.chat-panel[hidden] {
  display: none;
}

/* The panel takes focus when it opens (so keyboard users land inside it); no ring around the whole box. */
.chat-panel:focus {
  outline: none;
}

@keyframes chat-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
}

.chat-panel-head {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.625rem 0.625rem 0.875rem;
  background: var(--color-navy);
  color: #fff;
  font-weight: 700;
}

.chat-panel-coin {
  width: 30px;
  height: auto;
}

.chat-panel-head p {
  flex: 1;
}

.chat-panel-head [hidden] {
  display: none;
}

.chat-panel-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.chat-panel-icon:hover {
  background: rgba(255, 255, 255, 0.14);
}

.chat-panel-icon:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -2px;
}

.chat-view {
  position: relative;
  flex: 1;
  min-height: 0;
}

.chat-view[hidden] {
  display: none;
}

/* Ticket view scrolls inside the panel. */
.chat-view-ticket {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 1.125rem 1.25rem;
}

.chat-ticket-lead {
  margin-bottom: 1rem;
  color: var(--color-muted);
  font-size: 0.9375rem;
  line-height: 1.5;
}

.chat-view iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.chat-offline {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  height: 100%;
  padding: 2rem;
  color: var(--color-muted);
  text-align: center;
}

.chat-offline[hidden] {
  display: none;
}

.chat-panel-ticket {
  padding: 0.875rem;
  border: 0;
  border-top: 1px solid var(--color-line);
  background: var(--color-card);
  color: var(--color-brand-strong);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
}

.chat-panel-ticket:hover {
  background: var(--color-brand-soft);
}

.chat-panel-ticket[hidden] {
  display: none;
}

/* ---------- Phones ---------- */
@media (max-width: 599px) {
  .chat-fab-wrap {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .chat-fab img {
    width: 56px;
  }

  /* No hover on touch screens: the bubble would stick after a tap. */
  .chat-tip {
    display: none;
  }

  /* Full-screen chat. */
  .chat-panel {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    border-radius: 0;
  }

  .chat-fab-wrap.is-open .chat-fab {
    display: none;
  }
}

@media (hover: none) {
  .chat-tip {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-fab img,
  .chat-fab-help {
    animation: none;
    transition: none;
  }

  .chat-panel {
    animation: none;
  }

  .chat-tip {
    transition: none;
  }
}

@media print {
  .chat-fab-wrap {
    display: none;
  }
}
