/**
 * CloudScale Cyber DevTools - Export to PDF
 *
 * Screen: the button. Print: every rule is scoped to body.csdt-pdf-printing, which only the
 * button sets, so the theme's own Ctrl+P output is untouched. See class-pdf-export.php.
 */

.csdt-pdf-bar {
    display: flex;
    justify-content: flex-end;
    margin: 0 0 1.2em;
}

.csdt-pdf-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    /* Adobe red, the colour people recognise as "PDF". #EB1000 is Adobe's current red and
     * carries white at 4.56:1 (WCAG AA); the older #FA0F00 does not (4.09:1). */
    border: 1px solid #eb1000;
    border-radius: 6px;
    background: #eb1000;
    color: #fff;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
}

.csdt-pdf-btn:hover,
.csdt-pdf-btn:focus-visible {
    background: #c70a00;
    border-color: #c70a00;
    color: #fff;
}

.csdt-pdf-btn:focus-visible {
    outline: 2px solid #eb1000;
    outline-offset: 2px;
}

.csdt-pdf-btn[hidden],
.csdt-pdf-source {
    display: none;
}

@media print {

    /* ── Only the article: everything off the path from <body> down to it is hidden ── */
    body.csdt-pdf-printing.csdt-pdf-path > :not(.csdt-pdf-path):not(.csdt-pdf-root),
    body.csdt-pdf-printing .csdt-pdf-path > :not(.csdt-pdf-path):not(.csdt-pdf-root) {
        display: none !important;
    }

    body.csdt-pdf-printing,
    body.csdt-pdf-printing .csdt-pdf-path,
    body.csdt-pdf-printing .csdt-pdf-root {
        display: block !important;
        position: static !important;
        float: none !important;
        width: auto !important;
        max-width: none !important;
        height: auto !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        box-shadow: none !important;
        transform: none !important;
        overflow: visible !important;
        background: #fff !important;
    }

    /* ── Inside the article: what a reader does not want on paper ── */
    body.csdt-pdf-printing .csdt-pdf-root :is(
        .csdt-pdf-bar, .cs-code-actions, nav, form, iframe, button, .ad-unit, ins.adsbygoogle,
        #comments, .comments-area, .comment-respond, .post-navigation, .navigation,
        .sharedaddy, .jp-relatedposts, .addtoany_share_save_container, .a2a_kit, .wp-block-buttons
    ) {
        display: none !important;
    }

    /* ── Source line: title only when the theme's title is outside the article ── */
    body.csdt-pdf-printing .csdt-pdf-source {
        display: block !important;
        margin: 0 0 14pt !important;
        font-size: 9pt !important;
        color: #555 !important;
    }

    body.csdt-pdf-printing .csdt-pdf-title {
        display: none;
    }

    body.csdt-pdf-printing .csdt-pdf-need-title .csdt-pdf-title {
        display: block;
        margin: 0 0 4pt;
        font-size: 22pt;
        font-weight: 700;
        line-height: 1.2;
        color: #111;
    }

    /* ── Type: dark ink on white, whatever the theme's screen colours ── */
    body.csdt-pdf-printing .csdt-pdf-root :is(p, li, td, th, blockquote, figcaption, dd, dt):not(pre *, .cs-code-wrapper *) {
        font-size: 11pt !important;
        line-height: 1.55 !important;
    }

    body.csdt-pdf-printing .csdt-pdf-root :is(p, li, td, th, blockquote, figcaption, dd, dt, h1, h2, h3, h4, h5, h6, span, strong, em, b, i, div):not(pre *, .cs-code-wrapper *) {
        color: #111 !important;
    }

    body.csdt-pdf-printing .csdt-pdf-root a:not(pre *, .cs-code-wrapper *) {
        color: #0645ad !important;
    }

    body.csdt-pdf-printing .csdt-pdf-root h1 { font-size: 22pt !important; line-height: 1.2 !important; }
    body.csdt-pdf-printing .csdt-pdf-root h2 { font-size: 16pt !important; line-height: 1.25 !important; margin-top: 16pt !important; }
    body.csdt-pdf-printing .csdt-pdf-root h3 { font-size: 13.5pt !important; line-height: 1.3 !important; margin-top: 12pt !important; }
    body.csdt-pdf-printing .csdt-pdf-root :is(h4, h5, h6) { font-size: 12pt !important; }

    /* ── Page breaks ──
     * A heading never ends a page: it moves to the next one with the text it introduces.
     * Paragraphs leave at least three lines at the foot of a page and carry three to the next.
     * Figures, tables, code blocks and diagrams that fit on a page stay whole; the script marks
     * those with csdt-pdf-keep, because a block taller than a page cannot be kept whole and
     * asking for it only leaves a blank page in front of the split.
     */
    body.csdt-pdf-printing .csdt-pdf-root :is(h1, h2, h3, h4, h5, h6) {
        break-after: avoid !important;
        page-break-after: avoid !important;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    body.csdt-pdf-printing .csdt-pdf-root :is(p, li, blockquote, dd) {
        orphans: 3;
        widows: 3;
    }

    body.csdt-pdf-printing .csdt-pdf-root .csdt-pdf-keep,
    body.csdt-pdf-printing .csdt-pdf-root :is(tr, li, figcaption, .cs-code-toolbar) {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    body.csdt-pdf-printing .csdt-pdf-root :is(figure, .wp-block-image) > img + figcaption,
    body.csdt-pdf-printing .csdt-pdf-root thead {
        break-before: avoid !important;
    }

    body.csdt-pdf-printing .csdt-pdf-root thead {
        display: table-header-group !important;
    }

    /* ── Media fit the page width, and an image never runs past the foot of a page ── */
    body.csdt-pdf-printing .csdt-pdf-root :is(img, svg, canvas, video) {
        max-width: 100% !important;
        height: auto !important;
    }

    body.csdt-pdf-printing .csdt-pdf-root img {
        max-height: 220mm !important;
        object-fit: contain;
    }

    /* A tall diagram drawn at full page width runs over three pages. Capped, its viewBox scales
     * the whole drawing down to fit one page, and the script's keep rule then holds. */
    body.csdt-pdf-printing .csdt-pdf-root :is(.cs-code-diagram svg, svg[viewBox], canvas) {
        max-height: 200mm !important;
    }

    /* On screen a wide diagram keeps a minimum width and scrolls sideways (keepMermaidReadable
     * in cs-code-block.js); paper cannot scroll, so on paper it shrinks to the page instead. */
    body.csdt-pdf-printing .csdt-pdf-root .cs-code-diagram svg {
        min-width: 0 !important;
    }

    body.csdt-pdf-printing .csdt-pdf-root .cs-code-diagram {
        overflow: visible !important;
        text-align: center;
    }

    body.csdt-pdf-printing .csdt-pdf-root table {
        width: 100% !important;
        border-collapse: collapse !important;
    }

    body.csdt-pdf-printing .csdt-pdf-root :is(td, th) {
        border: 1px solid #bbb !important;
        padding: 4pt 6pt !important;
    }

    /* ── Code blocks and diagrams print as they look on screen, wrapped rather than cut ── */
    body.csdt-pdf-printing .csdt-pdf-root :is(.cs-code-wrapper, .cs-code-diagram, pre, th) {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body.csdt-pdf-printing .csdt-pdf-root :is(.cs-code-body, pre) {
        max-height: none !important;
        overflow: visible !important;
    }

    body.csdt-pdf-printing .csdt-pdf-root pre,
    body.csdt-pdf-printing .csdt-pdf-root pre code {
        white-space: pre-wrap !important;
        overflow-wrap: anywhere !important;
        font-size: 8.5pt !important;
        line-height: 1.45 !important;
    }
}
