<?php 
// --- SESSION & SECURITY ---
$sessionPath = dirname(__DIR__) . '/sessions';
if (!file_exists($sessionPath)) { @mkdir($sessionPath, 0755, true); }
ini_set('session.save_path', $sessionPath);
if (session_status() === PHP_SESSION_NONE) { session_start(); }

// রুট ফোল্ডার থেকে কনফিগ ফাইল ইনক্লুড
include '../config.php'; 

if(!isset($_SESSION['admin_logged_in'])) {
    header("Location: login.php"); // যেহেতু header.php এবং login.php এখন একই ফোল্ডারে
    exit;
}

// সাইট সেটিংস ডাটা আনা
$theme = $conn->query("SELECT * FROM site_settings WHERE id=1")->fetch_assoc();
$current_page = basename($_SERVER['PHP_SELF']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Super Admin - <?= htmlspecialchars($theme['site_title']) ?></title>
    
    <!-- External Resources -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
    
    <style>
        :root { --accent: #00f2ff; --bg: #0b0c10; --panel: #1f2833; --text: #fff; }
        body { background: var(--bg); color: var(--text); font-family: sans-serif; margin:0; padding-bottom:50px; }
        
        header { background: #000; border-bottom: 2px solid var(--accent); padding: 15px; display:flex; justify-content:space-between; align-items:center; position: sticky; top:0; z-index: 1000; }
        .logo { font-size: 20px; font-weight: bold; color: #fff; text-decoration: none; text-transform: uppercase; letter-spacing: 1px; }
        
        .container { max-width: 900px; margin: 30px auto; padding: 0 15px; }
        
        /* Navigation Menu */
        .grid-menu { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-bottom: 20px; }
        .menu-btn { background: #111; border: 1px solid #333; padding: 12px; text-align: center; cursor: pointer; color: #aaa; font-weight:bold; font-size: 10px; text-decoration: none; border-radius: 3px; transition: 0.3s; }
        .menu-btn:hover { color: #fff; border-color: var(--accent); }
        .menu-btn.active { border-color: var(--accent); color: #fff; background: rgba(0,242,255,0.1); }
        
        /* Control Boxes */
        .control-box { background: var(--panel); padding: 20px; margin-bottom: 15px; border-radius: 5px; border: 1px solid #333; }
        label { display: block; margin-top: 15px; font-size: 11px; color: var(--accent); font-weight: bold; text-transform: uppercase; }
        
        /* Inputs & Color Pickers */
        input, select, textarea { width: 100%; padding: 12px; background: #000; border: 1px solid #444; color: #fff; margin-top: 8px; box-sizing:border-box; border-radius: 4px; outline: none; }
        input:focus { border-color: var(--accent); }
        input[type="color"] { height: 45px; padding: 3px; cursor: pointer; border: 1px solid #444; }
        
        .btn { width: 100%; padding: 14px; background: var(--accent); color: #000; font-weight: bold; border: none; margin-top: 20px; cursor: pointer; border-radius: 4px; transition: 0.2s; }
        .btn:hover { opacity: 0.9; transform: scale(0.99); }
        
        .list-item { background: #151515; padding: 12px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; border: 1px solid #333; border-radius: 4px; }
        
        /* Modals */
        .modal { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.92); z-index: 9999; text-align: center; overflow-y: auto; }
        .modal:before { content: ''; display: inline-block; height: 100%; vertical-align: middle; }
        .modal-content { background: #1f2833; padding: 25px; border: 1px solid var(--accent); width: 90%; max-width: 400px; display: inline-block; vertical-align: middle; text-align: left; border-radius: 8px; box-shadow: 0 0 30px rgba(0,242,255,0.2); }
        
        /* Responsive Tabs */
        .device-btns { display: flex; gap: 5px; margin-bottom: 15px; }
        .dev-btn { flex: 1; padding: 12px; background: #111; border: 1px solid #444; color: #888; cursor: pointer; text-align: center; font-size: 11px; font-weight: bold; border-radius: 4px; }
        .dev-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }
        .dev-group { display: none; }
        .dev-group.active { display: block; }

        @media (max-width: 600px) {
            .grid-menu { grid-template-columns: repeat(3, 1fr); }
            .menu-btn { font-size: 8px; padding: 10px 5px; }
        }
    </style>
</head>
<body>

<header>
    <a href="categories.php" class="logo">ADMIN PANEL</a>
    <div>
        <a href="../index.php" target="_blank" style="color:#fff; text-decoration:none; margin-right:20px; font-size: 13px;"><i class="fas fa-external-link-alt"></i> View Site</a>
        <a href="../logout.php" style="color:#ff4444; text-decoration:none; font-weight:bold; font-size: 13px;"><i class="fas fa-sign-out-alt"></i> LOGOUT</a>
    </div>
</header>

<div class="container">
    <!-- নেভিগেশন মেনু -->
    <div class="grid-menu">
        <a href="categories.php" class="menu-btn <?= ($current_page == 'categories.php') ? 'active' : '' ?>">CATEGORIES</a>
        <a href="items.php" class="menu-btn <?= ($current_page == 'items.php') ? 'active' : '' ?>">ITEMS</a>
        <a href="effects.php" class="menu-btn <?= ($current_page == 'effects.php') ? 'active' : '' ?>">EFFECTS</a>
        <a href="content.php" class="menu-btn <?= ($current_page == 'content.php') ? 'active' : '' ?>">CONTENT</a>
        <a href="notices.php" class="menu-btn <?= ($current_page == 'notices.php') ? 'active' : '' ?>">NOTICES</a>
        <a href="links.php" class="menu-btn <?= ($current_page == 'links.php') ? 'active' : '' ?>">LINKS</a>
        <a href="officers.php" class="menu-btn <?= ($current_page == 'officers.php') ? 'active' : '' ?>">OFFICERS</a>
        <a href="notifications.php" class="menu-btn menu-btn-notif <?= ($current_page == 'notifications.php') ? 'active' : '' ?>"><i class="fas fa-bell"></i> APP NOTIF</a>
    </div>