.patient-panel { padding: 24px; margin-bottom: 22px; }
.patient-search, .patient-actions, .patient-pagination { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.patient-search input { flex: 1; min-width: 220px; padding: 12px; border: 1px solid #cbd9d6; border-radius: 8px; }
.patient-search label { font-weight: 600; }
.patient-pagination { margin-top: 22px; justify-content: flex-end; }
.patient-pagination span { margin-right: auto; }
.patient-details { display: grid; grid-template-columns: minmax(180px, 1fr) 2fr; gap: 12px 24px; }
.patient-details dt { font-weight: 600; }
.patient-details dd { margin: 0; overflow-wrap: anywhere; white-space: normal; }
.patient-image { display: block; max-width: 500px; width: 100%; height: auto; margin-bottom: 20px; }
.patient-delete { color: #a22b42; }
.patient-scanner { margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px solid #d6dfdd; }
.patient-scanner summary { cursor: pointer; font-weight: 600; color: #215f55; }
.patient-scanner input { max-width: 100%; }
#qr-video { display: block; width: 100%; max-width: 480px; max-height: 360px; margin-top: 16px; background: #111; border-radius: 8px; object-fit: cover; }
#qr-status { max-width: 640px; }
.patient-qr { margin: 12px auto 0; text-align: center; break-inside: avoid; }
.patient-qr img { display: block; width: 42mm; height: 42mm; margin: 0 auto; }
.patient-qr figcaption { margin-top: 3px; font-size: 10px; color: #526661; letter-spacing: normal; }
.patient-qr-download { display: inline-block; margin-top: 6px; font-size: 12px; text-decoration: underline; }

.patient-print-sheet {
  max-width: 210mm;
  margin: 0 auto;
  color: #1f2a2a;
  font-family: "Segoe UI", Arial, sans-serif;
}
.patient-print-header {
  display: block;
  margin-bottom: 24px;
  break-inside: avoid;
}
.patient-letterhead {
  display: grid;
  grid-template-columns: calc(2in + 6px) minmax(0, 1fr) 1in;
  align-items: center;
  gap: 10px;
  padding: 0 0 16px;
  border-bottom: 4px double #538135;
  margin-bottom: 20px;
}
.letterhead-logos { display: flex; align-items: center; gap: 6px; }
.letterhead-logos img { width: 1in; height: 1in; flex-shrink: 0; object-fit: contain; }
.letterhead-moh {
  width: 1in;
  height: 1in;
  aspect-ratio: 1;
  /* The source logo is horizontally stretched; restore its circular proportions. */
  object-fit: fill;
  border-radius: 50%;
}
.letterhead-text { text-align: center; font-family: "Times New Roman", serif; color: #111; line-height: 1.3; }
.letterhead-text p { margin: 0; font-size: 11px; }
.letterhead-text .letterhead-region { font-weight: 700; }
.letterhead-text .letterhead-ministry { font-size: 18px; font-weight: 700; margin: 3px 0; }
.letterhead-text .letterhead-contact { font-size: 9px; }
.patient-print-sheet { background: #fff; padding: 28px; line-height: 1.45; }
.patient-print-sheet .print-grid { display: block; }
.patient-print-sheet .print-row {
  display: grid;
  grid-template-columns: minmax(0, 45fr) minmax(0, 55fr);
  gap: 20px;
}
.patient-doc-title {
  margin-bottom: 18px;
  text-align: center;
}
.print-eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: #4b5e5d;
  text-transform: uppercase;
}
.patient-doc-title h1,
.patient-print-header h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
  color: #1b2b2b;
}
.patient-print-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 24px;
  min-width: 0;
  font-size: 12px;
  border-top: 1px solid #cbd5c7;
  border-bottom: 1px solid #cbd5c7;
  padding: 12px 0;
}
.patient-print-meta div:nth-child(2) { grid-column: 1 / -1; grid-row: 1; }
.patient-print-meta div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: baseline;
}
.patient-print-meta span {
  color: #526661;
}
.patient-print-meta strong {
  font-weight: 600;
  color: #1f2a2a;
}
.print-section {
  margin-bottom: 18px;
  border: 0;
  padding: 0;
  break-inside: auto;
}
.print-section h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #2b3f3d;
  border-bottom: 1px solid #8b9e80;
  padding: 7px 0;
  break-after: avoid;
}
.print-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px 16px;
  align-items: start;
}
.print-row {
  display: contents;
}
.print-label, .print-value {
  padding: 8px 0;
  border-bottom: 1px solid #edf1ef;
  font-size: 12px;
}
.print-label {
  font-weight: 600;
  color: #334744;
  grid-column: auto;
}
.print-value {
  color: #1f2a2a;
  white-space: normal;
  overflow-wrap: anywhere;
}
.print-empty {
  margin: 0;
  color: #62736f;
  font-size: 12px;
}
.print-attachment {
  padding-top: 10px;
  border-top: 1px solid #edf1ef;
  margin-top: 10px;
}
.print-attachment:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}
.attachment-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: #334744;
}
.attachment-meta {
  margin-bottom: 10px;
  font-size: 12px;
}
.attachment-meta a {
  color: #1a4a67;
  text-decoration: none;
}
@page { size: A4; margin: 25.4mm; }
@media print {
  .patient-qr-download, .patient-scanner { display: none !important; }
  html, body, .app-shell, .workspace, .dashboard {
    display: block !important;
    width: auto !important;
    max-width: none !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  .dashboard-footer { display: none !important; }
  body {
    background: #fff !important;
    color: #1f2a2a !important;
  }
  .sidebar, .topbar, .breadcrumb, .page-heading, .patient-actions, .button, .patient-search, .patient-pagination, .patient-delete, .patient-panel {
    display: none !important;
  }
  .patient-print-sheet {
    display: block !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .print-section, .patient-print-header {
    box-shadow: none !important;
    background: #fff !important;
  }
  .patient-print-header {
    display: block;
    break-inside: avoid;
  }
  .patient-print-meta { min-width: 0; margin-top: 12px; }
  .patient-print-meta strong { overflow-wrap: anywhere; }
  .print-section {
    border: 0;
    border-radius: 0;
    padding: 0;
    margin: 0 0 6mm;
    break-inside: auto;
  }
  .print-section h2, .patient-doc-title {
    break-after: avoid;
    page-break-after: avoid;
  }
  .print-grid { display: block; }
  .print-row {
    display: grid;
    grid-template-columns: minmax(0, 45fr) minmax(0, 55fr);
    gap: 5mm;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .print-label, .print-value { font-size: 10pt; overflow-wrap: anywhere; }
  .print-label, .print-value { padding: 2mm 0; }
  .print-section h2 { font-size: 10pt; margin-bottom: 1mm; }
  .patient-doc-title h1 { font-size: 20pt; }
  .patient-letterhead { margin-bottom: 5mm; padding-bottom: 4mm; }
  .print-attachment { break-inside: avoid; }
  .patient-image {
    max-width: 100%;
    max-height: 180mm;
    object-fit: contain;
    margin-bottom: 12px;
  }
}
@media (max-width: 640px) { .patient-details { grid-template-columns: 1fr; gap: 8px; } .patient-details dd { margin-bottom: 14px; } }
