/* =====================================================================
   THAI RET2 — MASTER STYLESHEET (Royal Navy & Gold Theme)
   ระบบบริหารจัดการผลการประเมินการอ่านการเขียน (สพป.ร้อยเอ็ด เขต 2)
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@400;500;600;700&family=Prompt:wght@400;500;600;700&display=swap');

:root {
  --navy-950: #0c0c24;
  --navy-900: #14143a;
  --navy-800: #20204F;
  --navy-700: #2C2C6E;
  --navy-600: #43439A;
  --gold: #C79A3E;
  --gold-light: #F6E6C2;
  --gold-dark: #977123;
  --bg: #F0F2F7;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --line: #E2E6EE;
  --line-light: #EEF2F6;
  --ink: #1e2530;
  --muted: #64748b;
  --ok: #209663;
  --blue: #4F46E5;
  --warn: #C79A3E;
  --danger: #E11D48;
  --radius: 12px;
  --radius-sm: 8px;
}

/* =====================================================================
   AUTH PAGES (login / password) — หน้าเข้าสู่ระบบ/ตั้งรหัส (standalone)
   ===================================================================== */
.login-wrap {
  /* body มี display:flex (สำหรับ layout หลัก) → บังคับ .login-wrap เต็มจอ ไม่งั้นการ์ดจะชิดซ้าย */
  flex: 1 1 100%;
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--navy-900) 0%, var(--navy-800) 55%, var(--navy-700) 100%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--gold);
  border-radius: 16px;
  padding: 34px 30px 26px;
  box-shadow: 0 20px 50px rgba(12, 12, 36, 0.35);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px; height: 64px;
  margin-bottom: 12px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: #ffffff;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: 1px;
  box-shadow: 0 6px 16px rgba(199, 154, 62, 0.45);
}
.login-title {
  margin: 0 0 4px;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--navy-900);
}
.login-sub { font-size: 0.85rem; color: var(--muted); line-height: 1.5; }
.login-card .field { margin-bottom: 16px; }
.login-card .field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--navy-900);
  margin-bottom: 6px;
}
.login-card .field input {
  width: 100%;
  padding: 11px 14px;
  font-size: 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-card .field input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(199, 154, 62, 0.18);
}
.login-card .btn-primary { width: 100%; padding: 12px; font-size: 1rem; margin-top: 4px; }
.login-foot {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.6;
}
@media (max-width: 480px) {
  .login-card { padding: 26px 20px 20px; border-radius: 14px; }
  .login-title { font-size: 1.3rem; }
}

/* =====================================================================
   TABLE FILTER — ช่องพิมพ์ค้นหาเหนือตาราง กรองแถวในหน้าทันที
   ===================================================================== */
.tbl-filter-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 4px 0 12px;
}
.tbl-filter {
  flex: 1 1 260px; min-width: 220px; max-width: 460px; box-sizing: border-box;
  padding: 9px 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; font-size: 0.9rem; color: var(--ink);
}
.tbl-filter:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(199, 154, 62, 0.15);
}
.tbl-filter-count { font-size: 0.82rem; color: var(--muted); font-weight: 700; white-space: nowrap; }

/* =====================================================================
   SEARCHABLE SELECT — พิมพ์ค้นหาใน dropdown ใหญ่ (เลือกโรงเรียน)
   ===================================================================== */
.ss-wrap { position: relative; }
.ss-native {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.ss-input {
  width: 100%; box-sizing: border-box;
  padding: 9px 32px 9px 12px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; font-size: 0.9rem; color: var(--ink);
}
.ss-input::placeholder { color: var(--ink); opacity: 1; }
.ss-input:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(199, 154, 62, 0.15);
}
.ss-caret {
  position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 0.7rem; pointer-events: none;
}
.ss-panel {
  display: none; position: absolute; z-index: 60; left: 0; right: 0;
  top: calc(100% + 4px); max-height: 300px; overflow-y: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 34px rgba(20, 20, 58, 0.2);
  -webkit-overflow-scrolling: touch;
}
.ss-open .ss-panel { display: block; }
.ss-item {
  padding: 9px 12px; font-size: 0.88rem; color: var(--ink); cursor: pointer;
  border-bottom: 1px solid var(--line-light);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ss-item:last-child { border-bottom: 0; }
.ss-item:hover, .ss-item.active { background: var(--gold-light); }
.ss-item.sel { font-weight: 700; color: var(--navy-900); }
/* รายการโรงเรียน: ชื่อ + บรรทัดรอง (อำเภอ · ศูนย์) + ป้ายชื่อซ้ำ */
.ss-item.ss-two { padding: 7px 12px; }
.ss-two .ss-main { display: flex; align-items: center; gap: 8px; overflow: hidden; text-overflow: ellipsis; }
.ss-two .ss-sub { font-size: 0.76rem; font-weight: 400; color: var(--muted); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; }
.ss-dup { flex: none; font-size: 0.68rem; font-weight: 700; padding: 1px 8px; border-radius: 8px; background: #fff3cd; color: #7a5a00; }
.ss-none, .ss-more { padding: 12px; color: var(--muted); font-size: 0.82rem; text-align: center; }

* { box-sizing: border-box; }
/* เลื่อนหน้าด้วยแถบเลื่อนของเบราว์เซอร์ (ขวาสุด) แบบเว็บทั่วไป
   เดิมล็อกความสูงหน้า = จอ แล้วให้เนื้อหาเลื่อนในกล่องของตัวเอง + เมนูซ้ายเลื่อนแยกอีกกล่อง
   ทำให้ชี้เมาส์ที่เมนูแล้วหมุนล้อ เมนูเลื่อนเอง (แถบเลื่อนถูกซ่อน จึงงงว่าเลื่อนอะไร) */
html, body {
  margin: 0; padding: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans Thai", "Prompt", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body {
  display: flex;
  align-items: flex-start;   /* ให้เมนูซ้าย sticky ได้ (ถ้า stretch เมนูจะสูงเท่าหน้าแล้วไม่ติดจอ) */
}

/* =====================================================================
   1. APP SHELL (SIDEBAR & TOPBAR)
   ===================================================================== */
.sidebar {
  width: 275px;
  background: linear-gradient(180deg, var(--navy-900) 0%, var(--navy-950) 100%);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid rgba(199, 154, 62, 0.25);
  box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  z-index: 20;
  /* ล็อกเมนูติดจอ ไม่เลื่อนตามเนื้อหา และไม่มีแถบเลื่อนของตัวเอง
     จอเตี้ยกว่าเมนู: assets/js/app.js ตั้ง top ติดลบ → เมนูเลื่อนลงตามแถบเลื่อนขวาจนเห็นท้ายเมนู แล้วล็อก */
  position: sticky;
  top: 0;
  min-height: 100vh;
  overflow: visible;
}
.sidebar::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}
.sidebar-header {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.logo-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(199,154,62,0.4);
}
.brand-title {
  font-weight: 800;
  font-size: 1.12rem;
  line-height: 1.1;
  color: #ffffff;
}
.brand-sub {
  font-size: 0.7rem;
  color: #cbd5e1;
  letter-spacing: 0.5px;
}

.sidebar-nav {
  flex: 1;
  overflow: visible;   /* ไม่เลื่อนในตัวเอง — ดู .sidebar */
  padding: 8px 10px 18px;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE / Edge */
}
.sidebar-nav::-webkit-scrollbar {
  display: none !important; /* Chrome, Safari, Opera */
  width: 0 !important;
  height: 0 !important;
}
.nav-group-title, .sb-group-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 8px 8px 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav-item, .sb-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 0.83rem;
  font-weight: 500;
  border-radius: 8px;
  transition: all 0.12s;
  cursor: pointer;
  margin-bottom: 2px;
}
.nav-item:hover, .sb-item:hover {
  background: rgba(255,255,255,0.08);
  color: #ffffff;
}
.nav-item.active, .sb-item.active {
  background: linear-gradient(90deg, rgba(199,154,62,0.25) 0%, rgba(79,70,229,0.2) 100%);
  color: #ffffff;
  font-weight: 700;
  border-left: 3px solid var(--gold);
}
.nav-item i, .sb-item i {
  width: 16px;
  text-align: center;
  font-size: 0.9rem;
}
.nav-item.active i, .sb-item.active i {
  color: var(--gold);
}

/* Modern Workspace Scrollbar — ตอนนี้คือแถบเลื่อนของทั้งหน้า (ขวาสุดของเบราว์เซอร์) */
html::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
html::-webkit-scrollbar-track {
  background: #f1f5f9;
}
html::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 5px;
  border: 2px solid #f1f5f9;
}
html::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Main Layout */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;        /* ตารางกว้างเลื่อนในกล่องของตัวเอง ไม่ดันทั้งหน้าให้เลื่อนแนวนอน */
  min-height: 100vh;
}
.topbar {
  position: sticky;    /* แถบบนติดจอเหมือนเดิม ขณะเลื่อนหน้าด้วยแถบเลื่อนขวา */
  top: 0;
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 10px rgba(0,0,0,0.03);
  z-index: 10;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar-title {
  font-size: 1.18rem;
  font-weight: 700;
  color: var(--navy-900);
}
.badge-year {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: var(--navy-800);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.btn-tv-mode {
  background: linear-gradient(135deg, var(--navy-900), var(--navy-800));
  color: #ffffff !important;
  border: 1px solid rgba(199,154,62,0.5);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  text-decoration: none;
}
.user-profile-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}
.content-area {
  flex: 1;
  padding: 24px 28px;
}

/* ---- ส่วนท้ายหน้า (หน่วยงาน · งาน · โครงการ) ----
   โทนเรียบ ไม่แย่งสายตาเนื้อหา: บรรทัดหน่วยงานเข้มสุด · เครดิตงานจาง · โครงการเน้นทองเล็กน้อย */
.app-footer {
  margin: 8px 28px 0;
  padding: 18px 12px 22px;
  border-top: 1px solid var(--line);
  text-align: center;
  line-height: 1.7;
  color: var(--muted);
}
.app-footer-org {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--navy-800);
}
.app-footer-org i { color: var(--gold); font-size: 0.9rem; }
.app-footer-credit {
  font-size: 0.78rem;
  margin-top: 2px;
}
.app-footer-project {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 8px;
  margin-top: 10px;
  font-size: 0.76rem;
}
.app-footer-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 12px;
  border-radius: 20px;
  background: var(--gold-light);
  color: var(--gold-dark);
  font-weight: 700;
}
.app-footer-tag i { font-size: 0.66rem; }
.app-footer-activity { font-weight: 600; color: var(--navy-700); letter-spacing: 0.2px; }
.app-footer-sep { color: #cbd5e1; }
@media (max-width: 1024px) {
  .app-footer { margin: 4px 16px 0; padding: 16px 4px 20px; }
}
@media (max-width: 640px) {
  .app-footer-org { display: block; }        /* ชื่อหน่วยงานยาว ตัด 2 บรรทัด — ให้ไอคอนไหลอยู่หน้าข้อความ ไม่ลอยค้างกลาง */
  .app-footer-org i { margin-right: 6px; }
  .app-footer-sep { display: none; }          /* จอแคบ: โครงการกับกิจกรรมขึ้นคนละบรรทัด ไม่ต้องมีจุดคั่น */
  .app-footer-tag { white-space: normal; text-align: center; }
}
/* แถบสถิติท้ายหน้า (ผู้ดูแลเขตเท่านั้น) — เม็ดยาเล็กขอบบาง ไม่แย่งสายตา */
.app-footer-stats { margin-top: 10px; }
.app-footer-stats a {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 6px;
  padding: 3px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.76rem;
  color: var(--navy-800);
  text-decoration: none;
  background: #fff;
}
.app-footer-stats a:hover, .app-footer-stats a:focus-visible { border-color: var(--gold); }
.app-footer-stats b { font-weight: 700; font-variant-numeric: tabular-nums; }
.app-footer-stats .afs-dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; }
.app-footer-stats .afs-go { color: var(--gold-dark); font-weight: 600; }
@media (max-width: 640px) { .app-footer-stats .afs-go { display: none; } }
body.tv-presentation-mode .app-footer { display: none !important; }
@media print { .app-footer { display: none !important; } }

/* พิมพ์จากหน้าจอในระบบ (เช่น "พิมพ์ใบสรุปคะแนนห้อง" ที่เรียก window.print())
   ให้ได้แค่เนื้อหา — ไม่ติดเมนูซ้ายพื้นกรมท่า แถบบน ปุ่มกลับขึ้นบนสุด หรือแถบเมนูมือถือ */
@media print {
  body { display: block; background: #fff; }
  .sidebar, .topbar, .mobile-nav, #backToTopBtn { display: none !important; }
  .main-wrapper { min-height: 0; }
  .content-area { padding: 0; }
}

/* =====================================================================
   2. CARDS & PANELS
   ===================================================================== */
.card, .panel, .box, .dash-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: 0 2px 12px rgba(20,20,58,0.04);
}
.card h2, .card h3 {
  margin: 0 0 12px;
  color: var(--navy-900);
  font-weight: 700;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* =====================================================================
   3. STAT GRID & METRIC CARDS
   ===================================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.stat-card {
  background: #ffffff;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
  transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(20,20,58,0.08);
}
.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}
.stat-icon.blue { background: #e0e7ff; color: #4338ca; }
.stat-icon.green { background: #dcfce7; color: #15803d; }
.stat-icon.gold { background: #fef3c7; color: #b45309; }
.stat-icon.purple { background: #f3e8ff; color: #7e22ce; }

.stat-val { font-size: 1.65rem; font-weight: 800; color: var(--navy-900); line-height: 1.1; }
.stat-lbl { font-size: 0.8rem; color: var(--muted); font-weight: 600; margin-top: 2px; }

/* =====================================================================
   4. FORM CONTROLS, PICKERS & INPUTS
   ===================================================================== */
.picker, .reg-form, .form-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}
.reg-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  width: 100%;
}
.pick-field, .field, .form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.pick-field label, .field label, .form-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--navy-800);
}
input[type=text],
input[type=number],
input[type=password],
input[type=date],
input[type=datetime-local],
input[type=email],
input[type=url],
select,
textarea {
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  background: #ffffff;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
  background: #ffffff;
}
input[type=checkbox] {
  width: 17px;
  height: 17px;
  accent-color: var(--blue);
  cursor: pointer;
}

/* =====================================================================
   5. TABLES & DATA GRIDS
   ===================================================================== */
table, .table, .data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  font-size: 0.88rem;
  background: #ffffff;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
}
table th, .table th, .data-table th {
  background: #f8fafc;
  color: var(--navy-800);
  font-weight: 700;
  padding: 11px 14px;
  border-bottom: 2px solid var(--line);
  text-align: left;
}
table td, .table td, .data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table tr:hover td, .data-table tr:hover td {
  background: #fbfbfe;
}
table tr:last-child td {
  border-bottom: none;
}

/* =====================================================================
   6. BUTTONS & ACTIONS
   ===================================================================== */
.btn, .btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  font-family: inherit;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}
.btn-primary, .btn.btn-primary {
  background: var(--blue);
  color: #ffffff !important;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}
.btn-primary:hover {
  background: #4338ca;
  color: #ffffff;
}
.btn-gold, .btn.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: #ffffff !important;
  box-shadow: 0 2px 8px rgba(199, 154, 62, 0.3);
}
.btn-gold:hover {
  filter: brightness(1.08);
}
.btn-ghost, .btn.btn-ghost {
  background: #f8fafc;
  color: var(--navy-800) !important;
  border: 1px solid #cbd5e1;
}
.btn-ghost:hover {
  background: #f1f5f9;
  border-color: var(--navy-700);
}
.btn-danger, .btn.btn-danger {
  background: #fee2e2;
  color: #b91c1c !important;
  border: 1px solid #fecaca;
}
.btn-danger:hover {
  background: #fecaca;
}

/* =====================================================================
   7. BADGES & PILLS
   ===================================================================== */
.badge, .badge-status, .diff-pill {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  line-height: 1;
}
.badge-admin, .badge-status.admin { background: #fef3c7; color: #92400e; }
.badge-staff, .badge-status.staff { background: #e0e7ff; color: #4338ca; }
.badge-teacher, .badge-status.open { background: #dcfce7; color: #15803d; }
.badge-status.closed, .badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-status.ghost { background: #f1f5f9; color: #475569; }

/* Premium iOS Switch Toggle (Zero Overflow, Crisp Alignment) */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
  margin: 0;
  cursor: pointer;
}
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #cbd5e1;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 26px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.12);
}
.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: #ffffff;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0,0,0,0.22);
}
input:checked + .slider { background-color: #10b981 !important; }
input:checked + .slider:before { transform: translateX(20px); }

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-bottom: 20px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }

/* =====================================================================
   8. SCORE ENTRY 2-COLUMN QUESTION GRID & LIVE GAUGES
   ===================================================================== */
.question-card {
  background: #ffffff;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: all 0.15s;
}
.question-card:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.q-chip {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--navy-800);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.q-info { flex-grow: 1; }
.q-label { font-size: 0.9rem; font-weight: 600; color: var(--ink); }
.q-input-wrap { position: relative; width: 110px; }
.q-input {
  width: 100%;
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
  color: var(--navy-900);
  padding: 8px 10px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}
.q-pct-sub { font-size: 0.72rem; color: var(--muted); text-align: right; margin-top: 2px; }

.live-gauge-card {
  background: linear-gradient(135deg, #f0fdf4, #eafaf1);
  border: 1px solid #bbf7d0;
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.takers-box {
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.quick-tools-bar {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

/* =====================================================================
   LUXURY ACTION BUTTONS & ICONS (Modern SaaS Action Pills)
   ===================================================================== */
.btn-excel {
  background: linear-gradient(135deg, #10b981, #059669) !important;
  color: #ffffff !important;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 6px rgba(16,185,129,0.25);
  text-decoration: none !important;
  border: none;
  transition: all 0.15s ease-in-out;
}
.btn-excel:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(16,185,129,0.35);
}

.btn-csv {
  background: linear-gradient(135deg, #6366f1, #4f46e5) !important;
  color: #ffffff !important;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 6px rgba(79,70,229,0.25);
  text-decoration: none !important;
  border: none;
  transition: all 0.15s ease-in-out;
}
.btn-csv:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(79,70,229,0.35);
}

.btn-edit {
  background: #fef3c7 !important;
  color: #92400e !important;
  border: 1px solid #fde68a !important;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none !important;
  transition: all 0.15s ease-in-out;
}
.btn-edit:hover {
  background: #fde68a !important;
  color: #78350f !important;
  transform: translateY(-1px);
}

.btn-view {
  background: #e0e7ff !important;
  color: #3730a3 !important;
  border: 1px solid #c7d2fe !important;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none !important;
  transition: all 0.15s ease-in-out;
}
.btn-view:hover {
  background: #c7d2fe !important;
  color: #312e81 !important;
  transform: translateY(-1px);
}

.btn-toggle {
  background: #f1f5f9 !important;
  color: #1e293b !important;
  border: 1px solid #cbd5e1 !important;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
}
.btn-toggle:hover {
  background: #e2e8f0 !important;
}

.btn-del {
  background: #fee2e2 !important;
  color: #b91c1c !important;
  border: 1px solid #fecaca !important;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
}
.btn-del:hover {
  background: #fecaca !important;
  color: #991b1b !important;
}

/* Backward compatibility for qgrid and icon-btn */
.qgrid {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  font-size: 0.88rem;
  background: #ffffff;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.qgrid th {
  background: #f8fafc;
  color: var(--navy-800);
  font-weight: 700;
  padding: 11px 14px;
  border-bottom: 2px solid var(--line);
  text-align: left;
}
.qgrid td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.qgrid tr:hover td {
  background: #fbfbfe;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  background: #f1f5f9;
  color: var(--navy-800) !important;
  border: 1px solid #cbd5e1;
  text-decoration: none !important;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
}
.icon-btn:hover {
  background: #e2e8f0;
  border-color: var(--navy-700);
}

/* =====================================================================
   RESPONSIVE DESIGN & MOBILE / IPAD OPTIMIZATIONS (Apple HIG & Android)
   ===================================================================== */

/* Tablet & iPad Breakpoint (1024px and below) */
@media (max-width: 1024px) {
  body {
    flex-direction: column;
    align-items: stretch;
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
  }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;   /* แท็บเล็ต: เมนูเป็นแถบบนสุด เลื่อนหายไปพร้อมหน้าเหมือนเดิม */
    min-height: 0;
    border-right: none;
    border-bottom: 1px solid rgba(199, 154, 62, 0.25);
  }
  .sidebar-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 10px 14px;
    max-height: 140px;
    overflow-x: auto;
  }
  .nav-group-title {
    display: none;
  }
  .nav-item {
    padding: 6px 10px;
    font-size: 0.8rem;
    white-space: nowrap;
  }
  .main-wrapper {
    flex: 1;
    overflow: visible;
    min-height: 0;
  }
  .topbar {
    position: static;   /* แถบบนตัดบรรทัดได้หลายแถวบนแท็บเล็ต — ไม่ตรึงไว้ ไม่งั้นบังเนื้อหา */
    padding: 0 16px;
    height: auto;
    min-height: 56px;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 8px;
    padding-bottom: 8px;
  }
  .topbar-left, .topbar-right {
    flex-wrap: wrap;
    gap: 8px;
  }
  .content-area {
    padding: 16px;
    overflow: visible;
  }
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Mobile Phones (768px and below) */
@media (max-width: 768px) {
  .sidebar {
    display: none; /* Hidden on mobile, use bottom bar or top menu */
  }
  .topbar {
    padding: 10px 14px;
  }
  .topbar-title {
    font-size: 1.05rem;
  }
  .btn-tv-mode {
    display: none; /* TV presentation mode not needed on small mobile */
  }
  .stat-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .stat-card {
    padding: 14px 16px;
  }
  .card, .panel, .box {
    padding: 14px 16px;
    border-radius: 10px;
  }
  
  /* Tables horizontally scrollable on small screens */
  .data-table, table, .qgrid {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Form Inputs iOS Friendly (Min 16px font to prevent Safari auto-zoom) */
  input[type=text],
  input[type=number],
  input[type=password],
  input[type=date],
  input[type=datetime-local],
  select,
  textarea {
    font-size: 16px !important;
    padding: 10px 12px;
  }
  
  /* Mobile Action Buttons */
  .btn, .btn-action {
    padding: 8px 12px;
    min-height: 40px; /* Touch friendly */
  }
  
  /* Mobile Bottom Navigation Bar */
  .mobile-nav {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--navy-950);
    border-top: 1px solid rgba(199,154,62,0.3);
    z-index: 9999;
    align-items: center;
    justify-content: space-around;
    padding: 0 4px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.25);
  }
  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.72rem;
    font-weight: 600;
    gap: 3px;
    flex: 1;
    height: 100%;
    transition: all 0.15s;
  }
  .mobile-nav-item i {
    font-size: 1.15rem;
  }
  .mobile-nav-item.active, .mobile-nav-item:hover {
    color: var(--gold);
  }
  
  body {
    padding-bottom: 70px; /* Leave space for bottom nav */
  }
}

/* Mobile Nav Hidden on Desktop by default */
.mobile-nav {
  display: none;
}


/* =====================================================================
   TV PRESENTATION MODE (โหมดจอทีวีห้องประชุมผู้บริหาร)
   ===================================================================== */
body.tv-presentation-mode {
  background: #0b1329 !important;
  color: #ffffff !important;
}
body.tv-presentation-mode .sidebar,
body.tv-presentation-mode .topbar,
body.tv-presentation-mode .mobile-nav {
  display: none !important;
}
body.tv-presentation-mode .main-wrapper {
  width: 100% !important;        /* 100vw รวมความกว้างแถบเลื่อนของหน้า → จะล้นแนวนอน */
  min-height: 100vh !important;  /* หน้าเลื่อนด้วยแถบเลื่อนของเบราว์เซอร์แล้ว ไม่ล็อกความสูง */
}
body.tv-presentation-mode .content-area {
  padding: 30px 40px !important;
  max-width: 100% !important;
}
body.tv-presentation-mode .stat-card {
  padding: 22px 26px !important;
  background: #ffffff !important;
  color: var(--ink) !important;
}
body.tv-presentation-mode .stat-val {
  font-size: 2.2rem !important;
}
.tv-floating-exit-btn {
  position: fixed;
  top: 18px;
  right: 24px;
  background: rgba(225, 29, 72, 0.95);
  color: #ffffff !important;
  font-weight: 700;
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 0.9rem;
  border: 1.5px solid #ffffff;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  cursor: pointer;
  z-index: 99999;
  display: none;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(8px);
  transition: transform 0.15s;
}
.tv-floating-exit-btn:hover {
  transform: scale(1.05);
  background: #e11d48;
}
body.tv-presentation-mode .tv-floating-exit-btn {
  display: flex !important;
}


/* =====================================================================
   TV WAR ROOM SUITE (ศูนย์บัญชาการจอทีวีห้องประชุม ผอ.เขต - เฉพาะ Admin)
   ===================================================================== */
body.tv-presentation-mode {
  background: #070d1e !important;
  color: #ffffff !important;
}
body.tv-presentation-mode .sidebar,
body.tv-presentation-mode .topbar,
body.tv-presentation-mode .mobile-nav {
  display: none !important;
}
body.tv-presentation-mode .main-wrapper {
  width: 100% !important;        /* 100vw รวมความกว้างแถบเลื่อนของหน้า → จะล้นแนวนอน */
  min-height: 100vh !important;  /* หน้าเลื่อนด้วยแถบเลื่อนของเบราว์เซอร์แล้ว ไม่ล็อกความสูง */
  padding: 0 !important;
}
body.tv-presentation-mode .content-area {
  padding: 85px 36px 85px !important;
  max-width: 100% !important;
}
body.tv-presentation-mode .stat-card {
  padding: 22px 26px !important;
  background: #ffffff !important;
  color: var(--ink) !important;
}
body.tv-presentation-mode .stat-val {
  font-size: 2.2rem !important;
}

/* TV Overlay & Header */
.tv-war-room-overlay {
  display: none;
}
body.tv-presentation-mode .tv-war-room-overlay {
  display: block;
}
.tv-live-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: rgba(7, 13, 30, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(199, 154, 62, 0.35);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 32px;
  z-index: 99998;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.tv-live-badge {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid #ef4444;
  color: #fca5a5;
  font-weight: 800;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 0.5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tv-clock-badge {
  font-family: monospace;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--gold, #C79A3E);
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(199, 154, 62, 0.3);
  padding: 4px 14px;
  border-radius: 8px;
  letter-spacing: 1px;
}
.tv-exit-btn {
  background: rgba(225, 29, 72, 0.95);
  color: #ffffff !important;
  font-weight: 700;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 0.85rem;
  border: 1px solid #ffffff;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  transition: transform 0.15s;
}
.tv-exit-btn:hover {
  transform: scale(1.05);
  background: #e11d48;
}

/* TV Floating Bottom Smart Remote Bar */
.tv-remote-bar {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(199, 154, 62, 0.4);
  padding: 8px 18px;
  border-radius: 30px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 99999;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
.tv-remote-btn {
  background: rgba(255,255,255,0.1);
  color: #ffffff !important;
  border: 1px solid rgba(255,255,255,0.2);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tv-remote-btn:hover {
  background: rgba(199, 154, 62, 0.3);
  border-color: var(--gold);
}
.tv-play-btn {
  background: linear-gradient(135deg, var(--gold, #C79A3E), var(--gold-dark, #9E7422));
  border-color: var(--gold);
}
.tv-slide-indicator {
  font-size: 0.82rem;
  font-weight: 700;
  color: #cbd5e1;
  padding: 0 6px;
}
@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}
.fade-in {
  animation: fadeIn 0.4s ease-in-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}


/* =====================================================================
   PAGINATION STYLES (Royal Navy & Gold Theme)
   ===================================================================== */
.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: 6px;
  background: #ffffff;
  border: 1px solid var(--line, #e2e8f0);
  color: var(--navy-900, #14143a);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  transition: all 0.15s ease;
  cursor: pointer;
}
.page-btn:hover:not(.disabled):not(.active) {
  background: #f1f5f9;
  border-color: var(--gold, #C79A3E);
  color: var(--gold-dark, #9E7422);
}
.page-btn.active {
  background: var(--navy-900, #14143a);
  border-color: var(--navy-900, #14143a);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(20, 20, 58, 0.2);
}
.page-btn.disabled {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #cbd5e1;
  cursor: not-allowed;
}
.page-dots {
  padding: 0 4px;
  color: #94a3b8;
  font-weight: 700;
  font-size: 0.85rem;
}


/* =====================================================================
   EXECUTIVE TACTILE & MICRO-INTERACTION EFFECTS (Subtle Luxury)
   ===================================================================== */

/* 1. Buttons & Clickable Elements */
.btn, .btn-action, .page-btn, button[type=submit], .nav-item, .sb-item {
  position: relative;
  overflow: hidden;
  transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1),
              background-color 0.2s ease,
              border-color 0.2s ease,
              color 0.2s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover, .btn-action:hover, .page-btn:hover:not(.disabled) {
  transform: translateY(-1.5px);
  box-shadow: 0 4px 14px rgba(20, 20, 58, 0.12);
}

.btn:active, .btn-action:active, .page-btn:active:not(.disabled), button[type=submit]:active {
  transform: scale(0.975) translateY(1px);
  box-shadow: 0 1px 3px rgba(20, 20, 58, 0.15) !important;
}

.btn-gold:hover {
  box-shadow: 0 6px 18px rgba(199, 154, 62, 0.35) !important;
  filter: brightness(1.05);
}

.btn-primary:hover {
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.3) !important;
}

.btn-excel:hover {
  box-shadow: 0 6px 18px rgba(32, 150, 99, 0.3) !important;
}

/* 2. Tactile Click Ripple Effect */
.click-ripple {
  position: absolute;
  border-radius: 50%;
  transform: scale(0);
  animation: rippleAnimation 0.45s cubic-bezier(0.25, 1, 0.5, 1) forwards;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.35);
}

.btn-ghost .click-ripple, .page-btn .click-ripple {
  background: rgba(199, 154, 62, 0.25);
}

@keyframes rippleAnimation {
  0% {
    transform: scale(0);
    opacity: 0.6;
  }
  100% {
    transform: scale(3.5);
    opacity: 0;
  }
}

/* 3. Inputs & Form Fields Focus Aura */
input[type=text],
input[type=number],
input[type=password],
input[type=date],
input[type=datetime-local],
input[type=email],
input[type=url],
select,
textarea {
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease, background-color 0.2s ease;
}

input[type=text]:focus,
input[type=number]:focus,
input[type=password]:focus,
input[type=date]:focus,
input[type=datetime-local]:focus,
input[type=email]:focus,
input[type=url]:focus,
select:focus,
textarea:focus {
  border-color: var(--gold, #C79A3E) !important;
  box-shadow: 0 0 0 3.5px rgba(199, 154, 62, 0.18) !important;
  transform: translateY(-0.5px);
  background-color: #ffffff !important;
}

/* 4. Cards & KPI Lift on Hover */
.card, .stat-card {
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

.stat-card:hover {
  transform: translateY(-2.5px);
  box-shadow: 0 8px 24px rgba(20, 20, 58, 0.08);
}

/* 5. Navigation Items Hover Glow */
.nav-item, .sb-item {
  transition: transform 0.15s ease, background-color 0.18s ease, color 0.18s ease;
}

.nav-item:hover, .sb-item:hover {
  transform: translateX(3px);
  background: rgba(255, 255, 255, 0.09);
}

.nav-item.active, .sb-item.active {
  transform: none;
}

/* 6. Table Rows Hover Lighting */
.data-table tbody tr {
  transition: background-color 0.15s ease;
}

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

/* 7. Status Badges Micro-Bounce */
.badge {
  transition: transform 0.15s ease, filter 0.15s ease;
  display: inline-flex;
  align-items: center;
}

.badge:hover {
  transform: scale(1.04);
}

/* 8. Alert & Notification Gentle Slide-in */
.alert, .note, .card-hero {
  animation: subtleEntrance 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes subtleEntrance {
  0% {
    opacity: 0;
    transform: translateY(-5px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}


/* =====================================================================
   CURATED 3-IN-1 EXECUTIVE SUITE (Top Loader, Back-to-Top, Smooth Numbers)
   ===================================================================== */

/* 1. Slim Gold Top-Bar Progress Bar */
#top-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--gold, #C79A3E) 0%, #fef08a 50%, var(--gold-dark, #9E7422) 100%);
  box-shadow: 0 0 10px rgba(199, 154, 62, 0.7);
  z-index: 999999;
  transition: width 0.3s cubic-bezier(0.1, 0.8, 0.2, 1), opacity 0.4s ease;
  pointer-events: none;
  opacity: 0;
}

/* 2. Floating Back-to-Top Button */
#backToTopBtn {
  position: fixed;
  bottom: 26px;
  right: 28px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--navy-900, #14143a), var(--navy-800, #20204F));
  color: var(--gold, #C79A3E);
  border: 1.5px solid var(--gold, #C79A3E);
  box-shadow: 0 4px 16px rgba(20, 20, 58, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.9);
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#backToTopBtn.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

#backToTopBtn:hover {
  background: linear-gradient(135deg, var(--gold, #C79A3E), var(--gold-dark, #9E7422));
  color: #ffffff;
  border-color: #ffffff;
  box-shadow: 0 6px 20px rgba(199, 154, 62, 0.4);
  transform: translateY(-3px) scale(1.05);
}

#backToTopBtn:active {
  transform: translateY(1px) scale(0.95);
}

/* ==========================================================================
   SAFE 60FPS UI RENDERING & CRISP LAYOUT ENHANCEMENTS
   ========================================================================== */
.btn, .sidebar, .switch, .slider {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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


/* ==========================================================================
   TOOLTIP กลาง — ชี้/แตะ/โฟกัส ที่ [data-tip] แล้วมีกล่องข้อมูลขึ้น
   --------------------------------------------------------------------------
   ใช้แทน <title> ของ SVG ซึ่งรอ ~1 วินาที แสดงได้บรรทัดเดียว และจัดสไตล์ไม่ได้
   กล่องเดียวใช้ร่วมทั้งหน้า (app.js สร้างให้ตอนโหลด) จึงไม่เพิ่ม DOM ตามจำนวนแท่ง
   ========================================================================== */
[data-tip] { cursor: pointer; }
svg [data-tip] { transition: opacity .12s ease; }
svg [data-tip]:hover, svg [data-tip]:focus { opacity: .82; outline: none; }

#tipLayer {
  position: fixed;
  left: -9999px;
  top: -9999px;
  z-index: 100000;
  pointer-events: none;          /* ไม่ให้กล่องบังการชี้แท่งถัดไป */
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .12s ease, transform .12s ease;
  max-width: 300px;
}
#tipLayer.on { opacity: 1; transform: translateY(0); }

#tipLayer .tip {
  position: relative;
  background: var(--navy-900, #14143a);
  color: #ffffff;
  border-radius: 9px;
  border-left: 3px solid var(--gold, #C79A3E);
  padding: 9px 12px;
  box-shadow: 0 8px 26px rgba(10, 10, 40, 0.34);
  font-size: 0.78rem;
  line-height: 1.55;
}
#tipLayer .tip b {
  display: block;
  color: var(--gold, #C79A3E);
  font-size: 0.8rem;
  font-weight: 800;
  margin-bottom: 4px;
}
#tipLayer .tip .r { display: flex; justify-content: space-between; gap: 14px; white-space: nowrap; }
#tipLayer .tip .r span:last-child { font-weight: 700; font-variant-numeric: tabular-nums; }
#tipLayer .tip .n {
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  color: #b9c0d8;
  font-size: 0.72rem;
  white-space: normal;
}
#tipLayer .tip .ar {
  position: absolute;
  width: 9px; height: 9px;
  background: var(--navy-900, #14143a);
  transform: rotate(45deg);
}

@media print { #tipLayer { display: none !important; } }

/* ==========================================================================
   หน้ากรอกคะแนน (/entry) — จัด 2 คอลัมน์ + แผงสรุปด้านขวา
   --------------------------------------------------------------------------
   ของเดิมใช้ repeat(auto-fill, minmax(130px,1fr)) กับช่องกรอกรายข้อ
   ซึ่ง "จองช่องไว้เต็มความกว้างเสมอ" — จอ 1400px ได้ ~10 ช่อง แต่ข้อสอบมี 5 ข้อ
   อีก 5 ช่องจึงว่างค้างทางขวา ดูเหมือนหน้าจอเอียงไปทางซ้าย
   แก้เป็นแทร็กความกว้างคงที่ + ชิดซ้าย แล้วเอาที่ว่างไปทำแผงสรุปแทน
   ========================================================================== */
.entry-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 1100px) {
  .entry-split { grid-template-columns: 1fr; }
}

/* ---- ช่องกรอกรายข้อ ---- */
.q-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, 116px);  /* กว้างคงที่ ไม่ยืดจนเทอะทะเมื่อข้อน้อย */
  justify-content: start;
  gap: 12px;
}
.q-cell {
  background: var(--surface-2, #f8fafc);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.q-cell span { font-weight: 800; font-size: 0.85rem; color: var(--navy-900); }
.q-cell .correct-input {
  width: 80px;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 800;
  padding: 6px;
  border-radius: 8px;
  border: 1.5px solid #cbd5e1;
  font-family: inherit;
}

/* ---- กล่องตัวอย่างการกรอก (พับได้) ---- */
.entry-example {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  border-radius: 9px;
  max-width: 460px;
  font-size: 0.83rem;
  color: #1e3a5f;
}
.entry-example > summary {
  cursor: pointer;
  padding: 8px 12px;
  font-weight: 700;
  list-style: none;
  user-select: none;
}
.entry-example > summary::-webkit-details-marker { display: none; }
.entry-example > summary::after { content: ' ▾'; color: #64748b; }
.entry-example[open] > summary::after { content: ' ▴'; }
.entry-example .body { padding: 0 14px 11px; line-height: 1.8; }
.entry-example ul { margin: 6px 0; padding-left: 20px; }

/* ---- แผงสรุปด้านขวา ---- */
.entry-side {
  background: var(--surface-2, #f8fafc);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}
.entry-side h4 {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--navy-900);
  border-bottom: 1px solid var(--line);
  padding-bottom: 7px;
}
.entry-side .kv {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  padding: 4px 0;
  border-bottom: 1px dashed var(--line);
}
.entry-side .kv b { font-variant-numeric: tabular-nums; }
.entry-side .side-empty { font-size: 0.76rem; color: var(--muted); padding: 6px 0; }
.entry-side .qrow { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; font-size: 0.76rem; }
.entry-side .qrow .lbl { width: 40px; color: var(--muted); }
.entry-side .qrow .trk { flex: 1; height: 12px; background: #e2e8f0; border-radius: 6px; overflow: hidden; }
.entry-side .qrow .trk i { display: block; height: 100%; }
.entry-side .qrow .val { width: 44px; text-align: right; font-weight: 800; }

/* ---- ความคืบหน้ารายส่วน (1 ส่วน = 1 ชั้น × 1 ด้าน) ---- */
.entry-progress {
  margin-top: 12px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 9px;
  padding: 10px;
  font-size: 0.78rem;
  line-height: 1.6;
}
.entry-progress .cap { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }
.p-tbl { width: 100%; border-collapse: separate; border-spacing: 3px; margin-top: 8px; }
.p-tbl th { font-size: 0.7rem; color: var(--muted); font-weight: 700; padding: 0 0 2px; text-align: center; }
.p-tbl td { padding: 0; }
.p-tbl td:first-child { font-size: 0.73rem; color: var(--navy-900); font-weight: 800; padding-right: 4px; text-align: right; width: 34px; }
.p-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  border: 1.5px solid var(--line);
  background: var(--surface, #fff);
  color: #cbd5e1;
  text-decoration: none;
}
.p-cell:hover { border-color: var(--gold); }
.p-cell.done { background: #dcfce7; border-color: #86efac; color: #15803d; }
.p-cell.now  { background: var(--navy-900); border-color: var(--navy-900); color: #fff; }
.p-next { width: 100%; justify-content: center; margin-top: 9px; font-size: 0.78rem; padding: 7px 10px; }
.p-done { margin-top: 9px; color: #15803d; font-weight: 700; text-align: center; }

/* ---- ลำดับการกรอก: ① จำนวนคน → ② คะแนนรายข้อ ----
   ② จะจางไว้จนกว่าจะกรอก ① เสร็จ · ① เปลี่ยนเป็น ✓ เมื่อกรอกแล้ว
   (สถานะสลับด้วย paintSteps() ใน app.js) */
.stepno {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--navy-900);
  color: #ffffff;
  font-size: 0.74rem;
  font-weight: 800;
  margin-right: 7px;
  vertical-align: -4px;
  transition: background .15s ease;
}
.stepno.wait { background: #cbd5e1; color: #64748b; }
.stepno.ok   { background: var(--ok); }

.step-hint { font-size: 0.78rem; color: #b45309; font-weight: 700; margin-top: 5px; }
.step-hint.hide { display: none; }

@media print { .entry-side, .entry-example, .step-hint { display: none !important; } }

/* ปุ่มรูปตา แสดง/ซ่อนรหัสผ่าน (app.js ใส่ให้ทุกช่อง input[type=password]) */
.pw-wrap { position: relative; display: block; width: 100%; }
.pw-wrap > input { width: 100%; padding-right: 44px !important; }
.pw-eye {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  width: 36px; height: 36px; padding: 0; margin: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: 6px;
  color: var(--muted, #64748b); cursor: pointer; box-shadow: none;
}
.pw-eye:hover { color: var(--navy-900, #14143a); background: rgba(100, 116, 139, 0.12); }
.pw-eye:focus-visible { outline: 2px solid var(--gold, #c79a3e); outline-offset: 1px; }
.pw-eye[aria-pressed="true"] { color: var(--gold-dark, #a67c2a); }
@media print { .pw-eye { display: none !important; } }

/* หน้าตั้งรหัสผ่านใหม่: รายการตรวจรหัสแบบสด (กติกาเดียวกับ App\Core\PasswordPolicy) */
.pw-rules { list-style: none; margin: 8px 0 0; padding: 0; font-size: 0.82rem; line-height: 1.75; color: var(--muted, #64748b); }
.pw-rules li::before { content: "○"; display: inline-block; width: 1.3em; font-weight: 700; }
.pw-rules li.ok { color: #15803d; }
.pw-rules li.ok::before { content: "✓"; }
.pw-rules li.bad { color: #b91c1c; }
.pw-rules li.bad::before { content: "✗"; }
.pw-tip { margin-top: 6px; font-size: 0.78rem; color: var(--muted, #64748b); line-height: 1.6; }
.pw-tip code { background: rgba(100, 116, 139, 0.12); padding: 1px 5px; border-radius: 4px; font-size: 0.78rem; }

/* ============================================================================
   กระดิ่งแจ้งเตือนบนแถบบน (assets/js/bell.js) — แผงรายการ · เสียง · เคลื่อนไหวเมื่อมีเรื่องใหม่
   สีบอกระดับ: เทา+✓ = ไม่มีเรื่อง · ฟ้า = ข่าว · เหลือง = ต้องตัดสินใจ · แดง = ด่วน
   ไม่มี JS = ยังเป็นลิงก์ธรรมดา (a.bell-btn) · ผู้ใช้ตั้ง "ลดการเคลื่อนไหว" = ไม่มีแอนิเมชัน
   ============================================================================ */
.bellwrap { position: relative; display: inline-flex; }
.bell-btn {
  position: relative; width: 42px; height: 36px; border-radius: 8px; border: 1px solid var(--line, #e2e6ee);
  background: #f8fafc; color: var(--navy-900, #14143a); display: inline-flex; align-items: center; justify-content: center;
  font-size: 1rem; text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s;
}
.bell-btn:hover { border-color: var(--gold, #c79a3e); }
.bell-btn:focus-visible, .bell-panel button:focus-visible, .bell-panel a:focus-visible, .bell-toast button:focus-visible { outline: 2px solid var(--gold, #c79a3e); outline-offset: 2px; }
.bell-btn .fa-bell { transform-origin: 50% 8%; }
.bell-btn.lv-none { color: #64748b; }
.bell-btn.lv-info { background: #eff6ff; border-color: #bfdbfe; color: #2563eb; }
.bell-btn.lv-warn { background: #fffbeb; border-color: #fde68a; color: #d97706; }
.bell-btn.lv-high { background: #fef2f2; border-color: #fecaca; color: #dc2626; }
.bell-badge {
  position: absolute; top: -7px; right: -7px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px;
  background: #dc2626; color: #fff; font-size: .7rem; font-weight: 800; line-height: 1; display: inline-flex; align-items: center; justify-content: center; border: 2px solid #fff;
}
.bell-btn.lv-warn .bell-badge { background: #d97706; }
.bell-btn.lv-info .bell-badge { background: #2563eb; }
.bell-badge[hidden], .bell-tick[hidden], .bell-snd[hidden], .bell-panel[hidden] { display: none !important; }
.bell-tick { position: absolute; right: -5px; bottom: -5px; width: 16px; height: 16px; border-radius: 50%; background: #15803d; color: #fff; font-size: .6rem; display: grid; place-items: center; border: 2px solid #fff; }
.bell-snd { position: absolute; left: -5px; bottom: -5px; width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 1px solid var(--line, #e2e6ee); font-size: .55rem; display: grid; place-items: center; }
@media (prefers-reduced-motion: no-preference) {
  .bell-btn.ring .fa-bell { animation: bellSwing 1.1s ease-in-out; }
  .bell-btn.attn::after { content: ""; position: absolute; inset: -1px; border-radius: 8px; border: 2px solid #dc2626; animation: bellRipple 2.2s ease-out infinite; pointer-events: none; }
  .bell-btn.attn.lv-warn::after { border-color: #d97706; }
  .bell-btn.attn.lv-info::after { border-color: #2563eb; }
  .bell-badge.pop { animation: bellPop .5s cubic-bezier(.3, 1.6, .5, 1); }
  .bell-toast { animation: bellSlide .3s ease-out; }
  .bell-panel { animation: bellDrop .16s ease-out; }
}
@keyframes bellSwing { 0% { transform: rotate(0) } 15% { transform: rotate(22deg) } 30% { transform: rotate(-18deg) } 45% { transform: rotate(13deg) } 60% { transform: rotate(-9deg) } 75% { transform: rotate(5deg) } 100% { transform: rotate(0) } }
@keyframes bellRipple { 0% { transform: scale(1); opacity: .75 } 100% { transform: scale(1.55, 1.7); opacity: 0 } }
@keyframes bellPop { 0% { transform: scale(.3) } 100% { transform: scale(1) } }
@keyframes bellSlide { from { transform: translateY(-10px); opacity: 0 } to { transform: none; opacity: 1 } }
@keyframes bellDrop { from { transform: translateY(-6px); opacity: 0 } to { transform: none; opacity: 1 } }
.bell-panel {
  position: absolute; right: 0; top: calc(100% + 10px); width: min(392px, 92vw); background: #fff; color: var(--navy-900, #14143a);
  border: 1px solid var(--line, #e2e6ee); border-radius: 14px; box-shadow: 0 14px 40px rgba(20, 20, 58, .22); z-index: 1200; overflow: hidden; text-align: left;
}
.bell-ph { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line, #e2e6ee); background: #f7f8fc; }
.bell-ph strong { font-size: .95rem; display: block; }
.bell-ph small { font-size: .74rem; color: #64748b; }
.bell-gear { border: 1px solid var(--line, #e2e6ee); background: #fff; border-radius: 8px; width: 32px; height: 32px; cursor: pointer; }
.bell-list { max-height: 340px; overflow: auto; }
.bell-it { padding: 11px 14px 11px 40px; border-bottom: 1px solid var(--line, #e2e6ee); position: relative; }
.bell-it:last-child { border-bottom: 0; }
.bell-it .ic { position: absolute; left: 10px; top: 12px; width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; font-size: .72rem; }
.bell-it.hi .ic { background: #fef2f2; color: #dc2626; } .bell-it.wa .ic { background: #fffbeb; color: #d97706; } .bell-it.in .ic { background: #eff6ff; color: #2563eb; }
.bell-it h5 { margin: 0; font-size: .86rem; line-height: 1.45; font-weight: 700; }
.bell-it p { margin: 2px 0 0; font-size: .78rem; color: #475569; line-height: 1.5; }
.bell-it .tag { display: inline-block; font-size: .64rem; font-weight: 700; border-radius: 5px; padding: 0 6px; margin-right: 6px; vertical-align: 1px; }
.bell-it.hi .tag { background: #fef2f2; color: #dc2626; } .bell-it.wa .tag { background: #fffbeb; color: #d97706; } .bell-it.in .tag { background: #eff6ff; color: #2563eb; }
.bell-it .new { position: absolute; left: 3px; top: 19px; width: 7px; height: 7px; border-radius: 50%; background: #2563eb; }
.bell-acts { display: flex; gap: 6px; margin-top: 7px; flex-wrap: wrap; }
.bell-acts a, .bell-acts button { font: inherit; font-size: .76rem; font-weight: 600; border: 1px solid var(--line, #e2e6ee); background: #fff; color: inherit; border-radius: 7px; padding: 3px 10px; cursor: pointer; text-decoration: none; }
.bell-acts a.pri { background: var(--navy-800, #20204f); border-color: var(--navy-800, #20204f); color: #fff; }
.bell-empty { padding: 26px 16px; text-align: center; color: #64748b; font-size: .88rem; display: grid; gap: 4px; }
.bell-empty b { color: #15803d; }
.bell-pf { padding: 10px 14px; border-top: 1px solid var(--line, #e2e6ee); display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .8rem; background: #f7f8fc; }
.bell-pf a { color: #2563eb; font-weight: 700; text-decoration: none; }
.bell-set { padding: 12px 14px; border-bottom: 1px solid var(--line, #e2e6ee); display: grid; gap: 10px; font-size: .84rem; background: #fff; }
.bell-set[hidden] { display: none; }
.bell-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.bell-row small { display: block; color: #64748b; font-size: .74rem; }
.bell-sw { position: relative; width: 42px; height: 24px; border-radius: 999px; border: 0; background: #cbd5e1; cursor: pointer; flex: none; transition: background .15s; }
.bell-sw::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.bell-sw[aria-checked="true"] { background: #15803d; } .bell-sw[aria-checked="true"]::after { transform: translateX(18px); }
.bell-set select { font: inherit; font-size: .8rem; padding: 4px 8px; border: 1px solid var(--line, #e2e6ee); border-radius: 8px; }
.bell-set .try { font: inherit; font-size: .76rem; font-weight: 600; border: 1px solid var(--line, #e2e6ee); background: #fff; border-radius: 7px; padding: 3px 10px; cursor: pointer; }
.bell-toasts { position: fixed; right: 16px; top: 64px; display: grid; gap: 8px; width: min(360px, calc(100vw - 32px)); z-index: 1300; pointer-events: none; }
.bell-toast { pointer-events: auto; background: #fff; border: 1px solid var(--line, #e2e6ee); border-left: 5px solid #dc2626; border-radius: 10px; box-shadow: 0 8px 24px rgba(20, 20, 58, .18); padding: 10px 12px; font-size: .84rem; display: grid; gap: 4px; color: var(--navy-900, #14143a); }
.bell-toast.wa { border-left-color: #d97706; } .bell-toast.in { border-left-color: #2563eb; } .bell-toast.ok { border-left-color: #15803d; }
.bell-toast b { font-size: .86rem; }
.bell-toast .bell-acts { margin-top: 2px; }
@media print { .bellwrap, .bell-toasts { display: none !important; } }
