/*
 * ── Bootstrap 5 override layer ───────────────────────────────────────────
 * โหลดก่อน role-layout.css → Bootstrap CSS จะถูก override โดย class ด้านล่าง
 * Reset เฉพาะ base element ที่ Bootstrap reboot เปลี่ยนค่า
 */
h1, h2, h3, h4, h5, h6 { margin: 0; }
p { margin: 0; }

/* Bootstrap 5.3.x ต้นฉบับมี selector รวมคลาสนี้ (ทำให้ .modal-dialog เป็น flex-direction:column และมี height
   จำกัด ให้ .modal-body ที่มี flex:1 1 auto ข้างในหดตัวและเลื่อนได้เองแทน) — ไฟล์ assets/vendor/bootstrap/
   bootstrap.min.css ที่แจกมากับระบบไม่มี rule นี้อยู่เลย (ยืนยันด้วย grep ตรงตัว) ทำให้ modal ที่ใส่ทั้ง
   .modal-dialog-centered และ .modal-dialog-scrollable ร่วมกัน (เช่น admin_teaching_assignments.php) เหลือแค่
   flex-direction แบบ default (row) จาก .modal-dialog-centered เพียงอย่างเดียว → เนื้อหายาวล้นออกไปพ้นขอบที่
   มองเห็นได้ของ modal-content โดยไม่เลื่อน ทำให้ปุ่ม footer หายไปบนจอที่เตี้ยพอ (พบจริงบน iPad landscape/มือถือ
   ด้วย Playwright — ดู 29_UAT_UX_ROOT_CAUSE_TH.md) เติม rule ที่หายไปกลับเข้ามาตรงนี้ ไม่แก้ไฟล์ vendor โดยตรง */
.modal-dialog-centered.modal-dialog-scrollable {
  flex-direction: column;
  justify-content: center;
  height: calc(100% - var(--bs-modal-margin, 0.5rem) * 2);
}

/* บั๊กที่สองซ่อนอยู่หลังบั๊กแรก (ยืนยันด้วย Playwright เป็น root cause จริงของปุ่มบันทึกหาย): หลาย modal ในระบบ
   (admin_teaching_assignments.php และโมดัลของ teacher_assignments.php/teacher_exams.php) ครอบ .modal-body กับ
   .modal-footer ไว้ด้วย <form> เดียวกัน (จำเป็นเพื่อให้ submit ได้ทุก field ในฟอร์มเดียว) — <form> ตัวนี้เป็น
   flex-item ลูกตรงของ .modal-content (คู่กับ .modal-header) แต่ตัว <form> เองไม่มี flex:1/min-height:0 แบบที่
   Bootstrap ให้ .modal-body โดยเฉพาะ จึงไม่หดตัวเลย ทำให้ .modal-body ข้างในไม่มีทางถูกบีบให้เกิด scroll ได้จริง
   ไม่ว่าจะแก้ข้อบนแค่ไหนก็ตาม (ยืนยันด้วยการวัดจริง: ก่อนแก้ข้อนี้ปุ่มยังหายอยู่แม้ flex-direction จะถูกต้องแล้ว)
   display:contents ทำให้ <form> หายไปจาก box model แต่ยังทำงานเป็น <form> ปกติทุกอย่าง (submit ได้เหมือนเดิม) และ
   ปล่อยให้ .modal-body/.modal-footer กลายเป็น flex-item ตรงของ .modal-content ตามที่ Bootstrap ต้องการจริง ๆ */
.modal-dialog-scrollable .modal-content > form {
  display: contents;
}

/*
 * ── Teach Smart application UI system ───────────────────────────────────
 * Hallmark redesign · genre: modern-minimal (operational workbench) · tone: utilitarian
 * Page = พื้นหลังเรียบ + หัวเรื่องบนพื้นหน้า (ไม่มีแถบ topbar) · เนื้อหาที่เป็น "งาน" (ตาราง/ฟอร์ม) อยู่ใน panel เดียว
 * ข้อมูลทั่วไปวางบนพื้นหน้าโดยตรงคั่นด้วยเส้น ไม่ห่อกล่อง · สีใช้บอกสถานะ/ลำดับความสำคัญเท่านั้น
 *
 * ตัวแปรสี:
 *   --bg      พื้นหน้า          --card    พื้นผิวงาน (panel/ฟอร์ม/modal)   --surface พื้นรอง (หัวตาราง/hover)
 *   --text    ข้อความหลัก       --muted   ข้อมูลรอง                         --line    ขอบตัวควบคุม (ปุ่ม/ช่องกรอก)
 *   --rule    เส้นคั่น/ขอบ panel (อ่อนกว่า --line)                           --brand   ปุ่มหลัก/ลิงก์/จุดเน้น
 * ห้ามใช้ #ffffff เป็นพื้นหลังหน้า/panel/ฟอร์ม/modal บนหน้าจอ (ยกเว้นหน้าพิมพ์และกรอบโลโก้)
 */
:root {
  --bg: #EEF1F4;
  --card: #FAFBFC;
  --surface: #E4E9EE;
  --text: #1B2733;
  --muted: #566574;
  --line: #8FA1B1;
  --scrim: rgba(15, 38, 58, .45);
  --scrim-soft: rgba(15, 38, 58, .15);
  --shadow-drawer: 16px 0 40px rgba(15, 38, 58, .25);
  --rule: #D9E0E6;
  --brand: #17324D;
  --brand-soft: #E1E8EE;
  --brand-dark: #0F263A;
  --success: #2F5E3E;
  --success-soft: #E4EFE6;
  --warning: #8A5C1E;
  --warning-soft: #F5EAD6;
  --danger: #A6413A;
  --danger-soft: #F3E2E0;
  --info: #3B6E8F;
  --info-soft: #E0EAF0;
  --radius: 8px;          /* panel, popup, modal */
  --radius-s: 6px;        /* ปุ่ม, ช่องกรอก, แท็บ */
  --success-line: color-mix(in srgb, var(--success) 30%, var(--card));
  --warning-line: color-mix(in srgb, var(--warning) 30%, var(--card));
  --danger-line: color-mix(in srgb, var(--danger) 30%, var(--card));
  --info-line: color-mix(in srgb, var(--info) 30%, var(--card));
  --shadow: none;
  --control-h: 38px;

  /* ── Sidebar ── */
  --sidebar-bg: #0F2740;
  --sidebar-text: #EAF2F8;
  --sidebar-text-muted: #A9BCCD;
  --sidebar-hover: rgba(255, 255, 255, .07);
  --sidebar-active: rgba(255, 255, 255, .12);
  --sidebar-accent: #8CC4EE;
  --sidebar-line: rgba(255, 255, 255, .10);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Prompt', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
td, th, .stat-value, .num { font-variant-numeric: tabular-nums; }

/* ── โครงหน้า ── */
.app-shell { display: flex; min-height: 100vh; width: 100%; }

.sidebar {
  width: 232px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh; /* มือถือ/iPad: 100vh รวมพื้นที่หลังแถบ URL จึงดันท้าย sidebar (ออกจากระบบ) ตกขอบ */
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-brand { flex-shrink: 0; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand-mark { width: 34px; height: 34px; border-radius: 6px; display: grid; place-items: center; background: var(--card); flex-shrink: 0; overflow: hidden; }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand-title { font-weight: 700; font-size: 16px; line-height: 1.1; color: var(--sidebar-text); }
.brand-subtitle { color: var(--sidebar-text-muted); font-size: 12px; margin-top: 2px; }

/* เมนูเป็นพื้นที่ scroll เดียวของ sidebar (min-height:0 ให้ flex child หดได้) — header/บัญชีคงที่ */
.sidebar-nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 4px 10px 12px; display: block; }
.sidebar-section { padding: 10px 0 2px; }
.sidebar-label { font-size: 11.5px; color: var(--sidebar-text-muted); font-weight: 600; margin: 0 10px 6px; opacity: .85; }
summary.sidebar-label { display: flex; align-items: center; justify-content: space-between; min-height: 28px; border-radius: 6px; list-style: none; cursor: pointer; }
summary.sidebar-label::-webkit-details-marker { display: none; }
summary.sidebar-label::after {
  content: ''; width: 12px; height: 12px; background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform .15s ease;
}
details[open] > summary.sidebar-label::after { transform: rotate(180deg); }
summary.sidebar-label:focus-visible { outline: 2px solid var(--sidebar-text); outline-offset: 2px; }
.nav-list { display: grid; gap: 1px; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: 10px;
  min-height: 36px; padding: 6px 10px; border-radius: 6px;
  color: var(--sidebar-text-muted); font-weight: 500; font-size: 14px;
  transition: background-color .15s ease, color .15s ease;
}
.nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.nav-link:focus-visible, .brand-mark:focus-visible, .sidebar-logout:focus-visible { outline: 2px solid var(--sidebar-text); outline-offset: -2px; }
.nav-link.is-active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-link.is-active::before { content: ''; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--sidebar-accent); }
.nav-icon { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nav-icon svg, .icon-svg { width: 18px; height: 18px; flex-shrink: 0; }

/* บัญชีผู้ใช้ท้ายเมนู: ชื่อ + บทบาท + ออกจากระบบ (แทนแถบ topbar) */
.sidebar-account { flex-shrink: 0; padding: 12px 18px calc(16px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--sidebar-line); display: grid; gap: 2px; }
.sidebar-account-name { color: var(--sidebar-text); font-weight: 600; font-size: 13.5px; overflow-wrap: anywhere; }
a.sidebar-account-name:hover { text-decoration: underline; text-underline-offset: 3px; }
a.sidebar-account-name:focus-visible { outline: 2px solid var(--sidebar-text); outline-offset: 2px; }
.sidebar-account-role { color: var(--sidebar-text-muted); font-size: 12px; }
.sidebar-logout { margin-top: 8px; display: inline-flex; align-items: center; min-height: 32px; color: var(--sidebar-text); font-weight: 600; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(255, 255, 255, .35); width: fit-content; }
.sidebar-logout:hover { text-decoration-color: currentColor; }

.app-main { min-width: 0; flex: 1; display: flex; flex-direction: column; }
/* หัวเรื่องหน้า: อยู่บนพื้นหน้าโดยตรง ไม่มีแถบแยก — เนื้อหามีน้ำหนักมากกว่าโครง */
.topbar { display: flex; align-items: center; gap: 12px; padding: 26px 32px 0; }
.mobile-menu-btn { display: none; flex-shrink: 0; border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--card); color: var(--brand-dark); width: 44px; height: 44px; cursor: pointer; }
.page-title { margin: 0; font-size: 24px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.content-wrap { padding: 16px 32px 48px; width: 100%; max-width: 1360px; }

/* ── ปุ่ม ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--card); color: var(--text); font-weight: 600; font-size: 14px; line-height: 1.2;
  cursor: pointer; white-space: nowrap; transition: background-color .15s ease, border-color .15s ease;
}
.btn:hover { background: var(--surface); }
.btn:focus-visible, .mobile-menu-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { color: var(--danger); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn-link { border-color: transparent; background: transparent; color: var(--brand); text-decoration: underline; text-underline-offset: 3px; padding: 0 6px; }
.btn-link:hover { background: transparent; color: var(--brand-dark); }

/* ── พื้นผิว ── */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: none; padding: 20px; }
.card-title { font-size: 15px; font-weight: 700; margin: 0 0 12px; }
.card-muted { color: var(--muted); font-size: 13px; margin: 0; }
.stat-card { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.stat-label { color: var(--muted); font-weight: 500; font-size: 13px; }
.stat-value { font-size: 24px; font-weight: 700; line-height: 1.2; margin-top: 2px; }
.stat-icon { display: none; }

/* ── ตาราง ── */
.table-card { overflow: hidden; padding: 0; }
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--rule); }
.table-toolbar .card-title { margin: 0; }
.table-toolbar form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.table-toolbar form .input, .table-toolbar form .select { width: auto; flex: 1 1 200px; max-width: 320px; }
.table-responsive { position: relative; width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
table:not(:has(thead th:nth-child(5))) { min-width: 0; }
th, td { padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--rule); vertical-align: middle; }
th { background: var(--card); color: var(--muted); font-size: 12.5px; font-weight: 600; border-bottom-color: var(--line); white-space: nowrap; }
td { font-size: 14px; }
tbody tr:last-child td { border-bottom: 0; }
tr:hover td { background: color-mix(in srgb, var(--surface) 45%, transparent); }

/* ── สถานะ: จุด + ข้อความ (ไม่ใช้กล่องสีพาสเทล) ── */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 0; background: none; color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge:has(svg)::before { display: none; }
.badge-success { color: var(--success); }
.badge-warning { color: var(--warning); }
.badge-danger { color: var(--danger); }
.badge-info { color: var(--info); }
.badge-brand { color: var(--brand-dark); }
a.badge-brand:hover { text-decoration: underline; text-underline-offset: 3px; }
a.badge:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.icon-svg-sm { width: 15px; height: 15px; flex-shrink: 0; }

/* ── ฟอร์ม ── */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-group { display: grid; gap: 6px; align-content: start; }
label { font-weight: 600; font-size: 13px; color: var(--text); }
.input, .select, .textarea { width: 100%; min-height: var(--control-h); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 7px 12px; outline: none; background: var(--card); color: var(--text); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.textarea { min-height: 96px; resize: vertical; }
.full { grid-column: 1 / -1; }

.quick-links { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.quick-link { padding: 14px 16px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--rule); display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.quick-link:hover { background: var(--surface); }
.quick-link strong { display: block; font-size: 14px; }
.quick-link span { color: var(--muted); font-size: 12px; }

.notice { padding: 10px 14px; border-radius: var(--radius-s); background: var(--brand-soft); color: var(--brand-dark); border: 1px solid var(--rule); font-weight: 500; }

/* ── วันที่ไทย วว/ดด/พ.ศ. (input + ปุ่มปฏิทิน + popup) ── */
.thai-date-field { position: relative; display: flex; gap: 6px; }
.thai-date-input { flex: 1; min-width: 0; }
.thai-date-input.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.thai-date-toggle {
  flex-shrink: 0; width: 44px; border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--bg); color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.thai-date-toggle:hover { color: var(--brand); border-color: var(--brand); }
.thai-date-error { grid-column: 1/-1; color: var(--danger); font-size: 12px; font-weight: 700; margin: 4px 0 0; }
.thai-date-popup {
  z-index: 1200; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 10px; width: 260px;
}
.thai-date-popup-head { display: flex; align-items: center; justify-content: space-between; font-weight: 800; font-size: 13px; margin-bottom: 6px; }
.thai-date-nav { border: 0; background: var(--surface); border-radius: 8px; width: 26px; height: 26px; cursor: pointer; font-size: 15px; }
.thai-date-popup-dow { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.thai-date-popup-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.thai-date-day { border: 0; background: transparent; border-radius: 8px; height: 30px; cursor: pointer; font-size: 13px; }
.thai-date-day:hover { background: var(--brand-soft); }
.thai-date-day.is-selected { background: var(--brand); color: #fff; font-weight: 800; }

@media (max-width: 1100px) {
  .grid-4, .quick-links, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* ── Off-canvas sidebar: < 900px, และแท็บเล็ตสัมผัส 900–1366px (เมาส์ที่ 1366px ยังเห็นเมนูถาวร) ──
   ในโหมดนี้หัวเรื่องหน้าเป็นแถบบนติดขอบ (ปุ่มเมนู + ชื่อหน้า) — ออกจากระบบอยู่ท้ายเมนู */
@media (max-width: 899px),
       (min-width: 900px) and (max-width: 1366px) and (hover: none) and (pointer: coarse) {
  /* top/bottom:0 ตามพื้นที่มองเห็นจริงของเบราว์เซอร์ (ไม่พึ่ง vh) — ปุ่มออกจากระบบไม่ตกขอบ */
  .sidebar { position: fixed; top: 0; bottom: 0; height: auto; left: -260px; width: 260px; max-width: 86vw; z-index: 30; transition: left .2s ease; }
  body.sidebar-open .sidebar { left: 0; box-shadow: var(--shadow-drawer); }
  body.sidebar-open { overflow: hidden; }
  body.sidebar-open::after { content: ''; position: fixed; inset: 0; background: var(--scrim); z-index: 25; }
  .mobile-menu-btn { display: grid; place-items: center; }
  .topbar { position: sticky; top: 0; z-index: 10; min-height: 60px; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--rule); }
  .page-title { font-size: 17px; font-weight: 600; }
  .content-wrap { padding: 16px 12px 40px; }
}
@media (max-width: 899px) {
  .grid-2, .grid-3, .grid-4, .quick-links, .form-grid { grid-template-columns: 1fr; }
}
@media (pointer: coarse) {
  :root { --control-h: 44px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 40px; }
  .sidebar-logout { min-height: 44px; }
}
@media (max-height: 480px) {
  /* แนวนอนบนมือถือ: ลดระยะ header/บัญชีเพื่อเหลือที่ให้เมนู */
  .sidebar-brand { padding: 10px 18px 6px; }
  .sidebar-account { padding-top: 8px; }
  .sidebar-logout { margin-top: 4px; }
}

/* ── Compact summary strip (Phase 4): teacher_classes/rooms/departments/subjects/assignments.
   Opt-in modifier on the existing .grid.stat-card pattern — only these pages add the
   .summary-strip class, so nothing else using .card/.stat-card/.grid-3 is affected. ── */
.summary-strip { margin-bottom: 16px; gap: 10px; }
.summary-strip .stat-card { padding: 12px 14px; gap: 8px; border-radius: var(--radius); min-width: 0; }
.summary-strip .stat-label { font-size: 11px; white-space: normal; }
.summary-strip .stat-value { font-size: 20px; margin-top: 2px; }
@media (max-width: 899px) {
  /* Keep 2 columns on smartphone instead of the site-wide 1-column collapse above —
     .summary-strip.grid-3 / .grid-4 has higher specificity than the bare .grid-3/.grid-4
     rule, so this wins without needing !important. */
  .summary-strip.grid-3,
  .summary-strip.grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 900px) and (max-width: 1180px) {
  /* iPad: 2-3 columns instead of the full row of 4. */
  .summary-strip.grid-4 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ── หน่วยพื้นฐานร่วม (ใช้เมื่อช่วยจริง ไม่ใช่ชุดโชว์) ──
   page-bar: แถวบริบท/ตัวกรอง/ปุ่มหลักใต้หัวเรื่อง | section-head: หัวข้อส่วน + ข้อมูลรองชิดขวา | tabs: แท็บขีดเส้นใต้
   stat-strip: ตัวเลขสรุปบนพื้นหน้า คั่นด้วยเส้น (ไม่ใช่การ์ด) | row-list: แถวคั่นเส้น | kv: คู่ชื่อ–ค่า | notice.is-*: แจ้งสถานะ */
.page-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin: 0 0 16px; }
.page-bar > .grow { flex: 1 1 280px; min-width: 0; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.context-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; margin: 0 0 16px; color: var(--muted); }
.context-line strong { color: var(--text); font-size: 15px; font-weight: 600; }
/* แถบเลือกขอบเขตของหน้า (ภาคเรียน/รายวิชา ฯลฯ): ตัวกรองบรรทัดเดียวบนพื้นหน้า ไม่ห่อกล่อง */
.scope-bar { margin: 0 0 18px; }
.scope-bar form { display: grid; grid-template-columns: minmax(150px, 200px) minmax(240px, 1fr); gap: 12px 16px; align-items: end; }
@media (max-width: 640px) { .scope-bar form { grid-template-columns: 1fr; } }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; margin: 28px 0 10px; }
.section-head:first-child { margin-top: 0; }
.section-head h2 { font-size: 15px; font-weight: 700; margin: 0; }
.tabs { display: flex; gap: 2px; margin: 0 0 16px; border-bottom: 1px solid var(--rule); overflow-x: auto; }
.tabs a, .tabs button { display: inline-flex; align-items: center; min-height: 42px; padding: 0 14px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font-weight: 600; white-space: nowrap; cursor: pointer; }
.tabs a:hover, .tabs button:hover { color: var(--text); }
.tabs .is-active, .tabs [aria-current] { color: var(--brand-dark); border-bottom-color: var(--brand); }
.tabs a:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 0; margin: 0 0 24px; padding: 0; }
.stat-strip > * { min-width: 0; padding: 2px 20px 2px 0; margin-right: 20px; border-right: 1px solid var(--rule); background: none; }
.stat-strip > *:last-child { border-right: 0; margin-right: 0; }
@media (max-width: 600px) {
  .stat-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .stat-strip > * { border-right: 0; margin-right: 0; padding: 0; }
}
.stat-text { margin-top: 2px; font-weight: 600; overflow-wrap: anywhere; }
.stat-strip a { color: inherit; border-radius: var(--radius-s); }
.stat-strip a:hover { background: var(--surface); }
.stat-strip a.is-active { box-shadow: inset 0 -3px 0 var(--brand); }
.stat-strip a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
/* ตารางที่ยุบเป็นรายการบนจอแคบ: คอลัมน์แรก = หัวเรื่องเต็มบรรทัด, ที่เหลือเรียงต่อเป็นข้อมูลรอง, คอลัมน์ท้าย = คำสั่งชิดขวา */
@media (max-width: 699px) {
  table.stack-rows { min-width: 0; }
  .stack-rows thead { display: none; }
  .stack-rows tbody, .stack-rows tr { display: block; }
  .stack-rows tr { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; padding: 12px 16px; border-bottom: 1px solid var(--rule); }
  .stack-rows tbody tr:last-child { border-bottom: 0; }
  .stack-rows td { display: block; padding: 0; border: 0; background: none; }
  .stack-rows td:first-child { flex: 1 1 100%; font-weight: 600; }
  .stack-rows td:last-child:not(:first-child) { margin-left: auto; }
  .stack-rows.drop-first td:first-child { display: none; }
  .stack-rows.drop-first td:nth-child(2) { flex: 1 1 100%; font-weight: 600; }
  .stack-rows td[style*="text-align"] { text-align: left; }
  .stack-rows td[data-label]::before { content: attr(data-label) " "; color: var(--muted); font-size: 12px; font-weight: 400; }
}
.kv-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 0 18px; padding: 0 0 16px; border-bottom: 1px solid var(--rule); }
.kv-head-name { font-size: 18px; font-weight: 700; }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 28px; align-items: start; }
@media (max-width: 1100px) { .split { grid-template-columns: minmax(0, 1fr); gap: 20px; } }
.split > div > section + section { margin-top: 24px; }
.todo > * { padding: 12px 0; }
.todo .num { font-size: 20px; font-weight: 700; }
.todo .is-zero { color: var(--muted); font-weight: 500; }
.panel-pad { padding: 4px 16px 8px; }
.row-list { display: grid; }
.row-list > * { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.row-list > *:last-child { border-bottom: 0; }
.row-meta { color: var(--muted); font-size: 13px; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 20px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.stackbar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--rule); }
.stackbar > i { display: block; height: 100%; }
.stackbar .is-ok { background: var(--success); }
.stackbar .is-late { background: var(--warning); }
.stackbar .is-miss { background: var(--danger); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 10px; color: var(--muted); font-size: 13px; }
.notice { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 14px; }
.notice.is-warning { background: var(--warning-soft); border-color: var(--warning-line); color: var(--warning); }
.notice.is-danger { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.notice.is-success { background: var(--success-soft); border-color: var(--success-line); color: var(--success); }
.notice.is-info { background: var(--info-soft); border-color: var(--info-line); color: var(--brand-dark); }
.count-link { font-weight: 600; color: var(--brand-dark); text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

td .btn-primary { background: var(--card); color: var(--brand-dark); border-color: var(--line); }
td .btn-primary:hover { background: var(--surface); border-color: var(--line); }

/* ── Modal (Bootstrap): พื้นผิว/ขอบ/หัวเรื่องเดียวกันทั้งระบบ แทน inline style รายหน้า ── */
.modal-content { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--card); color: var(--text); }
.modal-header, .modal-footer { border-color: var(--rule); }
.modal-title { font-size: 18px; font-weight: 700; }

/* ── Shared pagination control: ‹ 1 2 3 … 10 › (includes/pagination.php) ──
   Used across ADMIN and TEACHER list pages so every paginated screen looks the same. */
.ts-pagination {
  display: flex;
  justify-content: center;
  margin: 16px 0;
}
.ts-pagination-list {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  overflow: hidden;
  background: var(--card);
  flex-wrap: wrap;
}
.ts-pagination-list li { display: flex; border-right: 1px solid var(--line); }
.ts-pagination-list li:last-child { border-right: none; }
.ts-pagination-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  color: var(--brand);
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  background: transparent;
}
a.ts-pagination-link:hover { background: var(--surface); text-decoration: none; color: var(--brand-dark); }
a.ts-pagination-link:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.ts-pagination-link.is-current {
  background: var(--brand);
  color: var(--card);
}
.ts-pagination-link.is-disabled {
  color: var(--muted);
  opacity: .5;
  cursor: not-allowed;
}
.ts-pagination-ellipsis {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  color: var(--muted);
}

/* ── Shared row-action buttons: Edit / Toggle / Delete ──────────────────────
   Used by teacher_classes/rooms/departments/subjects/assignments so every
   list's action column renders identically sized, icon-only controls that
   never wrap to a new line regardless of how many actions a given row has. */
.ts-actions {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: nowrap;
}
.ts-actions form { margin: 0; display: inline-flex; }
.ts-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--muted);
  line-height: 1;
  cursor: pointer;
}
.ts-action-btn svg { width: 18px; height: 18px; display: block; }
.ts-action-btn:hover { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); }
.ts-action-btn:disabled,
.ts-action-btn.is-disabled {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}
.ts-action-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.ts-action-btn--danger:hover, .ts-action-btn--danger:focus-visible { color: var(--danger); background: var(--danger-soft); border-color: var(--danger); }
@media (pointer: coarse) { .ts-action-btn { width: 44px; height: 44px; flex-basis: 44px; border-color: var(--rule); } }

/* ── Print: ซ่อน UI chrome และรีเซ็ต layout ── */
@media print {
  .sidebar,
  .topbar,
  .mobile-menu-btn { display: none !important; }

  html, body {
    min-height: 0 !important;
    height: auto !important;
    background: #fff;
  }
  .app-shell {
    display: block;
    min-height: 0 !important;
  }
  .app-main {
    display: block;
  }
  .content-wrap {
    padding: 0;
    max-width: none;
  }
}

/* ── "รายวิชา" searchable dropdown-button (shared: ทุกหน้าที่มีตัวเลือกรายวิชา — ดูหัวไฟล์
   subject-combo.js) — รูปแบบ/interaction pattern อ้างอิงจาก coop-officers-club/includes/
   unit_search_dropdown.php (ปุ่มหน้าตาคล้าย select + เมนูมีช่องค้นหาตรึงบนสุด + รายการเลื่อนได้ด้านล่าง)
   .subject-dd-menu ใช้ position:fixed คำนวณพิกัดด้วย JS (subject-combo.js: positionPanel) จึงไม่ถูกตัด
   โดย .modal-body{overflow-y:auto} (modal-dialog-scrollable) ของ Bootstrap หรือ container ใดๆ ที่มี
   overflow — อย่าใส่ top/left/right คงที่ที่นี่ เพราะ JS จะเซ็ตให้ทุกครั้งที่เปิด ──────────────────── */
.subject-search-dd { position: relative; min-width: 0; }
/* <select> เดิมที่ถูก enhance() ครอบไว้ — ยังอยู่ใน DOM เป็น source of truth ตัวเดียว (name/id/value/
   selected/required/disabled/data-attribute/form submission ไม่เปลี่ยน) ซ้อนอยู่ใต้ปุ่มที่มองเห็นพอดีตัวด้วย
   opacity:0 (ไม่ใช่ display:none) เพื่อให้ยัง focusable — required validation ของเบราว์เซอร์เมื่อฟอร์ม
   ถูก submit ทั้งที่ยังไม่ได้เลือกวิชาจึงยัง focus()/แสดง bubble ที่ตำแหน่งปุ่มได้จริง ไม่โยน error
   "invalid form control is not focusable" และไม่ต้องถอด required ออกเลย */
.subject-dd-select {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; z-index: 0; pointer-events: none; border: 0; margin: 0; padding: 0;
}
.subject-dd-btn {
  position: relative; z-index: 1; width: 100%; min-height: 44px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px solid var(--line); border-radius: 13px; background: var(--bg); color: var(--text);
  padding: 11px 13px; font: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
.subject-dd-btn:hover { border-color: var(--brand); }
.subject-dd-btn:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.subject-dd-btn.is-open { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.subject-dd-btn.is-invalid { border-color: var(--danger); }
.subject-dd-btn.is-disabled, .subject-dd-btn:disabled { background: var(--card); color: var(--muted); cursor: not-allowed; }
.subject-dd-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subject-dd-label.is-placeholder { color: var(--muted); font-weight: 400; }
.subject-dd-caret { flex-shrink: 0; color: var(--muted); display: flex; transition: transform .15s ease; }
.subject-dd-btn.is-open .subject-dd-caret { transform: rotate(180deg); }
.subject-dd-menu {
  position: fixed; z-index: 1200; width: 320px; max-width: 92vw;
  background: var(--card); border: 1px solid var(--line); border-radius: 13px;
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
}
.subject-dd-search-wrap {
  display: flex; align-items: center; gap: 8px; padding: 8px; flex-shrink: 0;
  border-bottom: 1px solid var(--line); background: var(--card);
}
.subject-dd-search-icon { color: var(--muted); flex-shrink: 0; display: flex; }
.subject-dd-search {
  flex: 1; min-width: 0; min-height: 38px; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font: inherit; font-size: 14px; outline: none; background: var(--bg); color: var(--text);
}
.subject-dd-search:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.subject-dd-options { overflow-y: auto; padding: 6px; }
.subject-dd-option {
  display: flex; align-items: flex-start; gap: 8px; padding: 10px 10px; border-radius: 9px;
  font-size: 14px; color: var(--text); line-height: 1.4; cursor: pointer; text-decoration: none;
}
.subject-dd-option:hover, .subject-dd-option.is-active { background: var(--brand-soft); color: var(--brand-dark); }
.subject-dd-check { width: 14px; flex-shrink: 0; visibility: hidden; color: var(--brand-dark); margin-top: 2px; }
.subject-dd-option.is-selected .subject-dd-check { visibility: visible; }
.subject-dd-option.is-selected { font-weight: 800; }
.subject-dd-option-name { flex: 1; overflow-wrap: anywhere; }
.subject-dd-empty { padding: 16px 12px; font-size: 13px; color: var(--muted); text-align: center; margin: 0; }

/* ── "แผนก" searchable multi-select (assets/js/multi-select-combo.js) — เลือกได้หลายรายการ, ปุ่มแสดง
   เป็น chips แทน label เดี่ยว, ใช้ token/z-index/position:fixed แนวทางเดียวกับ .subject-dd-* ด้านบน ──── */
.ms-combo { position: relative; min-width: 0; }
.ms-combo-select {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; z-index: 0; pointer-events: none; border: 0; margin: 0; padding: 0;
}
.ms-combo-btn {
  position: relative; z-index: 1; width: 100%; min-height: 44px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px solid var(--line); border-radius: 13px; background: var(--bg); color: var(--text);
  padding: 8px 13px; font: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
.ms-combo-btn:hover { border-color: var(--brand); }
.ms-combo-btn:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.ms-combo-btn.is-open { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.ms-combo-btn.is-invalid { border-color: var(--danger); }
.ms-combo-btn.is-disabled, .ms-combo-btn:disabled { background: var(--card); color: var(--muted); cursor: not-allowed; }
.ms-combo-chips { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.ms-combo-placeholder { color: var(--muted); font-weight: 400; padding: 3px 0; }
.ms-combo-chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--brand-soft); color: var(--brand-dark);
  font-size: 12px; font-weight: 700; padding: 4px 6px 4px 10px; border-radius: 999px; max-width: 100%;
}
.ms-combo-chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.ms-combo-chip-x {
  display: flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 999px;
  color: var(--brand-dark); flex-shrink: 0;
}
.ms-combo-chip-x:hover { background: var(--scrim-soft); }
.ms-combo-caret { flex-shrink: 0; color: var(--muted); display: flex; align-self: flex-start; margin-top: 10px; transition: transform .15s ease; }
.ms-combo-btn.is-open .ms-combo-caret { transform: rotate(180deg); }
.ms-combo-menu {
  position: fixed; z-index: 1200; width: 320px; max-width: 92vw;
  background: var(--card); border: 1px solid var(--line); border-radius: 13px;
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
}
.ms-combo-search-wrap {
  display: flex; align-items: center; gap: 8px; padding: 8px; flex-shrink: 0;
  border-bottom: 1px solid var(--line); background: var(--card);
}
.ms-combo-search-icon { color: var(--muted); flex-shrink: 0; display: flex; }
.ms-combo-search {
  flex: 1; min-width: 0; min-height: 38px; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font: inherit; font-size: 14px; outline: none; background: var(--bg); color: var(--text);
}
.ms-combo-search:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.ms-combo-options { overflow-y: auto; padding: 6px; }
.ms-combo-option {
  display: flex; align-items: flex-start; gap: 8px; padding: 10px 10px; border-radius: 9px;
  font-size: 14px; color: var(--text); line-height: 1.4; cursor: pointer; text-decoration: none;
}
.ms-combo-option:hover, .ms-combo-option.is-active { background: var(--brand-soft); color: var(--brand-dark); }
.ms-combo-check { width: 14px; flex-shrink: 0; visibility: hidden; color: var(--brand-dark); margin-top: 2px; }
.ms-combo-option.is-selected .ms-combo-check { visibility: visible; }
.ms-combo-option.is-selected { font-weight: 800; }
.ms-combo-option-name { flex: 1; overflow-wrap: anywhere; }
.ms-combo-empty { padding: 16px 12px; font-size: 13px; color: var(--muted); text-align: center; margin: 0; }

/* ===== Forms & settings pages (profile, password, activation) ===== */
.field-err { color: var(--danger); font-size: 13px; font-weight: 600; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.profile-page { max-width: 640px; }
.profile-id { display: flex; flex-wrap: wrap; gap: 12px 40px; margin: 0 0 8px; padding: 0 0 18px; border-bottom: 1px solid var(--rule); }
.profile-id > div { min-width: 0; }
.profile-id dt { font-size: 12px; font-weight: 600; color: var(--muted); margin: 0 0 2px; }
.profile-id dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.profile-section { padding: 20px 0 22px; border-bottom: 1px solid var(--rule); }
.profile-section:last-child { border-bottom: 0; }
.profile-section > h2 { font-size: 15px; font-weight: 700; margin: 0 0 14px; }
@media (max-width: 600px) { .profile-page .form-grid { grid-template-columns: minmax(0, 1fr); } }

/* inline filter bars: selects + subject combos share one row */
.page-actions > .select, .page-actions > .input { flex: 0 1 220px; width: auto; }
.page-actions > .subject-search-dd { flex: 0 1 280px; width: 280px; max-width: 100%; }
@media (max-width: 600px) { .page-actions > .select, .page-actions > .input, .page-actions > .subject-search-dd { flex: 1 1 100%; width: 100%; max-width: 100%; } }

.page-bar > form.page-actions { flex: 1 1 520px; min-width: 0; }

/* keyboard focus: every interactive element shows a visible ring */
a:focus-visible, button:focus-visible, summary:focus-visible, [tabindex]:focus-visible, .thai-date-toggle:focus-visible, input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.table-responsive:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
