/* Digital School Portal - Report Print Styles
   ============================================================================
   Report-specific pagination. Loaded on every page, but the rules only apply to
   `body.page-report`, so a template opts in by declaring:

       {% block page_class %}page-report{% endblock %}

   Two deliberate omissions:

   * No `@page { size: ... }`. A document-level page size cannot be gated on the
     body class, so putting one here would force A4 portrait onto every page in
     the app and override the user's chosen paper in the print dialog. Paper size
     comes from the dialog (or, for server PDFs, from the `paper_size` argument
     that Playwright passes). Margins live in print.css.

   * No content-hiding selectors. An earlier version hid
     `[hx-get], [hx-post], [hx-trigger], [hx-target], form, select, input`, which
     deleted whole HTMX-driven report tables and filter results from the printed
     sheet. Only pagination and break-control rules belong here — see
     tests/test_mobile_nav_and_print.py for the guard.
   ============================================================================ */

@media print {
  :root,
  html,
  html[data-theme],
  body,
  body.page-report {
    color-scheme: light !important;
    --color-bg: #ffffff !important;
    --color-surface: #ffffff !important;
    --color-surface-2: #f8fafc !important;
    --color-surface-3: #f1f5f9 !important;
    --color-text: #0f172a !important;
    --color-text-muted: #475569 !important;
    --color-text-faint: #64748b !important;
    --color-border: #cbd5e1 !important;
    --color-border-inner: #e2e8f0 !important;
    --color-border-strong: #94a3b8 !important;
    --color-primary: #1e3a8a !important;
    --color-primary-dim: #1e3a8a !important;
    --color-primary-text: #1e3a8a !important;
    background: #ffffff !important;
    background-color: #ffffff !important;
    color: #0f172a !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 10px !important;
    line-height: 1.2 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Repeat table heads on every page and never split a row. */
  body.page-report .scores-table thead,
  body.page-report .conduct-table thead,
  body.page-report table.broadsheet thead,
  body.page-report table.result-table thead,
  body.page-report .portal-table thead,
  body.page-report table thead {
    display: table-header-group !important;
  }

  body.page-report .scores-table tbody tr,
  body.page-report .conduct-table tbody tr,
  body.page-report table.broadsheet tbody tr,
  body.page-report table.result-table tbody tr,
  body.page-report .portal-table tbody tr,
  body.page-report table tbody tr {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Keep headings with the content they introduce. */
  body.page-report .section-heading,
  body.page-report .title-banner,
  body.page-report .report-header,
  body.page-report h1,
  body.page-report h2,
  body.page-report h3 {
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  /* Keep summary blocks whole. */
  body.page-report .summary-grid,
  body.page-report .stats-cards,
  body.page-report .promotion-box,
  body.page-report .student-info-container,
  body.page-report .report-footer {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Transcripts break between sessions, never inside a term card. */
  body.page-report .session-block {
    page-break-inside: auto;
  }

  body.page-report .session-page-break {
    page-break-before: always !important;
    break-before: page !important;
  }

  body.page-report .no-break,
  body.page-report .term-card {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Only print a URL for links that leave the app. */
  body.page-report a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 80%;
    color: #666;
  }

  /* ── Compact Report Print Styling (1-Page Optimization) ────────────────── */
  @page {
    margin: 6mm 8mm !important;
  }

  body.page-report .print-root {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body.page-report .print-root .portal-card,
  body.page-report .portal-card#report-card,
  body.page-report .portal-card#annual-card {
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: #ffffff !important;
  }

  /* Header Compaction */
  body.page-report .print-root .text-center.mb-6,
  body.page-report .print-root header {
    margin-bottom: 4px !important;
    padding-bottom: 3px !important;
    border-bottom-width: 1px !important;
  }

  body.page-report img[alt="Logo"],
  body.page-report img[alt="{{ school.name }} Logo"],
  body.page-report .print-root img[src*="logo"] {
    max-height: 40px !important;
    max-width: 100px !important;
    width: auto !important;
    height: auto !important;
    margin: 0 auto 2px auto !important;
  }

  body.page-report h1,
  body.page-report .text-xl.font-bold {
    font-size: 14px !important;
    line-height: 1.15 !important;
    margin: 0 !important;
    font-weight: 800 !important;
    letter-spacing: 0.3px !important;
  }

  body.page-report .text-base.font-semibold,
  body.page-report .text-sm {
    font-size: 10px !important;
    line-height: 1.2 !important;
  }

  body.page-report .text-xs {
    font-size: 9px !important;
    line-height: 1.2 !important;
  }

  /* Student Info Grid Compaction */
  body.page-report .grid.grid-cols-3.gap-4.mb-6,
  body.page-report .student-info-container {
    margin-bottom: 6px !important;
    padding: 4px 8px !important;
    gap: 6px !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 4px !important;
    background: #f8fafc !important;
  }

  body.page-report img.w-20.h-20,
  body.page-report img.w-16.h-16,
  body.page-report .w-20.h-20,
  body.page-report .w-16.h-16 {
    width: 44px !important;
    height: 44px !important;
  }

  body.page-report dl.grid {
    gap: 2px 10px !important;
  }

  body.page-report dt {
    font-size: 8px !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    color: #475569 !important;
  }

  body.page-report dd {
    font-size: 10px !important;
    font-weight: 700 !important;
    color: #0f172a !important;
    margin-bottom: 1px !important;
  }

  /* Section Headings */
  body.page-report h2,
  body.page-report h3,
  body.page-report .font-semibold.text-sm.uppercase {
    font-size: 10px !important;
    font-weight: 800 !important;
    margin-top: 4px !important;
    margin-bottom: 2px !important;
    letter-spacing: 0.5px !important;
    color: #1e293b !important;
  }

  /* Tables Compaction */
  body.page-report table {
    margin-bottom: 4px !important;
    width: 100% !important;
    font-size: 9.5px !important;
  }

  body.page-report .overflow-x-auto {
    margin-bottom: 4px !important;
    overflow: visible !important;
  }

  body.page-report th {
    padding: 2.5px 4px !important;
    font-size: 9px !important;
    font-weight: 700 !important;
    background-color: #f1f5f9 !important;
    color: #0f172a !important;
    border: 1px solid #94a3b8 !important;
    text-align: center !important;
  }

  body.page-report th:first-child,
  body.page-report td:first-child {
    text-align: left !important;
  }

  body.page-report td {
    padding: 2px 4px !important;
    font-size: 9.5px !important;
    line-height: 1.15 !important;
    border: 1px solid #cbd5e1 !important;
    color: #0f172a !important;
  }

  /* Summary Stat Cards */
  body.page-report .grid.grid-cols-2.md\:grid-cols-5.gap-3.mb-6,
  body.page-report .stats-cards,
  body.page-report .summary-grid {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    gap: 4px !important;
    margin-bottom: 6px !important;
  }

  body.page-report .stats-cards > div,
  body.page-report .summary-grid > div,
  body.page-report .grid.grid-cols-2.md\:grid-cols-5 > div {
    padding: 2px 4px !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 4px !important;
    background: #f8fafc !important;
    text-align: center !important;
  }

  body.page-report .text-xl.font-bold,
  body.page-report .text-2xl.font-bold {
    font-size: 12px !important;
    line-height: 1.1 !important;
  }

  body.page-report .text-xs.mt-0\.5 {
    font-size: 8px !important;
    margin-top: 1px !important;
  }

  /* Legends & Rating Scales */
  body.page-report .grid.grid-cols-1.md\:grid-cols-2.gap-4.mb-6 {
    margin-bottom: 4px !important;
    gap: 4px !important;
  }

  body.page-report .flex.flex-wrap.gap-2 > span {
    padding: 1px 3px !important;
    font-size: 8px !important;
    border-radius: 2px !important;
  }

  /* Comments & Signatures */
  body.page-report .grid.grid-cols-1.md\:grid-cols-2.gap-6.mb-6,
  body.page-report .grid.grid-cols-1.md\:grid-cols-3.gap-4 {
    margin-bottom: 4px !important;
    gap: 6px !important;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  body.page-report .border-t.pt-4 {
    padding-top: 2px !important;
    margin-top: 2px !important;
  }

  body.page-report .min-h-12,
  body.page-report .min-h-10 {
    min-height: 20px !important;
    font-size: 9.5px !important;
  }

  body.page-report img[alt*="Signature"],
  body.page-report img[alt*="Stamp"] {
    max-height: 24px !important;
    width: auto !important;
  }

  body.page-report .mt-4.pt-3.border-t {
    margin-top: 2px !important;
    padding-top: 2px !important;
  }

  /* Page Break Containment */
  body.page-report #report-card,
  body.page-report #annual-card {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
}

