/* =========================================================================
   VES CHAT WIDGET - ESTILOS VISUALES PARAMETRIZADOS Y CORREGIDOS
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

#vites-chat-widget-root {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 999999;
    direction: ltr;
}

/* Ocultar elementos */
.vites-hidden {
    display: none !important;
}

/* =========================================================================
   1. BURBUJA FLOTANTE (BUBBLE)
   ========================================================================= */

#vites-chat-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    position: relative;
    box-shadow: 0 8px 24px var(--vites-shadow);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
    background-color: #ffffff;
    overflow: visible; /* Mantener visible para el efecto de pulso */
}

#vites-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 30px var(--vites-shadow-hover);
}

.vites-bubble-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--vites-primary) !important; /* Borde elegante de marca */
    box-sizing: border-box;
}

.vites-bubble-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.vites-bubble-avatar svg {
    background: var(--vites-gradient) !important;
}

/* Animación de Bote (Bounce) */
.vites-bubble-bounce {
    animation: vites-bounce 4s infinite ease-in-out;
}

@keyframes vites-bounce {
    0%, 100% { transform: translateY(0); }
    10% { transform: translateY(-10px); }
    14% { transform: translateY(3px); }
    18% { transform: translateY(-5px); }
    20% { transform: translateY(0); }
}

/* Efecto de Pulso */
.vites-pulse-effect {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--vites-primary);
    opacity: 0;
    animation: vites-pulse 2.5s infinite;
    pointer-events: none;
}

@keyframes vites-pulse {
    0% {
        transform: scale(0.95);
        opacity: 0.8;
    }
    100% {
        transform: scale(1.4);
        opacity: 0;
    }
}

/* =========================================================================
   2. VENTANA DE CHAT (CHAT WINDOW)
   ========================================================================= */

#vites-chat-window {
    position: absolute;
    bottom: 75px;
    right: 0;
    width: 380px;
    height: 580px;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
    display: flex;
    overflow: hidden;
    animation: vites-slide-up 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

@keyframes vites-slide-up {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.vites-chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Cabecera del Chat */
.vites-chat-header {
    padding: 16px 20px;
    background: var(--vites-gradient);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.vites-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.vites-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    background: white;
    border: 2px solid #ffffff !important; /* Borde elegante blanco */
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    box-sizing: border-box;
}

.vites-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.vites-header-avatar svg {
    background: var(--vites-gradient) !important;
}

.vites-header-info h4 {
    margin: 0 !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    letter-spacing: -0.3px;
    color: #ffffff !important; /* Forzar color blanco para evitar sobreescritura de temas */
}

.vites-status {
    font-size: 11px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 4px;
    color: rgba(255, 255, 255, 0.9) !important;
}

.vites-dot {
    width: 6px;
    height: 6px;
    background-color: #2ecc71;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 8px #2ecc71;
}

.vites-header-actions {
    display: flex;
    gap: 8px;
}

.vites-header-actions button {
    background: none;
    border: none;
    color: white !important;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s, transform 0.2s;
    padding: 4px;
    display: flex;
    align-items: center;
}

.vites-header-actions button:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* =========================================================================
   3. CUERPO DE MENSAJES (MESSAGES)
   ========================================================================= */

#vites-chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: linear-gradient(135deg, #071f3d 0%, #00360a 100%) !important; /* Degradado corporativo premium azul-verde */
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth;
    position: relative;
}

/* Scrollbar personalizado */
#vites-chat-body::-webkit-scrollbar {
    width: 5px;
}
#vites-chat-body::-webkit-scrollbar-track {
    background: transparent;
}
#vites-chat-body::-webkit-scrollbar-thumb {
    background: #e0e0e0;
    border-radius: 10px;
}

#vites-messages-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.vites-message {
    display: flex;
    width: 100%;
    animation: vites-msg-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes vites-msg-in {
    0% { transform: translateY(10px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

/* Estructura del contenido del mensaje con metadatos sobre la burbuja */
.vites-msg-content {
    display: flex;
    flex-direction: column;
    max-width: 82%;
}

.vites-msg-bot .vites-msg-content {
    align-items: flex-start;
}

.vites-msg-user .vites-msg-content {
    align-items: flex-end;
}

.vites-msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 5px;
    font-size: 11px;
    font-weight: 600;
}

.vites-msg-bot .vites-msg-meta {
    color: rgba(255, 255, 255, 0.9) !important;
}

.vites-msg-user .vites-msg-meta {
    color: rgba(255, 255, 255, 0.9) !important;
    justify-content: flex-end;
}

.vites-msg-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.8) !important;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.vites-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.vites-msg-avatar svg {
    width: 100%;
    height: 100%;
    display: block;
}

.vites-msg-name {
    font-size: 11px;
    font-weight: 600;
}

.vites-msg-bot .vites-msg-name {
    color: rgba(255, 255, 255, 0.95) !important;
}

.vites-msg-user .vites-msg-name {
    color: rgba(255, 255, 255, 0.95) !important;
}

.vites-msg-bubble {
    max-width: 100%;
    width: fit-content;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    box-sizing: border-box;
}

/* Encabezados procesados en burbujas */
.vites-msg-bubble h1,
.vites-msg-bubble h2,
.vites-msg-bubble h3 {
    margin: 6px 0 8px 0 !important;
    font-weight: 700 !important;
    line-height: 1.3 !important;
    color: #1a202c !important;
}

.vites-msg-bubble h1 { font-size: 1.15em !important; }
.vites-msg-bubble h2 { font-size: 1.05em !important; }
.vites-msg-bubble h3 { font-size: 0.95em !important; }

/* Mensajes del Bot */
.vites-msg-bot {
    justify-content: flex-start;
}

.vites-msg-bot .vites-msg-bubble {
    background: #ffffff !important;
    color: #1a202c !important;
    border-top-left-radius: 4px;
    border: none !important;
}

/* Mensajes del Usuario */
.vites-msg-user {
    justify-content: flex-end;
}

.vites-msg-user .vites-msg-bubble {
    background: #ffffff !important;
    color: #1a202c !important;
    border-top-right-radius: 4px;
    border: none !important;
}

/* Enlaces y Estilos en Burbujas */
.vites-msg-bubble a.vites-chat-link {
    color: var(--vites-primary) !important;
    text-decoration: underline;
    font-weight: 600;
}

.vites-msg-user .vites-msg-bubble a.vites-chat-link {
    color: #ffffff !important;
}

/* Enlaces de WhatsApp específicos */
a.vites-whatsapp-link {
    display: inline-flex;
    align-items: center;
    background: #2ecc71;
    color: white !important;
    text-decoration: none !important;
    padding: 8px 16px;
    border-radius: 10px;
    margin-top: 8px;
    font-weight: 600;
    font-size: 12px;
    box-shadow: 0 4px 10px rgba(46, 204, 113, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
}

a.vites-whatsapp-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(46, 204, 113, 0.5);
}

/* =========================================================================
   4. AREA DE ENTRADA (INPUT AREA)
   ========================================================================= */

#vites-chat-input-area {
    padding: 12px 18px;
    background: #ffffff;
    border-top: 1px solid #f0f0f5;
    display: flex;
    align-items: center;
}

.vites-chat-input-wrapper {
    display: flex;
    align-items: center;
    flex: 1;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    padding: 3px 6px 3px 14px;
    transition: border-color 0.2s, background-color 0.2s;
}

.vites-chat-input-wrapper:focus-within {
    border-color: var(--vites-primary);
    background: #ffffff;
}

#vites-message-input {
    flex: 1;
    border: none !important;
    padding: 8px 0;
    font-size: 13px;
    outline: none !important;
    background: transparent !important;
    color: #1a202c !important;
    box-shadow: none !important;
}

#vites-btn-send {
    background: var(--vites-gradient);
    border: none;
    color: white !important;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    flex-shrink: 0;
    box-shadow: none !important;
    padding: 0;
}

#vites-btn-send:hover {
    transform: scale(1.08);
}

#vites-btn-send svg {
    margin-left: 1px;
}

/* =========================================================================
   5. INDICADOR DE ESCRIBIENDO (TYPING INDICATOR)
   ========================================================================= */

#vites-typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 18px;
    background: white;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(0, 0, 0, 0.02);
    align-self: flex-start;
}

.vites-dot-bounce {
    width: 6px;
    height: 6px;
    background-color: #a0aec0;
    border-radius: 50%;
    animation: vites-dot-bounce 1.4s infinite ease-in-out both;
}

.vites-dot-bounce:nth-child(1) { animation-delay: -0.32s; }
.vites-dot-bounce:nth-child(2) { animation-delay: -0.16s; }

@keyframes vites-dot-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* =========================================================================
   6. FORMULARIO INICIAL (PRE-CHAT FORM)
   ========================================================================= */

#vites-prechat-form {
    flex: 1;
    padding: 30px 25px;
    background: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow-y: auto;
}

.vites-form-welcome {
    text-align: center;
    margin-bottom: 25px;
}

.vites-form-icon {
    font-size: 36px;
    margin-bottom: 10px;
}

.vites-form-welcome h3 {
    margin: 0 0 8px 0 !important;
    font-size: 18px !important;
    color: #2d3748 !important;
    font-weight: 700 !important;
}

.vites-form-welcome p {
    margin: 0;
    font-size: 13px;
    color: #718096 !important;
    line-height: 1.5;
}

#vites-init-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.vites-input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.vites-input-group label {
    font-size: 12px;
    font-weight: 600;
    color: #4a5568 !important;
}

.vites-input-group input {
    border: 1px solid #cbd5e0;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
    color: #2d3748 !important;
    background-color: #ffffff !important;
}

.vites-input-group input:focus {
    border-color: var(--vites-primary);
}

.vites-input-group small {
    font-size: 10px;
    color: #a0aec0 !important;
    margin-top: 2px;
}

.vites-btn-submit {
    background: var(--vites-gradient);
    color: white !important;
    border: none;
    padding: 12px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
    box-shadow: 0 4px 12px var(--vites-shadow);
    margin-top: 10px;
}

.vites-btn-submit:hover {
    opacity: 0.95;
    transform: translateY(-1px);
}

/* =========================================================================
   6B. MODAL/POPUP DE ESCAPE A WHATSAPP (FALLBACK DIALOGUE)
   ========================================================================= */

.vites-esc-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: vites-fade-in 0.2s ease;
}

@keyframes vites-fade-in {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

.vites-esc-modal {
    width: 85%;
    max-width: 310px;
    background: white;
    border-radius: 15px;
    padding: 22px 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    text-align: center;
    animation: vites-modal-zoom 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes vites-modal-zoom {
    0% { transform: scale(0.85); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.vites-esc-modal h4 {
    margin: 0 0 10px 0 !important;
    font-size: 15px !important;
    color: #2d3748 !important;
    font-weight: 700 !important;
}

.vites-esc-modal p {
    margin: 0 0 16px 0;
    font-size: 12px;
    color: #718096 !important;
    line-height: 1.4;
}

.vites-esc-modal input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #cbd5e0;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    margin-bottom: 15px;
    transition: border-color 0.2s;
    text-align: center;
    color: #2d3748 !important;
    background-color: #ffffff !important;
}

.vites-esc-modal input:focus {
    border-color: var(--vites-primary);
}

.vites-esc-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.vites-esc-btn-cancel {
    background: #edf2f7;
    color: #4a5568 !important;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.vites-esc-btn-cancel:hover {
    background: #e2e8f0;
}

.vites-esc-btn-confirm {
    background: #2ecc71;
    color: white !important;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(46, 204, 113, 0.2);
}

.vites-esc-btn-confirm:hover {
    background: #27ae60;
}

/* =========================================================================
   7. BANNER LATERAL EN PC (DESKTOP SIDEBAR BANNER)
   ========================================================================= */

#vites-chat-sidebar-banner {
    display: none !important; /* Ocultar por completo el banner lateral antiguo */
}

/* Asistente de Cuerpo Completo Flotando a la izquierda del chat window */
#vites-chat-assistant-character {
    display: none; /* Ocultar por defecto en móviles */
}

/* Pantallas grandes (Desktop) */
@media (min-width: 768px) {
    #vites-chat-window {
        width: 380px; /* Mantener la ventana de chat a 380px */
    }

    #vites-chat-assistant-character {
        display: block;
        position: absolute;
        bottom: 0;
        right: 340px; /* 380px (ancho del chat) - 40px de overlap para acercarla */
        width: 280px;
        height: 480px;
        z-index: 999998;
        pointer-events: none; /* No bloquear clics en la web */
        animation: vites-slide-up-char 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    }

    #vites-chat-assistant-character img {
        width: 100%;
        height: 100%;
        object-fit: contain;
        display: block;
        filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.25));
    }
}

@keyframes vites-slide-up-char {
    0% {
        opacity: 0;
        transform: translateY(40px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Ajustes responsivos para móvil */
@media (max-width: 480px) {
    #vites-chat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        border: none;
    }

    #vites-chat-bubble {
        bottom: 15px;
        right: 15px;
    }
}
