/* =======================================================
   🤖 BPRO AI CHAT WIDGET STYLES (ESTRUCTURA DE BURBUJA - DARK MODE)
   ======================================================= */

/* 1. Contenedor Principal (Posicionamiento Fijo) */
#bpro-ai-widget {
    position: fixed;
    bottom: 40px; 
    right: 25px; /* MODIFICADO: Movido a la derecha */
    left: auto;
    /* position: relative; */
    z-index: 30; /* 10000 antes */
    opacity: 1; 
}

/* 2. UNIDAD FLOTANTE: Contiene la burbuja de texto y el botón de chat */
#bpro-ai-floating-unit {
    display: flex;
    flex-direction: column;
    align-items: flex-end; /* MODIFICADO: Alineado a la derecha */
    opacity: 0; 
    animation: fadeInUnit 0.8s ease-out 1s forwards; 
}


/* 3. Burbuja de Mensaje (Texto Flotante Inicial) */
#bpro-ai-bubble {
    max-width: 250px; 
    background-color: #1a1d26; /* Fondo oscuro elegante */
    color: #e2e8f0;             /* Texto claro nítido */
    padding: 12px 15px;
    border-radius: 20px; 
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 14px;
    line-height: 1.4;
    text-align: left;
    margin-bottom: 5px; 
    cursor: pointer; 
    white-space: normal; 
    opacity: 0;
    transform: scale(0.5);
}

#bpro-ai-bubble.hidden {
    display: none;
}

/* 4. Contenedor del Botón */
#bpro-ai-button-wrapper {
    width: 100%; 
    display: flex;
    justify-content: flex-end; /* MODIFICADO: Alineado a la derecha */
    height: 60px; 
    position: relative; 
}


/* 5. Botón de Apertura (Icono del Robot) */
#bpro-ai-open-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: #007bff; 
    color: white;
    font-size: 28px; 
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 123, 255, 0.4);
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1;
}

#bpro-ai-open-btn:hover {
    background-color: #0056b3;
    transform: scale(1.05);
}

/* Notificación de Conversación Activa */
#bpro-ai-open-btn.active-conversation::after {
    content: '';
    position: absolute;
    top: 0px; 
    right: 0px; /* MODIFICADO: Esquina derecha */
    left: auto;
    width: 12px;
    height: 12px;
    background-color: #dc3545; 
    border-radius: 50%;
    border: 2px solid #07080b; 
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(220, 53, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}

/* 6. Ventana del Chat (Dark Mode Principal) */
#bpro-ai-chat-window {
    z-index: 50; /* La ventana flotante sí puede estar arriba al abrirse */
    width: 350px;
    height: 450px;
    background-color: #111318; /* Fondo oscuro principal que contrasta con #07080b */
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: absolute;
    bottom: 0; 
    right: 0; /* MODIFICADO: Anclado a la derecha */
    left: auto;
    transform-origin: bottom right; /* MODIFICADO: Origen de animación a la derecha */
    transition: all 0.3s ease-in-out;
}

/* =======================================================
   📱 MODO MÓVIL EXTREMO: PANTALLA COMPLETA PARA EL CHAT
   ======================================================= */
@media screen and (max-width: 480px) {
    #bpro-ai-widget {
        position: fixed !important;
        inset: 0 !important; /* Toma el control total si está abierto, o se ancla abajo si está cerrado */
        width: 100% !important;
        height: 100% !important;
        pointer-events: none !important; /* Permite hacer clic detrás si está cerrado */
    }

    /* Cuando el chat está abierto, el widget vuelve a habilitar los clics */
    #bpro-ai-chat-window:not(.hidden) ~ #bpro-ai-widget,
    #bpro-ai-widget:has(#bpro-ai-chat-window:not(.hidden)) {
        pointer-events: auto !important;
    }

    /* Botón flotante y burbuja anclados abajo a la derecha normalmente cuando está cerrado */
    #bpro-ai-floating-unit {
        position: fixed !important;
        bottom: 20px !important;
        right: 20px !important;
        pointer-events: auto !important;
        z-index: 99999 !important;
    }

    /* VENTANA DE CHAT: Ocupa toda la pantalla en móvil entre el header y el teclado */
    #bpro-ai-chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100dvh !important; /* Usa unidades dinámicas para evitar que el teclado rompa la caja */
        max-width: none !important;
        max-height: none !important;
        border-radius: 0 !important;
        border: none !important;
        z-index: 999999 !important;
        pointer-events: auto !important;
    }

    /* Modal de opciones adaptado a pantalla completa en móvil */
    #bpro-ai-close-modal {
        position: fixed !important;
        bottom: 20px !important;
        left: 20px !important;
        right: 20px !important;
        width: auto !important;
        max-width: none !important;
        z-index: 1000000 !important;
    }
}
/* FIN 📱 MODO MÓVIL.......*/

#bpro-ai-chat-window.hidden {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none; 
}

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


/* --- Estilos internos del Chatbox --- */
#bpro-ai-header {
    background-color: #181b24;
    color: white;
    padding: 15px 20px;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    justify-content: space-between; 
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

#bpro-ai-close-btn {
    background: none;
    border: none;
    color: #a0aec0;
    font-size: 24px; 
    cursor: pointer;
    line-height: 1;
    padding: 5px;
    transition: color 0.2s ease;
    font-family: Arial, sans-serif !important; 
    font-weight: 300; 
}

#bpro-ai-close-btn:hover {
    color: #fff;
}


/* Área de mensajes */
#bpro-ai-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px;
    background-color: #111318; 
    display: flex;
    flex-direction: column;
    scrollbar-width: thin; 
}

.ai-message, .user-message {
    padding: 10px 15px;
    margin-bottom: 10px;
    max-width: 85%;
    word-wrap: break-word;
    line-height: 1.4 !important;
    font-size: 14px !important;
    font-weight: normal !important;
    border-radius: 16px;
}

/* Burbuja de la IA (Gris oscuro elegante con texto claro legible) */
.ai-message {
    background-color: #1c212c; 
    color: #e2e8f0;             /* Texto blanco/gris claro de alto contraste */
    margin-right: auto;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Burbuja del Usuario */
.user-message {
    background-color: #007bff;
    color: white;
    margin-left: auto;
}


/* Enlaces dentro de las burbujas */
.ai-message a {
    color: #63b3ed; /* Azul claro brillante para destacar en fondo oscuro */
    text-decoration: underline; 
    font-weight: bold; 
    cursor: pointer;
}

.user-message a {
    color: #fff; 
    text-decoration: underline; 
    font-weight: bold;
    cursor: pointer;
}

.ai-message a:hover, .user-message a:hover {
    opacity: 0.8;
}


/* Área de Input */
#bpro-ai-input-area {
    display: flex;
    align-items: flex-end; 
    padding: 12px 15px;
    background-color: #181b24;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

#bpro-ai-input {
    flex-grow: 1; 
    box-sizing: border-box;
    box-shadow: none; 
    padding: 10px 12px !important; 
    background-color: #111318 !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important; 
    border-radius: 12px !important; 
    margin-right: 10px;
    min-height: 42px !important; 
    max-height: 75px; 
    overflow-y: auto; 
    resize: none; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    font-size: 15px !important; 
    line-height: 1.2 !important;
    color: #f7fafc !important; /* Texto blanco al escribir */
}

#bpro-ai-input:focus {
    border-color: #007bff !important;
    outline: none;
}

#bpro-ai-send-btn {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 18px; 
    border-radius: 20px;
    cursor: pointer;
    font-size: 15px; 
    margin-right: 0;
    align-self: center; 
    height: 42px; 
    font-weight: 600;
    transition: background-color 0.2s;
}

#bpro-ai-send-btn:hover {
    background-color: #0056b3;
}


/* Indicador de Escritura */
.typing-indicator-wrapper {
    padding: 10px 15px;
    margin-bottom: 10px;
    max-width: 65px; 
    word-wrap: break-word;
    line-height: 1.4;
    font-size: 14px;
    border-radius: 16px;
    background-color: #1c212c; 
    margin-right: auto;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.typing-dots {
    display: flex;
    align-items: center;
    justify-content: space-around;
    width: 35px; 
    height: 12px;
}

.dot {
    width: 6px;
    height: 6px;
    background-color: #a0aec0; 
    border-radius: 50%;
    opacity: 0; 
    animation: typing 1.5s infinite ease-in-out;
}

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

@keyframes typing {
    0%, 100% { opacity: 0; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.1); }
}


/* Scrollbars Dark */
#bpro-ai-messages::-webkit-scrollbar { width: 6px; }
#bpro-ai-messages::-webkit-scrollbar-track { background: #111318; border-radius: 8px; }
#bpro-ai-messages::-webkit-scrollbar-thumb { background: #2d3748; border-radius: 8px; }
#bpro-ai-messages::-webkit-scrollbar-thumb:hover { background: #4a5568; }

#bpro-ai-input::-webkit-scrollbar { width: 6px; }
#bpro-ai-input::-webkit-scrollbar-track { background: #111318; border-radius: 8px; }
#bpro-ai-input::-webkit-scrollbar-thumb { background: #2d3748; border-radius: 8px; }


/* Modal de Opciones de Cierre */
#bpro-ai-close-modal {
    position: absolute; 
    bottom: 0; 
    right: 0; /* MODIFICADO: Anclado a la derecha */
    left: auto;
    width: 250px;
    background: #181b24;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
    padding: 15px;
    display: flex;
    flex-direction: column;
    z-index: 30; /* ANTES 10000*/ 
    opacity: 1;
    transition: opacity 0.3s ease;
}

#bpro-ai-close-modal.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
}

#bpro-ai-close-modal .modal-content p {
    margin: 0 0 10px 0;
    color: #e2e8f0;
    font-weight: bold;
    font-size: 14px;
    text-align: left;
}

#bpro-ai-close-modal button {
    padding: 10px;
    margin-bottom: 8px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.2s;
    text-align: left;
    width: 100%; 
}

#modal-option-minimize {
    background-color: #24283b;
    color: #e2e8f0;
}

#modal-option-minimize:hover {
    background-color: #2d3748;
}

#modal-option-end-chat {
    background-color: #dc3545; 
    color: white;
}

#modal-option-end-chat:hover {
    background-color: #c82333;
}

#modal-option-cancel {
    background-color: transparent;
    color: #a0aec0;
    font-weight: bold;
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    margin-top: 5px;
}

#modal-option-cancel:hover {
    background-color: rgba(255, 255, 255, 0.05);
}


/* Animaciones */
@keyframes fadeInUnit {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes bubblePop {
    0% { transform: scale(0.5); opacity: 0; }
    80% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.bubble-pop {
    animation: bubblePop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.27) forwards;
}

#bpro-ai-floating-unit.hidden-bubble {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* =======================================================
   🤖 REGLA DEFINITIVA: OCULTAR ICONO CUANDO EL CHAT ESTÁ ABIERto
   ======================================================= */
#bpro-ai-chat-window:not(.hidden) ~ #bpro-ai-floating-unit {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
}