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

$db = new SQLite3('../a/.eggziedb.db');
$seller_name = $_SESSION['reseller_name'];
$result = $db->query("SELECT COUNT(*) as count FROM sub_revenda WHERE usuario = '$seller_name'");
$row = $result->fetchArray(SQLITE3_ASSOC);
$count = $row['count'];

if($count == 0) {
    header('Location: login.php');
    exit();
}

$seller_id = $_SESSION['id'];
$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'];
$IIIIIIIlI111 = $IIIIIIIlI1l1['LOGO'];

$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 http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="google" content="notranslate">
    <title>LDS Play APKs - Cyberpunk</title>
    <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon">

    <link href="../vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Orbitron:400,700|Poppins:300,400,600&display=swap" rel="stylesheet">
    <link href="../css/sb-admin-<?php echo $IIIIIIIllII1; ?>.css" rel="stylesheet">

    <style>
        :root{
            --bg0:#06040e;
            --bg1:#0a0620;

            --neon-cyan:#00f2ff;
            --neon-purple:#bc13fe;
            --neon-pink:#ff2bd6;
            --neon-lime:#b7ff00;
            --danger:#ff4b2b;

            --glass: rgba(255,255,255,.06);
            --glass2: rgba(255,255,255,.10);
            --stroke: rgba(255,255,255,.14);

            --text: rgba(255,255,255,.92);
            --muted: rgba(255,255,255,.68);

            --r-lg: 18px;
            --r-md: 14px;

            --shadow: 0 18px 60px rgba(0,0,0,.55);

            --pill-h: 44px;
        }

        /* ===== Fundo cyberpunk ===== */
        body{
            font-family:'Poppins',sans-serif;
            color: var(--text);
            background:
                radial-gradient(1100px 800px at 12% 8%, rgba(0,242,255,.14), transparent 55%),
                radial-gradient(900px 700px at 80% 25%, rgba(188,19,254,.14), transparent 58%),
                radial-gradient(1000px 900px at 30% 95%, rgba(255,43,214,.10), transparent 55%),
                linear-gradient(180deg, var(--bg1), var(--bg0));
            position: relative;
        }

        /* Scanlines */
        body::before{
            content:"";
            position: fixed;
            inset: 0;
            pointer-events:none;
            background:
              repeating-linear-gradient(
                180deg,
                rgba(255,255,255,.04) 0px,
                rgba(255,255,255,.04) 1px,
                rgba(0,0,0,0) 3px,
                rgba(0,0,0,0) 6px
              );
            opacity: .18;
            mix-blend-mode: overlay;
            z-index: 0;
        }

        /* Leve glow */
        body::after{
            content:"";
            position: fixed;
            inset: 0;
            pointer-events:none;
            background:
              radial-gradient(circle at 20% 10%, rgba(255,255,255,.06), transparent 40%),
              radial-gradient(circle at 80% 30%, rgba(255,255,255,.04), transparent 45%);
            opacity: .20;
            z-index: 0;
        }

        /* Conteúdo acima */
        #wrapper, #content-wrapper, #content, .topbar, .sidebar { position: relative; z-index: 1; }

        /* Scrollbar */
        ::-webkit-scrollbar{ width: 10px; height: 10px; }
        ::-webkit-scrollbar-thumb{
            background: linear-gradient(180deg, rgba(0,242,255,.45), rgba(255,43,214,.30));
            border-radius: 999px;
            border: 2px solid rgba(0,0,0,.4);
        }
        ::-webkit-scrollbar-track{ background: rgba(0,0,0,.25); }

        /* ===== Sidebar ===== */
        .sidebar{
            background: linear-gradient(180deg, rgba(10,6,32,.85), rgba(4,2,10,.92)) !important;
            border-right: 1px solid rgba(255,255,255,.10);
            box-shadow: 16px 0 60px rgba(0,0,0,.65);
            overflow:hidden;
        }

        .sidebar::before{
            content:"";
            position:absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 4px;
            background: linear-gradient(180deg, var(--neon-cyan), var(--neon-purple), var(--neon-pink));
            box-shadow: 0 0 25px rgba(0,242,255,.55), 0 0 45px rgba(188,19,254,.35);
            opacity: .95;
            pointer-events:none;
        }

        .sidebar::after{
            content:"";
            position:absolute;
            inset:-30%;
            background:
              radial-gradient(circle at 20% 18%, rgba(0,242,255,.20), transparent 35%),
              radial-gradient(circle at 80% 45%, rgba(188,19,254,.18), transparent 40%),
              radial-gradient(circle at 35% 85%, rgba(255,43,214,.12), transparent 45%);
            filter: blur(18px);
            opacity: .9;
            pointer-events:none;
        }

        /* Espaço pro logo + evitar invadir o card */
        .sidebar-brand{
            padding: 2.6rem 1rem .6rem !important;
            margin-bottom: 14px !important;
            text-decoration: none !important;
        }

        .img-profile-nav{
            border-radius: 50%;
            border: 2px solid rgba(0,242,255,.95);
            padding: 4px;
            background: rgba(0,0,0,.55);
            box-shadow:
                0 0 0 8px rgba(0,242,255,.08),
                0 0 26px rgba(0,242,255,.38),
                0 0 60px rgba(255,43,214,.10);
            transition: transform .55s ease, box-shadow .55s ease, filter .55s ease;
            will-change: transform;
        }
        .img-profile-nav:hover{
            transform: rotate(12deg) scale(1.08);
            filter: saturate(1.25) contrast(1.05);
            box-shadow:
                0 0 0 10px rgba(0,242,255,.10),
                0 0 42px rgba(0,242,255,.55),
                0 0 90px rgba(188,19,254,.20);
        }

        /* Card usuário mais pra baixo */
        .user-info-box{
            margin: 14px 14px 18px;
            background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.04));
            border: 1px solid rgba(255,255,255,.14);
            border-radius: var(--r-lg);
            padding: 14px 14px 12px;
            text-align:center;
            backdrop-filter: blur(16px);
            -webkit-backdrop-filter: blur(16px);
            box-shadow: var(--shadow);
            position:relative;
            overflow:hidden;
        }

        .user-info-box::before{
            content:"";
            position:absolute;
            inset:-60% -40%;
            background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,.08) 40%, transparent 52%);
            transform: rotate(12deg);
            animation: holoSweep 5.5s linear infinite;
            opacity: .75;
        }
        @keyframes holoSweep{
            0% { transform: translateX(-20%) rotate(12deg); }
            100% { transform: translateX(40%) rotate(12deg); }
        }

        .user-info-box small{
            display:inline-block;
            color: rgba(255,255,255,.70);
            letter-spacing:.18em;
            font-size: 10px;
            text-transform: uppercase;
            margin-bottom: 6px;
            position:relative;
            z-index:1;
        }

        .user-name-glitch{
            font-family:'Orbitron',sans-serif;
            color: var(--neon-cyan);
            letter-spacing: 1px;
            text-shadow:
                0 0 12px rgba(0,242,255,.40),
                0 0 30px rgba(188,19,254,.12);
            position:relative;
            z-index:1;
        }
        .user-name-glitch::before,
        .user-name-glitch::after{
            content: attr(data-text);
            position:absolute;
            left:0; top:0;
            width:100%;
            opacity:.55;
            pointer-events:none;
            mix-blend-mode: screen;
        }
        .user-name-glitch::before{
            transform: translate(1px, 0);
            color: var(--neon-pink);
            clip-path: inset(0 0 52% 0);
            animation: glitch1 3.2s infinite linear;
        }
        .user-name-glitch::after{
            transform: translate(-1px, 0);
            color: var(--neon-purple);
            clip-path: inset(48% 0 0 0);
            animation: glitch2 2.6s infinite linear;
        }
        @keyframes glitch1{
            0%, 100% { transform: translate(1px, 0); }
            40% { transform: translate(2px, -1px); }
            70% { transform: translate(1px, 1px); }
        }
        @keyframes glitch2{
            0%, 100% { transform: translate(-1px, 0); }
            35% { transform: translate(-2px, 1px); }
            80% { transform: translate(-1px, -1px); }
        }

        .id-badge{
            display:inline-flex;
            align-items:center;
            gap:8px;
            padding: 7px 12px;
            border-radius: 999px;
            font-size: 11px;
            color: rgba(255,255,255,.92);
            background: rgba(0,0,0,.48);
            border: 1px solid rgba(255,255,255,.16);
            box-shadow:
                inset 0 0 0 1px rgba(0,242,255,.10),
                0 0 18px rgba(0,242,255,.10);
            position:relative;
            z-index:1;
        }
        .id-badge::before{
            content:"";
            width:8px; height:8px;
            border-radius:50%;
            background: var(--neon-lime);
            box-shadow: 0 0 16px rgba(183,255,0,.75);
        }

        .sidebar-divider{
            border-top: 1px solid rgba(255,255,255,.10) !important;
            margin: 1rem 1rem;
        }

        /* ===== Menu ===== */
        .nav-item .nav-link{
            margin: 7px 12px;
            border-radius: var(--r-md);
            padding: 12px 14px;
            color: rgba(255,255,255,.76) !important;
            position:relative;
            overflow:hidden;
            transition: transform .22s ease, box-shadow .22s ease, background .22s ease;
            border: 1px solid rgba(255,255,255,.08);
            background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.02));
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
        }

        .nav-item .nav-link::before{
            content:"";
            position:absolute;
            inset:-60% -20%;
            background: linear-gradient(120deg, transparent 35%, rgba(255,255,255,.08) 45%, transparent 58%);
            transform: rotate(12deg);
            opacity: 0;
            transition: opacity .22s ease;
        }

        .nav-item .nav-link::after{
            content:"";
            position:absolute;
            left:0; top:10px; bottom:10px;
            width:3px;
            border-radius: 999px;
            background: transparent;
            transition: background .22s ease, box-shadow .22s ease;
        }

        .nav-item .nav-link i{
            color: rgba(0,242,255,.95);
            text-shadow: 0 0 12px rgba(0,242,255,.35);
            margin-right: 10px;
        }

        .nav-item .nav-link:hover,
        .nav-item.active .nav-link{
            transform: translateX(5px);
            background: linear-gradient(90deg, rgba(0,242,255,.16), rgba(255,43,214,.08), rgba(188,19,254,.06)) !important;
            color: #fff !important;
            box-shadow:
                0 16px 34px rgba(0,0,0,.35),
                inset 0 0 0 1px rgba(0,242,255,.16),
                0 0 22px rgba(0,242,255,.12);
            border-color: rgba(0,242,255,.14);
        }
        .nav-item .nav-link:hover::before{ opacity: 1; }
        .nav-item .nav-link:hover::after,
        .nav-item.active .nav-link::after{
            background: linear-gradient(180deg, var(--neon-cyan), var(--neon-pink));
            box-shadow: 0 0 18px rgba(0,242,255,.65);
        }

        /* Collapse interno */
        .collapse-inner{
            background: rgba(0,0,0,.30) !important;
            border: 1px solid rgba(255,255,255,.10) !important;
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
        }
        .collapse-item{
            border-radius: 12px;
            margin: 7px 10px;
            padding: 10px 12px !important;
            color: rgba(255,255,255,.90) !important;
            transition: background .2s ease, transform .2s ease;
        }
        .collapse-item:hover{
            background: rgba(0,242,255,.12) !important;
            transform: translateX(4px);
        }

        /* ===== Topbar ===== */
        .topbar{
            background: linear-gradient(180deg, rgba(10,10,22,.72), rgba(6,4,14,.62)) !important;
            backdrop-filter: blur(18px);
            -webkit-backdrop-filter: blur(18px);
            border-bottom: 1px solid rgba(255,255,255,.10);
            height: 5rem !important;
            box-shadow: 0 18px 55px rgba(0,0,0,.50);
            position:relative;
            overflow:hidden;
        }
        .topbar::before{
            content:"";
            position:absolute;
            inset:-40% -20%;
            background: radial-gradient(circle at 30% 30%, rgba(0,242,255,.12), transparent 40%),
                        radial-gradient(circle at 80% 40%, rgba(188,19,254,.10), transparent 45%);
            filter: blur(18px);
            opacity: .9;
            pointer-events:none;
        }

        /* ===== MACs e LOGOUT: harmonização definitiva ===== */
        .topbar .badge-macs,
        .topbar .btn-logout-top{
            height: var(--pill-h) !important;
            min-height: var(--pill-h) !important;
            max-height: var(--pill-h) !important;
            box-sizing: border-box !important;

            display: inline-flex !important;
            align-items: center !important;
            justify-content: center !important;

            padding: 0 18px !important;
            border-radius: 999px !important;
            line-height: 1 !important;
            vertical-align: middle !important;
        }

        /* Mata herança do nav-link que “aumenta” o logout */
        .topbar a.nav-link.btn-logout-top{
            padding-top: 0 !important;
            padding-bottom: 0 !important;
        }

        .topbar .badge-macs i,
        .topbar .btn-logout-top i{
            line-height: 1 !important;
            margin: 0 !important;
        }

        .badge-macs{
            background: linear-gradient(90deg, rgba(188,19,254,.16), rgba(0,242,255,.12), rgba(255,43,214,.10)) !important;
            border: 1px solid rgba(255,255,255,.16) !important;
            color: rgba(255,255,255,.95) !important;
            font-family: 'Orbitron', sans-serif;
            font-weight: 800;
            text-transform: uppercase;
            letter-spacing: .10em;
            box-shadow: 0 0 18px rgba(188,19,254,.22), 0 0 12px rgba(0,242,255,.12) !important;
            white-space: nowrap;
        }

        .btn-logout-top{
            background: linear-gradient(90deg, rgba(255,75,43,.18), rgba(255,43,214,.08)) !important;
            border: 1px solid rgba(255,75,43,.55) !important;
            color: rgba(255,255,255,.94) !important;
            font-family: 'Orbitron', sans-serif;
            font-weight: 900;
            text-transform: uppercase;
            font-size: 12px;
            letter-spacing: .10em;
            transition: transform .2s ease, box-shadow .2s ease, filter .2s ease;
            box-shadow: 0 0 18px rgba(255,75,43,.22), 0 0 12px rgba(255,43,214,.12) !important;
        }
        .btn-logout-top:hover{
            transform: translateY(-1px);
            filter: saturate(1.15);
            box-shadow: 0 0 30px rgba(255,75,43,.35), 0 0 22px rgba(255,43,214,.18) !important;
        }

        #content-wrapper{
            background: linear-gradient(
                180deg,
                rgba(10, 20, 45, 0.95) 0%,
                rgba(8, 12, 30, 0.98) 70%,
                rgba(6, 8, 20, 1) 100%
            ) !important;
        }
        #sidebarToggle{ box-shadow: 0 0 30px rgba(0,242,255,.35); }

        a:focus, button:focus{
            outline: none !important;
            box-shadow: 0 0 0 3px rgba(0,242,255,.18) !important;
        }

        /* ">" depois do texto em Publicidades */
        #accordionSidebar .nav-link[data-toggle="collapse"]::after,
        #accordionSidebar .nav-link.collapsed::after,
        #accordionSidebar .nav-link[data-toggle="collapse"]::before,
        #accordionSidebar .nav-link.collapsed::before{
            content: none !important;
        }
        #accordionSidebar .nav-link[data-toggle="collapse"]{
            display: flex;
            align-items: center;
            gap: 10px;
        }
        #accordionSidebar .nav-link[data-toggle="collapse"] span{
            flex: 1;
        }
        #accordionSidebar .nav-link[data-toggle="collapse"] span::after{
            content: " >";
            opacity: .9;
            color: rgba(255,255,255,.75);
            font-weight: 700;
            letter-spacing: .08em;
        }

        /* =========================================================
           FIX: OVERLAY INVISÍVEL BLOQUEANDO CLIQUES + TEMA POPUPS
           (Bootstrap Alert/Modal + Toastr + IziToast + SweetAlert2)
        ========================================================= */

        /* garante que overlays decorativos não roubem clique */
        body::before, body::after,
        .sidebar::before, .sidebar::after,
        .topbar::before{
            pointer-events: none !important;
        }

        /* neutraliza overlays comuns (se existirem) que travam a tela */
        .modal-backdrop,
        .backdrop,
        .overlay,
        .loading,
        .preloader,
        .blockUI,
        .blockOverlay,
        .ui-widget-overlay,
        #overlay,
        #preloader,
        #loading,
        #blockui{
            pointer-events: none !important;
        }

        /* mas os avisos reais precisam ser clicáveis */
        .modal, .modal * ,
        .toast, .toast *,
        #toast-container, #toast-container *,
        .iziToast, .iziToast *,
        .alert, .alert *,
        .swal2-container, .swal2-popup, .swal2-popup *{
            pointer-events: auto !important;
        }

        /* z-index dos avisos no topo */
        .modal, .toast, #toast-container, .iziToast, .alert, .swal2-container{
            z-index: 999999 !important;
        }

        /* Tema cyberpunk para popups */
        .alert,
        .modal-content,
        #toast-container .toast,
        .iziToast,
        .swal2-popup{
            background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.04)) !important;
            border: 1px solid rgba(0,242,255,.22) !important;
            border-radius: 18px !important;
            color: rgba(255,255,255,.92) !important;
            backdrop-filter: blur(18px) !important;
            -webkit-backdrop-filter: blur(18px) !important;
            box-shadow: 0 18px 70px rgba(0,0,0,.65) !important;
        }

        .alert .close,
        .alert button.close,
        .modal .close,
        #toast-container .toast .toast-close-button,
        .iziToast-close{
            color: var(--neon-cyan) !important;
            opacity: 1 !important;
            text-shadow: 0 0 12px rgba(0,242,255,.55) !important;
        }

        /* Ajuste mobile */
        @media (max-width: 768px){
            :root{ --pill-h: 40px; }
            .nav-item .nav-link{ margin: 7px 10px; }
            .user-info-box{ margin: 14px 10px 16px; }
            .topbar .badge-macs, .topbar .btn-logout-top{ padding: 0 12px !important; font-size: 11px; }
        }
    </style>
</head>

<body id="page-top">
    <div id="wrapper">
        <ul class="navbar-nav sidebar sidebar-dark accordion" id="accordionSidebar">

            <a class="sidebar-brand d-flex flex-column align-items-center justify-content-center" href="index.php">
                <div class="sidebar-brand-icon">
                    <?php 
                        $usuario_pasta = $seller_name; 
                        $diretorio_fisico = "../rtx/logo/" . $usuario_pasta . "/logo/";
                        $arquivos = glob($diretorio_fisico . "{*.jpg,*.jpeg,*.png,*.gif,*.webp}", GLOB_BRACE);

                        if ($arquivos && count($arquivos) > 0) {
                            $nome_arquivo = basename($arquivos[0]);
                            $url_final = "/iborevenda/rtx/logo/" . $usuario_pasta . "/logo/" . $nome_arquivo;
                        } else {
                            $url_final = "/iborevenda/img/logo.png";
                        }
                    ?>
                    <img class="img-profile-nav" width="75px" src="<?php echo $url_final; ?>" onerror="this.src='/iborevenda/img/logo.png';">
                </div>
            </a>

            <div class="user-info-box">
                <?php
                $result_ref = $db->query("SELECT id_ref FROM sub_revenda WHERE usuario = '$seller_name'");
                $row_ref = $result_ref->fetchArray();
                $id_ref = $row_ref['id_ref'] ?? '0';
                ?>
                <small>Bem Vindo</small>
                <strong class="d-block user-name-glitch" data-text="<?php echo strtoupper($seller_name); ?>">
                    <?php echo strtoupper($seller_name); ?>
                </strong>
                <span class="id-badge">REF ID: <?php echo $id_ref; ?></span>
            </div>

            <hr class="sidebar-divider">

            <li class="nav-item">
                <a class="nav-link" href="index.php">
                    <i class="fas fa-users"></i>
                    <span>Usuários</span>
                </a>
            </li>

            <li class="nav-item">
                <a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseAds">
                    <i class="fas fa-broadcast-tower"></i>
                    <span>Publicidades</span>
                </a>
                <div id="collapseAds" class="collapse" data-parent="#accordionSidebar">
                    <div class="bg-dark py-2 collapse-inner rounded border border-secondary">
                        <a class="collapse-item text-white" href="ads.php">Enviar Banner</a>
                    </div>
                </div>
            </li>

            <li class="nav-item">
                <a class="nav-link" href="Image.php">
                    <i class="fas fa-project-diagram"></i>
                    <span>Plano de Fundo</span>
                </a>
            </li>

            <li class="nav-item">
                <a class="nav-link" href="logo.php">
                    <i class="fas fa-eye"></i>
                    <span>Alterar Logotipo</span>
                </a>
            </li>

            <li class="nav-item">
                <a class="nav-link" href="layouts.php">
                    <i class="fas fa-microchip"></i>
                    <span>Temas</span>
                </a>
            </li>

            <div class="text-center d-none d-md-inline mt-4">
                <button class="rounded-circle border-0" id="sidebarToggle" style="background: var(--neon-cyan);"></button>
            </div>
        </ul>

        <div id="content-wrapper" class="d-flex flex-column">
            <div id="content">
                <nav class="navbar navbar-expand navbar-light topbar mb-4 static-top">
                    <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3" style="color: var(--neon-cyan);">
                        <i class="fa fa-bars"></i>
                    </button>

                    <ul class="navbar-nav ml-auto align-items-center">
                        <li class="nav-item px-2">
                            <?php
                                $db1 = new SQLite3('../a/.eggziedb.db');
                                $result_mac = $db1->query("SELECT macs FROM sub_revenda WHERE usuario = '$seller_name'");
                                $row_mac = $result_mac->fetchArray();
                                $macs = $row_mac['macs'] ?? '0';
                            ?>
                            <span class="badge badge-macs">
                                <i class="fas fa-bolt mr-2"></i><?php echo $macs; ?> MACs
                            </span>
                        </li>

                        <div class="topbar-divider d-none d-sm-block" style="border-right: 1px solid rgba(255,255,255,.10);"></div>

                        <li class="nav-item">
                            <a class="nav-link btn-logout-top" href="../logout.php">
                                <span>Logout</span>
                                <i class="fas fa-power-off ml-2"></i>
                            </a>
                        </li>
                    </ul>
                </nav>
