<?php
/**
 * UPGRADE PREMIUM BY MANUS AI
 * HEADER & SIDEBAR DESIGN: MODERN GLASSMORPHISM
 */
session_start();
if (!isset($_SESSION['eggzie_iboPlayer'])) {
    header('Location: login.php');
    exit();
}

error_reporting(0); // Ocultar avisos em produção

$admin_id = $_SESSION['id'] ?? '1';
$db_panels = new SQLite3('./a/.eggziepanels.db');
$user_data = $db_panels->query("SELECT * FROM USERS WHERE id='$admin_id'")->fetchArray();
$admin_name = $user_data['NAME'] ?? 'Administrador';
$admin_logo = $user_data['LOGO'] ?? 'img/logo.png';

$info_json = json_decode(file_get_contents('./includes/eggzie.json'), true);
$theme_version = $info_json['info']['aa'] ?? '2';

$current_page = basename($_SERVER['PHP_SELF']);
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>IBO NOTIFICATION - PREMIUM ADM</title>
    
    <!-- Fonts & Icons -->
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons+Round" rel="stylesheet">
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet">
    
    <style>
        :root {
            --primary: #6366f1;
            --primary-dark: #4f46e5;
            --secondary: #10b981;
            --bg-dark: #0f172a;
            --sidebar-bg: #1e293b;
            --card-bg: rgba(30, 41, 59, 0.7);
            --text-main: #f1f5f9;
            --text-muted: #94a3b8;
            --border: rgba(255, 255, 255, 0.1);
            --sidebar-width: 260px;
            --sidebar-collapsed-width: 80px;
            --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Inter', sans-serif;
        }

        body {
            background-color: var(--bg-dark);
            color: var(--text-main);
            min-height: 100vh;
            display: flex;
        }

        /* SIDEBAR */
        #sidebar {
            width: var(--sidebar-width);
            background: var(--sidebar-bg);
            height: 100vh;
            position: fixed;
            left: 0;
            top: 0;
            z-index: 1000;
            transition: var(--transition);
            border-right: 1px solid var(--border);
            display: flex;
            flex-direction: column;
        }

        #sidebar.collapsed {
            width: var(--sidebar-collapsed-width);
        }

        .sidebar-header {
            padding: 20px;
            display: flex;
            align-items: center;
            gap: 15px;
            border-bottom: 1px solid var(--border);
            min-height: 80px;
        }

        .sidebar-logo {
            width: 40px;
            height: 40px;
            border-radius: 10px;
            object-fit: cover;
        }

        .sidebar-brand-text {
            font-weight: 800;
            font-size: 18px;
            white-space: nowrap;
            opacity: 1;
            transition: var(--transition);
        }

        #sidebar.collapsed .sidebar-brand-text {
            opacity: 0;
            pointer-events: none;
        }

        .sidebar-menu {
            flex: 1;
            overflow-y: auto;
            padding: 20px 10px;
            list-style: none;
        }

        .menu-label {
            font-size: 11px;
            text-transform: uppercase;
            letter-spacing: 1px;
            color: var(--text-muted);
            margin: 20px 0 10px 15px;
            font-weight: 700;
        }

        #sidebar.collapsed .menu-label {
            display: none;
        }

        .menu-item {
            margin-bottom: 5px;
        }

        .menu-link {
            display: flex;
            align-items: center;
            gap: 15px;
            padding: 12px 15px;
            color: var(--text-muted);
            text-decoration: none;
            border-radius: 12px;
            transition: var(--transition);
        }

        .menu-link i, .menu-link .material-icons-round {
            font-size: 22px;
            min-width: 24px;
            text-align: center;
        }

        .menu-link span {
            font-size: 14px;
            font-weight: 500;
            white-space: nowrap;
        }

        .menu-link:hover {
            background: rgba(255, 255, 255, 0.05);
            color: white;
        }

        .menu-link.active {
            background: var(--primary);
            color: white;
            box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
        }

        /* MAIN CONTENT */
        #main-content {
            flex: 1;
            margin-left: var(--sidebar-width);
            transition: var(--transition);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        #main-content.expanded {
            margin-left: var(--sidebar-collapsed-width);
        }

        /* TOPBAR */
        .topbar {
            height: 80px;
            background: rgba(15, 23, 42, 0.8);
            backdrop-filter: blur(10px);
            border-bottom: 1px solid var(--border);
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 30px;
            position: sticky;
            top: 0;
            z-index: 999;
        }

        .topbar-left {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        #toggle-sidebar {
            background: none;
            border: none;
            color: var(--text-main);
            font-size: 20px;
            cursor: pointer;
            padding: 5px;
            border-radius: 8px;
            transition: 0.2s;
        }

        #toggle-sidebar:hover {
            background: rgba(255, 255, 255, 0.1);
        }

        .page-title {
            font-weight: 700;
            font-size: 20px;
        }

        .topbar-right {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .user-profile {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 8px 15px;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 50px;
            cursor: pointer;
            transition: 0.2s;
        }

        .user-profile:hover {
            background: rgba(255, 255, 255, 0.1);
        }

        .user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            object-fit: cover;
        }

        .user-name {
            font-size: 14px;
            font-weight: 600;
        }

        .content-body {
            padding: 30px;
            flex: 1;
        }

        /* MOBILE OVERLAY */
        .sidebar-overlay {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.5);
            backdrop-filter: blur(4px);
            z-index: 999;
        }

        @media (max-width: 992px) {
            #sidebar {
                left: calc(-1 * var(--sidebar-width));
            }
            #sidebar.mobile-open {
                left: 0;
            }
            #main-content {
                margin-left: 0 !important;
            }
            .sidebar-overlay.active {
                display: block;
            }
        }
    </style>
</head>
<body>
    <div class="sidebar-overlay" id="sidebar-overlay"></div>

    <!-- Sidebar -->
    <aside id="sidebar">
        <div class="sidebar-header">
            <img src="<?php echo $admin_logo; ?>" class="sidebar-logo" alt="Logo">
            <span class="sidebar-brand-text">IBO PREMIUM</span>
        </div>

        <ul class="sidebar-menu">
            <div class="menu-label">Principal</div>
            <li class="menu-item">
                <a href="dashboard.php" class="menu-link <?php echo $current_page == 'dashboard.php' ? 'active' : ''; ?>">
                    <span class="material-icons-round">dashboard</span>
                    <span>Dashboard</span>
                </a>
            </li>
            <li class="menu-item">
                <a href="users.php" class="menu-link <?php echo $current_page == 'users.php' ? 'active' : ''; ?>">
                    <span class="material-icons-round">people</span>
                    <span>Clientes</span>
                </a>
            </li>

            <div class="menu-label">Financeiro</div>
            <li class="menu-item">
                <a href="create_link.php" class="menu-link <?php echo $current_page == 'create_link.php' ? 'active' : ''; ?>">
                    <span class="material-icons-round">payments</span>
                    <span>Links de Pagamento</span>
                </a>
            </li>

            <div class="menu-label">Marketing & Avisos</div>
            <li class="menu-item">
                <a href="note.php" class="menu-link <?php echo $current_page == 'note.php' ? 'active' : ''; ?>">
                    <span class="material-icons-round">campaign</span>
                    <span>Notificações</span>
                </a>
            </li>
            <li class="menu-item">
                <a href="ads.php" class="menu-link <?php echo $current_page == 'ads.php' ? 'active' : ''; ?>">
                    <span class="material-icons-round">auto_awesome_motion</span>
                    <span>Gestão de Banners</span>
                </a>
            </li>

            <div class="menu-label">Configurações</div>
            <li class="menu-item">
                <a href="layouts.php" class="menu-link <?php echo $current_page == 'layouts.php' ? 'active' : ''; ?>">
                    <span class="material-icons-round">palette</span>
                    <span>Temas e Layouts</span>
                </a>
            </li>
            <li class="menu-item">
                <a href="profile.php" class="menu-link <?php echo $current_page == 'profile.php' ? 'active' : ''; ?>">
                    <span class="material-icons-round">manage_accounts</span>
                    <span>Meu Perfil</span>
                </a>
            </li>
            
            <li class="menu-item" style="margin-top: 20px;">
                <a href="logout.php" class="menu-link" style="color: #ef4444;">
                    <span class="material-icons-round">logout</span>
                    <span>Sair do Sistema</span>
                </a>
            </li>
        </ul>
    </aside>

    <!-- Main Content Wrapper -->
    <div id="main-content">
        <!-- Topbar -->
        <header class="topbar">
            <div class="topbar-left">
                <button id="toggle-sidebar">
                    <i class="fas fa-bars"></i>
                </button>
                <h1 class="page-title">
                    <?php 
                        $titles = [
                            'dashboard.php' => 'Dashboard Geral',
                            'users.php' => 'Gerenciar Clientes',
                            'create_link.php' => 'Financeiro',
                            'note.php' => 'Central de Notificações',
	                            'ads.php' => 'Gestão de Banners',
                            'layouts.php' => 'Personalização Visual',
                            'profile.php' => 'Configurações de Perfil'
                        ];
                        echo $titles[$current_page] ?? 'Painel Administrativo';
                    ?>
                </h1>
            </div>

            <div class="topbar-right">
                <div class="user-profile" onclick="location.href='profile.php'">
                    <img src="<?php echo $admin_logo; ?>" class="user-avatar" alt="Avatar">
                    <span class="user-name"><?php echo $admin_name; ?></span>
                </div>
            </div>
        </header>

        <main class="content-body">
