/* ============================================================
   ESFOTEX CHATBOT WIDGET STYLES (SCOPED - TEMA ROJO Y AZUL SUAVE ESFOTEX)
   ============================================================ */

#esfotex-chat-widget,
.chat-widget-container {
  position: fixed !important;
  bottom: 95px !important;
  right: 25px !important;
  z-index: 1000 !important;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
}

.whatsapp {
  position: fixed !important;
  bottom: 25px !important;
  right: 25px !important;
  z-index: 999 !important;
}

#esfotex-chat-widget *,
#esfotex-chat-widget *::before,
#esfotex-chat-widget *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* --- ANIMACIÓN DE ONDAS EN EL GLOBO DE TEXTO --- */
@keyframes esfotexBubblePulse {
  0% {
    box-shadow: 0 0 0 0 rgba(230, 57, 70, 0.6), 0 4px 20px rgba(0, 0, 0, 0.2);
    transform: scale(1);
  }
  70% {
    box-shadow: 0 0 0 14px rgba(230, 57, 70, 0), 0 6px 25px rgba(0, 0, 0, 0.25);
    transform: scale(1.03);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(230, 57, 70, 0), 0 4px 20px rgba(0, 0, 0, 0.2);
    transform: scale(1);
  }
}

/* --- BOTÓN FLOTANTE LAUNCHER (AVATAR CIRCULAR + GLOBO DE TEXTO) --- */
#esfotex-chat-widget .chat-launcher {
  background: transparent !important;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  box-shadow: none !important;
  position: relative;
}

/* Globo de texto (Speech Bubble) con Animación de Ondas */
#esfotex-chat-widget .launcher-text {
  background: #ffffff;
  color: #0f172a;
  font-size: 0.88rem;
  font-weight: 700;
  padding: 0.55rem 0.95rem;
  border-radius: 14px;
  position: relative;
  white-space: nowrap;
  animation: esfotexBubblePulse 2s infinite ease-in-out;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  order: 1;
}

/* Triángulo apuntando al avatar */
#esfotex-chat-widget .launcher-text::after {
  content: '';
  position: absolute;
  right: -7px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 7px solid #ffffff;
}

/* Ícono Mascota sin fondo */
#esfotex-chat-widget .launcher-icon {
  width: 60px;
  height: 60px;
  background: transparent url('../img/chat_ico.webp') center/contain no-repeat !important;
  font-size: 0;
  color: transparent;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.25));
  transition: transform 0.3s ease, filter 0.3s ease;
  order: 2;
}

/* Efecto al pasar el cursor (Hover) */
#esfotex-chat-widget .chat-launcher:hover .launcher-icon {
  transform: scale(1.1);
  filter: drop-shadow(0 6px 16px rgba(230, 57, 70, 0.4));
}

#esfotex-chat-widget .chat-launcher:hover .launcher-text {
  transform: scale(1.04);
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.3);
}

#esfotex-chat-widget .notification-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #e63946;
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #0f172a;
}

/* --- CAJA PRINCIPAL DEL CHAT --- */
#esfotex-chat-widget .chat-box {
  position: absolute;
  bottom: 4.5rem;
  right: 0;
  width: 380px;
  height: 580px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#esfotex-chat-widget .chat-box.hidden {
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
}

/* --- ENCABEZADO Y AVATAR --- */
#esfotex-chat-widget .chat-header {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  padding: 1rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid #e63946;
}

#esfotex-chat-widget .avatar-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Foto de Perfil usando chat_ico.webp (sin fondo) */
#esfotex-chat-widget .avatar {
  width: 42px;
  height: 42px;
  background: transparent url('../img/chat_ico.webp') center/contain no-repeat !important;
  font-size: 0 !important;
  color: transparent !important;
  border: none !important;
  box-shadow: none !important;
  flex-shrink: 0;
}

#esfotex-chat-widget .avatar-title h3 {
  font-size: 1rem;
  color: #ffffff;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
}

#esfotex-chat-widget .status {
  font-size: 0.75rem;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 2px;
}

#esfotex-chat-widget .status-dot {
  width: 8px;
  height: 8px;
  background: #22c55e;
  border-radius: 50%;
}

#esfotex-chat-widget .close-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 6px;
  line-height: 1;
  transition: color 0.2s ease;
}

#esfotex-chat-widget .close-btn:hover {
  color: #ffffff;
}

/* --- MENSAJES --- */
#esfotex-chat-widget .chat-messages {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  background: #0f172a;
}

#esfotex-chat-widget .message {
  max-width: 85%;
  padding: 0.8rem 1rem;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.45;
  word-break: break-word;
  animation: esfotexChatFadeIn 0.25s ease-out;
}

@keyframes esfotexChatFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Mensaje de Usuario: Rojo ESFOTEX */
#esfotex-chat-widget .message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #e63946 0%, #c1121f 100%);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(230, 57, 70, 0.25);
}

/* Mensaje del Bot: Azul Suave / Slate */
#esfotex-chat-widget .message.bot {
  align-self: flex-start;
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom-left-radius: 4px;
}

#esfotex-chat-widget .message p {
  margin-bottom: 0.5rem;
}
#esfotex-chat-widget .message p:last-child {
  margin-bottom: 0;
}
#esfotex-chat-widget .message strong {
  color: #f87171;
  font-weight: 600;
}
#esfotex-chat-widget .message.bot strong {
  color: #f87171;
}
#esfotex-chat-widget .message.user strong {
  color: #ffffff;
}

#esfotex-chat-widget .chat-media-container {
  margin-top: 0.75rem;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #0f172a;
}

#esfotex-chat-widget .chat-media-container img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transition: transform 0.2s ease;
}

#esfotex-chat-widget .chat-media-container img:hover {
  transform: scale(1.02);
}

#esfotex-chat-widget .chat-media-container video {
  width: 100%;
  max-height: 220px;
  display: block;
  border-radius: 12px;
}

#esfotex-chat-widget .media-caption {
  font-size: 0.75rem;
  color: #94a3b8;
  padding: 0.4rem 0.6rem;
  background: #1e293b;
  text-align: center;
}

#esfotex-chat-widget .typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 0.6rem 0.9rem;
  background: #1e293b;
  border-radius: 16px;
  width: fit-content;
  align-self: flex-start;
}

#esfotex-chat-widget .typing-indicator span {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: esfotexChatBounce 1.2s infinite ease-in-out;
}

#esfotex-chat-widget .typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
#esfotex-chat-widget .typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes esfotexChatBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* --- BOTONES DE ACCIÓN RÁPIDA --- */
#esfotex-chat-widget .quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.6rem 0.8rem;
  background: #1e293b;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

#esfotex-chat-widget .quick-actions button {
  white-space: nowrap;
  background: rgba(230, 57, 70, 0.12);
  border: 1px solid rgba(230, 57, 70, 0.3);
  color: #f1f5f9;
  font-size: 0.78rem;
  padding: 0.38rem 0.78rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

#esfotex-chat-widget .quick-actions button:hover {
  background: #e63946;
  color: #ffffff;
  border-color: #e63946;
}

/* --- INPUT Y BOTÓN ENVIAR --- */
#esfotex-chat-widget .chat-input-form {
  display: flex;
  padding: 0.8rem 1rem;
  background: #1e293b;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  gap: 0.5rem;
}

#esfotex-chat-widget .chat-input-form input {
  flex: 1;
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 0.65rem 0.9rem;
  color: #ffffff;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s ease;
}

#esfotex-chat-widget .chat-input-form input:focus {
  border-color: #e63946;
}

#esfotex-chat-widget .send-btn {
  background: linear-gradient(135deg, #e63946 0%, #c1121f 100%);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}

#esfotex-chat-widget .send-btn:hover {
  transform: scale(1.05);
  background: linear-gradient(135deg, #f87171 0%, #e63946 100%);
}

/* Lightbox Modal (Scoped) */
#image-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 1;
  transition: opacity 0.25s ease;
}

#image-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

#image-modal img {
  max-width: 90%;
  max-height: 85vh;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.8);
}

#image-modal .close-modal {
  position: absolute;
  top: 1.5rem;
  right: 2rem;
  color: #ffffff;
  font-size: 2rem;
  cursor: pointer;
}

/* Ondas para móvil sin escalar el botón ni alterar sus dimensiones. */
@keyframes whatsappPulseMobile {
  0% {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3), 0 0 0 0 rgba(37, 211, 102, 0.65);
  }
  70% {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3), 0 0 0 14px rgba(37, 211, 102, 0);
  }
  100% {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3), 0 0 0 0 rgba(37, 211, 102, 0);
  }
}

/* --- ADAPTACIÓN RESPONSIVA PARA MÓVILES --- */
@media (max-width: 768px) {
  .whatsapp {
    position: fixed !important;
    /* El borde derecho de algunas vistas móviles queda fuera de pantalla por
       el desbordamiento horizontal de la página. Anclar al borde izquierdo
       mantiene siempre visible WhatsApp y lo separa del chat. */
    /* Se eleva sobre la barra inferior del navegador móvil. */
    bottom: 90px !important;
    left: 15px !important;
    right: auto !important;
    width: 48px !important;
    height: 48px !important;
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    animation: whatsappPulseMobile 2s infinite ease-out !important;
    transform: none !important;
    transition: none !important;
    z-index: 2100 !important;
  }

  .whatsapp:hover,
  .whatsapp:focus,
  .whatsapp:active {
    transform: none !important;
  }

  .whatsapp img {
    width: 32px !important;
    height: 32px !important;
  }

  #esfotex-chat-widget,
  .chat-widget-container {
    position: fixed !important;
    bottom: 85px !important;
    right: 15px !important;
    z-index: 1000 !important;
  }

  #esfotex-chat-widget .launcher-icon {
    width: 48px !important;
    height: 48px !important;
  }

  #esfotex-chat-widget .launcher-text {
    font-size: 0.78rem !important;
    padding: 0.4rem 0.7rem !important;
  }

  #esfotex-chat-widget .chat-box {
    position: fixed !important;
    width: calc(100vw - 30px) !important;
    max-width: 360px !important;
    height: calc(100vh - 180px) !important;
    height: calc(100dvh - 180px) !important;
    min-height: 360px !important;
    max-height: 540px !important;
    bottom: 90px !important;
    right: 15px !important;
    border-radius: 18px !important;
    z-index: 2000 !important;
  }

  #esfotex-chat-widget .chat-header,
  #esfotex-chat-widget .quick-actions,
  #esfotex-chat-widget .chat-input-form {
    flex-shrink: 0 !important;
  }

  #esfotex-chat-widget .chat-messages {
    min-height: 0 !important;
  }

  #esfotex-chat-widget .chat-input-form input {
    min-width: 0 !important;
    font-size: 16px !important;
  }
}
