@media print {
  /* Hide elements not needed in print */
  header, footer, nav, .btn, #wb-info, #wb-sec, .wb-share, .pagedetails, 
  .noprint, .btn-group, #printToPDF-button {
    display: none !important;
  }

  /* Show print-only elements */
  .print-only {
    display: block !important;
  }

  /* Ensure all details are expanded in print */
  details.print-expanded {
    display: block !important;
  }
  details.print-expanded > summary {
    display: none !important;
  }
  details.print-expanded > * {
    display: block !important;
  }

  /* Improve readability and fit content on the page */
  body {
    font-size: 12pt;
    line-height: 1.5;
    color: #000;
    background: #fff;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  #wb-cont, main, article, section {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    float: none !important;
  }

  /* Prevent orphaned headings */
  h1, h2, h3, h4, h5, h6 {
    orphans: 2 !important;
  }
  /* Encourage blocks to avoid single lines at top/bottom of page */
  p, dl, ul, ol {
    orphans: 2 !important;
    widows: 2 !important;
  }

  /* Ensure links are visible in print */
  a {
    color: #000 !important;
  }
  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 90%;
    color: #333;
  }
  a[href^="#"]:after, 
  a[href^="javascript:"]:after {
    content: "";
  }

  /* Print title styling */
  #print-first-page-header, #print-toc {
    margin: 0 auto 2cm auto !important;
    width: 90% !important;
    max-width: 90% !important;
  }
  #print-page-title {
    text-align: center !important;
    font-size: 24pt !important;
    margin-bottom: 1cm !important;
    margin-top: 1cm !important;
  }

  /* Table of Contents layout */
  #print-toc ul {
    padding-left: 0 !important;
    list-style: none !important;
    width: 100% !important;
  }
  #print-toc li {
    margin-bottom: 0.5cm !important;
    display: flex !important;
    align-items: baseline !important;
  }
  #print-toc a {
    text-decoration: none !important;
    color: black !important;
    flex-grow: 1 !important;
  }

  /* Print images nicely */
  img {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  /* Hide elements not needed during print */
  .wb-toggle, .btn.bg-info, #print_note, .no-print {
    display: none !important;
  }

  /* Print expanded details */
  details { display: block !important; }
  summary { display: none !important; }
}