/*
 * Print Styles
 * Optimized layout and visibility for printing
 */

@media print {
  @page {
    margin: 1in;
  }

  body {
    font-size: 12pt;
    line-height: 1.5;
  }

  .print\:hidden,
  header,
  footer,
  nav,
  .no-print {
    display: none !important;
  }

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

  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
  }

  img, table, figure {
    page-break-inside: avoid;
  }

  /* Brochure page: proper page margins for breathing room AT THE TOP
     AND BOTTOM OF EVERY PAGE, but suppress the browser's default
     URL/date/page-N headers by emptying every @page margin box. */
  @page brochure {
    margin: 12mm 10mm;
    @top-left { content: ""; }
    @top-center { content: ""; }
    @top-right { content: ""; }
    @bottom-left { content: ""; }
    @bottom-center { content: ""; }
    @bottom-right { content: ""; }
  }

  body.brochure-page {
    page: brochure;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
    background-color: var(--color-white);
    padding: 0;
    margin: 0;
  }

  body.brochure-page .brochure {
    padding: 0;
    max-width: none;
  }

  body.brochure-page .brochure__paper {
    box-shadow: none;
    padding: 0;
  }

  /* Keep individual lesson cards intact across page breaks. Modules
     and titles are allowed to break freely so content flows tightly
     into available page space — strict break-after rules on titles
     caused half-empty pages whenever the next module's first row
     of cards didn't fit. */
  body.brochure-page .brochure__lesson {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Module title must stick with its first row of cards. Without
     this, modules orphan their title at the bottom of one page and
     start the cards on the next — worse than the half-empty-page
     trade-off. The brochure title and individual lesson titles can
     break freely (override the global h1-h6 rule for those). */
  body.brochure-page .brochure__module-title {
    break-after: avoid;
    page-break-after: avoid;
  }

  body.brochure-page .brochure__title,
  body.brochure-page .brochure__lesson-title {
    break-after: auto;
    page-break-after: auto;
  }

  /* Force a predictable 3-column grid for lessons when printing,
     regardless of viewport width. Otherwise auto-fill collapses to
     1 column on narrow print pages and the brochure balloons to
     hundreds of pages. */
  body.brochure-page .brochure__lessons {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5mm 4mm;
  }

  /* Compact thumbnails for print so more cards fit per page and
     modules don't push wholesale to the next page leaving big blanks. */
  body.brochure-page .brochure__lesson .thumbnail {
    aspect-ratio: 16 / 9;
    max-height: 26mm;
    overflow: hidden;
  }
  body.brochure-page .brochure__lesson .thumbnail__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  body.brochure-page .brochure__lesson .thumbnail__duration {
    font-size: 7pt;
  }

  /* Tighter spacing for print */
  body.brochure-page .brochure__hero {
    margin-bottom: 4mm;
    padding-bottom: 3mm;
  }

  body.brochure-page .brochure__section {
    margin-bottom: 4mm;
  }

  body.brochure-page .brochure__module {
    padding-block: 0;
    margin-bottom: 4mm;
  }

  body.brochure-page .brochure__module-title {
    margin-bottom: 1.5mm;
  }

  body.brochure-page .brochure__module-desc {
    margin-bottom: 3mm;
  }

  body.brochure-page .brochure__lesson-desc {
    font-size: 9pt;
    line-height: 1.35;
  }

  body.brochure-page .brochure__lesson-title {
    font-size: 10pt;
  }

  /* Hide the print toolbar (already covered by .no-print but explicit) */
  body.brochure-page .brochure__actions { display: none; }
}
