<?php
declare(strict_types=1);

require_once __DIR__ . "/../../includes/session_staff.php";
require_staff(null);

$s    = staff_current();
$nome = $s['nome'] ?? '';
$role = $s['role'] ?? '';

function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }
function is_admin($r){ return $r === 'ADMIN'; }

$cards = [
  [
    'title' => 'Usuários do Sistema',
    'desc'  => 'Gerenciar logins, senhas e permissões.',
    'url'   => APP_BASE . '/admin/usuarios.php',
    'icon'  => '👤',
    'admin' => true
  ],
  [
    'title' => 'Produtos do Cardápio',
    'desc'  => 'Cadastrar, editar preços e fotos.',
    'url'   => APP_BASE . '/admin/produtos.php',
    'icon'  => '🍔',
    'admin' => true
  ],
];
?>
<!doctype html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title>Administração</title>

<style>
:root{
  --bg:#0f0f10;
  --text:#f3f3f3;
  --muted: rgba(243,243,243,.70);
  --card: rgba(32,32,34,.72);
  --line: rgba(255,255,255,.12);
  --shadow: 0 18px 50px rgba(0,0,0,.55);
  --radius: 18px;
  --accent:#60cdff;
  --ok:#22c55e;
}

*{box-sizing:border-box}
body{
  margin:0;
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial;
  background:var(--bg);
  color:var(--text);
}

/* ===== Topbar igual ao painel ===== */
.topbar{
  position:sticky; top:0; z-index:50;
  padding:10px 0;
  backdrop-filter: blur(14px);
  background: rgba(15,15,16,.92);
  border-bottom:1px solid var(--line);
}
.topbar-inner{
  max-width:1100px; margin:0 auto; padding:0 14px;
  display:flex; align-items:center; gap:12px;
}
.brand-badge{
  width:40px;height:40px;border-radius:14px;
  background: rgba(255,255,255,.06);
  border:1px solid var(--line);
  display:grid;place-items:center;
  font-weight:900;
}
.spacer{flex:1}
.user{
  display:flex; align-items:center; gap:10px;
  padding:10px 12px;
  background: rgba(255,255,255,.04);
  border:1px solid var(--line);
  border-radius:999px;
}
.user .dot{
  width:10px;height:10px;border-radius:999px;background:var(--ok);
}
.btn{
  height:44px; padding:0 14px;
  display:inline-flex; align-items:center; gap:8px;
  border-radius:14px;
  border:1px solid var(--line);
  background: rgba(255,255,255,.05);
  text-decoration:none; color:var(--text);
}
.btn:hover{ background: rgba(255,255,255,.08) }

/* ===== Conteúdo ===== */
.wrap{ max-width:1100px; margin:0 auto; padding:22px 14px 40px; }

h1{
  font-size:20px;
  font-weight:900;
  margin:0 0 6px;
}
.sub{ color:var(--muted); margin-bottom:18px; }

.grid{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap:14px;
}

.card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--radius);
  padding:16px;
  box-shadow:var(--shadow);
  text-decoration:none;
  color:var(--text);
  display:flex;
  gap:14px;
  align-items:flex-start;
  transition:.15s;
}
.card:hover{ transform:translateY(-3px) }

.icon{
  font-size:26px;
  background:rgba(96,205,255,.12);
  border:1px solid rgba(96,205,255,.25);
  width:52px;height:52px;
  display:grid;place-items:center;
  border-radius:14px;
  flex:0 0 auto;
}

.meta .title{ font-weight:900; margin-bottom:6px }
.meta .desc{ font-size:13px; color:var(--muted) }

.footer{
  text-align:center;
  margin-top:30px;
  color:var(--muted);
  font-size:12px;
}
</style>
</head>
<body>

<header class="topbar">
  <div class="topbar-inner">
    <div class="brand-badge">ADM</div>

    <nav>
      <a class="btn" href="<?=h(APP_BASE.'/painel.php')?>">🏠 Painel</a>
    </nav>

    <div class="spacer"></div>

    <div class="user">
      <span class="dot"></span>
      <div>
        <div style="font-weight:800;font-size:13px"><?=h($nome)?></div>
        <div style="font-size:12px;color:var(--muted)"><?=h($role)?></div>
      </div>
    </div>

    <a class="btn" href="<?=h(APP_BASE.'/logout.php')?>">Sair</a>
  </div>
</header>

<main class="wrap">
  <h1>Portal Administrativo</h1>
  <div class="sub">Configurações e cadastros do sistema</div>

  <div class="grid">
    <?php foreach($cards as $c):
      if ($c['admin'] && !is_admin($role)) continue;
    ?>
      <a class="card" href="<?=h($c['url'])?>">
        <div class="icon"><?=$c['icon']?></div>
        <div class="meta">
          <div class="title"><?=h($c['title'])?></div>
          <div class="desc"><?=h($c['desc'])?></div>
        </div>
      </a>
    <?php endforeach; ?>
  </div>

  <div class="footer">© <?=date('Y')?> • Administração</div>
</main>

</body>
</html>
