/* ==========================================================================
   WIDGET DE CHAT FLOTANTE PREMIUM (Estilo Glassmorphism y Colores Agave)
   ========================================================================== */

#nopal-ai-chat-wrapper {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 99999;
    font-family: 'Plus Jakarta Sans', sans-serif;
}

/* 1. Botón Lanzador / Burbuja Flotante */
#nopal-ai-chat-launcher {
    background: linear-gradient(135deg, #064e3b 0%, #0f766e 100%);
    color: #ffffff;
    border: none;
    padding: 12px 22px;
    border-radius: 30px;
    box-shadow: 0 10px 25px -5px rgba(6, 78, 59, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#nopal-ai-chat-launcher:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 15px 30px -5px rgba(6, 78, 59, 0.6);
}

#nopal-ai-chat-launcher .chat-icon {
    font-size: 1.2rem;
    display: inline-block;
    animation: pulseChatIcon 2s infinite;
}

@keyframes pulseChatIcon {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* 2. Ventana de Chat */
#nopal-ai-chat-window {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 380px;
    height: 520px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 20px;
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Clases de Estado */
.chat-closed {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.6) translateY(40px);
}

.chat-opened {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1) translateY(0);
}

/* Cabecera */
.chat-header {
    background: linear-gradient(135deg, #064e3b 0%, #0f766e 100%);
    color: #ffffff;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

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

.chat-avatar {
    font-size: 1.6rem;
    background: rgba(255, 255, 255, 0.2);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.chat-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #ffffff;
    font-family: 'Outfit', sans-serif;
}

.chat-status {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background-color: #22c55e;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 8px #22c55e;
    animation: statusBlink 1.5s infinite;
}

@keyframes statusBlink {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

#nopal-ai-chat-close {
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}

#nopal-ai-chat-close:hover {
    opacity: 1;
}

/* Cuerpo / Historial de Mensajes */
.chat-body {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: rgba(250, 249, 246, 0.6);
}

/* Burbujas de Mensaje */
.chat-message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.88rem;
    line-height: 1.45;
    animation: bubbleEntrance 0.3s cubic-bezier(0.1, 0.8, 0.2, 1);
}

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

.msg-ai {
    align-self: flex-start;
    background-color: #ffffff;
    color: #1c1917;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #064e3b 0%, #0f766e 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(6, 78, 59, 0.15);
}

/* Burbuja de Carga (Escritura) */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 12px 18px;
    background-color: #ffffff;
    align-self: flex-start;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: #a8a29e;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

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

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

/* Footer */
.chat-footer {
    padding: 15px 20px;
    background: #ffffff;
    border-top: 1px solid #e7e5e4;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#nopal-ai-chat-form {
    display: flex;
    gap: 10px;
}

#nopal-ai-chat-input {
    flex-grow: 1;
    padding: 10px 16px;
    border: 1px solid #d6d3d1;
    border-radius: 20px;
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    transition: all 0.3s;
}

#nopal-ai-chat-input:focus {
    border-color: #0f766e;
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

#nopal-ai-chat-send {
    background: #0f766e;
    color: #ffffff;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

#nopal-ai-chat-send:hover {
    background: #d97706;
    transform: scale(1.05);
}

/* WhatsApp Link */
.chat-whatsapp-prompt {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #f0fdf4;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid #bbf7d0;
    font-size: 0.78rem;
}

.chat-whatsapp-prompt span {
    color: #166534;
    font-weight: 500;
}

.chat-wa-link {
    color: #ffffff;
    background-color: #22c55e;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    text-decoration: none;
    box-shadow: 0 2px 4px rgba(34, 197, 94, 0.2);
}

.chat-wa-link:hover {
    background-color: #16a34a;
    color: #ffffff;
}

.chat-body::-webkit-scrollbar {
    width: 6px;
}
.chat-body::-webkit-scrollbar-track {
    background: transparent;
}
.chat-body::-webkit-scrollbar-thumb {
    background-color: #d6d3d1;
    border-radius: 3px;
}

@media (max-width: 480px) {
    #nopal-ai-chat-wrapper {
        bottom: 20px;
        right: 20px;
        left: 20px;
    }
    #nopal-ai-chat-window {
        width: 100%;
        height: 480px;
    }
}
