/* Container chính */
#wqb-container {
    max-width: 1200px;
    margin: 20px auto;
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #333;
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

/* Phần thông tin khách hàng & Tìm kiếm */
.wqb-section {
    margin-bottom: 25px;
}

.wqb-section h3 {
    margin-bottom: 10px;
    font-size: 18px;
    color: #2c3e50;
    border-left: 4px solid #0073aa;
    padding-left: 10px;
}

.wqb-input {
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
}

/* --- QUAN TRỌNG: Thanh cuộn ngang cho Table --- */
.wqb-table-wrapper {
    width: 100%;
    overflow-x: auto;
    /* Kích hoạt cuộn ngang */
    margin-bottom: 20px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    /* Tạo đổ bóng nhẹ để nhận biết có thể cuộn */
    background: linear-gradient(to right, white 30%, rgba(255, 255, 255, 0)),
        linear-gradient(to right, rgba(255, 255, 255, 0), white 70%) 0 100%,
        radial-gradient(farthest-side at 0% 50%, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0)),
        radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0)) 0 100%;
    background-repeat: no-repeat;
    background-color: white;
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    background-attachment: local, local, scroll, scroll;
}

#quotation_table {
    width: 100%;
    min-width: 1000px;
    /* Đảm bảo bảng luôn rộng ít nhất 1000px để không bị dồn chữ */
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #ccc;
}

#quotation_table th {
    background-color: #f8f9fa;
    color: #2c3e50;
    font-weight: 600;
    padding: 12px 10px;
    border: 1px solid #ccc;
    text-align: center;
}

#quotation_table td {
    padding: 10px;
    border: 1px solid #ccc;
    vertical-align: middle;
}

/* Styling cho các input trong bảng */
#quotation_table textarea {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 5px;
    font-size: 13px;
    resize: vertical;
    /* Cho phép kéo dài chiều cao nhưng không làm rộng cột */
    min-height: 60px;
}

#quotation_table input[type="number"],
#quotation_table input[type="text"] {
    width: 100%;
    padding: 6px;
    border: 1px solid #ddd;
    border-radius: 3px;
    text-align: center;
}

/* Cột Ảnh */
#quotation_table img {
    border-radius: 4px;
    object-fit: cover;
    border: 1px solid #eee;
}

/* Footer & Tổng tiền */
#quotation_table tfoot td {
    background-color: #fcfcfc;
    font-weight: 500;
    padding: 8px 15px;
    border: 1px solid #ccc;
}

.wqb-total-row td {
    background-color: #fff9f9 !important;
    font-size: 1.1em;
}

/* Nút Xóa */
.remove-item {
    background: #ff4d4d;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 3px;
    cursor: pointer;
    transition: 0.3s;
}

.remove-item:hover {
    background: #cc0000;
}

/* Dropdown tìm kiếm */
.wqb-search-dropdown {
    position: absolute;
    width: 100%;
    max-height: 300px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #ddd;
    z-index: 999;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    display: none;
}

.wqb-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
}

.wqb-item:hover {
    background: #f9f9f9;
}

.wqb-item img {
    margin-right: 15px;
}

/* Nút hành động */
.wqb-actions {
    margin-top: 20px;
}

.wqb-actions-flex {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-end;
    align-items: center;
}

.wqb-btn {
    padding: 6px 12px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.wqb-btn:hover {
    transform: translateY(-1.5px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.wqb-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.btn-invoice {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
}

.btn-invoice:hover {
    background: linear-gradient(135deg, #c0392b, #962d22);
}

.btn-image {
    background: linear-gradient(135deg, #34495e, #2c3e50);
    color: white;
}

.btn-image:hover {
    background: linear-gradient(135deg, #2c3e50, #1a252f);
}

.btn-pdf {
    background: linear-gradient(135deg, #ff4757, #ee5253);
    color: white;
    box-shadow: 0 2px 6px rgba(255, 71, 87, 0.2);
}

.btn-pdf:hover {
    background: linear-gradient(135deg, #ff6b81, #ff4757);
    box-shadow: 0 4px 10px rgba(255, 71, 87, 0.35);
}

.btn-excel {
    background: linear-gradient(135deg, #27ae60, #219150);
    color: white;
    box-shadow: 0 2px 6px rgba(39, 174, 96, 0.2);
}

.btn-excel:hover {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    box-shadow: 0 4px 10px rgba(39, 174, 96, 0.35);
}

.btn-save {
    background: linear-gradient(135deg, #2ecc71, #27ae60) !important;
    color: white !important;
    box-shadow: 0 2px 6px rgba(46, 204, 113, 0.2);
}

.btn-save:hover {
    background: linear-gradient(135deg, #27ae60, #2ecc71) !important;
    box-shadow: 0 4px 10px rgba(46, 204, 113, 0.35);
}

/* --- DROPDOWN EXCEL/WORD ACTIONS --- */
.wqb-more-actions-wrapper {
    position: relative;
    display: inline-block;
}

.wqb-toggle-btn {
    background: linear-gradient(135deg, #4b5563, #374151);
    color: white;
    box-shadow: 0 2px 6px rgba(75, 85, 99, 0.2);
    border: none;
}

.wqb-toggle-btn:hover {
    background: linear-gradient(135deg, #6b7280, #4b5563);
    box-shadow: 0 4px 10px rgba(75, 85, 99, 0.35);
}

.wqb-toggle-btn.active {
    background: #1f2937;
    transform: translateY(0);
}

.wqb-more-actions-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 1000;
    min-width: 240px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    box-sizing: border-box;
    
    /* Animation mượt mà */
    transform: translateY(-8px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.wqb-more-actions-dropdown.show {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Định dạng các nút bên trong dropdown */
.wqb-more-actions-dropdown .wqb-btn:not([style*="display: none"]) {
    display: block !important;
    width: 100% !important;
    margin: 5px 0 !important;
    margin-left: 0 !important;
    text-align: left !important;
    box-sizing: border-box !important;
    padding: 6px 10px !important;
    font-size: 12px !important;
    border-radius: 4px !important;
    box-shadow: none !important;
}

.wqb-more-actions-dropdown .wqb-btn:hover {
    transform: translateX(4px) !important;
}

/* Xử lý Mobile Responsive cho dropdown */
@media screen and (max-width: 600px) {
    .wqb-actions-flex {
        justify-content: center;
        width: 100%;
    }
    
    .wqb-actions-flex .wqb-btn,
    .wqb-more-actions-wrapper {
        width: 100%;
    }
    
    .wqb-more-actions-dropdown {
        position: static !important;
        display: none;
        width: 100% !important;
        box-shadow: none !important;
        border: 1px solid #e5e7eb;
        margin-top: 10px;
        transform: none !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        border-radius: 8px;
    }
    
    .wqb-more-actions-dropdown.show {
        display: block !important;
    }
}

/* Tùy chỉnh thanh cuộn (cho Chrome/Safari) */
.wqb-table-wrapper::-webkit-scrollbar {
    height: 8px;
}

.wqb-table-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.wqb-table-wrapper::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.wqb-table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Vùng Preview A5 */
/* Container bao ngoài để khống chế vùng hiển thị */
.wqb-preview-section {
    width: 100%;
    overflow: hidden;
    /* Tránh tràn ngang màn hình */
    background: #f0f0f0;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#invoice-render-area {
    width: 148mm;
    /* Giữ nguyên chuẩn A5 */
    min-height: 210mm;
    background: #fff;
    padding: 6mm;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    font-family: "Times New Roman", Times, serif;
    color: #000;
    line-height: 1.4;
    position: relative;
    transform-origin: top center;
    /* Thu nhỏ từ tâm phía trên */
}

/* Xử lý hiển thị trên Mobile */
@media screen and (max-width: 600px) {
    #invoice-render-area {
        /* Tỷ lệ scale = (Chiều rộng màn hình mobile / 155mm) */
        /* Thường scale khoảng 0.5 - 0.6 là vừa đẹp trên iPhone/Android */
        transform: scale(0.6);

        /* Khi scale, trình duyệt vẫn giữ chỗ trống của kích thước cũ (148mm) */
        /* Dùng margin-bottom âm để kéo các phần tử bên dưới (nút bấm) lên sát hóa đơn */
        margin-bottom: -85mm;
    }

    .wqb-preview-section h3,
    .wqb-preview-section .btn-image-capture-wrapper {
        width: 100%;
        text-align: center;
    }
}

/* Fix lỗi hiển thị cho màn hình cực nhỏ */
@media screen and (max-width: 400px) {
    #invoice-render-area {
        transform: scale(0.5);
        margin-bottom: -105mm;
    }
}

.wqb-preview-actions {
    margin-top: 20px;
    text-align: center;
}

/* Bảng kê trong tờ hóa đơn ảnh (Đã đồng bộ với quotation_table) */
.invoice-table-image {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    background: #fff;
    border: 1px solid #ccc;
}

.invoice-table-image th {
    background-color: #f8f9fa;
    /* Màu nền header bảng chính */
    color: #2c3e50;
    font-weight: 600;
    padding: 10px 5px;
    border: 1px solid #ccc;
    font-size: 12px;
    text-transform: uppercase;
    text-align: center;
}

.invoice-table-image td {
    padding: 8px 6px;
    border: 1px solid #ccc;
    vertical-align: middle;
    font-size: 13px;
    line-height: 1.4;
    color: #333;
}

/* Định dạng Footer bảng xem trước */
.invoice-table-image tfoot td {
    background-color: #fcfcfc;
    /* Màu nền footer bảng chính */
    font-weight: 600;
    border: 1px solid #ccc;
}

/* Các ô số tiền căn phải */
.invoice-table-image .text-right {
    text-align: right;
}

/* Các ô căn giữa (STT, ĐVT, SL) */
.invoice-table-image .text-center {
    text-align: center;
}

/* Dòng tổng cộng cuối cùng nhấn mạnh hơn */
.invoice-table-image .total-row-highlight {
    background-color: #fff9f9 !important;
    /* Màu nền đỏ nhạt của bảng chính */
}

/* Nút Xuất ảnh riêng */
.btn-image-capture {
    background: #2ecc71;
    color: white;
    padding: 15px 30px;
    font-weight: bold;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(46, 204, 113, 0.4);
}

.btn-image-capture:hover {
    background: #27ae60;
}

/* Style lịch sử báo giá */
/* Container chung cho mỗi dòng lịch sử */
.wqb-history-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    margin-bottom: 10px;
    background: #fff;
    border-radius: 6px;
    border-left: 5px solid #ccc;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    transition: all 0.2s ease;
    cursor: pointer;
}

.wqb-history-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.12);
    background: #fdfdfd;
}

/* Style cho các Nhãn (Badge) */
.wqb-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 800;
    color: #fff;
    margin-right: 12px;
    min-width: 60px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background-color: chocolate;
}

/* Màu sắc riêng cho từng loại */

/* 1. Hóa đơn bán lẻ - Màu Cam/Đỏ rực */
.wqb-history-item.HoaDonBanLe {
    border-left-color: #e67e22;
}

.wqb-history-item.HoaDonBanLe .wqb-badge {
    background: #e67e22;
}

/* 2. Báo giá Excel - Màu Xanh Lá (giống màu Excel) */
.wqb-history-item.BaoGiaExcel {
    border-left-color: #27ae60;
}

.wqb-history-item.BaoGiaExcel .wqb-badge {
    background: #27ae60;
}

/* 3. Báo giá PDF - Màu Xanh Dương/Đen (giống màu PDF) */
.wqb-history-item.BaoGiaPDF {
    border-left-color: #2980b9;
}

.wqb-history-item.BaoGiaPDF .wqb-badge {
    background: #2980b9;
}

/* Style cho phần chữ hiển thị */
.wqb-history-info {
    font-size: 14px;
    color: #333;
    font-family: inherit;
    line-height: 1.4;
}

.wqb-history-info strong {
    color: #000;
}

.wqb-stt {
    display: inline-block;

    text-align: left;

    font-family: monospace;
    /* Font chữ đơn cách giúp số luôn thẳng hàng */
    color: #666;
}

/* --- HỢP ĐỒNG ACCORDION & FORM (Tím hoàng gia - Premium Style) --- */
.wqb-contract-accordion {
    margin-top: 20px;
    border: 1px solid #e1d5eb;
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(142, 68, 173, 0.05);
    transition: all 0.3s ease;
}

.wqb-contract-toggle-btn {
    width: 100%;
    padding: 15px 20px;
    background: #faf8fc;
    border: none;
    text-align: left;
    font-size: 16px;
    font-weight: 600;
    color: #732d91;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s ease;
}

.wqb-contract-toggle-btn:hover {
    background: #f4eefc;
}

.wqb-contract-toggle-btn::after {
    content: "▼";
    font-size: 12px;
    transition: transform 0.3s ease;
    color: #8e44ad;
}

.wqb-contract-accordion.open .wqb-contract-toggle-btn::after {
    transform: rotate(180deg);
}

.wqb-contract-content {
    display: none;
    border-top: 1px solid #e1d5eb;
    background: #fff;
}

.wqb-contract-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    padding: 20px;
}

.wqb-contract-field-full {
    grid-column: span 2;
}

#seller_fields_wrapper,
#delivery_fields_wrapper {
    grid-column: span 2;
    grid-template-columns: inherit;
    gap: inherit;
}

.wqb-contract-grid label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #4a4a4a;
    font-size: 13px;
}

.wqb-contract-grid input,
.wqb-contract-grid select,
.wqb-contract-grid textarea {
    width: 100%;
    padding: 6px 12px;
    border: 1px solid #d8cfe3;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    color: #333;
    background-color: #fff;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

.wqb-contract-grid input:focus,
.wqb-contract-grid select:focus,
.wqb-contract-grid textarea:focus {
    border-color: #8e44ad;
    box-shadow: 0 0 0 3px rgba(142, 68, 173, 0.15);
    outline: none;
}

/* Nút Tạo Hợp đồng */
.btn-contract {
    background: linear-gradient(135deg, #8e44ad, #732d91);
    color: white;
    box-shadow: 0 4px 10px rgba(142, 68, 173, 0.3);
    border: none;
}

.btn-contract:hover {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(142, 68, 173, 0.45);
}

.btn-contract:active {
    transform: translateY(0);
}

/* Nút Tạo Hợp đồng PDF */
.btn-contract-pdf {
    background: linear-gradient(135deg, #c0392b, #962d22);
    color: white;
    box-shadow: 0 4px 10px rgba(192, 57, 43, 0.3);
    border: none;
}

.btn-contract-pdf:hover {
    background: linear-gradient(135deg, #d35400, #c0392b);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(192, 57, 43, 0.45);
}

.btn-contract-pdf:active {
    transform: translateY(0);
}

/* Các nút xuất PDF mới */
.btn-bbgh-pdf {
    background: linear-gradient(135deg, #d35400, #b03a2e);
    color: white;
    box-shadow: 0 4px 10px rgba(211, 84, 0, 0.3);
    border: none;
}
.btn-bbgh-pdf:hover {
    background: linear-gradient(135deg, #e67e22, #d35400);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(211, 84, 0, 0.45);
}
.btn-bbgh-pdf:active { transform: translateY(0); }

.btn-dntt-pdf {
    background: linear-gradient(135deg, #8e44ad, #6c3483);
    color: white;
    box-shadow: 0 4px 10px rgba(142, 68, 173, 0.3);
    border: none;
}
.btn-dntt-pdf:hover {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(142, 68, 173, 0.45);
}
.btn-dntt-pdf:active { transform: translateY(0); }

.btn-dntt-pre-pdf {
    background: linear-gradient(135deg, #6c3483, #512e5f);
    color: white;
    box-shadow: 0 4px 10px rgba(108, 52, 131, 0.3);
    border: none;
}
.btn-dntt-pre-pdf:hover {
    background: linear-gradient(135deg, #8e44ad, #6c3483);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(108, 52, 131, 0.45);
}
.btn-dntt-pre-pdf:active { transform: translateY(0); }

.btn-dntt-d1-pdf {
    background: linear-gradient(135deg, #1f618d, #1a5276);
    color: white;
    box-shadow: 0 4px 10px rgba(31, 97, 141, 0.3);
    border: none;
}
.btn-dntt-d1-pdf:hover {
    background: linear-gradient(135deg, #2980b9, #1f618d);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(31, 97, 141, 0.45);
}
.btn-dntt-d1-pdf:active { transform: translateY(0); }

.btn-dntt-d2-pdf {
    background: linear-gradient(135deg, #1e8449, #196f3d);
    color: white;
    box-shadow: 0 4px 10px rgba(30, 132, 73, 0.3);
    border: none;
}
.btn-dntt-d2-pdf:hover {
    background: linear-gradient(135deg, #27ae60, #1e8449);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(30, 132, 73, 0.45);
}
.btn-dntt-d2-pdf:active { transform: translateY(0); }

/* Badges màu lịch sử PDF mới (an toàn class replace space thành _) */
.wqb-history-item.HĐ_PDF { border-left-color: #c0392b; }
.wqb-history-item.HĐ_PDF .wqb-badge { background: #c0392b; }

.wqb-history-item.BBBG_PDF { border-left-color: #d35400; }
.wqb-history-item.BBBG_PDF .wqb-badge { background: #d35400; }

.wqb-history-item.ĐNTT_PDF { border-left-color: #8e44ad; }
.wqb-history-item.ĐNTT_PDF .wqb-badge { background: #8e44ad; }

.wqb-history-item.ĐNTT_Đ1_PDF { border-left-color: #1f618d; }
.wqb-history-item.ĐNTT_Đ1_PDF .wqb-badge { background: #1f618d; }

.wqb-history-item.ĐNTT_Đ2_PDF { border-left-color: #1e8449; }
.wqb-history-item.ĐNTT_Đ2_PDF .wqb-badge { background: #1e8449; }


/* Badge màu Tím riêng cho Lịch sử Hợp đồng */
.wqb-history-item.HopDongDocx {
    border-left-color: #8e44ad;
}

.wqb-history-item.HopDongDocx .wqb-badge {
    background: #8e44ad;
}

/* Badge riêng cho Lịch sử Biên bản bàn giao */
.wqb-history-item.BBBG {
    border-left-color: #1abc9c;
}

.wqb-history-item.BBBG .wqb-badge {
    background: #1abc9c;
}

/* Badge riêng cho Lịch sử Đề nghị thanh toán */
.wqb-history-item.ĐNTT {
    border-left-color: #2c3e50;
}

.wqb-history-item.ĐNTT .wqb-badge {
    background: #2c3e50;
}

/* Badge riêng cho Lịch sử Lưu DL (xanh emerald premium) */
.wqb-history-item.Lưu_DL {
    border-left-color: #2ecc71;
}

.wqb-history-item.Lưu_DL .wqb-badge {
    background: #2ecc71;
}


/* Responsive Grid */
@media screen and (max-width: 768px) {
    .wqb-contract-grid {
        grid-template-columns: 1fr;
    }

    .wqb-contract-field-full {
        grid-column: span 1;
    }

    #seller_fields_wrapper,
    #delivery_fields_wrapper {
        grid-column: span 1;
    }
}