/**
 * Floating WhatsApp Chat Widget
 * @version 1.0.0
 * @license MIT
 * 
 * Copyright (c) 2026 AbitareHaus
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

:root {
  --wa-primary: #25D366;
  --wa-primary-hover: #20bd5a;
  --wa-dark: #075E54;
  --wa-teal: #128C7E;
  --wa-bg-body: #ECE5DD;
  --wa-white: #ffffff;
  --wa-shadow: 0 10px 30px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.08);
}

.wa-widget {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 999990;
  font-family: 'Nunito Sans', system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

/* Floating Launcher Button */
.wa-widget__launcher {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--wa-primary);
  color: var(--wa-white);
  border: 2px solid #ffffff;
  box-shadow: 0 8px 24px rgba(37, 211, 102, 0.42), 0 2px 8px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
  outline: none;
  text-decoration: none;
}

.wa-widget__launcher:hover {
  background: var(--wa-primary-hover);
  transform: scale(1.08);
  box-shadow: 0 10px 28px rgba(37, 211, 102, 0.55), 0 4px 12px rgba(0, 0, 0, 0.16);
}

.wa-widget__launcher:active {
  transform: scale(0.96);
}

.wa-widget__launcher svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
  transition: transform 0.25s ease;
}

/* Pulse Animation Ring */
.wa-widget__pulse {
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border-radius: 50%;
  border: 2px solid var(--wa-primary);
  animation: waPulse 2.4s infinite cubic-bezier(0.4, 0, 0.6, 1);
  pointer-events: none;
}

@keyframes waPulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 0; }
  100% { transform: scale(1.3); opacity: 0; }
}

/* Tooltip Badge */
.wa-widget__tooltip {
  position: absolute;
  left: 68px;
  top: 50%;
  transform: translateY(-50%);
  background: #020241;
  color: #ffffff;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(2, 2, 65, 0.2);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.wa-widget__tooltip::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-right-color: #020241;
}

.wa-widget__launcher:hover .wa-widget__tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) translateX(4px);
}

/* Interactive Chat Card Popup */
.wa-widget__popup {
  position: absolute;
  bottom: 70px;
  left: 0;
  width: 330px;
  max-width: calc(100vw - 32px);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: var(--wa-shadow);
  border: 1px solid rgba(2, 2, 65, 0.08);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.96);
  transform-origin: bottom left;
  transition: opacity 0.26s cubic-bezier(0.16, 1, 0.3, 1), transform 0.26s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.26s;
}

.wa-widget.is-open .wa-widget__popup {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.wa-widget.is-open .wa-widget__pulse {
  display: none;
}

/* Header */
.wa-popup__header {
  background: linear-gradient(135deg, var(--wa-teal) 0%, var(--wa-dark) 100%);
  padding: 16px;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.wa-popup__brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wa-popup__avatar-wrap {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.wa-popup__avatar {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.wa-popup__status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  background: #25D366;
  border: 2px solid #ffffff;
  border-radius: 50%;
}

.wa-popup__title {
  font-family: 'Poppins', system-ui, sans-serif;
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.25;
  color: #ffffff;
}

.wa-popup__subtitle {
  font-size: 0.75rem;
  color: #d1fae5;
  margin-top: 2px;
}

.wa-popup__close {
  background: none;
  border: none;
  color: #ffffff;
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
  transition: opacity 0.15s ease, background-color 0.15s ease;
}

.wa-popup__close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
}

/* Body */
.wa-popup__body {
  background: var(--wa-bg-body);
  background-image: radial-gradient(#d3c8ba 1px, transparent 1px);
  background-size: 16px 16px;
  padding: 20px 16px;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.wa-popup__bubble {
  background: #ffffff;
  border-radius: 0 12px 12px 12px;
  padding: 12px 14px;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #1f2937;
  position: relative;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  margin-left: 6px;
}

.wa-popup__bubble::before {
  content: '';
  position: absolute;
  top: 0;
  left: -6px;
  width: 0;
  height: 0;
  border-top: 8px solid #ffffff;
  border-left: 6px solid transparent;
}

.wa-popup__bubble-sender {
  display: block;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--wa-dark);
  margin-bottom: 4px;
}

.wa-popup__time {
  display: block;
  text-align: right;
  font-size: 0.6875rem;
  color: #9ca3af;
  margin-top: 4px;
}

/* Footer Action */
.wa-popup__footer {
  padding: 12px 16px 16px;
  background: #ffffff;
  border-top: 1px solid #f1f5f9;
}

.wa-popup__cta-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  background: var(--wa-primary);
  color: #ffffff;
  text-decoration: none;
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 600;
  font-size: 0.9375rem;
  padding: 12px 18px;
  border-radius: 10px;
  transition: background-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.32);
}

.wa-popup__cta-btn:hover {
  background: var(--wa-primary-hover);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(37, 211, 102, 0.45);
}

.wa-popup__cta-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

@media (max-width: 480px) {
  .wa-widget {
    bottom: 18px;
    left: 18px;
  }
  .wa-widget__popup {
    width: calc(100vw - 36px);
  }
}
