/* =============================================================
   apollo-mi-print.css — print stylesheet for PDF export
   Activated by media print or by adding 'mi-printing' to <body>.
   ============================================================= */

@media print {
  /* Running header + footer on every page (#17). Browser print engines
     (Chrome, Edge, Safari 17+) respect @page margin boxes; older Firefox
     falls back to plain margin with no header/footer — acceptable
     degradation. Margins widened slightly from 14mm/12mm to leave room
     for the running text. */
  @page {
    size: A4 portrait;
    margin: 18mm 12mm 16mm 12mm;

    @top-center {
      content: "Apollo — Market Intelligence · Olympus";
      font: 8pt/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
      color: #6b7280;
      padding-bottom: 3mm;
      border-bottom: 0.4pt solid #d1d5db;
      vertical-align: bottom;
    }

    @bottom-left {
      content: "apollo.olympus.cy";
      font: 7pt/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
      color: #6b7280;
      padding-top: 3mm;
      border-top: 0.4pt solid #d1d5db;
      vertical-align: top;
    }

    @bottom-right {
      content: "Page " counter(page) " of " counter(pages);
      font: 7pt/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
      color: #6b7280;
      padding-top: 3mm;
      border-top: 0.4pt solid #d1d5db;
      vertical-align: top;
    }
  }

  /* Hero section on the first page sits below the running header — no
     special-cased @page :first needed; the existing 18mm top margin gives
     the header room and the hero just renders below. */

  html, body {
    background: #ffffff !important;
    color: #15171c !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Hide chrome the user doesn't need on paper */
  .apollo-header .methodology-link,
  .apollo-nav,
  .mi-section-tools .mi-methodology-button,
  .mi-methodology-popover,
  .mi-footer .mi-btn,
  .mi-print-button,
  .mi-accordion-toggle .mi-accordion-chevron,
  /* Universal Olympus shell chrome (Phase 5 ?shell=universal) — hide on print.
     The MI page provides its own paper-friendly footer (`.mi-footer`). */
  .o-top,
  .o-side,
  .o-footer,
  .o-drawer {
    display: none !important;
  }

  /* Collapse the universal shell grid back to normal block flow on paper.
     Removes the 280px sidebar gutter so .o-main fills the page width. */
  .o-shell {
    display: block !important;
    grid-template-columns: none !important;
    grid-template-rows: none !important;
  }
  .o-main {
    grid-area: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  /* Ensure accordions are open on paper (override any aria-expanded=false) */
  .mi-accordion-body { display: block !important; }

  /* Disclosure grammar (P0-9): every Level-1 disclosure auto-expands on
     paper so the PDF carries the underlying data table for each chart.
     The React Disclosure component already toggles open via matchMedia
     ("print"); these rules are belt-and-braces — the panel renders even
     if the React state is briefly out of sync during the print-paint
     window.

     Level 2 (methodology) and Level 3 (source data) stay collapsed on
     paper — methodology has its own appendix in the print path, and raw
     source data is not added to the PDF (it links out to the Methodology
     → Data health surface, which is screen-only). */
  .ap-disclosure[data-disclosure-level="1"] .ap-disclosure-panel,
  .ap-disclosure[data-disclosure-level="1"] {
    display: block !important;
  }

  .ap-disclosure[data-disclosure-level="1"] .ap-disclosure-toggle {
    display: none !important;
  }

  .ap-disclosure[data-disclosure-level="1"]:not(.is-open)::after {
    content: "(see data table below)";
    display: none;
  }

  .ap-disclosure[data-disclosure-level="2"],
  .ap-disclosure[data-disclosure-level="3"] {
    display: none !important;
  }

  /* Trim scope-map and scope-aware Leaflet UI — non-essential on paper */
  .mi-scope-map-section { display: none !important; }

  /* Compact the spacing — paper is tighter than screen */
  .mi-page { max-width: 100%; padding: 0; }
  .mi-section {
    margin-bottom: 8pt;
    padding: 8pt 10pt;
    border: 0.5pt solid #d1d5db;
    box-shadow: none;
    page-break-inside: avoid;
  }
  .mi-section-hero {
    background: #1a2744 !important;
    color: #ffffff !important;
    page-break-after: avoid;
  }
  .mi-section-hero .mi-section-title { color: #ffffff !important; }
  .mi-section-hero .mi-caption { color: #c0c5cc !important; }
  .mi-kpi-value { color: #ffffff !important; font-size: 22pt; }
  .mi-section-title { font-size: 12pt; }
  .mi-sub-title { font-size: 10pt; }
  .mi-caption { font-size: 9pt; }
  .mi-table { font-size: 8pt; }

  /* Charts — let Chart.js render at the size given by canvas; force visible */
  .mi-chart-container { page-break-inside: avoid; height: auto !important; min-height: 150pt; }

  /* Page break opportunities */
  .mi-section + .mi-section { page-break-before: auto; }
  .mi-method-section { page-break-inside: avoid; }

  /* Footer (always last, in light grey) */
  .mi-footer {
    border-top: 1pt solid #6b7280;
    color: #4b5563 !important;
    background: transparent !important;
    page-break-before: auto;
  }
  .mi-footer-row .mi-citation {
    font-size: 7.5pt;
    background: #fafbfc !important;
    border: 0.5pt solid #d1d5db !important;
  }

  /* Caveat banners — keep visible but compact */
  .mi-banner {
    page-break-inside: avoid;
    font-size: 8pt;
    padding: 4pt 6pt;
  }

  /* Methodology page — ensure long content paginates cleanly */
  .mi-method-page { padding: 0; }
  .mi-method-header { page-break-after: avoid; }
  .mi-method-section { page-break-inside: avoid; margin-bottom: 8pt; }
  .mi-method-source { page-break-inside: avoid; }
  .mi-method-term { page-break-inside: avoid; }
}

/* Manual class added when user clicks "Print to PDF" — also expands accordions
   for browsers that ignore @media print rules during prepare-print. */
body.mi-printing .mi-accordion-body { display: block !important; }
body.mi-printing .mi-accordion-toggle { pointer-events: none; }
