<?php
session_start();
if (!isset($_SESSION['eggzie_iboPlayer'])) {
    header('Location: login.php');
    exit();
}

error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);

$IIIIIIIlI1lI = $_SESSION['id'];
$IIIIIIIlI1ll = new SQLite3('./a/.eggziepanels.db');
$adb = new SQLite3('./api/.adb.db');
$IIIIIIIlI1l1 = $IIIIIIIlI1ll->query('SELECT * FROM USERS WHERE id=\'1\'')->fetchArray();

$IIIIIIIlI11l = $IIIIIIIlI1l1['NAME'];

// Fallback de Logo
$IIIIIIIlI111 = $IIIIIIIlI1l1['LOGO'];
if (empty($IIIIIIIlI111) || strpos($IIIIIIIlI111, 'imgur.com/qV3DdMK') !== false) {
    $IIIIIIIlI111 = "https://a.imagem.app/ByrbbW.png";
}

$IIIIIIIllIII = file_get_contents('./includes/eggzie.json');
$IIIIIIIllIIl = json_decode($IIIIIIIllIII, true);
$IIIIIIIllII1 = $IIIIIIIllIIl['info']['aa'];
?>
<!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>FLUX PLAYER - THAILAND</title>
    
    <link href="css/sb-admin-<?php echo $IIIIIIIllII1; ?>.css" rel="stylesheet">
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/>

    <style>
        :root {
            --thai-bg: #06070a;
            --thai-card: #0f111a;
            --thai-neon: #8b5cf6;
            --sidebar-width: 260px;
        }

        body { background-color: var(--thai-bg) !important; color: #cbd5e1 !important; font-family: 'Inter', sans-serif; }

        /* Estrutura Principal */
        #wrapper { display: flex; width: 100%; min-height: 100vh; }

        /* Sidebar Ajustada */
        #accordionSidebar {
            background: var(--thai-card) !important;
            width: var(--sidebar-width) !important;
            min-width: var(--sidebar-width) !important;
            border-right: 1px solid rgba(255,255,255,0.05);
            transition: all 0.3s ease;
            position: relative;
            z-index: 1050;
        }

        /* Desktop: Quando recolhido */
        #accordionSidebar.toggled {
            width: 0 !important;
            min-width: 0 !important;
            overflow: hidden;
            border-right: none;
        }

        /* Conteúdo principal */
        #content-wrapper {
            flex: 1;
            display: flex;
            flex-direction: column;
            width: 100%;
            transition: all 0.3s ease;
        }

        /* Mobile (Max 768px) */
        @media (max-width: 768px) {
            #accordionSidebar {
                position: fixed !important;
                left: calc(var(--sidebar-width) * -1);
                top: 0; bottom: 0;
            }
            #accordionSidebar.toggled {
                left: 0 !important;
                width: var(--sidebar-width) !important;
                min-width: var(--sidebar-width) !important;
            }
            #content-wrapper { margin-left: 0 !important; }
        }

        .nav-link { 
            color: #94a3b8 !important; 
            padding: 12px 20px !important;
            margin: 4px 12px; 
            border-radius: 14px; 
            transition: 0.2s;
            display: flex !important;
            align-items: center;
            font-size: 11px !important;
            font-weight: 700;
            letter-spacing: 1px;
            text-transform: uppercase;
        }
        
        .nav-link i { color: var(--thai-neon) !important; width: 25px; margin-right: 10px; text-align: center; font-size: 1.1rem; }
        
        .nav-link:hover, .nav-item.active .nav-link {
            background: rgba(139, 92, 246, 0.08) !important;
            color: white !important;
            box-shadow: inset 4px 0 0 var(--thai-neon);
        }

        #sidebarOverlay {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.7);
            z-index: 1040;
            backdrop-filter: blur(4px);
        }
        #sidebarOverlay.show { display: block; }

        .topbar {
            background: rgba(6, 7, 10, 0.8) !important;
            backdrop-filter: blur(10px);
            border-bottom: 1px solid rgba(255,255,255,0.05);
            height: 70px;
        }

        .sidebar-heading {
            font-size: 9px;
            color: #475569;
            padding: 10px 25px;
            letter-spacing: 2px;
            font-weight: 800;
        }
    </style>
</head>

<body id="page-top">

<div id="sidebarOverlay" onclick="toggleSidebar()"></div>

<div id="wrapper">
    <ul class="navbar-nav sidebar sidebar-dark accordion" id="accordionSidebar">
        <div class="sidebar-brand d-flex align-items-center justify-content-center py-8">
            <img src="<?php echo $IIIIIIIlI111; ?>" style="max-height: 45px; width: auto;" id="sidebarLogo">
        </div>

        <div class="sidebar-heading">PRINCIPAL</div>
        <li class="nav-item"><a class="nav-link" href="users.php"><i class="fas fa-user-friends"></i> <span>Usuários</span></a></li>
        <li class="nav-item"><a class="nav-link" href="dns_manager.php"><i class="fas fa-server"></i> <span>Gerenciar DNS</span></a></li>
        
        <div class="sidebar-heading">AUTOMAÇÃO</div>
        <li class="nav-item"><a class="nav-link" href="chatbot.php"><i class="fas fa-robot"></i> <span>Chatbot AI</span></a></li>
        <li class="nav-item"><a class="nav-link" href="migrar.php"><i class="fas fa-exchange-alt"></i> <span>Migrar Dados</span></a></li>

        <div class="sidebar-heading">CUSTOMIZAÇÃO</div>
        <li class="nav-item"><a class="nav-link" href="ads.php"><i class="fas fa-ad"></i> <span>Banners</span></a></li>
        <li class="nav-item"><a class="nav-link" href="Image.php"><i class="fas fa-image"></i> <span>Fundo/BG</span></a></li>
        <li class="nav-item"><a class="nav-link" href="logo.php"><i class="fas fa-star"></i> <span>Marca/Logo</span></a></li>
        <li class="nav-item"><a class="nav-link" href="pageqrcode.php"><i class="fas fa-qrcode"></i> <span>QR Code</span></a></li>
        
        <div class="sidebar-heading">SISTEMA</div>
        <li class="nav-item">
            <a class="nav-link" href="admin_crypto.php" style="background: rgba(16, 185, 129, 0.05); color: #10b981 !important;">
                <i class="fas fa-shield-alt" style="color: #10b981 !important;"></i> 
                <span>Crypto Vault</span>
            </a>
        </li>
        <li class="nav-item"><a class="nav-link" href="profile.php"><i class="fas fa-user-shield"></i> <span>Configurações</span></a></li>
    </ul>

    <div id="content-wrapper">
        <div id="content">
            <nav class="navbar navbar-expand topbar mb-4 flex items-center justify-between px-6">
                <button id="sidebarToggleTop" class="text-violet-500 text-xl" onclick="toggleSidebar()">
                    <i class="fa fa-bars"></i>
                </button>
                
                <div class="hidden md:block">
                    <h6 class="m-0 font-black text-white text-[9px] tracking-[5px] uppercase italic opacity-40">Flux Player Management</h6>
                </div>

                <div class="flex items-center gap-4">
                    <div class="text-right hidden sm:block mr-2">
                        <p class="text-[10px] font-bold text-gray-500 m-0 leading-none">ADMINISTRADOR</p>
                        <p class="text-[11px] font-black text-white m-0 uppercase"><?php echo $IIIIIIIlI11l; ?></p>
                    </div>
                    <a href="logout.php" class="text-[9px] font-black border border-red-500/30 bg-red-500/10 text-red-500 px-6 py-2 rounded-full hover:bg-red-500 hover:text-white transition-all tracking-[2px]">SAIR</a>
                </div>
            </nav>

            <div class="container-fluid px-4 md:px-8">

    <script>
        function toggleSidebar() {
            const sidebar = document.getElementById('accordionSidebar');
            const overlay = document.getElementById('sidebarOverlay');
            const isMobile = window.innerWidth < 768;

            sidebar.classList.toggle('toggled');

            if (isMobile) {
                if (sidebar.classList.contains('toggled')) {
                    overlay.classList.add('show');
                    document.body.style.overflow = 'hidden'; // Trava o scroll no mobile com menu aberto
                } else {
                    overlay.classList.remove('show');
                    document.body.style.overflow = 'auto';
                }
            }
        }

        // Garante o fechamento do overlay ao redimensionar
        window.addEventListener('resize', function() {
            if (window.innerWidth >= 768) {
                document.getElementById('sidebarOverlay').classList.remove('show');
                document.body.style.overflow = 'auto';
            }
        });
    </script>