body.qcf-active .drop-msg .cls, 
body:not(.qcf-active) .drop-msg .show {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}
.btt:hover, .drop-msg:hover, body.qcf-active .drop-msg {
    transform: scale(1) translateZ(0);
}
.qcf-backdrop {
    opacity: 0;
    visibility: hidden;
    z-index: 1059;
    transition: opacity 0.2s, visibility 0.2s;
    display: block;
    background-color: rgba(0,0,0,0.16);
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    position: fixed;
}
body.qcf-active .qcf-backdrop {
    opacity: 1;
    visibility: visible;
}

/* --- Khung Widget Chính (.qcf) - PHIÊN BẢN SỬA LỖI --- */
body:not(.qcf-ready) .qcf, 
body:not(.qcf-ready) .qcf-backdrop {
    display: none;
}

.qcf {
    /* Các thuộc tính gốc được giữ lại */
    position: fixed;
    z-index: 1061;
    right: 20px;
    bottom: 90px;
    transition: all 0.4s;
    opacity: 0;
    visibility: hidden;
    transform: translate3d(0, 20px, 0) scale(0.97);
    width: 380px; 
    max-height: calc(100vh - 120px); /* 1. Giới hạn chiều cao tối đa */
    display: flex;                   /* 2. Biến thành flex container */
    flex-direction: column;          /* để quản lý nội dung bên trong 
    
    /* 3. Giữ lại các style gốc cần thiết */
    padding: 0;
    overflow: hidden; /* Giữ overflow hidden để bo góc hoạt động */
    border-radius: 12px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.15);
}

/* Trạng thái khi mở (giữ nguyên logic gốc) */
body.qcf-active .qcf {
    opacity: 1;
    visibility: visible;
    transform: translate3d(0, 0px, 0) scale(1);
}

/* --- Responsive (Tinh Chỉnh Lại) --- */
@media only screen and (max-width: 992px) {
    .btt, .drop-msg { right: 10px; bottom: 10px; }
    .drop-msg + .btt { bottom: 65px; }
}

@media only screen and (max-width: 480px) {
    .qcf {
        width: calc(100vw - 30px); /* Chiếm gần hết chiều rộng màn hình */
        right: 15px;
        bottom: 80px;
        max-height: calc(100vh - 100px); /* Chiều cao tối đa trên mobile */
    }
}

.qcf-tabs {
    display: flex;
    padding: 8px;
    background-color: #f0f2f5;
    border-bottom: 1px solid #e0e0e0;
}

.qcf-tab-trigger {
    flex: 1;
    padding: 12px 10px;
    background-color: #fff;
    border: 1px solid #ddd;
    color: #333;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    margin: 0 4px;
    border-radius: 6px; 
}
.qcf-tab-trigger i {
    margin-right: 8px;
}

.qcf-tab-trigger:hover {
    background-color: #f8f9fa;
    border-color: #0d6efd;
}

.qcf-tab-trigger.active {
    background-color: #0d6efd !important;
    color: white !important;
    border-color: #0d6efd !important;
}

/* --- View Content Area --- */
.qcf-content-switcher {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
    background-color: #fff;
}

.qcf-view {
    display: none;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.qcf-view.active {
    display: flex;
}

/* --- Contact Form View Specific Styles --- */
#qcf-form-view form {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-top: 0;
}
#qcf-form-view form .fs-14 {
    width: 100%;
    box-sizing: border-box;
}
#qcf-form-view form textarea {
    flex-grow: 1;
    resize: none;
}
#qcf-form-view form .d-flex {
    margin-top: auto;
}


/* --- AI Chat View Specific Styles --- */
#ai-chat-history {
    flex-grow: 1; /* Cho phép phần tử này co giãn để lấp đầy không gian */
    overflow-y: auto; /* Thêm thanh cuộn dọc KHI NỘI DUNG DÀI HƠN */
    max-height: 60vh !important;
    padding: 20px;
    background-color: #f9f9f9;
    display: flex;
    flex-direction: column;
    gap: 15px;

    /* --- CSS CHO THANH CUỘN (FIREFOX) --- */
    scrollbar-width: thin;          /* Thanh cuộn nhỏ */
    scrollbar-color: #ccc #f1f1f1;   /* Màu của con trượt và rãnh trượt */
}

/* --- CSS CHO THANH CUỘN (CHROME, SAFARI, EDGE) --- */
#ai-chat-history::-webkit-scrollbar {
  width: 6px; /* Chiều rộng thanh cuộn */
}

#ai-chat-history::-webkit-scrollbar-track {
  background: #f1f1f1; /* Màu của rãnh trượt */
  border-radius: 10px;
}

#ai-chat-history::-webkit-scrollbar-thumb {
  background: #ccc; /* Màu của con trượt */
  border-radius: 10px;
}

#ai-chat-history::-webkit-scrollbar-thumb:hover {
  background: #aaa; /* Màu con trượt khi di chuột vào */
}


#ai-consultant-form {
    border-top: 1px solid #eee;
}

#ai_form_content {
    width: 100%;
    border: none;
    resize: none;
    height: 80px;
    padding: 15px 20px;
    font-size: 15px;
    box-sizing: border-box;
    margin-top: 0 !important;
}
#ai_form_content:focus {
    outline: none;
}

#ai-qsubmit {
    border: 1px solid #0d6efd;
    color: #0d6efd;
    font-weight: 600;
    transition: all 0.2s ease;
}
#ai-qsubmit:hover {
    background-color: #0d6efd !important;
    color: white;
}


/* --- AI Chat Messages --- */
.message { max-width: 90%; display: flex; flex-direction: column; }
.message p { margin: 0; padding: 10px 15px; border-radius: 18px; line-height: 1.5; font-size: 15px; word-break: break-word; white-space: pre-wrap; }
.user-message { align-self: flex-end; align-items: flex-end; }
.user-message p { background-color: #007bff; color: white; border-bottom-right-radius: 4px; }
.ai-message { align-self: flex-start; align-items: flex-start; width: 100%; }
.ai-sender { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; font-size: 13px; color: #555; }
.ai-icon { width: 28px; height: 28px; background-color: #e9ecef; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.ai-icon i { font-size: 14px; color: #495057; }
.ai-message .ai-content, .ai-message .typing-dots { background-color: #e9ecef; color: #212529; padding: 10px 15px; border-radius: 18px; border-bottom-left-radius: 4px; align-self: flex-start; width: auto; max-width: 100%; box-sizing: border-box; }
.ai-content p:last-child { margin-bottom: 0; }
.ai-content ul { padding-left: 20px; margin: 5px 0 0 0; }
.ai-content li { margin-bottom: 5px; }

/* Typing Indicator */
.typing-dots { display: flex; align-items: center; padding: 15px; }
.typing-dots span { height: 8px; width: 8px; background-color: #888; border-radius: 50%; display: inline-block; margin: 0 2px; animation: typing-bubble 1.2s infinite ease-in-out; }
.typing-dots span:nth-of-type(1) { animation-delay: -0.2s; }
.typing-dots span:nth-of-type(2) { animation-delay: -0.1s; }
.typing-dots span:nth-of-type(3) { animation-delay: 0s; }
@keyframes typing-bubble { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-5px); } }


/* --- Final Product List Styles --- */
.product-list-container {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 100%;
}

.product-list-item {
    display: flex;
    align-items: center;
    padding: 10px;
    background-color: #fff;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.product-list-item:hover {
    background-color: #f8f9fa;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.product-list-image {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    margin-right: 15px;
    flex-shrink: 0;
    background-color: #eee;
}

/* --- Styling for Product Description in List --- */

.product-list-info {
    /* Existing styles */
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex-grow: 1;
    min-width: 0;
}

.product-list-name {
    /* Existing styles */
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 4px 0;
}

.product-list-price {
    /* Existing styles */
    font-size: 13px;
    font-weight: bold;
    color: #007bff;
    margin-bottom: 5px; /* Add some space below the price */
}

.product-list-desc {
    font-size: 12px;
    color: #6c757d; /* A subtle grey color */
    line-height: 1.4;
    
    /* Truncate the description to 2 lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;  
    overflow: hidden;
    text-overflow: ellipsis;
}