<?php
// /elms/lecturer/layout_top.php
if (session_status() === PHP_SESSION_NONE) session_start();

/* small helpers (safe to re-declare) */
if (!function_exists('esc')) {
  function esc($s){ return htmlspecialchars((string)$s, ENT_QUOTES|ENT_SUBSTITUTE, 'UTF-8'); }
}
if (!function_exists('app_url')) {
  function app_url(string $path=''): string {
    $script = str_replace('\\','/', $_SERVER['SCRIPT_NAME'] ?? '');
    $base = preg_replace('#/lecturer/.*$#', '/elms', $script) ?: '/elms';
    if ($path !== '' && $path[0] !== '/') $path = '/'.$path;
    return rtrim($base, '/') . $path;
  }
}

/* current user (works with either lecturer or user session) */
$lecturerName = $_SESSION['lecturer']['name']
  ?? ($_SESSION['user']['full_name'] ?? ($_SESSION['user']['username'] ?? 'Lecturer'));

/* page vars expected from including file */
$PAGE_TITLE  = $PAGE_TITLE  ?? 'Lecturer';
$ACTIVE_MENU = $ACTIVE_MENU ?? '';
?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title><?= esc($PAGE_TITLE) ?> ¡¤ Lecturer</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="../assets/elms-ui.css?v=4">
</head>
<body>
<div class="page">
  <!-- Left sidebar -->
  <aside class="sidebar">
    <div class="side-head">Lecturer</div>
    <div class="who">
      <div style="font-weight:700"><?= esc($lecturerName) ?></div>
      <div style="text-transform:uppercase;font-size:11px;letter-spacing:.08em">LECTURER</div>
    </div>
    <nav class="nav">
      <a class="<?= $ACTIVE_MENU==='dashboard' ? 'active':'' ?>"   href="<?= esc(app_url('/lecturer/dashboard.php')) ?>">”9Æ2 Dashboard</a>
      <a class="<?= $ACTIVE_MENU==='assessments' ? 'active':'' ?>" href="<?= esc(app_url('/lecturer/assessments/index.php')) ?>">•0ä8 Assessments</a>
      <a href="<?= esc(app_url('/logout.php')) ?>">”9ä9 Logout</a>
    </nav>
  </aside>

  <!-- Content area -->
  <main class="content">
    <div class="topbar">
      <div class="crumb"><?= esc($PAGE_TITLE) ?></div>
      <div class="when"><?= date('Y-m-d H:i') ?> (Sri Lanka)</div>
    </div>

    <div class="wrap">
