<?php
?>
<!DOCTYPE html>
<html lang="en" class="layout-menu-fixed layout-compact" data-assets-path="<?php echo APP_URL; ?>/assets/materio/assets/" data-template="vertical-menu-template-free">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    <title><?php echo isset($pageTitle) ? htmlspecialchars($pageTitle) : 'SmartThink LMS'; ?></title>

    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet" />

    <link rel="stylesheet" href="<?php echo APP_URL; ?>/assets/materio/assets/vendor/fonts/iconify-icons.css" />

    <link rel="stylesheet" href="<?php echo APP_URL; ?>/assets/materio/assets/vendor/libs/node-waves/node-waves.css" />
    <link rel="stylesheet" href="<?php echo APP_URL; ?>/assets/materio/assets/vendor/css/core.css" />
    <link rel="stylesheet" href="<?php echo APP_URL; ?>/assets/materio/assets/css/demo.css" />

    <link rel="stylesheet" href="<?php echo APP_URL; ?>/assets/materio/assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" />
    <link rel="stylesheet" href="<?php echo APP_URL; ?>/assets/materio/assets/vendor/libs/apex-charts/apex-charts.css" />

    <script src="<?php echo APP_URL; ?>/assets/materio/assets/vendor/js/helpers.js"></script>
    <script src="<?php echo APP_URL; ?>/assets/materio/assets/js/config.js"></script>

    <style>
        /* TCS-inspired color scheme and typography */
        :root {
            --tcs-primary: #004B87;
            --tcs-primary-light: #0066CC;
            --tcs-primary-dark: #003366;
            --tcs-accent: #00A3CC;
            --tcs-gray-50: #F8F9FA;
            --tcs-gray-100: #E9ECEF;
            --tcs-gray-200: #DEE2E6;
            --tcs-gray-300: #CED4DA;
            --tcs-gray-400: #ADB5BD;
            --tcs-gray-500: #6C757D;
            --tcs-gray-600: #495057;
            --tcs-gray-700: #343A40;
            --tcs-gray-800: #212529;
            --tcs-gray-900: #141619;
            --tcs-white: #FFFFFF;
        }

        body {
            font-family: 'Inter', sans-serif;
            background-color: var(--tcs-gray-50);
        }

        .st-brand {
            display: inline-flex;
            align-items: center;
            gap: 0.75rem;
        }

        .st-brand-mark {
            width: 48px;
            height: 48px;
            border-radius: 12px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            color: var(--tcs-white);
            font-weight: 800;
            letter-spacing: 0.5px;
            background: linear-gradient(135deg, var(--tcs-primary) 0%, var(--tcs-primary-light) 100%);
            box-shadow: 0 8px 24px rgba(0, 75, 135, 0.25);
        }

        .st-brand-name {
            line-height: 1.2;
            color: var(--tcs-gray-800);
        }

        .st-brand-sub {
            font-size: 0.8rem;
            color: var(--tcs-gray-500);
            font-weight: 500;
        }

        /* Navigation styling */
        #layout-menu {
            background: var(--tcs-white);
            border-right: 1px solid var(--tcs-gray-200);
            box-shadow: 2px 0 10px rgba(0, 0, 0, 0.08);
        }

        .menu-inner .menu-item {
            margin: 0.25rem 0;
        }

        .menu-inner .menu-link {
            border-radius: 8px;
            margin: 0 0.75rem;
            padding: 0.75rem 1rem;
            transition: all 0.2s ease;
            color: var(--tcs-gray-600);
        }

        .menu-inner .menu-link:hover {
            background-color: var(--tcs-gray-50);
            color: var(--tcs-primary);
            transform: translateX(4px);
        }

        .menu-inner .menu-link.active {
            background-color: var(--tcs-primary);
            color: var(--tcs-white);
            box-shadow: 0 4px 12px rgba(0, 75, 135, 0.3);
        }

        .menu-inner .menu-icon {
            color: inherit;
            margin-right: 0.75rem;
        }

        /* Navbar styling */
        .layout-navbar {
            background: var(--tcs-white);
            border-bottom: 1px solid var(--tcs-gray-200);
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
            backdrop-filter: blur(12px);
        }

        .navbar-nav .nav-link {
            color: var(--tcs-gray-600);
            transition: color 0.2s ease;
        }

        .navbar-nav .nav-link:hover {
            color: var(--tcs-primary);
        }

        /* Form styling */
        .form-control {
            border: 1px solid var(--tcs-gray-300);
            border-radius: 8px;
            padding: 0.75rem 1rem;
            transition: all 0.2s ease;
        }

        .form-control:focus {
            border-color: var(--tcs-primary);
            box-shadow: 0 0 0 0.2rem rgba(0, 75, 135, 0.25);
        }

        .btn-primary {
            background-color: var(--tcs-primary);
            border-color: var(--tcs-primary);
            border-radius: 8px;
            padding: 0.75rem 1.5rem;
            font-weight: 600;
            transition: all 0.2s ease;
        }

        .btn-primary:hover {
            background-color: var(--tcs-primary-dark);
            border-color: var(--tcs-primary-dark);
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(0, 75, 135, 0.3);
        }

        /* Card styling */
        .card {
            border: none;
            border-radius: 12px;
            box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
            transition: all 0.2s ease;
        }

        .card:hover {
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
            transform: translateY(-2px);
        }

        .card-header {
            background: var(--tcs-gray-50);
            border-bottom: 1px solid var(--tcs-gray-200);
            border-radius: 12px 12px 0 0 !important;
            padding: 1.5rem;
        }

        .card-body {
            padding: 1.5rem;
        }

        /* Avatar styling */
        .avatar-initial {
            background: linear-gradient(135deg, var(--tcs-primary) 0%, var(--tcs-accent) 100%);
        }

        /* Badge styling */
        .badge {
            border-radius: 20px;
            font-weight: 500;
            padding: 0.5rem 1rem;
        }

        /* Menu header styling */
        .menu-header {
            color: var(--tcs-gray-500);
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin: 1.5rem 0 0.5rem 0;
            font-size: 0.8rem;
        }

        /* Layout adjustments */
        .layout-page {
            background-color: var(--tcs-gray-50);
        }

        .content-wrapper {
            padding: 0;
        }

        .container-xxl {
            max-width: 1400px;
        }

        /* Responsive adjustments */
        @media (max-width: 1199.98px) {
            .layout-menu-toggle {
                margin-left: 0;
            }
        }

        @media (max-width: 767.98px) {
            .menu-inner .menu-link {
                margin: 0 0.5rem;
                padding: 0.5rem 0.75rem;
            }

            .card-body {
                padding: 1rem;
            }
        }
    </style>
</head>
<body>

<div class="layout-wrapper layout-content-navbar">
    <div class="layout-container">
        <aside id="layout-menu" class="layout-menu menu-vertical menu bg-menu-theme">
            <div class="app-brand demo">
                <a href="<?php echo APP_URL; ?>/lms/dashboard.php" class="app-brand-link">
                    <span class="st-brand">
                        <span class="st-brand-mark">ST</span>
                        <span class="st-brand-name">
                            <span class="app-brand-text demo menu-text fw-semibold">SmartThink</span>
                            <span class="d-block st-brand-sub">Learning Hub</span>
                        </span>
                    </span>
                </a>

                <a href="javascript:void(0);" class="layout-menu-toggle menu-link text-large ms-auto">
                    <i class="menu-toggle-icon d-xl-inline-block align-middle"></i>
                </a>
            </div>

            <div class="menu-inner-shadow"></div>

            <ul class="menu-inner py-1">
                <li class="menu-item active">
                    <a href="<?php echo APP_URL; ?>/lms/dashboard.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-home-smile-line"></i>
                        <div data-i18n="Dashboard">Dashboard</div>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/courses.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-book-open-line"></i>
                        <div data-i18n="Courses">Browse Courses</div>
                    </a>
                </li>

                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/community_index.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-chat-3-line"></i>
                        <div>Communities</div>
                    </a>
                </li>

                <?php if (hasRole('student')): ?>
                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/dashboard.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-speed-mini-line"></i>
                        <div data-i18n="Dashboard">My Dashboard</div>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/my_cohorts.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-team-line"></i>
                        <div>My Cohorts</div>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/certificates.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-award-line"></i>
                        <div data-i18n="Certificates">My Certificates</div>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/appointments.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-calendar-check-line"></i>
                        <div>My Appointments</div>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/payments.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-wallet-3-line"></i>
                        <div>My Payments</div>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/ai_premium.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-robot-2-line"></i>
                        <div>AI Cybersecurity Copilot</div>
                    </a>
                </li>
                <?php endif; ?>

                <?php if (hasRole('instructor') || hasPermission('can_create_courses')): ?>
                <li class="menu-header small text-uppercase"><span class="menu-header-text">Instructor</span></li>
                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/dashboards/instructor.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-quill-pen-line"></i>
                        <div>Instructor Dashboard</div>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/my_courses.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-book-3-line"></i>
                        <div>My Courses</div>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/assessments.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-list-check"></i>
                        <div>Assessments</div>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/enrollments.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-user-3-line"></i>
                        <div>Enrollments</div>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/instructor_cohorts.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-map-pin-user-line"></i>
                        <div>Cohorts</div>
                    </a>
                </li>
                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/media.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-folder-3-line"></i>
                        <div>Media</div>
                    </a>
                </li>
                <?php endif; ?>

                <?php if (hasRole('regional_admin')): ?>
                <li class="menu-header small text-uppercase"><span class="menu-header-text">Regional</span></li>
                <li class="menu-item">
                    <a href="dashboards/regional_admin.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-map-pin-user-line"></i>
                        <div>Manage Region</div>
                    </a>
                </li>
                <?php endif; ?>

                <?php if (hasRole('admin')) : ?>
                    <li class="menu-header small text-uppercase">
                        <span class="menu-header-text">Admin / CMS</span>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/dashboard.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-settings-3-line"></i>
                            <div data-i18n="Admin Panel">Admin Panel</div>
                        </a>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/courses.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-book-open-line"></i>
                            <div>CMS Courses</div>
                        </a>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/cohorts.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-team-line"></i>
                            <div>Cohorts</div>
                        </a>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/enrollments.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-user-3-line"></i>
                            <div>Enrollments</div>
                        </a>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/assessments.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-list-check"></i>
                            <div>Assessments</div>
                        </a>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/certificates.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-award-line"></i>
                            <div>Certificates</div>
                        </a>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/users.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-group-line"></i>
                            <div>Users</div>
                        </a>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/payments.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-wallet-3-line"></i>
                            <div>Payments</div>
                        </a>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/reports.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-bar-chart-2-line"></i>
                            <div>Reports</div>
                        </a>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/site_content.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-article-line"></i>
                            <div>Site Content</div>
                        </a>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/whatsapp.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-whatsapp-line"></i>
                            <div>WhatsApp</div>
                        </a>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/analytics.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-bar-chart-grouped-line"></i>
                            <div>Analytics</div>
                        </a>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/settings.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-tools-line"></i>
                            <div>System Settings</div>
                        </a>
                    </li>
                <?php endif; ?>

                <li class="menu-item">
                    <a href="<?php echo APP_URL; ?>/lms/profile.php" class="menu-link">
                        <i class="menu-icon icon-base ri ri-user-line"></i>
                        <div data-i18n="Profile">Profile</div>
                    </a>
                </li>

                <?php if (isset($_SESSION['role']) && in_array($_SESSION['role'], ['admin', 'super_admin'], true)) : ?>
                    <li class="menu-header small text-uppercase">
                        <span class="menu-header-text">Admin</span>
                    </li>
                    <li class="menu-item">
                        <a href="../cms/dashboard.php" class="menu-link">
                            <i class="menu-icon icon-base ri ri-settings-3-line"></i>
                            <div data-i18n="Admin Panel">Admin Panel</div>
                        </a>
                    </li>
                <?php endif; ?>
            </ul>
        </aside>

        <div class="layout-page">
            <nav class="layout-navbar container-xxl navbar-detached navbar navbar-expand-xl align-items-center bg-navbar-theme" id="layout-navbar">
                <div class="layout-menu-toggle navbar-nav align-items-xl-center me-4 me-xl-0 d-xl-none">
                    <a class="nav-item nav-link px-0 me-xl-6" href="javascript:void(0)">
                        <i class="icon-base ri ri-menu-line icon-md"></i>
                    </a>
                </div>

                <div class="navbar-nav-right d-flex align-items-center justify-content-end" id="navbar-collapse">
                    <div class="navbar-nav align-items-center">
                        <div class="nav-item d-flex align-items-center">
                            <i class="icon-base ri ri-search-line icon-lg lh-0"></i>
                            <input type="text" class="form-control border-0 shadow-none" placeholder="Search..." aria-label="Search..." />
                        </div>
                    </div>

                    <ul class="navbar-nav flex-row align-items-center ms-md-auto">
                        <li class="nav-item navbar-dropdown dropdown-user dropdown">
                            <a class="nav-link dropdown-toggle hide-arrow p-0" href="javascript:void(0);" data-bs-toggle="dropdown">
                                <div class="avatar avatar-online">
                                    <span class="avatar-initial rounded-circle bg-primary">
                                        <?php echo isset($user['first_name']) ? strtoupper(substr($user['first_name'], 0, 1)) : 'U'; ?>
                                    </span>
                                </div>
                            </a>
                            <ul class="dropdown-menu dropdown-menu-end">
                                <li>
                                    <a class="dropdown-item" href="profile.php">
                                        <i class="icon-base ri ri-user-line icon-md me-3"></i>
                                        <span>My Profile</span>
                                    </a>
                                </li>
                                <li>
                                    <div class="dropdown-divider my-1"></div>
                                </li>
                                <li>
                                    <div class="d-grid px-4 pt-2 pb-1">
                                        <a class="btn btn-danger d-flex" href="logout.php">
                                            <small class="align-middle">Logout</small>
                                            <i class="ri ri-logout-box-r-line ms-2 ri-xs"></i>
                                        </a>
                                    </div>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </nav>

            <div class="content-wrapper">
                <div class="container-xxl flex-grow-1 container-p-y">
