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

$db = new SQLite3('../a/.eggziedb.db');
$seller_name = $_SESSION['seller_name'];
$result = $db->query("SELECT COUNT(*) as count FROM 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'];

// ===============================================
// SISTEMA DE LOGOS INDIVIDUAIS - CORRIGIDO
// ===============================================

// Função para obter a logo da revenda - CORRIGIDA
function getRevendaLogo($revenda_id, $user_type = 'revenda') {
    try {
        // USAR BANCO DEDICADO PARA LOGOS
        $logos_db = new SQLite3('../a/.eggzielogos.db');
        
        // CRIAR TABELA SE NÃO EXISTIR - CORREÇÃO
        $logos_db->exec("
            CREATE TABLE IF NOT EXISTS revenda_logos (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                revenda_id INTEGER NOT NULL,
                user_type TEXT NOT NULL,
                logo_path TEXT NOT NULL,
                created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
                updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
                UNIQUE(revenda_id, user_type)
            )
        ");
        
        $stmt = $logos_db->prepare("SELECT logo_path FROM revenda_logos WHERE revenda_id = ? AND user_type = ?");
        $stmt->bindValue(1, $revenda_id, SQLITE3_INTEGER);
        $stmt->bindValue(2, $user_type, SQLITE3_TEXT);
        $result = $stmt->execute();
        
        if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
            $logos_db->close();
            return $row['logo_path'];
        }
        $logos_db->close();
    } catch (Exception $e) {
        error_log("Erro ao buscar logo: " . $e->getMessage());
    }
    
    return 'img/ibo.gif'; // Logo padrão
}

// Determinar tipo de usuário e obter logo
$user_type = 'revenda';
$current_revenda_id = $_SESSION['id'] ?? 1;

// Obter logo atual
$current_logo = getRevendaLogo($current_revenda_id, $user_type);

// ===============================================
// CÓDIGO ORIGINAL (mantido)
// ===============================================

$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'];

$IIIIIIIllIII = file_get_contents('../includes/eggzie.json');
$IIIIIIIllIIl = json_decode($IIIIIIIllIII, true);
$IIIIIIIllII1 = $IIIIIIIllIIl['info']['aa'];
?>

<!DOCTYPE html>
<html lang="en">
<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="description" content="">
    <meta name="author" content="">
    <meta name="google" content="notranslate">
    <title>IBO REVENDA ULTRA</title>
    <link rel="shortcut icon" href="../ibo1.gif" type="image/x-icon">
    <link rel="icon" href="../ibo1.gif" type="image/x-icon">
    
    <!-- Material Icons -->
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons+Round" rel="stylesheet">
    
    <!-- Custom styles for this template-->
    <link href="../css/sb-admin-<?php echo $IIIIIIIllII1; ?>.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../css/jquery.datetimepicker.min.css"/>
    
    <!-- Custom fonts for this template-->
    <link href="../vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
    <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
    
    <!-- Bootstrap JavaScript -->
    <script src="../vendor/jquery/jquery.min.js"></script>
    <script src="../vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
    
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">

    <style>
    /* === DESIGN FUTURISTA MODERNO - TEMA REVENDA === */
    :root {
        --primary: #FF6B9D;
        --primary-dark: #D94A7E;
        --secondary: #00D4FF;
        --accent: #FFD166;
        --surface: #0A0F1C;
        --surface-light: #1A1F2C;
        --surface-lighter: #2A2F3C;
        --text-primary: #FFFFFF;
        --text-secondary: #B0B7C3;
        --text-muted: #6B7280;
        --border: rgba(255,255,255,0.1);
        --glow: 0 0 20px rgba(255, 107, 157, 0.3);
        --glow-accent: 0 0 20px rgba(255, 209, 102, 0.3);
    }

    /* === FUNDO FUTURISTA === */
    body {
        background: linear-gradient(135deg, #0A0F1C 0%, #151B2D 50%, #0A0F1C 100%) !important;
        font-family: 'Inter', sans-serif !important;
        min-height: 100vh;
        color: var(--text-primary);
        overflow-x: hidden;
    }

    /* Efeito de partículas futuristas */
    body::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: 
            radial-gradient(circle at 20% 80%, rgba(255, 107, 157, 0.1) 0%, transparent 50%),
            radial-gradient(circle at 80% 20%, rgba(0, 212, 255, 0.1) 0%, transparent 50%),
            radial-gradient(circle at 40% 40%, rgba(255, 209, 102, 0.05) 0%, transparent 50%);
        pointer-events: none;
        z-index: -1;
    }

    /* === HEADER FUTURISTA === */
    .futuristic-header {
        background: rgba(10, 15, 28, 0.9) !important;
        backdrop-filter: blur(20px);
        border-bottom: 1px solid var(--border);
        box-shadow: var(--glow);
        padding: 12px 0;
    }

    .user-info {
        color: var(--text-primary);
        font-weight: 600;
        text-align: center;
    }

    .user-info h5 {
        margin: 0;
        font-size: 1.1rem;
        background: linear-gradient(135deg, var(--primary), var(--accent));
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }

    .futuristic-logout-btn {
        background: linear-gradient(135deg, var(--primary), var(--primary-dark)) !important;
        border: none;
        border-radius: 12px;
        padding: 10px 20px;
        color: white !important;
        font-weight: 600;
        text-transform: none;
        letter-spacing: 0.5px;
        transition: all 0.3s ease;
        text-decoration: none;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        box-shadow: var(--glow);
    }

    .futuristic-logout-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 0 30px rgba(255, 107, 157, 0.5);
        color: white !important;
    }

    /* === SIDEBAR FUTURISTA === */
    #sidebar {
        background: rgba(10, 15, 28, 0.95) !important;
        backdrop-filter: blur(20px);
        border-right: 1px solid var(--border);
        height: 100vh;
        transition: all 0.3s ease;
        width: 280px;
        position: fixed;
        left: 0;
        top: 0;
        z-index: 1000;
        padding: 0;
        display: flex;
        flex-direction: column;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    /* Container da sidebar com scroll */
    .sidebar-container {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 0 12px 20px 12px;
    }

    /* Custom scrollbar futurista */
    .sidebar-container::-webkit-scrollbar {
        width: 6px;
    }

    .sidebar-container::-webkit-scrollbar-track {
        background: var(--surface-light);
        border-radius: 3px;
    }

    .sidebar-container::-webkit-scrollbar-thumb {
        background: linear-gradient(135deg, var(--primary), var(--accent));
        border-radius: 3px;
    }

    /* === SEÇÕES FUTURISTAS === */
    .futuristic-section {
        background: var(--surface-light);
        border-radius: 16px;
        margin: 12px 0;
        padding: 0;
        border: 1px solid var(--border);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
        overflow: hidden;
        transition: all 0.3s ease;
        position: relative;
    }

    .futuristic-section::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 1px;
        background: linear-gradient(90deg, transparent, var(--primary), transparent);
    }

    .futuristic-section:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
        border-color: var(--primary);
    }

    .futuristic-section-header {
        background: linear-gradient(135deg, var(--surface-light), var(--surface-lighter));
        padding: 16px 20px;
        border-bottom: 1px solid var(--border);
        font-weight: 600;
        color: var(--text-primary);
        font-size: 14px;
        text-transform: uppercase;
        letter-spacing: 1px;
        display: flex;
        align-items: center;
        gap: 12px;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .futuristic-section-header .material-icons-round {
        font-size: 18px;
        background: linear-gradient(135deg, var(--primary), var(--accent));
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }

    .futuristic-section-content {
        padding: 8px 0;
    }

    /* === ITENS DA SIDEBAR FUTURISTAS === */
    .futuristic-item {
        display: flex !important;
        align-items: center !important;
        padding: 14px 20px !important;
        color: var(--text-secondary) !important;
        transition: all 0.3s ease;
        text-decoration: none;
        border: none;
        background: transparent;
        width: 100%;
        text-align: left;
        position: relative;
        overflow: hidden;
        border-radius: 12px;
        margin: 4px 8px;
        min-height: 52px;
        gap: 16px;
    }

    .futuristic-item::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        width: 3px;
        background: linear-gradient(135deg, var(--primary), var(--accent));
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .futuristic-item:hover {
        background: rgba(255, 107, 157, 0.1);
        color: var(--text-primary) !important;
        transform: translateX(8px);
    }

    .futuristic-item:hover::before {
        opacity: 1;
    }

    .futuristic-item .material-icons-round {
        font-size: 20px;
        width: 24px;
        text-align: center;
        background: linear-gradient(135deg, var(--primary), var(--accent));
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
        transition: all 0.3s ease;
        flex-shrink: 0;
    }

    .futuristic-item:hover .material-icons-round {
        transform: scale(1.1);
        filter: drop-shadow(0 0 8px rgba(255, 107, 157, 0.5));
    }

    .futuristic-item span {
        font-size: 14px;
        font-weight: 500;
        flex: 1;
        letter-spacing: 0.3px;
    }

    /* === ITEM COM COLLAPSE FUTURISTA - COMPORTAMENTO CORRETO === */
    .futuristic-collapse-toggle {
        cursor: pointer;
        position: relative;
    }

    .futuristic-collapse-toggle .material-icons-round:last-child {
        transition: transform 0.3s ease;
        margin-left: auto;
        font-size: 18px;
        opacity: 0.7;
    }

    .futuristic-collapse-toggle[aria-expanded="true"] .material-icons-round:last-child {
        transform: rotate(180deg);
        opacity: 1;
    }

    /* === MENU COLLAPSE FUTURISTA - COMPORTAMENTO DE ROLAGEM === */
    .futuristic-collapse-menu {
        background: var(--surface-lighter) !important;
        border-radius: 12px;
        margin: 8px 12px;
        border: 1px solid var(--border);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
        overflow: hidden;
        position: relative;
        /* COMPORTAMENTO CORRETO: faz parte do fluxo normal */
        position: static;
        max-height: none;
    }

    .futuristic-collapse-menu::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 1px;
        background: linear-gradient(90deg, transparent, var(--accent), transparent);
    }

    .futuristic-collapse-item {
        display: flex !important;
        align-items: center !important;
        padding: 14px 16px !important;
        color: var(--text-secondary) !important;
        text-decoration: none;
        transition: all 0.3s ease;
        border-bottom: 1px solid var(--border);
        min-height: 48px;
        box-sizing: border-box;
        border-radius: 0;
        gap: 12px;
    }

    .futuristic-collapse-item:last-child {
        border-bottom: none;
    }

    .futuristic-collapse-item:hover {
        background: rgba(255, 209, 102, 0.1);
        color: var(--text-primary) !important;
        transform: translateX(4px);
    }

    .futuristic-collapse-item .material-icons-round {
        font-size: 18px;
        width: 20px;
        text-align: center;
        background: linear-gradient(135deg, var(--accent), var(--primary));
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
        flex-shrink: 0;
    }

    .futuristic-collapse-item span {
        font-size: 13px;
        font-weight: 500;
        letter-spacing: 0.3px;
    }

    .futuristic-collapse-header {
        color: var(--text-muted) !important;
        font-size: 11px !important;
        font-weight: 700 !important;
        padding: 16px 16px 8px 16px !important;
        margin: 0 !important;
        text-transform: uppercase;
        letter-spacing: 1.5px;
        border-bottom: 1px solid var(--border);
        background: var(--surface-light);
    }

    /* === BOTÃO TOGGLE FUTURISTA === */
    #sidebarToggleTop {
        background: linear-gradient(135deg, var(--primary), var(--primary-dark)) !important;
        border: none;
        color: white !important;
        transition: all 0.3s ease;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 12px;
        box-shadow: var(--glow);
    }

    #sidebarToggleTop:hover {
        transform: scale(1.05);
        box-shadow: 0 0 20px rgba(255, 107, 157, 0.6);
    }

    #sidebarToggleTop .material-icons-round {
        color: white !important;
        font-size: 20px;
    }

    /* === CONTEÚDO PRINCIPAL === */
    #content-wrapper {
        background: transparent !important;
        margin-left: 280px;
        transition: all 0.3s ease;
        min-height: 100vh;
    }

    /* REMOVER TODOS OS FUNDOS BRANCOS DO CONTEÚDO */
    .container-fluid, .main-content, .content-wrapper, 
    .bg-white, .card, .shadow, .container {
        background: transparent !important;
    }

    /* GARANTIR que o conteúdo principal tenha fundo escuro */
    #content, #main, main, [role="main"] {
        background: transparent !important;
    }

    #wrapper.toggled #content-wrapper {
        margin-left: 0;
    }

    #wrapper.toggled #sidebar {
        margin-left: -280px;
    }

    /* === LOGO E BRAND FUTURISTA === */
    .futuristic-sidebar-brand {
        padding: 24px 0;
        border-bottom: 1px solid var(--border);
        text-align: center;
        margin-bottom: 8px;
        flex-shrink: 0;
        background: var(--surface-light);
        position: relative;
    }

    .futuristic-sidebar-brand::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 20%;
        right: 20%;
        height: 1px;
        background: linear-gradient(90deg, transparent, var(--primary), transparent);
    }

    .futuristic-sidebar-brand img {
        border-radius: 16px;
        transition: all 0.3s ease;
        box-shadow: var(--glow);
        border: 2px solid transparent;
        background: linear-gradient(135deg, var(--surface-light), var(--surface-lighter)) padding-box,
                   linear-gradient(135deg, var(--primary), var(--accent)) border-box;
        max-width: 120px;
        max-height: 60px;
        object-fit: contain;
    }

    .futuristic-sidebar-brand:hover img {
        transform: scale(1.02);
        box-shadow: 0 0 30px rgba(255, 107, 157, 0.5);
    }

    /* === COMPORTAMENTO DO COLLAPSE - CORRIGIDO PARA ROLAGEM === */
    /* Garantir que o collapse empurre os itens para baixo */
    #collapsePages.collapse:not(.show) {
        display: none;
    }

    #collapsePages.collapsing {
        height: 0;
        overflow: hidden;
        transition: height 0.35s ease;
    }

    #collapsePages.collapse.show {
        display: block;
        height: auto;
        /* COMPORTAMENTO CORRETO: faz parte do fluxo normal */
        position: static;
        z-index: auto;
    }

    /* Garantir que a seção de configurações tenha espaço suficiente */
    .futuristic-section:has(#collapsePages.show) {
        min-height: auto;
        overflow: visible;
    }

    /* === BADGES E INDICADORES === */
    .futuristic-badge {
        background: linear-gradient(135deg, var(--primary), var(--accent));
        color: var(--surface) !important;
        border-radius: 8px;
        padding: 6px 12px;
        font-weight: 600;
        font-size: 0.8rem;
        box-shadow: var(--glow);
    }

    .seller-info {
        text-align: center;
        padding: 16px;
        color: var(--text-primary);
        background: var(--surface-light);
        border-radius: 12px;
        margin: 12px;
        border: 1px solid var(--border);
        box-shadow: var(--glow);
    }

    .seller-info span {
        font-weight: 600;
        background: linear-gradient(135deg, var(--primary), var(--accent));
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }

    /* === RESPONSIVIDADE FUTURISTA === */
    @media (max-width: 768px) {
        .futuristic-header {
            padding: 10px 0;
        }
        
        .user-info h5 {
            font-size: 1rem;
        }
        
        .futuristic-logout-btn {
            padding: 8px 16px;
            font-size: 0.9rem;
        }
        
        #sidebar {
            margin-left: -280px;
            width: 280px;
            height: 100vh;
            z-index: 1050;
        }
        
        #content-wrapper {
            margin-left: 0 !important;
        }
        
        #wrapper.toggled #sidebar {
            margin-left: 0;
        }

        .futuristic-section {
            margin: 10px 0;
        }
        
        .futuristic-item {
            padding: 12px 16px !important;
            min-height: 50px;
            margin: 4px 6px;
            gap: 14px;
        }

        .futuristic-collapse-menu {
            margin: 6px 8px;
        }

        .futuristic-collapse-item {
            padding: 12px 14px !important;
            min-height: 46px;
            gap: 10px;
        }

        /* COMPORTAMENTO CORRETO NO MOBILE: collapse empurra os itens */
        .futuristic-section .nav-item {
            position: static;
        }

        #collapsePages {
            position: static;
            z-index: auto;
        }
    }

    /* Efeitos de brilho e neon */
    .glow-text {
        text-shadow: 0 0 10px currentColor;
    }

    .neon-border {
        border: 1px solid;
        border-image: linear-gradient(135deg, var(--primary), var(--accent)) 1;
    }
    
    /* === CAIXA DO EMAIL NEPSTER FUTURISTA === */
    .email-nepster-container {
        padding: 0 16px 16px 16px;
    }

    .email-nepster-box {
        background: linear-gradient(135deg, var(--surface-light), var(--surface-lighter));
        border: 1px solid var(--border);
        border-radius: 16px;
        padding: 16px;
        display: flex;
        align-items: center;
        gap: 12px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
        transition: all 0.3s ease;
        position: relative;
        overflow: hidden;
    }

    .email-nepster-box::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 2px;
        background: linear-gradient(90deg, var(--primary), var(--accent));
    }

    .email-nepster-box:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 30px rgba(0, 212, 255, 0.3);
        border-color: var(--secondary);
    }

    .email-icon {
        background: linear-gradient(135deg, var(--secondary), var(--primary));
        border-radius: 12px;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        box-shadow: 0 0 15px rgba(0, 212, 255, 0.5);
    }

    .email-icon i {
        color: white;
        font-size: 18px;
    }

    .email-content {
        flex: 1;
        min-width: 0;
    }

    .email-label {
        color: var(--text-secondary);
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 1px;
        margin-bottom: 4px;
    }

    .email-address {
        color: var(--text-primary);
        font-weight: 600;
        font-size: 13px;
        word-break: break-all;
        background: linear-gradient(135deg, var(--primary), var(--accent));
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }

    .email-copy-btn {
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid var(--border);
        border-radius: 8px;
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.3s ease;
        color: var(--text-secondary);
        flex-shrink: 0;
    }

    .email-copy-btn:hover {
        background: var(--secondary);
        color: white;
        transform: scale(1.1);
        box-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
    }

    /* Tooltip de copiado */
    .email-copy-btn.copied::after {
        content: 'Copiado!';
        position: absolute;
        top: -30px;
        left: 50%;
        transform: translateX(-50%);
        background: var(--accent);
        color: var(--surface);
        padding: 4px 8px;
        border-radius: 6px;
        font-size: 10px;
        font-weight: 600;
        white-space: nowrap;
    }
    
    
    
     /* === TOGGLE QUE ACOMPANHA A SIDEBAR - CORRIGIDO === */
@media (max-width: 768px) {
    #sidebarToggleTop {
        position: fixed;
        top: 20px;
        left: 20px;
        z-index: 1100;
        background: linear-gradient(135deg, var(--primary), var(--primary-dark)) !important;
        border: none;
        color: white !important;
        width: 45px;
        height: 45px;
        border-radius: 12px;
        display: flex !important;
        align-items: center;
        justify-content: center;
        box-shadow: var(--glow);
        transition: all 0.3s ease;
    }

    /* QUANDO SIDEBAR ABRE (wrapper NÃO toggled) */
    #wrapper:not(.toggled) #sidebarToggleTop {
        left: 300px; /* Ao lado da sidebar ABERTA */
    }

    /* QUANDO SIDEBAR FECHA (wrapper toggled) */
    #wrapper.toggled #sidebarToggleTop {
        left: 20px; /* Posição original - sidebar FECHADA */
    }

    /* Sidebar - COMPORTAMENTO CORRETO */
    #sidebar {
        margin-left: -280px; /* FECHADA por padrão */
        width: 280px;
        height: 100vh;
        z-index: 1050;
        transition: all 0.3s ease;
    }

    /* QUANDO SIDEBAR ABRE */
    #wrapper:not(.toggled) #sidebar {
        margin-left: 0; /* ABERTA */
    }

    /* QUANDO SIDEBAR FECHA */
    #wrapper.toggled #sidebar {
        margin-left: -280px; /* FECHADA */
    }
}

/* === CENTRALIZAR APENAS O TÍTULO NO MOBILE === */
@media (max-width: 768px) {
    .user-info {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        width: auto;
        text-align: center;
        top: 50%;
        transform: translate(-50%, -50%);
        margin: 0;
    }
    
    .user-info h5 {
        margin: 0;
        white-space: nowrap;
        font-size: 1rem;
    }
    
    /* Botão Sair fica no canto direito */
    .navbar-nav.ml-auto {
        margin-left: auto !important;
    }
    
    /* Ajustar o header */
    .futuristic-header {
        position: relative;
        min-height: 60px;
    }
}

/* === AJUSTE DO BADGE DE MACs === */
@media (max-width: 768px) {
    /* Badge de MACs abaixo do botão Sair */
    .navbar-nav.ml-auto {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 8px;
    }
    
    /* Botão Sair fica em cima */
    .futuristic-logout-btn {
        order: 1;
    }
    
    /* Badge de MACs fica embaixo */
    .futuristic-badge {
        order: 2;
        margin-top: 5px;
        font-size: 0.7rem;
        padding: 4px 8px;
    }
    
    /* Ajustar o header para os elementos */
    .futuristic-header {
        min-height: 80px;
        padding: 10px 15px !important;
    }
}
    </style>
</head>
<body id="page-top">
    
    <!-- Page Wrapper -->
    <div id="wrapper">
        <!-- Sidebar Futurista -->
        <ul class="navbar-nav sidebar sidebar-dark accordion" id="sidebar">
            <!-- Sidebar - Brand COM LOGO INDIVIDUAL -->
            <a class="futuristic-sidebar-brand d-flex align-items-center justify-content-center" href="users.php">
                <div class="sidebar-brand-icon">
                    <img class="img-profile" width="120px" src="<?php echo "../" . $current_logo; ?>" 
                         alt="Logo <?php echo $seller_name; ?>"
                         onerror="this.src='../img/ibo.gif'">
                </div>
            </a>
            
            <!-- Informações do Revendedor -->
            <div class="seller-info">
                <?php
                $result = $db->query("SELECT id_ref FROM revenda WHERE usuario = '$seller_name'");
                while ($row = $result->fetchArray()) {
                    $id_ref = $row['id_ref'];
                    break;
                }
                ?>
                <span>Olá, <?php echo $seller_name; ?> - ID REF: <?php echo $id_ref; ?></span>
            </div>

            <!-- 🔥 CAIXA DO EMAIL NEPSTER - USANDO BANCO CORRETO -->
            <div class="email-nepster-container">
                <?php
                // BUSCAR O EMAIL NO BANCO NEPSTER_EMAILS.DB
                $email_nepster = 'Email não configurado';
                
                try {
                    $nepster_db = new SQLite3('../a/.nepster_emails.db');
                    
                    // Buscar email pelo usuário atual
                    $stmt = $nepster_db->prepare("SELECT email FROM emails WHERE usuario = ?");
                    $stmt->bindValue(1, $seller_name, SQLITE3_TEXT);
                    $result = $stmt->execute();
                    
                    if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
                        $email_nepster = $row['email'];
                    }
                    
                    $nepster_db->close();
                } catch (Exception $e) {
                    $email_nepster = 'Erro ao buscar email';
                    error_log("Erro ao buscar email Nepster: " . $e->getMessage());
                }
                ?>
                <div class="email-nepster-box">
                    <div class="email-icon">
                        <i class="fas fa-envelope"></i>
                    </div>
                    <div class="email-content">
                        <div class="email-label">Email Nepster</div>
                        <div class="email-address" id="nepsterEmail"><?php echo htmlspecialchars($email_nepster); ?></div>
                    </div>
                    <button class="email-copy-btn" onclick="copyNepsterEmail()">
                        <i class="fas fa-copy"></i>
                    </button>
                </div>
            </div>
            
            <!-- Container com scroll -->
            <div class="sidebar-container">
                <!-- Seção 1: Gerenciamento de Usuários -->
                <div class="futuristic-section">
                    <div class="futuristic-section-header">
                        <span class="material-icons-round">manage_accounts</span>
                        <span>Gerenciamento</span>
                    </div>
                    <div class="futuristic-section-content">
                        <li class="nav-item">
                            <a class="futuristic-item" href="index.php">
                                <span class="material-icons-round">group_add</span>
                                <span>Usuários</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="futuristic-item" href="sub_revenda.php">
                                <span class="material-icons-round">account_tree</span>
                                <span>Sub Revenda</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="futuristic-item" href="add_cliente.php">
                                <span class="material-icons-round">person_add</span>
                                <span>Adicionar Cliente</span>
                            </a>
                        </li>
                    </div>
                </div>

                <!-- Seção 2: Configurações de Widget - COMPORTAMENTO CORRETO -->
                <div class="futuristic-section">
                    <div class="futuristic-section-header">
                        <span class="material-icons-round">tune</span>
                        <span>Configurações</span>
                    </div>
                    <div class="futuristic-section-content">
                        <!-- Item com collapse funcionando CORRETAMENTE -->
                        <li class="nav-item">
                            <a class="futuristic-item futuristic-collapse-toggle" data-toggle="collapse" data-target="#collapsePages" aria-expanded="false" aria-controls="collapsePages">
                                <span class="material-icons-round">dashboard</span>
                                <span>Config de Widget</span>
                                <span class="material-icons-round">expand_more</span>
                            </a>
                            <div id="collapsePages" class="collapse">
                                <div class="futuristic-collapse-menu">
                                    <h6 class="futuristic-collapse-header">Envio de Anúncios:</h6>
                                    <a class="futuristic-collapse-item" href="ads.php">
                                        <span class="material-icons-round">ads_click</span>
                                        <span>Enviar Banner</span>
                                    </a>
                                </div>
                            </div>
                        </li>
                        <li class="nav-item">
                            <a class="futuristic-item" href="Image.php">
                                <span class="material-icons-round">collections</span>
                                <span>Imagens de fundo</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="futuristic-item" href="logo.php">
                                <span class="material-icons-round">auto_awesome</span>
                                <span>Logotipo</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="futuristic-item" href="layouts.php">
                                <span class="material-icons-round">palette</span>
                                <span>Temas</span>
                            </a>
                        </li>
                    </div>
                </div>

                <!-- Seção 3: Sistema e Perfil -->
                <div class="futuristic-section">
                    <div class="futuristic-section-header">
                        <span class="material-icons-round">settings_suggest</span>
                        <span>Sistema</span>
                    </div>
                    <div class="futuristic-section-content">
                        <li class="nav-item">
                            <a class="futuristic-item" href="profile.php">
                                <span class="material-icons-round">person</span>
                                <span>Perfil</span>
                            </a>
                        </li>
                    </div>
                </div>
                
                <?php include 'footer_eon.php'; ?>

                <!-- Espaço extra no final -->
                <div style="height: 20px;"></div>
            </div>
        </ul>
        
        <!-- Content Wrapper -->
        <div id="content-wrapper" class="d-flex flex-column">
            <!-- Main Content -->
            <div id="content">
                <!-- Topbar Futurista -->
                <nav class="navbar navbar-expand navbar-light topbar mb-4 static-top shadow futuristic-header">
                    <!-- Sidebar Toggle (Topbar) -->
                    <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
                        <span class="material-icons-round">menu</span>
                    </button>
                    
                    <!-- User Info -->
                    <div class="user-info">
                        <h5>Revenda<br><?php echo $IIIIIIIlI11l; ?></h5>
                    </div>
                    
                    <!-- Topbar Navbar -->
                    <ul class="navbar-nav ml-auto">
                        <!-- Indicador de MACs -->
                        <li class="nav-item dropdown no-arrow mx-1">
                            <a class="nav-link dropdown-toggle">
                                <?php
                                $db1 = new SQLite3('../a/.eggziedb.db');
                                $result = $db1->query("SELECT macs FROM revenda WHERE usuario = '$seller_name'");
                                while ($row = $result->fetchArray()) {
                                    $macs = $row['macs'];
                                    break;
                                }
                                ?>
                                <span class="futuristic-badge"><?php echo $macs; ?> MACs</span>
                            </a>
                        </li>
                        
                        <div class="topbar-divider d-none d-sm-block"></div>
                        
                        <li class="nav-item dropdown no-arrow mx-1">
                            <a class="futuristic-logout-btn" href="../logout.php">
                                <span class="material-icons-round">logout</span>
                                <span>Sair</span>
                            </a>
                        </li>
                    </ul>
                </nav>

<script>
document.addEventListener('DOMContentLoaded', function() {
    // Toggle sidebar
    const sidebarToggle = document.getElementById('sidebarToggleTop');
    const wrapper = document.getElementById('wrapper');

    if (sidebarToggle) {
        sidebarToggle.addEventListener('click', function(e) {
            e.preventDefault();
            wrapper.classList.toggle('toggled');
            
            const icon = this.querySelector('.material-icons-round');
            if (wrapper.classList.contains('toggled')) {
                icon.textContent = 'chevron_right';
            } else {
                icon.textContent = 'menu';
            }
        });
    }

    // Collapse functionality - COMPORTAMENTO CORRETO
    $('.futuristic-collapse-toggle').on('click', function(e) {
        e.preventDefault();
        e.stopPropagation();
        
        const target = $(this).data('target');
        $(target).collapse('toggle');
        
        const isExpanded = $(this).attr('aria-expanded') === 'true';
        $(this).attr('aria-expanded', !isExpanded);

        // No mobile, fazer scroll suave para a seção expandida
        if (window.innerWidth <= 768 && !isExpanded) {
            setTimeout(() => {
                const expandedSection = $(this).closest('.futuristic-section');
                const sidebarContainer = $('.sidebar-container');
                const sectionTop = expandedSection.offset().top - sidebarContainer.offset().top + sidebarContainer.scrollTop();
                
                sidebarContainer.animate({
                    scrollTop: sectionTop - 10
                }, 300);
            }, 350);
        }
    });

    // Fechar sidebar no mobile ao clicar fora
    document.addEventListener('click', function(e) {
        if (window.innerWidth <= 768) {
            const sidebar = document.getElementById('sidebar');
            if (!sidebar.contains(e.target) && !sidebarToggle.contains(e.target)) {
                wrapper.classList.add('toggled');
                sidebarToggle.querySelector('.material-icons-round').textContent = 'chevron_right';
            }
        }
    });

    // Garantir que o collapse funcione corretamente
    $('#collapsePages').on('show.bs.collapse', function () {
        // Remover qualquer comportamento de sobreposição
        $(this).css({
            'position': 'static',
            'z-index': 'auto'
        });
    });

    // Efeitos de hover com delay
    const items = document.querySelectorAll('.futuristic-item, .futuristic-collapse-item');
    items.forEach((item, index) => {
        item.style.transitionDelay = `${index * 0.05}s`;
    });
});

// 🔹 SISTEMA DE ATUALIZAÇÃO DE LOGO EM TEMPO REAL
document.addEventListener('DOMContentLoaded', function() {
    // Verificar se há logo atualizada no localStorage
    const logoUpdated = localStorage.getItem('logo_updated');
    const newLogoPath = localStorage.getItem('new_logo_path');
    
    if (logoUpdated && newLogoPath) {
        // Se a logo foi atualizada há menos de 5 minutos, usa a nova
        const fiveMinutesAgo = Date.now() - (5 * 60 * 1000);
        if (parseInt(logoUpdated) * 1000 > fiveMinutesAgo) {
            updateHeaderLogo(newLogoPath);
        } else {
            // Limpa localStorage se for muito antigo
            localStorage.removeItem('logo_updated');
            localStorage.removeItem('new_logo_path');
        }
    }
    
    // Função para atualizar logo no header
    function updateHeaderLogo(newLogoPath) {
        const sidebarLogo = document.querySelector('.futuristic-sidebar-brand img');
        if (sidebarLogo) {
            sidebarLogo.src = '../' + newLogoPath + '?v=' + new Date().getTime();
            console.log('✅ Logo do header atualizada em tempo real:', newLogoPath);
        }
    }
    
    // Escutar evento customizado de atualização de logo
    window.addEventListener('logoUpdated', function() {
        const newLogoPath = localStorage.getItem('new_logo_path');
        if (newLogoPath) {
            updateHeaderLogo(newLogoPath);
        }
    });
});

// 🔥 FUNÇÃO PARA COPIAR EMAIL NEPSTER
function copyNepsterEmail() {
    const emailElement = document.getElementById('nepsterEmail');
    const emailText = emailElement.textContent;
    const copyBtn = event.currentTarget;
    
    // Copiar para área de transferência
    navigator.clipboard.writeText(emailText).then(function() {
        // Feedback visual
        copyBtn.classList.add('copied');
        copyBtn.innerHTML = '<i class="fas fa-check"></i>';
        
        setTimeout(function() {
            copyBtn.classList.remove('copied');
            copyBtn.innerHTML = '<i class="fas fa-copy"></i>';
        }, 2000);
        
        console.log('✅ Email copiado: ' + emailText);
    }).catch(function(err) {
        console.error('❌ Erro ao copiar email: ', err);
        // Fallback para método antigo
        const textArea = document.createElement('textarea');
        textArea.value = emailText;
        document.body.appendChild(textArea);
        textArea.select();
        document.execCommand('copy');
        document.body.removeChild(textArea);
        
        // Feedback visual mesmo com fallback
        copyBtn.classList.add('copied');
        copyBtn.innerHTML = '<i class="fas fa-check"></i>';
        
        setTimeout(function() {
            copyBtn.classList.remove('copied');
            copyBtn.innerHTML = '<i class="fas fa-copy"></i>';
        }, 2000);
    });
}
</script>