/* --- Contenedor Principal --- */
#chatbot-container {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 1000;
    pointer-events: none; /* Permite que los clics pasen a través del contenedor */
}

/* --- Ventana del Chat --- */
.chatbot-window {
    position: fixed;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    /* CAMBIO: Fondo gris con transparencia aún más ligera (ajustado a 0.3 para mayor visibilidad detrás) */
    background-color: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    bottom: 25px;
    right: 25px;
    width: 60px;
    height: 60px;
    border-radius: 30px;
    opacity: 0;
    transform: scale(0.2);
    transform-origin: bottom right;
    visibility: hidden;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: auto; /* Restaura los clics para la ventana */
    border: 1px solid rgba(224, 224, 224, 0.6);
}

.chatbot-window.open {
    bottom: 25px;
    right: 25px;
    width: 380px;
    max-width: calc(100vw - 50px);
    height: 600px;
    max-height: calc(100vh - 50px);
    border-radius: 15px;
    opacity: 1;
    transform: scale(1);
    visibility: visible;
}

.chatbot-window .chatbot-header,
.chatbot-window .chatbot-body,
.chatbot-window .chatbot-footer {
    opacity: 0;
    transition: opacity 0.1s ease-out;
}

.chatbot-window.open .chatbot-header,
.chatbot-window.open .chatbot-body,
.chatbot-window.open .chatbot-footer {
    opacity: 1;
    transition: opacity 0.2s ease-in 0.2s;
}

/* --- Botón Flotante (FAB) --- */
.chatbot-fab {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: transform 0.3s ease;
    z-index: 1001;
    pointer-events: auto; /* Asegura que el botón sea clickeable */
}

.chatbot-fab:hover { 
    transform: scale(1.1); 
}

.chatbot-fab:active {
    transform: scale(0.95);
}

/* SOLUCIÓN CLAVE: Ocultar completamente el FAB */
.chatbot-fab.hidden { 
    display: none !important;
}

/* --- Encabezado del Chat --- */
.chatbot-header { 
    background: linear-gradient(135deg, rgba(0, 123, 255, 0.7), rgba(0, 86, 179, 0.7)) !important; 
    color: white; 
    padding: 15px 20px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    flex-shrink: 0;
    border-radius: 15px 15px 0 0;
    /* NUEVO: Efecto de cristal esmerilado más fuerte */
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chatbot-header-title { 
    font-weight: 600; 
    font-size: 1.1rem;
    margin: 0;
}

.chatbot-close-btn { 
    background: none; 
    border: none; 
    color: white; 
    font-size: 1.2rem; 
    cursor: pointer; 
    opacity: 0.8; 
    transition: opacity 0.2s;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.chatbot-close-btn:hover { 
    opacity: 1;
    background-color: rgba(255, 255, 255, 0.1);
}

/* --- Cuerpo del Chat (Mensajes) --- */
.chatbot-body { 
    overflow-y: auto; 
    scroll-behavior: smooth; 
    flex: 1; 
    position: relative; 
    padding: 20px 15px;
    /* CAMBIO: Fondo blanco con transparencia aún más ligera (ajustado a 0.2) */
    background-color: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.chatbot-body::-webkit-scrollbar { 
    width: 8px; 
}

.chatbot-body::-webkit-scrollbar-track { 
    background: rgba(241, 241, 241, 0.5); 
}

.chatbot-body::-webkit-scrollbar-thumb { 
    background: rgba(193, 193, 193, 0.7); 
    border-radius: 4px; 
}

.chatbot-body::-webkit-scrollbar-thumb:hover { 
    background: rgba(168, 168, 168, 0.8); 
}

/* --- Pie del Chat (Input) --- */
.chatbot-footer { 
    display: flex; 
    padding: 15px; 
    border-top: 1px solid rgba(224, 224, 224, 0.7); 
    /* CAMBIO: Fondo blanco con transparencia aún más ligera (ajustado a 0.3) */
    background-color: rgba(255, 255, 255, 0.3); 
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    flex-shrink: 0;
    border-radius: 0 0 15px 15px;
    gap: 10px;
}

.chatbot-input { 
    flex-grow: 1; 
    border: 1px solid rgba(220, 220, 220, 0.8); 
    border-radius: 25px; 
    padding: 12px 16px; 
    outline: none; 
    transition: border-color 0.2s, box-shadow 0.2s;
    font-size: 14px;
    resize: none;
    font-family: inherit;
    /* CAMBIO: Input blanco con transparencia aún más ligera (ajustado a 0.3) */
    background-color: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.chatbot-input:focus { 
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
    background-color: rgba(255, 255, 255, 0.5);
}

.chatbot-input::placeholder {
    color: #999;
}

.chatbot-send-btn { 
    width: 44px; 
    height: 44px; 
    background-color: #007bff; 
    color: white; 
    border: none; 
    border-radius: 50%; 
    cursor: pointer; 
    font-size: 16px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: all 0.2s; 
    flex-shrink: 0;
}

.chatbot-send-btn:hover { 
    background-color: #0056b3;
    transform: scale(1.05);
}

.chatbot-send-btn:active {
    transform: scale(0.95);
}

.chatbot-send-btn:disabled { 
    opacity: 0.6; 
    cursor: not-allowed;
    transform: none;
}

/* --- Mensajes --- */
.chat-message { 
    display: flex; 
    margin: 15px 0; 
    max-width: 85%; 
    animation: messageSlideInFast 0.3s ease-out; 
    position: relative;
}

.message-content { 
    padding: 12px 16px; 
    border-radius: 18px; 
    line-height: 1.5; 
    word-wrap: break-word;
    font-size: 14px;
    position: relative;
}

.message-content a { 
    color: #0056b3; 
    text-decoration: underline; 
    font-weight: 600; 
}

.bot-message { 
    justify-content: flex-start; 
    padding-right: 40px;
}

.bot-message .message-content { 
    /* CAMBIO: Burbujas de mensajes con transparencia aún más ligera (ajustado a 0.5) */
    background-color: rgba(241, 243, 245, 0.5); 
    color: #333; 
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(233, 236, 239, 0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.user-message { 
    justify-content: flex-end; 
    margin-left: auto; 
}

.user-message .message-content { 
    background: linear-gradient(135deg, rgba(0, 123, 255, 0.5), rgba(0, 86, 179, 0.5));
    color: white; 
    border-bottom-right-radius: 4px;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

/* --- Botón de Copiar --- */
.copy-btn { 
    position: absolute; 
    bottom: 8px; 
    right: -35px; 
    background: rgba(255, 255, 255, 0.95); 
    border: 1px solid rgba(221, 221, 221, 0.7); 
    color: #666; 
    border-radius: 50%; 
    width: 30px; 
    height: 30px; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-size: 12px; 
    opacity: 0; 
    transition: all 0.2s; 
    visibility: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.bot-message:hover .copy-btn { 
    opacity: 1; 
    visibility: visible; 
}

.copy-btn:hover { 
    background-color: rgba(248, 249, 250, 0.95);
    color: #007bff;
    transform: scale(1.1);
}

.copy-btn:active {
    transform: scale(0.95);
}

.copy-btn.copied { 
    background-color: rgba(40, 167, 69, 0.9); 
    color: white;
    border-color: rgba(40, 167, 69, 0.7);
}

/* --- Indicador de Escritura --- */
.typing-dots { 
    display: inline-flex; 
    align-items: center; 
    gap: 4px; 
    padding: 8px 12px; 
}

.typing-dots span { 
    width: 8px; 
    height: 8px; 
    border-radius: 50%; 
    background-color: #007bff; 
    animation: typing-bounce-fast 1.4s infinite ease-in-out both; 
}

.typing-dots span:nth-child(1) { 
    animation-delay: -0.32s; 
}

.typing-dots span:nth-child(2) { 
    animation-delay: -0.16s; 
}

.typing-dots span:nth-child(3) { 
    animation-delay: 0s; 
}

@keyframes typing-bounce-fast { 
    0%, 80%, 100% { 
        transform: scale(0.6); 
        opacity: 0.4; 
    } 
    40% { 
        transform: scale(1); 
        opacity: 1; 
    } 
}

.chat-message.typing .message-content { 
    background-color: rgba(248, 249, 250, 0.5) !important; 
    min-height: 40px; 
    display: flex; 
    align-items: center;
    border: 1px solid rgba(233, 236, 239, 0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

/* --- Estilos de Contenido Formateado --- */
.message-content .info-item,
.message-content .list-item,
.message-content p {
    margin-bottom: 8px;
    line-height: 1.6;
}

.message-content > *:last-child {
    margin-bottom: 0;
}

.message-content .info-item strong {
    font-weight: 600;
    color: #2c3e50;
}

.message-content .list-item {
    padding-left: 20px;
    position: relative;
    margin-bottom: 6px;
}

.message-content .list-item::before {
    content: '•';
    position: absolute;
    left: 8px;
    top: 0;
    color: #007bff;
    font-weight: bold;
    font-size: 16px;
}

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

@keyframes chatWindowAppear {
    from {
        opacity: 0;
        transform: scale(0.3);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.chatbot-window.open {
    animation: chatWindowAppear 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* --- Notificación de Mensajes No Leídos --- */
#chatbot-container.new-message::after { 
    content: attr(data-unread-count); 
    position: absolute; 
    top: -8px; 
    right: -8px; 
    background: linear-gradient(135deg, #dc3545, #c82333);
    color: white; 
    border-radius: 50%; 
    width: 24px; 
    height: 24px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-size: 11px; 
    font-weight: bold; 
    z-index: 1002;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    animation: pulse-notification 2s infinite;
}

@keyframes pulse-notification {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* --- Responsive Design --- */
@media (max-width: 768px) { 
    #chatbot-container { 
        bottom: 20px; 
        right: 20px; 
    } 
    
    .chatbot-window {
        bottom: 20px;
        right: 20px;
    }
    
    .chatbot-window.open {
        bottom: 20px;
        right: 20px;
        width: calc(100vw - 40px);
        height: calc(62.5vh - 20px); /* CAMBIO: 50% + 25% adicional = 62.5% de la altura de la ventana */
        max-width: none;
        max-height: none;
    }
    
    .chatbot-fab {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        font-size: 24px;
    }
    
    .chatbot-header {
        padding: 12px 16px;
    }
    
    .chatbot-body {
        padding: 16px 12px;
    }
    
    .chatbot-footer {
        padding: 12px;
    }
    
    .chat-message {
        max-width: 90%;
        margin: 12px 0;
    }
    
    .bot-message { 
        padding-right: 8px; 
    } 
    
    .copy-btn { 
        display: none !important; 
    }
    
    .message-content {
        font-size: 14px;
        padding: 10px 14px;
    }
}

@media (max-width: 480px) {
    .chatbot-window.open {
        width: calc(100vw - 20px);
        height: calc(62.5vh - 10px); /* CAMBIO: 50% + 25% adicional = 62.5% de la altura de la ventana */
        bottom: 10px;
        right: 10px;
        border-radius: 12px;
    }
    
    .chatbot-fab {
        bottom: 15px;
        right: 15px;
        width: 52px;
        height: 52px;
        font-size: 22px;
    }
    
    #chatbot-container {
        bottom: 15px;
        right: 15px;
    }
    
    .chatbot-window {
        bottom: 15px;
        right: 15px;
    }
}

/* --- Estados de Carga y Error --- */
.chatbot-loading {
    pointer-events: none;
    opacity: 0.7;
}

.chatbot-error {
    border-color: #dc3545 !important;
}

.error-message .message-content {
    background-color: rgba(248, 215, 218, 0.5) !important;
    color: #721c24 !important;
    border-color: rgba(245, 198, 203, 0.7) !important;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

/* --- Accesibilidad --- */
.chatbot-fab:focus,
.chatbot-close-btn:focus,
.chatbot-send-btn:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

.chatbot-input:focus {
    outline: none;
}

/* --- Modo Oscuro (Opcional) --- */
@media (prefers-color-scheme: dark) {
    .chatbot-window {
        background-color: rgba(45, 55, 72, 0.65);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
        border-color: rgba(74, 85, 104, 0.3);
    }
    
    .chatbot-body {
        background-color: rgba(45, 55, 72, 0.5);
    }
    
    .chatbot-footer {
        background-color: rgba(45, 55, 72, 0.6);
        border-top-color: rgba(74, 85, 104, 0.5);
    }
    
    .chatbot-input {
        background-color: rgba(74, 85, 104, 0.5);
        border-color: rgba(74, 85, 104, 0.7);
        color: white;
    }
    
    .chatbot-input:focus {
        background-color: rgba(74, 85, 104, 0.6);
    }
    
    .chatbot-input::placeholder {
        color: #a0aec0;
    }
    
    .bot-message .message-content {
        background-color: rgba(74, 85, 104, 0.5);
        color: #e2e8f0;
        border-color: rgba(74, 85, 104, 0.7);
    }
    
    .chat-message.typing .message-content {
        background-color: rgba(74, 85, 104, 0.5) !important;
        border-color: rgba(74, 85, 104, 0.7) !important;
    }
    
    .copy-btn {
        background: rgba(74, 85, 104, 0.95);
        border-color: rgba(74, 85, 104, 0.7);
        color: #e2e8f0;
    }
    
    .copy-btn:hover {
        background-color: rgba(74, 85, 104, 1);
    }
}
