/* ============================================================
   Chatbot Widget
   ============================================================ */

#chatbot-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 58px;
    height: 58px;
    background: #2563eb;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(37,99,235,.45);
    z-index: 999998;
    transition: transform .2s, background .2s;
}
#chatbot-toggle:hover { background: #1d4ed8; transform: scale(1.08); }

/* Ventana del chat */
#chatbot-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 360px;
    height: 500px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
    display: none;
    flex-direction: column;
    z-index: 999999;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
}
#chatbot-window.open { display: flex; }

/* Cabecera */
#chatbot-header {
    background: #2563eb;
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 15px;
    flex-shrink: 0;
}
#chatbot-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    opacity: .8;
}
#chatbot-close:hover { opacity: 1; }

/* Área de mensajes */
#chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8fafc;
}

/* Burbuja genérica */
.chatbot-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.5;
    word-break: break-word;
    animation: msgIn .15s ease;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Mensajes del usuario */
.chatbot-msg.user {
    background: #2563eb;
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Mensajes del asistente */
.chatbot-msg.assistant {
    background: #fff;
    color: #1e293b;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

/* Indicador de carga (tres puntos) */
.chatbot-msg.loading {
    background: #fff;
    align-self: flex-start;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    padding: 12px 18px;
}
.chatbot-dots {
    display: flex;
    gap: 5px;
    align-items: center;
}
.chatbot-dots span {
    width: 7px;
    height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    animation: dotBounce 1.2s infinite ease-in-out;
}
.chatbot-dots span:nth-child(2) { animation-delay: .2s; }
.chatbot-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes dotBounce {
    0%, 80%, 100% { transform: scale(.8); opacity: .5; }
    40%           { transform: scale(1.2); opacity: 1; }
}

/* Área de entrada */
#chatbot-input-area {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    gap: 8px;
    flex-shrink: 0;
}
#chatbot-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 22px;
    padding: 9px 14px;
    outline: none;
    font-size: 14px;
    transition: border-color .2s;
    background: #f8fafc;
    color: #1e293b;
}
#chatbot-input:focus { border-color: #2563eb; background: #fff; }

#chatbot-send {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: #2563eb !important;
    border: none !important;
    border-radius: 50% !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0 !important;
    box-shadow: none;
    transition: background .2s, transform .15s;
}
#chatbot-send:hover  { background: #1d4ed8 !important; }
#chatbot-send:active { transform: scale(.93); }
#chatbot-send:disabled { background: #93c5fd !important; cursor: not-allowed; }
#chatbot-send svg {
    display: block !important;
    width: 18px !important;
    height: 18px !important;
    fill: #fff !important;
    pointer-events: none;
}
#chatbot-toggle svg {
    display: block !important;
    width: 26px !important;
    height: 26px !important;
    fill: #fff !important;
    pointer-events: none;
}

/* Mensaje de bienvenida inicial */
.chatbot-welcome {
    text-align: center;
    color: #94a3b8;
    font-size: 13px;
    margin: auto;
    padding: 20px;
    line-height: 1.6;
}

/* Spacer para empujar mensajes al fondo */
.cb-spacer { flex: 1; }

/* Responsive móvil — pantalla completa */
@media (max-width: 768px) {
    #chatbot-toggle {
        bottom: 80px;
        right: 16px;
        z-index: 999999;
    }

    /* Overlay de fondo para bloquear la tienda */
    #chatbot-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.45);
        z-index: 999997;
    }
    #chatbot-overlay.active { display: block; }

    /* Ventana a pantalla completa */
    #chatbot-window {
        position: fixed;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-height: none !important;
        border-radius: 0 !important;
        z-index: 999998;
    }

    /* Ajuste cuando sube el teclado virtual */
    #chatbot-window.keyboard-open {
        height: var(--cb-vp-height, 100%) !important;
    }

    #chatbot-header {
        padding-top: max(14px, env(safe-area-inset-top));
    }

    #chatbot-input-area {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}
