:root {
  --app-font-family: "Sarabun", "TH Sarabun New", "Noto Sans Thai", Arial, sans-serif;
}

html { font-size: 16px; }
body {
  background: #f5f7fb;
  font-family: var(--app-font-family);
  font-size: 1rem;
  line-height: 1.55;
}
button, input, select, textarea, .btn, .form-control, .form-select, .dropdown-menu {
  font-family: var(--app-font-family);
}
.navbar-brand { letter-spacing: .01em; }
.card { border: 0; border-radius: 1rem; box-shadow: 0 8px 26px rgba(31,45,61,.08); }
.table thead th { background: #eef4ff; white-space: nowrap; }
.status-cell { min-width: 170px; }
.question-card { border-left: 5px solid #0d6efd; }
.radio-choice label,
.choice-card { cursor: pointer; }
.choice-card {
  min-height: 48px;
  display: flex !important;
  align-items: center;
  gap: .5rem;
}
.choice-card .form-check-input,
.radio-choice .form-check-input,
.assessment-form .form-check-input {
  flex: 0 0 auto;
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0;
}
.assessment-form .question-title {
  font-size: 1.05rem;
  line-height: 1.55;
}
.assessment-help {
  border-left: 5px solid #0dcaf0;
}
.assessment-actions {
  align-items: center;
}
.print-only { display: none; }

/* รูปแบบรายงานพิมพ์สรุป SDQ ตามระบบดูแลช่วยเหลือนักเรียน */
.moe-report-page {
  max-width: 210mm;
  margin: 0 auto 1.5rem auto;
  border: 1px solid #d8dee9;
  color: #000;
  font-family: var(--app-font-family);
}
.report-table th,
.report-table td {
  border-color: #000 !important;
  padding: .35rem .45rem;
  vertical-align: middle;
}
.report-table thead th {
  background: #fff !important;
}
.signature-block {
  font-size: 1rem;
  line-height: 1.9;
}

@media (max-width: 575.98px) {
  main.container-fluid {
    padding-left: .75rem !important;
    padding-right: .75rem !important;
    padding-top: 1rem !important;
  }
  .assessment-header {
    gap: .75rem !important;
  }
  .assessment-header h1 {
    font-size: 1.35rem;
  }
  .assessment-meta {
    font-size: .95rem;
    line-height: 1.6;
  }
  .assessment-form .card {
    border-radius: .8rem;
  }
  .assessment-form .card-header {
    padding: .8rem .9rem;
  }
  .assessment-form .card-body {
    padding: .75rem;
  }
  .assessment-form .question-card {
    padding: .85rem !important;
    margin-bottom: .75rem !important;
    border-left-width: 4px;
  }
  .assessment-form .question-title {
    font-size: 1rem;
  }
  .choice-card {
    min-height: 52px;
    padding: .75rem .85rem !important;
    border-radius: .65rem !important;
    background: #fff !important;
  }
  .choice-card:has(input:checked) {
    border-color: #0d6efd !important;
    background: #eef4ff !important;
  }
  .assessment-actions {
    position: sticky;
    bottom: 0;
    z-index: 20;
    display: grid !important;
    grid-template-columns: 1fr;
    gap: .5rem !important;
    background: rgba(245,247,251,.98);
    border-top: 1px solid rgba(0,0,0,.08);
    padding: .75rem .75rem calc(.75rem + env(safe-area-inset-bottom));
    margin-left: -.75rem;
    margin-right: -.75rem;
  }
  .assessment-actions .btn {
    width: 100%;
    min-height: 48px;
  }
  .assessment-actions .btn-primary {
    order: -1;
  }
}

@page {
  size: A4 portrait;
  margin: 0;
}
@media print {
  * {
    box-shadow: none !important;
    text-shadow: none !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  html, body {
    width: 210mm !important;
    min-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    font-family: var(--app-font-family) !important;
    font-size: 16pt !important;
    line-height: 1.34 !important;
    background: #fff !important;
    color: #000 !important;
  }
  body * {
    font-family: var(--app-font-family) !important;
  }
  nav, footer, .no-print, .btn, .navbar, .card-header .btn { display: none !important; }
  main.container-fluid,
  .container,
  .container-fluid {
    width: 210mm !important;
    max-width: 210mm !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .card {
    box-shadow: none !important;
    border: 1px solid #bbb !important;
    border-radius: 0 !important;
  }
  .print-only { display: block !important; }
  .moe-report-page {
    width: 210mm !important;
    min-height: 297mm !important;
    max-width: 210mm !important;
    margin: 0 !important;
    padding: 20mm !important;
    border: 0 !important;
    background: #fff !important;
    color: #000 !important;
    font-size: 16pt !important;
    line-height: 1.34 !important;
    page-break-after: always;
    box-sizing: border-box !important;
    overflow: visible !important;
  }
  .moe-report-page:last-of-type {
    page-break-after: auto;
  }
  .moe-report-page h2,
  .moe-report-page h3,
  .moe-report-page div,
  .moe-report-page p,
  .moe-report-page li,
  .moe-report-page span,
  .signature-block,
  .signature-block div,
  .small,
  small {
    font-size: 16pt !important;
    line-height: 1.34 !important;
  }
  .moe-report-page h2 {
    font-size: 17pt !important;
    line-height: 1.25 !important;
  }
  .moe-report-page h3 {
    font-size: 16pt !important;
    line-height: 1.28 !important;
    margin-top: 8pt !important;
    margin-bottom: 5pt !important;
  }
  .moe-report-page .fw-bold,
  .moe-report-page .fw-semibold,
  .moe-report-page th {
    font-weight: 700 !important;
  }
  .report-table {
    width: 100% !important;
    table-layout: fixed !important;
    border-collapse: collapse !important;
    margin-bottom: 8pt !important;
    font-size: 15.5pt !important;
  }
  .report-table th,
  .report-table td {
    border: 1px solid #000 !important;
    padding: 2.2pt 3pt !important;
    vertical-align: middle !important;
    font-size: 15.5pt !important;
    line-height: 1.16 !important;
    white-space: normal !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
    color: #000 !important;
    background: #fff !important;
  }
  .report-table thead th {
    background: #fff !important;
  }
  .print-compact-table,
  .print-compact-table th,
  .print-compact-table td {
    font-size: 15pt !important;
    line-height: 1.12 !important;
    padding: 2pt 2.5pt !important;
  }
  .signature-block {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8pt !important;
    page-break-inside: avoid;
    margin-top: 10pt !important;
  }
  .signature-block > div {
    width: auto !important;
    max-width: none !important;
    padding: 0 !important;
  }
  .border {
    border-color: #000 !important;
  }
  .mb-0 { margin-bottom: 0 !important; }
  .mb-1 { margin-bottom: 2pt !important; }
  .mb-2 { margin-bottom: 4pt !important; }
  .mb-3 { margin-bottom: 7pt !important; }
  .mb-4 { margin-bottom: 9pt !important; }
  .mt-3 { margin-top: 7pt !important; }
  .mt-4 { margin-top: 9pt !important; }
  .p-2 { padding: 5pt !important; }
  .p-4 { padding: 20mm !important; }
  ol {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding-left: 22pt !important;
  }
  .text-muted { color: #000 !important; }
  a[href]:after { content: none !important; }

  /* หน้าสรุปภาพรวม SDQ: ใช้ขนาดตัวอักษรแบบย่อเมื่อพิมพ์ เพื่อไม่ให้ล้นหลายหน้า */
  body.summary-page {
    font-size: 11pt !important;
    line-height: 1.22 !important;
    background: #fff !important;
  }
  body.summary-page main.container-fluid {
    width: 210mm !important;
    max-width: 210mm !important;
    min-height: 297mm !important;
    margin: 0 !important;
    padding: 20mm !important;
    box-sizing: border-box !important;
  }
  body.summary-page .summary-print-page,
  body.summary-page .summary-print-page div,
  body.summary-page .summary-print-page p,
  body.summary-page .summary-print-page span,
  body.summary-page .summary-print-page th,
  body.summary-page .summary-print-page td {
    font-size: 11pt !important;
    line-height: 1.22 !important;
  }
  body.summary-page .summary-title-row {
    margin-bottom: 5mm !important;
  }
  body.summary-page .summary-print-page h1 {
    font-size: 15pt !important;
    line-height: 1.2 !important;
    margin: 0 0 1mm 0 !important;
  }
  body.summary-page .summary-print-page h2,
  body.summary-page .summary-print-page .card-header {
    font-size: 11.5pt !important;
    line-height: 1.18 !important;
  }
  body.summary-page .summary-print-page .text-muted {
    font-size: 10pt !important;
    color: #000 !important;
  }
  body.summary-page .row.g-3 {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 4mm !important;
    margin: 0 0 5mm 0 !important;
  }
  body.summary-page .row.g-3 > * {
    width: auto !important;
    max-width: none !important;
    padding: 0 !important;
  }
  body.summary-page .card {
    border: 1px solid #999 !important;
    border-radius: 0 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin-bottom: 4mm !important;
  }
  body.summary-page .card-body {
    padding: 4mm !important;
  }
  body.summary-page .card-header {
    padding: 3mm 3.5mm !important;
    background: #fff !important;
    border-bottom: 1px solid #999 !important;
  }
  body.summary-page .display-6 {
    font-size: 18pt !important;
    line-height: 1 !important;
    margin: 1mm 0 !important;
  }
  body.summary-page .badge {
    font-size: 8.5pt !important;
    line-height: 1.05 !important;
    padding: 1.6pt 3.2pt !important;
    border-radius: 2pt !important;
    color: #000 !important;
    border: 1px solid #777 !important;
    background: #fff !important;
  }
  body.summary-page hr {
    margin: 3mm 0 !important;
  }
  body.summary-page .table-responsive {
    overflow: visible !important;
  }
  body.summary-page table.table {
    width: 100% !important;
    table-layout: fixed !important;
    border-collapse: collapse !important;
    font-size: 10pt !important;
  }
  body.summary-page table.table thead {
    display: table-header-group !important;
  }
  body.summary-page table.table th,
  body.summary-page table.table td {
    font-size: 9.5pt !important;
    line-height: 1.12 !important;
    padding: 2.2pt 3pt !important;
    border: 1px solid #999 !important;
    vertical-align: top !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
  }
  body.summary-page table.table th:first-child,
  body.summary-page table.table td:first-child {
    width: 23mm !important;
  }
  body.summary-page table.table th:nth-child(2),
  body.summary-page table.table td:nth-child(2) {
    width: 58mm !important;
  }
  body.summary-page .small,
  body.summary-page small {
    font-size: 8.8pt !important;
    line-height: 1.08 !important;
  }
  body.summary-page .mb-3,
  body.summary-page .mb-4 {
    margin-bottom: 5mm !important;
  }
  body.summary-page .fw-bold,
  body.summary-page .fw-semibold,
  body.summary-page th {
    font-weight: 700 !important;
  }


  /* รายงานรายบุคคล: ลดขนาดเฉพาะหน้านี้เพื่อให้ตารางและกรอบอยู่ทรงบน A4 */
  body.individual-report-page,
  body.individual-report-page main.container-fluid {
    width: 210mm !important;
    max-width: 210mm !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }
  body.individual-report-page .individual-report-sheet {
    width: 210mm !important;
    min-height: 297mm !important;
    max-width: 210mm !important;
    margin: 0 !important;
    padding: 20mm !important;
    box-sizing: border-box !important;
    border: 0 !important;
    font-size: 12pt !important;
    line-height: 1.24 !important;
    overflow: visible !important;
  }
  body.individual-report-page .individual-report-sheet h2 {
    font-size: 14pt !important;
    line-height: 1.15 !important;
    margin-bottom: 2pt !important;
  }
  body.individual-report-page .individual-report-sheet h3 {
    font-size: 12pt !important;
    line-height: 1.15 !important;
    margin-top: 5pt !important;
    margin-bottom: 3pt !important;
  }
  body.individual-report-page .individual-report-sheet div,
  body.individual-report-page .individual-report-sheet p,
  body.individual-report-page .individual-report-sheet span,
  body.individual-report-page .individual-report-sheet li,
  body.individual-report-page .individual-report-sheet .small,
  body.individual-report-page .individual-report-sheet small {
    font-size: 12pt !important;
    line-height: 1.22 !important;
  }
  body.individual-report-page .individual-report-sheet .text-center.mb-3 {
    margin-bottom: 5pt !important;
  }
  body.individual-report-page .report-table {
    width: 100% !important;
    border-collapse: collapse !important;
    table-layout: fixed !important;
    margin-bottom: 5pt !important;
  }
  body.individual-report-page .report-table th,
  body.individual-report-page .report-table td {
    font-size: 10.7pt !important;
    line-height: 1.12 !important;
    padding: 1.9pt 2.6pt !important;
    border: 1px solid #000 !important;
    vertical-align: middle !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
  }
  body.individual-report-page .individual-info-table th,
  body.individual-report-page .individual-info-table td {
    font-size: 11pt !important;
  }
  body.individual-report-page .individual-info-table th:nth-child(1) { width: 24mm !important; }
  body.individual-report-page .individual-info-table th:nth-child(3) { width: 23mm !important; }
  body.individual-report-page .individual-score-table th:first-child,
  body.individual-report-page .individual-score-table td:first-child {
    width: 52mm !important;
    text-align: left !important;
  }
  body.individual-report-page .individual-score-table th:not(:first-child),
  body.individual-report-page .individual-score-table td:not(:first-child) {
    width: 36mm !important;
  }
  body.individual-report-page .individual-detail-table th:nth-child(1),
  body.individual-report-page .individual-detail-table td:nth-child(1) { width: 24mm !important; }
  body.individual-report-page .individual-detail-table th:nth-child(2),
  body.individual-report-page .individual-detail-table td:nth-child(2) { width: 28mm !important; }
  body.individual-report-page .individual-detail-table th:nth-child(3),
  body.individual-report-page .individual-detail-table td:nth-child(3) { width: 26mm !important; }
  body.individual-report-page .individual-detail-table th:nth-child(4),
  body.individual-report-page .individual-detail-table td:nth-child(4) { width: 26mm !important; }
  body.individual-report-page .individual-detail-table th:nth-child(5),
  body.individual-report-page .individual-detail-table td:nth-child(5) { width: auto !important; }
  body.individual-report-page .individual-report-sheet .border.p-3 {
    min-height: 34mm !important;
    padding: 4mm !important;
    margin-bottom: 5pt !important;
    font-size: 12pt !important;
    line-height: 1.28 !important;
  }
  body.individual-report-page .signature-block {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 6mm !important;
    margin-top: 6mm !important;
  }
  body.individual-report-page .signature-block div {
    font-size: 11pt !important;
    line-height: 1.28 !important;
  }
  body.individual-report-page .text-end.small {
    font-size: 10pt !important;
    margin-top: 4mm !important;
  }


  /* รายงานสรุปตามแบบฟอร์ม: จัดตารางให้เต็มความกว้างและสมดุลบนกระดาษ A4 */
  body.moe-summary-print-page,
  body.moe-summary-print-page main.container-fluid {
    width: 210mm !important;
    max-width: 210mm !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }
  body.moe-summary-print-page .moe-summary-sheet {
    width: 210mm !important;
    max-width: 210mm !important;
    min-height: 297mm !important;
    margin: 0 auto !important;
    padding: 20mm !important;
    box-sizing: border-box !important;
    border: 0 !important;
    font-size: 13.4pt !important;
    line-height: 1.22 !important;
    page-break-after: always !important;
    overflow: visible !important;
  }
  body.moe-summary-print-page .moe-summary-sheet:last-of-type {
    page-break-after: auto !important;
  }
  body.moe-summary-print-page .moe-summary-sheet .text-center.mb-3 {
    margin-bottom: 5pt !important;
  }
  body.moe-summary-print-page .moe-summary-sheet h2 {
    font-size: 15pt !important;
    line-height: 1.16 !important;
    margin: 0 0 1pt 0 !important;
  }
  body.moe-summary-print-page .moe-summary-sheet h3 {
    font-size: 13.4pt !important;
    line-height: 1.18 !important;
    margin: 6pt 0 3pt 0 !important;
  }
  body.moe-summary-print-page .moe-summary-sheet div,
  body.moe-summary-print-page .moe-summary-sheet p,
  body.moe-summary-print-page .moe-summary-sheet span,
  body.moe-summary-print-page .moe-summary-sheet li,
  body.moe-summary-print-page .moe-summary-sheet small,
  body.moe-summary-print-page .moe-summary-sheet .small {
    font-size: 13.4pt !important;
    line-height: 1.22 !important;
  }
  body.moe-summary-print-page .moe-summary-sheet .report-table {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 100% !important;
    display: table !important;
    table-layout: fixed !important;
    border-collapse: collapse !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    margin-bottom: 6pt !important;
  }
  body.moe-summary-print-page .moe-summary-sheet .report-table th,
  body.moe-summary-print-page .moe-summary-sheet .report-table td {
    border: 1px solid #000 !important;
    padding: 2.6pt 3.4pt !important;
    font-size: 12.8pt !important;
    line-height: 1.14 !important;
    vertical-align: middle !important;
    white-space: normal !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
    background: #fff !important;
    color: #000 !important;
  }
  body.moe-summary-print-page .moe-summary-sheet .moe-info-table th,
  body.moe-summary-print-page .moe-summary-sheet .moe-info-table td {
    font-size: 12.6pt !important;
    padding: 2.4pt 3.2pt !important;
  }
  body.moe-summary-print-page .moe-summary-sheet .moe-info-table th:nth-child(1) { width: 31mm !important; }
  body.moe-summary-print-page .moe-summary-sheet .moe-info-table td:nth-child(2) { width: 28mm !important; }
  body.moe-summary-print-page .moe-summary-sheet .moe-info-table th:nth-child(3) { width: 31mm !important; }
  body.moe-summary-print-page .moe-summary-sheet .moe-info-table td:nth-child(4) { width: auto !important; }
  body.moe-summary-print-page .moe-summary-sheet .moe-screening-table th:first-child,
  body.moe-summary-print-page .moe-summary-sheet .moe-screening-table td:first-child,
  body.moe-summary-print-page .moe-summary-sheet .moe-strength-table th:first-child,
  body.moe-summary-print-page .moe-summary-sheet .moe-strength-table td:first-child {
    width: 38mm !important;
  }
  body.moe-summary-print-page .moe-summary-sheet .moe-screening-table th:not(:first-child),
  body.moe-summary-print-page .moe-summary-sheet .moe-screening-table td:not(:first-child) {
    width: 33mm !important;
  }
  body.moe-summary-print-page .moe-summary-sheet .moe-strength-table th:not(:first-child),
  body.moe-summary-print-page .moe-summary-sheet .moe-strength-table td:not(:first-child) {
    width: 66mm !important;
  }
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table th,
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table td {
    font-size: 11.6pt !important;
    line-height: 1.10 !important;
    padding: 2.1pt 2.5pt !important;
  }
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table th:nth-child(1),
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table td:nth-child(1) { width: 11mm !important; }
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table th:nth-child(2),
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table td:nth-child(2) { width: 25mm !important; }
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table th:nth-child(3),
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table td:nth-child(3) { width: 58mm !important; }
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table th:nth-child(4),
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table td:nth-child(4) { width: 17mm !important; }
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table th:nth-child(5),
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table td:nth-child(5) { width: 22mm !important; }
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table th:nth-child(6),
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table td:nth-child(6) { width: 22mm !important; }
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table th:nth-child(7),
  body.moe-summary-print-page .moe-summary-sheet .moe-risk-table td:nth-child(7) { width: 15mm !important; }
  body.moe-summary-print-page .moe-summary-sheet .border.p-2 {
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 5pt 7pt !important;
    margin-bottom: 6pt !important;
  }
  body.moe-summary-print-page .moe-summary-sheet ol {
    padding-left: 18pt !important;
  }
  body.moe-summary-print-page .moe-summary-sheet .signature-block {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    column-gap: 7mm !important;
    margin-top: 7mm !important;
  }
  body.moe-summary-print-page .moe-summary-sheet .signature-block > div,
  body.moe-summary-print-page .moe-summary-sheet .signature-block > div div {
    font-size: 11.6pt !important;
    line-height: 1.24 !important;
    text-align: center !important;
  }
  body.moe-summary-print-page .moe-summary-sheet .text-end.small {
    font-size: 10.5pt !important;
    margin-top: 4mm !important;
  }

}
