:root {
  --brand: #2157d4;
  --brand-2: #00a7b5;
  --brand-3: #7c3aed;
  --ink: #162033;
  --muted: #657286;
  --line: #dbe5f0;
  --bg: #f3f7fb;
  --panel: #ffffff;
  --sidebar: #101b2f;
  --shadow: 0 18px 45px rgba(22, 32, 51, .09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(33, 87, 212, .12), transparent 34rem),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 42%, #eef4f9 100%);
  color: var(--ink);
  font-family: "Sarabun", "Segoe UI", Tahoma, sans-serif;
}

a { text-decoration: none; }

.eyebrow {
  color: var(--brand);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(120deg, rgba(16, 27, 47, .82), rgba(33, 87, 212, .64)),
    url("https://images.unsplash.com/photo-1523050854058-8df90110c9f1?auto=format&fit=crop&w=1600&q=80") center/cover;
}

.login-card {
  width: min(460px, 100%);
  background: rgba(255,255,255,.96);
  border: 1px solid rgba(255,255,255,.58);
  border-radius: 8px;
  padding: 30px;
  box-shadow: 0 26px 80px rgba(7, 18, 38, .28);
  backdrop-filter: blur(14px);
}

.login-mark,
.brand-mark,
.metric-icon,
.user-chip > span {
  display: inline-grid;
  place-items: center;
}

.login-mark {
  width: 54px;
  height: 54px;
  margin-bottom: 18px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 16px 34px rgba(33, 87, 212, .28);
  font-size: 1.35rem;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 290px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  color: #dbeafe;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(33, 87, 212, .22), transparent 23rem),
    var(--sidebar);
  border-right: 1px solid rgba(255,255,255,.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  color: #fff;
  font-weight: 800;
  line-height: 1.25;
  margin: 4px 2px 20px;
}

.brand-mark {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand-2), var(--brand-3));
  box-shadow: 0 12px 26px rgba(0, 0, 0, .24);
}

.sidebar-nav {
  display: grid;
  gap: 4px;
}

.sidebar .nav-group {
  display: block;
  gap: 4px;
}

.sidebar .nav-group summary {
  list-style: none;
  cursor: pointer;
}

.sidebar .nav-group summary::-webkit-details-marker {
  display: none;
}

.sidebar .nav-submenu {
  display: flex !important;
  flex-direction: column;
  gap: 3px;
  margin: 4px 0 8px 0;
  padding: 4px 0 4px 18px;
  border-left: 1px solid rgba(139, 215, 255, .22);
}

.sidebar .nav-sublink {
  display: flex !important;
  align-items: center;
  width: 100%;
  gap: 9px;
  min-height: 34px;
  color: #c9dcff;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: .9rem;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
}

.sidebar .nav-sublink i {
  flex: 0 0 18px;
  width: 18px;
  color: #8bd7ff;
}

.sidebar .nav-sublink span {
  min-width: 0;
}

.sidebar .nav-sublink:hover,
.sidebar .nav-sublink.active {
  color: #fff;
  background: rgba(255,255,255,.10);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  color: #d9e7ff;
  border-radius: 8px;
  padding: 11px 12px;
  font-weight: 700;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}

.nav-link i {
  width: 22px;
  color: #8bd7ff;
  font-size: 1rem;
}

.nav-link:hover,
.nav-link.active {
  color: #fff;
  background: rgba(255,255,255,.13);
  transform: translateX(2px);
}

.nav-link.active {
  box-shadow: inset 3px 0 0 var(--brand-2);
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  background: rgba(255,255,255,.86);
  border-bottom: 1px solid rgba(219, 229, 240, .86);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  backdrop-filter: blur(14px);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 11px;
}

.user-chip > span {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  font-weight: 800;
}

.content {
  padding: 24px;
}

.page-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
  padding: 24px;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(33, 87, 212, .96), rgba(0, 167, 181, .88)),
    linear-gradient(45deg, rgba(124, 58, 237, .35), transparent);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.page-hero h1 {
  margin: 4px 0;
  font-size: clamp(1.55rem, 2.6vw, 2.35rem);
  font-weight: 800;
}

.page-hero p {
  max-width: 650px;
  margin: 0;
  color: rgba(255,255,255,.86);
}

.page-hero .eyebrow {
  color: rgba(255,255,255,.82);
}

.page-hero > i {
  font-size: clamp(2.4rem, 6vw, 4.7rem);
  opacity: .28;
}

.metric,
.panel {
  border: 1px solid rgba(219, 229, 240, .92);
  border-radius: 8px;
  background: rgba(255,255,255,.94);
  box-shadow: var(--shadow);
}

.metric {
  position: relative;
  overflow: hidden;
  padding: 18px;
  min-height: 132px;
  height: 100%;
}

.metric::after {
  content: "";
  position: absolute;
  right: -24px;
  bottom: -34px;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(0, 167, 181, .10);
}

.metric-icon {
  width: 34px;
  height: 34px;
  margin-bottom: 12px;
  border-radius: 8px;
  color: var(--brand);
  background: #e8f0ff;
}

.metric .value {
  position: relative;
  z-index: 1;
  font-size: clamp(1.55rem, 3vw, 2.2rem);
  font-weight: 800;
  color: var(--ink);
}

.panel {
  padding: 18px;
}

.subject-form-toggle {
  padding: 0;
}

.subject-form-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  color: var(--ink);
  font-weight: 700;
  list-style: none;
}

.subject-form-summary::-webkit-details-marker {
  display: none;
}

.subject-form-summary span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.subject-form-toggle form {
  padding: 0 18px 18px;
}

.subject-form-chevron {
  transition: transform .18s ease;
}

.subject-form-toggle[open] .subject-form-chevron {
  transform: rotate(180deg);
}

.enroll-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0;
}

.enroll-summary span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid #dbe7f3;
  border-radius: 8px;
  background: #f7fbff;
  color: #334155;
  font-weight: 700;
  font-size: .92rem;
}

.enroll-list {
  overflow: hidden;
  border: 1px solid #dbe7f3;
  border-radius: 8px;
  background: #fff;
}

.enroll-row {
  display: grid;
  grid-template-columns: 44px minmax(128px, 150px) minmax(230px, 1fr) minmax(90px, 120px) minmax(112px, 140px);
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 10px 14px;
  border-bottom: 1px solid #e5edf5;
}

label.enroll-row {
  cursor: pointer;
  transition: background-color .14s ease;
}

label.enroll-row:hover {
  background: #f8fbff;
}

.enroll-row:last-child {
  border-bottom: 0;
}

.enroll-head {
  color: #526075;
  background: #f7faff;
  font-size: .84rem;
  font-weight: 800;
}

.enroll-check {
  display: flex;
  justify-content: center;
}

.enroll-check input {
  width: 18px;
  height: 18px;
}

.enroll-code {
  color: #0f3d70;
  font-weight: 800;
  white-space: nowrap;
}

.enroll-name {
  color: var(--ink);
  font-weight: 700;
  line-height: 1.35;
}

.enroll-class {
  color: #334155;
  font-weight: 700;
  white-space: nowrap;
}

.enroll-status .badge {
  font-size: .78rem;
}

.table {
  margin-bottom: 0;
}

.table thead th {
  color: #526075;
  white-space: nowrap;
  font-size: .88rem;
  background: #f7faff;
  border-bottom: 1px solid var(--line);
}

.table tbody td {
  border-color: #edf2f7;
}

.table-hover tbody tr:hover {
  --bs-table-hover-bg: #f8fbff;
}

.form-control,
.form-select {
  min-height: 42px;
  border-color: #d8e3ef;
  border-radius: 8px;
}

.form-control:focus,
.form-select:focus {
  border-color: rgba(33, 87, 212, .56);
  box-shadow: 0 0 0 .22rem rgba(33, 87, 212, .12);
}

.btn {
  border-radius: 8px;
  font-weight: 800;
}

.btn-primary {
  border-color: var(--brand);
  background: linear-gradient(135deg, var(--brand), #1976d2);
  box-shadow: 0 10px 22px rgba(33, 87, 212, .18);
}

.alert {
  border-radius: 8px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 11px;
  font-weight: 800;
  font-size: .84rem;
}

.st-present { background: #dcfce7; color: #166534; }
.st-absent { background: #fee2e2; color: #991b1b; }
.st-sick, .st-leave { background: #e0f2fe; color: #075985; }
.st-late { background: #fef3c7; color: #92400e; }
.st-activity { background: #ede9fe; color: #5b21b6; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 14px;
}

.row-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  min-width: 220px;
}

.pp5-row-actions {
  min-width: 520px;
}

.row-actions form {
  margin: 0;
}

.pp5-modal[hidden] {
  display: none;
}

.pp5-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
}

.pp5-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 27, 47, .48);
}

.pp5-modal-dialog {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 28px 90px rgba(16, 27, 47, .28);
  padding: 18px;
}

.pp5-cover {
  width: min(210mm, 100%);
  min-height: 297mm;
  margin: 0 auto;
  padding: 16mm 7mm 12mm;
  color: #000;
  background: #fff;
  border: 1px solid #d9dee8;
  box-shadow: var(--shadow);
  font-size: 12px;
  line-height: 1.45;
}

.pp5-cover-top {
  display: grid;
  grid-template-columns: 92px 1fr 112px;
  align-items: start;
  gap: 10px;
  margin: 0 0 25px;
}

.pp5-logo-wrap {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 5px;
}

.pp5-logo {
  display: grid;
  place-items: center;
  width: 66px;
  height: 66px;
  border: 3px solid #f3d23b;
  border-radius: 50%;
  outline: 2px solid #0b4aa0;
  background:
    radial-gradient(circle at center, #ffd84c 0 26%, #1c76cf 27% 55%, #ffe45f 56% 100%);
  color: #072c72;
  font-size: 13px;
  font-weight: 900;
  text-align: center;
}

.pp5-logo-img {
  width: 66px;
  height: 66px;
  object-fit: contain;
}

.pp5-title-block {
  text-align: center;
  padding-top: 2px;
}

.pp5-school {
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}

.pp5-code {
  text-align: right;
  font-weight: 700;
  padding-top: 4px;
  font-size: 12px;
}

.pp5-cover h2 {
  margin: 1px 0 5px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}

.pp5-center {
  text-align: center;
  font-weight: 700;
  line-height: 1.8;
}

.pp5-line-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 8px 14px;
  margin-bottom: 20px;
}

.pp5-line-grid > div {
  min-height: 24px;
}

.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }

.pp5-course-info {
  display: grid;
  gap: 7px;
  margin: 0 0 20px;
  font-size: 12px;
  line-height: 1.35;
}

.pp5-info-row {
  display: grid;
  align-items: baseline;
  column-gap: 22px;
}

.pp5-info-row strong {
  font-weight: 800;
  margin-right: 4px;
}

.pp5-info-row-main {
  grid-template-columns: 116px 1fr 122px;
}

.pp5-info-row-time {
  grid-template-columns: max-content max-content 1fr;
}

.pp5-info-row-time > div {
  white-space: nowrap;
}

.pp5-info-row-dept {
  grid-template-columns: max-content max-content;
}

.pp5-info-row-dept > div {
  white-space: nowrap;
}

.pp5-info-row-teacher {
  grid-template-columns: 1fr;
}

.pp5-info-row-main > div:last-child {
  text-align: right;
  white-space: nowrap;
}

.pp5-summary-grid {
  display: grid;
  grid-template-columns: 1fr .92fr;
  gap: 32px;
  align-items: start;
  margin-top: 8px;
}

.pp5-summary-grid h3 {
  margin: 0 0 6px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.pp5-cover-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #000;
}

.pp5-cover-table th,
.pp5-cover-table td {
  height: 22px;
  padding: 2px 6px;
  border: 1px solid #000;
  color: #000;
  font-weight: 400;
  vertical-align: top;
}

.pp5-cover-table th {
  font-weight: 700;
  text-align: center;
  background: #f4f6f8;
}

.pp5-cover-table tbody td {
  text-align: center;
}

.pp5-cover-table tbody td:first-child {
  text-align: center;
}

.pp5-cover-table td:last-child,
.pp5-cover-table th:last-child {
  text-align: center;
}

.pp5-sign-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 46px;
  margin-top: 22px;
}

.pp5-sign-grid p,
.pp5-director p {
  margin: 2px 0;
  text-align: center;
}

.pp5-sign-grid > div p:first-child {
  min-height: 36px;
}

.pp5-director {
  width: 50%;
  margin: 18px auto 0;
}

.pp5-page-label {
  margin-top: 2px;
  text-align: center;
  font-weight: 700;
}

.pp5-page2 {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 32mm 13mm 13mm;
  font-size: 12px;
  line-height: 1.45;
}

.pp5-page2-block {
  margin-bottom: 21mm;
}

.pp5-page2-block h2 {
  margin: 0 0 7mm;
  font-size: 13px;
  font-weight: 800;
  text-align: left;
}

.pp5-page2-text {
  min-height: 0;
  padding-left: 4mm;
  white-space: normal;
}

.pp5-page2-description {
  min-height: 39mm;
  padding-left: 15mm;
  padding-right: 12mm;
  text-indent: 12mm;
}

.pp5-page2-sign {
  width: 90mm;
  margin-top: auto;
  margin-left: auto;
  margin-right: 12mm;
  text-align: center;
}

.pp5-page2-sign p {
  margin: 0 0 6mm;
}

.pp5-page3 {
  width: min(297mm, 100%);
  min-height: 210mm;
  margin: 0 auto;
  padding: 18mm 7mm 8mm;
  color: #000;
  background: #fff;
  border: 1px solid #d9dee8;
  box-shadow: var(--shadow);
  font-size: 11px;
  line-height: 1.25;
}

.pp5-page3 h2 {
  margin: 0 0 2mm;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
}

/* ── Legend row (visible on screen only) ── */
.pp5-page3-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 0 0 4mm;
  font-size: 11px;
  color: #333;
}

.pp5-legend-arrow {
  color: #e67e22;
  font-weight: 700;
  font-size: 12px;
}

.pp5-legend-item {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 3px;
  font-weight: 700;
  font-size: 11px;
  border: 1px solid #ccc;
}

.pp5-legend-empty  { background: #fff; color: #555; }
.pp5-legend-present{ background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.pp5-legend-late   { background: #fef9c3; color: #854d0e; border-color: #fef08a; }
.pp5-legend-absent { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* ── Attendance table ── */
.pp5-attendance-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

.pp5-attendance-table th,
.pp5-attendance-table td {
  height: 7.2mm;
  padding: 1mm 1.2mm;
  border: 1px solid #b0b8c8;
  color: #000;
  font-weight: 400;
  text-align: center;
  vertical-align: middle;
}

.pp5-attendance-table thead th {
  font-weight: 700;
  background: #f5f7fa;
}

.pp5-attendance-table tbody td {
  height: 8.2mm;
  background: #fff;
}

.pp5-attendance-table .pp5-no,
.pp5-attendance-table col.pp5-no {
  width: 8mm;
}

.pp5-attendance-table .pp5-code-col,
.pp5-attendance-table col.pp5-code-col {
  width: 23mm;
}

.pp5-attendance-table .pp5-name-col,
.pp5-attendance-table col.pp5-name-col {
  width: 42mm;
}

.pp5-attendance-table .pp5-month-label,
.pp5-attendance-table col.pp5-month-label {
  width: 13mm;
}

.pp5-attendance-table .pp5-session-no,
.pp5-attendance-table .pp5-date-col,
.pp5-attendance-table .pp5-month,
.pp5-attendance-table col.pp5-session-no {
  width: 7mm;
}

.pp5-attendance-table .pp5-total-col,
.pp5-attendance-table .pp5-percent-col,
.pp5-attendance-table col.pp5-total-col,
.pp5-attendance-table col.pp5-percent-col {
  width: 13mm;
}

.pp5-attendance-table .pp5-note-col,
.pp5-attendance-table col.pp5-note-col {
  width: 28mm;
}

.pp5-note-cell {
  min-width: 28mm;
}

.pp5-student-name {
  text-align: left !important;
  white-space: nowrap;
  padding-left: 2mm !important;
}

.pp5-mark {
  font-size: 13px;
  font-weight: 700;
}

.absent-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 1.5px solid #dc2626;
  border-radius: 50%;
  color: #dc2626;
  font-size: 11px;
  font-weight: bold;
  line-height: 1;
}

.pp5-score-input {
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  text-align: center;
  font-size: 11px;
  font-weight: 500;
  background: transparent;
  outline: none;
  -moz-appearance: textfield;
}

.pp5-score-input::-webkit-outer-spin-button,
.pp5-score-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.pp5-score-input:focus {
  background: #f0f7ff;
}

/* ── Orange highlight for columns 11-12 ── */
.pp5-session-highlight {
  background: #fff3cd !important;
  color: #e67e22 !important;
  font-weight: 800 !important;
}

.pp5-date-highlight {
  background: #fff3cd !important;
  color: #e67e22 !important;
}

.pp5-cell-highlight {
  background: #fffbf0 !important;
}

.pp5-empty-row td {
  height: 8.2mm;
  background: #fff;
}

.pp5-empty {
  padding: 16mm !important;
  color: #6b7280 !important;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid-full {
  grid-column: 1 / -1;
}

.pp5-textarea {
  min-height: 118px;
  line-height: 1.55;
}

.attendance-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 220px minmax(160px, 1fr);
  gap: 10px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .sidebar-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    position: static;
  }

  .content {
    padding: 18px;
  }

  .form-grid,
  .form-grid.two,
  .attendance-row {
    grid-template-columns: 1fr;
  }

  .enroll-row {
    grid-template-columns: 34px minmax(100px, 128px) 1fr;
    gap: 8px 10px;
  }

  .enroll-head {
    display: none;
  }

  .enroll-class,
  .enroll-status {
    grid-column: 3;
  }
}

@media (max-width: 560px) {
  .login-card {
    padding: 24px;
  }

  .sidebar-nav {
    grid-template-columns: 1fr;
  }

  .topbar,
  .page-hero {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar .w-auto {
    width: 100% !important;
  }

  .enroll-row {
    grid-template-columns: 30px 1fr;
    padding: 12px;
  }

  .enroll-code,
  .enroll-name,
  .enroll-class,
  .enroll-status {
    grid-column: 2;
  }

  .enroll-code {
    white-space: normal;
  }
}

/* ── Page 4 (Moral / Attributes Score) ── */
.pp5-page4 {
  width: min(297mm, 100%);
  min-height: 210mm;
  margin: 0 auto;
  padding: 15mm 7mm 8mm;
  color: #000;
  background: #fff;
  border: 1px solid #d9dee8;
  box-shadow: var(--shadow);
  font-size: 10px;
  line-height: 1.25;
}

.pp5-page4-layout {
  display: grid;
  grid-template-columns: 1fr 50mm;
  gap: 6mm;
  align-items: start;
}

.pp5-page4 h2 {
  margin: 0 0 4mm;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
}

.pp5-attributes-table {
  width: 100%;
  border-collapse: collapse;
}

.pp5-attributes-table th,
.pp5-attributes-table td {
  border: 1px solid #b0b8c8;
  padding: 1.2px;
  text-align: center;
  font-size: 9px;
  vertical-align: middle;
  height: 6.8mm;
  position: relative;
}

.pp5-attributes-table td.pp5-khr-redline::after,
.pp5-scores-table td.pp5-khr-redline::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  border-top: 1.8px solid #d70000;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 3;
}

.pp5-attributes-table td.pp5-khr-redline,
.pp5-scores-table td.pp5-khr-redline {
  background-image: linear-gradient(to bottom, transparent calc(50% - 1px), #d70000 calc(50% - 1px), #d70000 calc(50% + 1px), transparent calc(50% + 1px));
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

.pp5-attributes-table td.pp5-khr-redline-start::after,
.pp5-scores-table td.pp5-khr-redline-start::after {
  left: 0;
}

.pp5-attributes-table td.pp5-khr-redline-end::after,
.pp5-scores-table td.pp5-khr-redline-end::after {
  right: 0;
}

.pp5-attributes-table td.pp5-khr-redline .pp5-khr-line,
.pp5-scores-table td.pp5-khr-redline .pp5-khr-line {
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  height: 0;
  border-top: 2px solid #d70000;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 4;
}

.pp5-attributes-table td.pp5-khr-redline-start .pp5-khr-line,
.pp5-scores-table td.pp5-khr-redline-start .pp5-khr-line {
  left: 0;
}

.pp5-attributes-table td.pp5-khr-redline-end .pp5-khr-line,
.pp5-scores-table td.pp5-khr-redline-end .pp5-khr-line {
  right: 0;
}

.pp5-attributes-table thead th {
  font-weight: 700;
  background: #f5f7fa;
}

.pp5-attributes-table th.pp5-vertical-header {
  height: 22mm;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  white-space: nowrap;
  font-weight: normal;
  font-size: 8.5px;
  padding: 1mm 0.5mm;
}

.pp5-max-score-row td {
  font-weight: bold;
  background: #fdfdfd;
}

.pp5-dates-row td {
  font-weight: bold;
  background: #fafafa;
}

.pp5-page4-sidebar {
  font-size: 10px;
  display: flex;
  flex-direction: column;
  gap: 6mm;
  border-left: 1px solid #d9dee8;
  padding-left: 6mm;
  height: 100%;
}

.pp5-sidebar-info {
  display: flex;
  flex-direction: column;
  gap: 2mm;
}

.pp5-sidebar-item strong {
  display: inline-block;
  width: 18mm;
}

.pp5-sidebar-legend {
  border: 1px solid #b0b8c8;
  padding: 3mm;
  background: #fcfdfd;
}

.pp5-sidebar-signatures {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6mm;
  padding-top: 6mm;
}

.pp5-signature-line {
  text-align: center;
  font-size: 9px;
  line-height: 1.6;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  html,
  body {
    width: 210mm;
    min-height: 297mm;
  }

  .sidebar,
  .topbar,
  .no-print,
  .pp5-page-label,
  .btn {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .app {
    display: block;
  }

  .content {
    padding: 0;
  }

  .panel,
  .metric {
    border: 0;
    box-shadow: none;
  }

  .pp5-cover {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    padding: 15mm 7mm 10mm;
    border: 0;
    box-shadow: none;
    font-size: 12px;
    page-break-after: always;
  }

  .pp5-cover-top {
    grid-template-columns: 92px 1fr 112px;
    margin-bottom: 24px;
  }

  .pp5-logo {
    width: 66px;
    height: 66px;
    font-size: 13px;
  }

  .pp5-course-info {
    font-size: 12px;
    gap: 7px;
    margin-bottom: 20px;
  }

  .pp5-summary-grid {
    gap: 32px;
  }

  .pp5-cover-table th,
  .pp5-cover-table td {
    height: 22px;
    padding: 2px 6px;
  }

  .pp5-sign-grid {
    gap: 18px 46px;
    margin-top: 22px;
  }

  .pp5-director {
    margin-top: 18px;
  }

  .pp5-page2 {
    padding: 32mm 13mm 13mm;
    font-size: 12px;
    line-height: 1.45;
  }

  .pp5-page3 {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    padding: 10mm 5mm 8mm;
    border: 0;
    box-shadow: none;
    font-size: 8.5px;
    page-break-after: always;
  }

  /* A4 portrait — ลด column ทุกอันให้พอดี 200mm */
  .pp5-page3 .pp5-attendance-table .pp5-no,
  .pp5-page3 .pp5-attendance-table col.pp5-no        { width: 5mm; }
  .pp5-page3 .pp5-attendance-table .pp5-code-col,
  .pp5-page3 .pp5-attendance-table col.pp5-code-col  { width: 17mm; }
  .pp5-page3 .pp5-attendance-table .pp5-name-col,
  .pp5-page3 .pp5-attendance-table col.pp5-name-col  { width: 30mm; }
  .pp5-page3 .pp5-attendance-table .pp5-month-label,
  .pp5-page3 .pp5-attendance-table col.pp5-month-label{ width: 8mm; }
  .pp5-page3 .pp5-attendance-table .pp5-session-no,
  .pp5-page3 .pp5-attendance-table .pp5-date-col,
  .pp5-page3 .pp5-attendance-table .pp5-month,
  .pp5-page3 .pp5-attendance-table col.pp5-session-no { width: 5mm; }
  .pp5-page3 .pp5-attendance-table .pp5-total-col,
  .pp5-page3 .pp5-attendance-table .pp5-percent-col,
  .pp5-page3 .pp5-attendance-table col.pp5-total-col,
  .pp5-page3 .pp5-attendance-table col.pp5-percent-col{ width: 9mm; }
  .pp5-page3 .pp5-attendance-table .pp5-note-col,
  .pp5-page3 .pp5-attendance-table col.pp5-note-col  { width: 21mm; }

  .pp5-page3 .pp5-attendance-table th,
  .pp5-page3 .pp5-attendance-table td {
    height: 6mm;
    padding: 0.5mm 0.5mm;
  }

  .pp5-page3 h2 {
    font-size: 12px;
    margin: 0 0 3mm;
  }

  .pp5-page3 .pp5-mark {
    font-size: 10px;
  }

  .pp5-page3 .absent-circle {
    width: 4.2mm;
    height: 4.2mm;
    border: 0.8px solid #dc2626 !important;
    color: #dc2626 !important;
    font-size: 8px;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .pp5-attendance-table th,
  .pp5-attendance-table td {
    border: 1px solid #888 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .pp5-session-highlight,
  .pp5-date-highlight {
    background: #fff3cd !important;
    color: #e67e22 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .pp5-cell-highlight {
    background: #fffbf0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* ── Page 4 Print Styles ── */
  .pp5-page4 {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    padding: 10mm 5mm 8mm;
    border: 0;
    box-shadow: none;
    font-size: 8px;
    page-break-after: always;
    box-sizing: border-box !important;
  }

  .pp5-page4-layout {
    display: grid !important;
    grid-template-columns: 1fr 48mm !important;
    gap: 4mm !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .pp5-page4-sidebar {
    border-left: 1px solid #000 !important;
    padding-left: 3mm;
    display: flex;
    flex-direction: column;
    min-height: 220mm;
  }

  .pp5-sidebar-legend {
    border: 1px solid #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .pp5-attributes-table {
    width: 100% !important;
    border-collapse: collapse !important;
    border: 1.5px solid #000 !important;
  }

  .pp5-attributes-table th,
  .pp5-attributes-table td {
    height: 5.5mm;
    border: 1px solid #000 !important;
    font-size: 7.5px;
    padding: 0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .pp5-attributes-table th {
    padding: 0.5mm !important;
  }

  .pp5-attributes-table th.pp5-vertical-header {
    height: 18mm;
    font-size: 6.5px;
    padding: 1mm 0.5mm !important;
  }

  /* ── Page 5 Print Styles ── */
  .pp5-attributes-table td.pp5-khr-redline::after,
  .pp5-scores-table td.pp5-khr-redline::after {
    border-top: 1.8px solid #d70000;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .pp5-attributes-table td.pp5-khr-redline .pp5-khr-line,
  .pp5-scores-table td.pp5-khr-redline .pp5-khr-line {
    border-top: 1.8px solid #d70000;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .pp5-attributes-table td.pp5-khr-redline,
  .pp5-scores-table td.pp5-khr-redline {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .pp5-page5 {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    padding: 10mm 5mm 8mm;
    border: 0;
    box-shadow: none;
    font-size: 8px;
    page-break-after: always;
    box-sizing: border-box !important;
  }
  .pp5-scores-table {
    width: 100% !important;
    border-collapse: collapse !important;
    border: 1.5px solid #000 !important;
  }
  .pp5-scores-table th,
  .pp5-scores-table td {
    border: 1px solid #000 !important;
    font-size: 7.5px;
    padding: 0 !important;
    height: 6mm;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .pp5-page5 .pp5-scores-table col:nth-child(1) { width: 5mm !important; }
  .pp5-page5 .pp5-scores-table col:nth-child(2) { width: 17mm !important; }
  .pp5-page5 .pp5-scores-table col:nth-child(3) { width: 30mm !important; }
  .pp5-page5 .pp5-scores-table col:nth-child(4) { width: 8mm !important; }
  .pp5-page5 .pp5-scores-table col:nth-child(n+5):nth-child(-n+22) { width: 5mm !important; }
  .pp5-page5 .pp5-scores-table col:nth-child(23) { width: 9mm !important; }
  .pp5-page5 .pp5-scores-table col:nth-child(24) { width: 9mm !important; }
  .pp5-page5 .pp5-scores-table col:nth-child(25) { width: 21mm !important; }
  
  .pp5-scores-table th.pp5-vertical-header {
    height: 18mm;
    font-size: 6.5px;
    padding: 1mm 0.5mm !important;
  }
  .pp5-topic-cell.pp5-vertical-text {
    height: 22mm !important;
    font-size: 6.5px;
  }

  /* ── Page 6 Print Styles ── */
  .pp5-page6 {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    padding: 5mm;
    border: 1.5px solid #000 !important;
    box-shadow: none;
    font-size: 8px;
    page-break-after: always;
    box-sizing: border-box !important;
  }
  .pp5-page6-layout {
    display: grid !important;
    grid-template-columns: 1fr 60mm !important;
    gap: 0 !important;
    width: 100% !important;
    min-height: 287mm;
    box-sizing: border-box !important;
  }
  .pp5-page6-main-section {
    padding-right: 3mm !important;
    box-sizing: border-box !important;
  }
  .pp5-page6-table,
  .pp5-page6-summary-table {
    width: 100% !important;
    border-collapse: collapse !important;
    border: 1.5px solid #000 !important;
  }
  .pp5-page6-table th,
  .pp5-page6-table td,
  .pp5-page6-summary-table th,
  .pp5-page6-summary-table td {
    border: 1px solid #000 !important;
    font-size: 7.5px;
    padding: 0.5mm !important;
    height: 5.5mm;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    text-align: center;
    vertical-align: middle;
  }
  .pp5-page6-table th.pp5-vertical-header {
    height: 16mm;
    font-size: 6.5px;
    padding: 1mm 0.5mm !important;
  }
  .pp5-page6-sidebar {
    border-left: 1px solid #000 !important;
    padding-left: 3mm;
    box-sizing: border-box !important;
    min-height: 287mm;
  }
  .pp5-page6-course-info {
    font-size: 8.5px;
    line-height: 1.4;
    border: 1px solid #000;
    padding: 2mm;
    margin-bottom: 3mm;
  }
}

/* ── Page 5 Screen Styles (non-print) ── */
.pp5-page5 {
  width: min(297mm, 100%);
  min-height: 210mm;
  margin: 0 auto;
  padding: 15mm 7mm 8mm;
  color: #000;
  background: #fff;
  border: 1px solid #d9dee8;
  box-shadow: var(--shadow);
  font-size: 10px;
  line-height: 1.25;
}
.pp5-page5 h2 {
  margin: 0 0 4mm;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
}
.pp5-scores-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.pp5-scores-table th,
.pp5-scores-table td {
  border: 1px solid #b0b8c8;
  padding: 1.2px;
  text-align: center;
  font-size: 9px;
  vertical-align: middle;
  height: 6.8mm;
  position: relative;
}
.pp5-scores-table thead th {
  font-weight: 700;
  background: #f5f7fa;
}
.pp5-scores-table th.pp5-vertical-header {
  height: 22mm;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  white-space: nowrap;
  font-weight: normal;
  font-size: 8.5px;
  padding: 1mm 0.5mm;
}

.pp5-khr-grade {
  color: #d70000 !important;
  font-weight: 800;
}

.pp5-page6-table .pp5-khr-grade,
.pp5-page6-summary-table .pp5-khr-grade {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.pp5-topic-label {
  font-weight: bold;
  background: #fafafa;
  text-align: left !important;
  padding-left: 4mm !important;
}
.pp5-topic-cell {
  height: 28mm !important;
  background: #fff;
}
.pp5-vertical-text {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  white-space: nowrap;
  padding: 2mm 0.5mm !important;
  font-size: 8.5px;
}

/* ── Page 6 Screen Styles (non-print) ── */
.pp5-page6 {
  width: min(297mm, 100%);
  min-height: 210mm;
  margin: 0 auto;
  padding: 7mm;
  color: #000;
  background: #fff;
  border: 1.5px solid #000;
  box-shadow: var(--shadow);
  font-size: 10px;
  line-height: 1.25;
  box-sizing: border-box;
}
.pp5-page6-layout {
  display: grid;
  grid-template-columns: 1fr 65mm;
  gap: 0;
  align-items: start;
  min-height: 196mm;
}
.pp5-page6-main-section {
  padding-right: 4mm;
  box-sizing: border-box;
}
.pp5-page6-table,
.pp5-page6-summary-table {
  width: 100%;
  border-collapse: collapse;
}
.pp5-page6-table th,
.pp5-page6-table td,
.pp5-page6-summary-table th,
.pp5-page6-summary-table td {
  border: 1px solid #b0b8c8;
  padding: 1.5px;
  text-align: center;
  font-size: 9px;
  vertical-align: middle;
  height: 6.8mm;
}
.pp5-page6-table thead th,
.pp5-page6-summary-table thead th {
  font-weight: 700;
  background: #f5f7fa;
}
.pp5-page6-table th.pp5-vertical-header {
  height: 20mm;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  white-space: nowrap;
  font-weight: normal;
  font-size: 8.5px;
  padding: 1mm 0.5mm;
}
.pp5-page6-sidebar {
  border-left: 1px solid #000;
  padding-left: 4mm;
  min-height: 196mm;
  box-sizing: border-box;
}
.pp5-page6-course-info {
  font-size: 10px;
  line-height: 1.5;
  border: 1px solid #b0b8c8;
  padding: 4mm;
  background: #fcfdfd;
  margin-bottom: 4mm;
}
