:root {
    --primary-color: #4e73df;
    --secondary-color: #224abe;
    --success-color: #1cc88a;
    --info-color: #36b9cc;
    --warning-color: #f6c23e;
    --danger-color: #e74a3b;
    --light-color: #f8f9fc;
    --dark-color: #5a5c69;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 0px;
    --font-family-base: 'Sarabun', sans-serif;
}

body {
    font-family: var(--font-family-base);
    background-color: var(--light-color);
    color: var(--dark-color);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    -webkit-tap-highlight-color: transparent;
}

/* --- Sidebar (ปรับปรุงเพื่อให้เลื่อนได้) --- */
#sidebar {
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(180deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1050;
    color: white;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    display: flex;
    flex-direction: column;
}

#sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-width)));
}

#sidebar::-webkit-scrollbar {
    display: none;
}

.sidebar-header {
    padding: 25px 20px;
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.05);
    margin-bottom: 10px;
}

#sidebar .nav-link {
    padding: 12px 18px;
    color: rgba(255, 255, 255, 0.75) !important;
    display: flex;
    align-items: center;
    border-radius: 12px;
    margin: 4px 15px;
    min-height: 46px;
    transition: all 0.2s ease;
    font-weight: 500;
    border-left: 3px solid transparent;
}

#sidebar .nav-link i {
    font-size: 1.2rem;
    margin-right: 12px;
    width: 24px;
    text-align: center;
    transition: transform 0.2s ease;
}

#sidebar .nav-link:hover {
    color: white !important;
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(4px);
}

#sidebar .nav-link.active {
    color: white !important;
    background: rgba(255, 255, 255, 0.2);
    border-left: 3px solid white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

#sidebar .nav-link:hover i {
    transform: scale(1.1);
}

/* Submenu Styling */
#sidebar .submenu {
    background: rgba(0, 0, 0, 0.1);
    margin: 4px 15px;
    border-radius: 12px;
    padding: 5px 0;
}

#sidebar .submenu .nav-link {
    margin: 2px 10px 2px 25px;
    padding: 8px 15px;
    font-size: 0.9rem;
    opacity: 0.8;
    border-left: none;
}

#sidebar .submenu .nav-link:hover,
#sidebar .submenu .nav-link.active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
    transform: none;
}

#sidebar .submenu .nav-link i {
    font-size: 1rem;
    margin-right: 10px;
    width: 20px;
}

/* --- Content Area --- */
#content {
    width: 100%;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.3s ease;
    background-color: var(--light-color);
}

#content.expanded {
    margin-left: 0;
}

/* --- UI Elements --- */
.card {
    border: none;
    border-radius: 16px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

/* บังคับไม่ให้มีการยุบตัวในสถานะคลิก (Active) */
.card:active,
.btn:active,
.btn-upload-photo:active,
.row>*:active {
    transform: none !important;
    transition: none !important;
}

/* Photo Preview (สำหรับการลงทะเบียนใบหน้า) */
.photo-preview-container {
    width: 150px;
    height: 180px;
    border: 2px dashed #dee2e6;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-color: #f8f9fa;
    position: relative;
    max-width: 100%;
}

.photo-preview-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* --- Navigation & Tables --- */
.navbar {
    padding: 0.75rem 1.5rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    height: 70px;
}

.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70px;
    background: #ffffff !important;
    z-index: 1030;
    padding-bottom: env(safe-area-inset-bottom);
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

/* Select2 Fix for Modals */
.select2-container {
    z-index: 9999 !important;
}

/* --- Mobile Queries --- */
@media (max-width: 991.98px) {
    #sidebar {
        transform: translateX(calc(-1 * var(--sidebar-width)));
    }

    #sidebar.active {
        transform: translateX(0);
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2);
    }

    #content {
        margin-left: 0 !important;
        padding-bottom: 90px !important;
    }

    .bottom-nav {
        display: flex;
    }

    .row>* {
        margin-bottom: 1rem;
    }
}

@media (max-width: 576px) {
    .container-fluid {
        padding: 15px !important;
    }

    .btn {
        min-height: 48px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .form-control,
    .form-select {
        height: 50px;
        font-size: 16px !important;
    }
}

.table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}