/* ==================== AI CHATBOT STYLES ==================== */

.ai-chatbot-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary, #ffffff);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    /* Usar max-height en lugar de height para permitir que el contenido se ajuste */
    max-height: 100vh;
    overflow: hidden;
}

.ai-chatbot-container.hidden {
    transform: translateY(100%);
    pointer-events: none;
    visibility: hidden;
}

.ai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    padding-top: 80px; /* Space for header */
    padding-bottom: 1rem; /* Espacio adicional para el último mensaje */
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: var(--bg-primary, #ffffff);
    /* Permitir scroll suave cuando aparece el teclado */
    -webkit-overflow-scrolling: touch;
    min-height: 0; /* Importante para que flex funcione correctamente */
    /* Asegurar que el contenedor de mensajes no empuje el input fuera de la pantalla */
    flex-shrink: 1;
}

.ai-message,
.user-message {
    display: flex;
    gap: 0.75rem;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    justify-content: flex-end;
}

.ai-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ai-message-content,
.user-message-content {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    line-height: 1.5;
}

.ai-message-content {
    background: var(--bg-secondary, #f5f5f5);
    color: var(--text-primary, #333);
    border-bottom-left-radius: 0.25rem;
}

.user-message-content {
    background: linear-gradient(135deg, #FF8000 0%, #FF6B00 100%);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.ai-message-content p,
.user-message-content p {
    margin: 0;
    font-size: 0.95rem;
    white-space: pre-line;
}

.ai-message-hint {
    margin-top: 0.5rem !important;
    font-size: 0.85rem !important;
    opacity: 0.8;
}

.ai-message-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.ai-action-btn {
    background: linear-gradient(135deg, #FF8000 0%, #FF6B00 100%);
    color: white;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-size: 0.9rem;
    text-align: left;
}

.ai-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 128, 0, 0.3);
}

.ai-action-btn:active {
    transform: translateY(0);
}

.ai-chatbot-input-container {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--bg-secondary, #f5f5f5);
    border-top: 1px solid var(--border-color, #e0e0e0);
    /* Mantener el input container en la parte inferior */
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.ai-chatbot-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 2rem;
    font-size: 0.95rem;
    background: var(--bg-primary, #ffffff);
    color: var(--text-primary, #333);
}

.ai-chatbot-input:focus {
    outline: none;
    border-color: #FF8000;
}

.ai-chatbot-send {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FF8000 0%, #FF6B00 100%);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

.ai-chatbot-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(255, 128, 0, 0.3);
}

.ai-chatbot-send:active {
    transform: scale(0.95);
}

/* Floating Bubble - Messenger Style */
.ai-chatbot-bubble {
    position: fixed;
    right: 20px;
    bottom: 80px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FF8000 0%, #FF6B00 100%);
    box-shadow: 0 4px 16px rgba(255, 128, 0, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
}

.ai-chatbot-bubble.hidden {
    display: none;
}

.ai-chatbot-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(255, 128, 0, 0.5);
}

.ai-chatbot-bubble:active {
    transform: scale(0.95);
}

.ai-bubble-icon {
    color: white;
    pointer-events: none;
}

.ai-bubble-close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 26px;
    height: 26px;
    min-width: 26px;
    min-height: 26px;
    border-radius: 50%;
    background: #dc3545;
    border: 2px solid white;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    padding: 0;
    z-index: 1;
}

.ai-bubble-close svg {
    width: 12px;
    height: 12px;
}

.ai-bubble-close:hover {
    transform: scale(1.15);
    background: #c82333;
}

.ai-bubble-close:active {
    transform: scale(0.95);
}

/* Dark Mode Support */
body.dark-mode .ai-message-content {
    background: var(--bg-tertiary, #2a2a2a);
    color: var(--text-primary, #f5f5f5);
}

body.dark-mode .ai-chatbot-input {
    background: var(--input-bg, #2a2a2a);
    color: var(--text-primary, #f5f5f5);
    border-color: var(--border-color, #4a4a4a);
}

body.dark-mode .ai-chatbot-messages {
    background: var(--bg-primary, #121212);
}

body.dark-mode .ai-message-avatar {
    background: var(--bg-tertiary, #2a2a2a);
}

/* Desktop Styles */
@media (min-width: 768px) {
    .ai-chatbot-container {
        top: 50%;
        left: 50%;
        right: auto;
        bottom: auto;
        transform: translate(-50%, -50%);
        width: 420px;
        height: 650px;
        border-radius: 1rem;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    }
    
    .ai-chatbot-container.hidden {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0;
    }
    
    .ai-chatbot-bubble {
        width: 64px;
        height: 64px;
    }
}

/* Smooth scrolling for messages */
.ai-chatbot-messages {
    scroll-behavior: smooth;
}

/* Loading animation for bot responses */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.ai-message.loading .ai-message-content::after {
    content: '...';
    animation: pulse 1.5s ease-in-out infinite;
}
