<style>
    /* Regras para garantir alinhamento perfeito e evitar quebras de texto */
    .sidebar .nav-link {
        white-space: nowrap !important; /* Impede que o texto caia para a linha de baixo */
        overflow: hidden;
        text-overflow: ellipsis; /* Coloca '...' se a tela for muito pequena */
        display: flex;
        align-items: center;
    }
    .sidebar .nav-link i.fa-fw {
        margin-right: 8px; /* Espaçamento padrão entre ícone e texto */
        text-align: center;
    }
</style>

<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 mt-2" style="color: var(--text-color);"><?= 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 <?= basename($_SERVER['PHP_SELF']) == 'index.php' ? 'active' : '' ?>">
            <i class="fas fa-home fa-fw"></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 fa-fw"></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 <?= basename($_SERVER['PHP_SELF']) == 'gerenciar_dns.php' ? 'active' : '' ?>"><i class="fas fa-network-wired fa-fw"></i> Servidores</a>
                    <a href="gerenciar_perfis.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'gerenciar_perfis.php' ? 'active' : '' ?>"><i class="fas fa-layer-group fa-fw"></i> Perfis</a>
                    <a href="gerenciar_linhas_csp.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'gerenciar_linhas_csp.php' ? 'active' : '' ?>"><i class="fas fa-plug fa-fw"></i> Linhas CSP</a>
                    <a href="gerenciar_usuarios_csp.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'gerenciar_usuarios_csp.php' ? 'active' : '' ?>"><i class="fas fa-users-cog fa-fw"></i> Usuários CSP</a>
                    <a href="gerenciar_backups_csp.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'gerenciar_backups_csp.php' ? 'active' : '' ?>"><i class="fas fa-save fa-fw"></i> Backups CSP</a>
                </div>
            </div>
            
            <a href="gerenciar_admins.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'gerenciar_admins.php' ? 'active' : '' ?>"><i class="fas fa-user-shield fa-fw"></i> Admins</a>
            <a href="personalizar_painel.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'personalizar_painel.php' ? 'active' : '' ?>"><i class="fas fa-paint-brush fa-fw"></i> Personalizar</a>
            <a href="config_geral.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'config_geral.php' ? 'active' : '' ?>"><i class="fas fa-cogs fa-fw"></i> Configurações</a>
            
            <div class="nav-group-title">ADMIN</div>
            <a href="gerenciar_ips.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'gerenciar_ips.php' ? 'active' : '' ?>"><i class="fas fa-user-shield fa-fw"></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 fa-fw"></i> Controle Anti-Fraude</a>
            <a href="gerenciar_backups.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'gerenciar_backups.php' ? 'active' : '' ?>"><i class="fas fa-database fa-fw"></i> Backup</a>
            <a href="ferramentas_migracao.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'ferramentas_migracao.php' ? 'active' : '' ?>"><i class="fas fa-exchange-alt fa-fw"></i> Exportar/Importar</a>
        <?php endif; ?>
        
        <div class="nav-group-title">Gestão de Clientes</div>
        <a href="clientes.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'clientes.php' ? 'active' : '' ?>"><i class="fas fa-users fa-fw"></i> Clientes</a>
        <a href="testes.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'testes.php' ? 'active' : '' ?>"><i class="fas fa-stopwatch fa-fw"></i> Testes</a>
        <a href="monitor.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'monitor.php' ? 'active' : '' ?>"><i class="fas fa-bell fa-fw"></i> Clientes Online</a>
        
        <div class="nav-group-title">Gestão de Revendedores</div>
        <a href="revendedores.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'revendedores.php' ? 'active' : '' ?>"><i class="fas fa-store fa-fw"></i> Revendedores</a>
        
        <div class="nav-group-title">ChatBot</div>
        <a href="gerador_robo.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'gerador_robo.php' ? 'active' : '' ?>"><i class="fas fa-robot fa-fw"></i> ChatBot</a>
        
        <div class="nav-group-title">API WhatsApp</div>
        <a href="automacao_whatsapp.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'automacao_whatsapp.php' ? 'active' : '' ?>"><i class="fab fa-whatsapp fa-fw"></i> Automação Zap</a>
        <a href="config_whatsapp.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'config_whatsapp.php' ? 'active' : '' ?>"><i class="fas fa-cogs fa-fw"></i> Config. API Zap</a> 
            
        <div class="nav-group-title">Ferramentas</div>
        <a href="meus_links.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'meus_links.php' ? 'active' : '' ?>"><i class="fas fa-link fa-fw"></i> Central Links</a>
        <a href="gerenciar_mascara.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'gerenciar_mascara.php' ? 'active' : '' ?>"><i class="fas fa-mask fa-fw"></i> Máscaras URL</a>        
        <a href="config_mp_revenda.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'config_mp_revenda.php' ? 'active' : '' ?>"><i class="fas fa-wallet fa-fw"></i> Config. Pagamento</a>
        <a href="gerenciar_planos.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'gerenciar_planos.php' ? 'active' : '' ?>"><i class="fas fa-tags fa-fw"></i> Planos de Venda</a>
        <a href="gerenciar_email.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'gerenciar_email.php' ? 'active' : '' ?>"><i class="fas fa-envelope fa-fw"></i> SMTP Email</a>
        <a href="relatorio.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'relatorio.php' ? 'active' : '' ?>"><i class="fas fa-file-invoice-dollar fa-fw"></i> Relatório de Faturas</a>
        <a href="suporte.php" class="nav-link <?= basename($_SERVER['PHP_SELF']) == 'suporte.php' ? 'active' : '' ?>">
            <i class="fas fa-headset fa-fw"></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 <?= basename($_SERVER['PHP_SELF']) == 'enviar_circular.php' ? 'active' : '' ?>"><i class="fas fa-paper-plane fa-fw"></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 fa-fw"></i> Atualização do Painel
        </a>
        <?php endif; ?>
        
        <a href="sair.php" class="nav-link text-danger mt-4"><i class="fas fa-sign-out-alt fa-fw"></i> Sair</a>
    </div>
</nav>
