/* ======================================
   style.css — Fixed Sidebar Layout
   ====================================== */

@import url('https://fonts.googleapis.com/css2?family=Sarabun:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,400;1,600&family=Noto+Sans+Thai:wght@300;400;500;600;700;800&family=Prompt:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,400;1,600&display=swap');

/* ======== Variables (โทนสีใหม่: น้ำเงิน-ชมพู หรูหรา วิชาการ ทันสมัย) ======== */
:root {
    /* ---- Fonts (ฟอนต์ระบบ Google Font: Sarabun, Noto Sans Thai & Prompt) ---- */
    --font-main: 'Sarabun', 'Noto Sans Thai', 'Prompt', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

    /* ---- Color Palette (น้ำเงิน / ชมพู / สกายบลู / ขาวบริสุทธิ์) ---- */
    --c1: #F8FAFC;   /* ฟ้าอมเทาอ่อนสะอาดตา — page bg, inputs */
    --c2: #FFFFFF;   /* ขาว — card bg, topbar */
    --c3: #E2E8F0;   /* เส้นขอบอ่อนนุ่มสะอาดตา — borders, dividers */
    --c4: #1E3A8A;   /* น้ำเงินเข้มรอยัลบลู — primary, accent, header */
    --c-pink: #EC4899; /* ชมพูโรสพิงค์สดใส — badge, hover, highlights */
    --c-pink-dark: #DB2777; /* ชมพูเข้มหรูหรา */
    --c-pink-light: #FCE7F3; /* ชมพูอ่อนละมุน — badge light bg */
    --c-text: #0F172A;              /* สีข้อความหลัก — Slate Dark */
    --c-text-muted: #64748B;        /* สีข้อความจาง — Muted Slate */
    --c-text-light: #FFFFFF;        /* สีข้อความบนพื้นหลังเข้ม */

    /* ---- Sidebar ---- */
    --sidebar-w: 240px;
    --sidebar-bg: #0F172A;          /* Deep Midnight Royal Blue */
    --sidebar-hover: rgba(236, 72, 153, 0.14); /* Soft Pink Hover Glow */
    --sidebar-active: linear-gradient(135deg, #1E40AF 0%, #EC4899 100%);
    --sidebar-text: #94A3B8;
    --sidebar-text-bright: #F8FAFC;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-section: #EC4899;

    /* ---- Topbar ---- */
    --topbar-h: 58px;
    --topbar-bg: var(--c2);
    --topbar-border: #E2E8F0;

    /* ---- Layout ---- */
    --bg: var(--c1);
    --card-bg: var(--c2);
    --text: var(--c-text);
    --text-muted: var(--c-text-muted);
    --border: var(--c3);

    /* ---- Semantic ---- */
    --primary: #1E3A8A;
    --primary-dark: #1E293B;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --info: #06B6D4;
    --purple: #8B5CF6;
    --pink: #EC4899;

    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow:    0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-md: 0 10px 25px rgba(15, 23, 42, 0.12);
    --radius: 12px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
body, input, button, select, textarea, optgroup, option, table, th, td, h1, h2, h3, h4, h5, h6, p, a, label, span, .btn, .form-control, .modal, .custom-modal-box, .swal2-popup {
    font-family: var(--font-main);
}
body {
    background: var(--bg);
    color: var(--c-text);
    line-height: 1.6;
    min-height: 100vh;
}
a { text-decoration: none; color: inherit; }

/* Ensure Font Awesome always renders properly */
.fa, .fas, .far, .fab, .fa-solid, .fa-regular, .fa-brands, [class^="fa-"], [class*=" fa-"], i[class*="fa"] {
    font-family: "Font Awesome 6 Free", "Font Awesome 6 Brands" !important;
    font-style: normal;
}
.fa-brands, .fab {
    font-family: "Font Awesome 6 Brands" !important;
}

/* ===================== SIDEBAR ===================== */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 200;
    transition: transform 0.28s cubic-bezier(.4,0,.2,1);
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}
.sidebar-brand-icon { font-size: 1.4rem; flex-shrink: 0; line-height: 1; }
.sidebar-brand-name {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--sidebar-text-bright);
    line-height: 1.25;
}
.sidebar-brand-sub {
    display: block;
    font-size: 0.7rem;
    color: var(--sidebar-section);
    margin-top: 1px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 6px;
    scrollbar-width: thin;
    scrollbar-color: rgba(236, 72, 153, 0.4) transparent;
}
.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}
.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(236, 72, 153, 0.4);
    border-radius: 4px;
}
.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-section-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #F472B6;
    padding: 6px 8px 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.sidebar-section-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(244, 114, 182, 0.25);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 6px;
    margin-bottom: 1px;
    color: var(--sidebar-text);
    font-size: 0.83rem;
    font-weight: 400;
    transition: background 0.15s, color 0.15s;
}
.sidebar-link:hover { background: var(--sidebar-hover); color: #F472B6; }
.sidebar-link.active {
    background: var(--sidebar-active);
    color: var(--c-text-light);
    font-weight: 500;
    box-shadow: 0 2px 10px rgba(236, 72, 153, 0.35);
}
.sidebar-icon { font-size: 0.88rem; flex-shrink: 0; width: 18px; text-align: center; }
.sidebar-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Submenu Dropdown in Sidebar */
.sidebar-dropdown {
    margin-bottom: 2px;
}
.sidebar-dropdown-toggle {
    cursor: pointer;
    position: relative;
}
.sidebar-caret {
    font-size: 0.72rem;
    margin-left: auto;
    transition: transform 0.2s ease;
    opacity: 0.75;
}
.sidebar-dropdown.open .sidebar-caret {
    transform: rotate(180deg);
}
.sidebar-link.parent-active {
    color: #F472B6;
    background: rgba(236, 72, 153, 0.12);
    font-weight: 600;
}
.sidebar-submenu {
    padding-left: 10px;
    margin: 3px 0 6px 14px;
    border-left: 1.5px solid rgba(244, 114, 182, 0.35);
}
.sidebar-sublink {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 6px;
    margin-bottom: 2px;
    color: var(--sidebar-text);
    font-size: 0.78rem;
    font-weight: 400;
    text-decoration: none;
    transition: all 0.15s ease-in-out;
}
.sidebar-sublink:hover {
    background: var(--sidebar-hover);
    color: #F472B6;
}
.sidebar-sublink.active {
    background: linear-gradient(135deg, #2563EB 0%, #3B82F6 100%);
    color: #FFF !important;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}
.sidebar-subicon {
    font-size: 0.78rem;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}
.sidebar-sublabel {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}
.sidebar-user { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.sidebar-user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563EB 0%, #EC4899 100%);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.95rem; font-weight: 600; color: var(--c-text-light); flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(236, 72, 153, 0.3);
}
.sidebar-user-info { display: flex; flex-direction: column; min-width: 0; }
.sidebar-user-name {
    font-size: 0.82rem; font-weight: 500;
    color: var(--sidebar-text-bright);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-bell {
    position: relative;
    width: 32px; height: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.05rem; color: var(--sidebar-text);
    transition: background 0.15s, color 0.15s, transform 0.15s; flex-shrink: 0;
    text-decoration: none;
}
.sidebar-bell:hover { background: rgba(245, 158, 11, 0.2); color: #FBBF24; }
.sidebar-bell.has-unread { color: #FBBF24; }
.sidebar-bell .sidebar-bell-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
    color: #FFFFFF;
    font-size: 0.60rem;
    font-weight: 800;
    min-width: 17px;
    height: 17px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    box-shadow: 0 0 0 2px var(--sidebar-bg, #0F172A), 0 2px 4px rgba(0, 0, 0, 0.3);
    line-height: 1;
    animation: bellBadgePulse 2s infinite;
}
.sidebar-logout {
    width: 32px; height: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; color: var(--sidebar-text);
    transition: background 0.15s, color 0.15s; flex-shrink: 0;
}
.sidebar-logout:hover { background: rgba(236, 72, 153, 0.2); color: #F472B6; }

/* ===================== MAIN WRAPPER ===================== */
.main-wrapper {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.28s cubic-bezier(.4,0,.2,1);
}

.topbar {
    position: sticky; top: 0; z-index: 100;
    height: var(--topbar-h);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}
.topbar-title { font-size: 1.1rem; font-weight: 600; color: var(--c-text); }
.topbar-date {
    font-size: 0.85rem; color: var(--c-text-muted);
    background: var(--c1); padding: 5px 12px;
    border-radius: 20px; border: 1px solid var(--border);
}

.main-content { flex: 1; padding: 28px; max-width: 1300px; width: 100%; }

/* Mobile toggle */
.sidebar-toggle {
    display: none; position: fixed;
    top: 12px; left: 12px; z-index: 300;
    width: 38px; height: 38px; border-radius: 8px;
    background: var(--sidebar-bg); border: none; cursor: pointer;
    flex-direction: column; align-items: center; justify-content: center;
    gap: 5px; padding: 8px; box-shadow: var(--shadow);
}
.sidebar-toggle span {
    display: block; width: 18px; height: 2px;
    background: rgba(255,255,255,0.8); border-radius: 2px;
}
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.45); z-index: 190;
    opacity: 0; transition: opacity 0.25s;
    pointer-events: none;
}
.sidebar-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

/* ===================== LOGIN PAGE ===================== */
.login-page {
    background: linear-gradient(135deg, #0A192F 0%, #1E3A8A 55%, #EC4899 100%);
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 20px;
}
.login-container { width: 100%; max-width: 420px; padding: 0 12px; }
.login-box {
    background: #FFFFFF; border-radius: 18px;
    padding: 44px 40px;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.35);
    border-top: 5px solid #EC4899;
}
.login-logo { text-align: center; margin-bottom: 32px; }
.school-icon { font-size: 3rem; margin-bottom: 8px; }
.login-logo h1 { font-size: 1.4rem; font-weight: 700; color: var(--text); }
.login-logo p  { color: var(--c-text-muted); font-size: 0.9rem; margin-top: 4px; }
.login-footer  { text-align: center; margin-top: 20px; color: var(--c-text-muted); }

/* ===================== PAGE HEADER ===================== */
.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 1.5rem; font-weight: 700; color: var(--c-text); }
.page-header p  { color: var(--c-text-muted); margin-top: 4px; font-size: 0.9rem; }

/* ===================== CARDS ===================== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}
.card-header {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(90deg, #F8FAFC 0%, #F1F5F9 100%);
    flex-wrap: wrap; gap: 8px;
}
.card-header h3 { font-size: 0.97rem; font-weight: 600; color: var(--c-text); }
.card-body { padding: 20px; overflow-x: auto; }
.mt-4 { margin-top: 24px; }
.mb-4 { margin-bottom: 24px; }

/* ===================== STATS ===================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
    gap: 16px; margin-bottom: 24px;
}
.stats-small {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    margin-bottom: 16px;
}
.stat-card {
    background: #FFFFFF; border-radius: var(--radius);
    padding: 20px 16px; text-align: center;
    box-shadow: var(--shadow-sm); border: 1px solid var(--c3);
    border-top: 4px solid;
    transition: box-shadow 0.2s, transform 0.2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-card.stat-blue   { border-top-color: #1E3A8A; }
.stat-card.stat-pink   { border-top-color: #EC4899; }
.stat-card.stat-green  { border-top-color: var(--success); }
.stat-card.stat-red    { border-top-color: var(--danger); }
.stat-card.stat-yellow { border-top-color: var(--warning); }
.stat-card.stat-purple { border-top-color: var(--purple); }
.stat-card.stat-info   { border-top-color: var(--info); }

/* ===================== TABLE ===================== */
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th {
    background: #F1F5F9; padding: 10px 14px; text-align: left;
    font-weight: 600; border-bottom: 2px solid var(--border);
    white-space: nowrap; color: #475569;
    font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.5px;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--c3); vertical-align: middle; }
.table tr:hover td { background: #F8FAFC; }
.table tr:last-child td { border-bottom: none; }

/* ===================== BADGES ===================== */
.badge {
    display: inline-block; padding: 3px 10px;
    border-radius: 100px; font-size: 0.75rem; font-weight: 600;
}
.badge-primary { background: #DBEAFE; color: #1E40AF; }
.badge-pink    { background: #FCE7F3; color: #BE185D; }
.badge-success { background: #D1FAE5; color: #065F46; }
.badge-danger  { background: #FEE2E2; color: #991B1B; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-info    { background: #E0F2FE; color: #0369A1; }
.badge-purple  { background: #F5F3FF; color: #6D28D9; border: 1px solid #DDD6FE; }
.badge-indigo  { background: #EEF2FF; color: #4338CA; border: 1px solid #C7D2FE; }
.badge-emerald { background: #ECFDF5; color: #047857; border: 1px solid #A7F3D0; }
.badge-slate   { background: #F1F5F9; color: #334155; border: 1px solid #CBD5E1; }

/* ===================== BUTTONS ===================== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 18px; border-radius: 8px;
    font-family: inherit; font-size: 0.88rem; font-weight: 500;
    border: none; cursor: pointer; text-decoration: none;
    transition: all 0.18s; white-space: nowrap; line-height: 1.4;
}
.btn-primary {
    background: linear-gradient(135deg, #1E3A8A 0%, #2563EB 100%);
    color: #FFFFFF; font-weight: 600;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}
.btn-primary:hover {
    background: linear-gradient(135deg, #1E293B 0%, #1D4ED8 100%);
    color: #FFFFFF;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}
.btn-pink {
    background: linear-gradient(135deg, #EC4899 0%, #DB2777 100%);
    color: #FFFFFF; font-weight: 600;
    box-shadow: 0 2px 6px rgba(236, 72, 153, 0.25);
}
.btn-pink:hover {
    background: linear-gradient(135deg, #DB2777 0%, #9D174D 100%);
    color: #FFFFFF;
    box-shadow: 0 4px 14px rgba(236, 72, 153, 0.4);
}
.btn-success { background: var(--success); color: white; }
.btn-danger  { background: var(--danger);  color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline { background: transparent; color: var(--c4); border: 1.5px solid var(--c4); }
.btn-outline:hover { background: var(--c4); color: white; }
.btn-outline-pink { background: transparent; color: #EC4899; border: 1.5px solid #EC4899; }
.btn-outline-pink:hover { background: #EC4899; color: white; }
.btn-sm  { padding: 4px 12px; font-size: 0.8rem; }
.btn-lg  { padding: 12px 28px; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===================== FORMS ===================== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 6px; font-size: 0.88rem; }
.form-control {
    width: 100%; padding: 9px 14px;
    border: 1.5px solid var(--border); border-radius: 8px;
    font-family: inherit; font-size: 0.88rem;
    background: var(--c1); color: var(--c-text);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus { outline: none; border-color: #2563EB; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2); }
.form-control-sm { padding: 5px 10px; font-size: 0.82rem; }
.form-inline { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.form-inline .form-group { margin-bottom: 0; }
.form-inline .form-group label { font-size: 0.82rem; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 150px; }
.form-row .col-3 { flex: 0 0 calc(25% - 12px); }
.form-row .col-4 { flex: 0 0 calc(33.33% - 12px); }

/* ===================== ALERTS ===================== */
.alert { padding: 13px 18px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; }
.alert-success { background: #d1fae5; color: #14532d; border-left: 4px solid #16a34a; }
.alert-danger  { background: #FFD1D1; color: #7f1d1d; border-left: 4px solid #dc2626; }
.alert-warning { background: #fef3c7; color: #78350f; border-left: 4px solid #d97706; }
.alert-info    { background: #e0f2fe; color: #0c4a6e; border-left: 4px solid #0891b2; }

/* ===================== ATTENDANCE ===================== */
.attendance-summary { display: flex; gap: 10px; padding: 12px 0; margin-bottom: 12px; flex-wrap: wrap; }
.attendance-summary .badge { font-size: 0.9rem; padding: 6px 16px; }

.status-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.status-btn {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 5px 12px; border-radius: 6px;
    font-size: 0.8rem; font-weight: 500;
    cursor: pointer; border: 1.5px solid transparent;
    transition: all 0.15s; user-select: none;
}
.status-btn input[type="radio"] { display: none; }
.status-btn.present        { background:#f0fdf4; color:#166534; border-color:#dcfce7; }
.status-btn.present.active { background:#16a34a; color:white;   border-color:#16a34a; }
.status-btn.absent         { background:#fff1f2; color:#991b1b; border-color:#fee2e2; }
.status-btn.absent.active  { background:#dc2626; color:white;   border-color:#dc2626; }
.status-btn.late           { background:#fffbeb; color:#854d0e; border-color:#fef3c7; }
.status-btn.late.active    { background:#d97706; color:white;   border-color:#d97706; }
.status-btn.leave          { background:#f0f9ff; color:#075985; border-color:#e0f2fe; }
.status-btn.leave.active   { background:#0891b2; color:white;   border-color:#0891b2; }

.student-row[data-status="absent"] td { background: #fff8f8 !important; }
.student-row[data-status="late"]   td { background: #fffdf0 !important; }
.student-row[data-status="leave"]  td { background: #f0f9ff !important; }

/* ===================== PROGRESS BAR ===================== */
.progress-bar { height: 7px; background: #e9ecef; border-radius: 99px; overflow: hidden; margin-bottom: 4px; min-width: 80px; }
.progress-fill    { height: 100%; border-radius: 99px; }
.progress-success { background: #2d8a4e; }
.progress-warning { background: var(--warning); }
.progress-danger  { background: var(--danger); }

/* ===================== UTILITIES ===================== */
.text-center { text-align: center; }
.text-muted  { color: var(--c-text-muted); }
.text-danger { color: var(--danger); }

/* ===================== FOOTER ===================== */
.footer {
    text-align: center; padding: 20px 28px;
    color: var(--c-text-muted); font-size: 0.82rem;
    border-top: 1px solid var(--border);
    background: var(--card-bg); margin-top: auto;
}

/* ===================== PRINT ===================== */
@media print {
    .sidebar, .topbar, .sidebar-toggle, .btn, form, .page-header p { display: none !important; }
    .main-wrapper { margin-left: 0 !important; }
    .card { box-shadow: none; border: 1px solid #ddd; }
    body { background: white; }
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.25); }
    .sidebar-overlay { display: block; pointer-events: none; }
    .sidebar-overlay.show { pointer-events: auto; }
    .main-wrapper { margin-left: 0; }
    .sidebar-toggle { display: flex; }
    .topbar { padding-left: 60px; }
    .main-content { padding: 20px 16px; }
}
@media (max-width: 600px) {
    .stats-grid { grid-template-columns: repeat(2,1fr); gap: 12px; }
    .form-row   { flex-direction: column; }
    .form-row .col-3, .form-row .col-4 { flex: 1 1 auto; }
    .status-buttons { flex-direction: column; }
    .table { font-size: 0.8rem; }
    .table th, .table td { padding: 8px 10px; }
    .btn-group { flex-direction: column; }
    .form-inline { flex-direction: column; align-items: stretch; }
}

/* ===== Table Summary Row ===== */
tfoot .table-summary td {
    background: #EFF6FF;
    border-top: 2px solid #1E3A8A;
    font-size: 0.88rem;
    font-weight: 600;
    color: #1E3A8A;
    padding: 12px 14px;
}

/* ===== Font Awesome Flat/Glyph Icons ===== */
.fa-solid {
    font-size: 0.95em;
    line-height: 1;
    vertical-align: -0.1em;
}

/* ขนาดใน sidebar */
.sidebar-icon .fa-solid {
    font-size: 1rem;
}

/* ขนาดใน buttons */
.btn .fa-solid {
    font-size: 0.85em;
}

/* ขนาดใน badge/alert */
.badge .fa-solid,
.alert .fa-solid {
    font-size: 0.85em;
}

/* login icon */
.school-icon .fa-solid {
    font-size: 2.8rem;
    color: #EC4899;
}

/* stat card icon (ถ้ามี) */
.stat-icon .fa-solid {
    font-size: 1.6rem;
    color: #1E3A8A;
}

/* topbar date icon */
.topbar-date .fa-solid {
    margin-right: 4px;
    color: #EC4899;
}

/* sidebar active icon color */
.sidebar-link.active .fa-solid {
    color: var(--c-text-light);
}

/* icon in table actions */
.table .fa-solid {
    font-size: 0.82em;
}

/* ===== Page Loader ===== */
#page-loader {
    position: fixed;
    inset: 0;
    background: var(--c1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

#page-loader.hide {
    opacity: 0;
    visibility: hidden;
}

.loader-logo {
    font-size: 2.2rem;
    color: #EC4899;
    margin-bottom: 20px;
    animation: loaderPulse 1.2s ease-in-out infinite;
}

.loader-bar {
    width: 180px;
    height: 4px;
    background: #E2E8F0;
    border-radius: 99px;
    overflow: hidden;
}

.loader-bar-fill {
    height: 100%;
    border-radius: 99px;
    background: linear-gradient(90deg, #1E3A8A 0%, #EC4899 100%);
    animation: loaderSlide 1s ease-in-out infinite;
}

.loader-text {
    margin-top: 14px;
    font-size: 0.82rem;
    color: var(--c-text-muted);
    font-family: var(--font-main);
    letter-spacing: 0.03em;
}

@keyframes loaderPulse {
    0%, 100% { transform: scale(1);   opacity: 1; }
    50%       { transform: scale(1.1); opacity: 0.7; }
}

@keyframes loaderSlide {
    0%   { width: 0%;   margin-left: 0; }
    50%  { width: 70%;  margin-left: 0; }
    100% { width: 0%;   margin-left: 100%; }
}

/* fade-in เนื้อหา */
.main-wrapper, .login-container, .change-pw-page {
    animation: pageFadeIn 0.35s ease forwards;
}

@keyframes pageFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* =====================================================
   RESPONSIVE — COMPREHENSIVE UPDATE
   ===================================================== */

/* ---- ป้องกัน overflow แนวนอนทั้งระบบ ---- */
html, body { overflow-x: hidden; }
.main-wrapper { overflow-x: hidden; }

/* ---- ตารางให้ scroll แนวนอนบนจอเล็ก ---- */
.card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { min-width: 500px; }

/* ---- form-inline บนมือถือให้ wrap ---- */
.form-inline { flex-wrap: wrap; }

/* ===================== Tablet (≤900px) ===================== */
@media (max-width: 900px) {
    /* Topbar */
    .topbar-date { display: none; }

    /* Stats */
    .stats-grid { grid-template-columns: repeat(3, 1fr); }

    /* Page header */
    .page-header { margin-bottom: 16px; }
    .page-header h2 { font-size: 1.25rem; }

    /* Card */
    .card-header { flex-wrap: wrap; gap: 8px; }
    .main-content { padding: 16px; }
}

/* ===================== Mobile (≤600px) ===================== */
@media (max-width: 600px) {
    /* Stats */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-number { font-size: 1.6rem; }

    /* Topbar */
    .topbar { height: auto; min-height: 50px; padding: 10px 16px 10px 56px; }
    .topbar-title { font-size: 0.95rem; }

    /* Page header */
    .page-header h2 { font-size: 1.1rem; }
    .page-header[style*="display:flex"] { flex-direction: column; align-items: flex-start !important; }

    /* Card */
    .card-header h3 { font-size: 0.88rem; }
    .card-body { padding: 14px 12px; }

    /* Form */
    .form-row { flex-direction: column; }
    .form-row > * { flex: 1 1 auto !important; width: 100% !important; min-width: unset !important; }
    .form-group[style*="flex:0 0"] { flex: 1 1 auto !important; }
    .form-inline { flex-direction: column; align-items: stretch; }
    .form-inline .form-group { width: 100%; }
    .form-inline .form-control { width: 100%; }

    /* Buttons */
    .btn-lg { padding: 10px 18px; font-size: 0.9rem; }
    .btn-group { flex-wrap: wrap; }
    .card-header .btn { font-size: 0.78rem; padding: 4px 10px; }

    /* Table */
    .table { font-size: 0.78rem; min-width: 420px; }
    .table th, .table td { padding: 7px 8px; }

    /* Attendance status buttons */
    .status-buttons { flex-wrap: wrap; gap: 4px; }
    .status-btn { padding: 4px 8px; font-size: 0.75rem; }

    /* Attendance summary badges */
    .attendance-summary { gap: 6px; }
    .attendance-summary .badge { font-size: 0.8rem; padding: 5px 10px; }

    /* Modal / inline forms */
    .form-group[style*="max-width"] { max-width: 100% !important; }

    /* Login */
    .login-box { padding: 28px 20px; }

    /* Sidebar toggle visibility */
    .sidebar-toggle { top: 8px; left: 8px; width: 34px; height: 34px; }
}

/* ===================== Small Mobile (≤400px) ===================== */
@media (max-width: 400px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-number { font-size: 1.4rem; }
    .stat-label { font-size: 0.75rem; }
    .main-content { padding: 12px 10px; }
    .table { font-size: 0.72rem; min-width: 360px; }
    .table th, .table td { padding: 5px 6px; }
}

/* ===================== NOTIFICATION BELL & BADGE ===================== */
.topbar-bell-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #FFFFFF;
    color: #475569;
    border: 1.5px solid #E2E8F0;
    font-size: 1.05rem;
    text-decoration: none;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    flex-shrink: 0;
}
.topbar-bell-btn:hover {
    background: #F8FAFC;
    color: #1E3A8A;
    border-color: #94A3B8;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0,0,0,0.08);
}
.topbar-bell-btn.has-unread {
    color: #1E3A8A;
    border-color: #BFDBFE;
    background: #EFF6FF;
}
.topbar-bell-btn .bell-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
    color: #FFFFFF;
    font-size: 0.68rem;
    font-weight: 800;
    min-width: 19px;
    height: 19px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid #FFFFFF;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.45);
    animation: bellBadgePulse 2s infinite;
}
@keyframes bellBadgePulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.12); }
    100% { transform: scale(1); }
}
