/* ============================================================
   WhatsApp Chat Popup
   Responsive: Desktop / Tablet / Mobile
   ============================================================ */

/* --- CSS Variables --- */
:root {
  --wa-green-dark: #075E54;
  --wa-green: #25D366;
  --wa-green-hover: #20BD5A;
  --wa-bg: #E5DDD5;
  --wa-msg-incoming: #FFFFFF;
  --wa-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  --wa-radius: 12px;
  --wa-z-overlay: 99999;
  --wa-z-popup: 100000;
}

/* --- Overlay --- */
.wa-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: var(--wa-z-overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0.35s ease;
  -webkit-tap-highlight-color: transparent;
}
.wa-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* --- Popup Container --- */
.wa-popup {
  position: fixed;
  z-index: var(--wa-z-popup);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0.35s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-font-smoothing: antialiased;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.wa-popup.active {
  opacity: 1;
  visibility: visible;
}

/* --- Chat Inner --- */
.wa-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: inherit;
  background: var(--wa-bg);
  border-radius: inherit;
  overflow: hidden;
}

/* ============================================================
   Desktop & Tablet (>= 576px)
   ============================================================ */
@media (min-width: 576px) {
  .wa-popup {
    bottom: 28px;
    right: 28px;
    width: 380px;
    max-height: 560px;
    border-radius: var(--wa-radius);
    box-shadow: var(--wa-shadow);
    transform: translateY(24px) scale(0.96);
    transform-origin: bottom right;
  }
  .wa-popup.active {
    transform: translateY(0) scale(1);
  }
  .wa-popup .wa-chat {
    border: 1px solid rgba(0, 0, 0, 0.08);
  }
  .wa-overlay.active {
    background: transparent;
    pointer-events: none;
  }
}

/* ============================================================
   Mobile (< 576px) — Bottom Sheet
   ============================================================ */
@media (max-width: 575px) {
  .wa-popup {
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 85vh;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    transform: translateY(100%);
  }
  .wa-popup.active {
    transform: translateY(0);
  }
  .wa-overlay.active {
    background: rgba(0, 0, 0, 0.5);
  }
}

/* ============================================================
   Header
   ============================================================ */
.wa-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--wa-green-dark);
  color: #fff;
  flex-shrink: 0;
}
.wa-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--wa-green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.wa-header-info {
  flex: 1;
  min-width: 0;
}
.wa-header-info h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wa-header-info p {
  margin: 2px 0 0;
  font-size: 11px;
  opacity: 0.85;
  line-height: 1.3;
  color: #fff;
}
.wa-header-close {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
  padding: 0;
}
.wa-header-close:hover,
.wa-header-close:focus {
  background: rgba(255, 255, 255, 0.25);
  outline: none;
}

/* --- Status Dot (inline, set via JS innerHTML) --- */
.wa-status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wa-green);
  margin-right: 4px;
  vertical-align: middle;
}

/* ============================================================
   Messages Area
   ============================================================ */
.wa-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.wa-messages::-webkit-scrollbar {
  width: 4px;
}
.wa-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}

/* --- Message Bubbles --- */
.wa-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: waMsgIn 0.3s ease both;
}
.wa-message.incoming {
  align-self: flex-start;
}
.wa-message.outgoing {
  align-self: flex-end;
}
.wa-bubble {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
  color: #111;
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}
.wa-message.incoming .wa-bubble {
  background: var(--wa-msg-incoming);
  border-bottom-left-radius: 4px;
}
.wa-message.outgoing .wa-bubble {
  background: #DCF8C6;
  border-bottom-right-radius: 4px;
}

@keyframes waMsgIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* --- Typing Indicator --- */
.wa-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--wa-msg-incoming);
  border-radius: 8px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
  animation: waMsgIn 0.3s ease both;
}
.wa-typing-dot {
  width: 7px;
  height: 7px;
  background: #90949c;
  border-radius: 50%;
  animation: waTyping 1.4s infinite ease-in-out;
}
.wa-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.wa-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes waTyping {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ============================================================
   Footer / CTA
   ============================================================ */
.wa-footer {
  padding: 12px 18px;
  background: #f0f0f0;
  flex-shrink: 0;
}
.wa-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 20px;
  background: var(--wa-green);
  color: #fff;
  border: none;
  border-radius: 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, transform 0.15s;
}
.wa-btn:hover,
.wa-btn:focus {
  background: var(--wa-green-hover);
  color: #fff;
  text-decoration: none;
  outline: none;
}
.wa-btn:active {
  transform: scale(0.97);
}
.wa-btn i {
  font-size: 20px;
}

/* ============================================================
   Reduced Motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .wa-popup,
  .wa-overlay,
  .wa-message,
  .wa-typing,
  .wa-typing-dot {
    animation: none !important;
    transition: none !important;
  }
}

/* ============================================================
   Print
   ============================================================ */
@media print {
  .wa-overlay,
  .wa-popup {
    display: none !important;
  }
}
