/* ============================================================================
   THAI SARABAN A4 PRINT & LIVE PREVIEW STANDARD
   Enforces local TH SarabunPSK .ttf + thai-saraban-webprint + print-3x
   NOTE: Zero hardcoded global @page rule here (injected dynamically on print)
   ============================================================================ */

@font-face {
  font-family: 'TH SarabunPSK';
  src: url('/fonts/THSarabun.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'TH SarabunPSK';
  src: url('/fonts/THSarabun-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'TH SarabunPSK';
  src: url('/fonts/THSarabun-Italic.ttf') format('truetype');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: 'TH SarabunPSK';
  src: url('/fonts/THSarabun-BoldItalic.ttf') format('truetype');
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}

/* True Thai Distributed Justification helpers */
.th-word {
  display: inline;
  white-space: nowrap;
}

.th-cj {
  display: inline;
  font-size: 0px;
  line-height: 0;
  white-space: nowrap;
}

.th-wj {
  display: inline;
  font-size: 0px;
  line-height: 0;
  white-space: normal;
}

/* Print container hidden on screen */
#printArea {
  display: none;
}

/* A4 Paper Canvas (used identically inside Studio Preview and #printArea) */
.a4-sheet {
  width: 210mm;
  min-height: 297mm;
  padding: 25mm 20mm 20mm 30mm;
  margin: 0 auto;
  background: #FFFFFF !important;
  color: #000000 !important;
  box-sizing: border-box !important;
  font-family: 'TH SarabunPSK', serif !important;
  font-size: 16pt;
  font-weight: 400;
  font-synthesis: none !important;
  line-height: 1.38;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.42);
  overflow-wrap: break-word;
}

.a4-sheet * {
  font-family: 'TH SarabunPSK', serif !important;
  font-synthesis: none !important;
  color: #000000;
}

.a4-sheet.a4-report-margins {
  padding: 20mm 18mm 18mm 22mm;
}

/* Official Memo Header */
.saraban-memo-head {
  position: relative;
  text-align: center;
  min-height: 1.55cm;
  margin-bottom: 6pt;
}

.saraban-garuda {
  position: absolute;
  left: 0;
  top: 0;
  height: 1.5cm;
  width: auto;
}

.saraban-memo-title {
  font-size: 29pt;
  font-weight: 700;
  line-height: 1.15;
  padding-top: 6pt;
}

.saraban-meta-line {
  font-size: 16pt;
  line-height: 1.38;
  margin-bottom: 2pt;
}

.saraban-meta-split {
  display: flex;
  justify-content: space-between;
  gap: 12pt;
}

.saraban-meta-label {
  font-weight: 700;
}

.saraban-hr {
  border: none;
  border-top: 1px solid #000000;
  margin: 5pt 0 8pt 0;
}

.saraban-body-p {
  margin: 0 0 6pt 0;
  text-indent: 2.5cm;
  text-align: justify;
  line-height: 1.38;
}

.saraban-sub-p {
  margin: 0 0 4pt 0;
  text-indent: 3.2cm;
  text-align: justify;
  line-height: 1.38;
}

/* A4 Tables (with tone-mark anti-clipping) */
.a4-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8pt 0 10pt 0;
  font-size: 14.5pt;
  line-height: 1.42;
}

.a4-table th,
.a4-table td {
  border: 0.75pt solid #000000;
  padding: 3pt 5pt;
  vertical-align: middle;
}

.a4-table th {
  font-weight: 700;
  text-align: center;
  background: #F1F5F9 !important;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.a4-table tr {
  page-break-inside: avoid;
  break-inside: avoid;
}

/* Signature Block */
.saraban-sig-wrap {
  margin-top: 18pt;
  display: flex;
  justify-content: flex-end;
  page-break-inside: avoid;
  break-inside: avoid;
}

.saraban-sig-box {
  width: 78mm;
  text-align: center;
  line-height: 1.38;
}

.saraban-sig-dual {
  margin-top: 22pt;
  display: flex;
  justify-content: space-between;
  gap: 14mm;
  page-break-inside: avoid;
  break-inside: avoid;
}

.saraban-sig-dual .saraban-sig-box {
  width: 45%;
}

.a4-school-header {
  display: flex;
  align-items: center;
  gap: 12pt;
  border-bottom: 1.5pt solid #000000;
  padding-bottom: 6pt;
  margin-bottom: 10pt;
}

.a4-school-logo {
  width: 16mm;
  height: 16mm;
  object-fit: cover;
  border-radius: 4pt;
}

/* Direct-Body Print Isolation */
@media print {
  html, body {
    background: #FFFFFF !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  #demoBar,
  #appShell {
    display: none !important;
  }

  #printArea {
    display: block !important;
    position: static !important;
    width: 210mm !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #FFFFFF !important;
  }

  .a4-sheet {
    box-shadow: none !important;
    margin: 0 !important;
    page-break-after: auto;
  }
}
