/* ===================================================================
   === ESTILOS DEL ASISTENTE DE IA (CEREBRO VALORDOLAR.CL) - V1.0 ===
   =================================================================== */

/* 1. BOTÓN FLOTANTE */
.ai-chat-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
    border: none;
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ai-chat-launcher:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 12px 32px rgba(37, 99, 235, 0.6), 0 0 15px rgba(37, 99, 235, 0.8);
}

.ai-chat-launcher i {
    color: #ffffff;
    font-size: 24px;
    transition: transform 0.3s ease;
}

.ai-chat-launcher.active {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

/* 2. CONTENEDOR DE CHAT (GLASSMORPHISM) */
.ai-chat-container {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    height: 520px;
    max-width: calc(100vw - 48px);
    max-height: calc(100vh - 140px);
    border-radius: 20px;
    background: rgba(18, 18, 18, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6), 0 0 30px rgba(37, 99, 235, 0.05);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.ai-chat-container.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* 3. CABECERA DEL CHAT */
.ai-chat-header {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.1), rgba(29, 78, 216, 0.15));
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.ai-chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #2563eb;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10px rgba(37, 99, 235, 0.5);
}

.ai-chat-header-avatar i {
    color: #ffffff;
    font-size: 18px;
}

.ai-chat-header-title h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: #ffffff;
    font-family: 'Inter', sans-serif;
}

.ai-chat-header-title span {
    font-size: 0.72rem;
    color: #10b981;
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
}

.ai-chat-header-title span::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 6px #10b981;
}

.ai-chat-close-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    transition: color 0.2s ease;
}

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

/* 4. AREA DE MENSAJES */
.ai-chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

/* Scrollbar personalizado */
.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}
.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

/* Burbujas de mensaje */
.ai-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.88rem;
    line-height: 1.45;
    font-family: 'Inter', sans-serif;
    word-wrap: break-word;
}

.ai-message.user {
    align-self: flex-end;
    background: #2563eb;
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.ai-message.assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    color: #e5e7eb;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.ai-message.assistant a.chat-link {
    color: #3b82f6;
    text-decoration: underline;
    font-weight: 600;
    transition: color 0.2s ease;
}

.ai-message.assistant a.chat-link:hover {
    color: #60a5fa;
}

/* 5. SUGERENCIAS DE CHAT (QUICK ACTIONS) */
.ai-chat-suggestions {
    padding: 0 16px 12px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ai-suggestion-btn {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.7);
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 0.76rem;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    transition: all 0.2s ease;
}

.ai-suggestion-btn:hover {
    background: rgba(37, 99, 235, 0.1);
    border-color: rgba(37, 99, 235, 0.4);
    color: #ffffff;
}

/* 6. AREA DE ENTRADA (INPUT) */
.ai-chat-input-area {
    padding: 12px 16px 16px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    gap: 8px;
    align-items: center;
}

.ai-chat-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 12px 14px;
    color: #ffffff;
    font-size: 0.88rem;
    outline: none;
    font-family: 'Inter', sans-serif;
    transition: all 0.2s ease;
}

.ai-chat-input:focus {
    border-color: rgba(37, 99, 235, 0.5);
    box-shadow: 0 0 8px rgba(37, 99, 235, 0.15);
}

.ai-chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: #2563eb;
    border: none;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ai-chat-send-btn:hover {
    background: #1d4ed8;
    box-shadow: 0 0 10px rgba(37, 99, 235, 0.4);
}

.ai-chat-send-btn:disabled {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.2);
    cursor: not-allowed;
    box-shadow: none;
}

/* 7. EFECTO DE ESCRITURA (TYPING INDICATOR) */
.ai-typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
    justify-content: center;
    height: 20px;
}

.ai-typing-dot {
    width: 6px;
    height: 6px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    animation: ai-typing-bounce 1.4s infinite ease-in-out both;
}

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

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

/* ===================================================================
   === EVITAR COLISIÓN CON EL BOTÓN SUBIR (SCROLL TO TOP)           ===
   =================================================================== */
.scroll-top-btn {
    right: 96px !important;
    bottom: 32px !important;
    z-index: 9997 !important; /* Por debajo del launcher y contenedor del chat */
    transition: all 0.3s cubic-bezier(0.165, 0.84, 0.44, 1) !important;
}

@media (max-width: 576px) {
    /* 1. Botón Subir (Scroll to Top) - Ajustes en móvil */
    .scroll-top-btn {
        width: 40px !important;
        height: 40px !important;
        right: 21px !important;
        bottom: 78px !important;
    }
    .scroll-top-btn i {
        font-size: 16px !important;
    }

    /* 2. Botón Lanzador de IA - Ajustes en móvil */
    .ai-chat-launcher {
        width: 50px;
        height: 50px;
        bottom: 16px;
        right: 16px;
    }
    .ai-chat-launcher i {
        font-size: 20px;
    }

    /* 3. Contenedor de Chat en móvil: Estilo "bottom-sheet" / cajón deslizable */
    .ai-chat-container {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 80vh;
        max-height: 80vh;
        border-radius: 24px 24px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        transform: translateY(100%) scale(1);
    }

    .ai-chat-container.active {
        transform: translateY(0) scale(1);
    }
    
    /* Soporte para áreas seguras de iOS (notch / barra de inicio) */
    .ai-chat-input-area {
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
}

