/* EMS Bill of Consignment - Export Page */

.export-page {
    font-family: Arial, Helvetica, sans-serif;
    background: #e9ecef;
    min-height: 100vh;
    padding: 20px;
}

.export-workspace {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    justify-content: center;
    align-items: flex-start;
    max-width: 1280px;
    margin: 0 auto;
}

.bill-preview-panel {
    flex: 1 1 480px;
    min-width: 320px;
    max-width: 100%;
}

.bill-preview-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #444;
    margin-bottom: 8px;
    text-align: center;
}

.bill-preview-empty {
    background: #fff;
    border: 2px dashed #ced4da;
    border-radius: 8px;
    padding: 48px 24px;
    text-align: center;
    color: #888;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.bill-preview-empty p {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #666;
}

.bill-preview-empty span {
    font-size: 0.85rem;
    line-height: 1.4;
}

/* ---- Toolbar ---- */

.export-toolbar {
    flex: 0 0 420px;
    max-width: 100%;
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    color: #333;
}

.export-toolbar__title {
    margin: 0 0 16px;
    font: inherit;
    line-height: 1.4;
}

.export-toolbar .form-label {
    font: inherit;
    margin-bottom: 4px;
    display: block;
}

.export-toolbar .form-control {
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 400;
    display: block;
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    box-sizing: border-box;
    color: #333;
}

.export-toolbar select.form-control {
    background: #fff;
    cursor: pointer;
}

.export-hint {
    font: inherit;
    font-weight: 400;
    color: #666;
    margin: 6px 0 0;
    line-height: 1.4;
}

.export-print-tip {
    font: inherit;
    font-weight: 400;
    color: #856404;
    background: #fff3cd;
    border: 1px solid #ffecb5;
    border-radius: 4px;
    padding: 6px 8px;
    margin-top: 8px;
    line-height: 1.4;
}

.export-alert {
    background: #f8d7da;
    color: #842029;
    border: 1px solid #f5c2c7;
    border-radius: 4px;
    padding: 8px 10px;
    font: inherit;
    font-weight: 400;
    margin-bottom: 12px;
}

.export-status {
    border-radius: 4px;
    padding: 8px 10px;
    font: inherit;
    font-weight: 400;
    margin-bottom: 12px;
    text-align: center;
}

.barcode-scan-input {
    letter-spacing: normal;
}

.barcode-input-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.barcode-input-row .barcode-scan-input {
    flex: 1;
}

.btn-camera {
    flex-shrink: 0;
    width: 48px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: #f8f9fa;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    padding: 0;
}

.btn-camera:hover { background: #e9ecef; }
.btn-camera:disabled { opacity: 0.5; cursor: not-allowed; }

.export-toolbar .row { display: flex; gap: 8px; }
.export-toolbar .col-4 { flex: 1; }
.export-toolbar .mb-2 { margin-bottom: 10px; }
.export-toolbar .text-danger { color: #dc3545; }

/* ---- Scan table ---- */

.scan-table-wrap {
    border: 1px solid #dee2e6;
    border-radius: 6px;
    overflow: hidden;
    background: #f8f9fa;
}

.scan-table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: #fff;
    border-bottom: 1px solid #dee2e6;
    font-size: 0.8rem;
    font-weight: 600;
}

.btn-link-sm {
    border: none;
    background: none;
    color: #dc3545;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.btn-link-sm:disabled {
    color: #adb5bd;
    cursor: not-allowed;
    text-decoration: none;
}

.scan-table-scroll {
    max-height: 220px;
    overflow-y: auto;
    background: #fff;
}

.scan-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
    font-weight: 400;
}

.scan-table th,
.scan-table td {
    padding: 6px 8px;
    border-bottom: 1px solid #eee;
    text-align: left;
    vertical-align: middle;
}

.scan-table th {
    background: #f1f3f5;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.scan-table__col-no {
    width: 28px;
    text-align: center;
    color: #888;
}

.scan-table__col-weight {
    width: 72px;
}

.scan-table__col-action {
    width: 32px;
    text-align: center;
}

.scan-table__code {
    font-weight: 600;
    word-break: break-all;
}

.scan-weight-input {
    padding: 4px 6px !important;
    font-size: 0.78rem !important;
    text-align: center;
}

.scan-table__empty td {
    text-align: center;
    color: #aaa;
    font-style: italic;
    padding: 16px 8px;
}

.btn-remove-scan {
    border: none;
    background: #f8d7da;
    color: #842029;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0;
}

.btn-remove-scan:hover {
    background: #f5c2c7;
}

#billsPrintArea {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.bill-print-item {
    width: 100%;
    display: flex;
    justify-content: center;
}

.export-toolbar .btn {
    display: inline-block;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    color: #fff;
}

.export-toolbar .btn-primary { background: #0d6efd; }
.export-toolbar .btn-success { background: #198754; }
.export-toolbar .btn-success:disabled { background: #adb5bd; cursor: not-allowed; opacity: 0.7; }
.export-toolbar .btn-secondary { background: #6c757d; }
.export-toolbar .btn:hover { opacity: 0.9; }
.export-actions { display: flex; gap: 8px; margin-top: 16px; }

/* Camera modal */
body.camera-open { overflow: hidden; }

.camera-modal {
    position: fixed;
    inset: 0;
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.camera-modal[hidden] { display: none !important; }

.camera-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

.camera-modal__dialog {
    position: relative;
    width: 100%;
    max-width: 480px;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

.camera-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid #dee2e6;
}

.camera-modal__title { margin: 0; font-size: 0.95rem; font-weight: 600; }

.camera-modal__close {
    border: none;
    background: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: #666;
    padding: 0 4px;
}

.camera-modal__body { display: flex; flex-direction: column; }

#cameraScanner {
    width: 100%;
    min-height: 280px;
    background: #000;
}

.camera-modal__feedback {
    min-height: 56px;
    padding: 12px;
    text-align: center;
    font-size: 0.9rem;
}

.camera-feedback-success { font-weight: 600; color: #155724; }

/* Trang in popup — chỉ phiếu */
body.print-popup {
    margin: 0;
    padding: 0;
    background: #fff;
    display: flex;
    justify-content: center;
}

body.print-popup .bill-of-consignment {
    box-shadow: none;
}

/* Phiếu bưu gửi EMS VISA — mẫu A5, in ngang (landscape) */

.bill-wrapper {
    display: flex;
    justify-content: center;
    padding: 0;
}

.bill-of-consignment {
    width: 148mm;
    min-width: 148mm;
    background: #fff;
    --bill-border: 0.35pt solid #c5c5c5;
    --bill-border-dots: 0.35pt dotted #b8b8b8;
    border: var(--bill-border);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 7pt;
    line-height: 1.35;
    color: #000;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    box-sizing: border-box;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* Header: logo trái | tiêu đề giữa | barcode ngang phải */
.bill-header {
    display: grid;
    grid-template-columns: 24mm 1fr 50mm;
    align-items: start;
    border-bottom: var(--bill-border);
    padding: 2mm;
    gap: 2mm;
}

.bill-header__logo {
    display: flex;
    align-items: center;
    padding-top: 0.5mm;
}

.bill-logo-img {
    display: block;
    max-width: 30mm;
    width: 100%;
    height: auto;
    max-height: 11mm;
    object-fit: contain;
}

.bill-header__title {
    text-align: center;
    font-weight: bold;
    font-size: 8pt;
    padding-top: 2.5mm;
    line-height: 1.2;
}

.bill-header__track {
    font-size: 6pt;
    text-align: right;
}

.bill-ed-row {
    display: flex;
    align-items: baseline;
    justify-content: flex-end;
    gap: 2px;
    margin-bottom: 0.5mm;
}

.bill-ed-label { font-style: italic; flex-shrink: 0; }

.bill-dots-inline--ed {
    flex: 0 1 14mm;
    min-width: 8mm;
    min-height: 1em;
    border-bottom: var(--bill-border-dots);
}

.bill-barcode-h {
    text-align: right;
    overflow: hidden;
    line-height: 0;
}

.bill-barcode-h svg {
    display: block;
    width: 100%;
    max-width: 46mm;
    height: auto;
    max-height: 10mm;
    margin-left: auto;
}

.bill-tracking-h {
    font-weight: bold;
    font-size: 7pt;
    text-align: right;
    letter-spacing: 0.3px;
    margin-top: 0.5mm;
    line-height: 1.3;
}

.bill-sendfrom-row {
    font-size: 6.5pt;
    text-align: right;
    margin-top: 0.5mm;
}

/* Người gửi | Người nhận */
.bill-parties {
    border-bottom: var(--bill-border);
}

.bill-parties__service-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: baseline;
    padding: 1.5mm 2mm;
    border-bottom: var(--bill-border);
}

.bill-parties__service-row .bill-line {
    margin-bottom: 0;
}

.bill-parties__sendfrom {
    font-size: 6.5pt;
    text-align: right;
}

.bill-parties__cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 38mm;
}

.bill-sender,
.bill-receiver {
    padding: 2mm;
}

.bill-sender { border-right: var(--bill-border); }

.bill-line { margin-bottom: 0.5mm; word-break: break-word; }

.bill-line--phone,
.bill-line--goods {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 2px;
}

.bill-lbl { font-weight: normal; }
.bill-lbl-en { font-style: italic; font-size: 6pt; }
.bill-val { font-weight: bold; }
.bill-unit { font-size: 6.5pt; }
.bill-receiver__title { margin-bottom: 1mm; }

.bill-dots {
    border-bottom: var(--bill-border-dots);
    min-height: 5mm;
    margin-bottom: 1mm;
}

.bill-dots-inline {
    flex: 1;
    border-bottom: var(--bill-border-dots);
    min-height: 1.1em;
    min-width: 12mm;
}

.bill-dots-inline--w {
    flex: 0 1 14mm;
    min-width: 10mm;
}

/* Hàng cuối: 4 cột dọc đều nhau */
.bill-bottom {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    min-height: 36mm;
    align-items: stretch;
}

.bill-bottom__content,
.bill-bottom__weight,
.bill-footer__cell {
    padding: 2mm;
    border-right: var(--bill-border);
    font-size: 5.5pt;
    line-height: 1.25;
}

.bill-bottom > :last-child {
    border-right: none;
}

.bill-footer__cell {
    display: flex;
    flex-direction: column;
    text-align: center;
}

.bill-bottom__content {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    font-size: 7pt;
    overflow: hidden;
}

.bill-content-label {
    flex-shrink: 0;
    margin-bottom: 0;
}

.bill-content-stamp-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 22mm;
    padding: 1mm 0;
}

.bill-content-stamp {
    border: 1.5pt solid #c00;
    color: #c00;
    padding: 2mm 5mm;
    text-align: center;
    font-weight: bold;
    font-size: 8pt;
    line-height: 1.25;
    letter-spacing: 0.2px;
    white-space: nowrap;
    transform: rotate(-16deg);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.bill-bottom__weight {
    font-size: 6.5pt;
}

.bill-weight-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 2px;
    margin-bottom: 0.3mm;
}

.bill-weight-unit {
    font-size: 6.5pt;
    margin-bottom: 2mm;
}

.bill-date-blank {
    margin: 0.2mm 0 0;
}

.bill-footer__sig {
    margin-top: 1mm;
    padding-top: 0;
    text-align: center;
}

.bill-footer__delivery {
    margin-top: auto;
    padding-top: 2mm;
    text-align: center;
    width: 100%;
}

.bill-footer__sig--last {
    margin-top: auto;
    padding-top: 2mm;
    text-align: center;
    width: 100%;
}

/* ---- Print root (clone bills here before printing) ---- */

.print-root {
    display: none;
}

body.printing-bill .export-page,
body.printing-bill .camera-modal {
    display: none !important;
}

body.printing-bill #printRoot {
    display: block;
}

@media print {
    @page {
        size: 210mm 148mm landscape;
        margin: 0;
    }

    html, body {
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
    }

    body > *:not(#printRoot) {
        display: none !important;
    }

    #printRoot {
        display: block !important;
        margin: 0;
        padding: 0;
    }

    #printRoot .bill-print-item {
        display: flex !important;
        justify-content: center;
        align-items: center;
        width: 210mm;
        height: 148mm;
        margin: 0;
        padding: 0;
        box-sizing: border-box;
        page-break-after: always;
        break-after: page;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    #printRoot .bill-print-item:last-child {
        page-break-after: auto;
        break-after: auto;
    }

    #printRoot .bill-of-consignment {
        width: 148mm !important;
        min-width: 148mm !important;
        max-width: 148mm !important;
        margin: 0 auto !important;
        padding: 0 !important;
        box-shadow: none !important;
        border: 0.35pt solid #c5c5c5 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .no-print {
        display: none !important;
    }

    .bill-header {
        display: grid !important;
        grid-template-columns: 24mm 1fr 50mm !important;
        border-bottom: 0.35pt solid #c5c5c5 !important;
    }

    .bill-parties {
        border-bottom: 0.35pt solid #c5c5c5 !important;
    }

    .bill-parties__service-row {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        border-bottom: 0.35pt solid #c5c5c5 !important;
    }

    .bill-parties__cols {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
    }

    .bill-sender {
        border-right: 0.35pt solid #c5c5c5 !important;
    }

    .bill-bottom {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
    }

    .bill-bottom__content,
    .bill-bottom__weight,
    .bill-footer__cell {
        border-right: 0.35pt solid #c5c5c5 !important;
        border-bottom: none !important;
    }

    .bill-bottom > :last-child {
        border-right: none !important;
    }

    .bill-dots,
    .bill-dots-inline,
    .bill-dots-inline--ed {
        border-bottom: 0.35pt dotted #b8b8b8 !important;
    }

    .bill-logo-img {
        display: block !important;
        max-width: 30mm !important;
        max-height: 11mm !important;
        object-fit: contain !important;
    }

    .bill-barcode-h svg {
        display: block !important;
        width: 46mm !important;
        max-width: 46mm !important;
        height: auto !important;
        max-height: 10mm !important;
        margin-left: auto !important;
    }

    .bill-content-stamp {
        border: 1.5pt solid #c00 !important;
        color: #c00 !important;
        transform: rotate(-16deg) !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

@media screen and (max-width: 900px) {
    .export-workspace {
        flex-direction: column;
        align-items: stretch;
    }

    .export-toolbar {
        flex: 1 1 auto;
        width: 100%;
    }

    .bill-of-consignment {
        width: 148mm;
        min-width: 0;
        max-width: 100%;
    }
}

@media screen and (max-width: 520px) {
    .bill-of-consignment {
        width: 100%;
        font-size: 6pt;
    }

    .bill-header {
        grid-template-columns: 20mm 1fr 40mm;
    }

    .bill-parties,
    .bill-parties__cols {
        grid-template-columns: 1fr;
    }

    .bill-bottom {
        grid-template-columns: 1fr;
    }

    .bill-bottom > * {
        border-right: none !important;
        border-bottom: var(--bill-border) !important;
    }

    .bill-bottom > :last-child {
        border-bottom: none !important;
    }

    .bill-parties__service-row {
        grid-template-columns: 1fr;
    }

    .bill-sender { border-right: none; border-bottom: var(--bill-border); }
}
