<div style="margin-bottom:20px">
  <h2 style="font-size:1.2rem;font-weight:700">🔥 Daftar Prioritas Bantuan</h2>
  <p class="text-muted text-sm"><?= e($ri['nama']) ?> · Diurutkan berdasarkan skor prioritas tertinggi</p>
</div>
<div class="card">
  <div class="card-body no-pad">
    <div class="table-wrap">
      <table>
        <thead><tr><th>Rank</th><th>Nama</th><th>Skor</th><th>Status</th><th>Penghasilan</th><th>Tanggungan</th><th>Bantuan Terakhir</th><th>Total</th><th>Aksi</th></tr></thead>
        <tbody>
          <?php foreach($data as $i=>$w): ?>
          <tr>
            <td>
              <div style="width:28px;height:28px;border-radius:50%;background:<?= $i<3?['#dc2626','#d97706','#0284c7'][$i]:'#e2e8f0' ?>;color:<?= $i<3?'#fff':'var(--clr-text)' ?>;display:flex;align-items:center;justify-content:center;font-weight:800;font-size:0.8rem"><?= $i+1 ?></div>
            </td>
            <td>
              <div style="font-weight:600"><?= e($w['nama']) ?></div>
              <?php if($w['is_lansia']): ?><span class="badge badge-orange" style="font-size:0.62rem">Lansia</span><?php endif; ?>
              <?php if($w['is_disabilitas']): ?><span class="badge badge-blue" style="font-size:0.62rem">Disabilitas</span><?php endif; ?>
            </td>
            <td>
              <div style="font-size:1.2rem;font-weight:800;color:<?= ['Tinggi'=>'#dc2626','Sedang'=>'#d97706','Rendah'=>'#16a34a'][$w['level_prioritas']]??'#6b7280' ?>"><?= $w['skor_prioritas'] ?></div>
              <?php $pc=['Tinggi'=>'badge-red','Sedang'=>'badge-yellow','Rendah'=>'badge-green']; ?>
              <span class="badge <?= $pc[$w['level_prioritas']]??'badge-gray' ?>" style="font-size:0.62rem"><?= $w['level_prioritas'] ?></span>
            </td>
            <td><?php $sc=['Miskin Ekstrem'=>'badge-red','Miskin'=>'badge-orange','Rentan Miskin'=>'badge-yellow']; ?>
              <span class="badge <?= $sc[$w['status_kemiskinan']]??'badge-gray' ?>"><?= e($w['status_kemiskinan']) ?></span></td>
            <td class="text-sm"><?= formatRupiah($w['penghasilan_bulanan']??0) ?>/bln</td>
            <td class="text-sm text-center"><?= $w['jumlah_tanggungan'] ?> orang</td>
            <td class="text-xs text-muted"><?= $w['bantuan_terakhir'] ? formatTanggal($w['bantuan_terakhir']) : '<span style="color:#dc2626;font-weight:600">Belum pernah</span>' ?></td>
            <td class="text-sm text-center"><?= number_format($w['jml_bantuan']) ?>×</td>
            <td>
              <a href="<?= APP_URL ?>/rumah-ibadah/warga/<?= $w['id'] ?>" class="btn btn-ghost btn-sm">Detail</a>
              <a href="<?= APP_URL ?>/rumah-ibadah/bantuan/tambah" class="btn btn-success btn-sm">📦 Bantu</a>
            </td>
          </tr>
          <?php endforeach; ?>
        </tbody>
      </table>
    </div>
    <?php if(empty($data)): ?>
    <div class="empty-state"><div class="empty-state-icon">👥</div><h3>Tidak ada warga binaan</h3></div>
    <?php endif; ?>
  </div>
</div>
