/* reader-print.css — portal-side print rules for /view/{id}.
   Companion to themes/print.css (which owns @page setup, running header/footer,
   and skill-output document rules). This file hides app chrome, re-flows the
   reader grid for full-width printing, forces tier colors, strips browser-added
   URL annotations, and adds the page-break rules from the chrome design brief. */

@media print {
  /* Hide portal chrome */
  .topbar,
  .reader-toolbar,
  .reader-rule,
  .sidebar-reader,
  .reader-toc,
  .crosswalk-callout,
  .foot,
  /* The on-screen classification banner is replaced by the @page running header
     below; hide the in-flow copy so it doesn't print twice. */
  .classification-banner {
    display: none !important;
  }

  /* Re-flow .reader-shell for a single full-width column */
  .reader-shell {
    display: block !important;
    grid-template-columns: 1fr !important;
    max-width: none;
    margin: 0;
    padding: 0;
  }
  /* Reset the on-screen "paper" treatment — physical paper already supplies the
     white background and margins via @page, so our box-shadow/padding/radius
     would only waste real margin and burn toner. */
  .reader-main {
    max-width: none;
    min-width: 0;
    background: transparent;
    padding: 0;
    box-shadow: none;
    border-radius: 0;
  }

  /* Force colored backgrounds and accents to print: cream policy block, gold/green/teal
     rules, visibility chips, metadata-table tint. Without this Chrome silently drops them. */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Strip the default ::after URL annotation that browsers append to every link.
     The skill's themes/print.css line ~89 keeps gov-external annotations via a more
     specific selector — that rule wins on selector specificity, so external link URLs
     still print where they're useful. */
  a[href]::after { content: "" !important; }

  /* Page-break rules per Document_Page_Chrome_Design_Brief §3.
     Note: deliberately no `li { page-break-inside: avoid }` rule — long enumerated
     guideline items (Policy 310 has 100+ word items) produce ugly half-empty pages
     when forced to stay together. Authors notice tables breaking, not prose. */
  h1, h2, h3 { page-break-after: avoid; }
  table, blockquote, svg, img,
  .policy-meta-table,
  .policy-statement-box,
  .gov-header { page-break-inside: avoid; }
  tr { page-break-inside: avoid; }
  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }
  p { orphans: 3; widows: 3; }

  /* ── Classification banner on every printed page (Status/Classification/Access §7.2)
     Two paths: (a) @page @top-center running header — supported by Firefox/some print
     engines; (b) a position:fixed fallback that paints once at the top of the printed
     output (Chrome ignores @page margin-box content, but does honor position:fixed in
     print so the banner still appears, just only on the first page). */
  body.classification-internal     { --print-banner-text: "INTERNAL";     --print-banner-bg: #B8870E; }
  body.classification-restricted   { --print-banner-text: "RESTRICTED";   --print-banner-bg: #8A2A2A; }
  body.classification-confidential { --print-banner-text: "CONFIDENTIAL"; --print-banner-bg: #5A1818; }
  body.classification-public       { --print-banner-text: "";             --print-banner-bg: transparent; }

  @page {
    @top-center {
      content: var(--print-banner-text, "");
      background: var(--print-banner-bg, transparent);
      color: white;
      font-weight: 700;
      letter-spacing: 0.18em;
      padding: 0.25rem 0;
    }
  }

  /* Fallback banner element for browsers that drop @top-center content (Chrome).
     Generated via ::before on body for Internal/Restricted/Confidential. Rendered as
     position:fixed so it sits at the top of the page; in Chrome's print path it
     surfaces on the first page. */
  body.classification-internal::before,
  body.classification-restricted::before,
  body.classification-confidential::before {
    content: var(--print-banner-text);
    position: fixed;
    top: 0; left: 0; right: 0;
    background: var(--print-banner-bg);
    color: white;
    font: 700 11pt/1.2 "Calibri", sans-serif;
    letter-spacing: 0.18em;
    text-align: center;
    padding: 4px 0;
    z-index: 9999;
  }
  body.classification-public::before { content: none; }

  /* Wide-page primitive — wide tables (flagged by WidePageWrapExtension) and
     images marked {.wide-page} print on a landscape sheet inside the otherwise
     portrait document. Named @page rule with size: landscape is supported by
     Chromium's print-to-PDF (Edge/Chrome — the in-house workflow); Firefox is
     partial. If a blank trailing page appears, drop page-break-after below. */
  @page wide-landscape {
    size: 11in 8.5in;
    margin: 0.5in;
  }
  .reader-main table.wide-page,
  .reader-main img.wide-page,
  .reader-main p.wide-page {
    page: wide-landscape;
    page-break-before: always;
    page-break-after: always;
    /* drop the screen break-out positioning; the landscape sheet IS the canvas */
    width: auto;
    max-width: 100%;
    margin: 0;
    overflow: visible;
  }
}
