<?php
include_once __DIR__ . '/auth.php';
$currentPage = basename(parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH) ?: '');
$navItems = [
    'home.php' => 'Home',
    'formularios.php' => 'Formulários',
    'pesquisas.php' => 'Pesquisas',
];
$usuarioNome = trim((string) ($_SESSION['usuario_nome'] ?? 'Acesso Livre'));
$pageTitle = trim((string) ($pageTitle ?? 'Sistema de Gestão'));
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title><?= htmlspecialchars($pageTitle, ENT_QUOTES, 'UTF-8') ?></title>
  <script src="https://cdn.tailwindcss.com"></script>
  <link rel="icon" type="image/png" href="img/Logo.png">
</head>
<body class="bg-slate-100 text-slate-800">
  <nav class="sticky top-0 z-40 border-b border-slate-200 bg-white/95 backdrop-blur">
    <div class="mx-auto flex max-w-7xl items-center justify-between gap-4 px-4 py-3 sm:px-6">
      <div class="flex items-center gap-3">
        <div class="flex h-10 w-10 items-center justify-center rounded-2xl bg-blue-600 text-lg font-bold text-white shadow-sm">M</div>
        <div>
          <div class="text-base font-bold leading-tight text-slate-900">Motion Fit</div>
          <div class="text-xs text-slate-500">Gestão de formulários e pesquisas</div>
        </div>
      </div>

      <div class="hidden items-center gap-2 md:flex">
        <?php foreach ($navItems as $href => $label): ?>
          <?php $active = $currentPage === $href; ?>
          <a href="<?= $href ?>" class="rounded-xl px-4 py-2 text-sm font-medium transition <?= $active ? 'bg-blue-600 text-white shadow-sm' : 'text-slate-600 hover:bg-slate-100 hover:text-slate-900' ?>">
            <?= htmlspecialchars($label, ENT_QUOTES, 'UTF-8') ?>
          </a>
        <?php endforeach; ?>
      </div>

      <div class="flex items-center gap-3">
        <div class="hidden rounded-2xl border border-slate-200 bg-slate-50 px-3 py-2 text-right sm:block">
          <div class="text-xs text-slate-500">Acesso atual</div>
          <div class="max-w-[180px] truncate text-sm font-semibold text-slate-800"><?= htmlspecialchars($usuarioNome, ENT_QUOTES, 'UTF-8') ?></div>
        </div>
      </div>
    </div>

    <div class="border-t border-slate-100 bg-white md:hidden">
      <div class="mx-auto flex max-w-7xl items-center gap-2 overflow-x-auto px-4 py-2 sm:px-6">
        <?php foreach ($navItems as $href => $label): ?>
          <?php $active = $currentPage === $href; ?>
          <a href="<?= $href ?>" class="whitespace-nowrap rounded-xl px-4 py-2 text-sm font-medium transition <?= $active ? 'bg-blue-600 text-white' : 'bg-slate-100 text-slate-700 hover:bg-slate-200' ?>">
            <?= htmlspecialchars($label, ENT_QUOTES, 'UTF-8') ?>
          </a>
        <?php endforeach; ?>
      </div>
    </div>
  </nav>

  <main class="mx-auto max-w-7xl px-4 py-6 sm:px-6">
