/* =========================================================
   KAZUKO INVOICE TEMPLATE ENGINE 05.2.2
   ========================================================= */

/* =========================================================
   THANH CÔNG CỤ XEM HÓA ĐƠN
   ========================================================= */

.invoice-preview-toolbar {
    position: sticky;
    top: 0;
    z-index: 25;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 auto 18px;
    padding: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 10px 28px rgba(15, 23, 42, .08);
    backdrop-filter: blur(12px);
}

.invoice-preview-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 9px;
}

/* =========================================================
   KHỔ GIẤY HÓA ĐƠN
   ========================================================= */

.invoice-paper-a4 {
    width: min(210mm, 100%);
    min-height: 297mm;
    margin: 0 auto 28px;
}

/* =========================================================
   BẢNG HÀNG HÓA CHUNG
   ========================================================= */

.invoice-grid {
    width: 100%;
    border-collapse: collapse;
    /*
     * Giữ fixed cho các mẫu nhiều cột.
     * Riêng mẫu vàng sẽ được ghi đè thành auto ở phần dưới.
     */
    table-layout: fixed;
    font-size: 12px;
}

    .invoice-grid th,
    .invoice-grid td {
        padding: 7px 6px;
        border: 1px solid #111827;
        text-align: center;
        vertical-align: middle;
        overflow-wrap: anywhere;
    }

    .invoice-grid th {
        font-weight: 800;
        background: #f8fafc;
    }

    .invoice-grid .text-start {
        text-align: left !important;
    }

    .invoice-grid .text-end {
        text-align: right !important;
    }

.invoice-empty-line {
    height: 90px;
    color: #6b7280;
}

/* =========================================================
   MẪU NHIỀU CỘT
   ========================================================= */

.invoice-grid-many-columns {
    font-size: 10.5px;
}

/* =========================================================
   MẪU HÓA ĐƠN VÀNG
   CHỈ CHỈNH TỶ LỆ CỘT, KHÔNG THU NHỎ TOÀN TRANG
   ========================================================= */

.invoice-grid-gold {
    width: 100%;
    /*
     * Quan trọng:
     * Không dùng fixed cho mẫu vàng.
     * Trình duyệt sẽ giữ nguyên toàn bộ chiều rộng bảng,
     * chỉ phân bổ lại các cột theo yêu cầu.
     */
    table-layout: auto;
}

    /* Cột 1: STT - nhỏ lại */
    .invoice-grid-gold th:nth-child(1),
    .invoice-grid-gold td:nth-child(1) {
        width: 38px;
        min-width: 38px;
        max-width: 38px;
        padding-left: 3px;
        padding-right: 3px;
        text-align: center;
        white-space: nowrap;
    }

    /* Cột 2: Tên hàng hóa, dịch vụ - chiếm phần còn lại */
    .invoice-grid-gold th:nth-child(2),
    .invoice-grid-gold td:nth-child(2) {
        width: auto;
        padding-left: 9px;
        padding-right: 9px;
        text-align: left;
        /*
     * Cho phép tên dài tự xuống dòng trong đúng ô.
     * Không để chữ đè vào đường kẻ.
     */
        white-space: normal;
        word-break: normal;
        overflow-wrap: break-word;
        line-height: 1.45;
    }

    /* Căn giữa riêng tiêu đề cột tên hàng */
    .invoice-grid-gold th:nth-child(2) {
        text-align: center;
    }

    /* Cột 3: Đơn vị tính - nhỏ lại */
    .invoice-grid-gold th:nth-child(3),
    .invoice-grid-gold td:nth-child(3) {
        width: 68px;
        min-width: 68px;
        max-width: 68px;
        padding-left: 4px;
        padding-right: 4px;
        text-align: center;
        white-space: nowrap;
    }

    /* Cột 4: Số lượng - nhỏ lại */
    .invoice-grid-gold th:nth-child(4),
    .invoice-grid-gold td:nth-child(4) {
        width: 72px;
        min-width: 72px;
        max-width: 72px;
        padding-left: 4px;
        padding-right: 4px;
        text-align: center;
        white-space: nowrap;
    }

    /* Cột 5: Đơn giá */
    .invoice-grid-gold th:nth-child(5),
    .invoice-grid-gold td:nth-child(5) {
        width: 112px;
        min-width: 112px;
        white-space: nowrap;
    }

    .invoice-grid-gold th:nth-child(5) {
        text-align: center;
    }

    .invoice-grid-gold td:nth-child(5) {
        text-align: right;
    }

    /* Cột 6: Thành tiền */
    .invoice-grid-gold th:nth-child(6),
    .invoice-grid-gold td:nth-child(6) {
        width: 122px;
        min-width: 122px;
        white-space: nowrap;
    }

    .invoice-grid-gold th:nth-child(6) {
        text-align: center;
    }

    .invoice-grid-gold td:nth-child(6) {
        text-align: right;
    }

    /*
 * Bảo đảm mọi ô của bảng vàng giữ đúng vạch cột,
 * không làm thay đổi chiều rộng toàn trang.
 */
    .invoice-grid-gold th,
    .invoice-grid-gold td {
        vertical-align: middle;
    }

/* =========================================================
   KHỐI TỔNG TIỀN
   ========================================================= */

.invoice-totals {
    width: min(460px, 100%);
    margin: 16px 0 18px auto;
    border: 1px solid #111827;
    border-bottom: 0;
}

.invoice-total-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 180px;
    border-bottom: 1px solid #111827;
}

    .invoice-total-row > span,
    .invoice-total-row > strong {
        padding: 8px 10px;
    }

    .invoice-total-row > strong {
        border-left: 1px solid #111827;
        text-align: right;
    }

.invoice-total-payment {
    font-size: 13px;
}

/* =========================================================
   QR CODE
   ========================================================= */

.invoice-qr-wrapper {
    position: relative;
}

.invoice-qr-box {
    position: absolute;
    top: 68px;
    right: max( 24px, calc((100% - min(210mm, 100%)) / 2 + 24px) );
    z-index: 5;
    width: 104px;
    text-align: center;
}

.invoice-qr-placeholder {
    display: grid;
    width: 88px;
    height: 88px;
    margin: 0 auto 4px;
    place-items: center;
    border: 1px solid #111827;
    background: #fff;
}

    .invoice-qr-placeholder i {
        font-size: 72px;
        line-height: 1;
    }

.invoice-qr-code,
.invoice-qr-url {
    overflow: hidden;
    color: #111827;
    font-size: 8px;
    line-height: 1.25;
    text-overflow: ellipsis;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 767.98px) {
    .invoice-preview-toolbar {
        position: static;
        align-items: stretch;
        flex-direction: column;
    }

    .invoice-preview-toolbar-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .invoice-preview-toolbar .btn {
        width: 100%;
    }

    .invoice-paper-a4 {
        min-height: 0;
        overflow-x: auto;
    }

    /*
     * Mẫu thông thường giữ chiều rộng tối thiểu để xem trên điện thoại.
     */
    .invoice-grid {
        min-width: 760px;
    }

    /*
     * Mẫu nhiều cột cần rộng hơn.
     */
    .invoice-grid-many-columns {
        min-width: 1020px;
    }

    /*
     * Mẫu vàng vẫn giữ tỷ lệ cột đã chỉnh,
     * không co toàn bảng thành một khối nhỏ.
     */
    .invoice-grid-gold {
        min-width: 760px;
    }

    .invoice-qr-box {
        position: static;
        width: 100%;
        margin: 0 auto 12px;
    }
}

/* =========================================================
   CHẾ ĐỘ IN
   ========================================================= */

@media print {
    @page {
        size: A4;
        margin: 8mm;
    }

    body {
        background: #fff !important;
    }

    .no-print,
    .customer-navbar,
    .customer-alert {
        display: none !important;
    }

    .customer-main {
        padding: 0 !important;
    }

    .invoice-paper-a4 {
        width: 100%;
        min-height: auto;
        margin: 0;
        box-shadow: none !important;
    }

    .invoice-grid {
        font-size: 10px;
    }

    .invoice-grid-many-columns {
        font-size: 8.5px;
    }

    /*
     * Khi in mẫu vàng vẫn giữ nguyên tỷ lệ cột.
     */
    .invoice-grid-gold {
        width: 100%;
        table-layout: auto;
    }

        .invoice-grid-gold th:nth-child(1),
        .invoice-grid-gold td:nth-child(1) {
            width: 30px;
            min-width: 30px;
            max-width: 30px;
        }

        .invoice-grid-gold th:nth-child(3),
        .invoice-grid-gold td:nth-child(3) {
            width: 58px;
            min-width: 58px;
            max-width: 58px;
        }

        .invoice-grid-gold th:nth-child(4),
        .invoice-grid-gold td:nth-child(4) {
            width: 62px;
            min-width: 62px;
            max-width: 62px;
        }

        .invoice-grid-gold th:nth-child(5),
        .invoice-grid-gold td:nth-child(5) {
            width: 96px;
            min-width: 96px;
        }

        .invoice-grid-gold th:nth-child(6),
        .invoice-grid-gold td:nth-child(6) {
            width: 106px;
            min-width: 106px;
        }
}
/* =========================================================
   MOBIFONE VAT ÍT CỘT
   Chỉ điều chỉnh tỷ lệ cột, giữ nguyên khổ hóa đơn
   ========================================================= */

.invoice-grid-few-columns {
    width: 100%;
    table-layout: auto;
}

    /* STT */
    .invoice-grid-few-columns th:nth-child(1),
    .invoice-grid-few-columns td:nth-child(1) {
        width: 38px;
        min-width: 38px;
        max-width: 38px;
        padding-left: 3px;
        padding-right: 3px;
        text-align: center;
        white-space: nowrap;
    }

    /* Tên hàng hóa, dịch vụ */
    .invoice-grid-few-columns th:nth-child(2),
    .invoice-grid-few-columns td:nth-child(2) {
        width: auto;
        padding-left: 9px;
        padding-right: 9px;
        white-space: normal;
        word-break: normal;
        overflow-wrap: break-word;
        line-height: 1.45;
    }

    .invoice-grid-few-columns th:nth-child(2) {
        text-align: center;
    }

    .invoice-grid-few-columns td:nth-child(2) {
        text-align: left;
    }

    /* Đơn vị tính */
    .invoice-grid-few-columns th:nth-child(3),
    .invoice-grid-few-columns td:nth-child(3) {
        width: 62px;
        min-width: 62px;
        max-width: 62px;
        padding-left: 4px;
        padding-right: 4px;
        text-align: center;
        white-space: nowrap;
    }

    /* Số lượng */
    .invoice-grid-few-columns th:nth-child(4),
    .invoice-grid-few-columns td:nth-child(4) {
        width: 70px;
        min-width: 70px;
        max-width: 70px;
        padding-left: 4px;
        padding-right: 4px;
        text-align: center;
        white-space: nowrap;
    }

    /* Đơn giá */
    .invoice-grid-few-columns th:nth-child(5),
    .invoice-grid-few-columns td:nth-child(5) {
        width: 112px;
        min-width: 112px;
        white-space: nowrap;
    }

    .invoice-grid-few-columns th:nth-child(5) {
        text-align: center;
    }

    .invoice-grid-few-columns td:nth-child(5) {
        text-align: right;
    }

    /* Thành tiền */
    .invoice-grid-few-columns th:nth-child(6),
    .invoice-grid-few-columns td:nth-child(6) {
        width: 122px;
        min-width: 122px;
        white-space: nowrap;
    }

    .invoice-grid-few-columns th:nth-child(6) {
        text-align: center;
    }

    .invoice-grid-few-columns td:nth-child(6) {
        text-align: right;
    }

@media print {
    .invoice-grid-few-columns {
        width: 100%;
        table-layout: auto;
    }

        .invoice-grid-few-columns th:nth-child(1),
        .invoice-grid-few-columns td:nth-child(1) {
            width: 30px;
            min-width: 30px;
            max-width: 30px;
        }

        .invoice-grid-few-columns th:nth-child(3),
        .invoice-grid-few-columns td:nth-child(3) {
            width: 54px;
            min-width: 54px;
            max-width: 54px;
        }

        .invoice-grid-few-columns th:nth-child(4),
        .invoice-grid-few-columns td:nth-child(4) {
            width: 60px;
            min-width: 60px;
            max-width: 60px;
        }

        .invoice-grid-few-columns th:nth-child(5),
        .invoice-grid-few-columns td:nth-child(5) {
            width: 96px;
            min-width: 96px;
        }

        .invoice-grid-few-columns th:nth-child(6),
        .invoice-grid-few-columns td:nth-child(6) {
            width: 106px;
            min-width: 106px;
        }
}