:root {
    /* Color Palette - Modern & Clean */
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #6366f1;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    
    --bg-main: #f8fafc;
    --bg-sidebar: #0f172a;
    --bg-card: #ffffff;
    --bg-header: #ffffff;
    
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-on-dark: #f8fafc;
    --text-on-primary: #ffffff;

    --sidebar-w: 280px;
    --header-h: 70px;
    
    --mobile-breakpoint: 1024px;
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
    font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
}

body { 
    margin: 0;
    padding: 0;
    min-height: 100vh; 
    background-color: var(--bg-main); 
    color: var(--text-main);
    line-height: 1.6;
}

.app-container {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

/* =========================================
   Login Page Styles
   ========================================= */
body.login-body {
    background: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container { 
    background: rgba(255, 255, 255, 0.8); 
    backdrop-filter: blur(16px); 
    -webkit-backdrop-filter: blur(16px); 
    border: 1px solid rgba(255, 255, 255, 0.5); 
    border-radius: var(--radius-xl); 
    padding: 48px; 
    width: 100%; 
    max-width: 420px; 
    box-shadow: var(--shadow-lg); 
    transition: transform 0.3s ease; 
}

.login-header { text-align: center; margin-bottom: 32px; }
.login-header h1 { font-size: 32px; font-weight: 800; color: var(--text-main); margin-bottom: 8px; letter-spacing: -1px; }
.login-header p { font-size: 14px; color: var(--text-muted); }

.form-group { margin-bottom: 24px; }
.form-group label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 600; color: #475569; }
.form-control { 
    width: 100%; 
    padding: 14px 16px; 
    border: 1px solid #e2e8f0; 
    border-radius: var(--radius-md); 
    font-size: 15px; 
    background: #fff; 
    transition: all 0.2s; 
    outline: none; 
}
.form-control:focus { 
    border-color: var(--primary); 
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1); 
}

/* Password Toggle Styles */
.password-group {
    position: relative;
    display: flex;
    align-items: center;
}
.password-toggle {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    z-index: 10;
}
.password-toggle:hover {
    color: var(--primary);
}


.btn-login { 
    width: 100%; 
    padding: 14px; 
    background: var(--primary); 
    color: white; 
    border: none; 
    border-radius: var(--radius-md); 
    font-size: 16px; 
    font-weight: 600; 
    cursor: pointer; 
    transition: all 0.2s; 
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2); 
}
.btn-login:hover { 
    background: var(--primary-hover); 
    transform: translateY(-1px); 
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.3); 
}

.alert-error { 
    background-color: #fee2e2; 
    border-left: 4px solid var(--danger); 
    color: #991b1b; 
    padding: 12px 16px; 
    border-radius: var(--radius-sm); 
    margin-bottom: 24px; 
    font-size: 14px; 
    font-weight: 500;
}

.credentials-hint { 
    margin-top: 32px; 
    font-size: 12px; 
    color: var(--text-muted); 
    text-align: center; 
    background: #f8fafc; 
    padding: 16px; 
    border-radius: var(--radius-md); 
    border: 1px dashed #e2e8f0;
    line-height: 1.8;
}

/* =========================================
   Sidebar Styling
   ========================================= */
.sidebar { 
    width: var(--sidebar-w); 
    background-color: var(--bg-sidebar); 
    color: var(--text-on-dark); 
    display: flex; 
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 50;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header { 
    padding: 24px; 
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.header-logo { 
    width: 48px; 
    height: 48px; 
    border-radius: 12px; 
    flex-shrink: 0; 
}

.sidebar-header h2 { 
    font-size: 20px; 
    font-weight: 700; 
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-menu { 
    flex: 1; 
    padding: 24px 16px;
    overflow-y: auto;
}

.sidebar-menu ul { list-style: none; }

.section-title { 
    font-size: 11px; 
    text-transform: uppercase; 
    color: #475569; 
    letter-spacing: 1.5px; 
    padding: 24px 12px 8px; 
    font-weight: 700;
}

.sidebar-menu li a { 
    display: flex; 
    align-items: center;
    gap: 12px;
    padding: 12px 16px; 
    color: #94a3b8; 
    text-decoration: none; 
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
}

.sidebar-menu li a:hover { 
    background-color: rgba(255,255,255,0.05); 
    color: #f1f5f9; 
}

.sidebar-menu li.active a { 
    background-color: var(--primary); 
    color: white; 
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

/* Submenu Styles */
.sidebar-item-group {
    margin-bottom: 4px;
}

.sidebar-group-header {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    width: 100% !important;
    padding: 12px 16px !important;
    color: #94a3b8 !important;
    background: transparent !important;
    border: none !important;
    border-radius: var(--radius-md) !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    gap: 12px !important;
    text-align: left !important;
}

.sidebar-group-header:hover {
    background-color: rgba(255,255,255,0.05);
    color: #f1f5f9;
}

.sidebar-group-header .header-content {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    flex: 1 !important; /* Stretches to push chevron to the right */
    justify-content: flex-start !important;
}

.sidebar-group-header .chevron {
    width: 16px;
    height: 16px;
    transition: transform 0.3s ease;
}

.sidebar-item-group.open .sidebar-group-header {
    background-color: rgba(255,255,255,0.03);
    color: #f1f5f9;
}

.sidebar-item-group.open .chevron {
    transform: rotate(180deg);
}

.sidebar-submenu {
    list-style: none;
    padding-left: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-item-group.open .sidebar-submenu {
    max-height: 1000px;
    margin-top: 4px;
    margin-bottom: 8px;
}

.sidebar-submenu li a {
    padding: 10px 16px 10px 48px !important; /* Fix indentation to match parent text align */
    font-size: 13.5px !important;
    opacity: 0.8 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
}

.sidebar-submenu li a:hover {
    opacity: 1;
    background-color: rgba(255,255,255,0.03);
}

.sidebar-submenu li.active a {
    background-color: rgba(79, 70, 229, 0.15);
    color: #a5b4fc;
    box-shadow: none;
    border-left: 3px solid var(--primary);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    opacity: 1;
}

/* Standardize symbols and icons across all menu items */
.sidebar-menu [data-lucide] {
    width: 20px;
    height: 20px;
    stroke-width: 2;
    flex-shrink: 0;
}

.user-panel { 
    padding: 20px 16px; 
    background-color: rgba(0,0,0,0.2); 
}

.btn-logout { 
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%; 
    padding: 12px; 
    border-radius: var(--radius-md); 
    background: rgba(239, 68, 68, 0.1); 
    color: #ef4444; 
    text-align: center; 
    text-decoration: none; 
    transition: all 0.2s; 
    font-size: 14px;
    font-weight: 600;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-logout:hover { 
    background: #ef4444; 
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2); 
}

/* =========================================
   Main Content Area
   ========================================= */
.main-content { 
    margin-left: var(--sidebar-w);
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    min-width: 0;
    width: calc(100% - var(--sidebar-w));
}

.topbar { 
    background: var(--bg-header); 
    height: var(--header-h);
    padding: 0 32px; 
    box-shadow: var(--shadow-sm); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    position: sticky;
    top: 0;
    z-index: 30;
    border-bottom: 1px solid #f1f5f9;
    width: 100%;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 45;
    animation: fadeIn 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
}

.mobile-toggle {
    display: none;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #f1f5f9;
    color: var(--text-main);
    border: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-right: 16px;
}

.topbar h3 { 
    font-size: 18px; 
    font-weight: 600; 
    color: var(--text-main);
}

.badge { 
    padding: 6px 14px; 
    border-radius: 9999px; 
    font-size: 12px; 
    font-weight: 600; 
    background: #eef2ff; 
    color: var(--primary); 
}

.badge.homeroom { 
    background: #fdf2f8; 
    color: #db2777; 
    margin-left: 8px; 
}

.content-area { 
    padding: 32px; 
    width: 100%;
    flex-grow: 1;
}

/* =========================================
   Dashboard Elements
   ========================================= */
.welcome-section {
    margin-bottom: 32px;
}

.welcome-section h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.5px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: white;
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 20px;
    border: 1px solid #f1f5f9;
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    background: #f5f3ff;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-info h4 {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
}

.stat-info p {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
}

.card-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); 
    gap: 24px; 
}

.card { 
    background: white; 
    border-radius: var(--radius-lg); 
    padding: 28px; 
    box-shadow: var(--shadow-md); 
    transition: all 0.3s ease; 
    border: 1px solid #f1f5f9;
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
}

.card:hover { 
    transform: translateY(-8px); 
    box-shadow: var(--shadow-lg); 
}

.card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.card h4 { 
    font-size: 20px; 
    font-weight: 700;
    margin-bottom: 12px; 
    color: var(--text-main); 
}

.card p { 
    font-size: 14px; 
    color: var(--text-muted); 
    line-height: 1.6; 
}

/* =========================================
   Utility Classes
   ========================================= */
.lucide {
    stroke-width: 2;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
    background: #f1f5f9;
    color: var(--text-main);
    border: 1px solid #e2e8f0;
}

.btn-secondary:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
}

.btn-outline-primary {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}

.btn-outline-primary:hover {
    background: rgba(79, 70, 229, 0.05);
    background-color: #eef2ff;
}
/* =========================================
   Manage Users (Tables & Buttons)
   ========================================= */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.btn-add { background: var(--success); color: white; padding: 10px 16px; border-radius: var(--radius-md); text-decoration: none; font-size: 14px; font-weight: 500; transition: 0.2s; border: none; cursor: pointer; }
.btn-add:hover { opacity: 0.9; }
.table-container { background: white; border-radius: var(--radius-lg); padding: 24px; box-shadow: var(--shadow-md); border: 1px solid #f1f5f9; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid #f1f5f9; font-size: 15px; }
th { background-color: #f8fafc; font-weight: 600; color: var(--text-muted); }
tr:hover td { background-color: #f8fafc; }

.role-tag { padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; display: inline-block; }
.role-admin { background: #fee2e2; color: #991b1b; }
.role-executive { background: #fef3c7; color: #92400e; }
.role-teacher { background: #dbeafe; color: #1e40af; }

.action-btns { display: flex; gap: 8px; }
.btn-sm { padding: 6px 12px; border-radius: 6px; font-size: 13px; text-decoration: none; color: white; transition: 0.2s; display: inline-flex; align-items: center; justify-content: center; }
.btn-edit { background: var(--info); }
.btn-delete { background: var(--danger); }
.btn-icon-only { padding: 8px; border-radius: 8px; }

/* =========================================
   Modal Styles (Enhanced)
   ========================================= */
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(15, 23, 42, 0.4); align-items: center; justify-content: center; backdrop-filter: blur(8px); padding: 20px; }
.modal-content { background-color: #fff; border-radius: var(--radius-xl); width: 100%; max-width: 800px; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); animation: modalSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1); border: 1px solid rgba(255,255,255,0.1); overflow: hidden; }

@keyframes modalSlideIn { from { opacity: 0; transform: translateY(20px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.modal-header { padding: 24px 32px; border-bottom: 1px solid #f1f5f9; display: flex; justify-content: space-between; align-items: center; background: #fff; }
.modal-header h2 { font-size: 20px; font-weight: 700; color: var(--text-main); }
.close { color: var(--text-muted); font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; transition: 0.2s; }
.close:hover { background: #f1f5f9; color: var(--danger); }

.modal-body { padding: 32px; max-height: 80vh; overflow-y: auto; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.modal-grid .form-group.full-width { grid-column: span 2; }

/* Responsive utility */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    background: white;
    border-radius: var(--radius-lg);
    -webkit-overflow-scrolling: touch;
}

.modal-footer { padding: 20px 32px; border-top: 1px solid #f1f5f9; display: flex; justify-content: flex-end; gap: 12px; background-color: #f8fafc; }
.btn-cancel { 
    padding: 10px 24px; 
    background-color: #fff; 
    border: 1px solid #e2e8f0; 
    border-radius: var(--radius-md); 
    font-size: 14px; 
    font-weight: 600; 
    color: var(--text-muted); 
    cursor: pointer; 
    transition: all 0.2s; 
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.btn-cancel:hover { background: #f1f5f9; color: var(--text-main); border-color: #cbd5e1; }
.btn-save { 
    padding: 10px 28px; 
    background-color: var(--primary); 
    border: none; 
    border-radius: var(--radius-md); 
    font-size: 14px; 
    font-weight: 600; 
    color: white; 
    cursor: pointer; 
    transition: all 0.2s; 
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.btn-save:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(79, 70, 229, 0.3); }

.input-with-icon { position: relative; display: flex; align-items: center; }
.input-with-icon i, .input-with-icon svg { position: absolute; left: 14px; color: var(--text-muted); pointer-events: none; width: 18px; height: 18px; }
.input-with-icon .form-control { padding-left: 44px; }

@media (max-width: 640px) {
    .modal-grid { grid-template-columns: 1fr; }
    .modal-grid .form-group.full-width { grid-column: span 1; }
}

/* =========================================
   Pagination Styles
   ========================================= */
.pagination { 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    gap: 8px; 
    margin: 32px 0; 
}

.page-link { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    min-width: 40px; 
    height: 40px; 
    padding: 0 14px; 
    background: #fff; 
    border: 1px solid #e2e8f0; 
    border-radius: 10px; 
    color: var(--text-main); 
    font-weight: 600; 
    text-decoration: none; 
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); 
    font-size: 14px;
}

.page-link:hover:not(.active) { 
    background: #f8fafc; 
    border-color: var(--primary); 
    color: var(--primary); 
    transform: translateY(-2px); 
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05); 
}

.page-link.active { 
    background: var(--primary); 
    border-color: var(--primary); 
    color: #fff; 
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3); 
}

/* =========================================
   Responsive Design
   ========================================= */

@media (max-width: 1024px) {
    .sidebar {
        left: calc(-1 * var(--sidebar-w));
    }

    .sidebar.open {
        left: 0;
        box-shadow: 20px 0 25px -5px rgba(0, 0, 0, 0.1);
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .mobile-toggle {
        display: flex;
    }

    .topbar {
        padding: 0 20px;
    }
}

@media (max-width: 768px) {
    .content-area {
        padding: 20px;
    }

    .topbar-left h3 {
        font-size: 15px;
    }

    .topbar-right .badge span {
        display: none;
    }

    .table-container, .table-responsive {
        padding: 0;
        margin: 0 -20px;
        width: calc(100% + 40px);
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    table {
        min-width: 600px;
    }
    
    .modal-content, .card {
        padding: 20px !important;
    }
    
    .modal-body {
        padding: 20px 0;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .page-header .btn-add, .page-header button {
        width: 100%;
        justify-content: center;
    }
}