<div class="main-content">
  <div class="container-fluid" style="margin-top: 50px;">

    <!-- JUDUL DASHBOARD -->
    <div class="row mb-4">
      <div class="col-12">
        <h1><i class="bi bi-speedometer2 me-2"></i>Dashboard SIDIK</h1>
        <p>Selamat datang, <strong><?= htmlspecialchars($this->session->userdata('nama_pegawai')) ?></strong>!</p>
      </div>
    </div>

    <!-- STATISTIK UTAMA (1 BARIS) -->
    <div class="row mb-4">
      <!-- Total UNOR -->
      <div class="col-md-3">
        <div class="card text-center h-100">
          <div class="card-body d-flex flex-column justify-content-center">
            <h5>Total UNOR</h5>
            <h2 class="fw-bold"><?= $stats['total_unor'] ?></h2>
          </div>
        </div>
      </div>

      <!-- UNOR Mandiri -->
      <div class="col-md-3">
        <div class="card text-center h-100">
          <div class="card-body d-flex flex-column justify-content-center">
            <h5>UNOR Mandiri</h5>
            <h2 class="fw-bold"><?= $stats['unor_mandiri'] ?></h2>
          </div>
        </div>
      </div>

      <!-- Non-Mandiri -->
      <div class="col-md-3">
        <div class="card text-center h-100">
          <div class="card-body d-flex flex-column justify-content-center">
            <h5>Non-Mandiri</h5>
            <h2 class="fw-bold"><?= $stats['unor_non_mandiri'] ?></h2>
          </div>
        </div>
      </div>

      <!-- Total Pegawai -->
      <div class="col-md-3">
        <div class="card text-center h-100">
          <div class="card-body d-flex flex-column justify-content-center">
            <h5>Total Pegawai</h5>
            <h2 class="fw-bold"><?= $stats['total_pegawai'] ?></h2>
          </div>
        </div>
      </div>
    </div>

    <!-- DISTRIBUSI JABATAN (di bawah statistik utama) -->
    <div class="row mb-4">
      <div class="col-md-6">
        <div class="card">
          <div class="card-header bg-primary text-white">Distribusi Jenis Jabatan</div>
          <ul class="list-group list-group-flush">
            <li class="list-group-item d-flex justify-content-between">
              Struktural
              <span class="badge bg-primary"><?= $stats['jabatan_struktural'] ?></span>
            </li>
            <li class="list-group-item d-flex justify-content-between">
              Fungsional
              <span class="badge bg-success"><?= $stats['jabatan_fungsional'] ?></span>
            </li>
          </ul>
        </div>
      </div>
    </div>

    <!-- PEGAWAI PER UNOR INDUK (TABEL) -->
    <div class="row mb-4">
      <div class="col-12">
        <div class="card">
          <div class="card-header bg-info text-white">Pegawai per UNOR Induk</div>
          <div class="card-body">
            <div class="table-responsive">
              <table class="table table-bordered">
                <thead>
                  <tr>
                    <th>No</th>
                    <th>UNOR Induk</th>
                    <th>Jumlah Pegawai</th>
                  </tr>
                </thead>
                <tbody>
                  <?php $no = 1; foreach ($stats['pegawai_per_unor_induk'] as $row): ?>
                    <tr>
                      <td><?= $no++ ?></td>
                      <td><?= htmlspecialchars($row->unor_induk_nama) ?></td>
                      <td><?= $row->total ?></td>
                    </tr>
                  <?php endforeach; ?>
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- DIALOG KINERJA PER UNOR INDUK (TABEL) -->
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card-header bg-warning text-dark">Status Dialog Kinerja per UNOR Induk</div>
          <div class="card-body">
            <div class="table-responsive">
              <table class="table table-bordered">
                <thead>
                  <tr>
                    <th>UNOR Induk</th>
                    <th>Template</th>
                    <th>Draft</th>
                    <th>On Proses</th>
                    <th>Selesai</th>
                  </tr>
                </thead>
                <tbody>
                  <?php
                  $current_unor = '';
                  foreach ($stats['dialog_per_unor_induk'] as $row):
                    if ($current_unor != $row->unor_induk_nama) {
                      $current_unor = $row->unor_induk_nama;
                      echo "<tr><td rowspan='5' style='vertical-align: middle;'><strong>" . htmlspecialchars($row->unor_induk_nama) . "</strong></td>";
                    } else {
                      echo "<tr>";
                    }
                    echo "
                      <td>Template {$row->template}</td>
                      <td>" . ($row->status == 'draft' ? $row->total : 0) . "</td>
                      <td>" . ($row->status == 'on_proses' ? $row->total : 0) . "</td>
                      <td>" . ($row->status == 'selesai' ? $row->total : 0) . "</td>
                    </tr>";
                  endforeach;
                  ?>
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>

  </div>
</div>