<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<style>
:root{--t8:#0b5a52;--t7:#0b7a6e;--t6:#0d9488;--t5:#14b8a6;--t4:#2dd4bf;--t1:#ccfbf1;--t0:#f0fdfa;--a5:#fffbeb;--a4:#fef3c7;--a3:#fbbf24;--a2:#d97706;--r5:#ef4444;--r0:#fef2f2;--r1:#fee2e2;--g5:#10b981;--g0:#f0fdf4;--g1:#dcfce7;--b0:#eff6ff;--b1:#dbeafe;--b5:#3b82f6;--p0:#f5f3ff;--p1:#ede9fe;--p5:#8b5cf6;--s0:#f8fafc;--s1:#f1f5f9;--s2:#e2e8f0;--s4:#94a3b8;--s5:#64748b;--s7:#334155;--s9:#0f172a;--rad:14px;--rsm:9px;--rxs:6px;--sha:0 4px 24px rgba(13,148,136,0.10),0 1px 4px rgba(0,0,0,0.05);--shs:0 1px 3px rgba(0,0,0,.06),0 4px 20px rgba(0,0,0,.06);}
.wkm-hdr{display:flex;justify-content:space-between;align-items:flex-start;flex-wrap:wrap;gap:14px;margin-bottom:20px;}
.wkm-hdr-l h4{font-size:1.25rem;font-weight:800;color:var(--t8);margin:0 0 5px;display:flex;align-items:center;gap:11px;letter-spacing:-.3px;}
.wkm-hdr-l h4 .hi{width:40px;height:40px;border-radius:11px;background:linear-gradient(135deg,#d97706,#f59e0b);display:flex;align-items:center;justify-content:center;color:#fff;font-size:1.05rem;box-shadow:0 4px 12px rgba(217,119,6,0.32);flex-shrink:0;}
.wkm-bc{display:flex;align-items:center;gap:6px;font-size:0.77rem;color:var(--s4);padding-left:51px;}
.wkm-bc a{color:var(--t6);text-decoration:none;font-weight:600;}
.btn-add{display:inline-flex;align-items:center;gap:7px;padding:10px 22px;border-radius:50px;border:none;background:var(--a2);color:#fff;font-size:0.85rem;font-weight:700;text-decoration:none;box-shadow:0 3px 12px rgba(217,119,6,0.28);transition:all .2s;}
.btn-add:hover{background:#b45309;transform:translateY(-1px);color:#fff;}
.wkm-stats{display:grid;grid-template-columns:repeat(4,1fr);gap:12px;margin-bottom:20px;}
.wkm-stat{background:#fff;border-radius:var(--rsm);box-shadow:var(--shs);border:1.5px solid var(--s1);padding:14px 16px;display:flex;align-items:center;gap:12px;}
.bsi-ico{width:42px;height:42px;border-radius:10px;flex-shrink:0;display:flex;align-items:center;justify-content:center;font-size:1.2rem;}
.ic-a{background:var(--a5);color:var(--a2);} .ic-g{background:var(--g0);color:var(--g5);} .ic-r{background:var(--r0);color:var(--r5);} .ic-t{background:var(--t0);color:var(--t6);}
.sv{font-size:1.4rem;font-weight:800;color:var(--s9);line-height:1;} .sl{font-size:0.72rem;color:var(--s4);font-weight:600;margin-top:2px;}
.flash{display:flex;align-items:flex-start;gap:10px;border-radius:var(--rsm);padding:13px 16px;margin-bottom:18px;font-size:0.85rem;}
.fl-s{background:var(--t0);border-left:4px solid var(--t6);color:var(--t8);}
.fl-e{background:var(--r0);border-left:4px solid var(--r5);color:#7f1d1d;}
.flash .fc{margin-left:auto;cursor:pointer;background:none;border:none;color:inherit;opacity:.55;}
.wkm-fbar{display:flex;gap:8px;margin-bottom:16px;flex-wrap:wrap;align-items:center;}
.bs-sel{padding:7px 12px;border-radius:var(--rsm);border:1.5px solid var(--s2);font-size:0.82rem;color:var(--s7);background:#fff;cursor:pointer;transition:border-color .18s;}
.bs-sel:focus{border-color:var(--t5);outline:none;}
.bs-sw{position:relative;flex:1;min-width:200px;}
.bs-sw i{position:absolute;left:10px;top:50%;transform:translateY(-50%);color:var(--s4);pointer-events:none;font-size:0.85rem;}
.bs-srch{width:100%;padding:7px 12px 7px 32px;border-radius:var(--rsm);border:1.5px solid var(--s2);font-size:0.82rem;color:var(--s7);background:#fff;box-sizing:border-box;transition:border-color .18s;}
.bs-srch:focus{border-color:var(--t5);outline:none;}
.wkm-card{background:#fff;border-radius:var(--rad);box-shadow:var(--sha);border:1.5px solid var(--s1);overflow:hidden;margin-bottom:0;}
.wkm-ch{display:flex;align-items:center;justify-content:space-between;padding:15px 22px;border-bottom:1.5px solid var(--s1);background:var(--s0);flex-wrap:wrap;gap:8px;}
.wkm-ch h5{font-size:0.9rem;font-weight:700;color:var(--t8);margin:0;display:flex;align-items:center;gap:7px;}
.bt-wrap{overflow-x:auto;}
.bt{width:100%;border-collapse:collapse;min-width:760px;}
.bt thead tr{background:var(--s0);border-bottom:2px solid var(--s2);}
.bt thead th{padding:10px 14px;font-size:0.69rem;font-weight:700;text-transform:uppercase;letter-spacing:.6px;color:var(--s4);white-space:nowrap;}
.bt tbody tr{border-bottom:1px solid var(--s1);transition:background .15s;}
.bt tbody tr:hover{background:var(--t0);}
.bt tbody tr:last-child{border-bottom:none;}
.bt tbody td{padding:11px 14px;font-size:0.84rem;color:var(--s7);vertical-align:middle;}
.nc{font-weight:700;color:var(--s9);}
.nikc{font-size:0.73rem;color:var(--s4);font-family:monospace;}
/* status badges */
.sp{display:inline-flex;align-items:center;gap:4px;border-radius:50px;padding:3px 10px;font-size:0.69rem;font-weight:700;}
.sp-w{background:var(--a5);color:var(--a2);border:1px solid var(--a4);}
.sp-v{background:var(--b0);color:var(--b5);border:1px solid var(--b1);}
.sp-s{background:var(--g0);color:var(--g5);border:1px solid var(--g1);}
.sp-t{background:var(--r0);color:var(--r5);border:1px solid var(--r1);}
/* kondisi rumah */
.kr{display:inline-flex;align-items:center;gap:4px;border-radius:50px;padding:2px 9px;font-size:0.69rem;font-weight:700;border:1px solid;}
.kr-baik{background:var(--g0);color:var(--g5);border-color:var(--g1);}
.kr-sedang{background:var(--a5);color:var(--a2);border-color:var(--a4);}
.kr-buruk{background:var(--r0);color:var(--r5);border-color:var(--r1);}
.kr-sangat_buruk{background:#fdf2f8;color:#9d174d;border-color:#fbcfe8;}
.ab{display:flex;gap:4px;flex-wrap:wrap;}
.a-btn{display:inline-flex;align-items:center;gap:4px;padding:5px 9px;border-radius:var(--rxs);border:1.5px solid var(--s2);background:#fff;color:var(--s5);font-size:0.73rem;font-weight:600;text-decoration:none;transition:all .15s;cursor:pointer;}
.a-btn:hover{background:var(--s0);border-color:var(--s4);}
.a-btn.d{border-color:var(--r1);color:var(--r5);}
.a-btn.d:hover{background:var(--r0);}
.a-btn.g{border-color:var(--g1);color:var(--g5);}
.a-btn.g:hover{background:var(--g0);}
.a-btn.b{border-color:var(--b1);color:var(--b5);}
.a-btn.b:hover{background:var(--b0);}
.a-btn.p{border-color:var(--p1);color:var(--p5);}
.a-btn.p:hover{background:var(--p0);}
.empty-s{text-align:center;padding:56px 24px;}
.em-ico{width:72px;height:72px;border-radius:50%;background:var(--a5);display:flex;align-items:center;justify-content:center;margin:0 auto 16px;color:var(--a2);font-size:1.8rem;}
.empty-s h6{font-weight:700;color:var(--s7);margin-bottom:4px;}
.empty-s p{font-size:0.83rem;color:var(--s4);}
.privacy-notice{display:flex;align-items:flex-start;gap:10px;background:var(--b0);border-left:4px solid var(--b5);border-radius:var(--rsm);padding:12px 16px;margin-bottom:18px;font-size:0.83rem;color:#1e3a5f;}
/* mobile cards */
.bm-list{display:none;padding:12px;}
.bm-card{background:#fff;border:1.5px solid var(--s2);border-radius:var(--rsm);padding:14px;margin-bottom:10px;}
.btn-fab{display:none;position:fixed;bottom:24px;right:20px;width:56px;height:56px;border-radius:50%;background:linear-gradient(135deg,#d97706,#f59e0b);color:#fff;align-items:center;justify-content:center;font-size:1.4rem;text-decoration:none;box-shadow:0 6px 20px rgba(217,119,6,0.45);z-index:200;transition:all .2s;}
.btn-fab:hover{transform:scale(1.08);color:#fff;}
/* modal verifikasi */
.vf-overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,0.45);z-index:1050;align-items:center;justify-content:center;}
.vf-overlay.show{display:flex;}
.vf-box{background:#fff;border-radius:var(--rad);padding:26px;width:100%;max-width:440px;box-shadow:0 8px 32px rgba(0,0,0,0.18);}
.vf-box h6{font-weight:800;color:var(--s9);margin:0 0 14px;font-size:1rem;}
.vf-box label{font-size:0.8rem;font-weight:700;color:var(--s5);display:block;margin-bottom:4px;}
.vf-box select,.vf-box textarea{width:100%;padding:8px 12px;border-radius:var(--rsm);border:1.5px solid var(--s2);font-size:0.84rem;color:var(--s7);margin-bottom:12px;box-sizing:border-box;}
.vf-box select:focus,.vf-box textarea:focus{border-color:var(--t5);outline:none;}
.vf-acts{display:flex;gap:8px;justify-content:flex-end;margin-top:4px;}
.btn-v{padding:8px 20px;border-radius:50px;font-size:0.83rem;font-weight:700;border:none;cursor:pointer;transition:all .18s;}
.btn-v-c{background:var(--s1);color:var(--s5);}
.btn-v-s{background:var(--t6);color:#fff;}
.btn-v-s:hover{background:var(--t7);}
@media(max-width:767px){
  .wkm-hdr{flex-direction:column;align-items:flex-start;}
  .btn-add{display:none;}
  .btn-fab{display:flex !important;}
  .wkm-stats{grid-template-columns:repeat(2,1fr);}
  .bt-wrap{display:none;}
  .bm-list{display:block;}
}
@media(min-width:768px){.btn-fab{display:none !important;}}
</style>

<div class="pg-wrapper">

<!-- Header -->
<div class="wkm-hdr">
  <div class="wkm-hdr-l">
    <h4>
      <span class="hi"><i class="bi bi-house-heart-fill"></i></span>
      Warga Kurang Mampu
    </h4>
    <div class="wkm-bc">
      <a href="<?php echo base_url('dashboard'); ?>">Dashboard</a>
      <span style="color:var(--s2);">/</span>
      <a href="<?php echo base_url('bansos'); ?>">Bantuan Sosial</a>
      <span style="color:var(--s2);">/</span>
      <span>Warga Kurang Mampu</span>
    </div>
  </div>
  <a href="<?php echo base_url('warga_kurang_mampu/tambah'); ?>" class="btn-add">
    <i class="bi bi-plus-circle"></i> Ajukan Data
  </a>
</div>

<!-- Flash -->
<?php if($this->session->flashdata('success')):?>
<div class="flash fl-s" id="flashMsg"><i class="bi bi-check-circle-fill"></i><span><?php echo $this->session->flashdata('success');?></span><button class="fc" onclick="this.parentElement.remove()">✕</button></div>
<?php endif;?>
<?php if($this->session->flashdata('error')):?>
<div class="flash fl-e" id="flashMsg"><i class="bi bi-x-circle-fill"></i><span><?php echo $this->session->flashdata('error');?></span><button class="fc" onclick="this.parentElement.remove()">✕</button></div>
<?php endif;?>

<!-- Privacy notice untuk non-admin -->
<?php if(!$is_admin):?>
<div class="privacy-notice">
  <i class="bi bi-shield-lock-fill"></i>
  <div><strong>Data Pribadi</strong> — Halaman ini hanya menampilkan data pengajuan milik Anda. Informasi bersifat <strong>privasi</strong>.</div>
</div>
<?php endif;?>

<!-- Statistik (admin only) -->
<?php if($is_admin):?>
<div class="wkm-stats">
  <div class="wkm-stat"><div class="bsi-ico ic-a"><i class="bi bi-people-fill"></i></div><div><div class="sv"><?php echo $total_all??0;?></div><div class="sl">Total Pengajuan</div></div></div>
  <div class="wkm-stat"><div class="bsi-ico" style="background:var(--a5);color:var(--a2);"><i class="bi bi-hourglass-split"></i></div><div><div class="sv"><?php echo $total_menunggu??0;?></div><div class="sl">Menunggu</div></div></div>
  <div class="wkm-stat"><div class="bsi-ico ic-g"><i class="bi bi-check-circle-fill"></i></div><div><div class="sv"><?php echo $total_disetujui??0;?></div><div class="sl">Disetujui</div></div></div>
  <div class="wkm-stat"><div class="bsi-ico ic-r"><i class="bi bi-x-circle-fill"></i></div><div><div class="sv"><?php echo $total_ditolak??0;?></div><div class="sl">Ditolak</div></div></div>
</div>
<?php endif;?>

<!-- Filter bar (admin) -->
<?php if($is_admin):?>
<div class="wkm-fbar">
  <form method="get" action="<?php echo base_url('warga_kurang_mampu');?>" style="display:contents;">
    <select name="status" class="bs-sel" onchange="this.form.submit()">
      <option value="">Semua Status</option>
      <option value="menunggu"    <?php echo $this->input->get('status')=='menunggu'   ?'selected':'';?>>Menunggu</option>
      <option value="diverifikasi"<?php echo $this->input->get('status')=='diverifikasi'?'selected':'';?>>Diverifikasi</option>
      <option value="disetujui"   <?php echo $this->input->get('status')=='disetujui'  ?'selected':'';?>>Disetujui</option>
      <option value="ditolak"     <?php echo $this->input->get('status')=='ditolak'    ?'selected':'';?>>Ditolak</option>
    </select>
    <select name="tahun" class="bs-sel" onchange="this.form.submit()">
      <option value="">Semua Tahun</option>
      <?php for($y=date('Y');$y>=2020;$y--):?>
      <option value="<?php echo $y;?>" <?php echo $this->input->get('tahun')==$y?'selected':'';?>><?php echo $y;?></option>
      <?php endfor;?>
    </select>
    <div class="bs-sw"><i class="bi bi-search"></i><input type="text" name="q" class="bs-srch" placeholder="Cari nama / NIK..." value="<?php echo htmlspecialchars($this->input->get('q')??'');?>"></div>
    <button type="submit" class="a-btn"><i class="bi bi-funnel"></i> Filter</button>
    <?php if($this->input->get('status')||$this->input->get('q')||$this->input->get('tahun')):?>
    <a href="<?php echo base_url('warga_kurang_mampu');?>" class="a-btn"><i class="bi bi-x-circle"></i> Reset</a>
    <?php endif;?>
  </form>
</div>
<?php endif;?>

<!-- Tabel utama -->
<div class="wkm-card">
  <div class="wkm-ch">
    <h5><i class="bi bi-house-heart" style="color:var(--a2);"></i><?php echo $is_admin?'Daftar Pengajuan Warga Kurang Mampu':'Pengajuan Saya';?></h5>
    <span style="font-size:0.78rem;color:var(--s4);"><i class="bi bi-database"></i> <?php echo count($list??[]);?> data</span>
  </div>

  <?php
  $kr_label = ['baik'=>'Baik','sedang'=>'Sedang','buruk'=>'Buruk','sangat_buruk'=>'Sangat Buruk'];
  $sp_map   = ['menunggu'=>['sp-w','bi-hourglass-split','Menunggu'],'diverifikasi'=>['sp-v','bi-shield-check','Diverifikasi'],'disetujui'=>['sp-s','bi-check-circle-fill','Disetujui'],'ditolak'=>['sp-t','bi-x-circle-fill','Ditolak']];
  ?>

  <?php if(empty($list)):?>
  <div class="empty-s">
    <div class="em-ico"><i class="bi bi-house-heart"></i></div>
    <h6><?php echo $is_admin?'Belum Ada Data Pengajuan':'Belum Ada Pengajuan';?></h6>
    <p><?php echo $is_admin?'Belum ada warga yang mengajukan data kurang mampu.':'Anda belum mengajukan data. Klik tombol "Ajukan Data" untuk memulai.';?></p>
  </div>
  <?php else:?>

  <!-- Desktop Table -->
  <div class="bt-wrap">
    <table class="bt">
      <thead><tr>
        <th>#</th>
        <?php if($is_admin):?><th>Nama Warga</th><th>NIK / No. KK</th><?php endif;?>
        <th>Penghasilan/Bln</th>
        <th>Tanggungan</th>
        <th>Kondisi Rumah</th>
        <th>Tgl Pengajuan</th>
        <th>Status</th>
        <th>Foto</th>
        <th>Aksi</th>
      </tr></thead>
      <tbody>
      <?php $no=1; foreach($list as $r):
        $sp = $sp_map[$r->status_pengajuan] ?? ['sp-w','bi-circle','–'];
        $fcount = count(json_decode($r->foto_rumah??'[]',true)?:[]);
        $kr_key = str_replace(' ','_', strtolower($r->kondisi_rumah??''));
      ?>
      <tr>
        <td><?php echo $no++;?></td>
        <?php if($is_admin):?>
        <td>
          <div class="nc"><?php echo htmlspecialchars($r->nama_lengkap??'-');?></div>
          <div class="nikc"><?php echo htmlspecialchars($r->no_kk??'-');?></div>
        </td>
        <td><div class="nikc"><?php echo htmlspecialchars($r->nik??'-');?></div></td>
        <?php endif;?>
        <td><strong style="color:var(--t7);">Rp <?php echo number_format($r->penghasilan_bulan,0,',','.');?></strong></td>
        <td style="text-align:center;"><?php echo (int)$r->jml_tanggungan;?> orang</td>
        <td><span class="kr kr-<?php echo $kr_key;?>"><?php echo $kr_label[$kr_key]??ucfirst($r->kondisi_rumah??'-');?></span></td>
        <td style="font-size:0.79rem;"><?php echo date('d M Y', strtotime($r->tgl_pengajuan));?></td>
        <td><span class="sp <?php echo $sp[0];?>"><i class="bi <?php echo $sp[1];?>" style="font-size:0.62rem;"></i><?php echo $sp[2];?></span></td>
        <td>
          <?php if($fcount > 0):?>
          <span style="font-size:0.76rem;color:var(--t7);font-weight:700;"><i class="bi bi-images"></i> <?php echo $fcount;?> foto</span>
          <?php else:?>
          <span style="font-size:0.74rem;color:var(--s4);">–</span>
          <?php endif;?>
        </td>
        <td>
          <div class="ab">
            <a href="<?php echo base_url('warga_kurang_mampu/detail/'.$r->id);?>" class="a-btn b" title="Detail"><i class="bi bi-eye"></i></a>
            <a href="<?php echo base_url('warga_kurang_mampu/cetak/'.$r->id);?>" class="a-btn g" title="Cetak" target="_blank"><i class="bi bi-printer"></i></a>
            <?php if($fcount>0):?>
            <a href="<?php echo base_url('warga_kurang_mampu/download_foto/'.$r->id);?>" class="a-btn p" title="Download Foto"><i class="bi bi-download"></i></a>
            <?php endif;?>
            <?php if($is_admin || $r->status_pengajuan==='menunggu'):?>
            <a href="<?php echo base_url('warga_kurang_mampu/edit/'.$r->id);?>" class="a-btn" title="Edit"><i class="bi bi-pencil"></i></a>
            <?php endif;?>
            <?php if($is_admin):?>
            <button class="a-btn" title="Verifikasi" onclick="openVerif(<?php echo $r->id;?>,'<?php echo $r->status_pengajuan;?>','<?php echo htmlspecialchars(addslashes($r->catatan_verifikasi??''));?>')"><i class="bi bi-shield-check"></i></button>
            <a href="<?php echo base_url('warga_kurang_mampu/hapus/'.$r->id);?>" onclick="return confirm('Hapus data pengajuan ini?')" class="a-btn d" title="Hapus"><i class="bi bi-trash"></i></a>
            <?php endif;?>
          </div>
        </td>
      </tr>
      <?php endforeach;?>
      </tbody>
    </table>
  </div>

  <!-- Mobile Cards -->
  <div class="bm-list">
    <?php foreach($list as $r):
      $sp = $sp_map[$r->status_pengajuan] ?? ['sp-w','bi-circle','–'];
      $fcount = count(json_decode($r->foto_rumah??'[]',true)?:[]);
      $kr_key = str_replace(' ','_', strtolower($r->kondisi_rumah??''));
    ?>
    <div class="bm-card">
      <?php if($is_admin):?>
      <div style="font-weight:700;font-size:0.88rem;color:var(--s9);"><?php echo htmlspecialchars($r->nama_lengkap??'-');?></div>
      <div class="nikc" style="margin-bottom:6px;"><?php echo htmlspecialchars($r->nik??'-');?></div>
      <?php endif;?>
      <div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:8px;">
        <strong style="color:var(--t7);font-size:0.9rem;">Rp <?php echo number_format($r->penghasilan_bulan,0,',','.');?>/bln</strong>
        <span class="sp <?php echo $sp[0];?>"><i class="bi <?php echo $sp[1];?>" style="font-size:0.62rem;"></i><?php echo $sp[2];?></span>
        <span class="kr kr-<?php echo $kr_key;?>"><?php echo $kr_label[$kr_key]??ucfirst($r->kondisi_rumah??'-');?></span>
      </div>
      <div style="font-size:0.76rem;color:var(--s5);margin-bottom:4px;"><i class="bi bi-people me-1"></i>Tanggungan: <strong><?php echo (int)$r->jml_tanggungan;?></strong> orang &nbsp;•&nbsp; <i class="bi bi-calendar3 me-1"></i><?php echo date('d M Y', strtotime($r->tgl_pengajuan));?></div>
      <?php if($fcount>0):?><div style="font-size:0.74rem;color:var(--t7);margin-bottom:8px;"><i class="bi bi-images me-1"></i><?php echo $fcount;?> foto rumah</div><?php endif;?>
      <div style="display:flex;gap:6px;flex-wrap:wrap;margin-top:8px;">
        <a href="<?php echo base_url('warga_kurang_mampu/detail/'.$r->id);?>" class="a-btn b" style="flex:1;justify-content:center;"><i class="bi bi-eye"></i> Detail</a>
        <a href="<?php echo base_url('warga_kurang_mampu/cetak/'.$r->id);?>" class="a-btn g" style="flex:1;justify-content:center;" target="_blank"><i class="bi bi-printer"></i> Cetak</a>
        <?php if($fcount>0):?>
        <a href="<?php echo base_url('warga_kurang_mampu/download_foto/'.$r->id);?>" class="a-btn p" style="flex:1;justify-content:center;"><i class="bi bi-download"></i> Foto</a>
        <?php endif;?>
        <?php if($is_admin || $r->status_pengajuan==='menunggu'):?>
        <a href="<?php echo base_url('warga_kurang_mampu/edit/'.$r->id);?>" class="a-btn" style="flex:1;justify-content:center;"><i class="bi bi-pencil"></i> Edit</a>
        <?php endif;?>
        <?php if($is_admin):?>
        <button class="a-btn" style="flex:1;justify-content:center;" onclick="openVerif(<?php echo $r->id;?>,'<?php echo $r->status_pengajuan;?>','<?php echo htmlspecialchars(addslashes($r->catatan_verifikasi??''));?>')"><i class="bi bi-shield-check"></i> Verif</button>
        <a href="<?php echo base_url('warga_kurang_mampu/hapus/'.$r->id);?>" onclick="return confirm('Hapus?')" class="a-btn d" style="flex:1;justify-content:center;"><i class="bi bi-trash"></i></a>
        <?php endif;?>
      </div>
    </div>
    <?php endforeach;?>
  </div>

  <?php endif;?>
</div>

</div><!-- /pg-wrapper -->

<!-- FAB mobile -->
<a href="<?php echo base_url('warga_kurang_mampu/tambah');?>" class="btn-fab"><i class="bi bi-plus-lg"></i></a>

<!-- Modal Verifikasi (admin) -->
<?php if($is_admin):?>
<div class="vf-overlay" id="verifOverlay">
  <div class="vf-box">
    <h6><i class="bi bi-shield-check me-2" style="color:var(--t6);"></i>Ubah Status Pengajuan</h6>
    <form id="verifForm" method="post" action="<?php echo base_url('warga_kurang_mampu/verifikasi');?>">
      <?php echo form_hidden($this->security->get_csrf_token_name(), $this->security->get_csrf_hash());?>
      <input type="hidden" name="id" id="verifId">
      <label>Status Pengajuan</label>
      <select name="status" id="verifStatus">
        <option value="menunggu">⏳ Menunggu</option>
        <option value="diverifikasi">🔵 Diverifikasi</option>
        <option value="disetujui">✅ Disetujui</option>
        <option value="ditolak">❌ Ditolak</option>
      </select>
      <label>Catatan Verifikasi</label>
      <textarea name="catatan" id="verifCatatan" rows="3" placeholder="Tulis catatan (opsional)..."></textarea>
      <div class="vf-acts">
        <button type="button" class="btn-v btn-v-c" onclick="closeVerif()">Batal</button>
        <button type="submit" class="btn-v btn-v-s"><i class="bi bi-check2"></i> Simpan</button>
      </div>
    </form>
  </div>
</div>
<?php endif;?>

<script>
$(document).ready(function(){
  setTimeout(function(){var el=document.getElementById('flashMsg');if(el){el.style.transition='opacity .4s';el.style.opacity='0';setTimeout(function(){el&&el.remove();},420);}},4500);
});

function openVerif(id, status, catatan) {
  document.getElementById('verifId').value      = id;
  document.getElementById('verifStatus').value  = status;
  document.getElementById('verifCatatan').value = catatan || '';
  document.getElementById('verifOverlay').classList.add('show');
}
function closeVerif() {
  document.getElementById('verifOverlay').classList.remove('show');
}
document.getElementById('verifOverlay')?.addEventListener('click', function(e){
  if(e.target === this) closeVerif();
});

// AJAX verifikasi
<?php if($is_admin):?>
document.getElementById('verifForm')?.addEventListener('submit', function(e){
  e.preventDefault();
  var fd = new FormData(this);
  fetch(this.action, {method:'POST', body:fd})
    .then(r=>r.json())
    .then(d=>{
      if(d.ok){ closeVerif(); location.reload(); }
    });
});
<?php endif;?>
</script>