/* PCH Print Styles — A4 optimized (#193) */
@media print {
  /* ── Page Setup ─────────────────────────────────────── */
  @page {
    size: A4 portrait;
    margin: 1.5cm;
  }

  /* ── Unlock Scrolling ───────────────────────────────── */
  /* index.html blocks body scrolling for <ScrollView>; on paper that clips
     the page to one screen, so print the full document height. */
  html, body, #root {
    height: auto !important;
    overflow: visible !important;
  }

  /* react-navigation pins the focused screen with position:absolute and
     overflow:hidden, so the screen's flex:1 chain (and its ScrollView) was only
     as tall as the menu column beside it: ~265 px of /about-system on paper.
     Put every ancestor of the screen's <main> back in flow; the flex:1 children
     then take their content height. Inactive screens stay display:none. */
  #root div:has(main#main-content) {
    position: relative !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* The screen's own <ScrollView> (react-native-web: overflow-y auto, flex
     1 1 0%) inside <main> stays a scroll container on paper, and Chromium
     cuts a scroll container at the end of its screen-sized box: the last
     bullet and closing sentence of /about-system were missing from the PDF.
     Put the screen's top container and every ScrollView inside <main> (the
     auto testID is "<File>-ScrollView-L<line>C<col>") back in flow too. */
  main#main-content > *,
  main#main-content [data-testid*="ScrollView"] {
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    flex-basis: auto !important;
  }

  /* Without a menu (presenter, doctor package, zen) the drawer column is empty
     and 0 px wide, but its 1 px border now runs the whole printed height. */
  #root div:has(main#main-content) > div:empty {
    border-width: 0 !important;
  }

  /* CookieConsentSpacer reserves the banner's height at the bottom of #root
     and of every scroll container; the banner is hidden on paper. */
  [data-cookie-pad] {
    padding-bottom: 0 !important;
  }

  /* ── Hide Interactive Elements ──────────────────────── */
  /* No bare `button`: react-native-web renders content rows (e.g. a report
     row) as <button>, and sets no class names: mark controls to drop with
     data-print="hide" (ZenExitButton, ScrollToTop). */
  [data-testid="app-drawer"],
  [data-cookie-banner],
  [data-testid="senior-every-screen-help"],
  [data-testid="install-prompt"],
  nav,
  .drawer-content,
  header,
  [role="navigation"],
  input[type="search"],
  .search-bar,
  .filter-chips,
  .fab,
  .command-palette,
  .reading-progress-bar,
  .feedback-widget,
  iframe,
  video,
  .sparkline,
  [data-print="hide"] {
    display: none !important;
  }

  /* The Oivo assistant (loader.js in index.html) appends its fixed microphone
     button, expand button and resize handle to <body>; the microphone printed
     on every page. Its panel is the iframe hidden above. */
  [aria-label$="Oivo Simple Assistant"] {
    display: none !important;
  }

  /* The menu column is react-navigation's, not AppDrawer's: without this it
     stays SIDEBAR_WIDTH wide and empty. The assistant toggle's fixed wrapper
     would print on every page. Kept out of the list above, so a browser
     without :has() drops only these, not the whole list. */
  div:has(> [data-testid="app-drawer"]),
  div:has(> [data-testid="side-chat-toggle"]) {
    display: none !important;
  }

  /* ── Reset Colors for Paper ─────────────────────────── */
  body, html, #root {
    background: white !important;
    color: #111 !important;
    font-size: 11pt !important;
    line-height: 1.4 !important;
  }

  * {
    color: #1a1a1a !important;
    background-color: transparent !important;
    box-shadow: none !important;
    text-shadow: none !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* ── Layout: Full Width ─────────────────────────────── */
  main, [role="main"], .main-content {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* ── Typography ─────────────────────────────────────── */
  h1 { font-size: 18pt !important; margin-bottom: 8pt !important; }
  h2 { font-size: 14pt !important; margin-bottom: 6pt !important; }
  h3 { font-size: 12pt !important; margin-bottom: 4pt !important; }

  p, li, td, th, span, div {
    font-size: 10pt !important;
  }

  /* ── Badges & Chips — Keep Color Coding ─────────────── */
  .badge, .chip, [data-badge] {
    border: 1px solid #999 !important;
    padding: 1px 4px !important;
    font-size: 9pt !important;
  }

  /* Confidence bars — print as bordered rectangles */
  [data-confidence] {
    border: 1px solid #666 !important;
    height: 6px !important;
  }

  /* ── Page Breaks ────────────────────────────────────── */
  .card, .section, article, [data-card] {
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 8pt !important;
  }

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

  /* Orphan/widow control */
  p {
    orphans: 3;
    widows: 3;
  }

  /* Force page break before major sections */
  [data-print="page-break"] {
    break-before: page;
    page-break-before: always;
  }

  /* ── Cards Grid for Print — 2 columns ──────────────── */
  .cards-grid, .stats-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8pt !important;
  }

  .card {
    border: 1px solid #ddd !important;
    padding: 6pt !important;
    border-radius: 4pt !important;
  }

  /* ── Tables ─────────────────────────────────────────── */
  table {
    border-collapse: collapse !important;
    width: 100% !important;
    font-size: 9pt !important;
  }

  td, th {
    border: 1px solid #ccc !important;
    padding: 3px 6px !important;
  }

  th {
    background-color: #f0f0f0 !important;
    font-weight: 700 !important;
  }

  /* ── Links — Show URLs ──────────────────────────────── */
  /* 9pt, not a fraction of the link: react-native-web renders a Text with
     href as <a> at its screen size (12-14 px), so 0.75em printed the address
     at 6.75-7.9pt. 9pt (12 px) is the smallest text on paper. */
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #666 !important;
    word-break: break-all;
  }

  /* Don't show URLs for internal links */
  a[href^="/"]::after,
  a[href^="#"]::after {
    content: none;
  }

  /* ── Print Header/Footer ────────────────────────────── */
  .print-header {
    display: block !important;
    text-align: center;
    font-size: 9pt;
    color: #666 !important;
    border-bottom: 1px solid #ddd;
    padding-bottom: 4pt;
    margin-bottom: 12pt;
  }

  .print-footer {
    display: block !important;
    text-align: center;
    font-size: 9pt;
    color: #666 !important;
    border-top: 1px solid #ddd;
    padding-top: 4pt;
    margin-top: 12pt;
  }

  /* ── Specific Screen Adjustments ────────────────────── */

  /* Blood results table — compact for print */
  .blood-results-table td {
    padding: 2px 4px !important;
    font-size: 9pt !important;
  }

  /* Protocol cards — single column for readability */
  .protocol-cards {
    display: block !important;
  }

  /* Graph — hide visualization, show node list */
  .graph-visualization, canvas, svg.graph {
    display: none !important;
  }
}
