@page split-page {
    size: A4 portrait;
    margin: 10mm;
}

@media print {
    body {
        font-size: 12pt;
        background: #fff;
        color: #000;
        margin: 0;
        padding: 0;
    }

    table {
        width: 100%;
        border-collapse: collapse;
    }

    th,
    td {
        border: 1px solid #000;
        padding: 5px;
    }

    nav,
    footer,
    .no-print,
    aside,
    header {
        display: none !important;
    }

    .print-table {
        page-break-before: always;
    }

    /* Splitsbrief (bestaande pagina) */
    .split-print-layout {
        page: split-page;
    }

    /* === Splitsbrieven standalone print === */
    .split-standalone-print {
        padding: 0;
        margin: 0;
    }

    .split-page-a4 {
        width: 100%;
        box-sizing: border-box;
        padding: 8mm;
        page-break-inside: avoid;
        break-inside: avoid;
        overflow: hidden;
    }

    .split-page-a4 + .split-page-a4 {
        page-break-before: always;
        break-before: page;
    }

    /* Flexbox ipv grid: CSS Grid 1fr resolved niet betrouwbaar in print context */
    .split-page-grid {
        display: flex;
        flex-wrap: wrap;
        gap: 4mm;
        width: 100%;
    }

    .split-page-grid > * {
        width: calc(50% - 2mm);
    }

    .split-page-table-header {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        font-weight: bold;
        font-size: 7pt;
        padding: 0.5mm 1.5mm;
        background: #d9d9d9 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .split-standalone-print table {
        width: 100% !important;
        border-collapse: separate !important;
        border-spacing: 0;
        empty-cells: show;
        font-size: 6pt;
        border-top: 1px solid #000;
        border-left: 1px solid #000;
        table-layout: fixed;
    }

    .split-standalone-print th,
    .split-standalone-print td {
        border-right: 1px solid #000;
        border-bottom: 1px solid #000;
    }

    .split-standalone-print th {
        background: #d9d9d9 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        font-size: 5pt;
        font-weight: bold;
        text-transform: uppercase;
        padding: 0.5mm 1mm;
        height: 4mm;
    }

    .split-standalone-print td {
        padding: 0.3mm 1mm;
        height: 5mm;
    }

    .split-standalone-print th:nth-child(1) { width: 10%; }
    .split-standalone-print th:nth-child(2) { width: 8%; }
    .split-standalone-print th:nth-child(3) { width: 40%; }
    .split-standalone-print th:nth-child(4) { width: 42%; }

    .split-standalone-print .split-separator-row td {
        background: #e8e8e8 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        height: 5mm;
        padding: 0;
    }

    .split-standalone-print .split-footer-row td {
        background: #1e3a5f !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        color: #fff;
        font-weight: bold;
        font-size: 5pt;
        padding: 0.5mm 1.5mm;
    }

    /* === Bestellingen print === */
    .order-print-layout {
        padding: 0;
        margin: 0;
    }

    .order-page-block {
        width: 100%;
        box-sizing: border-box;
        padding: 5mm;
        break-inside: avoid;
    }

    .order-page-block + .order-page-block {
        break-before: page;
    }

    .order-page-header-row {
        display: flex;
    }

    .order-page-header-row .order-page-header {
        flex: 1;
    }

    .order-page-header {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        font-weight: bold;
        font-size: 10pt;
        padding: 1mm 0 2mm;
        border-bottom: 2px solid #000;
        margin-bottom: 1.5mm;
    }

    .order-page-route {
        font-weight: normal;
        font-size: 8pt;
    }

    .order-print-layout table {
        width: 100%;
        border-collapse: separate !important;
        border-spacing: 0;
        empty-cells: show;
        font-size: 8pt;
        border-left: 1px solid #000;
        table-layout: fixed;
    }

    .order-print-layout th {
        border-top: 1px solid #000;
    }

    .order-print-layout th,
    .order-print-layout td {
        border-right: 1px solid #000;
        border-bottom: 1px solid #000;
    }

    .order-print-layout th {
        background: #d9d9d9 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        font-size: 7pt;
        font-weight: bold;
        text-transform: uppercase;
        padding: 1mm 1.5mm;
    }

    /* Kolombreedte: Aantal, Kg, Product|Partij, +/-, Stuks, Dag, Prijs, SAP */
    .order-print-layout th:nth-child(1) { width: 9%; }
    .order-print-layout th:nth-child(2) { width: 7%; }
    .order-print-layout th:nth-child(3) { width: auto; }
    .order-print-layout th:nth-child(4) { width: 7%; }
    .order-print-layout th:nth-child(5) { width: 9%; }
    .order-print-layout th:nth-child(6) { width: 7%; }
    .order-print-layout th:nth-child(7) { width: 11%; }

    .order-print-layout td {
        padding: 0.8mm 1.5mm;
    }

    .order-print-layout tr:nth-child(even) td {
        background: #f2f2f2 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .order-print-layout td:nth-child(3) {
        font-weight: 500;
    }

    .order-print-layout th.order-sap-col,
    .order-print-layout td.order-sap-col,
    .order-print-layout tr:nth-child(even) td.order-sap-col {
        border: none !important;
        background: transparent !important;
        padding: 0 0 0 1mm;
        font-size: 7pt;
        font-weight: bold;
        width: 5mm;
    }
}

/* === Screen preview only === */
@media screen {
    /* Shared print toolbar */
    .print-toolbar {
        position: sticky;
        top: 0;
        z-index: 10;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 24px;
        padding: 14px 24px;
        background: #fff;
        border-bottom: 1px solid #ccc;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    }

    /* === Bestellingen screen preview === */
    .order-print-layout {
        background: #e8e8e8;
        min-height: 100vh;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    }

    .order-page-block {
        width: 148mm;
        min-height: 105mm;
        background: #fff;
        margin: 16px auto;
        padding: 5mm;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        box-sizing: border-box;
        border: 1px solid #bbb;
    }

    .order-page-header {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        font-weight: bold;
        font-size: 12px;
        padding: 2px 0 4px;
        border-bottom: 2px solid #000;
        margin-bottom: 6px;
    }

    .order-page-route {
        font-weight: normal;
        color: #555;
    }

    .order-print-layout table {
        width: 100%;
        border-collapse: separate;
        border-spacing: 0;
        empty-cells: show;
        font-size: 11px;
        border-left: 1px solid #999;
        table-layout: fixed;
    }

    .order-print-layout th {
        border-top: 1px solid #999;
    }

    .order-print-layout th,
    .order-print-layout td {
        border-right: 1px solid #999;
        border-bottom: 1px solid #999;
    }

    .order-print-layout th {
        background: #d9d9d9;
        font-size: 10px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.02em;
        padding: 3px 6px;
        color: #333;
    }

    /* Kolombreedte: Aantal, Kg, Product|Partij, +/-, Stuks, Dag, Prijs, SAP */
    .order-print-layout th:nth-child(1) { width: 9%; }
    .order-print-layout th:nth-child(2) { width: 7%; }
    .order-print-layout th:nth-child(3) { width: auto; }
    .order-print-layout th:nth-child(4) { width: 7%; }
    .order-print-layout th:nth-child(5) { width: 9%; }
    .order-print-layout th:nth-child(6) { width: 7%; }
    .order-print-layout th:nth-child(7) { width: 11%; }

    .order-print-layout td {
        padding: 2px 6px;
        line-height: 1.4;
    }

    .order-print-layout tr:nth-child(even) td {
        background: #f5f7fa;
    }

    .order-print-layout tr:hover td {
        background: #e8f0fe;
    }

    .order-print-layout td:nth-child(3) {
        font-weight: 500;
    }

    .order-print-layout th.order-sap-col,
    .order-print-layout td.order-sap-col,
    .order-print-layout tr:nth-child(even) td.order-sap-col,
    .order-print-layout tr:hover td.order-sap-col {
        border: none;
        background: transparent !important;
        padding: 0 0 0 4px;
        font-size: 10px;
        font-weight: bold;
        width: 20px;
    }

    .order-page-header-row {
        display: flex;
        align-items: baseline;
        gap: 8px;
    }

    .order-page-header-row .order-page-header {
        flex: 1;
    }

    .order-page-checkbox {
        width: 16px;
        height: 16px;
        cursor: pointer;
        flex-shrink: 0;
        margin-top: 2px;
    }

    /* === Splitsbrieven screen preview === */
    .split-standalone-print {
        background: #e8e8e8;
        min-height: 100vh;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    }

    .split-page-a4 {
        width: 210mm;
        min-height: 297mm;
        background: #fff;
        margin: 16px auto;
        padding: 8mm;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        box-sizing: border-box;
        border: 1px solid #bbb;
    }

    .split-page-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
        gap: 8px;
        height: 100%;
    }

    .split-page-block {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .split-page-table-header {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        font-weight: bold;
        font-size: 10px;
        padding: 3px 6px;
        background: #d9d9d9;
    }

    .split-standalone-print table {
        width: 100%;
        border-collapse: separate;
        border-spacing: 0;
        empty-cells: show;
        font-size: 9px;
        border-top: 1px solid #999;
        border-left: 1px solid #999;
        table-layout: fixed;
        flex: 1;
    }

    .split-standalone-print th,
    .split-standalone-print td {
        border-right: 1px solid #999;
        border-bottom: 1px solid #999;
    }

    .split-standalone-print th {
        background: #d9d9d9;
        font-size: 8px;
        font-weight: 600;
        text-transform: uppercase;
        padding: 2px 4px;
        color: #333;
    }

    .split-standalone-print td {
        padding: 1px 4px;
        line-height: 1.3;
        height: 18px;
    }

    .split-standalone-print th:nth-child(1) { width: 10%; }
    .split-standalone-print th:nth-child(2) { width: 8%; }
    .split-standalone-print th:nth-child(3) { width: 40%; }
    .split-standalone-print th:nth-child(4) { width: 42%; }

    .split-standalone-print .split-separator-row td {
        background: #e8e8e8;
        height: 18px;
        padding: 0;
    }

    .split-standalone-print .split-footer-row td {
        background: #1e3a5f;
        color: #fff;
        font-weight: bold;
        font-size: 8px;
        padding: 2px 6px;
    }
}
