/* pdf.css — WeasyPrint (FULL REPLACEMENT)
   Strategy: stop relying on % sizing for large rasters.
   Use a dedicated named page (landscape) and size diagrams in mm.
*/

@media print {
  /* ===== Page setup ===== */
  @page {
    size: A4;
    margin: 18mm 18mm;
    @bottom-center {
      content: counter(page);
      font-family: Inter, Arial, sans-serif;
      font-size: 9pt;
      color: #5C6674;
    }
  }

  /* Landscape page used for full-width diagrams (e.g., Dysfunction Map) */
  @page diagram {
    size: A4 landscape;
    margin: 12mm 12mm;
    @bottom-center {
      content: counter(page);
      font-family: Inter, Arial, sans-serif;
      font-size: 9pt;
      color: #5C6674;
    }
  }

  /* Named page with background image for specific whitepapers */
  @page s2-pdf-bg {
    size: A4;
    margin: 18mm 18mm;
    @bottom-center {
      content: counter(page);
      font-family: Inter, Arial, sans-serif;
      font-size: 9pt;
      color: #5C6674;
    }
  }

  /* ===== Hide MkDocs/Material chrome ===== */
  .md-header, .md-tabs, .md-sidebar, .md-nav, .md-search, .md-footer,
  .md-top, .md-feedback, .md-consent, .md-overlay, .md-dialog,
  .md-tooltip, .md-source, .md-status, .md-announce {
    display: none !important;
  }

  /* ===== Reset layout constraints from the theme ===== */
  html, body {
    font-family: Inter, Arial, sans-serif;
    font-size: 11pt;
    line-height: 1.45;
    color: #0B1220;
  }

  .md-main__inner,
  .md-content,
  .md-content__inner {
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
  }

  /* Avoid any accidental clipping from inherited theme rules */
  article, main, section, div, figure {
    overflow: visible !important;
  }

  /* Print links cleanly */
  a {
    color: inherit;
    text-decoration: none;
  }

  /* ===== Pagination hygiene ===== */
  h1, h2, h3 {
    break-after: avoid;
    page-break-after: avoid;
  }
  p, li {
    orphans: 3;
    widows: 3;
  }
  blockquote, pre, table, ul, ol {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* ===== Figures ===== */
  figure {
    margin: 5mm 0 6mm 0;
  }
  figcaption {
    margin-top: 3mm;
    font-size: 9.5pt;
    color: #5C6674;
  }

  /* Default images: reasonable behavior */
  img, svg {
    display: block;
    max-width: 100% !important;
    height: auto !important;
    margin: 0 auto !important;
  }

  /* =========================================================
     FULL-PAGE DIAGRAM BLOCK (matches your <div class="pdf-page">)
     ========================================================= */
  .pdf-page {
    /* Always start diagrams on a new page */
    break-before: page;
    page-break-before: always;

    /* Put this block onto the dedicated landscape page */
    page: diagram;

    /* Ensure wrapper itself never constrains */
    width: auto !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Ensure the figure doesn't impose constraints */
  .pdf-page figure.wp-diagram {
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    max-width: none !important;
  }

  /*
    Scale diagrams to the maximum page width while preserving aspect ratio.
    Using 100% avoids hard mm values that can trigger cropping if the page
    ends up portrait or margins change.
  */
  .pdf-page img,
  .pdf-page svg {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;     /* keep aspect ratio */
    margin: 0 auto !important;   /* center */
  }

  /* Apply background image when the document is wrapped in .pdf-bg */
  .pdf-bg {
    page: pdf-bg;
    position: relative;
    z-index: 1;
    background: url("assets/pdf-bg.png") no-repeat center;
    background-size: 210mm 297mm;
    background-attachment: fixed;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
  }
  .pdf-bg * {
    page: pdf-bg;
  }
}

/* --- Page numbers --- */

@page {
  @bottom-center {
    content: counter(page);
    font-size: 9pt;
    color: #5C6674;
  }
}

/* Key: make the first page of the CONTENT show "2" */
.wp-content {
  counter-reset: page 1;
}
