@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    /* Premium Light Theme Colors */
    --primary: #2563EB; 
    --primary-hover: #1D4ED8;
    --primary-glow: rgba(37, 99, 235, 0.2);
    --surface: #FFFFFF; 
    --surface-solid: #F8FAFC;
    --background: #F1F5F9;
    --text-main: #0F172A; 
    --text-muted: #64748B;
    --border: #E2E8F0;
    --sidebar: #FFFFFF;
    --sidebar-hover: #F1F5F9;
    --success: #10B981; --danger: #EF4444; --warning: #F59E0B;
    
    --shadow-soft: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-float: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.025);
    --radius-md: 10px; --radius-lg: 16px; --radius-xl: 24px;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Plus Jakarta Sans', sans-serif; -webkit-tap-highlight-color: transparent; }
body { background-color: var(--background); color: var(--text-main); overflow-x: hidden; }

.text-danger { color: var(--danger); }

/* Subtle Background Mesh for Light Theme */
.bg-mesh {
    background-color: var(--background);
    background-image: radial-gradient(at 0% 0%, hsla(210, 100%, 95%, 1) 0px, transparent 50%), 
                      radial-gradient(at 100% 0%, hsla(220, 100%, 95%, 1) 0px, transparent 50%);
    background-attachment: fixed;
}

.premium-glass {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
}

.text-blue { color: var(--primary); }
.text-emerald { color: var(--success); }
.bg-blue-light { background: #DBEAFE; }
.bg-emerald-light { background: #D1FAE5; }

/* Animations */
.screen { display: none; height: 100vh; }
.screen.active { display: flex; animation: fadeScale 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes fadeScale { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: scale(1); } }

/* Table Row Entry Animation */
.row-enter {
    animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    opacity: 0;
    transform: translateY(10px);
}
@keyframes slideUpFade { to { opacity: 1; transform: translateY(0); } }

/* Login */
#login-screen { justify-content: center; align-items: center; background: var(--background); padding: 1rem; }
.login-card { padding: 3.5rem 2.5rem; border-radius: var(--radius-xl); width: 100%; max-width: 420px; text-align: center; background: white; border: 1px solid var(--border); box-shadow: var(--shadow-float); }
.logo-icon-large { font-size: 3.5rem; color: var(--primary); margin-bottom: 1rem; }
.login-card h2 { font-weight: 800; font-size: 1.8rem; letter-spacing: -0.5px; }
.login-card p { color: var(--text-muted); margin-bottom: 2rem; }

/* Inputs */
.input-group { position: relative; margin-bottom: 1rem; display: flex; align-items: center; }
.input-group i { position: absolute; left: 1rem; color: var(--text-muted); }
.input-group .toggle-pass { left: auto; right: 1rem; cursor: pointer; transition: 0.2s; }
.input-group .toggle-pass:hover { color: var(--primary); }
.input-group input { width: 100%; padding: 1rem 2.5rem 1rem 3rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-solid); color: var(--text-main); outline: none; transition: 0.3s; font-size: 0.95rem; }
.input-group input:focus { border-color: var(--primary); background: white; box-shadow: 0 0 0 3px var(--primary-glow); }

.premium-input, .premium-select { width: 100%; padding: 0.85rem 1rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-solid); outline: none; transition: 0.2s; font-size: 0.95rem; color: var(--text-main); margin-bottom: 1rem; }
.premium-input:focus, .premium-select:focus { border-color: var(--primary); background: white; box-shadow: 0 0 0 3px var(--primary-glow); }
.search-box { display: flex; align-items: center; background: white; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 0.5rem 1rem; min-width: 280px; transition: 0.2s; box-shadow: 0 1px 2px rgba(0,0,0,0.02); }
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.search-box input { border: none; outline: none; margin-left: 0.75rem; width: 100%; font-size: 0.95rem; background: transparent; color: var(--text-main); }
.input-grid { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }
.input-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* Buttons */
button { font-family: inherit; }
.btn-primary, .btn-secondary, .btn-icon { padding: 0.75rem 1.5rem; border: none; border-radius: var(--radius-md); font-weight: 600; font-size: 0.9rem; cursor: pointer; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; }
.btn-primary { background: var(--primary); color: white; box-shadow: 0 4px 6px -1px var(--primary-glow); }
.btn-primary:hover { transform: translateY(-2px); background: var(--primary-hover); box-shadow: 0 8px 15px -3px var(--primary-glow); }
.btn-primary:active { transform: scale(0.97); }
.btn-secondary { background: white; border: 1px solid var(--border); color: var(--text-main); box-shadow: 0 1px 2px rgba(0,0,0,0.02); }
.btn-secondary:hover { background: var(--surface-solid); border-color: #CBD5E1; }
.btn-icon { padding: 0.5rem; border-radius: 8px; background: transparent; color: var(--text-muted); width: 36px; height: 36px; border: 1px solid transparent; }
.btn-icon:hover { background: var(--surface-solid); color: var(--primary); border-color: var(--border); }
.btn-icon.delete:hover { color: var(--danger); background: #FEF2F2; border-color: #FECACA; }

/* Layout & Sidebar */
.layout { flex-direction: row; width: 100vw; overflow: hidden; }
.sidebar { width: 280px; background: var(--sidebar); color: var(--text-main); display: flex; flex-direction: column; transition: transform 0.3s; flex-shrink: 0; z-index: 50; border-right: 1px solid var(--border); }
.sidebar-header { padding: 2rem; font-size: 1.4rem; font-weight: 800; display: flex; align-items: center; justify-content: space-between; letter-spacing: -0.5px; }
.logo-text { display: flex; align-items: center; gap: 10px; color: var(--primary); }
.nav-links { list-style: none; padding: 0 1rem; flex-grow: 1; }
.nav-links li { padding: 1rem 1.2rem; margin-bottom: 0.5rem; border-radius: var(--radius-md); cursor: pointer; font-weight: 600; color: var(--text-muted); transition: all 0.2s; display: flex; align-items: center; gap: 1rem; }
.nav-links li:hover, .nav-links li.active-nav { background: var(--sidebar-hover); color: var(--primary); transform: translateX(4px); }
.sidebar-footer { padding: 1.5rem; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--border); }
.sidebar { 
    width: 280px; 
    background: var(--sidebar); 
    color: var(--text-main); 
    display: flex; 
    flex-direction: column; 
    transition: transform 0.3s; 
    flex-shrink: 0; 
    z-index: 50; 
    border-right: 1px solid var(--border);
    overflow-y: auto; /* Enable vertical scrolling */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}
.user-profile-mini { display: flex; align-items: center; gap: 10px; }
.user-profile-mini .avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--blue-light); color: var(--primary); display: flex; justify-content: center; align-items: center; font-size: 0.9rem; border: 1px solid var(--primary-glow); }
.user-info { display: flex; flex-direction: column; }
.user-name-display { font-size: 0.85rem; font-weight: 700; color: var(--text-main); }
.user-role-badge { background: var(--sidebar-hover); padding: 0.2rem 0.5rem; border-radius: 6px; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.5px; color: var(--text-muted); border: 1px solid var(--border); display: inline-block; margin-top: 2px;}
.btn-logout { background: transparent; padding: 0.5rem; color: var(--text-muted); border-radius: 8px; border: none; cursor: pointer; transition: 0.2s; font-size: 1.1rem; }
.btn-logout:hover { color: var(--danger); background: #FEF2F2; }

/* Content Area */
.content { flex-grow: 1; padding: 2rem 3rem; overflow-y: auto; height: 100vh; position: relative; }
.data-section { display: none; }
.data-section.active { display: block; animation: fadeScale 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2.5rem; }
.topbar-left { display: flex; align-items: center; gap: 1rem; }
#section-title { font-size: 1.8rem; font-weight: 800; color: var(--text-main); letter-spacing: -0.5px; }
.mobile-close-btn, #mobile-menu-btn { display: none; background: none; border: none; color: inherit; font-size: 1.2rem; cursor: pointer; }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.5rem; margin-bottom: 2.5rem; }
.stat-card { padding: 1.5rem; border-radius: var(--radius-lg); display: flex; align-items: center; gap: 1.5rem; transition: transform 0.2s; background: white; border: 1px solid var(--border); }
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-float); }
.stat-icon { width: 56px; height: 56px; border-radius: 14px; display: flex; justify-content: center; align-items: center; font-size: 1.6rem; }
.stat-details p { color: var(--text-muted); font-size: 0.875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 0.25rem; }
.stat-details h3 { font-size: 1.75rem; font-weight: 800; color: var(--text-main); }

/* Toolbars */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; gap: 1rem; }
.toolbar.flex-wrap { flex-wrap: wrap; }
.toolbar-group { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }

/* Tables */
.table-card { border-radius: var(--radius-lg); overflow: hidden; padding: 1px; background: white; border: 1px solid var(--border); box-shadow: var(--shadow-soft); }
.responsive-table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
th { background: var(--surface-solid); font-weight: 700; color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
tr { transition: background 0.2s; background: white; }
tr:last-child td { border-bottom: none; }
tr:hover { background: #F8FAFC; }

/* Checkboxes */
input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary); }

/* Badges */
.badge { padding: 0.35rem 0.75rem; border-radius: 99px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.5px; display: inline-block; }
.badge-level { background: #F1F5F9; color: #475569; border: 1px solid #E2E8F0; }
.badge-credit { color: #065F46; background: #D1FAE5; }
.badge-debit { color: #991B1B; background: #FEE2E2; }
.badge-mode { background: #E0E7FF; color: var(--primary); font-size: 0.7rem; margin-top: 4px; }

.pagination-controls { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.5rem; border-top: 1px solid var(--border); background: var(--surface-solid); }
.page-info { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }

/* Modals */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(4px); justify-content: center; align-items: center; z-index: 100; opacity: 0; transition: opacity 0.3s ease; padding: 1rem; }
.modal-overlay.active { display: flex; opacity: 1; animation: fadeScale 0.3s forwards; }
.modal-content { padding: 2.5rem; border-radius: var(--radius-xl); width: 100%; max-width: 500px; background: white; box-shadow: var(--shadow-float); }
.modal-content.large { max-width: 800px; max-height: 90vh; overflow-y: auto; }
.modal-content h3 { margin-bottom: 2rem; font-size: 1.5rem; font-weight: 800; letter-spacing: -0.5px; color: var(--text-main); }
.premium-form-group { margin-bottom: 1rem; }
.premium-form-group label { display: block; font-size: 0.8rem; font-weight: 700; color: var(--text-muted); margin-bottom: 0.5rem; text-transform: uppercase; }
.modal-actions { display: flex; justify-content: flex-end; gap: 1rem; margin-top: 2rem; }

/* Toasts & Loaders */
#toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 9999; }
.toast { background: white; border-left: 4px solid var(--primary); box-shadow: var(--shadow-float); padding: 1rem 1.5rem; border-radius: 8px; display: flex; align-items: center; gap: 10px; animation: slideInRight 0.3s ease forwards, fadeOut 0.3s ease 3s forwards; font-weight: 600; color: var(--text-main); border: 1px solid var(--border); }
.toast.error { border-left-color: var(--danger); }
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

.loader-overlay { display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(255,255,255,0.7); z-index: 999; justify-content: center; align-items: center; backdrop-filter: blur(2px); }
.loader-overlay.active { display: flex; }
.spinner { width: 40px; height: 40px; border: 4px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Mobile */
.mobile-overlay { display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.5); z-index: 40; opacity: 0; transition: opacity 0.3s; }
.mobile-overlay.active { display: block; opacity: 1; }

/* Mobile Native App Layout */
@media (max-width: 900px) {
    /* 1. App Body & Sticky Header */
    body { padding-bottom: 80px; /* Space for bottom nav */ }
    .content { padding: 0; height: auto; overflow: visible; }
    
    /* Updated Sticky Header for Mobile */
    .topbar {
        position: sticky; top: 0; background: rgba(255, 255, 255, 0.9);
        backdrop-filter: blur(10px); z-index: 100;
        padding: 1rem 1.5rem; border-bottom: 1px solid var(--border);
        margin-bottom: 1.5rem; box-shadow: 0 4px 15px -5px rgba(0,0,0,0.05);
        display: flex; justify-content: space-between; align-items: center; /* Keep items spaced out */
    }
    .topbar-left { width: auto; justify-content: flex-start; }
    #section-title { font-size: 1.3rem; text-align: left; }
    #mobile-menu-btn { display: none; }
    
    /* Make the topbar logout button only visible on mobile (desktop has it in sidebar) */
    .mobile-logout-btn { display: inline-flex; }
    /* 2. Bottom Navigation Bar */
    .sidebar {
        position: fixed; top: auto; bottom: 0; left: 0; width: 100vw; height: 75px;
        transform: translateX(0); flex-direction: row; justify-content: center;
        border-right: none; border-top: 1px solid var(--border); z-index: 1000;
        padding: 0; overflow: visible; box-shadow: 0 -4px 10px rgba(0,0,0,0.03);
    }
    .sidebar-header, .sidebar-footer { display: none !important; }
    .nav-links {
        display: flex; flex-direction: row; justify-content: space-around;
        width: 100%; padding: 0 0.5rem; margin: 0; align-items: center;
    }
    .nav-links li {
        flex: 1; flex-direction: column; gap: 6px; font-size: 0.7rem;
        padding: 0.6rem 0; text-align: center; border-radius: 12px; margin: 0;
        background: transparent !important; color: var(--text-muted);
    }
    .nav-links li i { font-size: 1.4rem; transition: transform 0.2s; }
    .nav-links li.active-nav { color: var(--primary); font-weight: 800; }
    .nav-links li.active-nav i { transform: translateY(-3px); }

    /* 3. Toolbar & Stats Tweaks */
    .stats-grid { 
        padding: 0 1rem; 
        display: grid; 
        grid-template-columns: 1fr 1fr; /* Forces two columns */
        gap: 0.75rem; 
    }
    .stat-card { 
        padding: 1rem 0.5rem; 
        flex-direction: column; /* Stacks icon and text vertically */
        text-align: center; 
        gap: 0.5rem;
    }
    .stat-icon { 
        width: 40px; height: 40px; font-size: 1.2rem; margin: 0 auto; 
    }
    .stat-details p { font-size: 0.65rem; }
    .stat-details h3 { font-size: 1.2rem; }
    .toolbar { padding: 0 1rem; justify-content: stretch; }
    .toolbar-group { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .toolbar-group .search-box { grid-column: span 2; min-width: 100%; margin-bottom: 0.5rem; }
    .toolbar-group > button.btn-secondary { font-size: 0.8rem; padding: 0.6rem; }
    
/* Hide traditional add buttons in the toolbar, we will use a FAB */
    #add-student-btn, .toolbar .btn-primary { display: none !important; }
    
    /* Ensure primary buttons inside modals always remain visible */
    .modal-content .btn-primary { display: inline-flex !important; }

    /* 4. Native App Cards (Replacing Tables) */
    .table-card { border: none; box-shadow: none; background: transparent; padding: 0 1rem; }
    .responsive-table thead { display: none; }
    
    .responsive-table tr { 
        display: grid;
        grid-template-columns: auto 1fr auto;
        align-items: center;
        gap: 0.5rem; margin-bottom: 1rem; 
        border: 1px solid var(--border); border-radius: var(--radius-xl); 
        padding: 1.2rem; background: var(--surface); 
        box-shadow: var(--shadow-float); position: relative;
    }
    
    .responsive-table td { display: block; padding: 0; border: none !important; text-align: left; }
    .responsive-table td::before { display: none; } /* Hide labels */
    
    /* Layout Mapping for List Items */
    .responsive-table td:nth-child(1) { grid-column: 1; grid-row: 1 / span 2; margin-right: 0.5rem; } /* Checkbox */
    .responsive-table td:nth-child(2) { grid-column: 2; grid-row: 1; } /* Name / Date */
    .responsive-table td:nth-child(3) { grid-column: 2; grid-row: 2; margin-top: 0.3rem; } /* Level / Student */
    .responsive-table td:nth-child(4) { grid-column: 2; grid-row: 3; margin-top: 0.3rem; } /* Contact / Type */
    .responsive-table td:nth-child(5) { grid-column: 3; grid-row: 1 / span 3; text-align: right; display: flex; align-items: center;} /* Balance / Amount */
    
    /* Hide specific non-essential info on mobile to prevent stress */
    .mobile-hide { display: none !important; }
    .mobile-actions { display: none !important; } /* Rely entirely on tap to view details */
    .mobile-tile-row::after { display: none; }
    
    /* Modals formatting */
    .modal-content { padding: 1.5rem; width: 92%; max-height: 85vh; overflow-y: auto; margin: auto; }
    
    /* 5. Floating Action Button (FAB) */
    .mobile-fab {
        display: flex !important; position: fixed; bottom: 95px; right: 20px;
        width: 60px; height: 60px; border-radius: 50%;
        background: var(--primary); color: white;
        align-items: center; justify-content: center;
        font-size: 1.5rem; box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
        z-index: 999; cursor: pointer; transition: transform 0.2s;
    }
    .mobile-fab:active { transform: scale(0.92); }
}

/* Hide FAB on desktop */
@media (min-width: 901px) {
    .mobile-fab { display: none !important; }
}
/* Hide mobile logout button on desktop */
@media (min-width: 901px) {
    .mobile-logout-btn { display: none !important; }
}