/* ==============================================================================
   VISIBLE AHORA AI SALES ASSISTANT - WIDGET ESTILOS (Organic Brutalism & Glassmorphism)
   Colores Corporativos:
   Primary: #003345 | Secondary: #006972 | Tertiary: #ff5500 | Surface: #f8f9fc
   ============================================================================== */

:root {
    --va-primary: #003345;
    --va-primary-dark: #001e29;
    --va-secondary: #006972;
    --va-secondary-light: #00838f;
    --va-tertiary: #ff5500;
    --va-tertiary-hover: #e64a00;
    --va-surface: #f8f9fc;
    --va-surface-card: #ffffff;
    --va-text-main: #191c1e;
    --va-text-muted: #5a646a;
    --va-border: rgba(0, 51, 69, 0.1);
    --va-shadow-float: 0 20px 50px -10px rgba(0, 51, 69, 0.22);
    --va-shadow-card: 0 8px 30px rgba(0, 51, 69, 0.08);
}

/* Contenedor Flotante Principal */
#va-chat-root {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99995;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--va-text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ==============================================================================
   COORDINACIÓN CON BOTÓN FLOTANTE DE WHATSAPP (SIN ENCIMAMIENTO)
   ============================================================================== */
a.fixed[href*="wa.me"],
#va-wa-float-btn {
    bottom: 96px !important;
    right: 27px !important;
    width: 52px !important;
    height: 52px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    z-index: 99990 !important;
    box-shadow: 0 10px 25px rgba(37, 211, 102, 0.35) !important;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

a.fixed[href*="wa.me"]:hover,
#va-wa-float-btn:hover {
    transform: scale(1.1) translateY(-2px) !important;
    box-shadow: 0 15px 35px rgba(37, 211, 102, 0.55) !important;
}

/* Ocultar suavemente el botón de WhatsApp cuando la ventana de chat está abierta */
body.va-chat-open a.fixed[href*="wa.me"],
body.va-chat-open #va-wa-float-btn,
body:has(.va-chat-window.va-active) a.fixed[href*="wa.me"],
body:has(.va-chat-window.va-active) #va-wa-float-btn {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: scale(0.6) translateY(20px) !important;
}

/* Disparador Flotante (Launcher del Chat) */
.va-launcher-btn {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--va-secondary) 0%, var(--va-primary) 100%);
    color: #ffffff;
    border: none;
    box-shadow: 0 10px 30px rgba(0, 51, 69, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.2) inset;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    outline: none;
}

.va-launcher-btn:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 15px 40px rgba(0, 105, 114, 0.45);
}

.va-launcher-icon {
    font-size: 26px;
    transition: transform 0.3s ease;
}

.va-launcher-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 15px;
    height: 15px;
    background-color: #10b981;
    border: 2.5px solid #ffffff;
    border-radius: 50%;
    animation: va-pulse-green 2s infinite;
}

@keyframes va-pulse-green {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Píldora de Invitación Proactiva (Ubicada a la izquierda del chat, sin tapar WhatsApp) */
.va-proactive-pill {
    position: absolute;
    bottom: 11px;
    right: 76px;
    background: #ffffff;
    color: var(--va-primary);
    padding: 10px 16px;
    border-radius: 20px;
    box-shadow: var(--va-shadow-card);
    border: 1px solid var(--va-border);
    font-size: 12.5px;
    font-weight: 700;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    animation: va-slide-left 0.4s ease-out;
    transition: transform 0.2s, box-shadow 0.2s;
    user-select: none;
}

.va-proactive-pill:hover {
    transform: translateX(-4px);
    box-shadow: var(--va-shadow-float);
}

@keyframes va-slide-left {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: translateX(0); }
}

.va-proactive-pill-dot {
    width: 8px;
    height: 8px;
    background-color: var(--va-tertiary);
    border-radius: 50%;
}

/* Ventana de Chat */
.va-chat-window {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 120px);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 28px;
    box-shadow: var(--va-shadow-float);
    border: 1px solid var(--va-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: scale(0.92) translateY(20px);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* Cabecera del Chat */
.va-chat-header {
    background: linear-gradient(135deg, var(--va-primary) 0%, #00222f 100%);
    color: #ffffff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

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

.va-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--va-secondary) 0%, var(--va-tertiary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 18px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.va-header-title {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -0.01em;
    margin: 0;
    line-height: 1.2;
}

.va-header-status {
    font-size: 11px;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.va-status-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #10b981;
}

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

.va-header-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #ffffff;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background-color 0.2s;
}

.va-header-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Barra Superior de Handoff a WhatsApp */
.va-header-banner {
    background: #f0fdf4;
    border-bottom: 1px solid #dcfce7;
    padding: 8px 16px;
    font-size: 11.5px;
    color: #166534;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.va-banner-link {
    color: #15803d;
    font-weight: 700;
    text-decoration: underline;
    cursor: pointer;
}

/* Área de Mensajes */
.va-messages-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--va-surface);
}

/* Burbujas de Mensaje */
.va-msg-row {
    display: flex;
    width: 100%;
}

.va-msg-row.va-user {
    justify-content: flex-end;
}

.va-msg-row.va-ia,
.va-msg-row.va-agente {
    justify-content: flex-start;
}

.va-msg-bubble {
    max-width: 82%;
    padding: 12px 16px;
    font-size: 13.5px;
    line-height: 1.48;
    border-radius: 20px;
    word-break: break-word;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 51, 69, 0.04);
}

.va-user .va-msg-bubble {
    background: var(--va-primary);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.va-ia .va-msg-bubble {
    background: #ffffff;
    color: var(--va-text-main);
    border: 1px solid rgba(0, 51, 69, 0.08);
    border-bottom-left-radius: 4px;
}

.va-agente .va-msg-bubble {
    background: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
    border-bottom-left-radius: 4px;
}

.va-agente-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    background: #0284c7;
    color: #ffffff;
    padding: 2px 6px;
    border-radius: 6px;
    margin-bottom: 4px;
}

.va-system-pill {
    align-self: center;
    background: rgba(0, 51, 69, 0.06);
    color: var(--va-text-muted);
    font-size: 11.5px;
    padding: 6px 14px;
    border-radius: 14px;
    text-align: center;
    max-width: 90%;
    margin: 4px 0;
}

/* Indicador de Escritura (Typing) */
.va-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: #ffffff;
    border-radius: 18px;
    border: 1px solid rgba(0, 51, 69, 0.08);
    width: fit-content;
}

.va-typing-dot {
    width: 6px;
    height: 6px;
    background: var(--va-secondary);
    border-radius: 50%;
    animation: va-bounce 1.4s infinite ease-in-out both;
}

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

@keyframes va-bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* Respuestas Rápidas (Quick Replies) */
.va-quick-replies {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 6px 16px 12px;
    background: var(--va-surface);
    scrollbar-width: none;
}

.va-quick-replies::-webkit-scrollbar {
    display: none;
}

.va-quick-btn {
    background: #ffffff;
    color: var(--va-primary);
    border: 1px solid var(--va-border);
    padding: 7px 13px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 51, 69, 0.04);
    transition: all 0.2s ease;
}

.va-quick-btn:hover {
    background: var(--va-primary);
    color: #ffffff;
    border-color: var(--va-primary);
    transform: translateY(-1px);
}

/* Área de Entrada (Input Form) */
.va-chat-footer {
    padding: 12px 16px;
    background: #ffffff;
    border-top: 1px solid var(--va-border);
}

.va-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--va-surface);
    border: 1px solid rgba(0, 51, 69, 0.12);
    border-radius: 20px;
    padding: 4px 6px 4px 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.va-input-container:focus-within {
    border-color: var(--va-secondary);
    box-shadow: 0 0 0 3px rgba(0, 105, 114, 0.15);
    background: #ffffff;
}

.va-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 13.5px;
    outline: none;
    color: var(--va-text-main);
}

.va-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--va-tertiary);
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

.va-send-btn:hover:not(:disabled) {
    background: var(--va-tertiary-hover);
    transform: scale(1.05);
}

.va-send-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

/* Animaciones */
@keyframes va-slide-up {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Adaptación Mobile-First */
@media (max-width: 480px) {
    #va-chat-root {
        bottom: 16px;
        right: 16px;
    }
    .va-launcher-btn {
        width: 54px;
        height: 54px;
    }
    a.fixed[href*="wa.me"],
    #va-wa-float-btn {
        bottom: 78px !important;
        right: 18px !important;
        width: 48px !important;
        height: 48px !important;
    }
    .va-proactive-pill {
        bottom: 8px;
        right: 64px;
        font-size: 11px;
        padding: 7px 12px;
        max-width: calc(100vw - 90px);
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .va-chat-window {
        bottom: 0;
        right: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
}
