<!DOCTYPE html>
<html lang="en" data-theme="<?= e(get_theme_slug_for_scope('admin')) ?>">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin - <?= get_setting('academy_name', 'CIX Orbit Academy') ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="<?= asset_url('css/style.css') ?>" rel="stylesheet">
    <?= render_theme_css('admin') ?>
</head>
<body>
<aside class="sidebar-cix" id="sidebar">
    <div class="sidebar-brand">
        <i class="fas fa-orbit" style="color:var(--secondary);font-size:1.3rem"></i>
        <div>
            <h5>CIX <span style="color:var(--secondary)">Orbit</span></h5>
            <small>Admin Panel</small>
        </div>
    </div>
    <?php $user = current_user(); $uri = $_SERVER['REQUEST_URI'] ?? ''; ?>
    <ul class="sidebar-nav">
        <li class="nav-section">Main</li>
        <li><a href="<?= base_url('admin/dashboard') ?>" class="<?= str_contains($uri, '/admin/dashboard') ? 'active' : '' ?>"><i class="fas fa-th-large"></i> Dashboard</a></li>
        <li class="nav-section">Academic</li>
        <li><a href="<?= base_url('admin/applications') ?>" class="<?= str_contains($uri, '/admin/application') ? 'active' : '' ?>"><i class="fas fa-file-alt"></i> Applications <?php $pendingApps = $pdo->query("SELECT COUNT(*) FROM applications WHERE status='pending'")->fetchColumn(); if ($pendingApps > 0): ?><span class="badge-cix"><?= $pendingApps ?></span><?php endif; ?></a></li>
        <li><a href="<?= base_url('admin/students') ?>" class="<?= str_contains($uri, '/admin/student') ? 'active' : '' ?>"><i class="fas fa-user-graduate"></i> Students</a></li>
        <li><a href="<?= base_url('admin/teachers') ?>" class="<?= str_contains($uri, '/admin/teacher') ? 'active' : '' ?>"><i class="fas fa-chalkboard-teacher"></i> Teachers</a></li>
        <li><a href="<?= base_url('admin/courses') ?>" class="<?= str_contains($uri, '/admin/course') ? 'active' : '' ?>"><i class="fas fa-book"></i> Courses</a></li>
        <li><a href="<?= base_url('admin/modules') ?>" class="<?= str_contains($uri, '/admin/module') ? 'active' : '' ?>"><i class="fas fa-layer-group"></i> Modules</a></li>
        <li><a href="<?= base_url('admin/lessons') ?>" class="<?= str_contains($uri, '/admin/lesson') ? 'active' : '' ?>"><i class="fas fa-file-alt"></i> Lessons</a></li>
        <li><a href="<?= base_url('admin/exercises') ?>" class="<?= str_contains($uri, '/admin/exercise') ? 'active' : '' ?>"><i class="fas fa-dumbbell"></i> Exercises</a></li>
        <li class="nav-section">Assessment</li>
        <li><a href="<?= base_url('admin/question-banks') ?>" class="<?= str_contains($uri, '/admin/question') ? 'active' : '' ?>"><i class="fas fa-database"></i> Question Bank</a></li>
        <li><a href="<?= base_url('admin/tests') ?>" class="<?= str_contains($uri, '/admin/test') ? 'active' : '' ?>"><i class="fas fa-laptop-code"></i> CBT Tests</a></li>
        <li><a href="<?= base_url('admin/assignments') ?>" class="<?= str_contains($uri, '/admin/assignment') ? 'active' : '' ?>"><i class="fas fa-tasks"></i> Assignments</a></li>
        <li class="nav-section">Finance</li>
        <li><a href="<?= base_url('admin/enrollments') ?>" class="<?= str_contains($uri, '/admin/enrollment') ? 'active' : '' ?>"><i class="fas fa-user-plus"></i> Enrollments</a></li>
        <li><a href="<?= base_url('admin/packages') ?>" class="<?= str_contains($uri, '/admin/package') ? 'active' : '' ?>"><i class="fas fa-box"></i> Packages</a></li>
        <li><a href="<?= base_url('admin/payments') ?>" class="<?= str_contains($uri, '/admin/payment') ? 'active' : '' ?>"><i class="fas fa-credit-card"></i> Payments <?php $pendingPay = $pdo->query("SELECT COUNT(*) FROM payments WHERE status='submitted'")->fetchColumn(); if ($pendingPay > 0): ?><span class="badge-cix"><?= $pendingPay ?></span><?php endif; ?></a></li>
        <li><a href="<?= base_url('admin/certificates') ?>" class="<?= str_contains($uri, '/admin/certificate') ? 'active' : '' ?>"><i class="fas fa-award"></i> Certificates</a></li>
        <li class="nav-section">System</li>
        <li><a href="<?= base_url('admin/announcements') ?>" class="<?= str_contains($uri, '/admin/announcement') ? 'active' : '' ?>"><i class="fas fa-bullhorn"></i> Announcements</a></li>
        <li><a href="<?= base_url('admin/support-tickets') ?>" class="<?= str_contains($uri, '/admin/support') ? 'active' : '' ?>"><i class="fas fa-headset"></i> Support</a></li>
        <li><a href="<?= base_url('admin/reports') ?>" class="<?= str_contains($uri, '/admin/report') ? 'active' : '' ?>"><i class="fas fa-chart-bar"></i> Reports</a></li>
        <li class="nav-section">Configuration</li>
        <li><a href="<?= base_url('admin/users') ?>" class="<?= str_contains($uri, '/admin/user') ? 'active' : '' ?>"><i class="fas fa-users-cog"></i> Users & Roles</a></li>
        <li><a href="<?= base_url('admin/themes') ?>" class="<?= str_contains($uri, '/admin/theme') ? 'active' : '' ?>"><i class="fas fa-palette"></i> Themes</a></li>
        <li><a href="<?= base_url('admin/ai-settings') ?>" class="<?= str_contains($uri, '/admin/ai') ? 'active' : '' ?>"><i class="fas fa-robot"></i> AI Settings</a></li>
        <li><a href="<?= base_url('admin/settings') ?>" class="<?= str_contains($uri, '/admin/setting') ? 'active' : '' ?>"><i class="fas fa-cog"></i> Settings</a></li>
        <li><a href="<?= base_url('admin/audit-logs') ?>" class="<?= str_contains($uri, '/admin/audit') ? 'active' : '' ?>"><i class="fas fa-history"></i> Audit Logs</a></li>
        <li><a href="<?= base_url('admin/system-health') ?>" class="<?= str_contains($uri, '/admin/system') ? 'active' : '' ?>"><i class="fas fa-heartbeat"></i> System Health</a></li>
        <li><a href="<?= base_url('admin/backup') ?>" class="<?= str_contains($uri, '/admin/backup') ? 'active' : '' ?>"><i class="fas fa-database"></i> Backup</a></li>
    </ul>
</aside>
<div class="main-content">
    <div class="top-bar">
        <div class="d-flex align-center gap-2">
            <button id="sidebarToggle" class="btn btn-outline-light d-lg-none"><i class="fas fa-bars"></i></button>
            <h4><?= $pageTitle ?? 'Dashboard' ?></h4>
        </div>
        <div class="d-flex align-center gap-2">
            <a href="<?= base_url('admin/search') ?>" class="btn-cix btn-cix-sm btn-cix-outline"><i class="fas fa-search"></i> Search</a>
            <span class="text-secondary"><i class="fas fa-user-shield me-1"></i> <?= e(current_user()['first_name'] ?? 'Admin') ?></span>
            <a href="<?= base_url('logout') ?>" class="btn-cix btn-cix-sm btn-cix-danger"><i class="fas fa-sign-out-alt"></i></a>
        </div>
    </div>
    <?php if ($flash = flash('success')): ?><div class="alert-cix alert-cix-success"><i class="fas fa-check-circle"></i> <?= $flash ?></div><?php endif; ?>
    <?php if ($flash = flash('error')): ?><div class="alert-cix alert-cix-error"><i class="fas fa-exclamation-circle"></i> <?= $flash ?></div><?php endif; ?>
