/* DocRx print stylesheet — P-10.
   Served with media="print" from index.html so it is downloaded but never applied on screen.
   Cascade note: Vite injects the bundled app CSS at the end of <head>, i.e. AFTER this sheet, so
   these rules are earlier in source order. Every override that competes with app utilities uses
   !important so print layout stays deterministic across screen sizes and paper formats. */
@media print {
  @page {
    /* Paper size is injected at print time from the doctor's selected
       A4/A5/Letter setting. Keep this rule size-neutral as a fallback. */
    margin: 0;
  }

  html, body {
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    color: #0f172a !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  /* Isolate print document when a prescription pad is mounted: remove non-prescription branches
     from layout flow so invisible shells and measurement trees never emit blank trailing pages. */
  body:has(#printable-prescription) *:not(#printable-prescription):not(#printable-prescription *):not(:has(#printable-prescription)) {
    display: none !important;
  }

  /* Normalize ancestor containers around #printable-prescription so the paper prints in normal
     block flow from (0, 0) without sidebar margins, viewport min-heights, or flex fragmentation bugs. */
  body:has(#printable-prescription) *:has(#printable-prescription) {
    display: block !important;
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
    min-height: 0 !important;
    height: auto !important;
    width: auto !important;
    max-width: none !important;
    overflow: visible !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
  }

  /* Expose prescription container and preserve inner backgrounds (accent bar, badges). */
  #printable-prescription,
  #printable-prescription * {
    visibility: visible;
    box-shadow: none !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Truly hide all action buttons, reorder chevrons, modals, banners, toolbars, measurement trees */
  .no-print,
  .print\:hidden,
  [class*="print:hidden"],
  [data-html2canvas-ignore="true"],
  [data-measure="true"] {
    display: none !important;
    visibility: hidden !important;
  }

  /* The pad's patient strip is plain text on paper; its screen-only dossier cue never prints. */
  [data-pad-patient-strip] {
    background: transparent !important;
    border-bottom: 1px solid #d8e2dd !important;
  }
  [data-pad-patient-strip] button {
    display: none !important;
  }

  [data-docrx-paper-chrome] {
    background-color: transparent !important;
  }

  /* Keep printable prescription in normal block flow for clean multi-page pagination. */
  #printable-prescription {
    position: static !important;
    margin: 0 !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    background-color: transparent !important;
    overflow: visible !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  #printable-prescription,
  #printable-prescription * {
    animation: none !important;
    transition: none !important;
  }

  #printable-prescription [data-section="doctor-letterhead"],
  #printable-prescription header {
    visibility: visible !important;
    opacity: 1 !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  #printable-prescription [data-section="patient-demographics"],
  #printable-prescription [data-section="continuation-header"] {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  #printable-prescription [data-section="chamber-footer"],
  #printable-prescription footer {
    visibility: visible !important;
    opacity: 1 !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    break-after: avoid !important;
    page-break-after: avoid !important;
  }

  /* Ensure lines of text and medication items never split across page breaks */
  #printable-prescription li,
  #printable-prescription tr,
  #printable-prescription .prescription-item-row,
  #printable-prescription .clinical-section-card,
  #printable-prescription [data-section="signature-block"] {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
}
