:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #6b7280;
  --primary: #16a34a;
  --primary-dark: #15803d;
  --accent: #2563eb;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --line: #e5e7eb;
  --shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
  --radius: 20px;
  --font-body: 'IBM Plex Sans Thai','Segoe UI Emoji','Apple Color Emoji','Noto Color Emoji','Noto Sans Thai', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: 'Kanit','Segoe UI Emoji','Apple Color Emoji','Noto Color Emoji','IBM Plex Sans Thai', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* ฟอนต์เอกสารราชการ — ใช้เฉพาะตอนพิมพ์/ส่งออกรายงาน (TH Sarabun) */
  --font-report: 'Sarabun','TH Sarabun New','TH SarabunPSK','IBM Plex Sans Thai','Noto Sans Thai', sans-serif;
}

/* ===== SAKOOL Class wordmark ===== */
.wm { font-weight: 900; letter-spacing: .2px; }
.wm em { font-style: normal; font-weight: 600; opacity: .9; }
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background: radial-gradient(circle at top left, #d1fae5 0, transparent 35%), var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body, button, input, select, textarea { font-family: var(--font-body); }
h1, h2, h3, h4, h5, h6, .swal2-title { font-family: var(--font-display); letter-spacing: .1px; }
.swal2-popup { font-family: var(--font-body) !important; }
/* ตัวเลข/รหัสที่กำหนด monospace แบบ inline ให้ใช้ฟอนต์ mono ชุดเดียวกัน */
[style*="monospace"] { font-family: var(--font-mono) !important; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 0; }
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(460px, 100%);
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 28px;
  padding: 34px;
  box-shadow: var(--shadow);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, #16a34a, #0891b2);
  color: white;
  font-weight: 900;
  font-size: 26px;
  box-shadow: 0 12px 28px rgba(22,163,74,.25);
  line-height: 1;
}
.brand h1, .brand p { margin: 0; }
.brand h1 { font-size: 24px; }
.brand p { color: var(--muted); font-size: 14px; }
.field { margin-bottom: 16px; }
label { display: block; margin-bottom: 8px; color: #374151; font-weight: 700; font-size: 14px; }
input, select, textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
  outline: none;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(22,163,74,.1); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 14px;
  font-weight: 800;
  transition: .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-soft { background: #d1fae5; color: #065f46; }
.btn-blue { background: #dbeafe; color: #1e40af; }
.btn-amber { background: #fef3c7; color: #92400e; }
.btn-red { background: #fee2e2; color: #991b1b; }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; gap: 4px; }
.btn-sm + .btn-sm { margin-left: 4px; }
.alert {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #fef2f2;
  color: #991b1b;
  font-weight: 700;
  display: none;
}
.alert.show { display: block; }
.shell { display: flex; min-height: 100vh; position: relative; }
.sidebar {
  width: 280px;
  background: #064e3b;
  color: white;
  padding: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  max-height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 5;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 3px; }
.sidebar .brand p { color: #a7f3d0; }
.sidebar .brand { margin-bottom: 22px; flex-shrink: 0; }
.nav { display: grid; gap: 6px; flex: 1; min-height: 0; }
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #064e3b;
  color: white;
  font-size: 22px;
  border: 0;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  cursor: pointer;
}
.nav button {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  background: transparent;
  color: #d1fae5;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: .2s ease;
}
.nav button .nav-icon { font-size: 18px; width: 22px; text-align: center; }
.nav button.active {
  background: linear-gradient(90deg, rgba(34,197,94,.4), rgba(255,255,255,.05));
  color: white;
  box-shadow: inset 3px 0 0 #4ade80;
}
.nav button:hover { background: rgba(255,255,255,.1); color: white; transform: translateX(2px); }
.nav button.nav-group { cursor: pointer; margin-top: 2px; }
.nav button.nav-group .nav-caret {
  margin-left: auto;
  font-size: 12px;
  opacity: .8;
}
.nav-group-body {
  display: grid;
  gap: 4px;
  padding-left: 10px;
  margin: 4px 0 6px 12px;
  border-left: 2px solid rgba(255,255,255,.08);
}
.nav button.nav-sub {
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 700;
  color: #a7f3d0;
  border-radius: 10px;
}
.nav button.nav-sub.active {
  background: linear-gradient(90deg, rgba(34,197,94,.4), rgba(255,255,255,.05));
  color: white;
  box-shadow: inset 3px 0 0 #4ade80;
}
.nav button.nav-sub .nav-icon { font-size: 15px; width: 18px; }
.main { flex: 1; padding: 28px; min-width: 0; animation: pageIn .35s cubic-bezier(.2,.7,.3,1); }
@keyframes pageIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.topbar h2 { margin: 0; font-size: 30px; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.card {
  background: rgba(255,255,255,.92);
  border: 1px solid rgba(255,255,255,.75);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: transform .2s ease, box-shadow .2s ease;
}
.card.hover-lift:hover { transform: translateY(-3px); box-shadow: 0 28px 60px rgba(15,23,42,.12); }
.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-icon {
  position: absolute;
  right: 14px;
  top: 12px;
  font-size: 56px;
  opacity: .18;
  pointer-events: none;
  filter: grayscale(.1);
  transition: transform .3s ease;
}
.stat-card:hover .stat-icon { transform: scale(1.1) rotate(-5deg); opacity: .28; }
.stat-card.green { background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%); border-color: #a7f3d0; }
.stat-card.blue { background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%); border-color: #bfdbfe; }
.stat-card.amber { background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%); border-color: #fde68a; }
.stat-card.purple { background: linear-gradient(135deg, #faf5ff 0%, #ede9fe 100%); border-color: #ddd6fe; }
.stat-title { color: var(--muted); font-weight: 800; position: relative; z-index: 1; }
.stat-value { font-size: 42px; font-weight: 900; margin-top: 8px; color: var(--primary-dark); position: relative; z-index: 1; }
.stat-card.blue .stat-value { color: #1e40af; }
.stat-card.amber .stat-value { color: #92400e; }
.stat-card.purple .stat-value { color: #5b21b6; }
.panel-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.panel-title h3 { margin: 0; font-size: 22px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 13px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: #475569; font-size: 13px; background: #f0fdf4; }
tr:hover td { background: #f9fafb; }
.badge { display: inline-flex; align-items: center; padding: 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 900; }
.badge.active { background: #dcfce7; color: #166534; }
.badge.disabled { background: #e5e7eb; color: #374151; }
.toggle {
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none;
}
.toggle input { display: none; }
.toggle .track {
  width: 42px; height: 24px; border-radius: 12px;
  background: #e5e7eb; position: relative; transition: .15s;
}
.toggle .track::after {
  content: ''; position: absolute; left: 3px; top: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: white; transition: .15s;
}
.toggle input:checked + .track { background: var(--primary); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.toast {
  position: fixed;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  max-width: 420px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #064e3b;
  color: white;
  box-shadow: var(--shadow);
  display: none;
  z-index: 10000;
  text-align: center;
}
.toast.show { display: block; }
.small { color: var(--muted); font-size: 13px; }
.code { font-family: var(--font-mono); font-size: 12px; background: #ecfdf5; padding: 5px 7px; border-radius: 8px; color: #065f46; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .empty-icon { font-size: 56px; margin-bottom: 12px; display: block; opacity: .6; }
.empty .empty-text { font-size: 15px; font-weight: 600; }
.btn { transition: transform .15s ease, box-shadow .15s ease; }
.btn:active { transform: translateY(0) scale(.97); }
.btn-primary { box-shadow: 0 4px 12px rgba(22,163,74,.25); }
.btn-primary:hover { box-shadow: 0 8px 20px rgba(22,163,74,.35); }
tr { transition: background .15s ease; }
.badge { transition: transform .15s ease; }
.badge:hover { transform: scale(1.05); }
.logo { transition: transform .3s ease; }
.brand:hover .logo { transform: rotate(-8deg) scale(1.05); }

.timetable-wrap { overflow-x: auto; padding: 10px 0; }
.timetable {
  border-collapse: separate;
  border-spacing: 8px;
  width: 100%;
  min-width: 900px;
  table-layout: fixed;
}
.timetable th, .timetable td {
  padding: 10px;
  text-align: center;
  border: 0;
  vertical-align: middle;
}
.timetable thead th {
  background: white;
  border: 2px dashed #cbd5e1;
  border-radius: 14px;
  font-size: 13px;
  color: #475569;
  font-weight: 800;
  padding: 10px 6px;
}
.timetable .corner {
  background: linear-gradient(135deg, #a78bfa, #f472b6);
  color: white;
  font-weight: 900;
  border: 0;
}
.timetable .day-cell {
  font-weight: 900;
  border-radius: 14px;
  padding: 14px 10px;
  width: 110px;
  box-shadow: 0 2px 0 rgba(0,0,0,.04);
}
.timetable .day-mon { background: #fef9c3; color: #854d0e; }
.timetable .day-tue { background: #fce7f3; color: #9f1239; }
.timetable .day-wed { background: #dcfce7; color: #166534; }
.timetable .day-thu { background: #fed7aa; color: #9a3412; }
.timetable .day-fri { background: #dbeafe; color: #1e40af; }
.timetable .day-sat { background: #ede9fe; color: #5b21b6; }
.timetable .day-sun { background: #fee2e2; color: #991b1b; }

.timetable .slot {
  background: white;
  border: 2px solid #e5e7eb;
  border-radius: 14px;
  height: 78px;
  cursor: pointer;
  transition: .15s;
  position: relative;
  padding: 8px;
}
.timetable .slot:hover {
  border-color: var(--primary);
  background: #f0fdf4;
  transform: translateY(-1px);
}
.timetable .slot.filled {
  border-style: solid;
  background: #ecfdf5;
  border-color: #6ee7b7;
  cursor: grab;
}
.timetable .slot.filled:active { cursor: grabbing; }
.timetable .slot.dragging {
  opacity: 0.4;
  transform: scale(.96);
  border-style: dashed;
}
.timetable .slot.drop-target {
  border-color: var(--primary) !important;
  background: linear-gradient(135deg, #ecfdf5, #d1fae5) !important;
  transform: scale(1.05);
  box-shadow: 0 8px 20px rgba(22,163,74,.25);
}
.timetable .slot.swap-target {
  border-color: #f59e0b !important;
  background: linear-gradient(135deg, #fffbeb, #fef3c7) !important;
  transform: scale(1.05);
  box-shadow: 0 8px 20px rgba(245,158,11,.25);
}
.timetable .slot .subj {
  font-weight: 900;
  color: #065f46;
  font-size: 14px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.timetable .slot .room {
  font-size: 12px;
  color: #475569;
  margin-top: 4px;
}
.timetable .slot .del-x {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(220,38,38,.1);
  color: #b91c1c;
  font-size: 14px;
  font-weight: 900;
  display: none;
  align-items: center;
  justify-content: center;
  border: 0;
}
.timetable .slot.filled:hover .del-x { display: inline-flex; }
.timetable .slot .plus {
  color: #94a3b8;
  font-size: 22px;
  font-weight: 900;
}
.timetable .period-head { font-weight: 900; color: #475569; }
.timetable .period-head .period-time { font-size: 11px; color: #64748b; font-weight: 700; }
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
  animation: fadeIn .15s ease;
}
.modal-overlay.show { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal {
  background: white;
  border-radius: 22px;
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 30px 80px rgba(0,0,0,.25);
  animation: slideUp .2s ease;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px 8px;
}
.modal-header h3 { margin: 0; font-size: 22px; }
.modal-close {
  background: #f3f4f6;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 22px;
  color: #475569;
  display: grid; place-items: center;
}
.modal-close:hover { background: #e5e7eb; }
.modal-body { padding: 8px 24px 16px; }
.modal-footer {
  padding: 12px 24px 22px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.modal-confirm-msg { padding: 4px 24px 18px; color: #475569; line-height: 1.6; }
.btn-ghost { background: transparent; color: #475569; }
.btn-ghost:hover { background: #f3f4f6; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #b91c1c; }
.status-pills { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.pill {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  background: #f1f5f9;
  color: #64748b;
  border: 2px solid transparent;
  transition: all .15s ease;
}
.pill:hover { transform: translateY(-1px); background: #e2e8f0; }
.pill.present.active { background: #dcfce7; color: #166534; border-color: #22c55e; }
.pill.absent.active { background: #fee2e2; color: #991b1b; border-color: #ef4444; }
.pill.late.active { background: #fef3c7; color: #92400e; border-color: #f59e0b; }
.pill.leave.active { background: #dbeafe; color: #1e40af; border-color: #3b82f6; }
.pill.activity.active { background: #ede9fe; color: #5b21b6; border-color: #8b5cf6; }
.pill.truant.active { background: #1f2937; color: #fef3c7; border-color: #111827; }
.attendance-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 16px;
  border-radius: 14px;
  background: white;
  border: 2px solid #e5e7eb;
  cursor: pointer;
  transition: all .2s ease;
}
.attendance-card:hover { border-color: var(--primary); transform: translateY(-3px); box-shadow: 0 12px 28px rgba(22,163,74,.15); }
.attendance-card .a-period { font-size: 12px; color: var(--muted); font-weight: 800; }
.attendance-card .a-class { font-size: 18px; font-weight: 900; color: #064e3b; }
.attendance-card .a-subject { font-size: 14px; color: #475569; }
.attendance-card .a-status { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 800; }
.attendance-card.done { background: #ecfdf5; border-color: #22c55e; }
.attendance-card.partial { background: #fffbeb; border-color: #f59e0b; }
.view-toggle { display: inline-flex; background: #e5e7eb; border-radius: 12px; padding: 4px; gap: 2px; }
.view-toggle button {
  padding: 8px 14px; border-radius: 10px; background: transparent;
  font-weight: 800; color: #475569;
}
.view-toggle button.active { background: white; color: var(--primary-dark); box-shadow: 0 2px 6px rgba(0,0,0,.06); }
.class-tabs {
  display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap;
  border-bottom: 2px solid #e5e7eb; padding-bottom: 0;
}
.class-tabs button {
  padding: 10px 16px; background: transparent;
  font-weight: 800; color: #64748b;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  border-radius: 8px 8px 0 0;
  transition: all .15s ease;
}
.class-tabs button:hover { color: #166534; background: #f0fdf4; }
.class-tabs button.active { color: #166534; border-bottom-color: #16a34a; background: #f0fdf4; }
.class-tabs .count { font-size: 11px; color: #94a3b8; font-weight: 700; margin-left: 4px; }
.class-tabs button.active .count { color: #16a34a; }
/* กัน body horizontal scroll — ใช้ max-width แทน overflow-x:hidden เพื่อไม่ทำลาย position:sticky */
html, body { max-width: 100vw; }
body { overflow-x: clip; }


/* iPad Pro landscape ลงมา (≤1366px) — sidebar เป็น overlay ใช้ hamburger */
@media (max-width: 1366px) {
  .timetable { min-width: 720px; }
  .timetable .day-cell { width: 80px; padding: 10px 6px; font-size: 13px; }
  .timetable .slot { height: 64px; }

  .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed;
    left: -300px;
    top: 0;
    bottom: 0;
    width: 280px;
    z-index: 90;
    transition: left .25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.2);
  }
  .shell.sidebar-open .sidebar { left: 0; }
  .shell.sidebar-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 80;
  }
  .main { padding: 64px 22px 24px; flex: 1; min-width: 0; max-width: 100%; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 10px; }
  .topbar .actions { width: 100%; flex-wrap: wrap; }
}

/* iPad portrait + tablet เล็ก — grid-2 พับเป็น 1 col */
@media (max-width: 1100px) {
  .grid-2, .form-grid { grid-template-columns: 1fr !important; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)) !important; }
}

/* Phone */
@media (max-width: 600px) {
  .main { padding: 60px 12px 16px; }
  .card { padding: 14px; }
  .grid, .grid-2, .form-grid { grid-template-columns: 1fr !important; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .topbar h2 { font-size: 19px; }
  .btn { padding: 10px 14px; font-size: 14px; }
}

/* ทุกตารางใหญ่ — scroll แนวนอนได้เสมอ */
.table-wrap, .timetable-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

/* Test info card — compact 5-col grid */
.test-info-card { padding: 22px 24px; }
.test-info-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
}
.test-info-grid .field { display: flex; flex-direction: column; }
.test-info-grid .field.full { grid-column: 1 / -1; }
.test-info-grid label { font-weight: 700; font-size: 13px; margin-bottom: 6px; color: #334155; }
.test-info-grid input, .test-info-grid select, .test-info-grid textarea {
  padding: 10px 12px; border: 1.5px solid #e5e7eb; border-radius: 10px;
  font-size: 14px; transition: border-color .15s;
}
.test-info-grid input:focus, .test-info-grid select:focus, .test-info-grid textarea:focus {
  outline: none; border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
@media (max-width: 1280px) { .test-info-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 768px) { .test-info-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .test-info-grid { grid-template-columns: 1fr; } }

/* Class chips — multi-select for tests */
.cls-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border: 2px solid #e5e7eb;
  border-radius: 999px;
  background: white;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  color: #475569;
  transition: all .15s ease;
  user-select: none;
}
.cls-chip:hover { border-color: #16a34a; background: #f0fdf4; transform: translateY(-1px); }
.cls-chip.on {
  background: linear-gradient(135deg, #16a34a, #15803d);
  border-color: #15803d;
  color: white;
  box-shadow: 0 4px 10px rgba(22,163,74,.3);
}
.cls-chip.on::before { content: '✓'; font-weight: 900; margin-right: 4px; }

/* Toggle switches — แสดงคะแนน / ทำซ้ำ */
.opt-toggles { display: flex; flex-wrap: wrap; gap: 24px; }
.opt-toggle {
  display: inline-flex; align-items: center; gap: 12px;
  cursor: pointer; user-select: none;
  padding: 10px 16px;
  background: #f8fafc;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  transition: all .15s ease;
}
.opt-toggle:hover { background: #f1f5f9; border-color: #cbd5e1; }
.opt-toggle input { display: none; }
.opt-toggle .opt-slider {
  width: 42px; height: 24px;
  background: #cbd5e1;
  border-radius: 999px;
  position: relative;
  transition: background .2s ease;
  flex-shrink: 0;
}
.opt-toggle .opt-slider::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform .2s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,.15);
}
.opt-toggle input:checked + .opt-slider { background: linear-gradient(135deg, #6366f1, #4338ca); }
.opt-toggle input:checked + .opt-slider::after { transform: translateX(18px); }
.opt-toggle .opt-text { font-weight: 700; color: #334155; font-size: 14px; }

/* Add question dropdown */
.add-q-menu { position: relative; }
.add-q-dropdown {
  display: flex; flex-direction: column;
  position: absolute; top: 100%; right: 0;
  margin-top: 6px;
  background: white;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  min-width: 200px;
  z-index: 20;
  overflow: hidden;
}
.add-q-dropdown button {
  background: white; color: #1f2937;
  border: 0;
  padding: 12px 16px;
  text-align: left;
  font-weight: 700; font-size: 14px;
  cursor: pointer;
  transition: background .15s;
}
.add-q-dropdown button:hover { background: #f0fdf4; color: #15803d; }
.add-q-dropdown button + button { border-top: 1px solid #f1f5f9; }

/* Simple question preview list (on main page) */
.qsimple-list {
  display: flex; flex-direction: column;
  gap: 8px;
}
.qsimple {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  cursor: pointer;
  transition: all .15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.qsimple:hover { transform: translateX(2px); border-color: #c7d2fe; box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.qsimple-num {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: white; font-weight: 900; font-size: 14px;
  flex-shrink: 0;
}

/* Add question dropdown (inside builder modal) */
.add-q-wrapper { position: relative; }
.add-q-menu-pop {
  display: flex; flex-direction: column;
  position: absolute; top: calc(100% + 6px); right: 0;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 12px 36px rgba(0,0,0,.18);
  min-width: 280px;
  z-index: 250;
  overflow: hidden;
  padding: 6px;
}
.add-q-menu-pop .aq-item {
  display: flex; align-items: center; gap: 12px;
  background: white;
  color: #1f2937;
  border: 0;
  border-left: 4px solid var(--c, #6366f1);
  padding: 10px 14px;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  margin: 2px 0;
  transition: all .12s;
}
.add-q-menu-pop .aq-item:hover { background: #f8fafc; transform: translateX(2px); }
.add-q-menu-pop .aq-item .aq-icon {
  width: 36px; height: 36px;
  background: var(--c, #6366f1);
  color: white;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 16px;
  border-radius: 10px;
  flex-shrink: 0;
}
.add-q-menu-pop .aq-item small { color: #64748b; font-weight: 500; font-size: 11px; }

/* Builder modal — full-screen editor for questions */
#builderModal { z-index: 200; }
.builder-modal {
  background: white;
  width: 100%;
  max-width: 1200px;
  height: 95vh;
  margin: auto;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.builder-modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
  background: white;
  flex-shrink: 0;
  flex-wrap: wrap; gap: 10px;
}
.builder-modal-body {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 0;
}

/* Split builder (used inside modal): left list + right editor */
.qbuilder-list {
  background: #f8fafc;
  border-right: 1px solid #e5e7eb;
  display: flex; flex-direction: column;
  min-height: 0;
}
.qbuilder-list-head {
  padding: 14px 16px;
  border-bottom: 1px solid #e5e7eb;
  display: flex; justify-content: space-between; align-items: center;
  background: white;
  flex-shrink: 0;
}
.qbuilder-list-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}
.qlist-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: white;
  border-left: 4px solid transparent;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all .15s ease;
  position: relative;
}
.qlist-item:hover { background: #f1f5f9; transform: translateX(2px); }
.qlist-item.on {
  background: white;
  border-left-color: #6366f1;
  box-shadow: 0 2px 8px rgba(99,102,241,.15);
}
.qlist-num {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: white; font-weight: 900; font-size: 13px;
  flex-shrink: 0;
}
.qlist-del {
  background: transparent; border: 0;
  width: 26px; height: 26px;
  border-radius: 6px;
  font-size: 18px; font-weight: 700;
  color: #94a3b8;
  cursor: pointer;
  opacity: 0;
  transition: all .15s;
}
.qlist-item:hover .qlist-del { opacity: 1; }
.qlist-del:hover { background: #fee2e2; color: #dc2626; }

.qbuilder-pane {
  padding: 24px;
  overflow-y: auto;
  min-height: 0;
}
.qbuilder-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  color: #64748b;
  padding: 40px 20px;
  height: 100%;
}
.qpane-head {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 14px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 18px;
  flex-wrap: wrap; gap: 8px;
}
.qpane-head .qcard-score {
  font-size: 13px; color: #475569; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px;
}
.qpane-head .qcard-score input {
  width: 70px; padding: 6px 10px; font-size: 14px;
  border: 1.5px solid #e5e7eb; border-radius: 8px;
}
.qpane-foot {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid #e5e7eb;
  display: flex; justify-content: flex-end;
}

@media (max-width: 1024px) {
  .builder-modal-body { grid-template-columns: 220px 1fr; }
}
@media (max-width: 768px) {
  .builder-modal { height: 100vh; max-height: 100vh; border-radius: 0; }
  .builder-modal-body { grid-template-columns: 1fr; }
  .qbuilder-list { border-right: 0; border-bottom: 1px solid #e5e7eb; max-height: 200px; }
}

/* Question preview cards (compact list) */
.qpreview {
  background: white;
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all .15s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,.04);
}
.qpreview:hover { transform: translateX(2px); box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.qpreview-head { display: flex; align-items: center; gap: 14px; }
.qpreview-num {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: white;
  font-weight: 900; font-size: 16px;
  flex-shrink: 0;
}
.qpreview-type { margin: 0 0 3px; font-size: 11px; font-weight: 800; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px; }
.qpreview-prompt { margin: 0; font-size: 14px; font-weight: 700; color: #1f2937; line-height: 1.4; word-break: break-word; }
.qpreview-ans { display: inline-block; margin-top: 6px; font-size: 12px; color: #15803d; background: #f0fdf4; padding: 2px 8px; border-radius: 6px; font-weight: 700; }
.qpreview-actions { display: flex; gap: 6px; flex-shrink: 0; }
.qpreview-actions button { padding: 6px 10px; font-size: 12px; }

@media (max-width: 600px) {
  .qpreview-actions { flex-direction: column; }
}

/* Question card (test builder) */
.qcard {
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 14px;
  background: white;
  border: 2px solid #e5e7eb;
  box-shadow: 0 4px 14px rgba(0,0,0,.04);
  transition: border-color .15s, transform .15s;
}
.qcard:hover { border-color: #c7d2fe; transform: translateY(-1px); }
.qcard-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap; gap: 8px;
}
.qcard-num { display: flex; align-items: center; gap: 10px; }
.qcard-num-circle {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  color: white;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 15px;
}
.qcard-score {
  font-size: 12px; color: #475569; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px;
}
.qcard-score input {
  width: 56px; padding: 6px 8px; font-size: 13px;
  border: 1.5px solid #e5e7eb; border-radius: 8px;
}

/* Kahoot-style MCQ choice grid */
.kahoot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.kahoot-cell {
  position: relative;
  padding: 18px 16px;
  border-radius: 14px;
  color: white;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 130px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  transition: transform .15s, box-shadow .15s;
}
.kahoot-cell:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,.2); }
.kahoot-cell.is-correct { box-shadow: 0 0 0 4px #fbbf24, 0 8px 24px rgba(251,191,36,.5); }
.kahoot-cell .kahoot-shape {
  font-size: 28px; font-weight: 900; line-height: 1;
  text-shadow: 0 2px 4px rgba(0,0,0,.2);
}
.kahoot-cell input[type="text"] {
  background: rgba(255,255,255,.95);
  color: #0f172a;
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 700;
  width: 100%;
}
.kahoot-actions { display: flex; gap: 6px; align-items: center; }
.kahoot-correct {
  flex: 1;
  background: rgba(255,255,255,.25);
  color: white;
  border: 1.5px solid rgba(255,255,255,.5);
  border-radius: 8px;
  padding: 7px 10px;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.kahoot-correct:hover { background: rgba(255,255,255,.4); }
.kahoot-correct.on {
  background: white;
  color: #0f172a;
}
.kahoot-rm {
  background: rgba(0,0,0,.3);
  color: white;
  border: 0; border-radius: 8px;
  width: 32px; height: 32px;
  font-size: 18px; font-weight: 900;
  cursor: pointer;
}
.kahoot-rm:hover { background: rgba(0,0,0,.5); }

/* True/False — 2 big colored buttons */
.tf-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.tf-btn {
  border: 0;
  border-radius: 14px;
  padding: 30px 16px;
  color: white;
  font-weight: 800;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,.15);
  transition: transform .15s, box-shadow .15s;
}
.tf-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,.2); }
.tf-true { background: linear-gradient(135deg, #22c55e, #15803d); }
.tf-false { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.tf-btn.on { box-shadow: 0 0 0 4px #fbbf24, 0 8px 24px rgba(251,191,36,.5); }
.tf-btn .tf-icon { font-size: 38px; line-height: 1; }
.tf-btn .tf-text { font-size: 17px; }
.tf-btn:not(.on) { opacity: .85; }
.tf-btn.on { opacity: 1; }

/* Homework gallery — thumbnails grid */
.hw-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.hw-thumb {
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.hw-thumb:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,.1); }
.hw-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Image viewer overlay */
.image-viewer {
  position: fixed; inset: 0; z-index: 999;
  background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none;
  animation: ivFadeIn .2s ease;
}
@keyframes ivFadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes cc-spin { to { transform: rotate(360deg) } }

/* ===== Compact tabs (level/room) ===== */
.cc-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid #e5e7eb;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0;
  margin: 0;
  scrollbar-width: thin;
}
.cc-tabs::-webkit-scrollbar { height: 4px; }
.cc-tabs::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }
.cc-tab {
  background: transparent;
  border: 0;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #64748b;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-family: inherit;
}
.cc-tab:hover { color: #0f172a; background: rgba(37, 99, 235, 0.05); }
.cc-tab.active {
  color: #16a34a;
  border-bottom-color: #16a34a;
  background: rgba(22, 163, 74, 0.06);
}
/* Pill-style for room tabs (inside soft container) */
#stuRoomTabs.cc-tabs { border-bottom: 0; }
#stuRoomTabs .cc-tab { border-radius: 8px; margin-bottom: 0; padding: 7px 12px; font-size: 12px; }
#stuRoomTabs .cc-tab.active { background: white; color: #0f172a; border-bottom-color: transparent; box-shadow: 0 1px 4px rgba(15,23,42,.08); }
.image-viewer .iv-img {
  max-width: 95vw; max-height: 88vh;
  transition: transform .15s ease;
  cursor: grab;
  touch-action: none;
}
.image-viewer .iv-img:active { cursor: grabbing; }
.image-viewer .iv-toolbar {
  position: absolute; top: 14px; right: 14px;
  display: flex; gap: 6px;
  background: rgba(0,0,0,.6); border-radius: 12px; padding: 4px;
  backdrop-filter: blur(8px);
}
.image-viewer .iv-btn {
  background: transparent; color: white; border: 0;
  padding: 8px 14px; font-weight: 800; font-size: 18px;
  border-radius: 8px; cursor: pointer; min-width: 40px;
}
.image-viewer .iv-btn:hover { background: rgba(255,255,255,.2); }
.image-viewer .iv-close { font-size: 24px; }
.image-viewer .iv-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(0,0,0,.55); color: white; border: 0;
  width: 56px; height: 56px; font-size: 36px; font-weight: 700;
  border-radius: 50%; cursor: pointer;
  backdrop-filter: blur(8px);
}
.image-viewer .iv-nav:hover { background: rgba(0,0,0,.85); }
.image-viewer .iv-prev { left: 18px; }
.image-viewer .iv-next { right: 18px; }
@media (max-width: 600px) {
  .image-viewer .iv-nav { width: 44px; height: 44px; font-size: 28px; }
  .image-viewer .iv-prev { left: 8px; }
  .image-viewer .iv-next { right: 8px; }
}

@media print {
  /* เอกสารที่พิมพ์ออกกระดาษใช้ฟอนต์สารบรรณทั้งหมด (รวมหัวข้อ/ตาราง) */
  body, body *, h1, h2, h3, h4, h5, h6 { font-family: var(--font-report) !important; }
  body { background: white; }
  .sidebar, .topbar .actions, .toast, .modal-overlay { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; animation: none; }
  body > *:not(.shell) { display: none !important; }
  .main > section:not(#reportArea), .main > .topbar { display: none !important; }
  #reportArea { display: block !important; }
  #reportArea .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  #reportArea .stat-card .stat-icon { display: none; }
  #reportArea table { font-size: 12px; }
  #reportArea th, #reportArea td { padding: 6px; }
  @page { size: A4; margin: 1.5cm; }
}

/* ===== Homework Gradebook ===== */
.gb-table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  font-size: 13px;
}
.gb-table th, .gb-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  border-right: 1px solid #f1f5f9;
  background: white;
  text-align: center;
  vertical-align: middle;
}
.gb-table thead th {
  background: #f8fafc;
  font-weight: 800;
  color: #334155;
  border-bottom: 2px solid #e2e8f0;
}
.gb-sticky-l { position: sticky; left: 0; z-index: 2; background: white; }
.gb-sticky-t { position: sticky; top: 0; z-index: 1; }
.gb-table thead .gb-sticky-l.gb-sticky-t { background: #f1f5f9; }
.gb-table .gb-name { text-align: left; }

.gb-hw-head { min-width: 130px; cursor: pointer; transition: background .15s; }
.gb-hw-head:hover { background: #ede9fe !important; }
.gb-hw-title { font-weight: 800; color: #1e293b; font-size: 13px; line-height: 1.3; }
.gb-hw-meta { font-size: 11px; color: #94a3b8; margin-top: 2px; }
.gb-hw-score { font-size: 11px; color: #6366f1; font-weight: 700; margin-top: 2px; }
.gb-hw-stat { font-size: 10px; color: #64748b; margin-top: 4px; font-weight: 600; }

/* ปิดรับงานด่วน — ปุ่มบนหัวคอลัมน์การบ้าน */
.gb-hw-closebtn { margin-top: 5px; border: 1px solid #e2e8f0; background: #fff; color: #b91c1c; font-size: 10px; font-weight: 800;
  padding: 3px 8px; border-radius: 999px; cursor: pointer; line-height: 1.4; white-space: nowrap; }
.gb-hw-closebtn:hover { background: #fee2e2; border-color: #fca5a5; }
.gb-hw-closebtn.reopen { color: #047857; }
.gb-hw-closebtn.reopen:hover { background: #d1fae5; border-color: #6ee7b7; }
.gb-hw-head.closed { background: #fff1f2 !important; }
.gb-hw-closed-tag { display: inline-block; margin-top: 3px; font-size: 10px; font-weight: 800; color: #b91c1c;
  background: #fee2e2; border-radius: 999px; padding: 1px 7px; }

.gb-cell { cursor: pointer; transition: background .12s; min-width: 90px; }
.gb-cell:hover { background: #f0fdf4 !important; }
.gb-cell.empty { color: #cbd5e1; background: #fafbfc; }
.gb-cell.submitted { background: #fef3c7; color: #92400e; }
.gb-cell.graded { background: #dcfce7; color: #065f46; }
.gb-cell.graded .gb-score { font-weight: 800; font-size: 14px; }
.gb-cell .gb-status { font-size: 18px; }
.gb-total { background: #f1f5f9; font-weight: 700; color: #475569; }

/* Subject + class tab pills (for renderHomeworks) */
.hwgb-tab {
  padding: 8px 14px;
  border-radius: 999px;
  background: white;
  color: var(--muted, #64748b);
  font-weight: 700;
  font-size: 13px;
  border: 1.5px solid var(--line, #e5e7eb);
  white-space: nowrap;
  cursor: pointer;
  transition: all .15s;
}
.hwgb-tab:hover { transform: translateY(-1px); }
.hwgb-tab.active {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  border-color: #6366f1;
  box-shadow: 0 4px 12px rgba(99, 102, 241, .25);
}
.hwgb-tab.tab-purple.active {
  background: linear-gradient(135deg, #ec4899, #f472b6);
  border-color: #ec4899;
  box-shadow: 0 4px 12px rgba(236, 72, 153, .25);
}
