<!-- Sidebar -->
<style>
  .sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    width: 250px;
    height: calc(100vh - 60px);
    background: #212529;
    color: #fff;
    overflow-y: auto;
    z-index: 1000;
    padding-bottom: 20px;
  }
  .sidebar .nav-link {
    color: #adb5bd;
    padding: 1.
    0px 20px;
    margin: 4px 0;
    border-radius: 0 8px 8px 0;
  }
  .sidebar .nav-link:hover, .sidebar .nav-link.active {
    color: #fff;
    background: #343a40;
  }
  .sidebar .dropdown-menu {
    background: #343a40;
    border: none;
    border-radius: 0;
    min-width: 100%;
  }
  .sidebar .dropdown-item {
    color: #adb5bd;
    padding: 8px 20px;
  }
  .sidebar .dropdown-item:hover {
    color: #fff;
    background: #495057;
  }
  @media (max-width: 768px) {
    .sidebar {
      display: none;
    }
  }
</style>

<div class="sidebar">
  <hr class="text-secondary mx-3">

  <?php
  $user_role = $this->session->userdata('role');
  $user_nama = $this->session->userdata('nama_pegawai') ?? 'Pengguna';
  $unor_id   = $this->session->userdata('unor_id'); // Ambil dari session
  ?>

  <ul class="nav flex-column px-3">

    <!-- SUPERADMIN -->
    <?php if ($user_role === 'superadmin'): ?>
      <li class="nav-item">
        <a class="nav-link <?= $this->uri->segment(2) === 'dashboard' ? 'active' : '' ?>" 
           href="<?= base_url('dashboard') ?>">
          <i class="bi bi-speedometer2 me-2"></i>Dashboard
        </a>
      </li>
      <li class="nav-item">
        <a class="nav-link <?= $this->uri->segment(2) === 'daftar-pegawai' ? 'active' : '' ?>" 
           href="<?= base_url('daftar-pegawai') ?>">
          <i class="bi bi-people me-2"></i>Daftar Pegawai
        </a>
      </li>
      <li class="nav-item">
        <a class="nav-link <?= $this->uri->segment(2) === 'unor' ? 'active' : '' ?>" 
           href="<?= base_url('unor') ?>">
          <i class="bi bi-building me-2"></i>Daftar UNOR
        </a>
      </li>
      <li class="nav-item">
        <a class="nav-link <?= $this->uri->segment(2) === 'admin_group' ? 'active' : '' ?>" 
           href="<?= base_url('admin_group') ?>">
          <i class="bi bi-shield-lock me-2"></i>Manajemen Admin
        </a>
      </li>

      <!-- DIALOG KINERJA BARU (Superadmin) -->
      <li class="nav-item">
        <a class="nav-link <?= $this->uri->segment(2) === 'dialog_kinerja' ? 'active' : '' ?>" 
           href="<?= base_url('dialog_kinerja') ?>">
          <i class="bi bi-chat-square-text me-2"></i>Dialog Kinerja
        </a>
      </li>

      <li class="nav-item">
        <a class="nav-link <?= $this->uri->segment(2) === 'laporan' ? 'active' : '' ?>" 
           href="<?= base_url('laporan') ?>">
          <i class="bi bi-file-earmark-text me-2"></i>Laporan
        </a>
      </li>

    <!-- ADMIN OPD -->
    <?php elseif ($user_role === 'admin_opd'): ?>
      <li class="nav-item">
        <a class="nav-link <?= $this->uri->segment(2) === 'dashboard' ? 'active' : '' ?>" 
           href="<?= base_url('dashboard') ?>">
          <i class="bi bi-speedometer2 me-2"></i>Dashboard
        </a>
      </li>
      <li class="nav-item">
        <a class="nav-link <?= $this->uri->segment(2) === 'daftar-pegawai' ? 'active' : '' ?>" 
           href="<?= base_url('daftar-pegawai') ?>">
          <i class="bi bi-people me-2"></i>Daftar Pegawai
        </a>
      </li>

      <!-- DIALOG KINERJA BARU (Admin OPD) -->
      <li class="nav-item">
        <a class="nav-link <?= $this->uri->segment(2) === 'dialog_kinerja' ? 'active' : '' ?>" 
           href="<?= base_url('dialog_kinerja') ?>">
          <i class="bi bi-chat-square-text me-2"></i>Dialog Kinerja
        </a>
      </li>

      <li class="nav-item">
        <a class="nav-link <?= $this->uri->segment(2) === 'laporan' ? 'active' : '' ?>" 
           href="<?= base_url('laporan') ?>">
          <i class="bi bi-file-earmark-text me-2"></i>Laporan
        </a>
      </li>

    <!-- USER (ASN) -->
    <?php elseif ($user_role === 'user'): ?>
      <li class="nav-item">
        <a class="nav-link <?= $this->uri->segment(2) === 'dashboard' ? 'active' : '' ?>" 
           href="<?= base_url('dashboard') ?>">
          <i class="bi bi-speedometer2 me-2"></i>Dashboard
        </a>
      </li>

      <!-- DIALOG KINERJA BARU (User/ASN) -->
      <?php
      // Ambil id_peg dari session (pastikan diset saat login)
      $pegawai_id = $this->session->userdata('pegawai_id');
      if (!empty($pegawai_id)):
      ?>
        <li class="nav-item">
          <a class="nav-link <?= strpos($this->uri->uri_string(), 'dialog_kinerja') !== false ? 'active' : '' ?>" 
             href="<?= base_url("dialog_kinerja/template/{$pegawai_id}/1") ?>">
            <i class="bi bi-chat-square-text me-2"></i>Dialog Saya
          </a>
        </li>
      <?php endif; ?>

      <li class="nav-item">
        <a class="nav-link <?= $this->uri->segment(2) === 'laporan' ? 'active' : '' ?>" 
           href="<?= base_url('laporan') ?>">
          <i class="bi bi-file-earmark-text me-2"></i>Laporan
        </a>
      </li>
    <?php endif; ?>

  </ul>

  <!-- PROFIL & LOGOUT -->
  <div class="px-3 mt-4">
    <div class="dropdown">
      <a class="nav-link text-white d-flex align-items-center" href="#" role="button" data-bs-toggle="dropdown">
        <i class="bi bi-person-circle me-2"></i>
        <span class="d-none d-md-inline"><?= htmlspecialchars($user_nama, ENT_QUOTES, 'UTF-8') ?></span>
      </a>
      <ul class="dropdown-menu bg-dark text-white">
        <li><a class="dropdown-item text-white" href="<?= base_url('profil') ?>">Profil</a></li>
        <li><hr class="dropdown-divider bg-secondary"></li>
        <li><a class="dropdown-item text-danger" href="<?= base_url('auth/logout') ?>">Logout</a></li>
      </ul>
    </div>
  </div>
</div>