/* Contenedor principal del chat */
#ldai-chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Burbuja del chat */
#ldai-chat-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

#ldai-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

#ldai-chat-bubble.chat-open {
    background: #ff6b6b;
    transform: rotate(45deg);
}

#ldai-chat-bubble span {
    position: absolute;
    top: -35px;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

#ldai-chat-bubble:hover span {
    opacity: 1;
}

#ldai-chat-icon {
    font-size: 24px;
    transition: transform 0.3s ease;
}

#ldai-chat-bubble.chat-open #ldai-chat-icon {
    transform: rotate(-45deg);
}

/* Ventana del chat - CORREGIDO */
#ldai-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 500px; /* Altura fija */
    max-height: calc(100vh - 120px); /* Máximo altura de viewport */
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column; /* IMPORTANTE: Flex column */
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header del chat */
#ldai-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    flex-shrink: 0; /* No se encoge */
}

#ldai-chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

#ldai-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Área de mensajes - CORREGIDO */
#ldai-chat-messages {
    flex: 1; /* Ocupa el espacio disponible */
    padding: 15px;
    overflow-y: auto; /* Scroll vertical */
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0; /* Permite que flex funcione correctamente */
}

#ldai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

#ldai-chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

#ldai-chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

#ldai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Mensajes */
.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    word-wrap: break-word;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    align-self: flex-end;
    align-items: flex-end;
}

.ai-message {
    align-self: flex-start;
    align-items: flex-start;
}

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    word-break: break-word;
}

.user-message .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-message .message-content {
    background: white;
    color: #333;
    border: 1px solid #e1e5e9;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    padding: 0 16px;
}

/* Indicador de pensamiento */
.thinking-message .message-content {
    display: flex;
    align-items: center;
    gap: 10px;
    font-style: italic;
    color: #666;
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    background: #667eea;
    border-radius: 50%;
    animation: thinking 1.4s infinite ease-in-out;
}

.thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes thinking {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Área de input - CORREGIDO */
#ldai-chat-input {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e1e5e9;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-shrink: 0; /* No se encoge NUNCA */
    position: relative; /* Asegurar posicionamiento */
    z-index: 10; /* Por encima de mensajes */
}

#ldai-message-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 25px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s ease;
    resize: none; /* Prevenir resize */
}

#ldai-message-input:focus {
    border-color: #667eea;
}

#ldai-send-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    flex-shrink: 0; /* No se encoge */
}

#ldai-send-button:hover {
    transform: scale(1.1);
}

#ldai-send-button:active {
    transform: scale(0.95);
}

#ldai-send-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Botones de acción */
.ldai-action-button {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
    margin-top: 8px;
}

.ldai-action-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(79, 172, 254, 0.3);
}

/* Formulario de reset de contraseña */
.reset-form {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
}

.reset-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #333;
    font-size: 13px;
}

.reset-form input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 10px;
    font-size: 13px;
    box-sizing: border-box;
}

.reset-form button {
    background: #28a745;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    width: 100%;
}

.reset-form button:hover {
    background: #218838;
}

/* Responsividad - MEJORADO */
@media (max-width: 480px) {
    #ldai-chat-window {
        width: calc(100vw - 40px);
        height: calc(100vh - 120px);
        bottom: 80px;
        right: 20px;
        left: 20px;
        max-height: calc(100vh - 120px);
    }
    
    #ldai-chat-container {
        right: 20px;
        bottom: 20px;
    }
    
    #ldai-chat-messages {
        padding: 12px;
    }
    
    #ldai-chat-input {
        padding: 12px 15px;
    }
    
    .message {
        max-width: 90%;
    }
}

@media (max-width: 380px) {
    #ldai-chat-messages {
        padding: 10px;
        gap: 10px;
    }
    
    #ldai-chat-input {
        padding: 10px 12px;
        gap: 8px;
    }
    
    .message {
        max-width: 95%;
    }
    
    .message-content {
        padding: 10px 12px;
        font-size: 13px;
    }
}

/* Estados adicionales */
.message.error .message-content {
    background: #ff6b6b;
    color: white;
}

.message.success .message-content {
    background: #51cf66;
    color: white;
}

.message.warning .message-content {
    background: #ffd43b;
    color: #333;
}

/* Efectos hover mejorados */
.message-content:hover {
    transform: translateY(-1px);
    transition: transform 0.2s ease;
}

/* Auto-scroll helper */
.ldai-scroll-to-bottom {
    scroll-behavior: smooth;
}

/* Estados de carga */
.ldai-chat-loading {
    opacity: 0.7;
    pointer-events: none;
}

.ldai-chat-loading #ldai-send-button {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Mejoras visuales adicionales */
#ldai-chat-window.focused {
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.2);
}

/* Badge de notificación */
#ldai-chat-bubble::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background: #ff4757;
    border-radius: 50%;
    border: 2px solid white;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s ease;
}

#ldai-chat-bubble.has-notification::after {
    opacity: 1;
    transform: scale(1);
}

/* CORRECCIÓN ESPECÍFICA PARA EL PROBLEMA DE SCROLL */
#ldai-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 500px !important; /* Forzar altura */
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

#ldai-chat-messages {
    flex: 1 1 auto !important; /* Flex grow y shrink */
    padding: 15px;
    overflow-y: scroll !important; /* Forzar scroll */
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 0; /* Importante para flex */
    max-height: 350px; /* Altura máxima específica */
}

#ldai-chat-input {
    flex: 0 0 auto !important; /* No crece ni se encoge */
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e1e5e9;
    display: flex;
    gap: 10px;
    align-items: center;
    height: 70px; /* Altura fija */
    box-sizing: border-box;
}

/* Forzar scroll visible */
#ldai-chat-messages::-webkit-scrollbar {
    width: 8px !important;
    display: block !important;
}

#ldai-chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1 !important;
    border-radius: 4px;
}

#ldai-chat-messages::-webkit-scrollbar-thumb {
    background: #888 !important;
    border-radius: 4px;
}

#ldai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #555 !important;
}