/* WhatsApp Bot Button — SIEMPRE VISIBLE, encima del sticky CTA */
.wa-widget-btn {
  position: fixed !important;
  bottom: 24px !important;
  right: 20px !important;
  z-index: 9500 !important;  /* Por encima del sticky CTA bar (9000), debajo de checkout modal (10000) */
  background: linear-gradient(135deg, #25d366, #128c7e) !important;
  color: #ffffff !important;
  display: flex !important;
  align-items: center;
  gap: 0.65rem;
  padding: 0.8rem 1.25rem;
  border-radius: 9999px;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: 0 8px 30px rgba(37, 211, 102, 0.45), 0 0 15px rgba(37, 211, 102, 0.3);
  border: none;
  cursor: pointer;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  transition: bottom 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s ease !important;
}

/* ── En móvil: sincronizado elegantemente con el scroll y sticky bar ── */
@media (max-width: 768px) {
  .wa-widget-btn {
    bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important;  /* Por defecto encima del sticky CTA bar */
    right: 14px !important;
    padding: 0.6rem 0.95rem !important;
    font-size: 0.82rem !important;
    gap: 0.5rem !important;
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.5), 0 0 12px rgba(37, 211, 102, 0.3) !important;
    z-index: 9500 !important;
  }

  /* Cuando el usuario está arriba (sin sticky bar visible), baja suavemente a 18px */
  body:not(.sticky-cta-active) .wa-widget-btn {
    bottom: calc(18px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Cuando el usuario hace scroll y aparece el sticky CTA bar, sube sobre la barra */
  body.sticky-cta-active .wa-widget-btn {
    bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

.wa-widget-btn:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 12px 36px rgba(37, 211, 102, 0.6) !important;
}

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


.wa-pulse-dot {
  width: 10px;
  height: 10px;
  background: #34d399;
  border-radius: 50%;
  box-shadow: 0 0 8px #34d399;
  animation: waPulse 2s infinite;
}

@keyframes waPulse {
  0% { transform: scale(0.95); opacity: 0.9; }
  50% { transform: scale(1.25); opacity: 1; box-shadow: 0 0 14px #34d399; }
  100% { transform: scale(0.95); opacity: 0.9; }
}

/* Contenedor raíz aislado con el nivel más alto de apilamiento */
#wa-widget-root {
  position: relative !important;
  z-index: 2147483645 !important;
}

/* Chat Box Window */
.wa-chat-window {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: #0b141a;
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147483647 !important;
  transform: scale(0.9) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* En móvil, posicionar la ventana del chat cómodamente con margen superior para no solaparse con nada */
@media (max-width: 768px) {
  .wa-chat-window {
    top: calc(10px + env(safe-area-inset-top, 0px)) !important;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
    right: 12px !important;
    left: 12px !important;
    width: auto !important;
    max-width: 440px !important;
    margin: 0 auto !important;
    height: auto !important;
    max-height: calc(100dvh - 22px) !important;
    border-radius: 18px !important;
    z-index: 2147483647 !important;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.95), 0 0 0 1px rgba(255, 255, 255, 0.15) !important;
  }
}

.wa-chat-window.active {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Header */
.wa-header {
  background: linear-gradient(135deg, #1f2c34, #128c7e);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.wa-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.wa-btn-logo-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wa-btn-logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid #ffffff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.wa-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.wa-avatar-img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}

.wa-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #e9edef;
  display: flex;
  align-items: center;
  gap: 4px;
}

.wa-verified {
  color: #38bdf8;
  font-size: 0.85rem;
}

.wa-status {
  font-size: 0.75rem;
  color: #25d366;
  display: flex;
  align-items: center;
  gap: 5px;
}

.wa-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.wa-btn-icon {
  background: transparent;
  border: none;
  color: #aebac1;
  font-size: 1.1rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  text-decoration: none;
}

.wa-btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

/* Chat Body */
.wa-body {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background-color: #0b141a;
  background-image: radial-gradient(circle, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Messages */
.wa-msg {
  max-width: 86%;
  padding: 10px 14px;
  font-size: 0.86rem;
  line-height: 1.45;
  border-radius: 12px;
  word-break: break-word;
  position: relative;
}

.wa-msg-bot {
  align-self: flex-start;
  background: #202c33;
  color: #e9edef;
  border-top-left-radius: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.wa-msg-user {
  align-self: flex-end;
  background: #005c4b;
  color: #e9edef;
  border-top-right-radius: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.wa-msg-time {
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.5);
  text-align: right;
  margin-top: 4px;
}

.wa-link-btn {
  display: inline-block;
  background: #00a884;
  color: #fff !important;
  font-weight: 700;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 8px;
  margin-top: 8px;
  font-size: 0.82rem;
}

.wa-link-btn:hover {
  background: #029070;
}

/* Quick Chips */
.wa-chips {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.wa-chip {
  background: rgba(32, 44, 51, 0.9);
  border: 1px solid rgba(0, 168, 132, 0.4);
  color: #38bdf8;
  padding: 7px 12px;
  border-radius: 16px;
  font-size: 0.78rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.wa-chip:hover {
  background: rgba(0, 168, 132, 0.2);
  border-color: #00a884;
  color: #fff;
  transform: translateX(3px);
}

/* Typing Indicator */
.wa-typing {
  align-self: flex-start;
  background: #202c33;
  padding: 8px 14px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  display: none;
}

.wa-typing-dot {
  width: 6px;
  height: 6px;
  background: #8696a0;
  border-radius: 50%;
  animation: typingDot 1.4s infinite;
}

.wa-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.wa-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Footer / Input */
.wa-footer {
  background: #202c33;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.wa-attach-btn {
  background: transparent;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8696a0;
  cursor: pointer;
  transition: color 0.2s, background 0.2s, transform 0.15s;
  flex-shrink: 0;
  padding: 0;
}

.wa-attach-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #25d366;
  transform: scale(1.08);
}

.wa-input {
  flex: 1;
  background: #2a3942;
  border: none;
  outline: none;
  padding: 10px 14px;
  border-radius: 20px;
  color: #fff;
  font-size: 0.88rem;
}

.wa-input::placeholder {
  color: #8696a0;
}

.wa-send-btn {
  background: #00a884;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s;
}

.wa-send-btn:hover {
  background: #029070;
  transform: scale(1.06);
}

@media (max-width: 640px) {
  .wa-btn-sub-text {
    display: none !important;
  }
  .wa-widget-btn {
    right: 14px !important;
    padding: 0.5rem 0.85rem !important;
    font-size: 0.82rem !important;
    gap: 0.45rem !important;
    border-radius: 9999px !important;
    max-width: 155px !important;
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4) !important;
    z-index: 9500 !important;
  }
  .wa-btn-logo-wrapper {
    width: 24px !important;
    height: 24px !important;
  }
  .wa-widget-btn svg {
    width: 17px !important;
    height: 17px !important;
  }
  .wa-chat-window {
    top: calc(8px + env(safe-area-inset-top, 0px)) !important;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
    right: 8px !important;
    left: 8px !important;
    width: auto !important;
    max-width: none !important;
    height: auto !important;
    max-height: calc(100dvh - 16px) !important;
    border-radius: 18px !important;
    z-index: 2147483647 !important;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.95), 0 0 0 1px rgba(255, 255, 255, 0.15) !important;
  }
}

/* Ocultar completamente el botón flotante cuando el chat está abierto */
#wa-widget-root.wa-open .wa-widget-btn,
.wa-chat-window.active ~ .wa-widget-btn {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
  transform: scale(0.8) !important;
}
