/* Print isolation + page-break rules. The @page margin rule itself is NOT
   here — it's injected at runtime into #page-rule-style (see app.js), because
   CSS custom properties inside @page have unreliable browser support, so the
   margin preset must be written as concrete values at print/preset-change time. */

@media print {
    /* display:none (not visibility:hidden) — visibility keeps the element's
       layout box, so the editor chrome (taller than one printed page) was
       silently inflating the print job with a trailing blank page. Hiding
       it by name actually removes it from flow. */
    .ctrl-topbar,
    .ctrl-databanner,
    #editor-column,
    #ctrl-resizer,
    .ctrl-preview-toolbar {
        display: none !important;
    }
    /* Drop the flex/height-100vh chain the editor layout relies on — under
       print it just adds residual padding/height above the sheet, which was
       enough on its own to push a short document onto a spurious 2nd page. */
    html, body {
        height: auto !important;
        overflow: visible !important;
    }
    .ctrl-layout, #preview-column, #doc-preview-scroll {
        display: block !important;
        height: auto !important;
        padding: 0 !important;
        /* #preview-column's base rule sets overflow:hidden (it's a scroll
           pane on screen) — an overflow:hidden ancestor combined with
           height:auto SHOULD just grow to fit all content with nothing
           visually clipped, but real browser print/paginate engines have
           had bugs where a hidden-overflow ancestor still caps content to
           one page's worth of height at the print/fragmentation boundary
           instead of letting it flow onto page 2+. #doc-preview-scroll had
           this reset already (below); #preview-column and .ctrl-layout
           didn't — closing that gap here rather than relying on it not
           mattering in every browser. */
        overflow: visible !important;
    }
    #doc-preview-scroll {
        background: none;
        border-radius: 0;
    }
    .doc-page {
        box-shadow: none;
        margin: 0;
        /* @page's own margin rule (injected by app.js, same values as this
           padding) already insets the physical printable area — keeping
           this padding too would inset it a SECOND time, narrowing the
           usable text width enough to force extra wrapped lines and, with
           them, spurious extra pages. On screen .doc-page is a full-size
           A4 mockup (padding = simulated margin); in print the page box
           IS already just the printable area, so the padding must be 0. */
        padding: 0;
        width: auto;
        min-height: 0;
        break-after: page;
        page-break-after: always;
    }
    .doc-page:last-child {
        break-after: auto;
        page-break-after: auto;
    }
    .doc-table,
    .doc-lettergrid,
    .doc-numberline,
    .doc-task-block {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    .doc-task-text {
        orphans: 3;
        widows: 3;
    }
}
