/* ===================================================================
   ธีมขาว-ทอง (สีประจำโรงเรียนทุ่งกุลาประชานุสรณ์) + โหมดมืด
   ออกแบบ mobile-first — แสดงผลสมบูรณ์บนมือถือก่อน แล้วขยายสู่เดสก์ท็อป
   =================================================================== */
:root{
  --gold:#B8912F; --gold-1:#D4AF57; --gold-2:#8B6D20; --gold-3:#F6EFDC;
  --bg:#F5F3EE; --surface:#FFFFFF; --surface-2:#FBF9F4;
  --text:#23241F; --text-soft:#6B6A63; --line:#E6E1D6;
  --shadow:0 2px 10px rgba(80,64,20,.08); --shadow-lg:0 12px 32px rgba(80,64,20,.14);
  --topbar-h:60px; --side-w:266px; --bottom-h:62px; --radius:14px;
  --ok:#198754; --warn:#E5A50A; --danger:#DC3545; --info:#0D6EFD; --teal:#20A4A0;
  --bs-body-font-family:'Sarabun',system-ui,-apple-system,'Segoe UI',sans-serif;
}
[data-bs-theme="dark"]{
  --gold:#D9B45B; --gold-1:#E7CB84; --gold-2:#B8912F; --gold-3:#2C2719;
  --bg:#131418; --surface:#1C1E24; --surface-2:#22252C;
  --text:#E9E6DE; --text-soft:#9A978E; --line:#31343C;
  --shadow:0 2px 10px rgba(0,0,0,.36); --shadow-lg:0 12px 32px rgba(0,0,0,.5);
}

*{ -webkit-tap-highlight-color:transparent; }
html,body{ overflow-x:hidden; }
body{
  font-family:var(--bs-body-font-family); background:var(--bg); color:var(--text);
  font-size:15px; margin:0; -webkit-font-smoothing:antialiased;
}
h1,h2,h3,h4,h5,h6{ font-weight:600; letter-spacing:-.01em; }
a{ color:var(--gold-2); text-decoration:none; }
a:hover{ color:var(--gold); }
[data-bs-theme="dark"] a{ color:var(--gold-1); }
.text-gold{ color:var(--gold)!important; }
.text-soft{ color:var(--text-soft)!important; }
.bg-gold-soft{ background:var(--gold-3)!important; }

/* ---------- ปุ่ม ---------- */
.btn-gold{
  background:linear-gradient(135deg,var(--gold-1),var(--gold)); border:0; color:#fff; font-weight:600;
  box-shadow:0 2px 8px rgba(184,145,47,.32);
}
.btn-gold:hover,.btn-gold:focus{ background:linear-gradient(135deg,var(--gold),var(--gold-2)); color:#fff; }
.btn-outline-gold{ border:1px solid var(--gold); color:var(--gold); background:transparent; }
.btn-outline-gold:hover{ background:var(--gold); color:#fff; }
.btn-icon{
  width:40px; height:40px; display:inline-flex; align-items:center; justify-content:center;
  border-radius:12px; border:0; background:transparent; color:var(--text); font-size:1.15rem; padding:0;
}
.btn-icon:hover{ background:var(--gold-3); color:var(--gold-2); }
[data-bs-theme="dark"] .btn-icon:hover{ color:var(--gold-1); }

/* ---------- หน้าเข้าสู่ระบบ ---------- */
.login-screen{ min-height:100dvh; display:flex; align-items:center; justify-content:center; padding:20px 16px; position:relative; }
.login-bg{
  position:fixed; inset:0; z-index:0;
  background:
    radial-gradient(1100px 520px at 12% -10%, rgba(212,175,87,.30), transparent 60%),
    radial-gradient(900px 480px at 100% 110%, rgba(184,145,47,.22), transparent 60%),
    var(--bg);
}
.login-card{
  position:relative; z-index:1; width:100%; max-width:440px; background:var(--surface);
  border:1px solid var(--line); border-top:4px solid var(--gold);
  border-radius:20px; padding:32px 26px 26px; box-shadow:var(--shadow-lg);
}
.login-logo{ width:76px; height:76px; }
.login-title{ font-size:1.18rem; font-weight:700; margin:12px 0 4px; color:var(--gold-2); line-height:1.4; }
[data-bs-theme="dark"] .login-title{ color:var(--gold-1); }
.login-sub{ color:var(--text-soft); margin:0; font-size:.92rem; line-height:1.6; }
.login-theme{ position:absolute; top:12px; right:14px; border:0; background:transparent; color:var(--text-soft); }
.demo-box{
  background:var(--surface-2); border:1px dashed var(--line); border-radius:12px; padding:12px 14px;
  max-height:220px; overflow:auto;
}
.demo-box code{ color:var(--gold-2); cursor:pointer; }
[data-bs-theme="dark"] .demo-box code{ color:var(--gold-1); }

/* ---------- แถบบน ---------- */
.topbar{
  position:fixed; top:0; left:0; right:0; height:var(--topbar-h); z-index:1030;
  display:flex; align-items:center; gap:8px; padding:0 10px;
  background:var(--surface); border-bottom:1px solid var(--line); box-shadow:var(--shadow);
}
.brand{ display:flex; align-items:center; gap:9px; min-width:0; flex:1; color:inherit; }
.brand-logo{ width:36px; height:36px; flex:none; }
.brand-text{ display:flex; flex-direction:column; min-width:0; line-height:1.2; }
.brand-text strong{ font-size:.94rem; color:var(--gold-2); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
[data-bs-theme="dark"] .brand-text strong{ color:var(--gold-1); }
.brand-text small{ font-size:.72rem; color:var(--text-soft); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.topbar-right{ display:flex; align-items:center; gap:4px; flex:none; }
.year-select{ align-items:center; gap:6px; color:var(--gold-2); }
.year-select .form-select{ width:auto; min-width:132px; border-color:var(--line); }
.badge-dot{
  position:absolute; top:6px; right:7px; width:9px; height:9px; border-radius:50%;
  background:var(--danger); border:2px solid var(--surface); padding:0;
}
.btn-user{ display:flex; align-items:center; gap:8px; border:0; background:transparent; padding:4px 6px; border-radius:12px; color:var(--text); }
.btn-user:hover{ background:var(--gold-3); }
.avatar{
  width:34px; height:34px; border-radius:50%; flex:none; display:grid; place-items:center;
  background:linear-gradient(135deg,var(--gold-1),var(--gold-2)); color:#fff; font-weight:700; font-size:.95rem;
}
.user-meta{ display:flex; flex-direction:column; line-height:1.15; text-align:left; max-width:170px; }
.user-name{ font-size:.86rem; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.user-role{ font-size:.72rem; color:var(--text-soft); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

/* ---------- การแจ้งเตือน ---------- */
.noti-menu{ width:min(360px,calc(100vw - 20px)); padding:0; border-radius:14px; overflow:hidden; border-color:var(--line); }
.noti-list{ max-height:min(60vh,420px); overflow:auto; }
.noti-item{ display:block; padding:10px 14px; border-bottom:1px solid var(--line); color:inherit; }
.noti-item:hover{ background:var(--surface-2); color:inherit; }
.noti-item.unread{ background:var(--gold-3); }
[data-bs-theme="dark"] .noti-item.unread{ background:var(--surface-2); }
.noti-item .t{ font-size:.87rem; font-weight:600; }
.noti-item .m{ font-size:.8rem; color:var(--text-soft); }

/* ---------- เมนูข้าง ---------- */
.sidebar{
  position:fixed; top:var(--topbar-h); bottom:0; left:0; width:var(--side-w); z-index:1020;
  background:var(--surface); border-right:1px solid var(--line); flex-direction:column;
}
.sidebar-nav{ flex:1; overflow-y:auto; padding:12px 10px 20px; }
.sidebar-offcanvas{ width:min(290px,86vw); background:var(--surface); }
.nav-group-title{
  font-size:.7rem; font-weight:700; letter-spacing:.08em; text-transform:uppercase;
  color:var(--text-soft); padding:16px 12px 6px;
}
.nav-link-item{
  display:flex; align-items:center; gap:10px; padding:10px 12px; border-radius:11px;
  color:var(--text); font-size:.9rem; margin-bottom:2px; position:relative;
}
.nav-link-item i{ font-size:1.05rem; color:var(--text-soft); width:20px; text-align:center; flex:none; }
.nav-link-item span{ flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.nav-link-item:hover{ background:var(--surface-2); color:var(--text); }
.nav-link-item.active{ background:var(--gold-3); color:var(--gold-2); font-weight:600; }
.nav-link-item.active i{ color:var(--gold); }
[data-bs-theme="dark"] .nav-link-item.active{ background:var(--gold-3); color:var(--gold-1); }
.nav-link-item .cnt{
  font-size:.7rem; font-weight:700; background:var(--danger); color:#fff;
  border-radius:20px; padding:1px 7px; flex:none;
}
.sidebar-foot{ border-top:1px solid var(--line); padding:12px; }
.pdca-mini{ display:grid; grid-template-columns:repeat(4,1fr); gap:6px; }
.pdca-mini div{
  text-align:center; border-radius:10px; padding:7px 2px; background:var(--surface-2);
  border:1px solid var(--line); font-size:.68rem; color:var(--text-soft); line-height:1.3;
}
.pdca-mini div b{ display:block; font-size:.95rem; color:var(--gold-2); }
[data-bs-theme="dark"] .pdca-mini div b{ color:var(--gold-1); }

/* ---------- พื้นที่เนื้อหา ---------- */
.content{
  padding:calc(var(--topbar-h) + 14px) 14px calc(var(--bottom-h) + 22px);
  min-height:100dvh;
}
@media (min-width:992px){
  .content{ margin-left:var(--side-w); padding:calc(var(--topbar-h) + 20px) 24px 40px; }
}
.page-head{ display:flex; flex-wrap:wrap; align-items:flex-start; gap:10px; margin-bottom:16px; }
.page-head h1{ font-size:1.22rem; margin:0; font-weight:700; }
.page-head .sub{ font-size:.84rem; color:var(--text-soft); margin-top:2px; }
.page-head .spacer{ flex:1 1 auto; }
@media (min-width:768px){ .page-head h1{ font-size:1.42rem; } }

/* ---------- การ์ด ---------- */
.card-x{
  background:var(--surface); border:1px solid var(--line); border-radius:var(--radius);
  box-shadow:var(--shadow); overflow:hidden;
}
.card-x .card-x-head{
  padding:13px 16px; border-bottom:1px solid var(--line); display:flex; align-items:center; gap:8px;
  font-weight:600; font-size:.95rem; background:var(--surface-2);
}
.card-x .card-x-head i{ color:var(--gold); }
.card-x .card-x-body{ padding:16px; }

.stat-grid{ display:grid; gap:12px; grid-template-columns:repeat(2,minmax(0,1fr)); }
@media (min-width:768px){ .stat-grid{ grid-template-columns:repeat(4,minmax(0,1fr)); } }
.stat{
  background:var(--surface); border:1px solid var(--line); border-left:4px solid var(--gold);
  border-radius:var(--radius); padding:13px 14px; box-shadow:var(--shadow); min-width:0;
}
.stat .lab{ font-size:.76rem; color:var(--text-soft); display:flex; align-items:center; gap:5px; }
.stat .val{ font-size:1.5rem; font-weight:700; line-height:1.25; margin-top:3px; }
.stat .val small{ font-size:.8rem; font-weight:500; color:var(--text-soft); }
.stat .hint{ font-size:.73rem; color:var(--text-soft); margin-top:2px; }
.stat.ok{ border-left-color:var(--ok); } .stat.warn{ border-left-color:var(--warn); }
.stat.danger{ border-left-color:var(--danger); } .stat.info{ border-left-color:var(--info); }
.stat.teal{ border-left-color:var(--teal); }

/* ---------- กราฟ ---------- */
.chart-box{ position:relative; width:100%; height:260px; }
.chart-box.tall{ height:320px; }
.chart-box.short{ height:210px; }
@media (min-width:992px){ .chart-box{ height:300px; } .chart-box.tall{ height:360px; } }

/* ---------- ตาราง ---------- */
.table-wrap{ overflow-x:auto; -webkit-overflow-scrolling:touch; }
.table-x{ width:100%; margin:0; font-size:.88rem; border-collapse:separate; border-spacing:0; }
.table-x th{
  background:var(--surface-2); color:var(--text-soft); font-weight:600; font-size:.78rem;
  text-align:left; padding:10px 12px; border-bottom:1px solid var(--line); white-space:nowrap;
}
.table-x td{ padding:11px 12px; border-bottom:1px solid var(--line); vertical-align:middle; }
.table-x tbody tr:hover{ background:var(--surface-2); }
.table-x tbody tr:last-child td{ border-bottom:0; }
.table-x .nowrap{ white-space:nowrap; }

/* รายการแบบการ์ดสำหรับมือถือ */
.mlist{ display:grid; gap:10px; }
.mcard{
  background:var(--surface); border:1px solid var(--line); border-radius:var(--radius);
  padding:13px 14px; box-shadow:var(--shadow);
}
.mcard .mc-top{ display:flex; gap:8px; align-items:flex-start; }
.mcard .mc-title{ font-weight:600; font-size:.93rem; flex:1; min-width:0; line-height:1.45; }
.mcard .mc-meta{ font-size:.78rem; color:var(--text-soft); margin-top:5px; display:flex; flex-wrap:wrap; gap:4px 12px; }
.mcard .mc-act{ display:flex; gap:6px; margin-top:10px; flex-wrap:wrap; }

/* ---------- ป้ายสถานะ ---------- */
.chip{
  display:inline-flex; align-items:center; gap:4px; font-size:.74rem; font-weight:600;
  padding:3px 10px; border-radius:20px; background:var(--surface-2);
  border:1px solid var(--line); color:var(--text-soft); white-space:nowrap;
}
.chip.gold{ background:var(--gold-3); border-color:var(--gold-1); color:var(--gold-2); }
.chip.ok{ background:rgba(25,135,84,.12); border-color:rgba(25,135,84,.4); color:#0f6e45; }
.chip.warn{ background:rgba(229,165,10,.14); border-color:rgba(229,165,10,.45); color:#9a6e00; }
.chip.danger{ background:rgba(220,53,69,.12); border-color:rgba(220,53,69,.4); color:#b02a37; }
.chip.info{ background:rgba(13,110,253,.10); border-color:rgba(13,110,253,.35); color:#0a58ca; }
.chip.teal{ background:rgba(32,164,160,.12); border-color:rgba(32,164,160,.4); color:#13807d; }
[data-bs-theme="dark"] .chip.ok{ color:#57d69c; } [data-bs-theme="dark"] .chip.warn{ color:#f0c657; }
[data-bs-theme="dark"] .chip.danger{ color:#f28b94; } [data-bs-theme="dark"] .chip.info{ color:#7cb0ff; }
[data-bs-theme="dark"] .chip.teal{ color:#5fd3cf; } [data-bs-theme="dark"] .chip.gold{ color:var(--gold-1); }

.lv{ display:inline-block; font-size:.74rem; font-weight:700; padding:3px 10px; border-radius:20px; color:#fff; white-space:nowrap; }

/* ---------- แถบความก้าวหน้า ---------- */
.bar{ height:7px; background:var(--line); border-radius:20px; overflow:hidden; }
.bar > i{ display:block; height:100%; border-radius:20px; background:linear-gradient(90deg,var(--gold-1),var(--gold)); transition:width .5s; }
.bar.ok > i{ background:linear-gradient(90deg,#3ecf8e,var(--ok)); }
.bar.danger > i{ background:linear-gradient(90deg,#f08a94,var(--danger)); }
.bar.info > i{ background:linear-gradient(90deg,#7cb0ff,var(--info)); }

/* ---------- PDCA / 8 ขั้นตอน ---------- */
.pdca-grid{ display:grid; gap:12px; grid-template-columns:repeat(2,minmax(0,1fr)); }
@media (min-width:992px){ .pdca-grid{ grid-template-columns:repeat(4,minmax(0,1fr)); } }
.pdca-card{
  border-radius:var(--radius); padding:14px; color:#fff; box-shadow:var(--shadow); min-height:118px;
  display:flex; flex-direction:column; justify-content:space-between;
}
.pdca-card.p{ background:linear-gradient(135deg,#5b8def,#3a6fd8); }
.pdca-card.d{ background:linear-gradient(135deg,#f0a84a,#d98216); }
.pdca-card.c{ background:linear-gradient(135deg,#34bdb9,#17908d); }
.pdca-card.a{ background:linear-gradient(135deg,#9b7ee0,#6f4fc4); }
.pdca-card .k{ font-size:2rem; font-weight:800; line-height:1; opacity:.9; }
.pdca-card .n{ font-size:.82rem; opacity:.95; }
.pdca-card .v{ font-size:1.05rem; font-weight:700; }

.step-list{ display:grid; gap:10px; }
.step-item{
  display:flex; gap:12px; align-items:flex-start; background:var(--surface);
  border:1px solid var(--line); border-radius:var(--radius); padding:12px 14px;
}
.step-no{
  width:34px; height:34px; border-radius:11px; flex:none; display:grid; place-items:center;
  font-weight:700; background:var(--gold-3); color:var(--gold-2); font-size:.95rem;
}
.step-item.done .step-no{ background:var(--ok); color:#fff; }
.step-item.in_progress .step-no{ background:var(--warn); color:#fff; }
.step-item.delayed .step-no{ background:var(--danger); color:#fff; }

/* ---------- แถบล่างมือถือ ---------- */
.bottom-nav{
  position:fixed; bottom:0; left:0; right:0; height:var(--bottom-h); z-index:1035;
  display:flex; background:var(--surface); border-top:1px solid var(--line);
  padding-bottom:env(safe-area-inset-bottom);
  box-shadow:0 -2px 14px rgba(80,64,20,.10);
}
.bottom-nav a,.bottom-nav button{
  flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px;
  color:var(--text-soft); font-size:.68rem; border:0; background:transparent; position:relative; padding:0;
}
.bottom-nav i{ font-size:1.2rem; }
.bottom-nav .active{ color:var(--gold); }
.nav-badge{
  position:absolute; top:6px; right:calc(50% - 20px); min-width:17px; height:17px; padding:0 4px;
  border-radius:20px; background:var(--danger); color:#fff; font-size:.63rem; font-style:normal;
  font-weight:700; display:grid; place-items:center;
}

/* ---------- ฟอร์ม ---------- */
.form-label{ font-size:.84rem; font-weight:600; margin-bottom:5px; }
.form-control,.form-select{ background:var(--surface); border-color:var(--line); color:var(--text); border-radius:10px; }
.form-control:focus,.form-select:focus{ border-color:var(--gold-1); box-shadow:0 0 0 .2rem rgba(184,145,47,.2); }
.form-control::placeholder{ color:var(--text-soft); opacity:.7; }
.input-group-text{ background:var(--surface-2); border-color:var(--line); color:var(--text-soft); }
.filter-bar{ display:flex; flex-wrap:wrap; gap:8px; margin-bottom:14px; }
.filter-bar .form-control,.filter-bar .form-select{ min-width:0; }
.filter-bar > *{ flex:1 1 150px; }
.filter-bar > .flex-none{ flex:0 0 auto; }

/* ---------- อื่น ๆ ---------- */
.modal-content{ background:var(--surface); border:1px solid var(--line); border-radius:16px; }
.modal-header,.modal-footer{ border-color:var(--line); }
.dropdown-menu{ background:var(--surface); border-color:var(--line); box-shadow:var(--shadow-lg); }
.dropdown-item{ color:var(--text); }
.dropdown-item:hover{ background:var(--surface-2); color:var(--text); }
.toast-area{ position:fixed; top:calc(var(--topbar-h) + 10px); right:12px; left:12px; z-index:1090; display:grid; gap:8px; pointer-events:none; }
@media (min-width:576px){ .toast-area{ left:auto; width:360px; } }
.toast-x{
  background:var(--surface); border:1px solid var(--line); border-left:4px solid var(--gold);
  border-radius:12px; padding:11px 14px; box-shadow:var(--shadow-lg); font-size:.88rem;
  display:flex; gap:9px; align-items:flex-start; pointer-events:auto; animation:slideIn .25s ease;
}
.toast-x.ok{ border-left-color:var(--ok); } .toast-x.err{ border-left-color:var(--danger); }
.toast-x i{ font-size:1.05rem; margin-top:1px; }
.toast-x.ok i{ color:var(--ok); } .toast-x.err i{ color:var(--danger); } .toast-x i{ color:var(--gold); }
@keyframes slideIn{ from{ opacity:0; transform:translateY(-8px); } to{ opacity:1; transform:none; } }
.page-loader{ position:fixed; inset:0; background:rgba(0,0,0,.18); display:grid; place-items:center; z-index:1080; }
.empty{ text-align:center; padding:44px 18px; color:var(--text-soft); }
.empty i{ font-size:2.6rem; color:var(--line); display:block; margin-bottom:10px; }
.skeleton{ background:linear-gradient(90deg,var(--surface-2),var(--line),var(--surface-2)); background-size:200% 100%;
  animation:sk 1.2s infinite; border-radius:10px; height:14px; }
@keyframes sk{ 0%{background-position:200% 0;} 100%{background-position:-200% 0;} }
.clickable{ cursor:pointer; }
::-webkit-scrollbar{ width:9px; height:9px; }
::-webkit-scrollbar-thumb{ background:var(--line); border-radius:20px; }
::-webkit-scrollbar-thumb:hover{ background:var(--gold-1); }
@media print{ .topbar,.sidebar,.bottom-nav,.no-print{ display:none!important; } .content{ margin:0; padding:0; } }

/* ไฮไลต์ข้อที่ประเมินล่าสุด (หน้ากรรมการประเมิน): แถบทองด้านข้าง + พื้นทองอ่อน + ป้าย "ประเมินล่าสุด" ค้างไว้จนกว่าจะประเมินข้ออื่น */
.mcard.latest-scored{
  border-color:var(--gold); border-left:7px solid var(--gold);
  background:linear-gradient(135deg,var(--gold-3),var(--surface) 70%);
  box-shadow:0 8px 24px rgba(184,145,47,.28);
}
.latest-flag{
  display:inline-flex; align-items:center; gap:6px; margin-bottom:8px;
  padding:3px 11px 3px 9px; border-radius:999px; font-size:.76rem; font-weight:700; color:#fff;
  background:linear-gradient(135deg,var(--gold-1),var(--gold)); box-shadow:0 2px 8px rgba(184,145,47,.35);
}
@keyframes savedFlash{
  0%   { box-shadow:0 0 0 4px var(--gold), 0 0 0 12px rgba(184,145,47,.35); }
  70%  { box-shadow:0 0 0 4px var(--gold), 0 0 0 12px rgba(184,145,47,.12); }
  100% { box-shadow:0 8px 24px rgba(184,145,47,.28); }
}
.mcard.latest-scored.flash{ animation:savedFlash 3s ease-out; }
@media (prefers-reduced-motion: reduce){ .mcard.latest-scored.flash{ animation:none; } }
