<?php
/**
 * Sidebar Dinamis — Permission-Aware
 *
 * Menggantikan sidebar hardcoded.
 * Menu tampil/sembunyi berdasarkan tabel menu_permissions di database.
 *
 * Cara pakai: sama seperti sidebar lama, include di template.
 */

$CI  =& get_instance();
$seg1 = $CI->uri->segment(1);
$seg2 = $CI->uri->segment(2);

// Load permission map sekali saja untuk semua menu
$CI->load->model('Menu_model');
$role = $CI->session->userdata('role');
$pmap = $CI->Menu_model->get_permissions_for_role($role);

// Helper: cek apakah slug bisa dilihat
if (!function_exists('_can_see')) {
    function _can_see($pmap, $slug) {
        return isset($pmap[$slug]) && $pmap[$slug]->can_view;
    }
}

if (!function_exists('_seg_in_arr')) {
    function _seg_in_arr($seg1, $arr) {
        return in_array($seg1, $arr);
    }
}
?>
<style>
/* ===== SIDEBAR PREMIUM COMPACT ===== */
.sidebar {
    width: 220px;
    min-height: 100vh;
    background: linear-gradient(135deg, #0d9488 0%, #115e59 100%);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1000;
    overflow-y: auto; overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.15) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }
.sidebar-brand { padding: 20px 16px 16px; text-align: center; border-bottom: 1px solid rgba(255,255,255,.1); flex-shrink: 0; }
.sidebar-brand .brand-icon { width: 42px; height: 42px; background: rgba(255,255,255,.18); border-radius: 10px; display: flex; align-items: center; justify-content: center; margin: 0 auto 8px; }
.sidebar-brand .brand-icon i { font-size: 1.2rem; color: #fff; }
.sidebar-brand h4 { font-size: .9rem; font-weight: 800; color: #fff; margin: 0; letter-spacing: .06em; text-transform: uppercase; }
.sidebar-brand small { font-size: .68rem; color: rgba(255,255,255,.55); font-weight: 500; }
.sidebar-menu { padding: 8px 0 16px; flex: 1; }
.sidebar-section-label { font-size: .62rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,255,255,.35); padding: 10px 18px 4px; }
.sidebar .nav-item { margin: 1px 8px; }
.sidebar .nav-link { display: flex; align-items: center; gap: 9px; padding: 8px 12px; border-radius: 8px; color: rgba(255,255,255,.75); font-size: .82rem; font-weight: 500; text-decoration: none; transition: all .15s ease; position: relative; white-space: nowrap; }
.sidebar .nav-link i { font-size: .95rem; width: 18px; text-align: center; flex-shrink: 0; opacity: .85; }
.sidebar .nav-link span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.1); color: #fff; }
.sidebar .nav-link:hover i { opacity: 1; }
.sidebar .nav-link.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 700; }
.sidebar .nav-link.active i { opacity: 1; }
.sidebar .nav-link.active::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 3px; height: 60%; background: #a7f3d0; border-radius: 0 2px 2px 0; }
.sidebar .nav-link.logout-link { color: rgba(255,120,120,.8); margin-top: 4px; }
.sidebar .nav-link.logout-link:hover { background: rgba(239,68,68,.15); color: #fca5a5; }
.sidebar .nav-link .sb-badge { font-size: .62rem; font-weight: 700; padding: 2px 6px; border-radius: 999px; line-height: 1.2; flex-shrink: 0; }
.sb-badge-danger { background: #ef4444; color: #fff; }
.sb-badge-info   { background: rgba(255,255,255,.2); color: rgba(255,255,255,.7); }
.sidebar .collapse .nav { padding: 2px 0 4px; }
.sidebar .collapse .nav-item { margin: 1px 0 1px 10px; }
.sidebar .collapse .nav-link { font-size: .79rem; padding: 6px 10px; border-radius: 7px; }
.sidebar .collapse .nav-link::before { display: none; }
.sidebar-divider { height: 1px; background: rgba(255,255,255,.08); margin: 6px 16px; }
.sidebar .nav-link .chevron { font-size: .65rem; color: rgba(255,255,255,.45); margin-left: auto; flex-shrink: 0; transition: transform .2s; }
.sidebar .nav-link[aria-expanded="true"] .chevron { transform: rotate(180deg); }
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); transition: transform .25s ease; box-shadow: none; }
    .sidebar.show { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.18); }
}
</style>

<nav class="sidebar" id="mainSidebar">

    <div class="sidebar-brand">
        <div class="brand-icon"><i class="bi bi-house-door-fill"></i></div>
        <h4>Auto RT</h4>
        <small>Solusi Manajemen RT Terintegrasi</small>
    </div>

    <div class="sidebar-menu">
        <ul class="nav flex-column">

            <!-- DASHBOARD (selalu tampil jika logged in) -->
            <li class="nav-item">
                <a class="nav-link <?= ($seg1 == 'dashboard' || $seg1 == '') ? 'active' : '' ?>"
                   href="<?= base_url('dashboard') ?>">
                    <i class="bi bi-speedometer2"></i><span>Dashboard</span>
                </a>
            </li>

            <div class="sidebar-divider"></div>

            <!-- ═══ KEPENDUDUKAN ═══ -->
            <?php
            $kep_segs = ['warga', 'kartu-keluarga'];
            $show_warga = _can_see($pmap,'warga');
            $show_kk    = _can_see($pmap,'kartu-keluarga');
            $show_pemilih = _can_see($pmap,'warga/pemilih');
            $show_kep = ($show_warga || $show_kk || $show_pemilih);
            ?>
            <?php if($show_kep): ?>
            <li class="nav-item">
                <a class="nav-link <?= _seg_in_arr($seg1,$kep_segs)?'active':'' ?>"
                   href="#menuKependudukan" data-bs-toggle="collapse"
                   aria-expanded="<?= _seg_in_arr($seg1,$kep_segs)?'true':'false' ?>">
                    <i class="bi bi-people-fill"></i><span>Kependudukan</span>
                    <i class="bi bi-chevron-down chevron"></i>
                </a>
                <div class="collapse <?= _seg_in_arr($seg1,$kep_segs)?'show':'' ?>" id="menuKependudukan">
                    <ul class="nav flex-column">
                        <?php if($show_warga): ?>
                        <li class="nav-item">
                            <a class="nav-link <?= ($seg1=='warga' && $seg2!='pemilih')?'active':'' ?>"
                               href="<?= base_url('warga') ?>">
                                <i class="bi bi-people"></i><span>Data Warga</span>
                            </a>
                        </li>
                        <?php endif; ?>
                        <?php if($show_kk): ?>
                        <li class="nav-item">
                            <a class="nav-link <?= $seg1=='kartu-keluarga'?'active':'' ?>"
                               href="<?= base_url('kartu-keluarga') ?>">
                                <i class="bi bi-house-door"></i><span>Kartu Keluarga</span>
                            </a>
                        </li>
                        <?php endif; ?>
                        <?php if($show_pemilih): ?>
                        <li class="nav-item">
                            <a class="nav-link <?= ($seg1=='warga'&&$seg2=='pemilih')?'active':'' ?>"
                               href="<?= base_url('warga/pemilih') ?>">
                                <i class="bi bi-person-vcard"></i><span>Pemilih Pemilu</span>
                            </a>
                        </li>
                        <?php endif; ?>
                    </ul>
                </div>
            </li>
            <?php endif; ?>

            <!-- ═══ KEUANGAN ═══ -->
            <?php
            $keu_segs = ['iuran','kas','tabungan','pinjaman','arisan'];
            $show_iuran    = _can_see($pmap,'iuran');
            $show_kas      = _can_see($pmap,'kas');
            $show_tabungan = _can_see($pmap,'tabungan');
            $show_pinjaman = _can_see($pmap,'pinjaman');
            $show_arisan   = _can_see($pmap,'arisan');
            $show_keu      = ($show_iuran||$show_kas||$show_tabungan||$show_pinjaman||$show_arisan);
            ?>
            <?php if($show_keu): ?>
            <li class="nav-item">
                <a class="nav-link <?= _seg_in_arr($seg1,$keu_segs)?'active':'' ?>"
                   href="#menuKeuangan" data-bs-toggle="collapse"
                   aria-expanded="<?= _seg_in_arr($seg1,$keu_segs)?'true':'false' ?>">
                    <i class="bi bi-cash-stack"></i><span>Keuangan</span>
                    <i class="bi bi-chevron-down chevron"></i>
                </a>
                <div class="collapse <?= _seg_in_arr($seg1,$keu_segs)?'show':'' ?>" id="menuKeuangan">
                    <ul class="nav flex-column">
                        <?php if($show_iuran): ?><li class="nav-item"><a class="nav-link <?=$seg1=='iuran'?'active':''?>" href="<?=base_url('iuran')?>"><i class="bi bi-receipt"></i><span><?=$role=='warga'?'Iuran Saya':'Iuran Warga'?></span></a></li><?php endif; ?>
                        <?php if($show_kas): ?><li class="nav-item"><a class="nav-link <?=$seg1=='kas'?'active':''?>" href="<?=base_url('kas')?>"><i class="bi bi-bank"></i><span>Kas RT</span><?php if($role=='warga'):?><span class="sb-badge sb-badge-info">View</span><?php endif;?></a></li><?php endif; ?>
                        <?php if($show_tabungan): ?><li class="nav-item"><a class="nav-link <?=$seg1=='tabungan'?'active':''?>" href="<?=base_url('tabungan')?>"><i class="bi bi-wallet2"></i><span><?=$role=='warga'?'Tabungan Saya':'Tabungan'?></span></a></li><?php endif; ?>
                        <?php if($show_pinjaman): ?><li class="nav-item"><a class="nav-link <?=$seg1=='pinjaman'?'active':''?>" href="<?=base_url('pinjaman')?>"><i class="bi bi-cash-coin"></i><span><?=$role=='warga'?'Pinjaman Saya':'Pinjaman'?></span></a></li><?php endif; ?>
                        <?php if($show_arisan): ?><li class="nav-item"><a class="nav-link <?=$seg1=='arisan'?'active':''?>" href="<?=base_url('arisan')?>"><i class="bi bi-gift-fill"></i><span>Arisan RT</span></a></li><?php endif; ?>
                    </ul>
                </div>
            </li>
            <?php endif; ?>

            <!-- ═══ INVENTARIS ═══ -->
            <?php
            $inv_segs = ['inventaris','peminjaman-inventaris'];
            $show_inv = (_can_see($pmap,'inventaris') || _can_see($pmap,'peminjaman-inventaris'));
            ?>
            <?php if($show_inv): ?>
            <li class="nav-item">
                <a class="nav-link <?= _seg_in_arr($seg1,$inv_segs)?'active':'' ?>"
                   href="#menuInventaris" data-bs-toggle="collapse"
                   aria-expanded="<?= _seg_in_arr($seg1,$inv_segs)?'true':'false' ?>">
                    <i class="bi bi-box-seam"></i><span>Inventaris</span>
                    <i class="bi bi-chevron-down chevron"></i>
                </a>
                <div class="collapse <?= _seg_in_arr($seg1,$inv_segs)?'show':'' ?>" id="menuInventaris">
                    <ul class="nav flex-column">
                        <?php if(_can_see($pmap,'inventaris')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='inventaris'?'active':''?>" href="<?=base_url('inventaris')?>"><i class="bi bi-grid-3x3-gap"></i><span>Data Barang</span></a></li><?php endif; ?>
                        <?php if(_can_see($pmap,'peminjaman-inventaris')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='peminjaman-inventaris'?'active':''?>" href="<?=base_url('peminjaman-inventaris')?>"><i class="bi bi-arrow-left-right"></i><span>Peminjaman</span></a></li><?php endif; ?>
                    </ul>
                </div>
            </li>
            <?php endif; ?>

            <!-- ═══ LAYANAN WARGA ═══ -->
            <?php
            $lay_segs = ['umkm','bansos','tamu','surat'];
            $show_lay = (_can_see($pmap,'umkm')||_can_see($pmap,'bansos')||_can_see($pmap,'tamu')||_can_see($pmap,'surat'));
            ?>
            <?php if($show_lay): ?>
            <li class="nav-item">
                <a class="nav-link <?= _seg_in_arr($seg1,$lay_segs)?'active':'' ?>"
                   href="#menuLayanan" data-bs-toggle="collapse"
                   aria-expanded="<?= _seg_in_arr($seg1,$lay_segs)?'true':'false' ?>">
                    <i class="bi bi-shop-window"></i><span>Layanan Warga</span>
                    <i class="bi bi-chevron-down chevron"></i>
                </a>
                <div class="collapse <?= _seg_in_arr($seg1,$lay_segs)?'show':'' ?>" id="menuLayanan">
                    <ul class="nav flex-column">
                        <?php if(_can_see($pmap,'umkm')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='umkm'?'active':''?>" href="<?=base_url('umkm')?>"><i class="bi bi-shop"></i><span>UMKM</span></a></li><?php endif; ?>
                        <?php if(_can_see($pmap,'bansos')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='bansos'?'active':''?>" href="<?=base_url('bansos')?>"><i class="bi bi-heart-pulse-fill"></i><span>Bantuan Sosial</span></a></li><?php endif; ?>
                        <?php if(_can_see($pmap,'tamu')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='tamu'?'active':''?>" href="<?=base_url('tamu')?>"><i class="bi bi-person-badge-fill"></i><span>E-Visitor</span><?php if($role=='warga'):?><span class="sb-badge sb-badge-info">View</span><?php endif;?></a></li><?php endif; ?>
                        <?php if(_can_see($pmap,'surat')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='surat'?'active':''?>" href="<?=base_url('surat')?>"><i class="bi bi-file-text-fill"></i><span><?=$role=='warga'?'Pengajuan Surat':'Surat Menyurat'?></span></a></li><?php endif; ?>
                    </ul>
                </div>
            </li>
            <?php endif; ?>

            <!-- ═══ KEGIATAN & INFO ═══ -->
            <?php
            $keg_segs = ['pengumuman','kalender','jadwal','notulen','kegiatan','struktur-rt','video','berita'];
            $show_keg = false;
            foreach($keg_segs as $_s) { if(_can_see($pmap,$_s)){$show_keg=true;break;} }
            ?>
            <?php if($show_keg): ?>
            <li class="nav-item">
                <a class="nav-link <?= _seg_in_arr($seg1,$keg_segs)?'active':'' ?>"
                   href="#menuKegiatan" data-bs-toggle="collapse"
                   aria-expanded="<?= _seg_in_arr($seg1,$keg_segs)?'true':'false' ?>">
                    <i class="bi bi-calendar3"></i><span>Kegiatan &amp; Info</span>
                    <i class="bi bi-chevron-down chevron"></i>
                </a>
                <div class="collapse <?= _seg_in_arr($seg1,$keg_segs)?'show':'' ?>" id="menuKegiatan">
                    <ul class="nav flex-column">
                        <?php if(_can_see($pmap,'pengumuman')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='pengumuman'?'active':''?>" href="<?=base_url('pengumuman')?>"><i class="bi bi-megaphone-fill"></i><span>Pengumuman</span></a></li><?php endif; ?>
                        <?php if(_can_see($pmap,'kalender')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='kalender'?'active':''?>" href="<?=base_url('kalender')?>"><i class="bi bi-calendar3"></i><span>Kalender</span></a></li><?php endif; ?>
                        <?php if(_can_see($pmap,'jadwal')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='jadwal'?'active':''?>" href="<?=base_url('jadwal')?>"><i class="bi bi-calendar-check"></i><span>Jadwal Kegiatan</span></a></li><?php endif; ?>
                        <?php if(_can_see($pmap,'kegiatan')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='kegiatan'?'active':''?>" href="<?=base_url('kegiatan')?>"><i class="bi bi-calendar-event-fill"></i><span>Kegiatan RT</span></a></li><?php endif; ?>
                        <?php if(_can_see($pmap,'notulen')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='notulen'?'active':''?>" href="<?=base_url('notulen')?>"><i class="bi bi-journal-text"></i><span>Notulen Rapat</span><?php if($role=='warga'):?><span class="sb-badge sb-badge-info">View</span><?php endif;?></a></li><?php endif; ?>
                        <?php if(_can_see($pmap,'struktur-rt')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='struktur-rt'?'active':''?>" href="<?=base_url('struktur-rt')?>"><i class="bi bi-diagram-3-fill"></i><span>Struktur RT</span></a></li><?php endif; ?>
                        <?php if(_can_see($pmap,'video')||_can_see($pmap,'berita')): ?>
                        <li class="nav-item">
                            <a class="nav-link <?= in_array($seg1,['video','berita'])?'active':'' ?>"
                               href="#menuMedia" data-bs-toggle="collapse"
                               aria-expanded="<?= in_array($seg1,['video','berita'])?'true':'false' ?>">
                                <i class="bi bi-play-circle-fill"></i><span>Media</span>
                                <i class="bi bi-chevron-down chevron"></i>
                            </a>
                            <div class="collapse <?= in_array($seg1,['video','berita'])?'show':'' ?>" id="menuMedia">
                                <ul class="nav flex-column">
                                    <?php if(_can_see($pmap,'video')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='video'?'active':''?>" href="<?=base_url('video')?>"><i class="bi bi-camera-video-fill"></i><span>Video</span></a></li><?php endif; ?>
                                    <?php if(_can_see($pmap,'berita')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='berita'?'active':''?>" href="<?=base_url('berita')?>"><i class="bi bi-newspaper"></i><span>Berita</span></a></li><?php endif; ?>
                                </ul>
                            </div>
                        </li>
                        <?php endif; ?>
                    </ul>
                </div>
            </li>
            <?php endif; ?>

            <!-- ═══ ASPIRASI & PARTISIPASI ═══ -->
            <?php
            $asp_segs = ['saran','pengaduan','polling'];
            $show_asp = (_can_see($pmap,'saran')||_can_see($pmap,'pengaduan')||_can_see($pmap,'polling'));
            $total_notif = 0;
            if($role==='admin'){
                if(isset($unread_saran) && $unread_saran>0) $total_notif += $unread_saran;
                if(isset($unread_pengaduan) && $unread_pengaduan>0) $total_notif += $unread_pengaduan;
            }
            ?>
            <?php if($show_asp): ?>
            <li class="nav-item">
                <a class="nav-link <?= _seg_in_arr($seg1,$asp_segs)?'active':'' ?>"
                   href="#menuAspirasi" data-bs-toggle="collapse"
                   aria-expanded="<?= _seg_in_arr($seg1,$asp_segs)?'true':'false' ?>">
                    <i class="bi bi-chat-dots-fill"></i><span>Aspirasi &amp; Partisipasi</span>
                    <?php if($total_notif>0): ?><span class="sb-badge sb-badge-danger"><?=$total_notif?></span><?php endif; ?>
                    <i class="bi bi-chevron-down chevron"></i>
                </a>
                <div class="collapse <?= _seg_in_arr($seg1,$asp_segs)?'show':'' ?>" id="menuAspirasi">
                    <ul class="nav flex-column">
                        <?php if(_can_see($pmap,'saran')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='saran'?'active':''?>" href="<?=base_url('saran')?>"><i class="bi bi-chat-dots-fill"></i><span>Saran &amp; Kritik</span><?php if($role==='admin'&&isset($unread_saran)&&$unread_saran>0):?><span class="sb-badge sb-badge-danger"><?=$unread_saran?></span><?php endif;?></a></li><?php endif; ?>
                        <?php if(_can_see($pmap,'pengaduan')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='pengaduan'?'active':''?>" href="<?=base_url('pengaduan')?>"><i class="bi bi-exclamation-circle-fill"></i><span>Pengaduan</span><?php if($role==='admin'&&isset($unread_pengaduan)&&$unread_pengaduan>0):?><span class="sb-badge sb-badge-danger"><?=$unread_pengaduan?></span><?php endif;?></a></li><?php endif; ?>
                        <?php if(_can_see($pmap,'polling')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='polling'?'active':''?>" href="<?=base_url('polling')?>"><i class="bi bi-bar-chart-fill"></i><span>Polling Warga</span></a></li><?php endif; ?>
                    </ul>
                </div>
            </li>
            <?php endif; ?>

            <div class="sidebar-divider" style="margin-top:8px;"></div>

            <!-- ═══ DATA MASTER ═══ -->
            <?php
            $master_segs = ['master-pendidikan','master-pekerjaan'];
            $show_master = (_can_see($pmap,'master-pendidikan')||_can_see($pmap,'master-pekerjaan'));
            ?>
            <?php if($show_master): ?>
            <li class="nav-item">
                <a class="nav-link <?= _seg_in_arr($seg1,$master_segs)?'active':'' ?>"
                   href="#menuMaster" data-bs-toggle="collapse"
                   aria-expanded="<?= _seg_in_arr($seg1,$master_segs)?'true':'false' ?>">
                    <i class="bi bi-database-fill-gear"></i><span>Data Master</span>
                    <i class="bi bi-chevron-down chevron"></i>
                </a>
                <div class="collapse <?= _seg_in_arr($seg1,$master_segs)?'show':'' ?>" id="menuMaster">
                    <ul class="nav flex-column">
                        <?php if(_can_see($pmap, 'master-pendidikan')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='master-pendidikan'?'active':''?>" href="<?=base_url('master-pendidikan')?>"><i class="bi bi-mortarboard-fill"></i><span>Pendidikan</span></a></li><?php endif; ?>
                        <?php if(_can_see($pmap, 'master-pekerjaan')): ?><li class="nav-item"><a class="nav-link <?=$seg1=='master-pekerjaan'?'active':''?>" href="<?=base_url('master-pekerjaan')?>"><i class="bi bi-briefcase-fill"></i><span>Pekerjaan</span></a></li><?php endif; ?>
                    </ul>
                </div>
            </li>
            <?php endif; ?>

            <div class="sidebar-divider" style="margin-top:8px;"></div>

            <!-- ═══ PENGATURAN ═══ -->
            <?php if($role==='admin'): ?>
            <?php $peng_segs = ['pengaturan','profil','reset']; ?>
            <li class="nav-item">
                <a class="nav-link <?= _seg_in_arr($seg1,$peng_segs)?'active':'' ?>"
                   href="#menuPengaturan" data-bs-toggle="collapse"
                   aria-expanded="<?= _seg_in_arr($seg1,$peng_segs)?'true':'false' ?>">
                    <i class="bi bi-gear-fill"></i><span>Pengaturan</span>
                    <i class="bi bi-chevron-down chevron"></i>
                </a>
                <div class="collapse <?= _seg_in_arr($seg1,$peng_segs)?'show':'' ?>" id="menuPengaturan">
                    <ul class="nav flex-column">
                        <li class="nav-item"><a class="nav-link <?=$seg1=='profil'?'active':''?>" href="<?=base_url('profil')?>"><i class="bi bi-person-circle"></i><span>Profil Saya</span></a></li>
                        <li class="nav-item"><a class="nav-link <?=$seg1=='pengaturan'?'active':''?>" href="<?=base_url('pengaturan')?>"><i class="bi bi-sliders"></i><span>Umum</span></a></li>
                        <?php if(_can_see($pmap, 'log-activity')): ?>
                        <li class="nav-item"><a class="nav-link <?=$seg1=='log-activity'?'active':''?>" href="<?=base_url('log-activity')?>"><i class="bi bi-clock-history"></i><span>Log Aktivitas</span></a></li>
                        <?php endif; ?>
                        <li class="nav-item"><a class="nav-link <?=$seg1=='menu-management'?'active':''?>" href="<?=base_url('menu-management')?>"><i class="bi bi-shield-lock-fill"></i><span>Menu &amp; Akses</span></a></li>
                        <li class="nav-item"><a class="nav-link <?=$seg1=='reset'?'active':''?>" href="<?=base_url('reset')?>"><i class="bi bi-exclamation-triangle-fill" style="color:#fca5a5;"></i><span>Reset</span></a></li>
                    </ul>
                </div>
            </li>
            <?php else: ?>
            <li class="nav-item">
                <a class="nav-link <?=$seg1=='profil'?'active':''?>" href="<?=base_url('profil')?>">
                    <i class="bi bi-person-circle"></i><span>Profil Saya</span>
                </a>
            </li>
            <?php endif; ?>

            <!-- Logout -->
            <li class="nav-item" style="margin-top:6px;">
                <a class="nav-link logout-link" href="<?= base_url('auth/logout') ?>">
                    <i class="bi bi-box-arrow-right"></i><span>Keluar</span>
                </a>
            </li>

        </ul>
    </div>
</nav>