/**
 * ROCO Print / PDF Stylesheet
 *
 * Loaded via <link media="print"> in index.html — bypasses Vite/Tailwind
 * bundling so @page and other print rules are preserved as-is.
 */

/* ── Page layout ──────────────────────────────────────────────────
 * @page { margin: 1.5cm 0; size: A4 } is declared in index.css
 * (main Vite bundle) so Chrome always picks it up.
 * Left/right: print:px-[2cm] on the content cell (dialog-immune).
 * ──────────────────────────────────────────────────────────────── */

/* ── Heatmap pages (landscape, one per heatmap) ──────────────────── */

@media print {
  /*
   * Each heatmap gets its own landscape A4 page.
   * The @page landscape override is injected dynamically by
   * triggerPrint() just before window.print() — more reliable
   * than CSS named pages across Chromium versions.
   */
  .print-heatmap-page {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    /* Clip any fractional overflow so it doesn't spill onto a
     * near-blank second page. */
    overflow: hidden;
  }

  /* Break before every heatmap EXCEPT the first — otherwise
   * the forced break before the first element creates a blank
   * page at the start of the print output. */
  .print-heatmap-page + .print-heatmap-page {
    break-before: page;
  }

  .print-heatmap-page .print-heatmap-title {
    flex: 0 0 auto;
    padding-bottom: 0.3cm;
  }

  .print-heatmap-page .print-heatmap-map {
    min-height: 0;
    margin-bottom: 0 !important;
  }

  /* Hide the WebGL canvas — the captured <img> snapshot shows
   * instead (see printSnapshot state in ZoneHeatmap).
   * WebGL canvases render as black in Chrome's print preview. */
  .print-heatmap-page canvas {
    display: none !important;
  }

  /* Keep each heatmap page together — no mid-map page break. */
  .print-heatmap-page {
    break-inside: avoid;
    break-after: avoid;
  }

  /* Heatmap-only print: suppress the main report body so only
   * the landscape heatmap pages appear in the output. */
  html[data-print-mode="heatmaps"] .roco-print-table {
    display: none !important;
  }
}

/* ── Global resets for print ─────────────────────────────────────── */

@media print {
  /* CSS table structure so print:px-[2cm] on the content cell
   * provides immune L/R margins.
   * !important overrides Tailwind `contents` (display:contents). */
  .roco-print-table  { display: table !important; width: 100%; height: auto !important; }
  .roco-print-tbody  { display: table-row-group !important; }
  .roco-print-tr     { display: table-row !important; }
  .roco-print-td     { display: table-cell !important; vertical-align: top; }

  /* Prevent any element from locking height or clipping content */
  body,
  html,
  #root,
  #root > * {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  /* Sidebar: hide via data attribute set by tour system */
  [data-tour-step="sidebar-navigation"] {
    display: none !important;
  }

  /* Interactive controls that don't belong in a PDF */
  [data-print-hide="true"] {
    display: none !important;
  }

  /* Preserve SVG chart colours (Recharts uses SVG fill/stroke) */
  .recharts-wrapper,
  .recharts-surface,
  .recharts-wrapper * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Expand overflow-x-auto tables so they don't clip */
  .prose table {
    overflow: visible !important;
    display: table !important;
  }

  /* Page-break hints: keep headings glued to what follows */
  h2,
  h3,
  h4 {
    break-after: avoid;
  }

  /* Prevent a break immediately before the element that follows a heading.
   * Combined with break-after:avoid above this strongly pairs heading+content
   * so the browser moves the heading to the next page rather than orphaning it. */
  h2 + *,
  h3 + *,
  h4 + * {
    break-before: avoid;
  }

  figure,
  pre,
  blockquote,
  li,
  .recharts-wrapper,
  [data-viz-id] {
    break-inside: avoid;
  }

  /* Allow table rows to break across pages naturally.
   * (break-inside: avoid on <table> would push the whole
   * table to the next page if it doesn't fit, creating
   * a blank gap on the previous page.) */
  tr {
    break-inside: avoid;
  }
}
