<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bill of Lading</title>
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }
        
        body {
            font-family: Arial, sans-serif;
            font-size: 12px;
            line-height: 1.4;
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
        }
        
        .container {
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 0;
        }
        
        .bol-preview {
            border: 1px solid black;
            padding: 5mm;
            width: 100%;
            height: 100%;
            box-sizing: border-box;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
        }
        
        .bol-title {
            text-align: center;
            color: #333;
            margin-bottom: 10px;
            font-size: 14px;
        }
        
        .header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;
            flex-wrap: nowrap;
        }
        .ship-from, .ship-to {
            width: 48%;
            flex-shrink: 0;
        }
        
        .ship-from h2, .ship-to h2 {
            font-size: 10px;
            margin-bottom: 3px;
        }
        
        .ship-from p {
            font-size: 8px;
            line-height: 1.2;
            margin: 0;
        }
        
        .ship-to p {
            font-size: 10px;
            line-height: 1.2;
            font-weight: bold;
            margin: 0;
        }
        
        .bol-number {
            text-align: center;
            margin: 10px 0;
        }
        
        .bol-number h2 {
            font-size: 10px;
            margin-bottom: 5px;
        }
        
        .barcode-container {
            text-align: center;
            margin: 5px 0;
        }
        
        .barcode {
            margin: 5px 0;
            text-align: center;
        }
        
        .barcode-content {
            font-size: 8px;
            margin-top: 3px;
        }
        
        .summary-table {
            width: 100%;
            border-collapse: collapse;
            margin: 10px 0;
        }
        
        .summary-table th, .summary-table td {
            border: 1px solid #000;
            padding: 2px;
            text-align: center;
            font-size: 8px;
        }
        
        h2 {
            font-size: 10px;
            margin: 10px 0 3px 0;
        }
        
        .details-table {
            width: 100%;
            border-collapse: collapse;
            margin: 10px 0;
            flex: 1;
            min-height: 0;
        }
        
        .details-table th:nth-child(1), .details-table td:nth-child(1) {
            width: 5%;
        }
        .details-table th:nth-child(2), .details-table td:nth-child(2),
        .details-table th:nth-child(4), .details-table td:nth-child(4),
        .details-table th:nth-child(6), .details-table td:nth-child(6) {
            width: 22%;
        }
        .details-table th:nth-child(3), .details-table td:nth-child(3),
        .details-table th:nth-child(5), .details-table td:nth-child(5),
        .details-table th:nth-child(7), .details-table td:nth-child(7) {
            width: 9%;
        }
        .details-table th, .details-table td {
            border: 1px solid #000;
            padding: 1px;
            text-align: center;
            font-size: 6px;
            word-break: break-all;
        }
        
        .details-table tbody {
            display: block;
            overflow-y: auto;
            max-height: 100%;
        }
        
        .details-table thead, .details-table tbody tr {
            display: table;
            width: 100%;
            table-layout: fixed;
        }
        
        .signature-area {
            display: flex;
            justify-content: space-between;
            margin: 10px 0;
            flex-wrap: nowrap;
        }
        .shipper-signature, .consignee-signature {
            width: 48%;
            border: 1px solid #000;
            padding: 3px;
            text-align: center;
            flex-shrink: 0;
        }
        
        .shipper-signature p, .consignee-signature p {
            font-size: 7px;
            margin: 0;
        }
        
        .notes {
            margin: 10px 0;
            border: 1px solid #000;
            padding: 3px;
        }
        
        .notes p {
            font-size: 8px;
            margin: 0;
        }
        
        @media print {
            @page {
                size: auto;
                margin: 0;
            }
            
            body {
                margin: 0 !important;
                padding: 0 !important;
                width: 100vw !important;
                height: 100vh !important;
                overflow: hidden !important;
                display: flex !important;
                justify-content: center !important;
                align-items: center !important;
                font-size: 14pt;
            }
            
            .container {
                width: 100% !important;
                height: 100% !important;
                padding: 0 !important;
            }
            
            .bol-preview {
                width: 100% !important;
                height: 100% !important;
                margin: 0 !important;
                padding: 5mm !important;
                border: 2px solid #000 !important;
                box-sizing: border-box !important;
                transform-origin: center !important;
                display: flex !important;
                flex-direction: column !important;
                position: relative !important;
                z-index: 1 !important;
            }
            
            .bol-title {
                font-size: 18pt !important;
            }
            
            h2 {
                font-size: 14pt !important;
            }
            
            .ship-from p, .ship-to p {
                font-size: 12pt !important;
            }
            
            .bol-number p {
                font-size: 12pt !important;
            }
            
            .summary-table th, .summary-table td {
                font-size: 12pt !important;
                padding: 4px !important;
                border: 1px solid #000 !important;
            }
            
            .details-table th, .details-table td {
                font-size: 10pt !important;
                padding: 3px !important;
                border: 1px solid #000 !important;
            }
            
            .shipper-signature p, .consignee-signature p {
                font-size: 12pt !important;
            }
            
            .notes p {
                font-size: 12pt !important;
            }
            
            .details-table {
                flex: 1 !important;
                min-height: 0 !important;
                border: 1px solid #000 !important;
            }
            
            .details-table tbody {
                display: block !important;
                overflow-y: auto !important;
                max-height: 100% !important;
            }
            
            .details-table thead, .details-table tbody tr {
                display: table !important;
                width: 100% !important;
                table-layout: fixed !important;
            }
            
            .details-table thead {
                border: 1px solid #000 !important;
            }
            
            .signature-area {
                border: 1px solid #000 !important;
            }
            
            .shipper-signature, .consignee-signature {
                border: 1px solid #000 !important;
            }
            
            .notes {
                border: 1px solid #000 !important;
            }
        }
        
        @media print {
            body {
                margin: 0;
                padding: 0;
            }
            @page {
                size: A4; /* 设置页面大小为A4 */
                margin: 0; /* 移除默认边距 */
            }
        }
        
        /* 针对不同纸张尺寸的媒体查询 */
        @media print and (width: 210mm) and (height: 297mm) {
            /* A4 纸张 */
            body {
                font-size: 11pt;
            }
        }
        
        @media print and (width: 216mm) and (height: 279mm) {
            /* Letter 纸张 */
            body {
                font-size: 12pt;
            }
        }
        
        @media print and (width: 100mm) and (height: 150mm) {
            /* 100mm x 150mm 纸张 */
            body {
                font-size: 8pt;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="bol-preview">
            <h1 class="bol-title">BILL OF LADING</h1>
            
            <div class="header">
                <div class="ship-from">
                    <h2>Ship From:</h2>
                    <p>Parcel Express<br>
                    730 N Edgewood Ave.<br>
                    Wood Dale, IL, 60191<br>
                    (312) 522-5808</p>
                </div>
                
                <div class="ship-to">
                    <h2>Ship To:</h2>
                    <p>{{channel}}</p>
                </div>
            </div>
            
            <div class="bol-number">
                <h2>Bill of Lading Number</h2>
                <div class="barcode-container">
                    <img id="barcode" src="data:image/png;base64,{{barcodeBase64}}" alt="Barcode">
                    <div class="barcode-content">{{bolNumber}}</div>
                </div>
            </div>
            
            <table class="summary-table">
                <thead>
                    <tr>
                        <th>Bill of Lading Number</th>
                        <th>Total Boxes</th>
                        <th>Total Pallets</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>{{bolNumber}}</td>
                        <td>{{bagTagCount}}</td>
                        <td>0</td>
                    </tr>
                </tbody>
            </table>
            
            <h2>BOL Number/MAWB/Container Number</h2>
            <table class="details-table">
                <thead>
                    <tr>
                        <th>Item</th>
                        <th>MAWB/Container Number</th>
                        <th>Items No.</th>
                        <th>MAWB/Container Number</th>
                        <th>Items No.</th>
                        <th>MAWB/Container Number</th>
                        <th>Items No.</th>
                    </tr>
                </thead>
                <tbody>
                    {{bagTagTableRows}}
                </tbody>
            </table>
            
            <div class="signature-area">
                <div class="shipper-signature">
                    <p>Shipper Signature + Time</p>
                </div>
                <div class="consignee-signature">
                    <p>Consignee Signature + Time</p>
                </div>
            </div>
            
            <div class="notes">
                <p>Notes (Tag Number) :</p>
            </div>
        </div>
    </div>
</body>
</html>