/* ==========================================================================
   Kamruzzaman Polash — Page Mascot (Unified Bottom-Right Floating Companion)
   100% Theme-adaptive, Accessible, Harmonized with Live Chat & Mobile Optimized
   ========================================================================== */

.page-mascot {
  position: fixed;
  right: 1.75rem;
  bottom: 1.75rem;
  left: auto;
  z-index: 97; /* Sits cleanly as primary interactive companion */
  display: flex;
  align-items: flex-end;
  pointer-events: none;
}

.page-mascot__dock {
  position: relative;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Mascot Button: Authentic transparent sticker */
.page-mascot__btn {
  position: relative;
  width: 84px;
  height: 84px;
  display: block;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  user-select: none;
  outline: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), filter 0.2s ease;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.16));
}

.dark .page-mascot__btn {
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.55));
}

.page-mascot__btn:hover {
  transform: translateY(-3px) scale(1.05);
}

.page-mascot__btn:active {
  transform: translateY(1px) scale(0.96);
}

.page-mascot__squash {
  position: absolute;
  inset: 0;
  display: block;
  transform-origin: center bottom;
  animation: mascotBreathe 3.8s ease-in-out infinite;
}

@keyframes mascotBreathe {
  0%, 100% {
    transform: translateY(0) scale(1, 1);
  }
  50% {
    transform: translateY(-2.2px) scale(1.012, 1.018);
  }
}

@media (prefers-reduced-motion: reduce) {
  .page-mascot__squash {
    animation: none !important;
  }
}

.page-mascot__layer {
  position: absolute;
  inset: 0;
  background-size: 300% 300%;
  background-repeat: no-repeat;
  pointer-events: none;
  transition: opacity 0.09s ease;
}

.page-mascot__layer--directions {
  background-image: url('/assets/images/mascot-directions.webp?v=1');
  opacity: 1;
}

.page-mascot__layer--blink {
  background-image: url('/assets/images/mascot-directions-blink.webp?v=1');
  opacity: 0;
}

.page-mascot__layer--reactions {
  background-image: url('/assets/images/mascot-reactions.webp?v=1');
  opacity: 0;
}

.page-mascot__layer--actions {
  background-image: url('/assets/images/mascot-actions.webp?v=1');
  opacity: 0;
}

.page-mascot__layer--actions-2 {
  background-image: url('/assets/images/mascot-actions-2.webp?v=1');
  opacity: 0;
}

/* Unread Badge on Mascot */
.page-mascot__unread {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 9999px;
  background: var(--accent);
  color: #ffffff;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.35rem;
  text-align: center;
  box-shadow: 0 2px 8px var(--accent-glow), 0 0 0 2px var(--paper);
  pointer-events: none;
  animation: unreadPop .25s cubic-bezier(.34, 1.56, .64, 1) forwards;
  z-index: 6;
}

@keyframes mascot-pulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes mascot-pulse-away {
  0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7); }
  70% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
  100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

/* Subtle Live Status Dot on Mascot Frame */
.page-mascot__status-dot {
  position: absolute;
  right: 6px;
  bottom: 4px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--ok-dot, #10b981);
  border: 2px solid var(--paper, #ffffff);
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: mascot-pulse 2s infinite cubic-bezier(0.66, 0, 0, 1);
  z-index: 5;
  pointer-events: none;
  transition: background 0.25s ease, opacity 0.25s ease;
}

.dark .page-mascot__status-dot {
  border-color: #121316;
}

.page-mascot__status-dot.is-away {
  background: #f59e0b;
  box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7);
  animation: mascot-pulse-away 2.5s infinite cubic-bezier(0.66, 0, 0, 1);
}

/* If live chat is hidden via admin config */
.page-mascot.chat--hidden .page-mascot__status-dot,
.page-mascot.chat--hidden .page-mascot__unread {
  display: none !important;
}

/* Sleek Custom Themed Hover Tooltip */
.page-mascot__tooltip {
  position: absolute;
  bottom: calc(100% + 12px);
  right: 0;
  left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 9999px;
  padding: 0.32rem 0.75rem;
  font-family: var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
  font-size: 0.74rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16), 0 2px 6px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 9;
}

.page-mascot__tooltip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok-dot, #10b981);
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: mascot-pulse 2s infinite cubic-bezier(0.66, 0, 0, 1);
  flex-shrink: 0;
  transition: background 0.25s ease;
}

.page-mascot__tooltip-dot.is-away {
  background: #f59e0b;
  box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7);
  animation: mascot-pulse-away 2.5s infinite cubic-bezier(0.66, 0, 0, 1);
}

/* Show tooltip on hover only when bubble is NOT open */
@media (hover: hover) and (pointer: fine) {
  .page-mascot:not(.is-talking) .page-mascot__dock:hover .page-mascot__tooltip {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* When mascot is talking or chat is open, suppress tooltip */
.page-mascot.is-talking .page-mascot__tooltip,
body:has(.live-chat.is-open) .page-mascot__tooltip,
.live-chat.is-open ~ .page-mascot .page-mascot__tooltip {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Speech Bubble (Anchored to the right above mascot) */
.page-mascot__bubble {
  position: absolute;
  bottom: calc(100% + 14px);
  right: 0;
  left: auto;
  transform: translateY(8px) scale(0.92);
  transform-origin: bottom right;
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  padding: 0.7rem 0.95rem;
  font-family: var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.45;
  width: max-content;
  max-width: min(300px, calc(100vw - 48px));
  white-space: normal;
  text-wrap: pretty;
  word-break: break-word;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.22), 0 3px 8px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.page-mascot__bubble::before {
  content: '';
  position: absolute;
  top: 100%;
  right: 32px;
  left: auto;
  border: 8px solid transparent;
  border-top-color: var(--line-2);
}

.page-mascot__bubble::after {
  content: '';
  position: absolute;
  top: 100%;
  right: 33px;
  left: auto;
  border: 7px solid transparent;
  border-top-color: var(--paper-2);
}

.page-mascot.is-talking .page-mascot__bubble {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* One-Click Live Chat CTA inside Speech Bubble */
.page-mascot__bubble-action {
  margin-top: 0.55rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--line-2);
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.page-mascot__bubble-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 9999px;
  padding: 0.35rem 0.8rem;
  font-family: var(--sans, sans-serif);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 2px 8px var(--accent-glow);
  transition: transform 0.18s ease, filter 0.18s ease;
}

.page-mascot__bubble-cta:hover {
  transform: translateY(-1px);
  filter: brightness(1.12);
  color: #ffffff;
}

.page-mascot__bubble-cta svg {
  flex-shrink: 0;
}

.page-mascot__bubble-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok-dot, #10b981);
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: mascot-pulse 2s infinite cubic-bezier(0.66, 0, 0, 1);
  flex-shrink: 0;
  display: inline-block;
}

/* Confetti & Emojis Canvas */
.mascot-fx-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 9999;
}

/* Clean Industry Standard: Redundant launcher pill is hidden, Mascot is primary */
.live-chat__launcher {
  display: none !important;
}

/* Desktop Chat Window floats above the Mascot dock with clean padding */
.live-chat__window {
  bottom: 7.35rem !important;
  right: 1.75rem !important;
}

/* While chat window is open, hide mascot bubble to prevent overlap */
body:has(.live-chat.is-open) .page-mascot__bubble,
.live-chat.is-open ~ .page-mascot .page-mascot__bubble {
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

/* Hide mascot when fullscreen mobile navigation menu is open */
body:has(.mobile-menu.is-open) .page-mascot,
.mobile-menu.is-open ~ .page-mascot {
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

/* ==========================================================================
   Mobile Optimization (< 580px)
   ========================================================================== */
@media (max-width: 579px) {
  /* On mobile: fullscreen chat modal hides mascot */
  body:has(.live-chat.is-open) .page-mascot,
  .live-chat.is-open ~ .page-mascot {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
  }

  .page-mascot {
    right: 0.85rem;
    bottom: 0.85rem;
    left: auto;
  }

  .page-mascot__btn {
    width: 62px;
    height: 62px;
  }

  .live-chat__window {
    bottom: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
  }

  .page-mascot__bubble {
    right: 0;
    left: auto;
    max-width: calc(100vw - 2.5rem);
    font-size: 0.74rem;
    padding: 0.55rem 0.8rem;
  }

  .page-mascot__bubble::before {
    right: 22px;
    left: auto;
  }

  .page-mascot__bubble::after {
    right: 23px;
    left: auto;
  }
}
