<?php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

$title = $title ?? 'Caerus Tech Inventory Management System';
$user = $_SESSION['user'] ?? null;
?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title><?= htmlspecialchars($title, ENT_QUOTES, 'UTF-8') ?></title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
  <link rel="stylesheet" href="assets/app.css">
</head>
<body>
<nav class="navbar navbar-expand-lg app-topbar sticky-top">
  <div class="container-fluid px-3 px-md-4 py-2">
    <a class="app-brand" href="dashboard.php">
      <span class="app-brand-mark">CT</span>
      <span>
        Caerus Tech IMS
        <small>Inventory, barcode stock control, and delivery tracking</small>
      </span>
    </a>

    <button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#topNav" aria-controls="topNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="topNav">
      <ul class="navbar-nav ms-auto align-items-lg-center gap-2">
        <?php if ($user): ?>
          <li class="nav-item">
            <span class="app-user-chip">
              <span>Signed in as</span>
              <strong><?= htmlspecialchars((string)($user['full_name'] ?? 'User'), ENT_QUOTES, 'UTF-8') ?></strong>
              <span class="text-uppercase"><?= htmlspecialchars((string)($user['role_name'] ?? ''), ENT_QUOTES, 'UTF-8') ?></span>
            </span>
          </li>
          <li class="nav-item">
            <a class="btn btn-sm btn-outline-secondary" href="logout.php">Log out</a>
          </li>
        <?php endif; ?>
      </ul>
    </div>
  </div>
</nav>

<div class="container-fluid">
  <div class="row app-shell gx-0">
