/* UKLU global print rules (loaded with media="print"). Companion to js/utils/print-engine.js.
   Guarantees: pure white paper + dark ink even when the staff app is in Dark Mode, no app chrome, RTL-correct tables,
   rows/totals/signatures never split across pages, per-clinic accent and black & white mode. */
@media print {
  :root { color-scheme: light; }
  html, body { background: #ffffff !important; color: #111111 !important; }

  /* App chrome never prints (the in-page print areas are revealed by the printing-* body classes in index.html) */
  #modal-root, #toast-root, .toast, [role="dialog"], #mobile-bottom-nav, #mobile-more-sheet { display: none !important; }

  /* The in-page print areas: white, dark ink, RTL, accent from clinic settings */
  #quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area, #prescription-print-area {
    background: #ffffff !important; color: #111111 !important; direction: rtl; -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  :is(#quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area) * {
    text-shadow: none !important; box-shadow: none !important;
  }
  /* Dark Mode fallback: if the .dark class is still on <html>, neutralise every dark override inside the print areas */
  html.dark :is(#quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area, #prescription-print-area),
  html.dark :is(#quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area, #prescription-print-area) * {
    color: #111111 !important; border-color: #888888 !important;
  }
  html.dark :is(#quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area, #prescription-print-area),
  html.dark :is(#quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area, #prescription-print-area) [class*="bg-"] {
    background-color: #ffffff !important;
  }

  /* Arabic text starts on the right; only numeric/currency columns are LTR + tabular */
  :is(#quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area) :is(th, td) { text-align: right; }
  :is(#quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area) :is(th, td).text-left,
  :is(#quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area) :is(th, td).ds-num {
    text-align: left; unicode-bidi: plaintext; font-variant-numeric: tabular-nums;
  }

  /* Pagination */
  :is(#quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area) :is(tr, .print-kpi-card, .print-signatures, .print-banner, .ds-sign, .ds-kpi) {
    break-inside: avoid; page-break-inside: avoid;
  }
  :is(#quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area) thead { display: table-header-group; }
  :is(#quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area) tfoot { display: table-row-group; }
  :is(#quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area) :is(h2, h3) { break-after: avoid; page-break-after: avoid; }

  /* Clinic accent colour on the document header rule */
  html.dp-printing :is(#quotation-print-area, #statement-print-area, #doctor-statement-print-area, #report-print-area) :is(.print-header, .ds-head) {
    border-bottom-color: var(--print-accent, #0F766E) !important;
  }

  /* Black & white (laser / toner saving) */
  html.dp-print-bw body, html.dp-print-bw body * {
    background: #ffffff !important; color: #000000 !important; border-color: #000000 !important; box-shadow: none !important;
  }
  html.dp-print-bw img { filter: grayscale(1) contrast(1.2); }
}
