/* =========================================================
   ai_chat.css - Floating AI Concierge (Apple Glass Style)
   ========================================================= */

/* Floating Button */
.ai-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 95px; /* Dejar espacio para WhatsApp en tienda */
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background: linear-gradient(135deg, var(--accent-blue), #1e40af);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(59, 130, 246, 0.4), 0 0 15px rgba(59, 130, 246, 0.2);
    z-index: 99999;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Ajuste específico para el panel de Admin para que no tape el sidebar */
.admin-page .ai-chat-bubble {
    right: auto;
    left: 30px;
}

.admin-page .ai-chat-window {
    right: auto;
    left: 30px;
}

.ai-chat-bubble:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 15px 40px rgba(59, 130, 246, 0.5);
}

.ai-chat-bubble svg {
    width: 28px;
    height: 28px;
}

/* Chat Window */
.ai-chat-window {
    position: fixed;
    bottom: 95px;
    right: 30px;
    width: 340px;
    height: 500px;
    max-height: 80vh;
    background: var(--bg-card);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.3);
    z-index: 99998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.9);
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Dark Mode Overrides (Simplificado para usar variables de main.css) */
html[data-theme='dark'] .ai-chat-window {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

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

/* Header */
.ai-chat-header {
    padding: 20px;
    background: linear-gradient(to right, rgba(59, 130, 246, 0.15), rgba(16, 185, 129, 0.1));
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}

html[data-theme='dark'] .ai-chat-header {
    background: linear-gradient(to right, rgba(59, 130, 246, 0.2), rgba(16, 185, 129, 0.15));
}

.ai-chat-header .status-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 8px #10b981;
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

/* Message Area */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.ai-msg {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6; /* Mayor espacio entre líneas */
    letter-spacing: 0.2px;
    position: relative;
    animation: msgIn 0.3s ease-out;
    color: var(--text-main);
}

.ai-msg strong {
    color: var(--accent-blue); /* Resaltar negritas en azul sutil */
    font-weight: 700;
}

html[data-theme='dark'] .ai-msg strong {
    color: #60a5fa;
}

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

.ai-msg p { margin-bottom: 10px; }
.ai-msg p:last-child { margin-bottom: 0; }
.ai-msg table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 11px; }
.ai-msg th, .ai-msg td { padding: 6px; border: 1px solid rgba(255,255,255,0.1); text-align: left; }
.ai-msg th { background: rgba(255,255,255,0.1); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.ai-msg h3 { 
    margin: 15px 0 8px 0; 
    font-size: 14px; 
    font-weight: 700; 
    color: var(--accent-green); 
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    padding-bottom: 4px;
}
.ai-msg ul, .ai-msg ol { padding-left: 20px; margin: 10px 0; }
.ai-msg li { margin-bottom: 8px; }

.ai-msg.user {
    align-self: flex-end;
    background: var(--accent-blue);
    color: #ffffff !important;
    border-bottom-right-radius: 4px;
}

.ai-msg.bot {
    align-self: flex-start;
    background: var(--bg-card-hover);
    color: var(--text-main) !important;
    border-bottom-left-radius: 4px;
    border-left: 4px solid var(--accent-green);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Forzar colores en modo oscuro según variables de tienda */
html[data-theme='dark'] .ai-msg.bot {
    background: #1a1a1a;
    color: #ffffff !important;
}

html[data-theme='dark'] .ai-msg.user {
    background: var(--accent-blue);
    color: #ffffff !important;
}

/* Typing Indicator */
.ai-typing {
    display: flex;
    gap: 4px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 18px;
    align-self: flex-start;
}

.ai-dot {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: ai-bounce 1.4s infinite ease-in-out;
}

.ai-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* Input Area */
.ai-chat-input-area {
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-chat-input-area input {
    flex: 1;
    min-width: 0; /* Important: prevents pushing button out */
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 16px; /* Prevents auto-zoom on mobile */
    color: white;
    outline: none;
    transition: all 0.2s;
}

html[data-theme='dark'] .ai-chat-input-area input {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.1);
    color: white;
}

.ai-chat-input-area input:focus {
    border-color: var(--accent-blue);
    background: white;
}

html[data-theme='dark'] .ai-chat-input-area input:focus {
    background: rgba(0, 0, 0, 0.4);
}

.ai-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent-blue);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.ai-send-btn:hover {
    transform: scale(1.1);
}

.ai-send-btn svg {
    width: 18px;
    height: 18px;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    /* Bloqueo de scroll cuando el chat está activo */
    body.ai-chat-open {
        overflow: hidden !important;
        overscroll-behavior: contain;
    }

    .ai-chat-window {
        width: 280px !important;
        height: 350px !important;
        max-height: 50vh !important;
        top: 70px !important; 
        bottom: auto !important;
        left: auto !important;
        right: 10px !important;
        border-radius: 12px !important;
        z-index: 1000000 !important;
        transform: translateY(-10px) scale(0.95) !important;
        background: rgba(10, 10, 10, 0.95) !important;
        backdrop-filter: blur(25px) !important;
        -webkit-backdrop-filter: blur(25px) !important;
        display: flex !important;
        flex-direction: column !important;
        box-shadow: 0 8px 32px rgba(0,0,0,0.4) !important;
        opacity: 0;
        pointer-events: none;
    }
    
    .ai-chat-window.active {
        transform: translateY(0) scale(1) !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }
    
    .ai-chat-messages {
        flex: 1 !important;
        padding: 15px !important;
        background: transparent !important;
    }

    .ai-chat-input-area {
        display: flex !important;
        align-items: center !important;
        padding: 12px !important;
        background: rgba(255,255,255,0.05) !important;
        border-top: 1px solid rgba(255,255,255,0.1) !important;
    }

    .ai-chat-header {
        padding: 12px !important;
        background: transparent !important;
    }

    /* Ya no ocultamos las burbujas */
    body.ai-chat-open .ai-chat-bubble,
    body.ai-chat-open #whatsappFloat {
        display: flex !important;
    }
    
    /* Ya no bloqueamos el scroll */
    body.ai-chat-open {
        overflow: auto !important;
        touch-action: auto !important;
    }
}

/* Cursor parpadeante durante el streaming */
@keyframes ai-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

.ai-cursor {
    display: inline-block;
    color: #555;
    animation: ai-blink 0.8s step-start infinite;
    margin-left: 1px;
    font-weight: 300;
}
