<!-- views/pinjaman/pengajuan.php -->
<style>
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
  --teal-900: #0d3d38;
  --teal-800: #0b5a52;
  --teal-700: #0b7a6e;
  --teal-600: #0d9488;
  --teal-500: #14b8a6;
  --teal-400: #2dd4bf;
  --teal-100: #ccfbf1;
  --teal-50:  #f0fdfa;
  --green-500: #10b981;
  --green-600: #059669;
  --amber-400: #fbbf24;
  --amber-500: #f59e0b;
  --amber-600: #d97706;
  --amber-50:  #fffbeb;
  --amber-100: #fef3c7;
  --red-400:  #f87171;
  --red-500:  #ef4444;
  --red-600:  #dc2626;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-50:  #eff6ff;
  --slate-50: #f8fafc;
  --slate-100:#f1f5f9;
  --slate-200:#e2e8f0;
  --slate-400:#94a3b8;
  --slate-500:#64748b;
  --slate-700:#334155;
  --slate-900:#0f172a;
  --card-shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 20px rgba(0,0,0,.06);
}

.paj-wrapper {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  color: var(--slate-900);
  padding-bottom: 32px;
}

/* ── Page Header ── */
.paj-page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.paj-page-header h4 {
  font-size: 1.3rem; font-weight: 800;
  color: var(--slate-900); margin: 0 0 6px;
  display: flex; align-items: center; gap: 10px;
}
.paj-page-header h4 .head-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--teal-700), var(--teal-500));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.05rem;
  box-shadow: 0 4px 12px rgba(13,148,136,.3);
  flex-shrink: 0;
}
.paj-breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: .78rem; color: var(--slate-400);
  flex-wrap: wrap;
}
.paj-breadcrumb a { color: var(--teal-600); text-decoration: none; font-weight: 600; }
.paj-breadcrumb a:hover { color: var(--teal-700); text-decoration: underline; }
.paj-breadcrumb .sep { color: var(--slate-300); }
.paj-breadcrumb .current { color: var(--slate-500); font-weight: 600; }

.btn-ajukan {
  display: inline-flex; align-items: center; gap: 6px;
  background: linear-gradient(135deg, var(--teal-600), var(--teal-500));
  color: #fff; border: none; border-radius: 8px;
  padding: 9px 18px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: .82rem; font-weight: 700;
  text-decoration: none; white-space: nowrap; cursor: pointer;
  box-shadow: 0 4px 12px rgba(13,148,136,.28);
  transition: transform .15s, box-shadow .15s;
  flex-shrink: 0;
}
.btn-ajukan:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(13,148,136,.38); color: #fff; }

/* ── Flash Messages ── */
.paj-flash {
  display: flex; align-items: flex-start; gap: 11px;
  border-radius: 10px; padding: 13px 16px;
  margin-bottom: 18px; font-size: .85rem;
  animation: fadeUp .3s ease both;
}
.paj-flash.success {
  background: #d1fae5; border: 1px solid #6ee7b7; color: #065f46;
}
.paj-flash.error {
  background: #fee2e2; border: 1px solid #fca5a5; color: #991b1b;
}
.paj-flash i { font-size: 1rem; margin-top: 1px; flex-shrink: 0; }
.paj-flash .flash-close {
  margin-left: auto; background: none; border: none;
  cursor: pointer; opacity: .6; font-size: .9rem;
  color: inherit; padding: 0 2px; line-height: 1;
  flex-shrink: 0;
}
.paj-flash .flash-close:hover { opacity: 1; }

/* ── Main Card ── */
.paj-card {
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--slate-200);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  animation: fadeUp .35s ease both;
}
.paj-card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(90deg, var(--teal-50), #fff);
  border-bottom: 1px solid rgba(13,148,136,.1);
  gap: 12px; flex-wrap: wrap;
}
.paj-card-head h5 {
  margin: 0; font-size: .98rem; font-weight: 800;
  color: var(--slate-900);
  display: flex; align-items: center; gap: 8px;
}
.paj-card-head h5 i { color: var(--teal-600); }
.paj-count-pill {
  background: var(--teal-50); color: var(--teal-700);
  border: 1px solid rgba(13,148,136,.2);
  padding: 3px 10px; border-radius: 20px;
  font-size: .74rem; font-weight: 700;
}

/* ── Table ── */
.paj-table-wrap { overflow-x: auto; }
.paj-table {
  width: 100%; border-collapse: collapse;
  font-size: .83rem;
}
.paj-table thead th {
  padding: 11px 14px;
  background: var(--slate-50);
  border-bottom: 2px solid var(--slate-200);
  font-weight: 700; font-size: .74rem;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--slate-500); white-space: nowrap;
}
.paj-table tbody tr { border-bottom: 1px solid #f8fafc; transition: background .12s; }
.paj-table tbody tr:last-child { border-bottom: none; }
.paj-table tbody tr:hover { background: var(--teal-50); }
.paj-table tbody td { padding: 12px 14px; vertical-align: middle; }
.paj-table tfoot td {
  padding: 12px 14px;
  background: linear-gradient(90deg, var(--teal-50), #fff);
  border-top: 2px solid rgba(13,148,136,.15);
}

/* ── Badges ── */
.badge-kode {
  font-family: monospace; font-size: .78rem; font-weight: 700;
  background: var(--slate-100); color: var(--slate-600);
  padding: 3px 8px; border-radius: 5px;
}
.badge-jenis {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 20px;
  font-size: .73rem; font-weight: 700;
  background: linear-gradient(135deg, #dbeafe, #bfdbfe);
  color: var(--blue-600);
  border: 1px solid rgba(59,130,246,.2);
}
.badge-status {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 20px;
  font-size: .73rem; font-weight: 700; white-space: nowrap;
}
.badge-status.pending {
  background: var(--amber-100); color: #92400e;
  border: 1px solid var(--amber-400);
}
.badge-status.disetujui {
  background: #d1fae5; color: #065f46;
  border: 1px solid #6ee7b7;
}
.badge-status.ditolak {
  background: #fee2e2; color: #991b1b;
  border: 1px solid #fca5a5;
}

/* ── Action buttons ── */
.btn-detail-sm {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--teal-50); color: var(--teal-700);
  border: 1px solid rgba(13,148,136,.25); border-radius: 6px;
  padding: 5px 11px; font-size: .76rem; font-weight: 700;
  font-family: 'Plus Jakarta Sans', sans-serif;
  cursor: pointer; text-decoration: none; transition: all .15s;
}
.btn-detail-sm:hover { background: var(--teal-600); color: #fff; border-color: var(--teal-600); }
.btn-proses-sm {
  display: inline-flex; align-items: center; gap: 4px;
  background: linear-gradient(135deg, var(--teal-600), var(--teal-500));
  color: #fff; border: none; border-radius: 6px;
  padding: 5px 11px; font-size: .76rem; font-weight: 700;
  font-family: 'Plus Jakarta Sans', sans-serif;
  cursor: pointer; text-decoration: none;
  box-shadow: 0 2px 8px rgba(13,148,136,.22);
  transition: all .15s;
}
.btn-proses-sm:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(13,148,136,.32); color: #fff; }

/* ── Empty State ── */
.paj-empty {
  padding: 60px 24px; text-align: center; color: var(--slate-400);
}
.paj-empty .ei {
  width: 68px; height: 68px; border-radius: 18px;
  background: var(--teal-50); color: var(--teal-400);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; margin: 0 auto 14px;
}
.paj-empty h5 { color: var(--slate-600); font-weight: 700; margin-bottom: 6px; font-size: .95rem; }
.paj-empty p  { font-size: .82rem; margin: 0; }

/* ── MOBILE CARDS ── */
.paj-mobile { display: none; padding: 12px 14px; }
.paj-m-card {
  border: 1px solid var(--slate-200); border-radius: 12px;
  padding: 13px 14px; margin-bottom: 10px;
  background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.05);
  position: relative; overflow: hidden;
  transition: box-shadow .15s;
}
.paj-m-card::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  border-radius: 3px 0 0 3px;
}
.paj-m-card.pending   { --mc: var(--amber-500); }
.paj-m-card.disetujui { --mc: var(--green-500); }
.paj-m-card.ditolak   { --mc: var(--red-500); }
.paj-m-card::before { background: var(--mc, var(--teal-500)); }
.paj-m-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.1); }

.paj-m-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.paj-m-kode { font-family: monospace; font-size: .8rem; font-weight: 700; color: var(--slate-600); }
.paj-m-body { margin-bottom: 10px; }
.paj-m-nama { font-size: .87rem; font-weight: 700; color: var(--slate-900); margin-bottom: 2px; }
.paj-m-jenis { font-size: .78rem; color: var(--slate-400); margin-bottom: 6px; }
.paj-m-nominal { font-size: 1.05rem; font-weight: 800; color: var(--teal-700); margin-bottom: 2px; }
.paj-m-tenor { font-size: .76rem; color: var(--slate-400); }
.paj-m-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.paj-m-date { font-size: .73rem; color: var(--slate-400); display: flex; align-items: center; gap: 4px; }
.paj-m-actions { display: flex; gap: 6px; }

/* ── Modal ── */
.paj-modal .modal-content {
  border: none; border-radius: 16px; overflow: hidden;
  font-family: 'Plus Jakarta Sans', sans-serif;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
}
.paj-modal .modal-header {
  background: linear-gradient(135deg, var(--teal-800), var(--teal-600));
  color: #fff; padding: 18px 22px; border: none;
}
.paj-modal .modal-header .modal-title {
  font-size: 1rem; font-weight: 800;
  display: flex; align-items: center; gap: 8px;
}
.paj-modal .btn-close-white { filter: brightness(0) invert(1); opacity: .8; }
.paj-modal .btn-close-white:hover { opacity: 1; }
.paj-modal .modal-body { padding: 22px; }
.paj-modal .modal-footer {
  padding: 14px 22px; border-top: 1px solid var(--slate-200);
  background: var(--slate-50);
}

/* info grid in modal */
.modal-info-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 14px; margin-bottom: 14px;
}
.modal-info-item label {
  display: block; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--slate-400); margin-bottom: 3px;
}
.modal-info-item .val { font-size: .88rem; font-weight: 600; color: var(--slate-800); }
.modal-info-item .val.teal   { color: var(--teal-700); font-size: .96rem; }
.modal-info-item .val.red    { color: var(--red-500);  font-size: .96rem; }
.modal-info-item .val.green  { color: var(--green-500);font-size: .96rem; }
.modal-divider {
  border: none; border-top: 1px solid var(--slate-100); margin: 16px 0;
}
.modal-info-full { margin-bottom: 14px; }
.modal-info-full label {
  display: block; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--slate-400); margin-bottom: 4px;
}
.modal-info-full .val { font-size: .88rem; color: var(--slate-700); line-height: 1.5; }
.penolakan-box {
  background: #fff5f5; border: 1px solid #fca5a5;
  border-radius: 8px; padding: 11px 14px;
  margin-top: 8px; font-size: .84rem; color: #991b1b;
}
.penolakan-box strong { display: block; margin-bottom: 3px; }

.btn-modal-close {
  background: var(--slate-100); color: var(--slate-600);
  border: 1px solid var(--slate-200); border-radius: 8px;
  padding: 8px 18px; font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: .82rem; font-weight: 700; cursor: pointer;
  transition: all .15s;
}
.btn-modal-close:hover { background: var(--slate-200); }
.btn-modal-proses {
  background: linear-gradient(135deg, var(--teal-600), var(--teal-500));
  color: #fff; border: none; border-radius: 8px;
  padding: 8px 18px; font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: .82rem; font-weight: 700; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  box-shadow: 0 4px 12px rgba(13,148,136,.25);
  transition: all .15s;
}
.btn-modal-proses:hover { box-shadow: 0 6px 18px rgba(13,148,136,.35); color: #fff; transform: translateY(-1px); }

/* ── Animations ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}

/* ══════════ RESPONSIVE ══════════ */
@media (max-width: 767px) {
  .paj-table-wrap { display: none; }
  .paj-mobile { display: block; }
  .paj-page-header h4 .page-title { display: none; }

  .modal-info-grid { grid-template-columns: 1fr; gap: 10px; }
}

@media (max-width: 500px) {
  .paj-page-header { gap: 10px; }
}
</style>

<div class="paj-wrapper container-fluid">

  <!-- ── Page Header ── -->
  <div class="paj-page-header">
    <div>
      <h4>
        <div class="head-icon"><i class="bi bi-file-earmark-text"></i></div>
        <span class="page-title"><?php echo $title; ?></span>
      </h4>
      <div class="paj-breadcrumb">
        <a href="<?php echo base_url('dashboard'); ?>"><i class="bi bi-grid-1x2-fill me-1"></i>Dashboard</a>
        <span class="sep">›</span>
        <a href="<?php echo base_url('pinjaman'); ?>">Pinjaman</a>
        <span class="sep">›</span>
        <span class="current">Pengajuan</span>
      </div>
    </div>
    <?php if(is_warga()): ?>
    <a href="<?php echo base_url('pinjaman/ajukan'); ?>" class="btn-ajukan">
      <i class="bi bi-plus-circle-fill"></i> Ajukan Pinjaman Baru
    </a>
    <?php endif; ?>
  </div>

  <!-- ── Flash Messages ── -->
  <?php if($this->session->flashdata('success')): ?>
  <div class="paj-flash success" id="flashSuccess">
    <i class="bi bi-check-circle-fill"></i>
    <span><?php echo $this->session->flashdata('success'); ?></span>
    <button class="flash-close" onclick="this.closest('.paj-flash').remove()"><i class="bi bi-x"></i></button>
  </div>
  <?php endif; ?>

  <?php if($this->session->flashdata('error')): ?>
  <div class="paj-flash error" id="flashError">
    <i class="bi bi-exclamation-triangle-fill"></i>
    <span><?php echo $this->session->flashdata('error'); ?></span>
    <button class="flash-close" onclick="this.closest('.paj-flash').remove()"><i class="bi bi-x"></i></button>
  </div>
  <?php endif; ?>

  <!-- ── Main Card ── -->
  <div class="paj-card">
    <div class="paj-card-head">
      <h5>
        <i class="bi bi-file-earmark-text-fill"></i>
        Daftar Pengajuan Pinjaman
      </h5>
      <?php if(!empty($pengajuan)): ?>
      <span class="paj-count-pill"><?php echo count($pengajuan); ?> pengajuan</span>
      <?php endif; ?>
    </div>

    <?php if(empty($pengajuan)): ?>
    <div class="paj-empty">
      <div class="ei"><i class="bi bi-inbox"></i></div>
      <h5>Belum Ada Pengajuan</h5>
      <p>
        <?php if(is_warga()): ?>
          Klik <strong>Ajukan Pinjaman Baru</strong> untuk membuat pengajuan pertama Anda.
        <?php else: ?>
          Belum ada data pengajuan pinjaman dari warga.
        <?php endif; ?>
      </p>
    </div>

    <?php else: ?>

    <!-- DESKTOP TABLE -->
    <div class="paj-table-wrap">
      <table class="paj-table" id="tablePengajuan">
        <thead>
          <tr>
            <th width="46px">No</th>
            <th>Kode Pengajuan</th>
            <?php if(is_admin()): ?>
            <th>Nama Warga</th>
            <?php endif; ?>
            <th>Jenis Pinjaman</th>
            <th class="text-end">Nominal</th>
            <th>Tenor</th>
            <th>Tgl Pengajuan</th>
            <th>Status</th>
            <th class="text-center" width="140px">Aksi</th>
          </tr>
        </thead>
        <tbody>
          <?php $no = 1; foreach($pengajuan as $p): ?>
          <tr>
            <td style="color:var(--slate-400);font-size:.78rem;"><?php echo $no++; ?></td>
            <td><span class="badge-kode"><?php echo htmlspecialchars($p->kode_pengajuan); ?></span></td>
            <?php if(is_admin()): ?>
            <td style="font-weight:600;"><?php echo htmlspecialchars($p->nama_lengkap); ?></td>
            <?php endif; ?>
            <td><span class="badge-jenis"><i class="bi bi-tag-fill"></i><?php echo htmlspecialchars($p->nama_pinjaman); ?></span></td>
            <td class="text-end" style="font-weight:700;color:var(--teal-700);">Rp <?php echo number_format($p->nominal_pengajuan, 0, ',', '.'); ?></td>
            <td style="color:var(--slate-500);"><?php echo $p->tenor; ?> bln</td>
            <td style="font-size:.8rem;white-space:nowrap;color:var(--slate-500);"><?php echo date('d/m/Y', strtotime($p->tanggal_pengajuan)); ?></td>
            <td>
              <?php if($p->status_pengajuan == 'pending'): ?>
                <span class="badge-status pending"><i class="bi bi-clock"></i>Pending</span>
              <?php elseif($p->status_pengajuan == 'disetujui'): ?>
                <span class="badge-status disetujui"><i class="bi bi-check-circle-fill"></i>Disetujui</span>
              <?php else: ?>
                <span class="badge-status ditolak"><i class="bi bi-x-circle-fill"></i>Ditolak</span>
              <?php endif; ?>
            </td>
            <td class="text-center">
              <button class="btn-detail-sm" data-bs-toggle="modal" data-bs-target="#detailModal<?php echo $p->id; ?>">
                <i class="bi bi-eye"></i> Detail
              </button>
              <?php if(is_admin() && $p->status_pengajuan == 'pending'): ?>
              <a href="<?php echo base_url('pinjaman/proses_pengajuan/'.$p->id); ?>" class="btn-proses-sm ms-1">
                <i class="bi bi-gear-fill"></i> Proses
              </a>
              <?php endif; ?>
            </td>
          </tr>
          <?php endforeach; ?>
        </tbody>
      </table>
    </div>

    <!-- MOBILE CARDS -->
    <div class="paj-mobile">
      <?php foreach($pengajuan as $p): ?>
      <div class="paj-m-card <?php echo $p->status_pengajuan; ?>">
        <div class="paj-m-top">
          <span class="paj-m-kode"><?php echo htmlspecialchars($p->kode_pengajuan); ?></span>
          <?php if($p->status_pengajuan == 'pending'): ?>
            <span class="badge-status pending"><i class="bi bi-clock"></i>Pending</span>
          <?php elseif($p->status_pengajuan == 'disetujui'): ?>
            <span class="badge-status disetujui"><i class="bi bi-check-circle-fill"></i>Disetujui</span>
          <?php else: ?>
            <span class="badge-status ditolak"><i class="bi bi-x-circle-fill"></i>Ditolak</span>
          <?php endif; ?>
        </div>
        <div class="paj-m-body">
          <?php if(is_admin()): ?>
          <div class="paj-m-nama"><?php echo htmlspecialchars($p->nama_lengkap); ?></div>
          <?php endif; ?>
          <div class="paj-m-jenis"><span class="badge-jenis"><i class="bi bi-tag-fill"></i><?php echo htmlspecialchars($p->nama_pinjaman); ?></span></div>
          <div class="paj-m-nominal">Rp <?php echo number_format($p->nominal_pengajuan, 0, ',', '.'); ?></div>
          <div class="paj-m-tenor">Tenor <?php echo $p->tenor; ?> bulan</div>
        </div>
        <div class="paj-m-footer">
          <span class="paj-m-date"><i class="bi bi-calendar3"></i><?php echo date('d/m/Y', strtotime($p->tanggal_pengajuan)); ?></span>
          <div class="paj-m-actions">
            <button class="btn-detail-sm" data-bs-toggle="modal" data-bs-target="#detailModal<?php echo $p->id; ?>">
              <i class="bi bi-eye"></i> Detail
            </button>
            <?php if(is_admin() && $p->status_pengajuan == 'pending'): ?>
            <a href="<?php echo base_url('pinjaman/proses_pengajuan/'.$p->id); ?>" class="btn-proses-sm">
              <i class="bi bi-gear-fill"></i> Proses
            </a>
            <?php endif; ?>
          </div>
        </div>
      </div>
      <?php endforeach; ?>
    </div>

    <?php endif; ?>
  </div><!-- /.paj-card -->

</div><!-- /.paj-wrapper -->


<!-- ══════════ MODALS ══════════ -->
<?php if(!empty($pengajuan)): foreach($pengajuan as $p): ?>
<div class="modal fade paj-modal" id="detailModal<?php echo $p->id; ?>" tabindex="-1" aria-hidden="true">
  <div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable">
    <div class="modal-content">

      <div class="modal-header">
        <div class="modal-title">
          <i class="bi bi-file-earmark-text"></i>
          Detail Pengajuan Pinjaman
        </div>
        <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
      </div>

      <div class="modal-body">

        <div class="modal-info-grid">
          <div class="modal-info-item">
            <label>Kode Pengajuan</label>
            <div class="val"><span class="badge-kode"><?php echo htmlspecialchars($p->kode_pengajuan); ?></span></div>
          </div>
          <div class="modal-info-item">
            <label>Tanggal Pengajuan</label>
            <div class="val"><?php echo date('d F Y', strtotime($p->tanggal_pengajuan)); ?></div>
          </div>
          <div class="modal-info-item">
            <label>Nama Pemohon</label>
            <div class="val"><?php echo htmlspecialchars($p->nama_lengkap); ?></div>
          </div>
          <div class="modal-info-item">
            <label>Jenis Pinjaman</label>
            <div class="val"><span class="badge-jenis"><i class="bi bi-tag-fill"></i><?php echo htmlspecialchars($p->nama_pinjaman); ?></span></div>
          </div>
        </div>

        <hr class="modal-divider">

        <div class="modal-info-grid">
          <div class="modal-info-item">
            <label>Nominal Pengajuan</label>
            <div class="val teal">Rp <?php echo number_format($p->nominal_pengajuan, 0, ',', '.'); ?></div>
          </div>
          <div class="modal-info-item">
            <label>Tenor</label>
            <div class="val"><?php echo $p->tenor; ?> bulan</div>
          </div>
          <div class="modal-info-item">
            <label>Bunga</label>
            <div class="val"><?php echo $p->bunga_persen; ?>% / bulan</div>
          </div>
          <div class="modal-info-item">
            <label>Total Pinjaman</label>
            <div class="val red">Rp <?php echo number_format($p->total_pinjaman, 0, ',', '.'); ?></div>
          </div>
        </div>

        <div class="modal-info-item" style="margin-bottom:14px;">
          <label>Angsuran / Bulan</label>
          <div class="val green">Rp <?php echo number_format($p->angsuran_per_bulan, 0, ',', '.'); ?></div>
        </div>

        <hr class="modal-divider">

        <div class="modal-info-full">
          <label>Keperluan</label>
          <div class="val"><?php echo htmlspecialchars($p->keperluan); ?></div>
        </div>

        <?php if(!empty($p->jaminan)): ?>
        <div class="modal-info-full">
          <label>Jaminan</label>
          <div class="val"><?php echo htmlspecialchars($p->jaminan); ?></div>
        </div>
        <?php endif; ?>

        <div class="modal-info-full">
          <label>Status</label>
          <div class="val">
            <?php if($p->status_pengajuan == 'pending'): ?>
              <span class="badge-status pending"><i class="bi bi-clock"></i>Menunggu Persetujuan</span>
            <?php elseif($p->status_pengajuan == 'disetujui'): ?>
              <span class="badge-status disetujui"><i class="bi bi-check-circle-fill"></i>Disetujui</span>
              <?php if(!empty($p->tanggal_disetujui)): ?>
              <span style="font-size:.78rem;color:var(--slate-400);margin-left:8px;">
                pada <?php echo date('d F Y', strtotime($p->tanggal_disetujui)); ?>
              </span>
              <?php endif; ?>
            <?php else: ?>
              <span class="badge-status ditolak"><i class="bi bi-x-circle-fill"></i>Ditolak</span>
              <?php if(!empty($p->keterangan_penolakan)): ?>
              <div class="penolakan-box">
                <strong><i class="bi bi-info-circle me-1"></i>Alasan Penolakan</strong>
                <?php echo htmlspecialchars($p->keterangan_penolakan); ?>
              </div>
              <?php endif; ?>
            <?php endif; ?>
          </div>
        </div>

      </div><!-- /.modal-body -->

      <div class="modal-footer">
        <button type="button" class="btn-modal-close" data-bs-dismiss="modal">
          <i class="bi bi-x me-1"></i>Tutup
        </button>
        <?php if(is_admin() && $p->status_pengajuan == 'pending'): ?>
        <a href="<?php echo base_url('pinjaman/proses_pengajuan/'.$p->id); ?>" class="btn-modal-proses">
          <i class="bi bi-gear-fill"></i> Proses Pengajuan
        </a>
        <?php endif; ?>
      </div>

    </div>
  </div>
</div>
<?php endforeach; endif; ?>


<script>
$(document).ready(function() {
  $('#tablePengajuan').DataTable({
    language: { url: '//cdn.datatables.net/plug-ins/1.13.7/i18n/id.json' },
    order: [[<?php echo is_admin() ? '6' : '5'; ?>, 'desc']],
    pageLength: 25,
    responsive: true,
    columnDefs: [{ orderable: false, targets: -1 }]
  });

  // Auto-close flash after 4s
  setTimeout(() => {
    document.querySelectorAll('.paj-flash').forEach(el => {
      el.style.transition = 'opacity .4s';
      el.style.opacity = '0';
      setTimeout(() => el.remove(), 400);
    });
  }, 4000);
});
</script>