@media print {
  /* Hide navigation and UI elements */
  nav,
  header,
  footer,
  .nextra-nav-container,
  .nextra-sidebar-container,
  .nextra-toc,
  .nextra-breadcrumb,
  .nx-mt-8,
  button {
    display: none !important;
  }

  /* Optimize main content */
  main,
  article {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Page setup */
  @page {
    size: A4;
    margin: 2cm;
  }

  /* Typography */
  body {
    font-size: 12pt;
    line-height: 1.5;
    color: #000;
    background: #fff;
  }

  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
    page-break-inside: avoid;
    color: #000 !important;
  }

  /* Links */
  a {
    color: #000 !important;
    text-decoration: underline;
  }

  a[href^="http"]:after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }

  /* Code blocks */
  pre,
  code {
    background: #f5f5f5 !important;
    border: 1px solid #ddd !important;
    page-break-inside: avoid;
    white-space: pre-wrap;
    word-wrap: break-word;
  }

  pre {
    padding: 10px !important;
  }

  code {
    padding: 2px 4px !important;
  }

  /* Tables */
  table {
    page-break-inside: avoid;
    border-collapse: collapse;
  }

  table, th, td {
    border: 1px solid #000;
  }

  /* Images */
  img {
    max-width: 100% !important;
    page-break-inside: avoid;
  }

  /* Avoid breaks */
  ul, ol, dl {
    page-break-before: avoid;
  }
}
