/* ==========================================================================
   SHA LAB LIS — Print stylesheet
   A4 laboratory reports, A4 invoices, thermal receipts and barcode labels.
   Loaded with media="print" and also applied inside print preview windows.
   ========================================================================== */

@page { size: A4; margin: 12mm 10mm 14mm; }
@page thermal { size: 80mm auto; margin: 3mm; }
@page label { margin: 0; }

@media print {
  html, body { background: #fff !important; margin: 0; padding: 0; }
  .no-print, .sidebar, .topbar, .toasts, .modal-backdrop, .pagination, .toolbar { display: none !important; }
  .content { padding: 0 !important; }
  a[href]::after { content: none !important; }
  .print-page { page-break-after: always; }
  .print-page:last-child { page-break-after: auto; }
  tr, .avoid-break { page-break-inside: avoid; }
  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }
}

/* ------------------------------------------------------- document shell -- */
.doc {
  background: #fff;
  color: #111827;
  font-family: 'Noto Kufi Arabic', 'Inter', 'Segoe UI', Tahoma, sans-serif;
  font-size: 11pt;
  line-height: 1.45;
}
.doc--a4 { width: 190mm; min-height: 273mm; margin: 0 auto; padding: 0; position: relative; }
.doc--thermal { width: 72mm; margin: 0 auto; font-size: 9pt; }

.doc__watermark {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 72pt; font-weight: 800; color: rgba(15, 23, 42, .05);
  transform: rotate(-28deg); pointer-events: none; z-index: 0; letter-spacing: .1em;
}
.doc > * { position: relative; z-index: 1; }

/* ------------------------------------------------------------- header ---- */
.doc__head {
  display: flex; align-items: flex-start; gap: 12mm;
  border-bottom: 2.4pt solid #0d5955; padding-bottom: 4mm; margin-bottom: 5mm;
}
.doc__logo { width: 22mm; height: 22mm; object-fit: contain; flex: 0 0 22mm; }
/* Both letterheads side by side, when a partner report carries the two. */
.doc__logos { display: flex; gap: 3mm; align-items: center; flex: 0 0 auto; }
.doc__logos .doc__logo { width: 18mm; height: 18mm; flex: 0 0 18mm; }
.doc__logo-fallback {
  width: 22mm; height: 22mm; flex: 0 0 22mm; border-radius: 4mm;
  background: linear-gradient(135deg, #128a83, #0d5955);
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 13pt;
}
.doc__lab { flex: 1; min-width: 0; }
.doc__lab h1 { font-size: 17pt; margin: 0 0 1mm; color: #0d5955; font-weight: 700; }
.doc__lab .doc__sub { font-size: 9pt; color: #4b5563; line-height: 1.5; }
.doc__meta { text-align: end; font-size: 8.5pt; color: #4b5563; min-width: 42mm; }
.doc__meta strong { color: #111827; }
.doc__title {
  text-align: center; font-size: 13pt; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: #0d5955; margin: 3mm 0 4mm;
  border-block: 1pt solid #d1d5db; padding: 1.6mm 0;
}

/* ----------------------------------------------------- patient details --- */
.doc__patient {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5mm 6mm;
  border: 1pt solid #d1d5db; border-radius: 2mm; padding: 3mm 4mm; margin-bottom: 4mm;
  font-size: 9.5pt; background: #f9fafb;
}
.doc__patient div { min-width: 0; }
.doc__patient .lbl { color: #6b7280; font-size: 8pt; display: block; }
.doc__patient .val { font-weight: 650; color: #111827; word-break: break-word; }

/* ------------------------------------------------------- result table ---- */
table.doc__table { width: 100%; border-collapse: collapse; font-size: 10pt; }
.doc__table th {
  background: #0d5955; color: #fff; text-align: start; padding: 2mm 2.5mm;
  font-size: 8.5pt; font-weight: 650; letter-spacing: .03em; text-transform: uppercase;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.doc__table td { padding: 1.7mm 2.5mm; border-bottom: .6pt solid #e5e7eb; vertical-align: top; }
.doc__table tr.dept-row td {
  background: #eef7f6; font-weight: 700; color: #0d5955; font-size: 9.5pt;
  padding: 2mm 2.5mm; letter-spacing: .04em;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.doc__table .num { text-align: end; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: plaintext; }
.doc__table .res { font-weight: 700; font-size: 10.5pt; }
.doc__table .res--abn { color: #b91c1c; }
.doc__table .res--crit { color: #fff; background: #b91c1c; padding: .4mm 1.6mm; border-radius: 1mm;
  -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.doc__flag { font-weight: 800; font-size: 9pt; }
.doc__flag--H, .doc__flag--HH { color: #b45309; }
.doc__flag--L, .doc__flag--LL { color: #1d4ed8; }
.doc__flag--HH, .doc__flag--LL { color: #b91c1c; }
.doc__comment { font-size: 8.5pt; color: #4b5563; font-style: italic; padding-inline-start: 3mm; }
.doc__note { font-size: 8.5pt; color: #4b5563; margin-top: 3mm; }

/* ------------------------------------------------------------ footer ----- */
.doc__signatures {
  display: flex; justify-content: space-between; gap: 8mm; margin-top: 12mm;
  page-break-inside: avoid;
}
.doc__sign { flex: 1; text-align: center; font-size: 8.5pt; }
.doc__sign img { max-height: 14mm; margin-bottom: 1mm; }
.doc__sign .line { border-top: .8pt solid #9ca3af; margin: 8mm 4mm 1.2mm; }
.doc__sign .name { font-weight: 650; color: #111827; }
.doc__sign .role { color: #6b7280; font-size: 8pt; }

.doc__foot {
  margin-top: 6mm; padding-top: 3mm; border-top: 1pt solid #d1d5db;
  display: flex; justify-content: space-between; align-items: flex-end; gap: 6mm;
  font-size: 8pt; color: #6b7280;
}
.doc__qr { text-align: center; font-size: 7pt; }
.doc__qr svg { width: 22mm; height: 22mm; display: block; }
.doc__verify-code { font-family: 'SF Mono', Menlo, monospace; letter-spacing: .08em; font-size: 7.5pt; }

/* --------------------------------------------------------- receipts ------ */
.receipt { width: 72mm; font-size: 9pt; }
.receipt__head { text-align: center; margin-bottom: 3mm; }
.receipt__head h2 { font-size: 12pt; margin: 0 0 1mm; }
.receipt__head .sub { font-size: 8pt; color: #4b5563; }
.receipt__rows { width: 100%; border-collapse: collapse; font-size: 8.5pt; }
.receipt__rows td { padding: 1mm 0; vertical-align: top; }
.receipt__rows .num { text-align: end; direction: ltr; unicode-bidi: plaintext; }
.receipt__sep { border-top: 1px dashed #9ca3af; margin: 2mm 0; }
.receipt__total { font-weight: 800; font-size: 11pt; }
.receipt__foot { text-align: center; font-size: 7.5pt; color: #6b7280; margin-top: 3mm; }

/* ----------------------------------------------------------- labels ------ */
.labels { display: flex; flex-wrap: wrap; gap: 2mm; }
.label {
  border: .5pt solid #d1d5db; padding: 1.6mm 2mm; box-sizing: border-box;
  display: flex; flex-direction: column; justify-content: space-between;
  page-break-inside: avoid; overflow: hidden; background: #fff;
}
.label__top { display: flex; justify-content: space-between; gap: 2mm; font-size: 7pt; }
.label__name { font-weight: 700; font-size: 8.5pt; line-height: 1.2; }
.label__meta { font-size: 6.5pt; color: #374151; line-height: 1.3; }
.label__code { font-family: 'SF Mono', Menlo, monospace; font-size: 8pt; letter-spacing: .04em;
  text-align: center; direction: ltr; }
.label svg { display: block; width: 100%; height: auto; }
@media print { .label { border: none; } }

/* ------------------------------------------------------------ A4 invoice - */
.inv__table { width: 100%; border-collapse: collapse; font-size: 10pt; margin-top: 4mm; }
.inv__table th { background: #f3f4f6; padding: 2mm; text-align: start; font-size: 9pt;
  border-bottom: 1pt solid #d1d5db; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.inv__table td { padding: 2mm; border-bottom: .5pt solid #e5e7eb; }
.inv__totals { margin-inline-start: auto; width: 70mm; margin-top: 4mm; font-size: 10pt; }
.inv__totals tr td { padding: 1.4mm 2mm; }
.inv__totals tr:last-child td { font-weight: 800; font-size: 11.5pt; border-top: 1.2pt solid #111827; }

/* ------------------------------------------------- on-screen preview ----- */
.print-preview { background: #e5e7eb; padding: 20px; display: grid; place-items: start center; min-height: 60vh; }
.print-preview .doc {
  box-shadow: 0 8px 30px rgba(0,0,0,.16); padding: 12mm 10mm 14mm; border-radius: 2px;
}
.print-preview .doc--thermal { padding: 4mm; }
