/* =========================================
   ESTILOS DEL CHATBOT JPG (PREMIUM v3.1 - FIXED)
   Estilo WhatsApp + Identidad Visual JPG
========================================= */

/* --- VARIABLES MAESTRAS --- */
:root {
    --jpg-yellow: #fdb913;    /* Amarillo Corporativo */
    --jpg-black: #111111;     /* Negro Corporativo */
    --jpg-white: #ffffff;
    --jpg-bg: #e5ddd5;        /* Fondo estilo WhatsApp */
    --shadow-float: 0 4px 25px rgba(0,0,0,0.15);
    --font-chat: 'Inter', sans-serif;
    --font-header: 'Syne', sans-serif;
}

/* --- CONTENEDOR FLOTANTE --- */
#chatbot-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 9999;
    font-family: var(--font-chat);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 15px;
    pointer-events: none; /* Permite clicks detrás si está invisible */
}

/* Habilitar clicks en hijos */
#chatbot-container > * {
    pointer-events: auto;
}

/* --- GLOBO DE VISTA PREVIA (NOTIFICACIÓN) --- */
.chat-preview-bubble {
    background: white;
    padding: 14px 20px;
    border-radius: 20px 20px 5px 20px; /* Forma de burbuja de cómic */
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
    max-width: 260px;
    font-size: 0.95rem;
    color: #333;
    font-weight: 500;
    opacity: 0;
    transform: translateY(20px) scale(0.9);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid rgba(0,0,0,0.05);
    position: relative;
    margin-bottom: 10px;
}

.chat-preview-bubble.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Flechita del globo */
.chat-preview-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 20px;
    width: 0; 
    height: 0; 
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid white;
}

/* --- BOTÓN TRIGGER (FLOTANTE) --- */
.chat-trigger {
    width: 65px;
    height: 65px;
    background-color: var(--jpg-black);
    color: var(--jpg-yellow);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: var(--shadow-float);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    border: 2px solid rgba(255,255,255,0.1);
    z-index: 10000;
}

.chat-trigger:hover {
    transform: scale(1.1) rotate(-5deg);
    background-color: var(--jpg-yellow);
    color: var(--jpg-black);
    box-shadow: 0 8px 30px rgba(253, 185, 19, 0.4);
}

.chat-trigger i {
    font-size: 28px;
}

/* Badge de Notificación (Rojo) */
.notification-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ff3b30;
    color: white;
    font-size: 0.75rem;
    font-weight: 800;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    transform: scale(0);
    transition: transform 0.3s ease;
    z-index: 10;
}

.notification-badge.active {
    transform: scale(1);
}

/* --- VENTANA DEL CHAT (MAIN WINDOW) --- */
.chat-window {
    width: 380px;
    height: 600px;
    max-height: 75vh; /* Ajustado para evitar desborde */
    background: #f2f2f2;
    border-radius: 24px;
    box-shadow: var(--shadow-float);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(0);
    opacity: 0;
    transition: all 0.35s cubic-bezier(0.19, 1, 0.22, 1);
    position: absolute;
    bottom: 85px;
    right: 0;
}

.chat-window.active {
    transform: scale(1);
    opacity: 1;
}

/* HEADER */
.chat-header {
    flex-shrink: 0; /* No encoger */
    background: var(--jpg-black);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    z-index: 2;
}

.chat-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 42px;
    height: 42px;
    background: var(--jpg-yellow);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--jpg-black);
    font-size: 1.2rem;
    border: 2px solid rgba(255,255,255,0.1);
}

.chat-info h3 {
    margin: 0;
    font-size: 1rem;
    font-family: var(--font-header);
    font-weight: 700;
    letter-spacing: 0.5px;
}

.chat-status {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #25D366; /* Verde Online */
    border-radius: 50%;
    box-shadow: 0 0 5px rgba(37, 211, 102, 0.6);
}

/* BODY (MENSAJES) - CORREGIDO */
.chat-body {
    flex: 1; /* Ocupa el espacio central */
    padding: 20px;
    overflow-y: auto; /* Scroll vertical */
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: #efe7dd;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%239C92AC' fill-opacity='0.05' fill-rule='evenodd'/%3E%3C/svg%3E");
    scroll-behavior: smooth;
    min-height: 0; /* Crucial para Firefox */
}

/* MENSAJES */
.msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    word-wrap: break-word;
}

.bot-msg {
    background: white;
    color: #111;
    align-self: flex-start;
    border-top-left-radius: 0; /* Pico izq */
}

.user-msg {
    background: var(--jpg-yellow);
    color: black;
    align-self: flex-end;
    border-top-right-radius: 0; /* Pico der */
}

/* Metadata del mensaje (Hora y Checks) */
.msg-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    font-size: 0.65rem;
    opacity: 0.6;
}

.double-check {
    color: #53bdeb; /* Azul WhatsApp */
    font-size: 0.7rem;
}

/* OPCIONES (BOTONES) */
.options-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 5px;
}

.option-btn {
    background: white;
    border: 1px solid #ddd;
    color: var(--jpg-black);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.option-btn:hover {
    background: var(--jpg-yellow);
    border-color: var(--jpg-yellow);
    color: black;
    transform: translateY(-2px);
}

/* --- SUGERENCIAS (CHIPS) - CORREGIDO --- */
.suggestion-area {
    flex-shrink: 0; /* IMPORTANTE: No dejar que se encoja */
    background: #f0f0f0;
    padding: 10px 15px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    white-space: nowrap;
    border-top: 1px solid rgba(0,0,0,0.05);
    z-index: 10;
    
    /* Scrollbar visible y estilizado */
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}

.suggestion-area::-webkit-scrollbar {
    height: 5px;
}
.suggestion-area::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 10px;
}
.suggestion-area::-webkit-scrollbar-thumb:hover {
    background: var(--jpg-yellow);
}

.chip {
    background: white;
    border: 1px solid #ddd;
    padding: 6px 14px;
    border-radius: 16px;
    font-size: 0.8rem;
    color: #555;
    cursor: pointer;
    transition: 0.2s;
    flex-shrink: 0; /* Evita que se aplasten */
    user-select: none;
}

.chip:hover {
    background: var(--jpg-black);
    color: var(--jpg-yellow);
    border-color: var(--jpg-black);
}

/* --- FOOTER (INPUT) - CORREGIDO --- */
.chat-footer {
    flex-shrink: 0; /* No desaparecer */
    padding: 10px 15px;
    background: #ffffff;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 60px;
    border-top: 1px solid #ddd;
    position: relative;
    z-index: 20; /* Encima de todo */
}

.chat-input {
    flex: 1;
    border: 1px solid #ddd;
    background: white;
    padding: 12px 18px;
    border-radius: 24px;
    font-family: var(--font-chat);
    font-size: 0.95rem;
    outline: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    color: #333;
    pointer-events: auto; /* Habilitar click explícitamente */
}

.chat-input::placeholder { color: #aaa; }

.btn-send {
    background: var(--jpg-black);
    color: white;
    width: 45px;
    height: 45px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.btn-send:hover {
    background: var(--jpg-yellow);
    color: black;
    transform: scale(1.1);
}

/* --- ANIMACIONES --- */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeInUp 0.3s ease-out; }

/* Typing Indicator (Puntos) */
.typing-indicator {
    background: white;
    padding: 10px 15px;
    border-radius: 12px;
    border-top-left-radius: 0;
    width: fit-content;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.typing-indicator span {
    width: 6px; height: 6px;
    background: #bbb;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* RESPONSIVE MÓVIL - CORREGIDO */
@media (max-width: 480px) {
    #chatbot-container {
        bottom: 0; right: 0; 
        padding: 0; margin: 0;
        width: 100%; height: 100%; 
        pointer-events: none;
        z-index: 9999;
    }

    /* Botón flotante siempre visible */
    .chat-trigger {
        position: fixed;
        bottom: 20px;
        right: 20px;
        pointer-events: auto;
    }
    
    /* Ventana full screen en móvil */
    .chat-window {
        width: 100%;
        height: 100%;
        max-height: 100%;
        bottom: 0; right: 0;
        border-radius: 0;
        pointer-events: auto;
        display: flex;
        flex-direction: column;
    }

    /* Asegurar que el cuerpo no se coma el footer */
    .chat-body {
        flex: 1;
        height: auto; 
    }
    
    .chat-preview-bubble {
        position: fixed;
        bottom: 95px;
        right: 20px;
        pointer-events: none; /* No bloquear clicks si no se ve */
    }
    .chat-preview-bubble.visible {
        pointer-events: auto;
    }
}