/* ==========================================================================
   UNOMASENLAOFICINA - CHATBOT STYLES UNIFICADO (CORREGIDO MOBILE)
   ========================================================================== */

/* ==========================================================================
   CHATBOT CONTAINER
   ========================================================================== */

.chatbot-container {
    position: fixed;
    bottom: var(--space-5);
    right: var(--space-5);
    z-index: var(--z-chatbot);
    font-family: var(--font-family-primary);
    pointer-events: none;
}

.chatbot-container > * {
    pointer-events: auto;
}

/* ==========================================================================
   CHATBOT TOGGLE BUTTON
   ========================================================================== */

.chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--gradient-primary);
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-primary-lg);
    transition: var(--transition-all);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-white);
    font-size: var(--font-size-2xl);
    position: relative; /* AÑADIDO: Para que funcione como referencia */
    z-index: calc(var(--z-chatbot) + 1); /* AÑADIDO: Asegurar que siempre esté visible */
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-2xl);
}

.chatbot-toggle.active {
    background: var(--color-error);
    box-shadow: var(--shadow-error);
}

.chatbot-icon {
    transition: transform var(--transition-normal);
}

.chatbot-toggle.active .chatbot-icon {
    transform: rotate(135deg);
}

/* ==========================================================================
   CHATBOT WINDOW
   ========================================================================== */

.chatbot-window {
    position: fixed;
    background: var(--color-bg-primary);
    border-radius: var(--border-radius-2xl);
    box-shadow: var(--shadow-2xl);
    overflow: hidden;
    border: 1px solid var(--color-gray-200);
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-all);
    
    /* Dimensiones para escritorio */
    width: 90vw;
    height: 85vh;
    max-width: 800px;
    max-height: 750px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);

    /* Flexbox layout para estructura vertical */
    display: flex;
    flex-direction: column;
}

.chatbot-window.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

/* ==========================================================================
   CHATBOT HEADER
   ========================================================================== */

.chatbot-header {
    background: var(--gradient-primary);
    color: var(--color-text-white);
    padding: var(--space-5) var(--space-6);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

.chatbot-title {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-lg);
}

.chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xl);
    flex-shrink: 0;
    font-weight: var(--font-weight-bold);
}

.chatbot-status {
    font-size: var(--font-size-xs);
    opacity: 0.9;
    margin-top: var(--space-1);
    font-weight: var(--font-weight-normal);
}

.chatbot-close {
    background: none;
    border: none;
    color: var(--color-text-white);
    font-size: var(--font-size-3xl);
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-colors);
    font-weight: var(--font-weight-normal);
}

.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   CHATBOT BODY & MESSAGES
   ========================================================================== */

.chatbot-body {
    flex: 1; 
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-6);
    background: var(--color-bg-secondary);
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: var(--color-gray-100);
    border-radius: var(--border-radius-sm);
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--color-gray-300);
    border-radius: var(--border-radius-sm);
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--color-gray-400);
}

/* ==========================================================================
   MENSAJES
   ========================================================================== */

.message {
    margin-bottom: var(--space-4);
    display: flex;
    max-width: 90%;
}

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

.message.assistant { 
    justify-content: flex-start; 
    margin-right: auto; 
}

.message-content {
    padding: var(--space-3) var(--space-5);
    border-radius: var(--border-radius-2xl);
    font-size: var(--font-size-base);
    line-height: var(--line-height-relaxed);
    word-wrap: break-word;
    max-width: 100%;
}

.message.user .message-content { 
    background: var(--gradient-primary); 
    color: var(--color-text-white); 
    border-bottom-right-radius: var(--border-radius-sm);
}

.message.assistant .message-content { 
    background: var(--color-bg-primary); 
    color: var(--color-text-primary); 
    border: 1px solid var(--color-gray-200); 
    border-bottom-left-radius: var(--border-radius-sm); 
    box-shadow: var(--shadow-sm);
}

.message-time { 
    font-size: var(--font-size-xs); 
    opacity: 0.6; 
    margin-top: var(--space-1);
    font-weight: var(--font-weight-normal);
}

.message.user .message-time { 
    text-align: right; 
}

.message.assistant .message-time { 
    text-align: left; 
}

/* ==========================================================================
   QUICK REPLIES
   ========================================================================== */

.quick-replies { 
    display: flex; 
    flex-wrap: wrap; 
    gap: var(--space-2); 
    margin-top: var(--space-4); 
}

.quick-reply { 
    background: var(--color-bg-muted); 
    border: 1px solid var(--color-gray-300); 
    border-radius: var(--border-radius-xl); 
    padding: var(--space-2) var(--space-4); 
    font-size: var(--font-size-sm); 
    cursor: pointer; 
    transition: var(--transition-colors); 
    color: var(--color-text-secondary);
    font-weight: var(--font-weight-medium);
}

.quick-reply:hover { 
    background: var(--color-primary); 
    color: var(--color-text-white); 
    border-color: var(--color-primary);
    transform: translateY(-1px);
}

/* ==========================================================================
   CHATBOT INPUT
   ========================================================================== */

.chatbot-input-container {
    padding: var(--space-4);
    background: var(--color-bg-primary);
    border-top: 1px solid var(--color-gray-200);
    display: flex;
    gap: var(--space-3);
    align-items: flex-end;
    flex-shrink: 0;
}

.chatbot-input { 
    flex: 1; 
    border: 2px solid var(--color-gray-200); 
    border-radius: var(--border-radius-2xl); 
    padding: var(--space-3) var(--space-4); 
    font-size: var(--font-size-base); 
    resize: none; 
    outline: none; 
    transition: var(--transition-colors); 
    max-height: 120px; 
    min-height: 44px; 
    font-family: var(--font-family-primary);
    line-height: var(--line-height-normal);
}

.chatbot-input:focus { 
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chatbot-input::placeholder {
    color: var(--color-text-muted);
}

.chatbot-send { 
    width: 44px; 
    height: 44px; 
    border-radius: 50%; 
    background: var(--gradient-primary); 
    border: none; 
    color: var(--color-text-white); 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: var(--transition-transform); 
    font-size: var(--font-size-lg); 
    flex-shrink: 0;
    font-weight: var(--font-weight-bold);
}

.chatbot-send:hover { 
    transform: scale(1.05);
    box-shadow: var(--shadow-primary);
}

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

/* ==========================================================================
   TYPING INDICATOR
   ========================================================================== */

.typing-indicator { 
    display: flex; 
    align-items: center; 
    gap: var(--space-2); 
    padding: var(--space-3) var(--space-4); 
    margin-bottom: var(--space-4);
    background: var(--color-bg-primary);
    border-radius: var(--border-radius-2xl);
    border: 1px solid var(--color-gray-200);
    max-width: 120px;
}

.typing-indicator span {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    font-weight: var(--font-weight-medium);
}

.typing-dots { 
    display: flex; 
    gap: var(--space-1); 
}

.typing-dot { 
    width: 6px; 
    height: 6px; 
    border-radius: 50%; 
    background: var(--color-gray-400); 
    animation: typingBounce 1.4s infinite ease-in-out; 
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0; }

@keyframes typingBounce { 
    0%, 80%, 100% { 
        transform: scale(0); 
    } 
    40% { 
        transform: scale(1); 
    } 
}

/* ==========================================================================
   MOBILE RESPONSIVE (CORREGIDO Y SIMPLIFICADO)
   ========================================================================== */

@media (max-width: 768px) {
    /* Ventana que ocupe casi toda la pantalla pero con márgenes seguros */
    .chatbot-window {
        /* Dimensiones ajustadas para móvil */
        width: calc(100vw - 16px);
        max-width: 100vw;
        height: calc(100vh - 120px); /* Dejar espacio para el botón y márgenes */
        max-height: calc(100vh - 120px);
        
        /* Posicionamiento seguro */
        position: fixed;
        top: 8px;
        left: 8px;
        right: 8px;
        bottom: auto;
        transform: scale(0.95);
        
        /* Estados de animación */
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
    }

    .chatbot-window.show {
        transform: scale(1);
        opacity: 1;
        visibility: visible;
    }
    
    /* Ajustar el contenedor para mobile */
    .chatbot-container {
        bottom: var(--space-4);
        right: var(--space-4);
    }
    
    /* Botón más pequeño en mobile */
    .chatbot-toggle {
        width: 55px;
        height: 55px;
        font-size: var(--font-size-xl);
    }
    
    /* Ajustes menores para mobile */
    .chatbot-header {
        padding: var(--space-4) var(--space-5);
    }
    
    .chatbot-title {
        font-size: var(--font-size-base);
    }
    
    .chatbot-avatar {
        width: 35px;
        height: 35px;
        font-size: var(--font-size-lg);
    }
    
    .chatbot-messages {
        padding: var(--space-4);
    }
    
    .message {
        max-width: 95%;
    }
    
    .message-content {
        padding: var(--space-3) var(--space-4);
        font-size: var(--font-size-sm);
    }
    
    .quick-reply {
        padding: var(--space-2) var(--space-3);
        font-size: var(--font-size-xs);
    }
    
    .chatbot-input-container {
        padding: var(--space-3);
    }
    
    .chatbot-input {
        padding: var(--space-3);
        font-size: var(--font-size-sm);
    }
    
    .chatbot-send {
        width: 40px;
        height: 40px;
        font-size: var(--font-size-base);
    }
}

@media (max-width: 480px) {
    .chatbot-window {
        /* En pantallas muy pequeñas, usar casi toda la pantalla */
        width: calc(100vw - 8px);
        height: calc(100vh - 100px);
        max-height: calc(100vh - 100px);
        top: 4px;
        left: 4px;
        right: 4px;
    }
    
    .chatbot-container {
        bottom: var(--space-3);
        right: var(--space-3);
    }
    
    .chatbot-toggle {
        width: 50px;
        height: 50px;
        font-size: var(--font-size-lg);
    }
    
    /* Hacer los mensajes más compactos */
    .chatbot-messages {
        padding: var(--space-3);
    }
    
    .message {
        max-width: 100%;
        margin-bottom: var(--space-3);
    }
    
    .message-content {
        padding: var(--space-2) var(--space-3);
        font-size: var(--font-size-sm);
    }
    
    .quick-replies {
        gap: var(--space-1);
    }
    
    .quick-reply {
        padding: var(--space-1) var(--space-2);
        font-size: var(--font-size-xs);
    }
    
    /* Input más compacto */
    .chatbot-input-container {
        padding: var(--space-2);
    }
    
    .chatbot-input {
        padding: var(--space-2);
        font-size: var(--font-size-sm);
        min-height: 40px;
    }
    
    .chatbot-send {
        width: 40px;
        height: 40px;
        font-size: var(--font-size-base);
    }
    
    /* Header más compacto */
    .chatbot-header {
        padding: var(--space-3) var(--space-4);
    }
    
    .chatbot-avatar {
        width: 30px;
        height: 30px;
        font-size: var(--font-size-base);
    }
    
    .chatbot-title {
        font-size: var(--font-size-sm);
    }
    
    .chatbot-status {
        font-size: 10px;
    }
}

/* ==========================================================================
   ACCESIBILIDAD Y OTROS ESTADOS
   ========================================================================== */

.chatbot-window,
.chatbot-toggle,
.message-content,
.quick-reply,
.chatbot-input {
    font-family: var(--font-family-primary);
}

.chatbot-toggle:focus,
.chatbot-close:focus,
.chatbot-send:focus,
.chatbot-input:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.quick-reply:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

@media (prefers-reduced-motion: reduce) {
    .chatbot-toggle,
    .chatbot-window,
    .message,
    .quick-reply,
    .typing-dot {
        animation: none;
        transition: none;
    }
    
    .chatbot-toggle:hover,
    .chatbot-send:hover {
        transform: none;
    }
}

@media print {
    .chatbot-container {
        display: none !important;
    }
}