<?php
// /elms/includes/student_layout_top.php
declare(strict_types=1);

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

require_once __DIR__ . '/elms_notifications.php';
require_once __DIR__ . '/elms_settings.php';

$PAGE_TITLE = $PAGE_TITLE ?? 'Student Portal';
$ACTIVE     = $ACTIVE ?? '';

$studentName  = $GLOBALS['STUDENT_NAME'] ?? $_SESSION['student_name'] ?? $_SESSION['full_name'] ?? 'Student';
$studentEmail = $GLOBALS['STUDENT_EMAIL'] ?? $_SESSION['student_email'] ?? $_SESSION['academic_email'] ?? '';
$studentRegNo = $GLOBALS['STUDENT_REG_NO'] ?? $_SESSION['center_reg_no'] ?? $_SESSION['student_reg_no'] ?? '';


$layoutDb = $mysqli ?? ($conn ?? null);
$themeColor = '#2563eb';

if ($layoutDb instanceof mysqli) {
    $themeColor = elms_setting($layoutDb, 'theme_color', '#2563eb');
}

if (!preg_match('/^#[0-9a-fA-F]{6}$/', $themeColor)) {
    $themeColor = '#2563eb';
}


if (!function_exists('h')) {
    function h($value): string
    {
        return htmlspecialchars((string)$value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
    }
}

if (!function_exists('student_active')) {
    function student_active(string $key, string $active): string
    {
        return $key === $active ? 'active' : '';
    }
}

$studentInitial = strtoupper(substr(trim((string)$studentName), 0, 1) ?: 'S');
$studentPhoto = $_SESSION['student_photo'] ?? $_SESSION['photograph'] ?? '';

if ($studentPhoto === '') {
    $layoutDb = $mysqli ?? ($conn ?? null);
    $layoutStudentId = (int)($GLOBALS['STUDENT_ID'] ?? ($_SESSION['student_id'] ?? 0));

    if ($layoutDb instanceof mysqli && $layoutStudentId > 0) {
        $q = $layoutDb->prepare("SELECT photograph FROM studentss WHERE id=? LIMIT 1");
        if ($q) {
            $q->bind_param('i', $layoutStudentId);
            $q->execute();
            $r = $q->get_result()->fetch_assoc();
            $q->close();

            $studentPhoto = trim((string)($r['photograph'] ?? ''));
            $_SESSION['student_photo'] = $studentPhoto;
        }
    }
}

if ($studentPhoto !== '') {
    if (!preg_match('~^https?://~i', $studentPhoto) && !str_starts_with($studentPhoto, '/')) {
        $studentPhoto = '/edenrms/uploads/' . $studentPhoto;
    }
}

/* ---------------- Notifications ---------------- */

$notifCount = 0;
$notifRows = [];

$notifDb = $mysqli ?? ($conn ?? null);
$notifStudentId = (int)($GLOBALS['STUDENT_ID'] ?? ($_SESSION['student_id'] ?? 0));

if ($notifDb instanceof mysqli && $notifStudentId > 0) {
    $notifCount = lms_unread_notification_count($notifDb, 'student', $notifStudentId);
    $notifRows  = lms_recent_notifications($notifDb, 'student', $notifStudentId, 6);
}

$navItems = [
    [
        'key'   => 'dashboard',
        'label' => 'Dashboard',
        'icon'  => 'bi-house-door',
        'url'   => '/elms/student/index.php',
    ],
    [
        'key'   => 'submit',
        'label' => 'Submit',
        'icon'  => 'bi-clipboard-check',
        'url'   => '/elms/student/assessments/assessments.php',
    ],
    [
        'key'   => 'results',
        'label' => 'Results',
        'icon'  => 'bi-award',
        'url'   => '/elms/student/results.php',
    ],
];
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title><?= h($PAGE_TITLE) ?> | EDEN ELMS Student</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">

    <style>
        :root {
            --student-bg: #f7f8fb;
            --student-card: #ffffff;
            --student-text: #16213a;
            --student-muted: #6b7280;
            --student-border: #e5e7eb;
            --student-primary: <?= h($themeColor) ?>;
--student-primary-2: <?= h($themeColor) ?>;
            --student-soft: #eff6ff;
            --student-danger: #dc2626;
            --student-success: #16a34a;
            --student-warning: #f59e0b;
        }

        * {
            box-sizing: border-box;
        }

        html,
        body {
            min-height: 100%;
        }

        body {
            margin: 0;
            background: var(--student-bg);
            color: var(--student-text);
            font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
            font-size: 14px;
        }

        a {
            text-decoration: none;
        }

        .student-app {
            min-height: 100vh;
            background: var(--student-bg);
        }

        /* Top Header */

        .student-top-header {
            background: #fff;
            border-bottom: 1px solid var(--student-border);
            position: sticky;
            top: 0;
            z-index: 1040;
        }

        .student-top-inner {
            min-height: 76px;
            max-width: 1540px;
            margin: 0 auto;
            padding: 0 28px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 22px;
        }

        .student-brand {
            display: inline-flex;
            align-items: center;
            gap: 12px;
            color: var(--student-text);
            min-width: 190px;
        }

        .student-brand-logo {
            width: 58px;
            height: 42px;
            object-fit: contain;
        }

        .student-brand-fallback {
            width: 54px;
            height: 42px;
            border-radius: 13px;
            background: linear-gradient(135deg, var(--student-primary), var(--student-primary-2));
            display: grid;
            place-items: center;
            color: #fff;
            font-weight: 900;
            letter-spacing: -.3px;
        }

        .student-brand-title {
            font-weight: 900;
            font-size: 1rem;
            letter-spacing: -.2px;
            margin: 0;
            line-height: 1.1;
        }

        .student-brand-sub {
            color: var(--student-muted);
            font-size: .74rem;
            margin-top: 2px;
            font-weight: 650;
        }

        .student-main-nav {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            flex: 1;
        }

        .student-main-nav a {
            display: inline-flex;
            align-items: center;
            gap: 7px;
            color: #526071;
            font-weight: 750;
            padding: 10px 12px;
            border-radius: 999px;
            transition: .16s ease;
            font-size: .88rem;
            white-space: nowrap;
        }

        .student-main-nav a:hover {
            color: var(--student-primary);
            background: var(--student-soft);
        }

        .student-main-nav a.active {
            background: #003f91;
            color: #fff;
            box-shadow: 0 8px 18px rgba(3,78,162,.18);
        }

        .student-header-actions {
            display: flex;
            align-items: center;
            justify-content: flex-end;
            gap: 12px;
            min-width: 230px;
        }

        .student-icon-btn {
            width: 42px;
            height: 42px;
            border: 1px solid var(--student-border);
            background: #fff;
            color: #334155;
            border-radius: 50%;
            display: grid;
            place-items: center;
            position: relative;
            transition: .15s ease;
        }

        .student-icon-btn:hover {
            color: var(--student-primary);
            background: #f8fafc;
            border-color: #bfdbfe;
        }

        .notif-red-dot {
            position: absolute;
            top: 3px;
            right: 4px;
            min-width: 16px;
            height: 16px;
            padding: 0 4px;
            border-radius: 999px;
            background: var(--student-danger);
            color: #fff;
            font-size: .62rem;
            display: grid;
            place-items: center;
            border: 2px solid #fff;
            font-weight: 900;
        }

        .student-profile-trigger {
            border: 0;
            background: transparent;
            display: flex;
            align-items: center;
            gap: 9px;
            padding: 4px 0;
            color: var(--student-text);
        }

        .student-avatar {
            width: 42px;
            height: 42px;
            border-radius: 50%;
            background: #e7efff;
            color: var(--student-primary);
            display: grid;
            place-items: center;
            font-weight: 900;
            border: 1px solid #dbeafe;
        }

        .student-profile-name {
            font-weight: 850;
            font-size: .9rem;
            max-width: 190px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .student-profile-reg {
            color: var(--student-muted);
            font-size: .75rem;
            text-align: left;
        }

        .mobile-nav-btn {
            display: none;
            width: 42px;
            height: 42px;
            border-radius: 13px;
            border: 1px solid var(--student-border);
            background: #fff;
            align-items: center;
            justify-content: center;
        }

        /* Mobile Menu */

        .student-mobile-menu {
            display: none;
            border-top: 1px solid var(--student-border);
            background: #fff;
            padding: 10px 16px 16px;
        }

        .student-mobile-menu.show {
            display: block;
        }

        .student-mobile-menu a {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 12px 14px;
            border-radius: 14px;
            color: #526071;
            font-weight: 750;
            margin-bottom: 4px;
        }

        .student-mobile-menu a.active {
            background: #003f91;
            color: #fff;
        }

        /* Notification dropdown */

        .student-notif-menu {
            width: 390px;
            max-width: 92vw;
            padding: 0;
            border-radius: 18px;
            border: 1px solid var(--student-border);
            box-shadow: 0 18px 45px rgba(15,23,42,.14);
            overflow: hidden;
        }

        .student-notif-head {
            padding: 16px 17px;
            border-bottom: 1px solid var(--student-border);
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
            background: #fff;
        }

        .student-notif-scroll {
            max-height: 420px;
            overflow: auto;
            background: #fafafa;
            padding: 10px;
        }

        .student-notif-item {
            display: block;
            border-radius: 16px;
            background: #fff;
            color: var(--student-text);
            padding: 13px;
            margin-bottom: 10px;
            border: 1px solid #eef2f7;
            white-space: normal;
        }

        .student-notif-item.unread {
            background: #f8fbff;
            border-color: #dbeafe;
        }

        .student-notif-title {
            font-weight: 850;
            margin-bottom: 4px;
        }

        .student-notif-message {
            color: #5b6472;
            font-size: .83rem;
            line-height: 1.45;
        }

        .student-notif-footer {
            padding: 10px;
            background: #fff;
            border-top: 1px solid var(--student-border);
            text-align: center;
        }

        /* Main Page */

        .student-page {
            max-width: 1540px;
            margin: 0 auto;
            padding: 24px 28px 38px;
        }

        .student-page-head {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 18px;
            margin-bottom: 22px;
        }

        .student-breadcrumb {
            display: flex;
            align-items: center;
            gap: 9px;
            color: var(--student-muted);
            font-size: .8rem;
            font-weight: 650;
            margin-bottom: 12px;
        }

        .student-breadcrumb a {
            color: var(--student-muted);
        }

        .student-breadcrumb a:hover {
            color: var(--student-primary);
        }

        .student-page-title-row {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .student-back-btn {
            width: 36px;
            height: 36px;
            display: grid;
            place-items: center;
            border-radius: 50%;
            border: 1px solid #dbe3ef;
            background: #fff;
            color: var(--student-primary);
        }

        .student-page-title {
            margin: 0;
            font-size: 1.55rem;
            font-weight: 900;
            color: #12386f;
            letter-spacing: -.5px;
        }

        .student-page-subtitle {
            margin: 4px 0 0;
            color: var(--student-muted);
            font-size: .9rem;
        }

        /* Page tabs like reference */

        .student-page-tabs {
            display: flex;
            align-items: center;
            gap: 24px;
            border-bottom: 1px solid var(--student-border);
            margin-bottom: 20px;
            overflow-x: auto;
        }

        .student-page-tabs a,
        .student-page-tabs button {
            border: 0;
            background: transparent;
            color: #8a8f98;
            padding: 12px 0 11px;
            font-weight: 850;
            position: relative;
            white-space: nowrap;
        }

        .student-page-tabs a.active,
        .student-page-tabs button.active {
            color: var(--student-primary);
        }

        .student-page-tabs a.active::after,
        .student-page-tabs button.active::after {
            content: "";
            position: absolute;
            left: 0;
            right: 0;
            bottom: -1px;
            height: 2px;
            background: var(--student-primary);
            border-radius: 999px;
        }

        /* Common UI */

        .student-card {
            background: var(--student-card);
            border: 1px solid var(--student-border);
            border-radius: 18px;
            box-shadow: 0 10px 28px rgba(15,23,42,.045);
        }

        .student-card-header {
            padding: 17px 18px;
            border-bottom: 1px solid var(--student-border);
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 14px;
        }

        .student-card-body {
            padding: 18px;
        }

        .student-section-title {
            margin: 0;
            font-size: 1.05rem;
            font-weight: 900;
            color: #263247;
        }

        .student-muted {
            color: var(--student-muted);
        }

        .student-pill {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 6px 10px;
            border-radius: 999px;
            background: #eff6ff;
            color: var(--student-primary);
            font-weight: 850;
            font-size: .74rem;
        }

        .btn-student-primary {
            background: var(--student-primary-2);
            border-color: var(--student-primary-2);
            color: #fff;
            border-radius: 12px;
            font-weight: 850;
            padding: 9px 14px;
        }

        .btn-student-primary:hover {
            background: #1d4ed8;
            border-color: #1d4ed8;
            color: #fff;
        }

        .form-control,
        .form-select {
            border-radius: 12px;
            border-color: #dbe3ef;
            padding: 10px 12px;
        }

        .form-control:focus,
        .form-select:focus {
            border-color: var(--student-primary-2);
            box-shadow: 0 0 0 .2rem rgba(37,99,235,.12);
        }

        .table {
            vertical-align: middle;
        }

        .table thead th {
            background: #f8fafc;
            color: #475569;
            font-size: 12px;
            text-transform: uppercase;
            letter-spacing: .04em;
            border-bottom: 1px solid var(--student-border);
        }

        .dropdown-menu {
            border: 1px solid var(--student-border);
            border-radius: 16px;
            box-shadow: 0 18px 45px rgba(15,23,42,.14);
            padding: 8px;
        }

        .dropdown-item {
            border-radius: 11px;
            font-weight: 700;
            font-size: .86rem;
            padding: 9px 10px;
        }
        .student-profile-menu {
    width: 280px;
    padding: 0;
    overflow: hidden;
    border-radius: 18px;
}

.student-profile-menu-head {
    padding: 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #fff;
}

.student-profile-menu-name {
    font-weight: 900;
    color: #111827;
    line-height: 1.35;
}

.student-profile-menu-meta {
    color: #6b7280;
    font-size: .8rem;
    margin-top: 3px;
}

.student-profile-menu-body {
    padding: 8px;
}

.student-profile-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 11px;
}

.student-profile-menu .dropdown-item.active-soft {
    background: #f3f4f6;
    color: #111827;
}

        @media (max-width: 1150px) {
            .student-main-nav {
                display: none;
            }

            .mobile-nav-btn {
                display: inline-flex;
            }

            .student-top-inner {
                padding: 0 18px;
            }

            .student-header-actions {
                min-width: auto;
            }
        }

        @media (max-width: 768px) {
            .student-top-inner {
                min-height: 68px;
                gap: 12px;
            }

            .student-brand {
                min-width: auto;
            }

            .student-brand-title,
            .student-brand-sub {
                display: none;
            }

            .student-profile-name,
            .student-profile-reg {
                display: none;
            }

            .student-page {
                padding: 18px 14px 30px;
            }

            .student-page-head {
                display: block;
            }

            .student-page-title {
                font-size: 1.25rem;
            }

            .student-breadcrumb {
                font-size: .75rem;
                overflow-x: auto;
                white-space: nowrap;
            }
        }

        @media (max-width: 480px) {
            .student-brand-logo {
                width: 48px;
                height: 36px;
            }

            .student-icon-btn,
            .student-avatar,
            .mobile-nav-btn {
                width: 38px;
                height: 38px;
            }

            .student-notif-menu {
                width: 340px;
            }
        }
        @media (max-width: 992px) {
    .student-top-inner {
        min-height: 64px;
        padding: 0 14px;
    }

    .student-main-nav {
        display: none !important;
    }

    .mobile-nav-btn {
        display: inline-flex !important;
    }

    .student-brand {
        min-width: auto;
    }

    .student-brand-logo {
        width: 48px;
        height: 34px;
    }

    .student-brand-title {
        font-size: .85rem;
    }

    .student-brand-sub {
        font-size: .68rem;
    }

    .student-header-actions {
        min-width: auto;
        gap: 8px;
    }

    .student-profile-name,
    .student-profile-reg {
        display: none;
    }

    .student-page {
        padding: 18px 14px 28px;
    }
}
    </style>
</head>

<body>

<div class="student-app">

    <header class="student-top-header">
        <div class="student-top-inner">
            <div class="d-flex align-items-center gap-2">
                <button type="button" class="mobile-nav-btn" onclick="toggleStudentMobileMenu()" aria-label="Menu">
                    <i class="bi bi-list fs-5"></i>
                </button>

                <a href="/elms/student/index.php" class="student-brand">
                    <img
                        src="/elms/includes/logo/edden_logo.jpg"
                        alt="EDEN CAMPUS"
                        class="student-brand-logo"
                        onerror="this.style.display='none';this.nextElementSibling.style.display='grid';"
                    >
                    <span class="student-brand-fallback" style="display:none;">EC</span>

                    <span>
                        <span class="student-brand-title d-block">EDEN CAMPUS</span>
                        <span class="student-brand-sub d-block">Student Portal</span>
                    </span>
                </a>
            </div>

            <nav class="student-main-nav">
                <?php foreach ($navItems as $item): ?>
                    <a href="<?= h($item['url']) ?>" class="<?= student_active($item['key'], $ACTIVE) ?>">
                        <i class="bi <?= h($item['icon']) ?>"></i>
                        <span><?= h($item['label']) ?></span>
                    </a>
                <?php endforeach; ?>
            </nav>

            <div class="student-header-actions">
                <div class="dropdown">
                    <button
                        class="student-icon-btn"
                        type="button"
                        data-bs-toggle="dropdown"
                        aria-expanded="false"
                        title="Notifications"
                    >
                        <i class="bi bi-bell"></i>

                        <?php if ($notifCount > 0): ?>
                            <span class="notif-red-dot">
                                <?= $notifCount > 99 ? '99+' : (int)$notifCount ?>
                            </span>
                        <?php endif; ?>
                    </button>

                    <div class="dropdown-menu dropdown-menu-end student-notif-menu">
                        <div class="student-notif-head">
                            <strong>Notifications</strong>
                            <span class="badge bg-primary rounded-pill"><?= (int)$notifCount ?> new</span>
                        </div>

                        <?php if (!$notifRows): ?>
                            <div class="p-4 text-center text-muted">
                                <i class="bi bi-bell-slash fs-3 d-block mb-2"></i>
                                No notifications yet
                            </div>
                        <?php else: ?>
                            <div class="student-notif-scroll">
                                <?php foreach ($notifRows as $n): ?>
                                    <?php
                                    $nTitle = $n['title'] ?? 'Notification';
                                    $nMsg   = $n['message'] ?? '';
                                    $nLink  = $n['link_url'] ?: '/elms/student/notifications.php';
                                    $nDate  = !empty($n['created_at']) ? date('d M Y, h:i A', strtotime((string)$n['created_at'])) : '';
                                    $unread = ((int)($n['is_read'] ?? 0) === 0);
                                    ?>

                                    <a href="<?= h($nLink) ?>" class="student-notif-item <?= $unread ? 'unread' : '' ?>">
                                        <div class="student-notif-title"><?= h($nTitle) ?></div>

                                        <?php if ($nMsg !== ''): ?>
                                            <div class="student-notif-message">
                                                <?= h($nMsg) ?>
                                            </div>
                                        <?php endif; ?>

                                        <?php if ($nDate !== ''): ?>
                                            <div class="small text-muted mt-2">
                                                <i class="bi bi-clock me-1"></i><?= h($nDate) ?>
                                            </div>
                                        <?php endif; ?>
                                    </a>
                                <?php endforeach; ?>
                            </div>

                            <div class="student-notif-footer">
                                <a href="/elms/student/notifications.php" class="btn btn-sm btn-outline-primary rounded-pill px-3">
                                    View All
                                </a>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>

                <div class="dropdown">
                    <button
                        class="student-profile-trigger"
                        type="button"
                        data-bs-toggle="dropdown"
                        aria-expanded="false"
                    >
                        <div class="text-end">
                            <div class="student-profile-name"><?= h($studentName) ?></div>
                            <div class="student-profile-reg"><?= h($studentRegNo ?: 'Student') ?></div>
                        </div>

                        <span class="student-avatar">
    <?php if ($studentPhoto !== ''): ?>
        <img src="<?= h($studentPhoto) ?>"
             alt="Profile"
             style="width:100%;height:100%;object-fit:cover;border-radius:50%;"
             onerror="this.style.display='none';this.parentNode.innerHTML='<?= h($studentInitial) ?>';">
    <?php else: ?>
        <?= h($studentInitial) ?>
    <?php endif; ?>
</span>
                        <i class="bi bi-chevron-down small text-muted"></i>
                    </button>

<div class="dropdown-menu dropdown-menu-end student-profile-menu">
    <div class="student-profile-menu-head">
        <div class="student-profile-menu-name">
            <?= h($studentName) ?>
        </div>

        <?php if ($studentEmail !== ''): ?>
            <div class="student-profile-menu-meta">
                <?= h($studentEmail) ?>
            </div>
        <?php endif; ?>

        <?php if ($studentRegNo !== ''): ?>
            <div class="student-profile-menu-meta">
                <?= h($studentRegNo) ?>
            </div>
        <?php endif; ?>
    </div>

    <div class="student-profile-menu-body">
        <a class="dropdown-item <?= $ACTIVE === 'profile' ? 'active-soft' : '' ?>"
   href="#"
   data-bs-toggle="modal"
   data-bs-target="#studentProfileModal"
   onclick="openStudentProfileModal(); return false;">
            <i class="bi bi-person-circle"></i>
            Profile
        </a>

        <a class="dropdown-item <?= $ACTIVE === 'results' ? 'active-soft' : '' ?>" href="/elms/student/results.php">
            <i class="bi bi-award"></i>
            Results
        </a>

        <a class="dropdown-item <?= $ACTIVE === 'notifications' ? 'active-soft' : '' ?>" href="/elms/student/notifications.php">
            <i class="bi bi-bell"></i>
            Notifications
        </a>

        <hr class="dropdown-divider my-2">

        <a class="dropdown-item text-danger" href="/elms/student/logout.php">
            <i class="bi bi-box-arrow-right"></i>
            Logout
        </a>
    </div>
</div>
                </div>
            </div>
        </div>

        <nav class="student-mobile-menu" id="studentMobileMenu">
            <?php foreach ($navItems as $item): ?>
                <a href="<?= h($item['url']) ?>" class="<?= student_active($item['key'], $ACTIVE) ?>">
                    <i class="bi <?= h($item['icon']) ?>"></i>
                    <span><?= h($item['label']) ?></span>
                </a>
            <?php endforeach; ?>

            <a href="/elms/student/profile.php" class="<?= student_active('profile', $ACTIVE) ?>">
                <i class="bi bi-person-circle"></i>
                <span>Profile</span>
            </a>

            <a href="/elms/student/logout.php" class="text-danger">
                <i class="bi bi-box-arrow-right"></i>
                <span>Logout</span>
            </a>
        </nav>
    </header>

<div class="modal fade" id="studentProfileModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable">
        <div class="modal-content border-0 rounded-4 overflow-hidden">
            <div class="modal-header border-0 bg-white">
                <h5 class="modal-title fw-bold text-primary">My Profile</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>

            <div class="modal-body p-0">
                <iframe
                    id="studentProfileFrame"
                    src="about:blank"
                    style="width:100%;height:82vh;border:0;background:#fff;display:block;"
                    title="Student Profile"
                ></iframe>
            </div>
        </div>
    </div>
</div>

<script>
function openStudentProfileModal() {
    const frame = document.getElementById('studentProfileFrame');
    if (frame && frame.getAttribute('src') === 'about:blank') {
        frame.setAttribute('src', '/elms/student/profile.php?embedded=1');
    }
}
</script>

    <main class="student-page">
        <div class="student-page-head">
            <div>
                <div class="student-breadcrumb">
                    <a href="/elms/student/index.php">
                        <i class="bi bi-house-door"></i>
                    </a>
                    <i class="bi bi-chevron-right small"></i>
                    <span>Student Portal</span>
                    <i class="bi bi-chevron-right small"></i>
                    <span><?= h($PAGE_TITLE) ?></span>
                </div>

                <div class="student-page-title-row">
                    <a href="javascript:history.back()" class="student-back-btn" title="Back">
                        <i class="bi bi-arrow-left"></i>
                    </a>

                    <div>
                        <h1 class="student-page-title"><?= h($PAGE_TITLE) ?></h1>
                        <p class="student-page-subtitle">
                            Welcome back, <?= h($studentName) ?>
                        </p>
                    </div>
                </div>
            </div>
        </div>
        
        
        <script>
function toggleStudentMobileMenu() {
    const menu = document.getElementById('studentMobileMenu');
    if (menu) {
        menu.classList.toggle('show');
    }
}

document.addEventListener('click', function (e) {
    const menu = document.getElementById('studentMobileMenu');
    const btn = e.target.closest('.mobile-nav-btn');

    if (!menu) return;

    if (!btn && !menu.contains(e.target)) {
        menu.classList.remove('show');
    }
});
</script>