/* Standard visual contract for every printable report, preview and PDF. */
:root {
  --report-letter-width: 216mm;
  --report-letter-height: 330mm;
  --report-letter-margin: 12mm;
  --report-ink: #172033;
  --report-blue: #123d78;
  --report-blue-soft: #eaf2ff;
  --report-yellow: #ffd447;
  --report-line: #b5c9e2;
}

/* Formato oficial único para vista previa, impresión y PDF. */
@page { size: 216mm 330mm; margin: 0; }
@page letter-landscape { size: 330mm 216mm; margin: 0; }

#module-informes .letter-layout-page.letter-landscape-page {
  page: letter-landscape !important;
}

#module-informes .academic-grade-table .academic-annual-general > * {
  border-top: 3px solid var(--report-yellow) !important;
  background: var(--report-blue) !important;
  color: #fff !important;
  font-weight: 800 !important;
}

#module-informes .academic-grade-table .academic-annual-general th {
  text-align: right !important;
}

body.report-print-body,
body.report-pdf-render {
  background: #f3f6fb !important;
  color: var(--report-ink) !important;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
  overflow-x: visible !important;
}

body.report-print-body .report-print-root,
body.report-pdf-render .report-print-root {
  width: var(--letter-width, var(--report-letter-width)) !important;
  max-width: var(--letter-width, var(--report-letter-width)) !important;
  margin: 18px auto !important;
  padding: 0 !important;
  overflow-x: visible !important;
}

body.report-print-body.report-landscape-document .report-print-root,
body.report-pdf-render.report-landscape-document .report-print-root {
  width: var(--letter-width, 330mm) !important;
  max-width: var(--letter-width, 330mm) !important;
}

/* ui-final.css conservaba el ancho vertical (215,9 mm) también cuando el
   documento era horizontal. En pantalla eso recortaba tanto la barra como los
   últimos campos del informe. La ventana ocupa el viewport y solamente la hoja
   mantiene su medida física; fitLetterReportViewport se encarga de escalarla. */
@media screen {
  html body.report-print-body.report-landscape-document {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
  }

  html body.report-print-body.report-landscape-document .report-preview-toolbar {
    width: 100% !important;
    max-width: 100% !important;
  }
}

html body.report-print-body.report-landscape-document :is(#module-informes,.report-print-root),
html body.report-pdf-render.report-landscape-document :is(#module-informes,.report-print-root) {
  width: var(--letter-width, 330mm) !important;
  max-width: var(--letter-width, 330mm) !important;
}

html body.report-print-body.report-landscape-document .report-print-page,
html body.report-pdf-render.report-landscape-document .report-print-page {
  width: var(--letter-width, 330mm) !important;
  max-width: var(--letter-width, 330mm) !important;
  height: var(--letter-height, 216mm) !important;
  min-height: var(--letter-height, 216mm) !important;
  max-height: var(--letter-height, 216mm) !important;
}

#module-informes .letter-layout-page {
  width: var(--letter-width, var(--report-letter-width)) !important;
  max-width: var(--letter-width, var(--report-letter-width)) !important;
  height: var(--letter-height, var(--report-letter-height)) !important;
  min-height: var(--letter-height, var(--report-letter-height)) !important;
  max-height: var(--letter-height, var(--report-letter-height)) !important;
  padding: var(--report-letter-margin) !important;
  background: #fff !important;
  color: var(--report-ink) !important;
  box-shadow: 0 12px 34px rgba(15, 23, 42, .14) !important;
}

#module-informes .letter-layout-page.letter-landscape-page {
  --report-letter-margin: 12mm;
}

#module-informes .letter-layout-page :is(.report-header,.academic-report-header,.certificate-head,.achievement-summary-heading,.letter-institutional-header) {
  border-bottom-color: var(--report-blue) !important;
}

#module-informes .letter-layout-page :is(h1,h2,h3,h4) { color: var(--report-blue) !important; }
#module-informes .letter-layout-page :is(th,td) { border-color: var(--report-line) !important; }
#module-informes .letter-layout-page th { background: var(--report-blue-soft) !important; color: var(--report-blue) !important; }

#module-informes .letter-layout-page :is(table,.table-wrap,[class*="scroll"]) {
  overflow: visible !important;
  max-width: 100% !important;
}

/* Pagination replaces internal scrolling. Scrollbars stay hidden but normal
   wheel/keyboard navigation remains available between report pages. */
body.report-print-body :is(.report-print-root,.report-print-page,.letter-layout-page,.letter-layout-content,.table-wrap,[class*="scroll"]),
body.report-pdf-render :is(.report-print-root,.report-print-page,.letter-layout-page,.letter-layout-content,.table-wrap,[class*="scroll"]) {
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}

body.report-print-body :is(.report-print-root,.report-print-page,.letter-layout-page,.letter-layout-content,.table-wrap,[class*="scroll"])::-webkit-scrollbar,
body.report-pdf-render :is(.report-print-root,.report-print-page,.letter-layout-page,.letter-layout-content,.table-wrap,[class*="scroll"])::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}

#module-informes .letter-layout-page table {
  table-layout: fixed !important;
  border-collapse: collapse !important;
}

#module-informes .letter-layout-page :is(th,td) {
  overflow-wrap: anywhere !important;
  word-break: normal !important;
  white-space: normal !important;
}

/* El boletín semestral individual debe conservarse en una sola Carta vertical.
   Reordena la ficha superior en dos filas de tres campos y deja toda la tabla
   dentro del ancho imprimible, sin alterar sus datos. */
body.report-print-body #module-informes .academic-grade-report.is-semestral .academic-report-student-grid,
body.report-pdf-render #module-informes .academic-grade-report.is-semestral .academic-report-student-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  grid-auto-rows: min-content !important;
  align-items: start !important;
}

body.report-print-body #module-informes .academic-grade-report.is-semestral .academic-report-field,
body.report-pdf-render #module-informes .academic-grade-report.is-semestral .academic-report-field,
body.report-print-body #module-informes .academic-grade-report.is-semestral .academic-report-field.is-wide,
body.report-pdf-render #module-informes .academic-grade-report.is-semestral .academic-report-field.is-wide {
  grid-column: auto !important;
}

body.report-print-body #module-informes .academic-grade-report.is-semestral .academic-report-field,
body.report-pdf-render #module-informes .academic-grade-report.is-semestral .academic-report-field {
  min-width: 0 !important;
  min-height: 0 !important;
  display: grid !important;
  grid-template-columns: max-content minmax(0, 1fr) !important;
  align-items: center !important;
  gap: 5px !important;
}

body.report-print-body #module-informes .academic-grade-report.is-semestral .academic-report-field b,
body.report-pdf-render #module-informes .academic-grade-report.is-semestral .academic-report-field b {
  min-width: 0 !important;
  min-height: 0 !important;
  height: auto !important;
  overflow-wrap: break-word !important;
  word-break: normal !important;
}

#module-informes .letter-layout-page :is(thead,tr,figure,.report-signatures,.academic-report-signatures,.certificate-signatures,.firmas,[class*="signature"]) {
  break-inside: avoid !important;
  page-break-inside: avoid !important;
}

#module-informes .letter-layout-page .letter-page-footer {
  left: var(--report-letter-margin) !important;
  right: var(--report-letter-margin) !important;
  bottom: 8mm !important;
  border-top-color: var(--report-yellow) !important;
  color: var(--report-blue) !important;
}

/* Single institutional student record: screen and Carta output share this layout. */
#module-ficha .ficha-personality-card,
#module-ficha .ficha-ranking-card {
  border-top: 3px solid var(--report-yellow) !important;
}

#module-ficha .ficha-ranking-summary {
  margin: 0 0 10px !important;
  color: var(--report-blue) !important;
}

#module-ficha .ficha-ranking-card tr.is-current-student td {
  background: #fff6cc !important;
  color: #503f00 !important;
  font-weight: 800 !important;
}

#module-ficha .ficha-signatures {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18mm;
  margin: 20mm 0 4mm !important;
  break-inside: avoid;
  page-break-inside: avoid;
}

#module-ficha .ficha-signatures div {
  min-height: 14mm;
  border-bottom: 1px solid var(--report-blue);
  display: flex;
  align-items: end;
  justify-content: center;
  padding-bottom: 3mm;
  color: var(--report-blue);
  font-size: 9pt;
  font-weight: 700;
  text-align: center;
}

@media (max-width: 700px) {
  #module-ficha .ficha-signatures { grid-template-columns: 1fr; gap: 9mm; }
}

@media print {
  #module-ficha .ficha-signatures { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media print {
  html, body.report-print-body, body.report-pdf-render {
    background: #fff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.report-print-body .report-print-root,
  body.report-pdf-render .report-print-root {
    margin: 0 auto !important;
    zoom: 1 !important;
  }

  html body.report-print-body.report-landscape-document,
  html body.report-pdf-render.report-landscape-document {
    width: 330mm !important;
    max-width: 330mm !important;
  }

  #module-informes .letter-layout-page {
    margin: 0 !important;
    box-shadow: none !important;
  }

  #module-informes .letter-layout-page:last-child {
    break-after: auto !important;
    page-break-after: auto !important;
  }
}

@media screen and (max-width: 720px) {
  html body.report-print-body .report-preview-toolbar {
    flex-wrap: wrap !important;
    gap: 6px !important;
    padding: 8px 10px !important;
  }

  html body.report-print-body .report-preview-toolbar .report-paper-control {
    flex: 1 0 100% !important;
    margin: 0 !important;
  }

  html body.report-print-body .report-preview-toolbar button {
    flex: 1 1 130px !important;
    justify-content: center !important;
  }
}
