<?php
$stmt = $conn->query("SELECT school_name, school_logo, school_favicon FROM administratives LIMIT 1");
if ($stmt && $stmt->num_rows > 0) {
    $adminData = $stmt->fetch_assoc();
    $school_name    = $adminData['school_name'] ?? 'CBT Admin Panel';
    $school_logo    = !empty($adminData['school_logo'])    ? $adminData['school_logo']    : null;
    $school_favicon = !empty($adminData['school_favicon']) ? $adminData['school_favicon'] : null;
}
?>
<?php
$student_name  = '';
$student_photo = '';

if (isset($_SESSION['student_id'])) {
    $student_id = $_SESSION['student_id'];
    $stmt = $conn->prepare("SELECT firstname, lastname, passport FROM students WHERE id = ? LIMIT 1");
    $stmt->bind_param("i", $student_id);
    $stmt->execute();
    $result = $stmt->get_result();
    if ($result && $result->num_rows > 0) {
        $student       = $result->fetch_assoc();
        $student_name  = $student['firstname'] . ' ' . $student['lastname'];
        $student_photo = !empty($student['passport']) ? $student['passport'] : $student_photo;
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="<?= htmlspecialchars($school_name) ?> CBT Exam — Online Assessment Portal">
  <title><?= htmlspecialchars($school_name) ?> - Online Exam</title>

  <!-- Favicon -->
  <?php if (!empty($school_favicon)): ?>
    <link rel="icon" href="../../<?= htmlspecialchars($school_favicon) ?>" type="image/x-icon">
  <?php endif; ?>

  <!-- Google Fonts -->
  <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;800&display=swap" rel="stylesheet">

  <!-- AdminLTE & Icons -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/css/adminlte.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet">

  <!-- CBT Premium Theme -->
  <link rel="stylesheet" href="../../assets/css/cbt-theme.css">

  <style>
    /* Exam-specific: no sidebar for exam page — full-width content */
    body.exam-mode .main-sidebar { display: none !important; }
    body.exam-mode .content-wrapper { margin-left: 0 !important; }
    body.exam-mode .main-header.navbar { margin-left: 0 !important; width: 100% !important; }

    .content-wrapper {
      overflow-y: auto;
      max-height: calc(100vh - 58px);
    }
  </style>
</head>
<body class="hold-transition sidebar-mini layout-fixed exam-mode">
<div class="wrapper">

<!-- Minimal Exam Topbar -->
<nav class="main-header navbar navbar-expand navbar-white navbar-light">
  <ul class="navbar-nav">
    <li class="nav-item d-none d-sm-inline-block">
      <a href="#" class="nav-link font-weight-bold text-uppercase">
        <?php if ($school_logo): ?>
          <img src="../../<?= htmlspecialchars($school_logo) ?>" alt="logo" height="28" class="mr-2" style="vertical-align:middle; border-radius:6px;">
        <?php endif; ?>
        <?= htmlspecialchars($school_name) ?>
      </a>
    </li>
  </ul>
  <ul class="navbar-nav ml-auto align-items-center">
    <li class="nav-item me-2 d-none d-sm-inline-block">
      <span class="nav-link text-muted" style="font-size:0.82rem; font-weight:600;">
        <i class="fas fa-user-graduate me-1"></i>
        <?= htmlspecialchars($student_name) ?>
      </span>
    </li>
    <li class="nav-item">
      <a class="nav-link text-danger" href="../logout.php" title="Exit Exam"
         onclick="return confirm('Exit exam? Progress may be lost.')">
        <i class="fas fa-sign-out-alt"></i>
      </a>
    </li>
  </ul>
</nav>
