/* ========================================= */
/*      CHATBOT IA - ESTILOS COMPLETOS      */
/*           Roberto Acuña - CREINTI         */
/* ========================================= */

/* ================================ */
/*   CONTENEDOR PRINCIPAL           */
/* ================================ */

.chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Asegurar que siempre esté dentro del viewport */
@media (max-width: 1024px) {
    .chatbot-widget {
        right: 15px;
        bottom: 15px;
    }
}

/* ================================ */
/*   BOTÓN FLOTANTE DEL CHATBOT     */
/* ================================ */

.chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff6600 0%, #ff8800 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    box-shadow: 0 8px 20px rgba(255, 102, 0, 0.4);
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    animation: slideInUp 0.5s ease-out, pulse 2s infinite 0.5s;
}

/* Texto de respaldo (oculto si Font Awesome carga) */
.chat-button-text {
    display: none;
    font-size: 0.9rem;
    font-weight: bold;
}

/* Si no hay íconos de Font Awesome, mostrar texto */
.chat-button:not(:has(i.fa-solid)) .chat-button-text,
.chat-button i.fa-solid:empty + .chat-button-text {
    display: block;
}

.chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 30px rgba(255, 102, 0, 0.6);
}

.chat-button:active {
    transform: scale(0.95);
}

/* Badge de notificación */
.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #e74c3c;
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: bold;
    border: 2px solid white;
    animation: bounce 2s infinite;
}

/* ================================ */
/*   ANIMACIONES DEL BOTÓN          */
/* ================================ */

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0% {
        box-shadow: 0 8px 20px rgba(255, 102, 0, 0.4);
    }
    50% {
        box-shadow: 0 8px 20px rgba(255, 102, 0, 0.4), 0 0 0 15px rgba(255, 102, 0, 0);
    }
    100% {
        box-shadow: 0 8px 20px rgba(255, 102, 0, 0.4);
    }
}

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

/* ================================ */
/*   TOOLTIP DE AYUDA               */
/* ================================ */

.chat-tooltip {
    position: absolute;
    bottom: 70px;
    right: 70px;
    background: #333;
    color: white;
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 0.9rem;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    animation: tooltipBounce 2s infinite;
    opacity: 1;
    transition: opacity 0.3s;
}

.chat-tooltip.hidden {
    opacity: 0;
    pointer-events: none;
}

.chat-tooltip::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 15px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #333;
}

@keyframes tooltipBounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

/* ================================ */
/*   VENTANA DEL CHAT               */
/* ================================ */

.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 400px;
    height: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(50px) scale(0.9);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.chat-window.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ================================ */
/*   HEADER DEL CHAT                */
/* ================================ */

.chat-header {
    background: linear-gradient(135deg, #ff6600 0%, #ff8800 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    color: #ff6600;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.chat-status {
    display: flex;
    flex-direction: column;
}

.chat-status h3 {
    font-size: 1rem;
    margin: 0;
    font-weight: 600;
}

.chat-status span {
    font-size: 0.8rem;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 5px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #27ae60;
    border-radius: 50%;
    display: inline-block;
    animation: blink 1.5s infinite;
}

@keyframes blink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.3;
    }
}

.chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s;
    flex-shrink: 0;
}

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

/* ================================ */
/*   CUERPO DEL CHAT                */
/* ================================ */

.chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Scrollbar personalizado */
.chat-body::-webkit-scrollbar {
    width: 6px;
}

.chat-body::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-body::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.chat-body::-webkit-scrollbar-thumb:hover {
    background: #999;
}

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

.chat-message {
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.bot {
    align-items: flex-start;
}

.chat-message.user {
    align-items: flex-end;
}

.message-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.4;
    word-wrap: break-word;
}

.chat-message.bot .message-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chat-message.user .message-bubble {
    background: #ff6600;
    color: white;
    border-bottom-right-radius: 4px;
}

.message-time {
    font-size: 0.7rem;
    color: #999;
    margin-top: 4px;
}

/* ================================ */
/*   BOTONES DE RESPUESTA RÁPIDA    */
/* ================================ */

.quick-replies {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.quick-reply-btn {
    background: white;
    border: 2px solid #ff6600;
    color: #ff6600;
    padding: 12px 16px;
    border-radius: 24px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.quick-reply-btn:hover {
    background: #ff6600;
    color: white;
    transform: translateX(5px);
}

.quick-reply-btn:active {
    transform: translateX(3px);
}

.quick-reply-btn i {
    font-size: 1rem;
}

/* ================================ */
/*   INDICADOR DE ESCRITURA         */
/* ================================ */

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 16px;
    width: fit-content;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* ================================ */
/*   FOOTER DEL CHAT                */
/* ================================ */

.chat-footer {
    padding: 15px;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
}

.chat-input {
    flex: 1;
    border: 2px solid #e0e0e0;
    border-radius: 24px;
    padding: 12px 16px;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.3s;
    font-family: inherit;
}

.chat-input:focus {
    border-color: #ff6600;
}

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

.chat-send {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: #ff6600;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.3s;
    flex-shrink: 0;
}

.chat-send:hover {
    background: #ff8800;
    transform: scale(1.05);
}

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

/* ================================ */
/*   RESPONSIVE                     */
/* ================================ */

@media (max-width: 768px) {
    .chatbot-widget {
        bottom: 20px;
        right: 20px;  /* Más separado del borde */
        z-index: 999; /* Alto para superponerse */
    }

    .chat-window {
        width: calc(100vw - 30px);
        height: 85vh;
        bottom: 75px;
        right: 15px;
        left: 15px;
        margin: 0 auto;
        z-index: 10000; /* Solo alto cuando está abierto */
    }

    .chat-button {
        width: 50px; /* Tamaño visible en tablets */
        height: 50px;
        font-size: 1.4rem;
        opacity: 0.95; /* Casi completamente visible */
        transition: all 0.3s ease;
    }

    .chat-button:hover {
        opacity: 1;
    }

    .chat-tooltip {
        display: none !important; /* Ocultar en todos los móviles/tablets */
    }

    .message-bubble {
        max-width: 85%;
    }

    .chat-header {
        padding: 15px;
    }

    .chat-body {
        padding: 15px;
    }

    .chat-footer {
        padding: 12px;
    }

    /* Estado compacto al hacer scroll */
    .chatbot-widget.scrolled .chat-button {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
        opacity: 0.65;
    }
}


@media (max-width: 480px) {
    .chat-window {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 0;
        z-index: 10000; /* Máximo z-index cuando está abierto */
    }

/* Reposicionar el Widget (el contenedor del botón y la ventana) */
    .chat-window.active {
        /*
         * Eliminar la transformación de la animación para asegurar
         * que scale(1) y translateY(0) no interfieran con la posición 
         * 100% de la pantalla. Esto está bien como está, pero la siguiente 
         * regla es clave:
        */
        opacity: 1;
        transform: translateY(0) scale(1);
        pointer-events: all;
    }
    
    /*
     * LA REGLA CLAVE: Cuando el chat está activo, movemos el widget
     * principal a la esquina superior izquierda para que la ventana
     * absoluta cubra todo.
    */
    .chatbot-widget:has(.chat-window.active) {
        bottom: auto; 
        right: auto;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        /* Reducir Z-index para que no tape el botón. 
           (Aunque la ventana sigue teniendo z-index 10000) */
        z-index: 999;
    }

    .chatbot-widget {
        bottom: 20px;
        right: 20px;  /* Más separado del borde para verse completo */
        z-index: 999; /* Alto para superponerse sobre contenido */
    }

    .chat-button {
        width: 50px;  /* Tamaño visible */
        height: 50px;
        font-size: 1.4rem;
        box-shadow: 0 4px 12px rgba(255, 102, 0, 0.3);
        opacity: 0.95; /* Ligeramente transparente pero muy visible */
        transition: all 0.3s ease;
    }

    .chat-button:hover,
    .chat-button:active {
        opacity: 1;
        transform: scale(1.05);
    }

    /* Badge proporcional al botón */
    .chat-badge {
        width: 20px;
        height: 20px;
        font-size: 0.75rem;
        top: -4px;
        right: -4px;
    }

    /* Ocultar tooltip en móviles */
    .chat-tooltip {
        display: none !important;
    }
}

/* Media query adicional para móviles en landscape */
@media (max-width: 768px) and (orientation: landscape) {
    .chatbot-widget {
        bottom: 10px;
        right: 10px;
    }

    .chat-button {
        width: 45px;
        height: 45px;
        font-size: 1.3rem;
    }

    .chat-window {
        width: 400px;
        height: 90vh;
        bottom: 60px;
        right: 10px;
        left: auto;
    }
}

/* ================================ */
/*   ESTADOS Y UTILIDADES           */
/* ================================ */

.hidden {
    display: none !important;
}

.fade-out {
    animation: fadeOut 0.3s ease-out forwards;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Estado compacto en scroll (móviles) - menos agresivo */
@media (max-width: 768px) {
    .chatbot-widget.scrolled .chat-button {
        width: 48px;  /* Solo un poco más pequeño */
        height: 48px;
        font-size: 1.3rem;
        opacity: 0.9;
    }

    .chatbot-widget.scrolled .chat-badge {
        width: 18px;
        height: 18px;
        font-size: 0.7rem;
    }

    /* Al hacer hover, siempre 100% visible */
    .chatbot-widget .chat-button:hover {
        opacity: 1;
        transform: scale(1.05);
    }
}

/* Deshabilitar selección de texto en botones */
.chat-button,
.chat-close,
.chat-send,
.quick-reply-btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ================================ */
/*   ACCESIBILIDAD                  */
/* ================================ */

.chat-button:focus,
.chat-close:focus,
.chat-send:focus,
.quick-reply-btn:focus {
    outline: 2px solid #ff6600;
    outline-offset: 2px;
}

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

/* Para lectores de pantalla */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}