<?php
require_once __DIR__ . '/functions.php';
requireLogin();
$storeName   = getSetting('store_name', 'Rewards System');
$currentPage = basename($_SERVER['PHP_SELF'], '.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= e($pageTitle ?? 'Dashboard') ?> — <?= e($storeName) ?></title>

<!-- Bootstrap 5 -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.2/font/bootstrap-icons.css" rel="stylesheet">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<!-- Custom -->
<link href="<?= BASE_URL ?>/assets/css/style.css" rel="stylesheet">
</head>
<body>

<div class="d-flex" id="app-wrapper">

  <!-- ── Sidebar ── -->
  <?php include __DIR__ . '/sidebar.php'; ?>

  <!-- ── Content wrapper ── -->
  <div id="content-wrapper" class="flex-grow-1 d-flex flex-column">

    <!-- Top nav -->
    <nav class="navbar navbar-light bg-white border-bottom shadow-sm px-3 py-2 topnav">
      <button class="btn btn-light btn-sm me-2" id="sidebarToggle" title="Toggle Sidebar">
        <i class="bi bi-list fs-5"></i>
      </button>
      <span class="fw-bold text-dark"><?= e($pageTitle ?? '') ?></span>
      <div class="ms-auto d-flex align-items-center gap-3">
        <span class="badge <?= isAdmin() ? 'bg-danger' : 'bg-primary' ?> text-uppercase">
          <?= e($_SESSION['role'] ?? 'user') ?>
        </span>
        <span class="d-none d-md-inline text-muted small">
          <i class="bi bi-person-circle me-1"></i><?= e($_SESSION['full_name'] ?? $_SESSION['username'] ?? '') ?>
        </span>
        <a href="<?= BASE_URL ?>/logout.php" class="btn btn-outline-danger btn-sm">
          <i class="bi bi-box-arrow-right me-1"></i>Logout
        </a>
      </div>
    </nav>

    <!-- Page body -->
    <div class="page-body p-4 flex-grow-1">
