/* ============================================================
   1. GLOBAL VARIABLES & RESET
   ============================================================ */
:root {
    --primary-color: #A51C30;
    --primary-dark: #800020;
    --secondary-color: #6c757d;
    --bg-body: #f8f9fa;
    --text-main: #333;
    
    /* Dimensions */
    --topbar-height: 60px;
    --sidebar-width: 250px;
    --sidebar-collapsed-width: 70px;

    /* Z-Index Hierarchy (สำคัญมาก ห้ามแก้) */
    --z-content: 1;
    --z-topbar: 1030;
    --z-sidebar: 1040;
    --z-backdrop: 1050;
    --z-modal: 1060;
    --z-swal: 1070;
    --z-overlay: 9999;
}

body {
    font-family: 'Sarabun', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    font-size: 0.95rem;
    padding-top: calc(var(--topbar-height) + 20px);
    transition: margin-left 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); /* Smooth transition */
    overflow-x: hidden;
}

/* Custom Text Utils */
.text-brown { color: #8B4513 !important; }
.text-primary { color: var(--primary-color) !important; }
.fw-bold { font-weight: 600 !important; }
.fw-extrabold { font-weight: 800 !important; }
.x-small { font-size: 0.75rem; color: #6c757d; font-weight: bold; }
.small, small { font-size: 0.85rem; }

/* ============================================================
   2. LOGIN PAGE STATE (ปรับปรุง Google Logo & Background Animation)
   ============================================================ */
body.login-state {
    padding: 0 !important; margin: 0 !important;
    background-color: #fcfcfc; height: 100vh; overflow: hidden;
    display: flex; flex-direction: column;
}

body.login-state .topbar, 
body.login-state .sidebar, 
body.login-state #studentDashboard, 
body.login-state #adminDashboard, 
body.login-state #loadingOverlay { display: none !important; }

#loginPageWrapper {
    display: none; flex-direction: column; justify-content: center; align-items: center;
    flex-grow: 1; width: 100%; position: relative;
    background: radial-gradient(circle at center, #ffffff 0%, #f8f9fa 100%);
}
body.login-state #loginPageWrapper { display: flex; }

/* 🌟 ส่วนแก้ไข: แอนิเมชั่นอีโมจิเก้าอี้ลอย */
.floating-background {
    position: absolute; width: 100%; height: 100%;
    top: 0; left: 0; overflow: hidden; pointer-events: none; z-index: 0;
}
.float-icon {
    position: absolute; 
    opacity: 0.07; /* ปรับความจางของอีโมจิ */
    font-size: 3rem; /* ขนาดเริ่มต้น */
    animation: floatAnim 10s ease-in-out infinite;
    user-select: none; /* ห้ามลากคลุมดำ */
}
@keyframes floatAnim {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-25px) rotate(15deg); }
}

.login-card-custom {
    width: 100%; max-width: 420px; border: none; border-radius: 24px !important;
    background: rgba(255, 255, 255, 0.95); /* พื้นหลังโปร่งแสงนิดๆ */
    box-shadow: 0 20px 60px rgba(0,0,0,0.08);
    padding: 50px 30px; text-align: center; margin-top: -50px; 
    overflow: hidden; animation: slideUp 0.6s ease-out;
    position: relative; z-index: 1;
    backdrop-filter: blur(5px); /* เพิ่มความเบลอหลังการ์ด */
}

/* 🌟 ส่วนแก้ไข: โลโก้ ENG แบบสี่เหลี่ยม */
.login-logo-img { 
    width: auto; height: 120px; /* ปรับขนาดให้เหมาะสม */
    object-fit: contain; 
    border-radius: 0; /* ❌ เอาวงกลมออก */
    box-shadow: none; /* ❌ เอาเงาออก */
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
    margin-bottom: 10px;
}
.login-logo-img:hover { transform: scale(1.1); }

.sys-title-main { font-size: 1.8rem; font-weight: 800; color: #C02F1D; line-height: 1.3; margin-bottom: 5px; }
.sys-title-sub { font-size: 1.2rem; font-weight: 600; color: #555; margin-bottom: 15px; }

.btn-google {
    background-color: #ffffff; color: #333; border: 1px solid #dadce0; border-radius: 8px;
    padding: 2px 2px 2px 2px; font-weight: 600; font-size: 1rem;
    display: flex; align-items: center; justify-content: center; gap: 15px;
    transition: all 0.2s ease; width: 100%; cursor: pointer; max-width: 280px; margin: 0 auto;
}
.google-icon-wrapper {
    background: white; padding: 10px; display: flex; align-items: center; justify-content: center;
    border-top-left-radius: 8px; border-bottom-left-radius: 8px;
}
.btn-google img { width: 20px; height: 20px; }

.btn-google:hover { 
    background-color: #f8f9fa; 
    box-shadow: 0 1px 3px rgba(60,64,67,0.3), 0 4px 8px 3px rgba(60,64,67,0.15); 
}
.btn-google:active { background-color: #eeeeee; transform: scale(0.98); }

.login-footer-text {
    width: 100%; text-align: center; font-size: 0.8rem; color: #888;
    padding: 20px; background: transparent; position: absolute; bottom: 0; left: 0; line-height: 1.6; z-index: 1;
}


/* ============================================================
   3. LAYOUT & NAVIGATION
   ============================================================ */
.topbar {
    background: #ffffff; box-shadow: 0 4px 12px rgba(0,0,0,0.03); height: var(--topbar-height);
    position: fixed; top: 0; right: 0; left: 0; z-index: var(--z-topbar);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; transition: left 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: var(--sidebar-width);
    background: #ffffff; box-shadow: 4px 0 15px rgba(0,0,0,0.03); z-index: var(--z-sidebar);
    transition: width 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), transform 0.3s ease;
    overflow-x: hidden; display: flex; flex-direction: column;
}

.sidebar-header {
    height: var(--topbar-height); display: flex; align-items: center; padding: 0 20px;
    border-bottom: 1px solid #f0f0f0; overflow: hidden; white-space: nowrap;
}
.sidebar-header img { width: 40px; border-radius: 50%; margin-right: 12px; cursor: pointer; transition: 0.2s; flex-shrink: 0; }
.sidebar-header .brand-text { font-weight: 700; color: var(--primary-color); line-height: 1.1; }

/* Collapsed State */
.sidebar.collapsed { width: var(--sidebar-collapsed-width); }
.sidebar.collapsed .brand-text { display: none; }
.sidebar.collapsed .sidebar-header { padding: 0; justify-content: center; }
.sidebar.collapsed .sidebar-header img { margin-right: 0 !important; }
.sidebar.collapsed .sidebar-menu .nav-link span { display: none; }
.sidebar.collapsed .sidebar-menu .nav-link { justify-content: center; padding: 12px 0; }
.sidebar.collapsed .sidebar-menu .nav-link i { margin-right: 0; }

body.sidebar-collapsed { margin-left: var(--sidebar-collapsed-width); }
body.sidebar-collapsed .topbar { left: var(--sidebar-collapsed-width); }

/* Responsive Sidebar */
@media (min-width: 992px) { 
    body { margin-left: var(--sidebar-width); } 
    .topbar { left: var(--sidebar-width); } 
}
@media (max-width: 991.98px) { 
    body { margin-left: 0 !important; } 
    .topbar { left: 0 !important; } 
    .sidebar { transform: translateX(-100%); } 
    .sidebar.mobile-show { transform: translateX(0); width: var(--sidebar-width); } 
}

.sidebar-menu { flex-grow: 1; padding: 15px 10px; overflow-y: auto; }
.sidebar-menu .nav-item { margin-bottom: 4px; list-style: none; }
.sidebar-menu .nav-link {
    display: flex; align-items: center; font-size: 0.95rem; padding: 10px 15px;
    border-radius: 10px; color: #555; text-decoration: none; white-space: nowrap;
    transition: all 0.2s ease;
}
.sidebar-menu .nav-link i { min-width: 25px; text-align: center; font-size: 1.1rem; margin-right: 15px; transition: margin 0.3s; }
.sidebar-menu .nav-link:hover { background-color: #f8f9fa; color: var(--primary-color); transform: translateX(3px); }
.sidebar-menu .nav-link.active { background-color: #fff0f2; color: var(--primary-color); font-weight: bold; }

/* Navbar User Profile */
.lang-switcher { display: flex; gap: 5px; align-items: center; margin-right: 15px; background: #f1f3f5; padding: 4px; border-radius: 25px; }
.lang-btn { background: transparent; border: none; font-size: 12px; font-weight: 600; color: #888; cursor: pointer; padding: 4px 10px; border-radius: 20px; transition: 0.2s; display: flex; align-items: center; gap: 6px; }
.lang-btn.active { background: #fff; color: var(--primary-color); box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.profile-img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }

/* ============================================================
   4. UI COMPONENTS (Smooth & Modern)
   ============================================================ */
/* General Elements */
.hidden { display: none !important; }
.cursor-pointer { cursor: pointer; }
.btn { border-radius: 50px !important; transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1); }
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn-primary { background-color: var(--primary-color); border-color: var(--primary-color); }
.btn-primary:hover { background-color: var(--primary-dark); border-color: var(--primary-dark); }

.form-control, .form-select { border-radius: 12px !important; padding: 10px 15px; border: 1px solid #dee2e6; transition: border-color 0.2s; }
.form-control:focus, .form-select:focus { border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(165, 28, 48, 0.1); }

.card { border-radius: 20px !important; overflow: hidden; border: none; box-shadow: 0 5px 20px rgba(0,0,0,0.03); transition: transform 0.2s ease; }
.main-card { margin-bottom: 20px; }

/* ============================================================
   STAT CARDS (การ์ดสถิติ Dashboard)
   ============================================================ */
.stat-card {
    border: none; 
    border-radius: 20px; /* เพิ่มความมนให้ดูทันสมัยขึ้น */
    padding: 25px 20px; 
    color: white;
    position: relative; 
    overflow: hidden; 
    box-shadow: 0 8px 20px rgba(0,0,0,0.08);
    cursor: pointer; 
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); 
    min-height: 130px; /* เพิ่มความสูงการ์ดนิดหน่อยให้รับกับเลขที่ใหญ่ขึ้น */
    display: flex; 
    flex-direction: column; 
    justify-content: center;
}

.stat-card:hover { 
    transform: translateY(-5px) scale(1.02); 
    box-shadow: 0 12px 30px rgba(0,0,0,0.15); 
}

/* --- ปรับขนาดตัวเลขให้ใหญ่และมีมิติ --- */
.stat-card h3 { 
    margin: 0 0 5px 0; 
    z-index: 2; 
    position: relative; 
    line-height: 1; 
}

/* ตัวเลขด้านใน (แก้ปัญหาเลขเล็ก) */
.stat-card h3 span {
    font-size: 3.5rem !important; /* ขยายตัวเลขให้ใหญ่สะใจ (เดิม 2.5) */
    font-weight: 800;
    text-shadow: 2px 3px 6px rgba(0,0,0,0.2); /* เพิ่มเงาให้ตัวเลขดูเด้งออกมา */
    opacity: 1;
}

/* --- ปรับขนาดตัวอักษรคำอธิบาย --- */
.stat-card > span { 
    font-size: 1.1rem; /* ขยายคำอธิบาย (เช่น "รออนุมัติ") ให้ชัดขึ้น */
    font-weight: 600; 
    opacity: 0.95; 
    z-index: 2; 
    position: relative; 
    letter-spacing: 0.5px;
}

/* --- ไอคอนพื้นหลัง --- */
.stat-card .stat-icon { 
    position: absolute; 
    right: -10px; 
    bottom: -15px; 
    font-size: 6.5rem; /* ขยายไอคอนจางๆ ให้ใหญ่ขึ้น */
    opacity: 0.15; 
    transform: rotate(-15deg); 
    transition: 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); 
}

.stat-card:hover .stat-icon { 
    transform: rotate(0deg) scale(1.1); 
    opacity: 0.25; 
}

.stat-card:hover { transform: translateY(-5px) scale(1.02); box-shadow: 0 12px 30px rgba(0,0,0,0.15); }
.stat-card h3 { font-weight: 800; margin: 0; font-size: 2.5rem; z-index: 2; position: relative; line-height: 1.1; }
.stat-card span { font-size: 0.95rem; font-weight: 500; opacity: 0.9; z-index: 2; position: relative; }
.stat-card .stat-icon { position: absolute; right: -10px; bottom: -10px; font-size: 5rem; opacity: 0.2; transform: rotate(-15deg); transition: 0.3s; }
.stat-card:hover .stat-icon { transform: rotate(0deg) scale(1.1); opacity: 0.3; }

/* Gradients */
.bg-gradient-primary { background: linear-gradient(135deg, #A51C30, #d6334c); }
.bg-gradient-warning { background: linear-gradient(135deg, #ffc107, #ffdb4d); color: #333 !important; }
.bg-gradient-info { background: linear-gradient(135deg, #0dcaf0, #39daff); color: #333 !important; }
.bg-gradient-success { background: linear-gradient(135deg, #198754, #28a745); }

/* Badges */
.status-badge { font-size: 0.8rem; padding: 5px 12px; border-radius: 20px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.st-pending { background-color: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.st-approved { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.st-changes { background-color: #cff4fc; color: #055160; border: 1px solid #b6effb; }
.st-rejected { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.st-cancelled { background-color: #e2e3e5; color: #383d41; border: 1px solid #d6d8db; }

/* Tables */
.table-responsive { border-radius: 16px; overflow: hidden; border: 1px solid #f0f0f0; }
.table { margin-bottom: 0; }
.table thead th { 
    background-color: #f8f9fa; color: #6c757d; font-weight: 600; 
    text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.5px; 
    border-bottom: 2px solid #eee; 
    padding: 12px 8px; /* ลด Padding ให้เล็กลง */
}
.table tbody td { 
    padding: 10px 8px; /* ลด Padding บน-ล่าง ซ้าย-ขวา */
    vertical-align: middle; color: #444; border-bottom: 1px solid #f5f5f5; 
}
.table-hover tbody tr:hover { background-color: #fafafa; }


/* ============================================================
   5. SPECIAL COMPONENTS (ROOMS, SEATS, ETC.)
   ============================================================ */

/* --- Modern Room Card --- */
.room-card-modern {
    background: #ffffff;
    border: 1px solid #eaecf0;
    border-radius: 16px !important;
    position: relative;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex; flex-direction: column;
    padding: 15px; min-height: 120px;
    overflow: visible !important;
    border-left: 5px solid transparent;
}
.room-card-modern:hover { transform: translateY(-5px); box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08); z-index: 5; }
.room-card-modern.status-active { border-left-color: #2ecc71; }
.room-card-modern.status-inactive { border-left-color: #95a5a6; background-color: #fafafa; opacity: 0.9; }

.room-name { font-size: 1.1rem; font-weight: 800; color: #2d3436; margin-bottom: 4px; line-height: 1.2; }
.room-info-text { font-size: 0.8rem; color: #636e72; font-weight: 500; margin-bottom: 10px; }
.card-bottom-row { margin-top: auto; display: flex; justify-content: space-between; align-items: center; padding-top: 8px; border-top: 1px dashed #f1f2f6; }
.seat-display { font-size: 0.85rem; font-weight: 700; color: #2d3436; background: #eef2f7; padding: 3px 10px; border-radius: 6px; }

/* Mini Toggle Switch */
.mini-switch .form-check-input { width: 32px !important; height: 18px !important; margin-top: 0; cursor: pointer; }
.mini-switch .form-check-input:checked { background-color: #2ecc71; border-color: #2ecc71; }

/* Menu Dots Button */
.btn-more-mini {
    position: absolute; top: 10px; right: 10px;
    width: 28px; height: 28px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    color: #b2bec3; border: none; background: transparent; transition: 0.2s; cursor: pointer;
}
.btn-more-mini:hover { background: #f1f2f6; color: var(--primary-color); }

/* --- Seat Map & Grid --- */
.seat-grid { 
    display: grid; gap: 6px; justify-content: center; padding: 25px; 
    background: #f8f9fa; border-radius: 16px; margin-top: 20px; 
    overflow-x: auto; border: 1px solid #eee; 
}
.grid-header-label { display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 0.9rem; color: #666; width: 40px; height: 40px; }
.seat { 
    width: 40px; height: 40px; background-color: #fff; 
    border: 1px solid #cbd5e0; border-radius: 8px; 
    display: flex; align-items: center; justify-content: center; 
    cursor: pointer; font-size: 10px; font-weight: bold; color: #666; 
    transition: all 0.2s; box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.seat:hover:not(.occupied) { transform: scale(1.15); border-color: var(--primary-color); z-index: 2; box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
.seat.selected { 
    background-color: #dc3545 !important; color: #fff !important; 
    border: 2px solid #a71d2a !important; transform: scale(1.1); 
    box-shadow: 0 0 12px rgba(220, 53, 69, 0.4); 
}
.seat.occupied { background-color: #e9ecef; color: #adb5bd; border-color: #dee2e6; cursor: not-allowed; }
.seat.my-seat { 
    background-color: #198754 !important; color: white !important; 
    border: 2px solid #146c43; transform: scale(1.1); z-index: 5; 
    box-shadow: 0 4px 10px rgba(25, 135, 84, 0.3); 
}

.screen-display { width: 80%; height: 8px; background: #495057; border-radius: 5px; margin: 0 auto 30px; position: relative; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
.screen-display::after { content: attr(data-text); position: absolute; top: -25px; left: 50%; transform: translateX(-50%); font-size: 11px; color: #495057; font-weight: bold; white-space: nowrap; }

/* ============================================================
   6. MODALS, ALERTS, & OVERLAYS (Z-INDEX FIX)
   ============================================================ */
/* Ensure Backdrop is correct */
.modal-backdrop { z-index: var(--z-backdrop) !important; }
.modal { z-index: var(--z-modal) !important; }

/* Modal Styling */
.modal-content { border-radius: 20px !important; border: none; box-shadow: 0 15px 40px rgba(0,0,0,0.2); }
.modal-header { border-bottom: 1px solid #f0f0f0; padding: 15px 25px; }
.modal-body { padding: 25px; }
.modal-footer { border-top: 1px solid #f0f0f0; padding: 15px 25px; }

/* SweetAlert Z-Index override */
div:where(.swal2-container) { z-index: var(--z-swal) !important; }
div:where(.swal2-popup) { border-radius: 24px !important; padding: 2em; }

/* Loading Overlay (Topmost) */
#loadingOverlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.85); /* Modern whitish blur */
    z-index: var(--z-overlay);
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(8px);
    transition: opacity 0.3s ease;
}
#loadingOverlay.hidden { display: none !important; }

/* Log Icons */
.log-icon-box { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-right: 15px; flex-shrink: 0; font-size: 1rem; }
.log-bg-success { background: #d4edda; color: #155724; }
.log-bg-warning { background: #fff3cd; color: #856404; }
.log-bg-danger { background: #f8d7da; color: #721c24; }
.log-bg-info { background: #cff4fc; color: #055160; }

/* ============================================================
   7. SYSTEM & UTILITY STYLES
   ============================================================ */
/* System Closed State */
.system-closed-wrapper { text-align: center; padding: 60px 20px; background: #ffffff; border-radius: 24px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); border: 1px solid #f0f0f0; max-width: 600px; margin: 40px auto; }
.closed-icon-bg { width: 100px; height: 100px; background: #fff5f5; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 25px; position: relative; }
.closed-icon-bg::after { content: ''; position: absolute; width: 120px; height: 120px; border: 1px dashed #ffcdd2; border-radius: 50%; animation: spin 20s linear infinite; }
.closed-contact-box { background: #f8f9fa; border-radius: 12px; padding: 15px; margin-top: 25px; font-size: 0.9rem; color: #666; border: 1px solid #eee; }

/* Headers Strip */
.section-header-strip {
    background: #ffffff; padding: 12px 20px; border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03); border-left: 6px solid #ccc;
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px; margin-top: 20px;
}
.header-active { border-left-color: #2ecc71; }
.header-inactive { border-left-color: #95a5a6; }

/* Pagination */
.pagination-custom .page-link { border: none; color: #6c757d; border-radius: 50%; width: 35px; height: 35px; display: flex; align-items: center; justify-content: center; margin: 0 3px; font-weight: 600; transition: all 0.2s; }
.pagination-custom .page-link:hover { background-color: #e9ecef; color: var(--primary-color); }
.pagination-custom .page-item.active .page-link { background-color: var(--primary-color); color: white; box-shadow: 0 2px 5px rgba(165, 28, 48, 0.3); }
.pagination-custom .page-item.disabled .page-link { opacity: 0.5; cursor: default; }

/* Animations */
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.5s ease-out forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Blur Effect for Session Timeout */
body.blur-active > *:not(.swal2-container) { filter: blur(8px) grayscale(80%); pointer-events: none; transition: all 0.5s ease; }
body.blur-active .swal2-container { background-color: rgba(0, 0, 0, 0.4) !important; }

/* ============================================================
   8. PRINT STYLES (Keep at bottom)
   ============================================================ */
.preview-wrapper { background-color: #525659; padding: 30px; height: 750px; overflow-y: auto; overflow-x: hidden; border-radius: 12px; display: flex; justify-content: center; }
.preview-sheet { width: 210mm; min-height: 297mm; background: white; box-shadow: 0 0 20px rgba(0,0,0,0.5); margin-bottom: 30px; padding: 15mm; box-sizing: border-box; display: flex; flex-direction: column; font-family: 'Sarabun', sans-serif; color: #000; position: relative; }
.print-logo { position: absolute; top: 10mm; left: 15mm; width: 60px; height: auto; }
.print-header-top { display: flex; justify-content: center; align-items: center; margin-bottom: 10px; position: relative; height: 40px; }
.print-title { font-size: 18pt; font-weight: bold; text-align: center; width: 100%; }
.print-return-note { font-size: 12pt; position: absolute; right: 0; top: 5px; }
.print-info-left { text-align: left; margin-left: 20px; margin-bottom: 15px; font-size: 14pt; line-height: 1.5; }
.front-room { border: 1px solid #000; width: 40%; margin: 0 auto 15px auto; text-align: center; padding: 2px; font-size: 14pt; background: #eee; }
.print-grid { display: grid; gap: 0; width: 100%; align-content: start; border: 1px solid #000; }
.print-seat { border: 1px solid #000; height: 75px; width: 100%; box-sizing: border-box; overflow: hidden; padding: 2px; position: relative; background: #fff; }
.seat-content { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; white-space: nowrap; line-height: 1.1; }
.seat-no { font-weight: bold; border-bottom: 1px solid #000; width: 100%; text-align: center; margin-bottom: 2px; padding-bottom: 1px; }
.print-row-label, .print-col-label { display: flex; align-items: center; justify-content: center; font-weight: bold; border: 1px solid #000; background: #f0f0f0; }
.print-footer { margin-top: auto; padding-top: 20px; text-align: center; font-size: 12pt; white-space: nowrap; width: 100%; }
.print-timestamp { font-size: 10pt; color: #666; margin-top: 5px; }
#printableArea { display: none; }

@media print {
    @page { size: A4 portrait; margin: 0; }
    body > * { display: none !important; }
    #printableArea { display: block !important; position: absolute; top: 0; left: 0; width: 100%; height: 100%; margin: 0; padding: 0; background: white; z-index: 99999; }
    .preview-sheet { box-shadow: none; margin: 0; width: 100%; height: 100%; padding: 15mm; page-break-after: always; border: none; }
    .preview-sheet:last-child { page-break-after: auto; }
    .print-grid, .print-seat, .front-room, .seat-no { border-color: #000 !important; color: #000 !important; }
}


/* ================== USER MANAGEMENT STYLES ================== */

/* Layout */
.user-manage-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}
.user-form-card {
    position: sticky;
    top: 100px; /* ให้ลอยตามเวลาเลื่อนหน้าจอ */
    z-index: 10;
}

/* Badges */
.badge-role {
    font-size: 0.8rem;
    padding: 6px 12px;
    border-radius: 50px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* 👑 Developer (Gold) */
.badge-dev {
    background: linear-gradient(135deg, #FFD700, #FDB931);
    color: #5a4a06;
    border: 1px solid #e6c200;
}

/* 🛡️ Admin Support (Blue) */
.badge-admin {
    background-color: #e7f1ff;
    color: #0d6efd;
    border: 1px solid #cce5ff;
}

/* 🎓 Student (Green) */
.badge-student {
    background-color: #d1e7dd;
    color: #0f5132;
    border: 1px solid #badbcc;
}

/* Action Buttons */
.btn-action-group {
    display: flex;
    justify-content: flex-end;
    gap: 5px;
}

/* Custom Text Colors for Table & Popups */
.text-blue { color: #0d6efd !important; }
.text-pink { color: #d63384 !important; }


/* ============================================================
   TIMELINE LOG STYLES (ประวัติการดำเนินการ)
   ============================================================ */
.custom-timeline {
    position: relative;
    padding-left: 40px;
    margin: 10px 0;
    list-style: none;
}

/* เส้นตรงแกนกลางของ Timeline */
.custom-timeline::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 20px;
    width: 3px;
    background: #e9ecef;
    border-radius: 3px;
}

.timeline-item {
    position: relative;
    margin-bottom: 25px;
}

.timeline-item:last-child {
    margin-bottom: 0;
}

/* วงกลมไอคอน */
.timeline-icon {
    position: absolute;
    left: -40px;
    top: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    z-index: 2;
    border: 3px solid #ffffff;
    box-shadow: 0 3px 8px rgba(0,0,0,0.1);
}

/* กล่องเนื้อหาประวัติ */
.timeline-content {
    background: #ffffff;
    padding: 15px;
    border-radius: 12px;
    border: 1px solid #f0f0f0;
    box-shadow: 0 4px 10px rgba(0,0,0,0.02);
    position: relative;
    transition: transform 0.2s ease;
}

.timeline-content:hover {
    transform: translateX(3px);
    border-color: #dee2e6;
}

/* สีพื้นหลังของไอคอนแต่ละสถานะ */
.tl-bg-primary { background-color: #0d6efd; color: #fff; }
.tl-bg-success { background-color: #198754; color: #fff; }
.tl-bg-warning { background-color: #ffc107; color: #212529; }
.tl-bg-danger { background-color: #dc3545; color: #fff; }
.tl-bg-info { background-color: #0dcaf0; color: #212529; }
.tl-bg-secondary { background-color: #6c757d; color: #fff; }

/* สีตัวอักษรของหัวข้อ */
.tl-text-primary { color: #0d6efd; }
.tl-text-success { color: #198754; }
.tl-text-warning { color: #d39e00; }
.tl-text-danger { color: #dc3545; }
.tl-text-info { color: #08a1be; }
.tl-text-secondary { color: #6c757d; }


/* ============================================================
   PRINT LAYOUT - ORIGINAL A4 STYLE (UPDATED V2)
   ============================================================ */
@page { size: A4 portrait; margin: 0; }

.a4-print-container {
    width: 210mm; min-height: 297mm; 
    padding: 10mm 15mm; 
    margin: 0 auto; background: white;
    box-shadow: 0 0 15px rgba(0,0,0,0.1); 
    box-sizing: border-box; position: relative;
    font-family: 'Sarabun', sans-serif; color: #000;
    display: flex; flex-direction: column;
}

@media print {
    body * { visibility: hidden; }
    #printableArea, #printableArea * { visibility: visible; }
    #printableArea { position: absolute; left: 0; top: 0; width: 100%; }
    .a4-print-container { box-shadow: none; margin: 0; page-break-after: always; }
}

.print-header-top {
    display: flex; justify-content: space-between; align-items: center; 
    margin-bottom: 10px; position: relative;
}
.print-logo-img { height: 45px; width: auto; } 
.print-main-title {
    font-size: 26px; font-weight: bold;
    position: absolute; left: 50%; transform: translateX(-50%);
}
.print-header-note { font-size: 20px; font-weight: bold; } 

/* 1. ปรับช่องว่างระหว่างข้อมูลวิชากับสี่เหลี่ยมหน้าห้องให้เล็กลง */
.print-room-info { font-size: 18px; font-weight: bold; line-height: 1.4; margin-bottom: 5px; }
.front-room-box { width: 200px; border: 2px solid #000; text-align: center; padding: 5px; margin: 5px auto 15px auto; font-weight: bold; font-size: 18px; }

/* ตารางและช่องว่าง */
.seat-grid-container {
    display: grid; gap: 8px; margin-bottom: 10px;
}

/* 4. คลาสสำหรับ Label แถวและคอลัมน์ (A,B,C / 1,2,3) */
.print-col-label, .print-row-label {
    display: flex; justify-content: center; align-items: center;
    font-weight: bold; font-size: 16px; color: #333;
}
.print-col-label { margin-bottom: 2px; }
.print-row-label { margin-right: 5px; }

.grid-seat-cell {
    aspect-ratio: 5 / 4; 
    border: 1px solid #000; 
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    padding: 2px; text-align: center; background: #fff; overflow: hidden;
}

/* 2. ปรับขนาดตัวหนังสือในช่องที่นั่ง */
.seat-label { font-size: 20px; margin-bottom: 3px; font-weight: 900; } /* เลขที่นั่งใหญ่สุด */
.student-id-box { font-size: 14px; font-weight: bold; width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.1; } /* รหัสนศ. */
.subject-info-box { font-size: 14px; margin-top: 2px; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; } /* รหัส-ตอน เท่ากับรหัสนศ. */

.print-footer-signature { text-align: center; font-size: 16px; margin-top: 20px; }

/* 3. Footer ชิดขอบล่างสุด และจัดกึ่งกลาง */
.print-meta-footer {
    text-align: center; font-size: 12px; color: #6c757d; 
    margin-top: auto; padding-top: 10px;
}




/* ============================================================
   9. MOBILE & TABLET RESPONSIVE PATCH (แพทช์แก้ไขมือถือ)
   ============================================================ */
@media (max-width: 991.98px) {
    /* 🌟 1. จัด Layout ของ Header ใน Sidebar ให้พอดีกับปุ่มปิด */
    .sidebar-header {
        justify-content: flex-start; 
        padding-right: 15px; 
    }
    
    /* 🌟 2. บังคับตารางให้มีแถบเลื่อนซ้าย-ขวา (Horizontal Scroll) */
    .table-responsive {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; /* ทำให้ใช้นิ้วไถได้ลื่นไหล */
        border-radius: 8px;
    }
    .table th, .table td {
        white-space: nowrap !important; /* ห้ามตัวหนังสือตัดขึ้นบรรทัดใหม่เด็ดขาด ให้ยืดออกไปเลย */
    }


/* 🌟 จัดการ Tabs ทุกอันในหน้าแอดมิน ให้ไถเลื่อนซ้ายขวาได้บนมือถือ */
    #roomTabs, #settingsTabs {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        border-radius: 12px !important; /* ปรับให้โค้งมนแบบแอปฯ แทนทรงแคปซูลยาวๆ */
        padding: 5px !important;
        justify-content: flex-start !important;
        width: 100%;
    }
    #roomTabs .nav-item, #settingsTabs .nav-item {
        flex: 0 0 auto; /* บังคับไม่ให้ปุ่มหดตัวจนเบียดกัน */
    }
    #roomTabs .nav-link, #settingsTabs .nav-link {
        white-space: nowrap; /* ห้ามข้อความในปุ่มตกบรรทัด */
    }
    /* ซ่อนแถบ Scrollbar ให้ดูสะอาดตา (ใช้ได้บน Chrome/Safari/iOS) */
    #roomTabs::-webkit-scrollbar, #settingsTabs::-webkit-scrollbar {
        height: 0px; 
        display: none;
    }

}

@media (max-width: 767.98px) {
    /* 🌟 3. ปรับขนาดการ์ดสถิติ (Stat Cards) ไม่ให้ล้นจอ */
    .stat-card {
        min-height: 90px;
        padding: 15px 12px;
        border-radius: 16px;
    }
    .stat-card h3 span {
        font-size: 2.2rem !important; /* ย่อขนาดตัวเลขลง */
    }
    .stat-card > span {
        font-size: 0.9rem; /* ย่อขนาดคำอธิบายลง */
    }
    .stat-card .stat-icon {
        font-size: 4rem; /* ย่อขนาดลายน้ำด้านหลัง */
        right: -5px; 
        bottom: -5px;
    }
    
    /* 🌟 จัดการ์ดสถิติให้แสดง 2 อันต่อแถวบนมือถือ (แบ่งครึ่งจอ) */
    #st-section-status > .row.g-3 > .col-md-3,
    #ad-section-req > .row.g-3 > .col-md-3 {
        width: 50%;
        flex: 0 0 50%;
    }

    /* 🌟 4. ปรับระยะขอบ (Padding) ลดความอ้วนของการ์ดเพื่อเพิ่มพื้นที่หน้าจอ */
    body {
        padding-top: calc(var(--topbar-height) + 10px);
    }
    .card-body {
        padding: 15px !important; 
    }

    /* 🌟 5. ปรับหน้า Login ให้เลื่อนขึ้นลงได้ กรณีจอมือถือเล็กมากๆ */
    body.login-state {
        overflow-y: auto !important;
        height: auto;
        min-height: 100vh;
    }
    .login-card-custom {
        margin-top: 20px;
        padding: 30px 20px;
    }
}


/* 🌟 แพทช์แก้ปัญหาขอบทะลักซ้าย-ขวา สำหรับ Master Card Layout */
.main-card .row {
    margin-left: 0 !important;
    margin-right: 0 !important;
}

.main-card .row > [class*="col-"] {
    padding-left: 10px !important;
    padding-right: 10px !important;
}

/* ปรับระยะห่างในการ์ดหลักให้เท่ากันทุกมุมในโหมด Mobile */
@media (max-width: 767.98px) {
    .main-card.p-4 {
        padding: 1rem !important; /* ปรับเป็น 16px บนมือถือเพื่อให้ประหยัดพื้นที่ */
    }
}




/* 🌟 ปรับรายละเอียดภายในการ์ดห้องสอบให้กะทัดรัด (Compact Room Card) */

/* 1. ปรับบรรทัด อาคาร/ชั้น และ แถว/คอลัมน์ */
.room-card-modern .room-info-text {
    font-size: 0.72rem !important; /* ย่อจาก 0.8rem ลงมาเพื่อให้พอดีบรรทัด */
    margin-bottom: 2px !important;  /* กระชับพื้นที่แนวตั้ง */
    white-space: nowrap;           /* บังคับให้อยู่บรรทัดเดียว ห้ามตัดขึ้นบรรทัดใหม่ */
    overflow: hidden;
    text-overflow: ellipsis;       /* ถ้าชื่อยาวเกินจริงๆ ให้ขึ้น ... แทนการล้นขอบ */
    opacity: 0.85;
}

/* 2. ปรับขนาดชื่อห้องสอบ (หัวข้อการ์ด) ให้เล็กลงนิดนึงเพื่อให้สมส่วน */
.room-card-modern .room-name {
    font-size: 0.95rem !important; /* ย่อจาก 1.1rem */
    margin-bottom: 4px !important;
}

/* 3. ปรับขนาด Badge "รวม XX ที่นั่ง" ด้านล่าง */
.room-card-modern .seat-display {
    font-size: 0.7rem !important;  /* ย่อตัวอักษรข้างใน */
    padding: 2px 6px !important;   /* ลดความอ้วนของตัว Badge */
    border-radius: 4px !important;
}

/* 4. ปรับระยะห่างในการ์ด (เฉพาะตอนแสดงผล 2 คอลัมน์บนมือถือ) */
@media (max-width: 767.98px) {
    .room-card-modern {
        padding: 10px !important; /* ลด Padding ในการ์ดลงเพื่อให้มีพื้นที่วางตัวหนังสือมากขึ้น */
        min-height: auto !important; /* ให้ความสูงยืดหยุ่นตามเนื้อหา */
    }
}