<div class="overlay" id="overlay" onclick="toggleMenu()"></div>

<nav class="sidebar" id="sidebar">
    <div class="text-center mb-4 position-relative">
        <h4 class="fw-bold text-white mt-2"><?= htmlspecialchars($nomePainel) ?></h4>
        <button class="btn btn-sm d-lg-none position-absolute" style="top: -10px; right: -15px; color: #a6a6b7; font-size: 1.5rem;" onclick="toggleMenu()">
            <i class="fas fa-times"></i>
        </button>
    </div>
    
    <div class="nav flex-column">
        <a href="index.php" class="nav-link active"><i class="fas fa-home"></i> Dashboard</a>
        <?php if ($isAdmin): ?>
            <div class="nav-group-title">ADMINISTRATIVO</div>
            <a href="#submenuCsp" data-bs-toggle="collapse" class="nav-link d-flex justify-content-between align-items-center" aria-expanded="true">
                <span><i class="fas fa-server"></i> Gerenciar CSP</span>
                <i class="fas fa-chevron-down submenu-icon"></i>
            </a>
            <div class="collapse show" id="submenuCsp">
                <div class="ms-3 ps-2 border-start border-secondary">
                    <a href="gerenciar_dns.php" class="nav-link"><i class="fas fa-network-wired"></i> Servidores</a>
                    <a href="gerenciar_perfis.php" class="nav-link"><i class="fas fa-layer-group"></i> Perfis</a>
                    <a href="gerenciar_linhas_csp.php" class="nav-link"><i class="fas fa-plug"></i> Linhas CSP</a>
                    <a href="gerenciar_usuarios_csp.php" class="nav-link"><i class="fas fa-users-cog"></i> Usuários CSP</a>
                    <a href="gerenciar_backups_csp.php" class="nav-link"><i class="fas fa-save"></i> Backups CSP</a>
                </div>
            </div>
            <a href="gerenciar_admins.php" class="nav-link"><i class="fas fa-user-shield"></i> Admins</a>
            <a href="personalizar_painel.php" class="nav-link"><i class="fas fa-paint-brush"></i> Personalizar</a>
            <a href="config_geral.php" class="nav-link"><i class="fas fa-cogs"></i> Configurações</a>
            
            
            
            <div class="nav-group-title">ADMIN</div>
            <a href="gerenciar_ips.php" class="nav-link"><i class="fas fa-user-shield"></i> Firewall IPs</a>
            <a href="gerenciar_bloqueios.php" class="nav-link <?= (basename($_SERVER['PHP_SELF']) == 'gerenciar_bloqueios.php') ? 'active' : '' ?>">
    <i class="fas fa-shield-alt" style="width: 20px; text-align: center;"></i> Controle Anti-Fraude
</a>

            <a href="gerenciar_backups.php" class="nav-link"><i class="fas fa-database"></i> Backup</a>
            <a href="ferramentas_migracao.php" class="nav-link"><i class="fas fa-exchange-alt"></i> Exportar/Importar</a>
        <?php endif; ?>
        
        <div class="nav-group-title">Gestao de Clientes</div>
        <a href="clientes.php" class="nav-link"><i class="fas fa-users"></i> Clientes</a>
        <a href="testes.php" class="nav-link"><i class="fas fa-stopwatch"></i> Testes</a>
        <a href="monitor.php" class="nav-link"><i class="fas fa-bell"></i> Clientes Online</a>
        <div class="nav-group-title">Gestao de Revendedores</div>
        <a href="revendedores.php" class="nav-link"><i class="fas fa-store"></i> Revendedores</a>
        
        <div class="nav-group-title">ChatBot</div>
        <li style="list-style: none;">
            <a href="gerador_robo.php" class="nav-link" style="color: #a6a6b7; padding: 12px 15px; border-radius: 8px; display: flex; align-items: center; gap: 12px; text-decoration: none; margin-bottom: 5px; font-weight: 500; transition: 0.2s;">
                <i class="fa fa-robot"></i> <span>ChatBot</span>
            </a>
        </li>
        
        <div class="nav-group-title">Api WhatsApp</div>
        <li style="list-style: none;">
           <a href="automacao_whatsapp.php" class="nav-link"><i class="fab fa-whatsapp"></i> Automação Zap</a>
           <a href="config_whatsapp.php" class="nav-link"><i class="fas fa-cogs"></i> Config. API Zap</a> 
        </li>
            
        <div class="nav-group-title">Ferramentas</div>
        <a href="meus_links.php" class="nav-link"><i class="fas fa-link"></i> Central Links</a>
        <a href="gerenciar_mascara.php" class="nav-link"><i class="fas fa-mask"></i> Máscaras URL</a>        
        <a href="config_mp_revenda.php" class="nav-link"><i class="fas fa-wallet"></i> Config. Pagamento</a>
        <a href="gerenciar_planos.php" class="nav-link"><i class="fas fa-tags"></i> Planos de Venda</a>
        <a href="gerenciar_email.php" class="nav-link"><i class="fas fa-envelope"></i> SMTP Email</a>
        <a href="relatorio.php" class="nav-link"><i class="fas fa-file-invoice-dollar"></i> Relatório de Faturas</a>
        <a href="suporte.php" class="nav-link"><i class="fas fa-headset"></i> Suporte <?php if(isset($total_msg_nao_lidas) && $total_msg_nao_lidas > 0): ?><span class="badge bg-danger ms-auto rounded-pill"><?= $total_msg_nao_lidas ?></span><?php endif; ?></a>
        <a href="enviar_circular.php" class="nav-link"><i class="fas fa-paper-plane"></i> Enviar Circular</a>
        
        
        <?php if (isset($_SESSION['nivel']) && strtolower($_SESSION['nivel']) === 'admin'): ?>
<a href="atualizar.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'atualizar.php' ? 'active' : '' ?>">
    <i class="fas fa-sync-alt"></i> Atualização do Painel
</a>
<?php endif; ?>

  </div>      
        <a href="sair.php" class="nav-link text-danger mt-4"><i class="fas fa-sign-out-alt"></i> Sair</a>
    </div>
</nav>