/* =============================================================================
   A4 print layout + @media print rules — specs.md §13
   Compact single-page (or front/back) A4 portrait sheet, 5mm margins
   ========================================================================== */
@page {
  size: A4;
  margin: 5mm;
}

body { font-size: 9px; }

/* Screen preview of the sheet */
.a4-sheet {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  background: #fff;
  color: #111;
  padding: 4mm;
  border: 1px solid #e5e5e5;
  box-shadow: 0 3px 14px rgba(0, 0, 0, .16);
  font-size: 9px;
  font-family: 'Inter', Arial, sans-serif;
}

.print-page .app-content { background: #e9ecef; }

/* ---------------- Sheet header ---------------- */
.sheet-header {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 2px solid #111;
  padding-bottom: 4px;
  margin-bottom: 6px;
}
.sheet-logo { height: 38px; width: auto; object-fit: contain; }
.sheet-name { font-size: 14px; font-weight: 700; line-height: 1.15; }
.sheet-addr { font-size: 8px; color: #333; }
.sheet-meta { margin-left: auto; text-align: right; font-size: 8px; line-height: 1.4; }

/* ---------------- Sheet tables & text blocks ---------------- */
.sheet-table { width: 100%; border-collapse: collapse; margin-bottom: 4px; }
.sheet-table th,
.sheet-table td { border: 1px solid #333; padding: 1px 4px; font-size: 8px; vertical-align: top; }
.sheet-table th {
  background: #f4f4f4;
  font-weight: 600;
  text-align: left;
  width: 66px;
  white-space: nowrap;
}

/* Vision table (9-column Auto R / Distance / Near* grid): tight rows keep
   the printout on a single A4 portrait page */
.sheet-vision th,
.sheet-vision td { padding: 0 2px; line-height: 1.3; white-space: nowrap; }
.sheet-vision thead th { width: auto; text-align: center; }
.sheet-vision thead th:first-child { width: 66px; text-align: left; }
/* REFRACTION / OPTICAL heading + column header row (blank first cell,
   SPH/CYL/Axis/V-A for each eye) with a subtle OD | OS divider */
.sheet-vision .refraction-heading {
  text-align: center;
  font-weight: 700;
  border-top: 1px solid #333;
}
.sheet-vision .sub-header th {
  background: #eef3f7;
  text-align: center;
  font-weight: 700;
  width: auto;
}
.sheet-vision tbody td:nth-of-type(4),
.sheet-vision .sub-header th:nth-of-type(5) { border-right: 2px solid #333; }

.sheet-section-title {
  font-weight: 700;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid #333;
  padding-bottom: 1px;
  margin: 5px 0 3px;
}

.sheet-label { display: block; font-size: 8px; font-weight: 600; color: #333; text-transform: uppercase; }
.sheet-text {
  border: 1px solid #333;
  padding: 2px 4px;
  min-height: 20px;
  white-space: pre-wrap;
  font-size: 8.5px;
  margin-bottom: 4px;
}

/* Printed vision grid: two columns OD / OS */
.sheet-od-os { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

/* Disease group boxes (paper-style) */
.sheet-disease-grid { display: flex; flex-wrap: wrap; gap: 4px; }
.sheet-disease-item {
  border: 1px solid #333;
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.sheet-disease-item .box {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1px solid #333;
  font-size: 9px;
  line-height: 9px;
  text-align: center;
}
.sheet-disease-item.checked { background: #f0f0f0; font-weight: 600; }
.sheet-disease-item.checked .box::before { content: "\2713"; }

/* History chips (HTN / DM / ...) */
.hx-item {
  display: inline-block;
  border: 1px solid #333;
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 8px;
  margin: 0 4px 4px 0;
}
.hx-item.checked { background: #111; color: #fff; }

/* SVG eye diagrams area */
.sheet-diagrams { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0; }
.sheet-diagrams svg { border: 1px solid #333; border-radius: 4px; }

/* =============================================================================
   Digital stamp (Change 2)
   The doctor's stamp is drawn automatically at the bottom-right of every
   printed sheet — there is no manual signature or "Stamp" line any more.
   ========================================================================== */
.sheet-stamp {
  margin-top: 8mm;
  width: 58mm;
  margin-left: auto;
  border: 1.5px solid #1a3d6d;
  border-radius: 3px;
  padding: 1.5mm 2mm;
  text-align: center;
  color: #1a3d6d;
  transform: rotate(-4deg);
  opacity: .85;
  background: rgba(255, 255, 255, .6);
  break-inside: avoid;
}

.sheet-stamp .st-hospital {
  font-size: 7px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  line-height: 1.3;
}

.sheet-stamp .st-doctor {
  font-size: 11px;
  font-weight: 800;
  margin: .5mm 0;
  line-height: 1.2;
}

.sheet-stamp .st-designation {
  font-size: 7.5px;
  letter-spacing: .03em;
  line-height: 1.3;
}

/* Double rule above and below the stamp so it reads as a real seal. */
.sheet-stamp::before,
.sheet-stamp::after {
  content: "";
  display: block;
  border-top: 1px solid currentColor;
  margin: 1mm 0;
  opacity: .5;
}

/* =============================================================================
   @media print — hide app chrome, print only the sheet (any page: Ctrl+P)
   ========================================================================== */
@media print {
  body { background: #fff !important; font-size: 9px; }

  .sidebar,
  .sidebar-backdrop,
  .topbar,
  .app-footer,
  .ai-assistant,
  .toast-stack,
  .print-toolbar,
  .no-print { display: none !important; }

  .app-shell { display: block !important; min-height: 0 !important; }
  .app-main { display: block !important; }
  .app-content { padding: 0 !important; animation: none !important; }

  .card { box-shadow: none !important; border-color: #dee2e6 !important; }

  .a4-sheet {
    width: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    font-size: 9px !important;
  }

  .sheet-table, .sheet-text, .sheet-table th, .sheet-table td { break-inside: avoid; }
  .sheet-disease-item, .hx-item { break-inside: avoid; }
  .sheet-section-title { break-after: avoid; }
  .sheet-stamp { break-inside: avoid; }

  a[href]::after { content: none !important; }
}
