/* === KỸ THUẬT CÁCH LY GIAO DIỆN (ISOLATION) === */

/* 1. Wrapper tổng */
#ngungon-chatbot-wrapper {
    all: initial;
    font-family: 'Inter', sans-serif !important;

    /* 2. Z-Index Tối Thượng */
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    z-index: 2147483647 !important;

    display: flex !important;
    flex-direction: column !important;
    align-items: flex-end !important;
    width: auto !important;
    height: auto !important;
    line-height: 1.5 !important;
}

/* 3. Reset cho tất cả phần tử con bên trong */
#ngungon-chatbot-wrapper *,
#ngungon-chatbot-wrapper *::before,
#ngungon-chatbot-wrapper *::after {
    box-sizing: border-box;
    font-family: inherit;
}

/* 4. Fix lỗi CSS phổ biến */
#ngungon-chatbot-wrapper button {
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    text-transform: none;
    box-shadow: none !important;
}

#ngungon-chatbot-wrapper input {
    color: #111827 !important;
    font-size: 16px !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    outline: none !important;
    border: none !important;
    background: transparent !important;
    line-height: normal !important;
}

#ngungon-chatbot-wrapper a {
    text-decoration: none !important;
    border: none !important;
    box-shadow: none !important;
    transition: all 0.2s;
}

#ngungon-chatbot-wrapper ul,
#ngungon-chatbot-wrapper li {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

#ngungon-chatbot-wrapper img {
    max-width: 100% !important;
    display: block !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* === CUSTOM STYLES CHO CHATBOT === */
.ngungon-gradient {
    background: #ffffff !important;
    border-bottom: 2px solid #e5e7eb !important;
    /* Separator between header and body */
}

.ngungon-launcher-bg {
    background-image: linear-gradient(to bottom right, #4F46E5, #818CF8) !important;
    color: white !important;
}

/* Or keep Blue if preferred, but Indigo feels more "Sleeping" */
/* Let's keep it close to blue but slightly softer? No, let's stick to the previous blue gradient but rename class for consistency, or keep .txv-gradient name? Better rename. */
.ngungon-btn-primary {
    background-color: #4338CA !important;
    /* Indigo 700 */
    color: white !important;
}

.ngungon-btn-primary:hover {
    background-color: #3730A3 !important;
    /* Indigo 800 */
}

.chat-bubble {
    max-width: 85% !important;
    padding: 10px 15px !important;
    border-radius: 15px !important;
    margin-bottom: 10px !important;
    word-wrap: break-word !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) !important;
    font-size: 14px !important;
}

.user-bubble {
    background-image: linear-gradient(to bottom right, #4F46E5, #818CF8) !important;
    /* Indigo */
    color: white !important;
    align-self: flex-end !important;
    border-bottom-right-radius: 5px !important;
}

.bot-bubble {
    background-color: #f3f4f6 !important;
    color: #1f2937 !important;
    align-self: flex-start !important;
    border-bottom-left-radius: 5px !important;
    border: 1px solid #e5e7eb !important;
}

/* Typing Animation */
.typing-dots {
    display: flex !important;
    align-items: center !important;
    height: 14px !important;
}

.typing-dots .dot {
    background-color: #6b7280 !important;
    width: 6px !important;
    height: 6px !important;
    border-radius: 50% !important;
    margin: 0 2px !important;
    animation: typing 1.2s infinite ease-in-out !important;
}

.typing-dots .dot:nth-child(1) {
    animation-delay: -0.30s !important;
}

.typing-dots .dot:nth-child(2) {
    animation-delay: -0.15s !important;
}

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0);
        opacity: 0.5;
    }

    40% {
        transform: scale(1.0);
        opacity: 1;
    }
}

/* Product Carousel Styles */
.ngungon-product-carousel {
    -ms-overflow-style: none;
    /* IE and Edge */
    scrollbar-width: none;
    /* Firefox */
}

.ngungon-product-carousel::-webkit-scrollbar {
    display: none;
}

.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ============================================
   MOBILE 80% OVERLAY MODE
   ============================================ */
@media (max-width: 640px) {

    /* Wrapper: cho phép click qua khi chat đóng */
    #ngungon-chatbot-wrapper {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        pointer-events: none !important;
        display: block !important;
    }

    /* Launcher button: góc phải dưới, có thể click */
    #ngungon-chatbot-wrapper #chat-launcher {
        position: fixed !important;
        bottom: 20px !important;
        right: 20px !important;
        pointer-events: auto !important;
        z-index: 2147483646 !important;
    }


    /* Chat window: fixed TOP - không bị ảnh hưởng bởi keyboard */
    #ngungon-chatbot-wrapper #chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: auto !important;
        width: 100% !important;
        /* Cách keyboard = icon height (56px) + 3px = 59px */
        height: calc(100vh - 59px) !important;
        height: calc(100dvh - 59px) !important;
        max-width: 100% !important;
        max-height: calc(100vh - 59px) !important;
        max-height: calc(100dvh - 59px) !important;
        margin: 0 !important;
        border-radius: 0 0 16px 16px !important;
        pointer-events: auto !important;
        display: flex !important;
        flex-direction: column !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
    }

    /* Header: luôn fixed top trong chat window */
    #ngungon-chatbot-wrapper #chat-window .ngungon-gradient {
        flex-shrink: 0 !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 10 !important;
        background: #ffffff !important;
    }

    /* Chat area: flex-grow, scrollable */
    #ngungon-chatbot-wrapper #chatArea {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        min-height: 0 !important;
    }

    /* Input area: cố định dưới cùng */
    #ngungon-chatbot-wrapper #chat-window>div:last-child {
        flex-shrink: 0 !important;
        position: sticky !important;
        bottom: 0 !important;
        background: #f9fafb !important;
        z-index: 10 !important;
    }

    /* Input: font-size 16px để tránh iOS auto-zoom */
    #ngungon-chatbot-wrapper input {
        font-size: 16px !important;
        -webkit-text-size-adjust: 100% !important;
    }
}