@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;
        gap: 4mm;
        width: 100%;
    }

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

    /* MOE-353: each column stacks its tables independently (masonry) */
    .split-page-column {
        display: flex;
        flex-direction: column;
        gap: 4mm;
    }

    .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;
    }

    /* MOE-353: +/- (2) wider than Stuks (1) — room to write corrections by hand */
    .split-standalone-print th.col-stuks { width: 10%; }
    .split-standalone-print th.col-diff { width: 12%; }
    .split-standalone-print th.col-artikel { width: 39%; }
    .split-standalone-print th.col-naam { width: 39%; }

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

    /* MOE-344: comments stand out in bold; a long word may break instead of overflowing */
    .split-standalone-print .split-comment-row td {
        font-weight: bold;
        overflow-wrap: anywhere;
    }

    .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;
    }

    /* MOE-353: rows size to their content (tables are no longer a fixed 18
       rows), top-aligned like the printed flex layout */
    .split-page-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: start;
        gap: 8px;
    }

    /* MOE-353: each column stacks its tables independently (masonry) */
    .split-page-column {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .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;
    }

    /* MOE-353: +/- (2) wider than Stuks (1) — room to write corrections by hand */
    .split-standalone-print th.col-stuks { width: 10%; }
    .split-standalone-print th.col-diff { width: 12%; }
    .split-standalone-print th.col-artikel { width: 39%; }
    .split-standalone-print th.col-naam { width: 39%; }

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

    /* MOE-344: comments stand out in bold; a long word may break instead of overflowing */
    .split-standalone-print .split-comment-row td {
        font-weight: bold;
        overflow-wrap: anywhere;
    }

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

/* === MOE-341: stickers (splitsbrief print page) === */
/* One label per page, like the customer's current stickers: three centred
   lines in one font and one size, lower case, no frame. The label size comes
   from STICKER_WIDTH/STICKER_HEIGHT in services/splitStickers.ts (inline). */
.sticker-page {
    box-sizing: border-box;
    padding: 3mm 5mm;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    overflow: hidden;
    overflow-wrap: break-word;
    font-family: Calibri, Carlito, 'Segoe UI', Arial, sans-serif;
    font-weight: normal;
    line-height: 1.1;
    text-transform: lowercase;
    color: #000;
    background: #fff;
}

.sticker-line {
    max-width: 100%;
}

/* Like on the photo: amount and product sit together, the customer name
   below them with more white space. */
.sticker-line:nth-child(3) {
    margin-top: 1em;
}

.sticker-lg {
    font-size: 26pt;
}

.sticker-md {
    font-size: 21pt;
}

.sticker-sm {
    font-size: 16pt;
}

@media screen {
    /* The sticker sheet only exists for the print; the screen keeps showing
       the split tables (and the scroll position) while the dialog is open. */
    .sticker-sheet {
        display: none;
    }

    /* The split tables use table-layout: fixed, so the checkbox column needs
       room: the same 4 columns scaled to 96%, plus 4% for the checkbox. In
       print the checkbox column is display:none and the normal widths apply. */
    .split-standalone-print .split-select-mode th.split-select-cell { width: 4%; }
    .split-standalone-print .split-select-mode th.col-stuks { width: 9.6%; }
    .split-standalone-print .split-select-mode th.col-diff { width: 11.52%; }
    .split-standalone-print .split-select-mode th.col-artikel { width: 37.44%; }
    .split-standalone-print .split-select-mode th.col-naam { width: 37.44%; }

    .split-select-cell {
        text-align: center;
        padding: 0 !important;
    }

    .split-select-cell input {
        width: 12px;
        height: 12px;
        margin: 0;
        cursor: pointer;
        vertical-align: middle;
    }

    /* Negative vertical margins keep the title bar at its normal height. */
    .split-select-all {
        margin-right: 6px;
        font-weight: normal;
        cursor: pointer;
    }

    .split-select-all input {
        width: 10px;
        height: 10px;
        margin: -2px 3px -2px 0;
        vertical-align: middle;
        cursor: pointer;
    }
}

@media print {
    .sticker-sheet {
        margin: 0;
        padding: 0;
    }

    .sticker-printing .split-page-a4 {
        display: none;
    }

    .sticker-page {
        break-after: page;
        page-break-after: always;
    }

    .sticker-page:last-child {
        break-after: auto;
        page-break-after: auto;
    }
}
