/* --- CÀI ĐẶT CHUNG & VỊ TRÍ --- */
#tvai-widget {
    position: fixed;
    right: 20px;
    z-index: 999999;
    bottom: 30px;
}
.tvai-body {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-image: none !important;
    background-color: #ffffff !important;
}
.tvai-chat-message.user .tvai-message-content {
    background-color: #e9e9eb;
    color: #000000;
    border-bottom-right-radius: 4px;
}
.tvai-chat-message.assistant .tvai-message-content {
    background-color: #e5e5ea;
    color: #016391;
    border-bottom-left-radius: 4px;
}
#tvai-bubble {
    right: 20px;
    bottom: 30px;
    width: 60px;
    height: 60px;
    background-color: #0073aa;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: fixed;
    box-shadow: 0 4px 10px rgba(0,0,0,0.25);
    transition: opacity 0.3s, transform 0.3s;
    z-index: 99999;
}


/* ================================================================== */
/* =================== LOGIC HIỂN THỊ TRÊN PC ===================== */
/* ================================================================== */
@media (min-width: 769px) {
    #tvai-bubble { display: none !important; }

    #tvai-widget {
        width: 370px;
        max-height: 70vh;
        background: #fff;
        border-radius: 10px;
        box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
        display: flex;
        flex-direction: column;
        transition: all 0.3s ease;
    }

    #tvai-widget.tvai-collapsed {
        height: 50px;
        width: 300px;
        overflow: hidden;
    }

    #tvai-widget.tvai-collapsed .tvai-body,
    #tvai-widget.tvai-collapsed .tvai-input-wrapper {
        display: none;
    }

    #tvai-widget.tvai-collapsed #tvai-close-btn {
        display: none;
    }

    #tvai-widget.tvai-widget-expanded {
        width: 750px;
        height: 95vh;
        max-height: 900px;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        bottom: auto;
    }
    #tvai-widget.tvai-widget-expanded .tvai-body,
    #tvai-widget.tvai-widget-expanded .tvai-input-wrapper {
        display: flex;
    }

    .tvai-header-buttons > button {
        width: 24px;
        height: 24px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: rgba(255, 255, 255, 0.15);
        border-radius: 4px;
        transition: background-color 0.2s;
    }
    .tvai-header-buttons > button:hover {
        background-color: rgba(255, 255, 255, 0.3);
    }
    
    
    #tvai-expand-btn svg {
        width: 16px;
        height: 16px;
    }
}

/* =================================================================== */
/* =================== LOGIC HIỂN THỊ TRÊN MOBILE ==================== */
/* =================================================================== */
@media (max-width: 768px) {
    .tvai-header-info,
    #tvai-expand-btn {
        display: none !important;
    }

    #tvai-widget {
        display: flex;
        flex-direction: column;
        position: fixed; /* Đảm bảo là fixed */
        top: 50%;
        left: 50%;
        width: 95vw;
        height: 80vh;
        border-radius: 12px;
        background: #fff;
        box-shadow: 0 5px 25px rgba(0,0,0,0.2);
        /* Mặc định ẩn đi */
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transform: translate(-50%, -50%) scale(0.95);
        transition: opacity 0.3s ease, transform 0.3s ease;
        z-index: 999999;
    }

    /* Dùng class này để hiển thị mạnh mẽ hơn */
    #tvai-widget.tvai-is-open {
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        transform: translate(-50%, -50%) scale(1) !important;
    }

    
    #tvai-close-btn {
        position: absolute;
        top: 50%;
        right: 20px;
        transform: translateY(-50%) scale(1.5); /* Giảm scale cho hợp lý hơn */
        color: #e74c3c;
        font-size: 24px;
    }
    #tvai-bubble.tvai-hidden {
        opacity: 0;
        visibility: hidden;
    }
}
#tvai-close-btn {
        color: #e74c3c;
        font-size: 30px;
    }
/* =================================================================== */
/* =============== CÁC THÀNH PHẦN BÊN TRONG WIDGET ================= */
/* =================================================================== */

.tvai-header-info {
    flex-grow: 1;
    cursor: pointer;
}
.tvai-header-buttons {
    display: flex;
    align-items: center;
    gap: 15px;
}
.tvai-header-buttons > button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    opacity: 0.9;
    margin: 0;
}
.tvai-header-buttons > button:hover {
    opacity: 1;
}
.tvai-input-wrapper { 
    display: flex; 
    border-top: 1px solid #ddd; 
    padding: 15px; 
    background: #fff; 
    flex-shrink: 0; 
    align-items: center;
}
#tvai-chat-input { 
    flex-grow: 1; 
    border: 1px solid #ccc; 
    border-radius: 20px; 
    padding: 20px 15px; 
    font-size: 14px; 
    outline: none; 
    margin: 0;
}
#tvai-chat-send { 
    background-color: #0073aa; 
    color: white; 
    border: none; 
    padding: 0 15px; 
    border-radius: 20px; 
    margin: 0 15px;
    cursor: pointer; 
    font-weight: bold; 
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Thêm các class tiện ích cần thiết */
.tvai-hidden {
    display: none !important;
}

/* Style cho các tin nhắn được tạo động */
.tvai-chat-message { display: flex; gap: 10px; align-items: flex-end; max-width: 90%; }
/*.tvai-chat-avatar { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; background: #e0e0e0; }*/
.tvai-message-content-wrapper { display: flex; flex-direction: column; }
.tvai-message-content { padding: 10px 15px; border-radius: 18px; line-height: 1.5; word-wrap: break-word; }
.tvai-message-sender-name { font-size: 11px; color: #888; margin-bottom: 4px; font-weight: bold; }
.tvai-chat-message.assistant { align-self: flex-start; }
.tvai-chat-message.assistant .tvai-message-sender-name { text-align: left; }
.tvai-chat-message.user { align-self: flex-end; }
.tvai-chat-message.user .tvai-message-content-wrapper { order: 1; }
.tvai-chat-message.user .tvai-chat-avatar { order: 2; }
.tvai-chat-message.user .tvai-message-sender-name { text-align: right; }
.tvai-chat-choices { display: flex; flex-wrap: wrap; gap: 8px; padding-left: 42px; }
.tvai-choice-button { background: #fff; border: 1px solid #0073aa; color: #0073aa; padding: 8px 12px; border-radius: 20px; cursor: pointer; font-size: 14px; }
.tvai-choice-button:hover { background: #0073aa; color: #fff; }
.tvai-typing-indicator span { height: 8px; width: 8px; background-color: #9E9E9E; border-radius: 50%; display: inline-block; animation: tvai-typing-fade 1s infinite; }
.tvai-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.tvai-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes tvai-typing-fade { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
/* CSS cho báo giá */
.tvai-quote-container {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 15px;
    margin: 10px 0;
    max-width: 95%;
    align-self: center;
}
.tvai-quote-header {
    font-size: 16px;
    font-weight: bold;
    color: #0073aa;
    text-align: center;
    margin-bottom: 15px;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 10px;
}
.tvai-quote-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 14px;
}
.tvai-quote-label { 
    color: #495057; 
}
.tvai-quote-price { 
    font-weight: bold; 
    color: #dc3545; 
}
.tvai-quote-footer {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.tvai-button-confirm, .tvai-button-secondary {
    width: 100%;
    padding: 10px;
    border-radius: 5px;
    border: 1px solid;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: background-color 0.2s, color 0.2s;
}
.tvai-button-confirm { 
    background-color: #28a745; 
    color: white; 
    border-color: #28a745; 
}
.tvai-button-confirm:hover {
    background-color: #218838;
}
.tvai-button-secondary { 
    background-color: transparent; 
    color: #6c757d; 
    border-color: #6c757d; 
}
.tvai-button-secondary:hover {
    background-color: #6c757d;
    color: white;
}
/* =================================================================== */
/* =============== CSS CHO BẢNG XÁC NHẬN THÔNG TIN ================= */
/* =================================================================== */
.tvai-confirmation-container {
    background-color: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 15px;
    margin: 10px auto; /* Căn giữa container */
    max-width: 95%;
    align-self: center; /* Đảm bảo căn giữa trong flex container */
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.tvai-confirmation-container table {
    width: 100%;
    border-collapse: collapse; /* Gộp đường viền cho đẹp hơn */
}

.tvai-confirmation-container th {
    font-size: 16px;
    padding: 12px;
    background-color: #f8f9fa;
    text-align: center;
    color: #333;
    border-bottom: 2px solid #dee2e6;
}

.tvai-confirmation-container td {
    padding: 10px 8px;
    border-bottom: 1px solid #f0f0f0; /* Đường viền mờ giữa các hàng */
    font-size: 14px;
    vertical-align: middle;
}

/* Tạo hiệu ứng màu xen kẽ cho các hàng */
.tvai-confirmation-container tr:nth-child(even) {
    background-color: #f8f9fa;
}

.tvai-confirmation-container td:first-child {
    font-weight: bold;
    color: #555;
    width: 40%;
}

.tvai-confirmation-container .tvai-info-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.tvai-confirmation-container .tvai-info-input:focus {
    border-color: #0073aa;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.15);
    outline: none;
}

.tvai-confirmation-buttons {
    display: flex;
    justify-content: center; /* Căn giữa nút */
    margin-top: 20px;
}

#tvai-submit-final-info-btn {
    padding: 10px 25px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    background-color: #28a745;
    color: white;
    transition: background-color 0.2s;
}

#tvai-submit-final-info-btn:hover {
    background-color: #218838;
}
/* CSS CHO NÚT ĐẶT HÀNG NỔI */
#tvai-floating-order-btn {
    position: absolute;
    left: -45px;
    top: 50%;
    transform: translateY(-50%) rotate(270deg); /* Xoay dọc nút */
    transform-origin: center;
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    z-index: 11;
    white-space: nowrap; /* Ngăn chữ xuống dòng */
    transition: background-color 0.2s, transform 0.2s;
}
#tvai-floating-order-btn:hover {
    background-color: #218838;
    transform: translateY(-50%) rotate(270deg) scale(1.05);
}
#tvai-floating-order-btn:disabled {
    background-color: #999;
    cursor: not-allowed;
}
/* --- CSS Tối Ưu Cho Avatar --- */

/* Đặt kích thước cố định cho thẻ bao quanh avatar */
.tvai-chat-avatar {
    width: 36px;  /* Kích thước hợp lý hơn */
    height: 36px; /* Kích thước hợp lý hơn */
    border-radius: 50%;
    flex-shrink: 0;
    background-color: #e0e0e0;
}

/* Đảm bảo ảnh bên trong vừa với khung và không bị méo (QUAN TRỌNG) */
.tvai-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
/* Căn giữa và tạo khoảng cách cho khu vực đăng nhập */
#tvai-google-login-container {
    text-align: center;
    padding: 10px 5px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* Tạo khoảng cách giữa dòng chữ và nút bấm */
#tvai-google-login-container p {
    margin-top: 0;
    margin-bottom: 15px;
    color: #555;
}
/* --- CSS Sửa lỗi hiển thị Header --- */

/* 1. Căn chỉnh chung cho toàn bộ thanh header */
.tvai-header {
    display: flex;
    height: 50px;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    background-color: #3b82f6; /* Màu xanh dương mặc định */
    color: white;
    border-radius: 5;
    position: relative;
    font-size: 16px;
    font-weight: bold;
    flex-shrink: 0;
}
/* 2. Căn chỉnh cho khu vực thông tin (icon và chữ) */
.tvai-header-info {
    display: flex;
    align-items: center;
    gap: 10px; /* Khoảng cách giữa icon và chữ */
    flex-grow: 1;
    overflow: hidden; /* Ngăn nội dung dài tràn ra ngoài */
}

/* 3. QUAN TRỌNG: Giới hạn kích thước và bo tròn cho ảnh trong header */
#tvai-header-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover; /* Đảm bảo ảnh không bị méo */
    flex-shrink: 0;
    background-color: #fff; /* Thêm màu nền trắng phòng trường hợp ảnh trong suốt */
}

/* 4. Đảm bảo dòng chữ tiêu đề hiển thị đẹp */
.tvai-header-info span {
    font-weight: bold;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 5. Căn chỉnh cho các nút bấm bên phải */
.tvai-header-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}
/* CSS tùy chỉnh cho nút đăng nhập Google */
.tvai-google-button {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    color: #3c4043 !important;
    background-color: #fff !important;
    border: 1px solid #dadce0 !important;
    border-radius: 4px !important;
    padding: 8px 16px !important;
    cursor: pointer !important;
    transition: background-color .3s, border-color .3s !important;
    /* Thêm các thuộc tính kích thước nếu cần */
    /* Ví dụ: */
    /* height: 36px !important; */
}

.tvai-google-button svg {
    margin-right: 8px !important; /* Giảm khoảng cách icon */
    height: 18px !important;
    width: 18px !important;
}

.tvai-google-button span {
    font-size: 14px !important;
}
#tvai-confirmation-buttons button{
    background: #045c85;
    color: #fff;
    padding: 8px;
    border-radius: 5px;
    border: none;
}
#tvai-confirmation-buttons button:hover{
    background: #01e7d4;
    color: #b30000;
}
/* ============================================= */
/* NÂNG CẤP GIAO DIỆN BONG BÓNG CHAT
/* ============================================= */

/* Thiết lập lại để các tin nhắn liền kề có khoảng cách hợp lý */
.tvai-chat-message {
    margin-bottom: 10px;
}
.tvai-chat-message + .tvai-chat-message.assistant {
    margin-top: -2px; /* Giảm khoảng cách giữa 2 tin nhắn của bot */
}

/* Tùy chỉnh bong bóng chat chung */
.tvai-message-content {
    padding: 10px 15px;
    border-radius: 18px;
    line-height: 1.5;
    max-width: 100%;
    word-wrap: break-word;
}

/* Bong bóng chat của Bot */
.tvai-chat-message.assistant .tvai-message-content {
    background-color: #E9E9EB;
    color: #000;
    border-top-left-radius: 4px;
}

/* Bong bóng chat của User */
.tvai-chat-message.user .tvai-message-content {
    background-color: #007AFF;
    color: white;
    border-top-right-radius: 4px;
}

/* Căn chỉnh lại wrapper */
.tvai-message-content-wrapper {
    max-width: 85%;
}

/* Đảm bảo các dòng mới (\n) được hiển thị đúng */
.tvai-message-content br {
    content: "";
    display: block;
    margin-bottom: 0.5em;
}