/* Floating WhatsApp chat button + popup.
   Markup: templates/partials/whatsapp-widget.php
   Behaviour: assets/js/whatsapp-widget.js */

.sw-wa {
  --sw-wa-green: #25d366;
  --sw-wa-teal: #075e54;
  --sw-wa-chat-bg: #ece5dd;
  position: fixed;
  right: 30px;
  bottom: 30px;
  z-index: 2147483000;
  font-family: "Outfit", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

/* ---------- Launcher ---------- */

.sw-wa-launcher {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--sw-wa-green);
  box-shadow: 0 10px 25px rgba(37, 211, 102, 0.35);
  color: #fff;
  cursor: pointer;
  transition: background-color 0.25s, box-shadow 0.25s, transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sw-wa-launcher svg {
  width: 32px;
  height: 32px;
}

.sw-wa-launcher:hover {
  transform: translateY(-3px) scale(1.05);
}

.sw-wa-launcher:focus-visible,
.sw-wa-close:focus-visible,
.sw-wa-cta:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(7, 94, 84, 0.6);
}

.sw-wa.is-open .sw-wa-launcher {
  background: var(--sw-wa-teal);
  box-shadow: 0 10px 25px rgba(7, 94, 84, 0.35);
}

/* A soft ring that leaves the button a few times when the badge arrives. */
.sw-wa.has-badge:not(.is-open) .sw-wa-launcher::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.6);
  animation: sw-wa-pulse 1.8s ease-out 3;
  pointer-events: none;
}

.sw-wa-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 20px;
  height: 20px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #ff3b30;
  animation: sw-wa-badge-in 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.sw-wa-badge[hidden],
.sw-wa-typing[hidden],
.sw-wa-message[hidden] {
  display: none;
}

/* ---------- Popup ---------- */

.sw-wa-popup {
  position: absolute;
  right: 0;
  bottom: 76px;
  display: flex;
  flex-direction: column;
  width: 340px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px);
  overflow: hidden;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
  text-align: start;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(16px) scale(0.94);
  transform-origin: bottom right;
  transition: opacity 0.22s ease, transform 0.26s cubic-bezier(0.34, 1.3, 0.64, 1), visibility 0s linear 0.26s;
}

.sw-wa.is-open .sw-wa-popup {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  transition-delay: 0s;
}

.sw-wa-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 18px 20px;
  background: var(--sw-wa-teal);
  color: #fff;
}

.sw-wa-avatar {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #fff;
}

.sw-wa-avatar img {
  width: 40px;
  height: auto;
  max-height: 40px;
  object-fit: contain;
}

.sw-wa-online {
  position: absolute;
  right: 0;
  bottom: 1px;
  width: 13px;
  height: 13px;
  border: 2px solid var(--sw-wa-teal);
  border-radius: 50%;
  background: var(--sw-wa-green);
}

.sw-wa-heading {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.sw-wa-title {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

.sw-wa-subtitle {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.85);
}

.sw-wa-close {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  cursor: pointer;
  transition: background-color 0.2s;
}

.sw-wa-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

.sw-wa-close svg {
  width: 20px;
  height: 20px;
}

.sw-wa-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  min-height: 150px;
  padding: 22px 20px 26px 24px;
  overflow-y: auto;
  background: var(--sw-wa-chat-bg);
}

.sw-wa-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 16px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

.sw-wa-typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9aa5ab;
  animation: sw-wa-dot 1.2s ease-in-out infinite;
}

.sw-wa-typing span:nth-child(2) { animation-delay: 0.15s; }
.sw-wa-typing span:nth-child(3) { animation-delay: 0.3s; }

.sw-wa-message {
  position: relative;
  max-width: 100%;
  padding: 10px 14px 8px;
  border-radius: 0 14px 14px 14px;
  background: #fff;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
  color: #111b21;
  transform-origin: top left;
  animation: sw-wa-message-in 0.3s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}

/* The little tail at the top corner of the bubble. */
.sw-wa-message::before {
  content: "";
  position: absolute;
  top: 0;
  left: -9px;
  border-style: solid;
  border-width: 0 10px 12px 0;
  border-color: transparent #fff transparent transparent;
}

.sw-wa-sender {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 700;
  color: #5b6770;
}

.sw-wa-text {
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
  color: #111b21;
}

.sw-wa-time {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 700;
  text-align: end;
  color: #5b6770;
}

.sw-wa-footer {
  padding: 16px 20px 20px;
  background: #fff;
}

.sw-wa-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 18px;
  border-radius: 999px;
  background: var(--sw-wa-green);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
  transition: filter 0.2s, transform 0.2s;
}

.sw-wa-cta:hover {
  color: #fff;
  filter: brightness(0.95);
  transform: translateY(-1px);
}

.sw-wa-cta svg {
  flex: none;
  width: 22px;
  height: 22px;
}

/* ---------- Right-to-left (Arabic) ----------
   The button stays bottom-right like the rest of the site's fixed pieces;
   only what is inside the popup is mirrored. */

[dir="rtl"] .sw-wa-header { padding: 18px 20px 18px 16px; }
[dir="rtl"] .sw-wa-online { right: auto; left: 0; }
[dir="rtl"] .sw-wa-body { padding: 22px 24px 26px 20px; }
[dir="rtl"] .sw-wa-message { border-radius: 14px 0 14px 14px; transform-origin: top right; }
[dir="rtl"] .sw-wa-message::before {
  left: auto;
  right: -9px;
  border-width: 0 0 12px 10px;
  border-color: transparent transparent transparent #fff;
}

/* ---------- Small screens ---------- */

@media (max-width: 768px) {
  .sw-wa {
    right: 20px;
    bottom: 20px;
  }

  .sw-wa-launcher {
    width: 56px;
    height: 56px;
  }

  .sw-wa-popup {
    bottom: 70px;
  }
}

@media (max-width: 400px) {
  .sw-wa {
    right: 16px;
    bottom: 16px;
  }

  .sw-wa-popup {
    max-height: calc(100vh - 104px);
  }

  .sw-wa-header { padding: 14px 12px 14px 16px; }
  .sw-wa-body { padding: 18px 16px 20px 20px; }
  .sw-wa-footer { padding: 12px 16px 16px; }
  .sw-wa-cta { font-size: 15px; }
}

/* ---------- Animations ---------- */

@keyframes sw-wa-badge-in {
  0% { transform: scale(0); }
  60% { transform: scale(1.3); }
  80% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

@keyframes sw-wa-pulse {
  0% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.6); }
  100% { box-shadow: 0 0 0 18px rgba(37, 211, 102, 0); }
}

@keyframes sw-wa-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

@keyframes sw-wa-message-in {
  0% { opacity: 0; transform: translateY(8px) scale(0.92); }
  100% { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sw-wa-launcher,
  .sw-wa-popup,
  .sw-wa-cta {
    transition: none;
  }

  .sw-wa-launcher:hover,
  .sw-wa-cta:hover {
    transform: none;
  }

  .sw-wa-popup {
    transform: none;
  }

  .sw-wa-badge,
  .sw-wa-message,
  .sw-wa-typing span,
  .sw-wa.has-badge:not(.is-open) .sw-wa-launcher::after {
    animation: none;
  }
}
