/* ==========================================================================
   WhatsApp Widget Integrado - Estilos Completos y Definitivos v3.3
   CORRECCIÓN CRÍTICA DE ADAPTABILIDAD TOTAL GLOBAL
   ========================================================================== */

/* CAPA DE ADAPTABILIDAD TOTAL GLOBAL
   Asegura que el widget gestione su espacio en función de la pantalla. */
.wai-widget-wrapper {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: flex-end; /* Alinea los elementos a la derecha */
    gap: 12px;
    line-height: normal;
    box-sizing: border-box;
    pointer-events: none; /* Asegura que el contenedor no bloquee clics */
    
    /* Configuración por defecto para PC/Resoluciones altas */
    width: auto; 
    max-width: 380px; /* Ancho máximo seguro para que no se desborde */
}

/* Reactivación de clics para los elementos internos */
.wai-widget-wrapper #wai-whatsapp-icon,
.wai-widget-wrapper #wai-chat-box {
    pointer-events: auto;
}

/* Icono flotante de WhatsApp con animación moderna (Efecto 2026/2027) */
#wai-whatsapp-icon {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(37, 211, 102, 0.4);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
    animation: waiFloatPulse 3s infinite ease-in-out;
    flex-shrink: 0;
    z-index: 100001;
}

#wai-whatsapp-icon:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 15px 35px rgba(37, 211, 102, 0.6);
}

#wai-whatsapp-icon svg {
    width: 35px;
    height: 35px;
    fill: #ffffff;
}

@keyframes waiFloatPulse {
    0% { transform: translateY(0) scale(1); box-shadow: 0 8px 20px rgba(37, 211, 102, 0.35); }
    50% { transform: translateY(-6px) scale(1.03); box-shadow: 0 14px 30px rgba(37, 211, 102, 0.5); }
    100% { transform: translateY(0) scale(1); box-shadow: 0 8px 20px rgba(37, 211, 102, 0.35); }
}

/* Utilidad para ocultar elementos */
.wai-chat-hidden {
    display: none !important;
}

/* ==================================================
   Caja del Chat (Ventana emergente)
   ================================================== */
#wai-chat-box {
    width: 360px; /* Ancho fijo por defecto para PC */
    height: 550px;
    max-height: 80vh; /* Adaptabilidad crítica en móviles */
    background: #efeae2;
    background-image: radial-gradient(circle, rgba(0,0,0,0.035) 1px, transparent 1px);
    background-size: 16px 16px;
    border-radius: 16px;
    box-shadow: 0 12px 35px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: bottom right;
    animation: waiFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 100000;
}

@keyframes waiFadeIn {
    from { opacity: 0; transform: translateY(15px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ==================================================
   Burbuja de Bienvenida (El globo con texto)
   CORRECCIÓN CRÍTICA GLOBAL: Fondo blanco y texto oscuro forzado.
   MODERNIZACIÓN ESTÉTICA GLOBAL Y ANIMACIÓN DE APERTURA SUTIL
   ================================================== */

#wai-help-bubble {
    position: absolute;
    bottom: 12px; /* Posición relativa al icono de WhatsApp */
    right: 75px;  /* Separación a la izquierda del icono */
    /* Sombra suave moderna para dar profundidad */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15) !important;
    
    /* Tipografía Moderna */
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    font-weight: 500; /* Ligeramente gruesa */
    letter-spacing: -0.2px; /* Toque moderno */
    line-height: 1;
    z-index: 99998;
    
    /* Alineación Interna */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px; /* Espacio con icono si lo hubiera */
    
    /* Borde sutil opcional para definición */
    border: 1px solid rgba(0, 0, 0, 0.05);

    pointer-events: none; /* Asegura que el globo no bloquee clics al fondo */
    max-width: 230px;
    box-sizing: border-box;
    white-space: nowrap; /* Evita que el texto se corte en PC */
    cursor: pointer;
    overflow: hidden;
    
    /* Transición suave para todos los cambios */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* NUEVA ANIMACIÓN DE APERTURA SUTIL (Se ejecuta una vez al cargar) */
    animation: waiBubbleAppear 0.5s ease-out forwards;
    animation-delay: 0.5s; /* Pequeño retraso para naturalidad */
    opacity: 0; /* Estado inicial antes de la animación */
}

/* El triángulo indicador de la burbuja */
#wai-help-bubble::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    /* CORRECCIÓN: Mismo color que el fondo del globo forzado */
    border-left: 6px solid #ffffff !important;
}

/* CORRECCIÓN: Asegurar que el span interno también sea oscuro de forma global */
#wai-help-bubble span {
    background: transparent !important;
    color: #1a1a1a !important; /* Texto casi negro */
    font-family: inherit;
    font-size: inherit;
    line-height: 1.4;
    display: block;
    margin: 0;
    padding: 0;
}

/* Definición de la nueva animación de aparición sutil */
@keyframes waiBubbleAppear {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==================================================
   Encabezado del Chat
   ================================================== */
.wai-chat-header {
    background: #00a884;
    color: #ffffff;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.wai-header-info { display: flex; flex-direction: column; }
.wai-header-title { font-size: 16px; line-height: 1.2; }

.wai-status-text {
    font-size: 11px;
    font-weight: 400;
    opacity: 0.9;
    display: flex;
    align-items: center;
    margin-top: 3px;
}

.wai-status-dot {
    width: 8px;
    height: 8px;
    background-color: #34bf49;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
    box-shadow: 0 0 0 0 rgba(52, 191, 73, 0.7);
    animation: pulseDot 2s infinite;
}

@keyframes pulseDot {
    0% { box-shadow: 0 0 0 0 rgba(52, 191, 73, 0.7); }
    70% { box-shadow: 0 0 0 6px rgba(52, 191, 73, 0); }
    100% { box-shadow: 0 0 0 0 rgba(52, 191, 73, 0); }
}

/* Botones del encabezado */
.wai-header-actions { display: flex; align-items: center; gap: 8px; }

#wai-reset-chat {
    background: rgba(255, 255, 255, 0.25);
    border: none;
    color: #ffffff;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 15px;
    transition: all 0.2s;
}
#wai-reset-chat:hover { background: rgba(255, 255, 255, 0.4); transform: translateY(-1px); }

#wai-close-chat {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 26px;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
    padding: 0;
    margin-top: -2px;
}
#wai-close-chat:hover { opacity: 1; }

/* ==================================================
   Cuerpo del Chat (Mensajes)
   ================================================== */
#wai-chat-body {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: inherit;
    scroll-behavior: smooth;
}

.wai-message {
    padding: 10px 15px;
    border-radius: 12px;
    max-width: 82%;
    font-size: 14.5px;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.wai-message.ai-msg {
    background: #ffffff;
    align-self: flex-start;
    color: #111b21;
    border-top-left-radius: 3px;
}

.wai-message.user-msg {
    background: #e7ffdb;
    align-self: flex-end;
    color: #111b21;
    border-top-right-radius: 3px;
}

/* Opciones rápidas (Botones) */
.wai-quick-options {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-top: 15px;
    width: 100%;
}

.wai-opt-btn {
    background: #ffffff;
    border: 1px solid #00a884;
    color: #00a884;
    padding: 11px 16px;
    text-align: left;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
    display: flex;
    align-items: center;
}

.wai-opt-btn:hover {
    background-color: #00a884;
    color: #ffffff;
    transform: translateY(-2px);
}

.wai-branch-option {
    position: relative;
    padding-right: 35px;
}
.wai-branch-option::after {
    content: '›';
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    font-weight: 300;
    opacity: 0.6;
}

.wai-pdf-btn, .wai-whatsapp-btn {
    display: block;
    margin-top: 12px;
    padding: 12px 16px;
    color: #ffffff !important;
    text-decoration: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
    transition: all 0.2s;
}
.wai-pdf-btn { background-color: #d32f2f; }
.wai-pdf-btn:hover { background-color: #b71c1c; }

.wai-whatsapp-btn { background-color: #25d366; }
.wai-whatsapp-btn:hover { background-color: #128c7e; }

/* ==================================================
   Área de Entrada (Footer)
   ================================================== */
.wai-bottom-container {
    background: #f0f2f5;
    border-top: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    position: relative;
    margin-top: auto;
}

.wai-chat-footer {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    box-sizing: border-box;
}

.wai-input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    background: #ffffff;
    border-radius: 24px;
    padding: 2px 5px 2px 15px;
    border: 1px solid #e0e0e0;
    box-sizing: border-box;
}

#wai-user-input {
    flex: 1;
    padding: 9px 5px;
    border: none;
    outline: none;
    font-size: 14.5px;
    background: transparent;
    color: #111b21;
    margin: 0;
    line-height: normal;
    resize: none;
    height: 20px;
}

#wai-send-btn {
    background: transparent;
    color: #00a884;
    border: none;
    cursor: pointer;
    padding: 8px;
    margin-left: 5px;
    display: flex;
}
#wai-send-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

/* ==================================================
   SKIN CLIENGO (Sobreescribe el diseño base)
   ================================================== */
#wai-chat-box.wai-skin-cliengo { background: #ffffff; background-image: none; }
.wai-skin-cliengo .wai-chat-header { background: #ffffff; color: #333333; border-bottom: 1px solid #e5e5e5; box-shadow: none; }
.wai-skin-cliengo .wai-status-text { color: #666666; }
.wai-skin-cliengo #wai-reset-chat { background: #f0f0f0; color: #555; }
.wai-skin-cliengo #wai-close-chat { color: #999; }
.wai-skin-cliengo #wai-chat-body { background: #fafafa; }
.wai-skin-cliengo .wai-message.ai-msg { background: #5b9bd5; color: #ffffff; border-radius: 14px; border-top-left-radius: 4px; }
.wai-skin-cliengo .wai-message.user-msg { background: #e6f0fa; color: #333; border-radius: 14px; border-top-right-radius: 4px; }
.wai-skin-cliengo .wai-opt-btn { border: 1px solid #5b9bd5; color: #5b9bd5; border-radius: 20px; text-align: center; justify-content: center; }
.wai-skin-cliengo .wai-opt-btn:hover { background: #5b9bd5; color: #ffffff; }
.wai-skin-cliengo .wai-bottom-container { background: #ffffff; }
.wai-skin-cliengo .wai-input-wrapper { border: none; border-bottom: 1px solid #ccc; border-radius: 0; box-shadow: none; }
.wai-skin-cliengo #wai-send-btn { color: #5b9bd5; }

/* ==================================================
   Estilos Responsivos (Móviles)
   CORRECCIÓN CRÍTICA: Ajuste orgánico en porcentaje para cualquier pantalla móvil.
   MODERNIZACIÓN BURBUJA RESPONSIVE
   ================================================== */
@media screen and (max-width: 480px) {
    /* CORRECCIÓN: El contenedor principal se expande al 100% del ancho móvil */
    .wai-widget-wrapper { 
        bottom: 20px; 
        right: 20px; 
        width: calc(100vw - 40px); /* Ocupa todo el ancho móvil menos márgenes seguros */
        max-width: none;
    }
    
    /* CORRECCIÓN: La ventana de chat se expande al 100% de la anchura del contenedor */
    #wai-chat-box { 
        width: 100%; 
        height: 500px; 
        bottom: 75px; 
        right: 0; 
    }
    
    /* Adaptación Responsiva Burbuja (Móviles) - Modernizada */
    #wai-help-bubble { 
        position: absolute !important;
        right: 70px !important; /* Ajuste para móvil */
        max-width: 180px !important;
        white-space: normal; /* Permite que el texto se parta en varias líneas si es necesario */
        
        /* Reducción de sombra para móvil para que no se vea pesada */
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1) !important;
    }
}

/* ==================================================
   ESTILOS ADICIONALES PARA EL ADMIN
   ================================================== */
#wai-sortable-tbody tr { transition: background-color 0.2s ease; }
#wai-sortable-tbody tr:hover { background-color: #f0f6fc !important; }
#wai-sortable-tbody td { vertical-align: middle !important; padding: 12px 10px !important; }

/* ==================================================
   Branding (Footer)
   ================================================== */
.wai-branding {
    text-align: center;
    font-size: 10px;
    letter-spacing: 0.5px;
    color: #8696a0; /* Un gris sutil para que no compita con el chat */
    padding: 2px 15px 12px 15px; /* Espaciado equilibrado */
    width: 100%;
    box-sizing: border-box;
    text-transform: uppercase; /* Le da un toque más corporativo y pulido */
}

.wai-branding a {
    color: #00a884; /* Mantiene el color primario del widget */
    text-decoration: none;
    font-weight: 700;
    transition: opacity 0.2s ease;
}

.wai-branding a:hover {
    opacity: 0.7; /* Efecto hover elegante en lugar de subrayado */
}

/* ==================================================
   Ajuste para SKIN CLIENGO (Opcional, si usas ese skin)
   ================================================== */
.wai-skin-cliengo .wai-branding a {
    color: #5b9bd5; /* Lo adapta al azul del tema Cliengo */
}