/**
 * Print stylesheet. Linked with media="print".
 * Repeating header/footer live in @page margin boxes (injected in layout.php)
 * so they cannot mix into the document body.
 */

@page {
    margin: 14mm 12mm 16mm 12mm;
}

html, body {
    background: #fff !important;
    color: #111 !important;
    font-size: 11pt;
    line-height: 1.45;
    height: auto !important;
    overflow: visible !important;
    margin: 0 !important;
    padding: 0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.topbar,
.print-hide,
.doc-toc,
.tabs,
.btn,
.badge,
.player-wrap,
video,
.chapters,
.auth-wrap {
    display: none !important;
}

.doc-layout.has-toc {
    display: block;
}

.doc-sidebar {
    display: none !important;
}

.container,
.container-doc,
.card,
.doc-main,
.doc-body,
.doc-sidebar,
.md-table-wrap {
    max-width: none !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    color: #111 !important;
    overflow: visible !important;
    max-height: none !important;
    height: auto !important;
}

.card + .card { margin-top: 8mm; }

.muted,
.library-heading,
.doc-body blockquote {
    color: #444 !important;
    background: transparent !important;
}

.doc-body {
    font-size: 11pt;
    line-height: 1.5;
    letter-spacing: 0;
    font-weight: 400;
    orphans: 3;
    widows: 3;
}

.doc-body h1, .doc-body h2, .doc-body h3,
.doc-body h4, .doc-body h5, .doc-body h6 {
    color: #111 !important;
    break-after: avoid;
    page-break-after: avoid;
}

/* Each top-level section (`#` / h1) starts on a new sheet.
   The email stamp is a sibling immediately before h1, so the break
   belongs on the stamp (or on h1 when there is no stamp). */
.doc-body > h1,
.doc-body > .doc-stamp:has(+ h1) {
    break-before: page;
    page-break-before: always;
}
.doc-body > .doc-stamp:has(+ h1) {
    break-after: avoid;
    page-break-after: avoid;
}
.doc-body > .doc-stamp:has(+ h1) + h1 {
    break-before: auto;
    page-break-before: auto;
}
.doc-body > h1:first-child,
.doc-body > .doc-stamp:first-child:has(+ h1) {
    break-before: auto;
    page-break-before: auto;
}

.doc-body a {
    color: #111 !important;
    text-decoration: underline;
}

.doc-body blockquote {
    border-left: 2pt solid #888 !important;
    padding: 2mm 4mm;
}

.doc-body pre,
.doc-body code {
    background: #f4f4f4 !important;
    color: #111 !important;
    border-color: #ccc !important;
}

.doc-toc-cover {
    display: none !important;
}

/* Page 1: cover only — one sheet, no extra padding, no overflow. */
.doc-titlepage {
    display: block !important;
    break-after: page;
    page-break-after: always;
    break-inside: avoid;
    page-break-inside: avoid;
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
    max-height: 240mm;
    overflow: hidden;
    line-height: 0;
    background: #fff !important;
    border-radius: 0 !important;
    position: relative;
    z-index: 1;
}
.doc-titlepage .doc-cover {
    display: block;
    width: 100% !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: 240mm !important;
    object-fit: contain;
    object-position: center top;
    border-radius: 0 !important;
    margin: 0 !important;
}

/* Page 2: title and abstract. */
.doc-frontmatter {
    break-after: page;
    page-break-after: always;
    min-height: 0;
    padding: 8mm 0 4mm !important;
}
.doc-title {
    font-size: 22pt !important;
    color: #111 !important;
    margin: 0 0 8mm !important;
}
.doc-abstract {
    max-width: none;
    margin: 0 !important;
}
.doc-abstract-label {
    color: #444 !important;
    font-size: 9pt !important;
    margin: 0 0 3mm !important;
}
.doc-abstract p {
    color: #111 !important;
    font-size: 12pt !important;
    line-height: 1.5 !important;
}

.doc-stamp {
    background: #fff !important;
    width: 50%;
    max-width: 70mm;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.doc-stamp-invert {
    background: #fff !important;
    filter: invert(1);
}
.doc-stamp-email { color: #111 !important; }

.md-table th, .md-table td {
    border: 0.4pt solid #888 !important;
    background: #fff !important;
    color: #111 !important;
    text-transform: none;
}

img { max-width: 100% !important; }

.doc-body img {
    break-inside: avoid;
    page-break-inside: avoid;
}

.version-note {
    background: transparent !important;
    border: 0.4pt solid #888 !important;
    color: #111 !important;
}

.print-watermark {
    display: grid !important;
    position: fixed;
    inset: -15% -8%;
    grid-template-columns: repeat(3, 1fr);
    gap: 18mm 12mm;
    align-content: space-evenly;
    justify-items: center;
    transform: rotate(-28deg);
    z-index: 0;
    pointer-events: none;
    color: #000 !important;
    opacity: 0.08;
    font-family: var(--font-sans), "Source Sans 3", sans-serif;
    font-size: 12pt;
    font-weight: 600;
    letter-spacing: 0.06em;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.print-watermark span {
    white-space: nowrap;
}

.container,
.doc-main,
.doc-body {
    position: relative;
    z-index: 1;
}
