<?php
session_start();
require '../config.php';
if(!isset($_SESSION['admin_id'])) { header("Location: login.php"); exit; }

$page = $_GET['p'] ?? 'dashboard';
$allowed = ['dashboard','packages','categories','orders','settings','players','logs'];
$page = in_array($page, $allowed) ? $page : 'dashboard';
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Admin • Reckon Store</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://fonts.bunny.net/css?family=Space+Grotesk:wght@500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
    <style>
        :root{--green:#00ff88;--purple:#e879f9;--bg:#0a0a1a;--card:#161625;--sidebar:#111;}
        *{margin:0;padding:0;box-sizing:border-box;}
        body{background:var(--bg);color:#fff;font-family:'Space Grotesk',sans-serif;display:flex;min-height:100vh;}
        
        /* SIDEBAR */
        .sidebar{width:280px;background:var(--sidebar);border-right:3px solid var(--green);position:fixed;height:100%;overflow-y:auto;z-index:1000;}
        .sidebar-header{background:#000;padding:1.5rem;text-align:center;border-bottom:3px solid var(--green);}
        .sidebar-header h2{color:var(--green);font-size:1.8rem;}
        .sidebar-menu{margin-top:2rem;}
        .sidebar-item a{display:flex;align-items:center;padding:1rem 1.5rem;color:#ccc;text-decoration:none;transition:0.3s;}
        .sidebar-item a:hover,.sidebar-item.active a{background:var(--green);color:#000;font-weight:bold;}
        .sidebar-item i{margin-right:12px;font-size:1.3rem;}
        
        /* MAIN CONTENT */
        .main{margin-left:280px;padding:2rem;width:100%;}
        .topbar{background:#000;padding:1rem 2rem;position:fixed;top:0;left:280px;right:0;z-index:999;border-bottom:3px solid var(--green);display:flex;justify-content:space-between;align-items:center;}
        .content{padding-top:80px;}
        .card{background:var(--card);border-radius:15px;padding:2rem;margin:1rem 0;box-shadow:0 10px 40px rgba(0,255,0,0.1);}
        h1{color:var(--green);margin-bottom:1.5rem;}
    </style>
</head>
<body>

<!-- SIDEBAR -->
<div class="sidebar">
    <div class="sidebar-header">
        <h2>RECKON ADMIN</h2>
    </div>
    <div class="sidebar-menu">
        <div class="sidebar-item <?= $page=='dashboard'?'active':'' ?>"><a href="?p=dashboard"><i class="fas fa-tachometer-alt"></i> Dashboard</a></div>
        <div class="sidebar-item <?= $page=='packages'?'active':'' ?>"><a href="?p=packages"><i class="fas fa-cube"></i> Packages</a></div>
        <div class="sidebar-item <?= $page=='categories'?'active':'' ?>"><a href="?p=categories"><i class="fas fa-tags"></i> Categories</a></div>
        <div class="sidebar-item <?= $page=='orders'?'active':'' ?>"><a href="?p=orders"><i class="fas fa-shopping-cart"></i> Orders</a></div>
        <div class="sidebar-item <?= $page=='players'?'active':'' ?>"><a href="?p=players"><i class="fas fa-users"></i> Players</a></div>
        <div class="sidebar-item <?= $page=='settings'?'active':'' ?>"><a href="?p=settings"><i class="fas fa-cog"></i> Settings</a></div>
        <div class="sidebar-item"><a href="logout.php"><i class="fas fa-sign-out-alt"></i> Logout</a></div>
    </div>
</div>

<!-- MAIN -->
<div class="main">
    <div class="topbar">
        <div>Welcome back, <strong><?=htmlspecialchars($_SESSION['admin_name'])?></strong></div>
        <div><i class="fas fa-user-shield"></i> Admin Panel</div>
    </div>

    <div class="content">
        <?php include "pages/$page.php"; ?>
    </div>
</div>
</body>
</html>