/* ============================================================
   KcwOne — app.css (ธีมรวมที่เดียว)
   แก้สี/ฟอนต์/รัศมีทั้งระบบได้จาก :root ด้านล่างจุดเดียว
   ============================================================ */

:root {
    /* สีหลัก (โทนคราม/ม่วง) */
    --brand:        #4f46e5;
    --brand-dark:   #4338ca;
    --brand-light:  #eef2ff;
    --brand-2:      #7c3aed;

    /* sidebar เข้ม */
    --sidebar-bg:   #1e1b4b;
    --sidebar-bg-2: #312e81;
    --sidebar-text: #c7d2fe;
    --sidebar-active-bg: rgba(255, 255, 255, .12);
    --sidebar-active-text: #ffffff;

    /* พื้นหลัง/พื้นผิว/ข้อความ */
    --bg:        #f4f5fb;
    --surface:   #ffffff;
    --text:      #1f2330;
    --muted:     #6b7280;
    --border:    #e6e8f0;

    /* สถานะ */
    --success: #16a34a;
    --danger:  #dc2626;
    --warning: #d97706;
    --info:    #0ea5e9;

    /* สีการ์ดสถิติ */
    --c-indigo: #4f46e5;
    --c-violet: #7c3aed;
    --c-teal:   #0d9488;
    --c-amber:  #d97706;

    /* รูปทรง */
    --radius:    14px;
    --radius-sm: 10px;
    --shadow:    0 2px 12px rgba(30, 27, 75, .08);
    --shadow-lg: 0 10px 30px rgba(30, 27, 75, .15);

    /* ฟอนต์ */
    --font-main: 'Sarabun', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-head: 'Kanit', var(--font-main);

    --sidebar-w: 256px;
    --topbar-h: 64px;
}

* { box-sizing: border-box; }

body {
    font-family: var(--font-main);
    background: var(--bg);
    color: var(--text);
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6, .font-head { font-family: var(--font-head); }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }

/* ───────── ปุ่มธีม ───────── */
.btn-brand {
    background: var(--brand);
    border: 1px solid var(--brand);
    color: #fff;
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding: .55rem 1.1rem;
    transition: background .15s, transform .1s;
}
.btn-brand:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-brand:active { transform: translateY(1px); }

.btn-ghost {
    background: rgba(255, 255, 255, .14);
    border: 1px solid rgba(255, 255, 255, .35);
    color: #fff;
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding: .55rem 1.1rem;
    backdrop-filter: blur(6px);
}
.btn-ghost:hover { background: rgba(255, 255, 255, .24); color: #fff; }

.btn-soft {
    background: var(--brand-light);
    color: var(--brand-dark);
    border: 1px solid var(--border);
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding: .55rem 1.1rem;
}
.btn-soft:hover { background: #e0e7ff; color: var(--brand-dark); }

.btn-icon {
    background: transparent;
    border: none;
    font-size: 1.4rem;
    color: var(--text);
    line-height: 1;
    padding: .25rem .5rem;
}

/* ============================================================
   LAYOUT หลังบ้าน
   ============================================================ */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--sidebar-bg-2), var(--sidebar-bg));
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
}

.sidebar-brand {
    display: flex; align-items: center; gap: .65rem;
    padding: 1.1rem 1.25rem;
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
}
.sidebar-brand > i { font-size: 1.6rem; }
.sidebar-brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.sidebar-brand-text strong { font-family: var(--font-head); font-size: 1.15rem; }
.sidebar-brand-text small { color: var(--sidebar-text); font-size: .72rem; opacity: .8; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem .6rem; }
.sidebar-link {
    display: flex; align-items: center; gap: .75rem;
    padding: .65rem .8rem;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-size: .95rem;
    margin-bottom: .15rem;
    transition: background .12s, color .12s;
}
.sidebar-link i { font-size: 1.15rem; width: 1.3rem; text-align: center; }
.sidebar-link:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.sidebar-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); font-weight: 500; }
/* ── เมนูที่ถูก "เน้น" จากหน้าจัดเมนู ──────────────────────────────
   ขีดชมพูด้านซ้าย + พื้นจาง ๆ · ตั้งใจไม่ใช้สีเต็มแถว เพราะจะไปชนกับ
   สถานะ .active ของหน้าปัจจุบัน แล้วผู้ใช้จะแยกไม่ออกว่าอยู่หน้าไหน
   ⚠ มุมต้องเหลี่ยม — ขอบด้านเดียวกับมุมมนเข้ากันไม่ได้ */
.sidebar-accent {
    background: rgba(244, 114, 182, .14);
    border-left: 3px solid #F472B6;
    border-radius: 0;
    color: #fff;
}
.sidebar-accent i:first-child { color: #F9A8D4; }
.sidebar-accent:hover { background: rgba(244, 114, 182, .24); color: #fff; }
/* หน้าปัจจุบันยังต้องเด่นกว่าการเน้นเสมอ ไม่งั้นหลงว่าอยู่หน้าไหน */
.sidebar-accent.active { background: var(--sidebar-active-bg); }

/* รีเซ็ตสไตล์ browser เริ่มต้นของ <button> (เช่นปุ่ม "ติดตั้งแอปลงมือถือ") ให้เหมือน <a>.sidebar-link ทุกจุด */
button.sidebar-link { width: 100%; border: none; background: transparent; font: inherit; text-align: left; cursor: pointer; }
.sidebar-footer { padding: .6rem; border-top: 1px solid rgba(255, 255, 255, .1); }

/* กลุ่มเมนูแบบยุบ/ขยาย */
.sidebar-group-toggle { width: 100%; border: none; background: transparent; font: inherit; text-align: left; cursor: pointer; }
.sidebar-caret { margin-left: auto; font-size: .75rem; transition: transform .2s ease; }
.sidebar-group-toggle[aria-expanded="true"] .sidebar-caret { transform: rotate(180deg); }
.sidebar-subnav { margin: .1rem 0 .35rem .35rem; padding-left: .7rem; border-left: 1px solid rgba(255, 255, 255, .12); }
.sidebar-sublink { font-size: .9rem; }
/* ชั้นที่ 3 (หมวดย่อย › เมนู) — เยื้องเพิ่มนิดเดียวและเส้นจางลง
   ถ้าเยื้องเยอะกว่านี้ข้อความยาว ๆ จะตัดคำจนอ่านไม่ออกบนมือถือ */
.sidebar-subnav-2 { margin-left: .2rem; padding-left: .55rem; border-left-color: rgba(255, 255, 255, .08); }
.sidebar-sublink-2 { font-size: .86rem; opacity: .92; }
/* ไอคอนบอกว่าลิงก์เปิดแท็บใหม่ */
.sidebar-ext { margin-left: auto; font-size: .7rem; opacity: .55; }

.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 1035;
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ⭐ ยุบเมนูด้านข้าง (ปุ่มบนแถบบน) — ใช้กับจอใหญ่เท่านั้น
   จอเล็กมีกติกาของตัวเองอยู่แล้ว (เมนูซ่อนเป็นค่าเริ่มต้น + เปิดทับด้วยปุ่มแฮมเบอร์เกอร์)
   จึงต้องไม่ให้คลาสนี้ไปยุ่งกับจอเล็ก ไม่งั้นเปิดเมนูบนมือถือไม่ขึ้น */
@media (min-width: 992px) {
    html.sidebar-hidden .app-sidebar { transform: translateX(-100%); }
    html.sidebar-hidden .app-main { margin-left: 0; }
    .app-sidebar { transition: transform .2s ease; }
    .app-main { transition: margin-left .2s ease; }
}

.app-topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 1rem;
    padding: 0 1.25rem;
    position: sticky; top: 0; z-index: 1020;
}
.topbar-title { font-size: 1.15rem; margin: 0; font-weight: 600; flex: 1; min-width: 0; }
/* ⚠ แถบบนสูงคงที่ 64px และบนมือถือช่องชื่อเหลือกว้างแค่ ~110px — ชื่อหน้ายาวจะสูงเกินแถบจนตัวหนังสือโดนตัดหัว
     จอเล็กจึงย่อขนาดลงและจบที่ 2 บรรทัด (ชื่อเต็มยังอยู่ที่หัวหน้าเพจและชื่อแท็บ) */
@media (max-width: 767.98px) {
    /* ⚠ overflow-wrap: anywhere — คำไทยยาวคำเดียวที่กว้างกว่าช่อง (เช่น "สาธารณประโยชน์") ตัดบรรทัดไม่ได้ ถูกเฉือนขวา 32px ที่จอ 360 */
    .topbar-title { font-size: 1rem; line-height: 1.22; overflow: hidden; overflow-wrap: anywhere;
                    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
}
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.topbar-right .btn-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; }
.topbar-right .btn-icon:hover { background: var(--brand-light); }

.user-chip {
    display: flex; align-items: center; gap: .6rem;
    background: var(--brand-light);
    border: none; border-radius: 999px;
    padding: .3rem .7rem .3rem .35rem;
    color: var(--text);
}
.user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--brand); color: #fff;
    display: grid; place-items: center;
    overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.user-meta { flex-direction: column; line-height: 1.1; text-align: left; }
.user-name { font-weight: 600; font-size: .85rem; }
.user-role { font-size: .72rem; color: var(--muted); }

.app-content { padding: 1.5rem; flex: 1; }

/* ───────── ส่วนท้าย (footer ลิขสิทธิ์) — ติดค้างล่างจอตลอด ───────── */
.app-footer {
    position: sticky;
    bottom: 0;
    z-index: 1010;
    padding: 10px 1.5rem;
    text-align: center;
    color: var(--muted);
    font-size: .82rem;
    line-height: 1.5;
    border-top: 1px solid var(--border);
    background: var(--surface);
    box-shadow: 0 -2px 10px rgba(30, 27, 75, .06);
}
.app-footer .af-main strong { color: var(--brand); font-family: var(--font-head); font-weight: 600; }
.app-footer .af-extra { margin-top: 3px; font-size: .78rem; }

/* ───────── หัวหน้าเพจ + แผง ───────── */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
/* ⭐ กลุ่มปุ่มมุมขวาของหัวหน้าเพจต้องตัดบรรทัดได้ — ปุ่ม 3-4 ปุ่มเรียงแถวเดียวล้นจอมือถือ 33-87px (ตรวจ 18 ก.ย. 69) */
.page-head > .d-flex { flex-wrap: wrap; min-width: 0; }
.page-title { margin: 0; font-size: 1.5rem; }
.page-sub { margin: .15rem 0 0; color: var(--muted); }
.term-chip {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 999px; padding: .5rem 1rem; font-size: .9rem;
    box-shadow: var(--shadow); white-space: nowrap;
}
.term-chip i { color: var(--brand); }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
    overflow: hidden;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.panel-head h3 { margin: 0; font-size: 1.05rem; }
.panel-body { padding: 1.25rem; }
.panel-link { font-size: .85rem; color: var(--brand); text-decoration: none; white-space: nowrap; }
.panel-link:hover { text-decoration: underline; }

/* การ์ดวันหยุด/กิจกรรมที่กำลังจะถึง (แดชบอร์ด) */
.upcoming-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.upcoming-list li { display: flex; align-items: center; gap: .6rem; padding: .55rem .8rem; border: 1px solid var(--border); border-radius: 10px; flex-wrap: wrap; }
.upcoming-list .up-date { font-weight: 600; color: var(--brand-dark); white-space: nowrap; min-width: 120px; font-size: .85rem; }
.upcoming-list .up-name { flex: 1; min-width: 130px; }

/* ไฟล์แนบข่าวประกาศ */
.att-list { display: flex; flex-direction: column; gap: .35rem; }
.att-item { display: flex; align-items: center; gap: .5rem; padding: .35rem .6rem; border: 1px solid var(--border); border-radius: 8px; font-size: .85rem; }
.att-item > i { color: var(--brand); }
.att-item .att-name { flex: 1; color: var(--brand); text-decoration: none; word-break: break-all; }
.att-item .att-name:hover { text-decoration: underline; }

/* ข่าวประกาศหน้าสาธารณะ: รูปปก + ไฟล์แนบ */
.pm-news-cover { max-width: 100%; border-radius: 10px; margin: .25rem 0 .5rem; max-height: 280px; object-fit: cover; }
.pm-news-files { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.pm-file { display: inline-flex; align-items: center; gap: .3rem; font-size: .85rem; padding: .25rem .6rem; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; color: var(--brand); background: var(--surface); }
.pm-file:hover { background: var(--brand-light); }

/* ข่าวคลิกเปิดรายละเอียด */
.ann-card-clickable, .pm-news-clickable { cursor: pointer; transition: transform .12s, box-shadow .12s, border-color .12s; }
.ann-card-clickable:hover, .pm-news-clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--brand); }
.ann-readmore, .pm-readmore { color: var(--brand); font-weight: 500; font-size: .85rem; white-space: nowrap; }
.ann-card-clickable .ann-readmore { display: inline-block; margin-top: .5rem; }
.pm-news-more { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: .4rem; }
.pm-article-body { white-space: pre-line; line-height: 1.7; }

/* แถบเมนูประจำโมดูล (ปุ่มกลับระบบหลัก + ลิงก์ในโดเมน) */
.module-bar { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: .45rem .6rem; margin-bottom: 1rem; }
.module-bar-back { display: inline-flex; align-items: center; font-size: .82rem; font-weight: 600; color: var(--brand); text-decoration: none; padding: .35rem .7rem; border-radius: 8px; background: var(--brand-light); white-space: nowrap; }
.module-bar-back:hover { background: var(--brand); color: #fff; }
.module-bar-links { display: flex; flex-wrap: wrap; gap: .25rem; margin-left: .4rem; padding-left: .6rem; border-left: 1px solid var(--border); }
.module-bar-link { font-size: .82rem; color: var(--muted); text-decoration: none; padding: .35rem .7rem; border-radius: 8px; white-space: nowrap; }
.module-bar-link:hover { background: var(--bg); color: var(--brand); }
.module-bar-link.active { background: var(--brand); color: #fff; font-weight: 500; }
@media (max-width: 575.98px) { .module-bar-links { border-left: none; padding-left: 0; margin-left: 0; } }

/* แดชบอร์ดประจำโมดูล (แถบสรุปเหนือตาราง) */
/* ⚠⚠ ต้องเป็น minmax(0, …) ไม่ใช่ 1fr เฉย ๆ — แทร็ก 1fr ขยายตามความกว้างขั้นต่ำของลูก
     กราฟ (canvas ที่ Chart.js ตั้งความกว้างไว้แล้ว) จึงดันทั้งแดชบอร์ดล้นจอ 13px ที่ 360px จนหน้าเลื่อนข้างได้ (5 โมดูล · ตรวจ 18 ก.ย. 69) */
.mdash { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; margin-bottom: 1rem; }
@media (min-width: 992px) { .mdash { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); align-items: start; } }
.mdash-chart, .mdash-cards { min-width: 0; }
.mdash-canvas canvas { max-width: 100%; }
.mdash-stat .l { overflow-wrap: anywhere; }
.mdash-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: .7rem; }
.mdash-stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: .7rem .9rem; }
.mdash-stat .v { font-size: 1.5rem; font-weight: 700; color: var(--brand-dark); line-height: 1.1; }
.mdash-stat .l { font-size: .76rem; color: var(--muted); margin-top: .1rem; }
.mdash-stat .l i { margin-right: .2rem; }
.mdash-chart { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: .8rem 1rem; }
.mdash-chart h6 { font-size: .85rem; color: var(--brand-dark); margin: 0 0 .5rem; font-weight: 600; }
.mdash-canvas { position: relative; height: 210px; }

/* ───────── การ์ดสถิติ ───────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem; margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem 1.25rem;
    display: flex; align-items: center; gap: 1rem;
    border-left: 4px solid var(--brand);
}
.stat-card.c-indigo { border-left-color: var(--c-indigo); }
.stat-card.c-violet { border-left-color: var(--c-violet); }
.stat-card.c-teal   { border-left-color: var(--c-teal); }
.stat-card.c-amber  { border-left-color: var(--c-amber); }
.stat-icon {
    width: 52px; height: 52px; border-radius: 12px;
    display: grid; place-items: center; font-size: 1.5rem;
    background: var(--brand-light); color: var(--brand);
}
.c-violet .stat-icon { background: #f3e8ff; color: var(--c-violet); }
.c-teal   .stat-icon { background: #ccfbf1; color: var(--c-teal); }
.c-amber  .stat-icon { background: #fef3c7; color: var(--c-amber); }
.stat-value { font-family: var(--font-head); font-size: 1.8rem; font-weight: 600; line-height: 1; }
.stat-label { color: var(--muted); font-size: .9rem; }

/* ───────── ทางลัด ───────── */
.quick-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: .85rem; padding: 1.25rem;
}
.quick-card {
    display: flex; flex-direction: column; align-items: center; gap: .5rem;
    padding: 1.1rem .75rem; text-align: center;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text);
    transition: transform .12s, box-shadow .12s, border-color .12s;
}
.quick-card i { font-size: 1.6rem; color: var(--brand); }
.quick-card span { font-size: .9rem; }
.quick-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--brand); color: var(--text); }

/* ============================================================
   หน้า AUTH (login / forgot / reset / maintenance)
   ============================================================ */
.auth-wrap {
    min-height: 100vh;
    display: grid; place-items: center;
    padding: 1.5rem; position: relative; overflow: hidden;
}
.auth-bg {
    position: absolute; inset: 0; z-index: 0;
    background: linear-gradient(135deg, var(--sidebar-bg), var(--brand) 60%, var(--brand-2));
}
.auth-bg::after {
    content: ''; position: absolute; inset: 0;
    background:
        radial-gradient(circle at 20% 20%, rgba(255,255,255,.18), transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(255,255,255,.12), transparent 45%);
}
/* ⭐ ภาพพื้นหลังหน้าเข้าสู่ระบบ — ใช้ภาพเดียวกับหน้าแรกสาธารณะ (--auth-bg)
   ชั้นภาพอยู่บนพื้นไล่สีเดิม แล้วทับด้วยฝ้าไล่สีแบรนด์ตามระดับที่ตั้งไว้ (--auth-dim)
   ⚠ ฝ้าจำเป็นจริง — ภาพถ่ายกิจกรรมมักมีรายละเอียดเยอะจนการ์ดกระจกอ่านยากถ้าไม่ลดคอนทราสต์ */
.auth-bg.has-img {
    background-image: var(--auth-bg);
    background-size: cover; background-position: center; background-repeat: no-repeat;
}
.auth-bg.has-img::after {
    background: linear-gradient(135deg, var(--sidebar-bg), var(--brand) 60%, var(--brand-2));
    opacity: var(--auth-dim, .55);
}
.auth-card {
    position: relative; z-index: 1;
    width: 100%; max-width: 420px;
    background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, .6);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    padding: 2rem;
}
.auth-brand { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.25rem; }
.auth-brand > i { font-size: 2rem; color: var(--brand); }
.auth-brand h1 { font-size: 1.3rem; margin: 0; }
.auth-brand p { margin: 0; color: var(--muted); font-size: .85rem; }
.auth-title { font-size: 1.4rem; margin: 0 0 .15rem; }
.auth-subtitle { color: var(--muted); font-size: .9rem; margin-bottom: 1.25rem; }
.auth-link { font-size: .88rem; }
.auth-foot { text-align: center; margin-top: 1.25rem; font-size: .9rem; }

.form-label { font-weight: 500; font-size: .9rem; margin-bottom: .35rem; }
.input-group-text { background: var(--brand-light); border-color: var(--border); color: var(--brand); }
.form-control:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .15); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }

/* ============================================================
   สวิตช์พรีเมียม (ยกระดับ toggle ทั้งระบบ — ใช้กับ .form-switch ทุกที่)
   ============================================================ */
.form-switch { padding-left: 3.4em; min-height: 1.65em; position: relative; }
.form-switch .form-check-input {
  --sw-knob: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='9' fill='%23ffffff'/%3E%3C/svg%3E");
  width: 2.9em;
  height: 1.55em;
  margin-left: -3.4em;
  margin-top: .04em;
  border: 0;
  background-color: transparent;
  background-image: var(--sw-knob), linear-gradient(145deg, #cbd5e1, #94a3b8);
  background-repeat: no-repeat;
  background-position: left .18em center, center;
  background-size: 1.18em, cover;
  border-radius: 2em;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, .3), 0 1px 2px rgba(0, 0, 0, .05);
  transition: background-position .32s cubic-bezier(.34, 1.56, .64, 1), background-image .25s ease, box-shadow .2s ease;
  cursor: pointer;
  vertical-align: -0.35em;
}
.form-switch .form-check-input:hover { filter: brightness(.97); }
.form-switch .form-check-input:focus {
  background-image: var(--sw-knob), linear-gradient(145deg, #cbd5e1, #94a3b8);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, .3), 0 0 0 .2rem rgba(79, 70, 229, .2);
}
.form-switch .form-check-input:checked {
  background-color: transparent;
  background-image: var(--sw-knob), linear-gradient(145deg, var(--brand), var(--brand-2));
  background-position: right .18em center, center;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, .25), 0 2px 6px rgba(79, 70, 229, .3);
}
.form-switch .form-check-input:checked:focus {
  background-image: var(--sw-knob), linear-gradient(145deg, var(--brand), var(--brand-2));
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, .25), 0 0 0 .2rem rgba(79, 70, 229, .3);
}
.form-switch .form-check-input:disabled { opacity: .55; cursor: not-allowed; }
.form-switch .form-check-label { padding-top: .16em; }
/* ป้าย ON/OFF บนแทร็ก (ตรงข้ามลูกบิด) — :has() รองรับเบราว์เซอร์สมัยใหม่, ถ้าไม่รองรับสวิตช์ยังทำงานปกติ */
/* ยึดป้ายกับตัวสวิตช์ (แถบบนสุด) ไม่ใช่กึ่งกลางกล่อง — กัน label ยาวหลายบรรทัดดันป้ายหล่นล่าง */
.form-switch::after {
  content: 'OFF'; position: absolute; top: 0; left: 0; width: 4.83em; height: 2.68em; margin-top: .07em;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 1em; font-size: .6em; font-weight: 800; letter-spacing: .03em;
  color: #475569; pointer-events: none; z-index: 2; transition: color .25s ease;
}
.form-switch:has(.form-check-input:checked)::after {
  content: 'ON'; justify-content: flex-start; padding-right: 0; padding-left: 1.15em; color: #fff;
}
.form-switch:has(.form-check-input:disabled)::after { opacity: .55; }

/* ============================================================
   หน้าแรกสาธารณะ (PUBLIC LANDING)
   ============================================================ */
.pub { background: var(--bg); }
.pub-nav {
    display: flex; align-items: center; justify-content: space-between;
    padding: .85rem 1.5rem; background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 1020;
}
.pub-brand { display: flex; align-items: center; gap: .55rem; font-family: var(--font-head); font-weight: 600; font-size: 1.15rem; color: var(--text); }
.pub-brand i { color: var(--brand); font-size: 1.5rem; }
.pub-nav-right { display: flex; align-items: center; gap: 1.1rem; }
.pub-nav-link { color: var(--text); font-size: .95rem; }
.pub-nav-link:hover { color: var(--brand); }

.pub-hero {
    position: relative; overflow: hidden;
    /* --pub-hero-bg = สีที่ผู้ดูแลตั้งเองในหน้าตั้งค่า · ไม่ตั้ง = ไล่สีเดิมของธีม */
    background: var(--pub-hero-bg, linear-gradient(135deg, var(--sidebar-bg), var(--brand) 65%, var(--brand-2)));
    color: #fff; padding: 4rem 1.5rem;
}
.pub-hero::after {
    content: ''; position: absolute; inset: 0;
    background:
        radial-gradient(circle at 15% 25%, rgba(255,255,255,.18), transparent 40%),
        radial-gradient(circle at 85% 75%, rgba(255,255,255,.1), transparent 45%);
}
.pub-hero-inner { position: relative; z-index: 1; max-width: 880px; margin: 0 auto; text-align: center; }
.pub-badge {
    display: inline-block; background: rgba(255,255,255,.16);
    border: 1px solid rgba(255,255,255,.3);
    border-radius: 999px; padding: .3rem 1rem; font-size: .85rem; margin-bottom: 1rem;
}
.pub-hero-inner h1 { font-size: clamp(1.8rem, 4vw, 2.8rem); margin: 0 0 1rem; }
.pub-hero-vision { font-size: 1.05rem; opacity: .95; max-width: 680px; margin: 0 auto 1.75rem; line-height: 1.7; }
.pub-hero-buttons { display: flex; flex-wrap: wrap; gap: .75rem; justify-content: center; }

.pub-section { max-width: 1100px; margin: 0 auto; padding: 3rem 1.5rem; }
.pub-section-alt { background: var(--surface); max-width: none; }
.pub-section-alt > * { max-width: 1100px; margin-left: auto; margin-right: auto; }
.pub-section-head { text-align: center; margin-bottom: 2rem; }
.pub-section-head h2 { font-size: 1.6rem; margin: 0 0 .35rem; }
.pub-section-head p { color: var(--muted); margin: 0; }
.pub-empty { text-align: center; color: var(--muted); padding: 2rem; }

/* ───────── ภาพพื้นหลังทั้งหน้า (ตั้งค่าระบบ → หน้าแรกสาธารณะ) ─────────
   ภาพตรึงอยู่กับที่ตลอดทั้งหน้า + ฝ้าทับตามระดับที่ตั้ง (--pub-dim) ให้ตัวอักษรอ่านออกเสมอ
   ไม่ตั้งภาพ = ไม่มีคลาสนี้เลย หน้าเดิมไม่ถูกแตะ

   ⚠ ไม่ใช้ background-attachment: fixed เพราะกรอบภาพจะอิง "ขอบบนของจอ"
     ทำให้ส่วนบนของภาพไปอยู่ใต้แถบเมนู (ทึบ) แล้วโดนบังหายไป
     จึงวางภาพเป็นชั้นของตัวเองที่เริ่มพอดีใต้แถบเมนู (--pub-nav-h)
     ผลพลอยได้: position:fixed ทำงานบนมือถือได้ดีกว่า background-attachment:fixed มาก */
/* --pub-nav-h มาจาก JS ที่วัดแถบเมนูจริง (ดู landing.php)
   ค่าใน var(...) ข้างล่างเป็นแค่ตาข่ายรองรับกรณี JS ไม่ทำงาน — ประมาณจากชื่อโรงเรียนที่ยาวปกติ */
.pub-has-bg { position: relative; --pub-nav-fallback: 68px; }
/* ⚠ ต้องตรงกับ breakpoint 575.98px ของ .pub-nav ด้านล่าง (แถบเมนูตกลง 2 แถวคงที่ในช่วงนี้ทั้งหมด
   จึงใช้เลขเดียวได้ทั้งช่วง ไม่ต้องมีหลายขั้นเหมือนเดิม — ของเดิมมีหลายขั้นเพราะแถบเมนูบีบ/ล้นไม่คงที่) */
@media (max-width: 575.98px) { .pub-has-bg { --pub-nav-fallback: 90px; } }
.pub-has-bg::before,
.pub-has-bg::after {
    content: ''; position: fixed;
    top: var(--pub-nav-h, var(--pub-nav-fallback)); left: 0; right: 0; bottom: 0;
    z-index: 0; pointer-events: none;
}
.pub-has-bg::before {                       /* ชั้นภาพ — ขอบบนของภาพ = ใต้แถบเมนูพอดี */
    background-image: var(--pub-bg);
    background-size: cover; background-position: center top; background-repeat: no-repeat;
}
.pub-has-bg::after {                        /* ชั้นฝ้า — คลุมเท่าชั้นภาพ (อยู่หลังใน source จึงทับด้านบน) */
    background: var(--bg); opacity: var(--pub-dim, .55);
}
/* ยกเนื้อหาขึ้นเหนือฝ้า — เว้น .pub-nav ไว้เพราะเป็น sticky (z-index 1020) อยู่แล้ว
   ถ้าไปตั้ง position ทับจะทำให้แถบบนไม่ติดขอบจอ */
.pub-has-bg > *:not(.pub-nav) { position: relative; z-index: 1; }

/* แถบที่เดิมทึบ → ให้เห็นภาพผ่าน แต่ยังคุมความคมของตัวอักษรบนแถบนั้น ๆ
   ใช้สีดำโปร่งแทนสีธีม เพราะภาพที่ผู้ใช้อัปเป็นสีอะไรก็ได้
   --pub-hero-bg / --pub-footer-bg มาจากสีที่ผู้ดูแลตั้งเอง (ถ้าตั้ง) — ดู landing.php */
.pub-has-bg .pub-hero { background: var(--pub-hero-bg, linear-gradient(135deg, rgba(15,23,42,.66), rgba(15,23,42,.42))); }
.pub-has-bg .pub-hero::after { background: none; }
.pub-has-bg .pub-section-alt { background: transparent; }
.pub-has-bg .pub-footer { background: var(--pub-footer-bg, rgba(15,23,42,.80)); }

/* ───────── สีแถบหัวเรื่อง/ส่วนท้ายที่ผู้ดูแลตั้งเอง (ตั้งค่าระบบ → หน้าแรกสาธารณะ) ─────────
   ตัว background อยู่ที่ .pub-hero / .pub-footer ต้นฉบับ (ใส่ var + fallback ไว้ตรงนั้นเลย)
   ห้ามประกาศ .pub-hero/.pub-footer ซ้ำตรงนี้ — ของต้นฉบับอยู่ล่างกว่าในไฟล์ จะทับกลับ

   เลือกสีสว่าง → ตัวอักษรสีขาวเดิมจะอ่านไม่ออก สลับเป็นสีเข้มให้อัตโนมัติ
   (ระบบคำนวณความสว่างของสีที่เลือกให้เอง ผู้ดูแลไม่ต้องคิดเอง) */
.pub-hero-light .pub-hero { color: #1f2937; }
.pub-hero-light .pub-badge { background: rgba(0,0,0,.07); border-color: rgba(0,0,0,.18); color: #1f2937; }
/* ปุ่มโปร่งของเดิมเป็นขาวจาง ๆ บนพื้นสว่างจะมองแทบไม่เห็น → สลับเป็นดำจาง */
.pub-hero-light .pub-hero .btn-ghost { background: rgba(0,0,0,.06); border-color: rgba(0,0,0,.28); color: #1f2937; }
.pub-hero-light .pub-hero .btn-ghost:hover { background: rgba(0,0,0,.13); color: #111827; }

.pub-footer-light .pub-footer { color: #1f2937; }
.pub-footer-light .pub-footer h3,
.pub-footer-light .pub-footer h4 { color: #111827; }
.pub-footer-light .pub-footer .text-white { color: #1f2937 !important; }
.pub-footer-light .pub-copyright { border-top-color: rgba(0,0,0,.15); }

.pub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1.1rem; }

.ann-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: .5rem;
}
.ann-tag {
    align-self: flex-start;
    background: var(--brand-light); color: var(--brand);
    border-radius: 999px; padding: .15rem .7rem; font-size: .78rem; font-weight: 500;
}
.ann-card h3 { font-size: 1.1rem; margin: 0; }
.ann-card p { color: var(--muted); font-size: .92rem; margin: 0; flex: 1; }
.ann-date { color: var(--muted); font-size: .82rem; }

.module-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.5rem 1.25rem; box-shadow: var(--shadow);
    display: flex; flex-direction: column; align-items: center; gap: .5rem;
    text-align: center; cursor: pointer;
    transition: transform .12s, box-shadow .12s, border-color .12s;
}
.module-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--brand); }
.module-card > i { font-size: 2.2rem; color: var(--brand); }
.module-name { font-family: var(--font-head); font-weight: 600; font-size: 1.05rem; }
.module-desc { color: var(--muted); font-size: .85rem; }

/* --pub-footer-bg = สีที่ผู้ดูแลตั้งเองในหน้าตั้งค่า · ไม่ตั้ง = สีเดิมของธีม */
.pub-footer { background: var(--pub-footer-bg, var(--sidebar-bg)); color: #e5e7ff; padding: 2.5rem 1.5rem 1.5rem; }
.pub-footer-grid { max-width: 1100px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.5rem; }
.pub-footer h3 { color: #fff; font-size: 1.2rem; }
.pub-footer h4 { color: #fff; font-size: 1rem; margin-bottom: .75rem; }
.pub-footer p { margin: .35rem 0; font-size: .92rem; opacity: .9; }
.pub-copyright { max-width: 1100px; margin: 1.5rem auto 0; padding-top: 1.25rem; border-top: 1px solid rgba(255,255,255,.12); text-align: center; font-size: .85rem; opacity: .8; }

/* ───────── หน้าแรกสาธารณะบนจอเล็ก (มือถือ) ─────────
   แถบเมนูบนเดิมยัดชื่อโรงเรียน + ลิงก์ 3 อัน + ปุ่มเข้าสู่ระบบไว้แถวเดียว (justify-content:space-between)
   จอแคบกว่า ~575px ชื่อโรงเรียนอย่างเดียวก็กินที่เกินครึ่งแล้ว ที่เหลือจึงบีบลิงก์+ปุ่มจนอ่านไม่ออก/ล้นขอบจอ

   แก้ให้ .pub-nav-right (ลิงก์ทั้ง 3 + ปุ่มเข้าสู่ระบบ) ตกลงไปเป็นแถวที่สองเสมอ (flex-basis:100%)
   ไม่ใช่บีบให้เล็กลงเรื่อย ๆ ตามความยาวชื่อโรงเรียน — ได้ผลลัพธ์เดียวกันทุกจอแคบ ไม่ต้องมีเมนูแฮมเบอร์เกอร์เพิ่ม */
@media (max-width: 575.98px) {
    .pub-nav { flex-wrap: wrap; row-gap: .5rem; padding: .65rem 1rem; }
    .pub-brand span { font-size: 1rem; }
    .pub-brand i { font-size: 1.3rem; }
    .pub-nav-right { flex-basis: 100%; gap: .6rem; }
    .pub-nav-link { font-size: .85rem; }
    .pub-nav-right .btn { padding: .35rem .7rem; font-size: .82rem; white-space: nowrap; }

    .pub-hero { padding: 2.5rem 1.15rem; }
    .pub-hero-inner h1 { margin-bottom: .6rem; }
    .pub-badge { font-size: .78rem; padding: .25rem .85rem; }
    .pub-hero-vision { font-size: .95rem; margin-bottom: 1.4rem; }
    .pub-hero-buttons { gap: .6rem; }
    .pub-hero-buttons .btn { flex: 1 1 140px; }   /* ปุ่มยืดเต็มแถวเมื่อเหลือตัวเดียว แทนที่จะลอยเล็ก ๆ กลางจอ */

    .pub-section { padding: 2.25rem 1.15rem; }
    .pub-section-head { margin-bottom: 1.5rem; }
    .pub-section-head h2 { font-size: 1.3rem; }

    .pub-footer { padding: 2rem 1.15rem 1.25rem; }
}

/* ───────── เนื้อหา modal สาธารณะ ───────── */
.pm-title { font-family: var(--font-head); }
.pm-block { margin-bottom: 1.25rem; }
.pm-block h6 { color: var(--brand); font-weight: 600; }
.pm-list { list-style: none; padding: 0; margin: 0; }
.pm-list li { padding: .25rem 0; }
.pm-list i { color: var(--brand); width: 1.2rem; }
.pm-stats { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.pm-stat {
    flex: 1; min-width: 120px; text-align: center;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 1rem;
    display: flex; flex-direction: column; gap: .25rem;
}
.pm-stat-num { font-family: var(--font-head); font-size: 1.6rem; font-weight: 600; color: var(--brand); }
.pm-stat span:last-child { color: var(--muted); font-size: .85rem; }
.pm-people { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.pm-person { display: flex; align-items: center; gap: .65rem; padding: .65rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.pm-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--brand-light); color: var(--brand); display: grid; place-items: center; }
.pm-person-name { font-weight: 500; }
.pm-person-meta { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .2rem; }
.pm-news-item { padding-bottom: 1rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.pm-news-item:last-child { border-bottom: none; margin-bottom: 0; }
.pm-news-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .35rem; }
.pm-cal { list-style: none; padding: 0; margin: 0; }
.pm-cal-item { display: flex; gap: 1rem; padding: .65rem 0; border-bottom: 1px dashed var(--border); }
.pm-cal-date { min-width: 130px; color: var(--brand); font-weight: 500; }
.pm-cal-body { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); transition: transform .25s ease; }
    .app-sidebar.open { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .sidebar-backdrop.show { display: block; }
}

/* ============================================================
   หน้า CRUD / ตารางข้อมูล (ครู, นักเรียน ฯลฯ)
   ============================================================ */
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.toolbar .spacer { margin-left: auto; }
.toolbar .form-control, .toolbar .form-select { max-width: 230px; font-size: .82rem; font-weight: 300; padding-top: .35rem; padding-bottom: .35rem; }
.toolbar .form-control::placeholder { font-weight: 300; }

.data-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
/* ⭐ ข้อความยาวไม่มีช่องว่าง (ลิงก์สมัครกิจกรรม · โค้ด) ในกล่องแจ้งเตือนต้องตัดบรรทัดได้ — ไม่งั้นดันทั้งหน้าล้นจอ 48px (ตรวจ 18 ก.ย. 69)
     ⚠ ลูกของ .alert.d-flex ต้อง min-width:0 ด้วย (flex item ปกติไม่ยอมหดต่ำกว่าคำที่ยาวที่สุด) */
.alert { overflow-wrap: anywhere; }
.alert.d-flex > div { min-width: 0; }
.data-card .table-responsive { margin: 0; }
.data-card .table { margin: 0; }
.data-card .table { font-size: .9rem; }
.data-card .table thead th { background: var(--brand-light); color: var(--brand-dark); font-weight: 600; white-space: nowrap; border-bottom: 1px solid var(--border); }
.data-card .table td { vertical-align: middle; white-space: nowrap; }
.data-card .table tbody tr:hover { background: var(--brand-light); }

/* ตารางแบบบาง/เล็ก — ตัวเล็ก ช่องไฟแคบ ไม่ตัดคำ/บรรทัด (สืบทอด white-space: nowrap จาก .table td) */
.data-card .table-slim { font-size: .76rem; }
.data-card .table-slim thead th { font-weight: 500; font-size: .74rem; padding: .45rem .45rem; }
.data-card .table-slim td { font-weight: 300; padding: .38rem .45rem; }
.data-card .table-slim .row-detail { font-weight: 500; }
.data-card .table-slim .badge-soft { font-size: .68rem; padding: .12rem .4rem; }
.data-card .table-slim .small, .data-card .table-slim small { font-size: .7rem; }
.data-card .table-slim .btn-icon-sm { padding: .26rem .45rem; font-size: 1.08rem; min-width: 34px; min-height: 32px; }
.col-check { width: 32px; text-align: center; padding-left: .35rem; padding-right: .35rem; }
.col-seq { width: 40px; text-align: center; color: var(--muted); }

/* ท้ายตาราง: ข้อมูล + ปุ่มแบ่งหน้า */
.dt-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; padding: .7rem 1rem; border-top: 1px solid var(--border); }
.dt-info { color: var(--muted); font-size: .8rem; }
.dt-pager { display: flex; gap: .25rem; flex-wrap: wrap; }
.page-btn { min-width: 32px; height: 32px; padding: 0 .5rem; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; color: var(--text); font-size: .82rem; cursor: pointer; transition: background .12s, border-color .12s; }
.page-btn:hover:not(:disabled):not(.active) { background: var(--brand-light); border-color: var(--brand); }
.page-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.page-btn:disabled { opacity: .45; cursor: default; }
.page-ellipsis { padding: 0 .25rem; color: var(--muted); align-self: center; }
.dt-perpage { display: flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .8rem; font-weight: 300; white-space: nowrap; }
.dt-perpage .form-select { width: auto; max-width: 90px; }
.page-btn.disabled { opacity: .45; pointer-events: none; }
.audit-pre { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem; font-size: .76rem; line-height: 1.5; max-height: 50vh; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0; }

.btn-icon-sm { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border); background: var(--surface); padding: .32rem .5rem; border-radius: 8px; color: var(--muted); line-height: 1; font-size: 1.15rem; min-width: 36px; min-height: 34px; transition: background .12s, color .12s, border-color .12s; }
.btn-icon-sm + .btn-icon-sm { margin-left: .3rem; }
.btn-icon-sm:hover { background: var(--brand-light); color: var(--brand); border-color: var(--brand); }
.btn-icon-sm.danger:hover { color: var(--danger); background: #fee2e2; border-color: #fca5a5; }
.btn-icon-sm .bi-toggle-on { font-size: 1.3rem; }

.badge-soft { display: inline-block; padding: .25rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 500; }
.badge-soft.ok { background: #dcfce7; color: #166534; }
.badge-soft.off { background: #fee2e2; color: #991b1b; }
.badge-soft.info { background: var(--brand-light); color: var(--brand-dark); }
.badge-soft.muted { background: var(--bg); color: var(--muted); }
.badge-soft.warn { background: #fef3c7; color: #b45309; }
.badge-soft.danger { background: #fee2e2; color: #b91c1c; }

/* ช่องเลือกรูปในหน้าตั้งค่า (ตัวอย่างภาพ + ปุ่มอัปโหลด/เอาออก) */
.set-img-preview {
    border: 1px dashed var(--border); border-radius: var(--radius-sm);
    background: var(--bg); overflow: hidden;
    min-height: 130px; max-height: 260px;
    display: grid; place-items: center;
}
.set-img-preview img { width: 100%; max-height: 260px; object-fit: cover; display: block; }
.set-img-preview .set-img-none { color: var(--muted); font-size: .85rem; }
.set-img-preview:not(.is-empty) .set-img-none { display: none; }

.empty-state { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.empty-state i { font-size: 2.5rem; opacity: .5; display: block; margin-bottom: .5rem; }
.row-hidden { display: none !important; }
.page-hidden { display: none !important; }
.row-detail { cursor: pointer; color: var(--text); text-decoration: none; }
.row-detail:hover { color: var(--brand); text-decoration: underline; }

/* modal รายละเอียด: รูปด้านซ้าย — ข้อมูลด้านขวา (พื้นหลังไล่สี) */
#detailModal .modal-dialog { max-width: 540px; }
.detail-layout { display: flex; gap: 1rem; align-items: stretch; flex-wrap: wrap; }
.detail-media { flex: 0 0 150px; align-self: stretch; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border); border-radius: 16px; background: linear-gradient(160deg, var(--brand-light), #e7f1fb); min-height: 190px; }
.detail-info { flex: 1 1 200px; background: linear-gradient(140deg, var(--brand-light), #eef6fc 55%, #fff); border: 1px solid var(--border); border-radius: 16px; padding: 1.05rem 1.2rem; display: flex; align-items: center; }
.detail-list { display: grid; grid-template-columns: max-content 1fr; gap: .5rem 1.1rem; margin: 0; width: 100%; font-size: .82rem; }
.detail-list dt { color: var(--brand-dark); font-weight: 500; }
.detail-list dd { margin: 0; font-weight: 300; color: var(--text); }
@media (max-width: 560px) { .detail-media { flex-basis: 100%; } .detail-photo, .detail-avatar { aspect-ratio: 16 / 10; } }

/* รูปใน modal — พอร์ตเทรต 3:4 สม่ำเสมอ อยู่บนสุดของช่องซ้าย (ที่เหลือเป็นแผงไล่สี) */
.detail-photo, .detail-avatar { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; object-position: top center; display: block; flex: 0 0 auto; }
.detail-avatar { display: grid; place-items: center; color: var(--brand); font-size: 3rem; }
.avatar-sm { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--brand-light); color: var(--brand); display: inline-grid; place-items: center; flex-shrink: 0; }
.profile-photo, .profile-avatar { width: 140px; height: 140px; border-radius: 50%; object-fit: cover; border: 4px solid var(--brand-light); }
.profile-avatar { background: var(--brand-light); color: var(--brand); display: inline-grid; place-items: center; font-size: 3.5rem; }

/* ทำเนียบบุคลากร (การ์ดรูปเต็ม + แถบชื่อ) */
.directory-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 1.1rem; }
.person-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; cursor: pointer; transition: transform .15s ease, box-shadow .15s ease; }
.person-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.person-photo-wrap { position: relative; aspect-ratio: 3 / 4; overflow: hidden; background: linear-gradient(160deg, var(--brand-light), #fff); }
.person-photo { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; transition: transform .35s ease; }
.person-card:hover .person-photo { transform: scale(1.06); }
.person-avatar { width: 100%; height: 100%; display: grid; place-items: center; color: var(--brand); font-size: 3.5rem; opacity: .55; }
.person-banner { position: relative; background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff; padding: .7rem .6rem .75rem; text-align: center; }
.person-banner::before { content: ''; position: absolute; left: 50%; top: -9px; transform: translateX(-50%); width: 34px; height: 4px; border-radius: 99px; background: rgba(255, 255, 255, .55); }
.person-name { font-weight: 700; font-size: .94rem; line-height: 1.25; color: #fff; }
.person-role { font-size: .77rem; opacity: .9; margin-top: .1rem; }
.person-dept { font-size: .73rem; font-weight: 600; opacity: .97; margin-top: .25rem; color: #fff; }
.person-dept::before { content: ''; display: block; width: 24px; height: 2px; margin: 0 auto .28rem; border-radius: 99px; background: rgba(255, 255, 255, .4); }
.person-badge { position: absolute; top: .5rem; right: .5rem; background: rgba(0, 0, 0, .5); color: #fff; font-size: .68rem; padding: .15rem .55rem; border-radius: 999px; }

/* หัวเรื่องทำเนียบ (กึ่งกลาง) */
.dir-header { text-align: center; margin: .25rem 0 1.4rem; }
.dir-header h2 { font-family: var(--font-head, inherit); font-weight: 700; color: var(--brand-dark); margin: 0; font-size: clamp(1.15rem, 2.4vw, 1.5rem); }
.dir-header .dir-sub { color: var(--muted); margin-top: .3rem; font-size: .92rem; }
.dir-header .dir-count { display: inline-block; margin-top: .35rem; font-size: .82rem; color: var(--brand); background: var(--brand-light); padding: .12rem .7rem; border-radius: 999px; }

/* แถวทำเนียบแบบพีระมิด — จัดกึ่งกลางทุกแถว, ขนาดลดหลั่นตามลำดับ */
.dir-tier { margin-bottom: .4rem; }
.dir-tier-label { text-align: center; font-weight: 600; color: var(--brand-dark); font-size: .9rem; margin: .2rem 0 .7rem; }
.dir-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 1rem; margin: 0 auto 1.5rem; }
.dir-row--director { max-width: 230px; }
.dir-row--director > .person-card { width: 205px; }
.dir-row--deputy { max-width: 880px; }
.dir-row--deputy > .person-card { width: 198px; }
.dir-row--head { max-width: 840px; }
.dir-row--head > .person-card { width: 188px; }
.dir-row--rest > .person-card { width: 152px; }
.dir-row--rest .person-banner { padding: .55rem .5rem .6rem; }
.dir-row--rest .person-name { font-size: .83rem; }
.dir-row--rest .person-role { font-size: .71rem; }
.dir-row--rest .person-dept { font-size: .68rem; margin-top: .18rem; }
.dir-row--rest .person-dept::before { margin-bottom: .2rem; }
.dir-row--rest .person-avatar { font-size: 2.6rem; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline-item { position: relative; padding: 0 0 1rem 1.5rem; border-left: 2px solid var(--border); }
.timeline-item:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline-item::before { content: ''; position: absolute; left: -7px; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--brand); }
.timeline-item.current::before { background: var(--success); box-shadow: 0 0 0 3px #dcfce7; }

@media (max-width: 575.98px) {
    .toolbar .form-control, .toolbar .form-select { max-width: none; flex: 1 1 100%; }
}

/* Modal: จำกัดความสูงไม่เกินจอ + เลื่อนเนื้อหาในตัวได้ (กันฟอร์มยาวล้นจนปุ่มบันทึกหาย)
   ⚠⚠ (11 ก.ย. 2569) บน iPhone Safari ปุ่ม "บันทึก/ยกเลิก" ท้ายกล่องถูกตัดครึ่ง (โรงเรียนส่งภาพมา)
      สาเหตุ 2 ชั้นที่ซ้อนกัน
      1) บน iOS `100vh` = ความสูงจอ "ตอนแถบเบราว์เซอร์ยุบหาย" ไม่ใช่พื้นที่ที่เห็นจริง
         ตัวกล่องถูกวางในพื้นที่ที่เห็นจริงซึ่งเตี้ยกว่า ~80–120px → ส่วนล่างของกล่องล้นจอ
         → ใช้ `100dvh` (ความสูงที่เห็นจริง iOS 15.4+) บรรทัด vh ข้างบนคงไว้เป็นค่าสำรองของเบราว์เซอร์เก่า
      2) กล่องที่มี <form> ห่อ header/body/footer (32 กล่องใน 13 โมดูล) — form เป็น block ธรรมดา
         flex ของ .modal-content จึงส่งไม่ถึง body → body ไม่ยอมหดตามพื้นที่ → ปุ่มล้นออกนอกกล่อง
         → ให้ form เป็น flex คอลัมน์ต่ออีกชั้น (min-height: 0 คือตัวที่ทำให้ "หดได้" จริง)
         3) ⭐ ไม่พึ่ง dvh อย่างเดียว — iPhone รุ่นเก่า (iOS < 15.4) ไม่รู้จัก dvh
         ผูกความสูงกล่องกับ ".modal" (กล่องใสเต็มจอที่ Bootstrap วางไว้ = พื้นที่ที่เห็นจริงบน iOS) แทนหน่วยของจอ
         .modal-dialog สูงเท่าพื้นที่นั้น (หักขอบ) → .modal-content สูงไม่เกิน 100% ของ dialog
         บนคอม .modal สูงเท่าจอพอดี → ได้ขนาดเท่าเดิมทุกพิกเซล (เดิม calc(100vh - 2rem))
         (dialog สูงเต็มแต่ใส + pointer-events: none อยู่แล้ว — แตะที่ว่างยังปิดกล่องได้เหมือนเดิม)
      ผลรวม: เนื้อหาเลื่อนในกล่อง ส่วนหัวและปุ่มท้ายกล่องอยู่ในจอเสมอ ไม่ว่าจอจะเตี้ยแค่ไหน
      วัดแล้วทั้ง 131 กล่องในระบบ: จำลอง iPhone + เนื้อหายาว เดิมถูกตัด 97/111 → ใหม่ 0/111
   ⚠ อย่าย้ายกลับไปใช้ 100vh ล้วน และอย่าลบกฎ form ข้างล่าง — เทสต์ tests/modal_mobile_test.php คุมไว้ */
.modal-dialog { margin: 1rem auto; height: calc(100% - 2rem); }
.modal-content {
    max-height: 100%;
    display: flex; flex-direction: column;
}
.modal-content > form {
    display: flex; flex-direction: column;
    flex: 1 1 auto; min-height: 0;
}
.modal-body {
    max-height: calc(100vh - 200px);
    max-height: calc(100dvh - 200px);
    overflow-y: auto;
    flex: 1 1 auto; min-height: 0;
    -webkit-overflow-scrolling: touch;
}
.modal-header, .modal-footer { flex-shrink: 0; }

/* ───────── กระดิ่งแจ้งเตือน ───────── */
.notif-badge { position: absolute; top: 2px; right: 2px; min-width: 17px; height: 17px; padding: 0 4px; background: var(--danger, #dc2626); color: #fff; font-size: .66rem; font-weight: 700; line-height: 17px; text-align: center; border-radius: 999px; }
.notif-menu { min-width: 330px; max-width: 360px; padding: 0; overflow: hidden; }
.notif-list { max-height: 60vh; overflow-y: auto; }
.notif-item { display: flex; gap: .6rem; align-items: flex-start; padding: .6rem .9rem; border-bottom: 1px solid var(--border); cursor: pointer; text-decoration: none; color: inherit; transition: background .12s; }
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--brand-light); }
.notif-item.unread { background: #eff6ff; }
.notif-item.unread:hover { background: var(--brand-light); }
.notif-item .ni-icon { flex-shrink: 0; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; background: var(--brand-light); color: var(--brand); font-size: 1rem; }
.notif-item .ni-title { font-weight: 600; font-size: .82rem; line-height: 1.25; }
.notif-item .ni-msg { font-size: .76rem; color: var(--muted); line-height: 1.3; }
.notif-item .ni-time { font-size: .68rem; color: var(--muted); margin-top: .15rem; }
.notif-empty { text-align: center; color: var(--muted); font-size: .8rem; padding: 1.6rem 1rem; }

/* ───────── ปฏิทินเลือกวันที่แบบไทย (Thai date picker) ───────── */
.tdp-wrap { position: relative; display: block; }
/* ซ่อน input วันที่เดิมแบบยังส่งค่า/โฟกัสด้วยโค้ดได้ */
.tdp-native-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0 0 0 0) !important; white-space: nowrap !important; border: 0 !important; opacity: 0 !important; pointer-events: none !important; }
.tdp-display { cursor: pointer; padding-right: 2.4rem; background-image: none !important; }
.tdp-display::placeholder { color: var(--muted); }
.tdp-display:focus { border-color: var(--brand); box-shadow: 0 0 0 .18rem rgba(79, 70, 229, .15); }
.tdp-wrap .tdp-ico { position: absolute; right: .85rem; top: 50%; transform: translateY(-50%); color: var(--brand); pointer-events: none; font-size: 1.02rem; }
.tdp-display:disabled ~ .tdp-ico { color: var(--muted); }

.tdp-pop { position: fixed; z-index: 3000; width: 304px; background: #fff; border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 16px 44px rgba(30, 27, 75, .22); padding: 12px; font-family: var(--font-main); opacity: 0; transform: translateY(-6px) scale(.98); transition: opacity .14s ease, transform .14s ease; }
.tdp-pop.show { opacity: 1; transform: translateY(0) scale(1); }
.tdp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.tdp-nav { width: 34px; height: 34px; border: 0; background: transparent; border-radius: 9px; cursor: pointer; color: #475569; display: inline-flex; align-items: center; justify-content: center; font-size: 1.05rem; transition: .12s; }
.tdp-nav:hover { background: var(--brand-light); color: var(--brand); }
.tdp-title { border: 0; background: transparent; font-family: var(--font-head); font-weight: 600; font-size: 1.02rem; color: #0f2350; cursor: pointer; padding: 6px 14px; border-radius: 9px; transition: .12s; }
.tdp-title:hover { background: var(--brand-light); color: var(--brand); }
.tdp-dows { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 2px; }
.tdp-dow { text-align: center; font-size: .72rem; font-weight: 600; color: var(--muted); padding: 5px 0; }
.tdp-dow.sun { color: #dc2626; }
.tdp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.tdp-day { border: 0; background: transparent; aspect-ratio: 1 / 1; border-radius: 50%; cursor: pointer; font-family: inherit; font-size: .9rem; color: var(--text); display: inline-flex; align-items: center; justify-content: center; transition: background .1s, color .1s; }
.tdp-day:hover:not(.disabled):not(.sel) { background: var(--brand-light); color: var(--brand); }
.tdp-day.muted { color: #cbd0da; }
.tdp-day.sun:not(.muted):not(.sel) { color: #dc2626; }
.tdp-day.today:not(.sel) { box-shadow: inset 0 0 0 1.5px var(--brand); font-weight: 600; }
.tdp-day.sel { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 600; box-shadow: 0 3px 10px rgba(79, 70, 229, .4); }
.tdp-day.disabled { color: #e2e5ec; cursor: not-allowed; }
.tdp-mgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 4px 0; }
.tdp-cell { border: 0; background: transparent; border-radius: 10px; cursor: pointer; font-family: inherit; font-size: .92rem; color: var(--text); padding: 13px 0; transition: background .1s, color .1s; }
.tdp-cell:hover:not(.sel) { background: var(--brand-light); color: var(--brand); }
.tdp-cell.sel { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 600; }
.tdp-foot { display: flex; justify-content: space-between; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.tdp-foot button { border: 0; background: transparent; color: var(--brand); font-family: inherit; font-weight: 600; font-size: .86rem; cursor: pointer; padding: 6px 14px; border-radius: 8px; transition: .12s; }
.tdp-foot button:hover { background: var(--brand-light); }
.tdp-foot .tdp-clear { color: var(--muted); }
.tdp-foot .tdp-clear:hover { color: var(--danger); background: #fef2f2; }
@media (max-width: 360px) { .tdp-pop { width: calc(100vw - 24px); } }

/* ── ช่องเลือกแบบค้นหาได้ (Kcw searchable select) ────────────────
   ใช้อัตโนมัติกับช่องเลือกรายวิชาทุกโมดูล · ดู SearchSelect ใน app.js

   ⭐ position: fixed ไม่ใช่ absolute — ห้ามเปลี่ยนกลับ
      .data-card (และการ์ดอื่นอีกหลายตัว) มี overflow:hidden ไว้ตัดมุมตาราง
      ถ้าเมนูเป็น absolute เมนูจะถูกขอบการ์ดตัดจนเหลือแถบบาง ๆ กดตัวเลือกไม่ได้
      fixed หลุดจากกรอบที่ตัดทุกชั้น แล้วให้ JS คำนวณตำแหน่ง/ความสูงให้แทน
      (แบบเดียวกับปฏิทินไทย .tdp-pop) */
.kcw-ss-input { cursor: text; }
.kcw-ss-menu { position: fixed; z-index: 1080; background: #fff; border: 1px solid var(--border); border-radius: 10px; max-height: 280px; overflow-y: auto; box-shadow: 0 8px 24px rgba(15, 35, 80, .16); }
/* ตัวเลือกยาว ๆ (เช่น ชื่อยา + จำนวนคงเหลือ) ให้ขึ้นบรรทัดใหม่ ดีกว่าตัดท้ายด้วย … */
.kcw-ss-opt { padding: 7px 12px; cursor: pointer; font-size: .95rem; line-height: 1.35; overflow-wrap: anywhere; }
.kcw-ss-opt:hover { background: var(--brand-light); color: var(--brand); }
.kcw-ss-opt.kcw-ss-on { background: var(--brand-light); color: var(--brand); }
.kcw-ss-group { padding: 6px 12px 2px; font-size: .78rem; font-weight: 700; color: var(--muted); background: #f8fafc; position: sticky; top: 0; }
