<aside class="main-sidebar sidebar-light elevation-4" style="background:#eef3f8;">
  <!-- Logo -->
  <a href="dashboard.php" class="brand-link text-center bg-white border-bottom">
    <img src="../img/logo.png" alt="YönetimOnline" style="width:170px;height:auto;">
  </a>

  <!-- Sidebar -->
  <div class="sidebar yo-sidebar" style="overflow-y:auto; visibility:hidden;">
    <nav class="mt-3">
      <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">

        <!-- SUPER ADMIN -->
        <?php if (($_SESSION['rol'] ?? '') === 'superadmin'): ?>
          <li class="nav-item"><a href="siteler.php" class="nav-link text-dark"><i class="nav-icon fas fa-building" style="color:#1e60d4;"></i><p>Site Bilgi</p></a></li>
          <li class="nav-item"><a href="dashboard.php" class="nav-link text-dark"><i class="nav-icon fas fa-gauge-high" style="color:#1e60d4;"></i><p>Kontrol Paneli</p></a></li>
          <li class="nav-item"><a href="gelir_gider.php" class="nav-link text-dark"><i class="nav-icon fas fa-money-bill-trend-up" style="color:#1e60d4;"></i><p>Gelir - Gider</p></a></li>
          <li class="nav-item"><a href="toplu_sms.php" class="nav-link text-dark"><i class="nav-icon fas fa-comment-sms" style="color:#1e60d4;"></i><p>Toplu SMS</p></a></li>
          <li class="nav-item"><a href="anlasmali_firmalar.php" class="nav-link text-dark"><i class="nav-icon fas fa-handshake-simple" style="color:#1e60d4;"></i><p>Anlaşmalı Firmalar</p></a></li>
          <li class="nav-item"><a href="ozel_teklifler.php" class="nav-link text-dark"><i class="nav-icon fas fa-gift" style="color:#1e60d4;"></i><p>Özel Teklifler</p></a></li>
        <?php endif; ?>

        <!-- YÖNETİCİ -->
        <?php if (($_SESSION['rol'] ?? '') === 'yonetici'): ?>
          <li class="nav-item"><a href="dashboard.php" class="nav-link text-dark"><i class="nav-icon fas fa-gauge-high" style="color:#1e60d4;"></i><p>Kontrol Paneli</p></a></li>
          <li class="nav-item"><a href="alt_kullanici.php" class="nav-link text-dark"><i class="nav-icon fas fa-user-gear" style="color:#1e60d4;"></i><p>Alt Kullanıcı</p></a></li>
          <li class="nav-item"><a href="uye_kayit.php" class="nav-link text-dark"><i class="nav-icon fas fa-user-plus" style="color:#1e60d4;"></i><p>Üye Kayıt</p></a></li>
          <li class="nav-item"><a href="uye_detay.php" class="nav-link text-dark"><i class="nav-icon fas fa-users" style="color:#1e60d4;"></i><p>Üye Detay</p></a></li>
          <li class="nav-item"><a href="aidat_yonetimi.php" class="nav-link text-dark"><i class="nav-icon fas fa-file-invoice-dollar" style="color:#1e60d4;"></i><p>Aidat Yönetimi</p></a></li>
          <li class="nav-item"><a href="gelir_gider.php" class="nav-link text-dark"><i class="nav-icon fas fa-right-left" style="color:#1e60d4;"></i><p>Gelir - Gider</p></a></li>
          <li class="nav-item"><a href="isletme_defteri.php" class="nav-link text-dark"><i class="nav-icon fas fa-right-left" style="color:#1e60d4;"></i><p>İşletme Defteri</p></a></li>
          <li class="nav-item"><a href="demirbaslar.php" class="nav-link text-dark"><i class="nav-icon fas fa-boxes-stacked" style="color:#1e60d4;"></i><p>Demirbaşlar</p></a></li>
          <li class="nav-item"><a href="ozel_grup.php" class="nav-link text-dark"><i class="nav-icon fas fa-user-group" style="color:#1e60d4;"></i><p>Grup Ödeme</p></a></li>
          <li class="nav-item"><a href="borc_defteri.php" class="nav-link text-dark"><i class="nav-icon fas fa-book" style="color:#1e60d4;"></i><p>Borç Defteri</p></a></li>
          <li class="nav-item"><a href="yillik_borc_defteri.php" class="nav-link text-dark"><i class="nav-icon fas fa-book" style="color:#1e60d4;"></i><p>Yıllık Borç Defteri</p></a></li>
          <li class="nav-item"><a href="tahsilat.php" class="nav-link text-dark"><i class="nav-icon fas fa-money-check-dollar" style="color:#1e60d4;"></i><p>Tahsilat</p></a></li>
          <li class="nav-item"><a href="toplu_sms.php" class="nav-link text-dark"><i class="nav-icon fas fa-comment-sms" style="color:#1e60d4;"></i><p>Toplu SMS</p></a></li>
          <li class="nav-item"><a href="whatsapp.php" class="nav-link text-dark"><i class="nav-icon fab fa-whatsapp" style="color:#1e60d4;"></i><p>Whatsapp</p></a></li>
          <li class="nav-item"><a href="anket.php" class="nav-link text-dark"><i class="nav-icon fas fa-square-poll-vertical" style="color:#1e60d4;"></i><p>Anket</p></a></li>
          <li class="nav-item"><a href="duyuru.php" class="nav-link text-dark"><i class="nav-icon fas fa-bullhorn" style="color:#1e60d4;"></i><p>Duyuru</p></a></li>
          <li class="nav-item"><a href="toplanti_salonu.php" class="nav-link text-dark"><i class="nav-icon fas fa-calendar-check" style="color:#1e60d4;"></i><p>Toplantı</p></a></li>
          <li class="nav-item"><a href="banka_hesap.php" class="nav-link text-dark"><i class="nav-icon fas fa-building-columns" style="color:#1e60d4;"></i><p>Banka Hesabı</p></a></li>
          <li class="nav-item"><a href="hesap_takip.php" class="nav-link text-dark"><i class="nav-icon fas fa-building-columns" style="color:#1e60d4;"></i><p>Hesap Takip</p></a></li>
          <li class="nav-item"><a href="rapor_merkezi.php" class="nav-link text-dark"><i class="nav-icon fas fa-chart-line" style="color:#1e60d4;"></i><p>Raporlar</p></a></li>
          <li class="nav-item"><a href="butce_hesap.php" class="nav-link text-dark"><i class="nav-icon fas fa-calculator" style="color:#1e60d4;"></i><p>Bütçe</p></a></li>
          <li class="nav-item"><a href="site_destek.php" class="nav-link text-dark"><i class="nav-icon fas fa-headset" style="color:#1e60d4;"></i><p>Destek</p></a></li>
          <li class="nav-item"><a href="icra_takip.php" class="nav-link text-dark"><i class="nav-icon fas fa-gavel" style="color:#1e60d4;"></i><p>İcra Takibi</p></a></li>
          <li class="nav-item"><a href="anlasmali_firmalar.php" class="nav-link text-dark"><i class="nav-icon fas fa-handshake-simple" style="color:#1e60d4;"></i><p>Anlaşmalı Firmalar</p></a></li>
          <li class="nav-item"><a href="ozel_teklifler.php" class="nav-link text-dark"><i class="nav-icon fas fa-gift" style="color:#1e60d4;"></i><p>Özel Teklifler</p></a></li>
          <li class="nav-item"><a href="guvenlik_takip.php" class="nav-link text-dark"><i class="nav-icon fas fa-shield-halved" style="color:#1e60d4;"></i><p>Güvenlik</p></a></li>
          <li class="nav-item"><a href="sayac_okuma.php" class="nav-link text-dark"><i class="nav-icon fas fa-gauge" style="color:#1e60d4;"></i><p>Sayaç</p></a></li>
          <li class="nav-item"><a href="plaka_sorgu.php" class="nav-link text-dark"><i class="nav-icon fas fa-car-side" style="color:#1e60d4;"></i><p>Plaka</p></a></li>
          <li class="nav-item"><a href="hatirlatmalar.php" class="nav-link text-dark"><i class="nav-icon fas fa-bell" style="color:#1e60d4;"></i><p>Hatırlatmalar</p></a></li>
          <li class="nav-item"><a href="calisan_bilgi.php" class="nav-link text-dark"><i class="nav-icon fas fa-user-tie" style="color:#1e60d4;"></i><p>Çalışanlar</p></a></li>
        <?php endif; ?>

        <!-- ÜYE -->
        <?php if (($_SESSION['rol'] ?? '') === 'uye'): ?>
          <li class="nav-item"><a href="dashboard.php" class="nav-link text-dark"><i class="nav-icon fas fa-home" style="color:#1e60d4;"></i><p>Kontrol Paneli</p></a></li>
          <li class="nav-item"><a href="anketler.php" class="nav-link text-dark"><i class="nav-icon fas fa-square-poll-vertical" style="color:#1e60d4;"></i><p>Anketler</p></a></li>
          <li class="nav-item"><a href="rapor_merkez.php" class="nav-link text-dark"><i class="nav-icon fas fa-file-lines" style="color:#1e60d4;"></i><p>Raporlar</p></a></li>
          <li class="nav-item"><a href="hesap_bilgi.php" class="nav-link text-dark"><i class="nav-icon fas fa-wallet" style="color:#1e60d4;"></i><p>Hesap</p></a></li>
          <li class="nav-item"><a href="destek.php" class="nav-link text-dark"><i class="nav-icon fas fa-life-ring" style="color:#1e60d4;"></i><p>Destek</p></a></li>
          <li class="nav-item"><a href="ozel_teklifler.php" class="nav-link text-dark"><i class="nav-icon fas fa-tags" style="color:#1e60d4;"></i><p>Özel Teklifler</p></a></li>
        <?php endif; ?>

        <!-- ALT KULLANICI -->
        <?php if (($_SESSION['rol'] ?? '') === 'alt_kullanici'): ?>
          <li class="nav-item"><a href="dashboard.php" class="nav-link text-dark"><i class="nav-icon fas fa-gauge-high" style="color:#1e60d4;"></i><p>Kontrol Paneli</p></a></li>
          <?php if (in_array('uye_kayit', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="uye_kayit.php" class="nav-link text-dark"><i class="nav-icon fas fa-user-plus" style="color:#1e60d4;"></i><p>Üye Kayıt</p></a></li>
          <?php endif; ?>
          <?php if (in_array('uye_detay', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="uye_detay.php" class="nav-link text-dark"><i class="nav-icon fas fa-users" style="color:#1e60d4;"></i><p>Üye Detay</p></a></li>
          <?php endif; ?>
          <?php if (in_array('aidat_yonetimi', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="aidat_yonetimi.php" class="nav-link text-dark"><i class="nav-icon fas fa-file-invoice-dollar" style="color:#1e60d4;"></i><p>Aidat Yönetimi</p></a></li>
          <?php endif; ?>
          <?php if (in_array('gelir_gider', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="gelir_gider.php" class="nav-link text-dark"><i class="nav-icon fas fa-right-left" style="color:#1e60d4;"></i><p>Gelir - Gider</p></a></li>
          <?php endif; ?>
          <?php if (in_array('demirbaslar', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="demirbaslar.php" class="nav-link text-dark"><i class="nav-icon fas fa-boxes-stacked" style="color:#1e60d4;"></i><p>Demirbaşlar</p></a></li>
          <?php endif; ?>
          <?php if (in_array('grup_odeme', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="ozel_grup.php" class="nav-link text-dark"><i class="nav-icon fas fa-user-group" style="color:#1e60d4;"></i><p>Grup Ödeme</p></a></li>
          <?php endif; ?>
          <?php if (in_array('tahsilat', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="tahsilat.php" class="nav-link text-dark"><i class="nav-icon fas fa-money-check-dollar" style="color:#1e60d4;"></i><p>Tahsilat</p></a></li>
          <?php endif; ?>
          <?php if (in_array('toplu_sms', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="toplu_sms.php" class="nav-link text-dark"><i class="nav-icon fas fa-comment-sms" style="color:#1e60d4;"></i><p>Toplu SMS</p></a></li>
          <?php endif; ?>
          <?php if (in_array('whatsapp', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="whatsapp.php" class="nav-link text-dark"><i class="nav-icon fab fa-whatsapp" style="color:#1e60d4;"></i><p>Whatsapp</p></a></li>
          <?php endif; ?>
          <?php if (in_array('anket', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="anket.php" class="nav-link text-dark"><i class="nav-icon fas fa-square-poll-vertical" style="color:#1e60d4;"></i><p>Anket</p></a></li>
          <?php endif; ?>
          <?php if (in_array('duyuru', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="duyuru.php" class="nav-link text-dark"><i class="nav-icon fas fa-bullhorn" style="color:#1e60d4;"></i><p>Duyuru</p></a></li>
          <?php endif; ?>
          <?php if (in_array('toplanti', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="toplanti_salonu.php" class="nav-link text-dark"><i class="nav-icon fas fa-calendar-check" style="color:#1e60d4;"></i><p>Toplantı</p></a></li>
          <?php endif; ?>
          <?php if (in_array('banka_hesabi', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="banka_hesap.php" class="nav-link text-dark"><i class="nav-icon fas fa-building-columns" style="color:#1e60d4;"></i><p>Banka Hesabı</p></a></li>
          <?php endif; ?>
          <?php if (in_array('raporlar', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="rapor_merkezi.php" class="nav-link text-dark"><i class="nav-icon fas fa-chart-line" style="color:#1e60d4;"></i><p>Raporlar</p></a></li>
          <?php endif; ?>
          <?php if (in_array('butce', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="butce_hesap.php" class="nav-link text-dark"><i class="nav-icon fas fa-calculator" style="color:#1e60d4;"></i><p>Bütçe</p></a></li>
          <?php endif; ?>
          <?php if (in_array('destek', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="site_destek.php" class="nav-link text-dark"><i class="nav-icon fas fa-headset" style="color:#1e60d4;"></i><p>Destek</p></a></li>
          <?php endif; ?>
          <?php if (in_array('icra_takibi', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="icra_takip.php" class="nav-link text-dark"><i class="nav-icon fas fa-gavel" style="color:#1e60d4;"></i><p>İcra Takibi</p></a></li>
          <?php endif; ?>
          <?php if (in_array('anlasmali_firmalar', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="anlasmali_firmalar.php" class="nav-link text-dark"><i class="nav-icon fas fa-handshake-simple" style="color:#1e60d4;"></i><p>Anlaşmalı Firmalar</p></a></li>
          <?php endif; ?>
          <?php if (in_array('ozel_teklifler', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="ozel_teklifler.php" class="nav-link text-dark"><i class="nav-icon fas fa-gift" style="color:#1e60d4;"></i><p>Özel Teklifler</p></a></li>
          <?php endif; ?>
          <?php if (in_array('guvenlik', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="guvenlik_takip.php" class="nav-link text-dark"><i class="nav-icon fas fa-shield-halved" style="color:#1e60d4;"></i><p>Güvenlik</p></a></li>
          <?php endif; ?>
          <?php if (in_array('sayac', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="sayac_okuma.php" class="nav-link text-dark"><i class="nav-icon fas fa-gauge" style="color:#1e60d4;"></i><p>Sayaç</p></a></li>
          <?php endif; ?>
          <?php if (in_array('plaka', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="plaka_sorgu.php" class="nav-link text-dark"><i class="nav-icon fas fa-car-side" style="color:#1e60d4;"></i><p>Plaka</p></a></li>
          <?php endif; ?>
          <?php if (in_array('hatirlatmalar', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="hatirlatmalar.php" class="nav-link text-dark"><i class="nav-icon fas fa-bell" style="color:#1e60d4;"></i><p>Hatırlatmalar</p></a></li>
          <?php endif; ?>
          <?php if (in_array('calisanlar', $_SESSION['yetkiler'] ?? [])): ?>
            <li class="nav-item"><a href="calisan_bilgi.php" class="nav-link text-dark"><i class="nav-icon fas fa-user-tie" style="color:#1e60d4;"></i><p>Çalışanlar</p></a></li>
          <?php endif; ?>
        <?php endif; ?>

        <!-- ÇIKIŞ -->
        <li class="nav-item mt-5">
          <a href="logout.php" class="nav-link text-danger">
            <i class="nav-icon fas fa-right-from-bracket"></i>
            <p>Çıkış Yap</p>
          </a>
        </li>
      </ul>
    </nav>
  </div>

  <!-- SCROLL KORUMA -->
  <script>
    // Scroll kaydet
    window.addEventListener('beforeunload', function () {
      var sb = document.querySelector('.yo-sidebar');
      if (sb) sessionStorage.setItem('yo_sidebar_scroll', sb.scrollTop);
    });
    // DOM gelir gelmez uygula
    (function () {
      var sb = document.querySelector('.yo-sidebar');
      if (!sb) return;
      var pos = sessionStorage.getItem('yo_sidebar_scroll');
      if (pos !== null) {
        sb.scrollTop = parseInt(pos, 10);
      }
      sb.style.visibility = 'visible';
    })();
  </script>
</aside>