<!-- views/pinjaman/index.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;
  --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);
}


/* Alternative style - lebih prominent */
.btn-jenis-pinjaman-alt {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #f0fdfa, #ccfbf1);
  color: var(--teal-800);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.85rem; font-weight: 700;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--teal-200);
  transition: all .2s;
}
.btn-jenis-pinjaman-alt:hover {
  background: linear-gradient(135deg, var(--teal-600), var(--teal-500));
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(13,148,136,.25);
}
.btn-jenis-pinjaman-alt::before {
  content: '\F5B0'; /* Bootstrap Icons tags-fill */
  font-family: 'bootstrap-icons';
  font-size: 1.1rem;
}


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

/* ─── PAGE HEADER ─────────────────── */
.ar-page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 24px;
}
.ar-header-left h4 {
  font-size: 1.25rem;
  font-weight: 800;
  color: #0b5a52;
  margin: 0 0 5px;
  display: flex;
  align-items: center;
  gap: 11px;
  letter-spacing: -.3px;
}
.ar-header-left h4 .hi {
  width: 40px; height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, #0d9488, #14b8a6);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.05rem;
  box-shadow: 0 4px 12px rgba(13,148,136,0.32);
  flex-shrink: 0;
}
.ar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.77rem;
  color: #94a3b8;
  padding-left: 51px;
}
.ar-breadcrumb a { color: #0d9488; text-decoration: none; font-weight: 600; }
.ar-breadcrumb a:hover { text-decoration: underline; }
.ar-breadcrumb .sep { color: #e2e8f0; }

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

/* ── Alert Verifikasi ── */
.alert-verifikasi {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(135deg, var(--amber-50), var(--amber-100));
  border: 1px solid var(--amber-400);
  border-radius: 12px; padding: 14px 18px;
  margin-bottom: 20px;
  animation: fadeUp .35s ease both, pulseBorder 2.5s ease-in-out infinite;
}
@keyframes pulseBorder {
  0%,100% { box-shadow: 0 0 0 0 rgba(251,191,36,.25); }
  50%      { box-shadow: 0 0 0 5px rgba(251,191,36,.06); }
}
.alert-verifikasi .av-icon { font-size: 1.4rem; color: var(--amber-600); flex-shrink: 0; }
.alert-verifikasi .av-text { flex: 1; }
.alert-verifikasi .av-text strong { font-size: .88rem; color: #92400e; display: block; }
.alert-verifikasi .av-text small  { font-size: .78rem; color: #b45309; }
.btn-verifikasi-now {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--amber-500); color: #fff;
  border: none; border-radius: 7px; padding: 7px 14px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: .78rem; font-weight: 700;
  text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background .15s;
}
.btn-verifikasi-now:hover { background: var(--amber-600); color: #fff; }

/* ── Summary Cards ── */
.pin-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

/* ── PERBAIKAN: card bisa diklik ── */
.pin-summary-card {
  border-radius: 14px; padding: 20px 18px;
  position: relative; overflow: hidden;
  color: #fff;
  transition: transform .2s, box-shadow .2s;
  display: block;          /* penting agar <a> berperilaku seperti block */
  text-decoration: none;   /* hilangkan underline bawaan link */
  cursor: pointer;
}
.pin-summary-card:hover {
  transform: translateY(-4px);
  color: #fff;             /* jaga warna teks tetap putih saat hover */
  text-decoration: none;
}

.pin-summary-card::before {
  content: '';
  position: absolute; top: -28px; right: -28px;
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255,255,255,.1);
}
.pin-summary-card::after {
  content: '';
  position: absolute; bottom: -45px; right: 40px;
  width: 160px; height: 160px; border-radius: 50%;
  background: rgba(255,255,255,.06);
}
.pin-summary-card .sc-label {
  font-size: .72rem; font-weight: 600; opacity: .85;
  text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: 8px; position: relative; z-index: 1;
}
.pin-summary-card .sc-value {
  font-size: 1.5rem; font-weight: 800; line-height: 1.15;
  position: relative; z-index: 1;
}
.pin-summary-card .sc-value small { font-size: .6em; font-weight: 600; opacity: .8; }
.pin-summary-card .sc-sub {
  font-size: .72rem; opacity: .72; margin-top: 5px;
  position: relative; z-index: 1;
}
.pin-summary-card .sc-icon {
  position: absolute; right: 18px; top: 50%; transform: translateY(-50%);
  width: 50px; height: 50px;
  background: rgba(255,255,255,.16); border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.35rem; z-index: 1;
}

.sc-teal   { background: linear-gradient(135deg, var(--teal-800), var(--teal-600), var(--teal-400)); box-shadow: 0 8px 28px rgba(13,148,136,.28); }
.sc-green  { background: linear-gradient(135deg, #059669, #10b981, #34d399); box-shadow: 0 8px 28px rgba(16,185,129,.28); }
.sc-orange { background: linear-gradient(135deg, #d97706, #f59e0b, #fbbf24); box-shadow: 0 8px 28px rgba(245,158,11,.28); }
.sc-amber  { background: linear-gradient(135deg, #b45309, #d97706, #f59e0b); box-shadow: 0 8px 28px rgba(245,158,11,.30); border: 2px solid var(--amber-400); }
.sc-blue   { background: linear-gradient(135deg, #1d4ed8, #3b82f6, #60a5fa); box-shadow: 0 8px 28px rgba(59,130,246,.28); }
.sc-muted  { background: linear-gradient(135deg, #475569, #64748b, #94a3b8); box-shadow: 0 4px 16px rgba(100,116,139,.2); opacity: .75; }

.sc-badge {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  background: var(--red-500); color: #fff;
  font-size: .7rem; font-weight: 800;
  padding: 2px 8px; border-radius: 20px;
  border: 2px solid rgba(255,255,255,.5);
}
.sc-action {
  display: block; margin-top: 11px; position: relative; z-index: 1;
  background: rgba(255,255,255,.18); color: #fff;
  border: 1px solid rgba(255,255,255,.3); border-radius: 7px;
  padding: 5px 12px; font-size: .74rem; font-weight: 700;
  text-align: center; text-decoration: none;
  transition: background .15s;
}
.sc-action:hover { background: rgba(255,255,255,.3); color: #fff; }

/* ── Pending Verifikasi Table ── */
.pin-pending-wrap {
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--amber-400);
  border-top: 3px solid var(--amber-500);
  box-shadow: var(--card-shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.pin-pending-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px;
  background: linear-gradient(90deg, var(--amber-50), #fff);
  border-bottom: 1px solid var(--amber-100);
}
.pin-pending-head h5 {
  margin: 0; font-size: .95rem; font-weight: 800; color: #92400e;
  display: flex; align-items: center; gap: 8px;
}
.pin-pending-head h5 i { color: var(--amber-500); }
.pending-count-pill {
  background: var(--amber-500); color: #fff;
  font-size: .72rem; font-weight: 800;
  padding: 2px 9px; border-radius: 20px;
}
.btn-lihat-semua {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--amber-500); color: #fff;
  border: none; border-radius: 7px; padding: 7px 14px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: .78rem; font-weight: 700;
  text-decoration: none; white-space: nowrap;
  transition: background .15s;
}
.btn-lihat-semua:hover { background: var(--amber-600); color: #fff; }

/* Table shared */
.pin-table-wrap { overflow-x: auto; }
.pin-table {
  width: 100%; border-collapse: collapse;
  font-size: .83rem; min-width: 700px;
}
.pin-table thead th {
  padding: 10px 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;
}
.pin-table tbody tr { border-bottom: 1px solid #f8fafc; transition: background .12s; }
.pin-table tbody tr:last-child { border-bottom: none; }
.pin-table tbody tr:hover { background: var(--teal-50); }
.pin-table tbody tr.row-pending:hover { background: var(--amber-50); }
.pin-table tbody tr.row-pending td { background: var(--amber-50); }
.pin-table tbody td { padding: 11px 14px; vertical-align: middle; }

.more-link {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px;
  color: var(--amber-600); font-size: .82rem; font-weight: 700;
  text-decoration: none;
  border-top: 1px solid var(--amber-100);
  background: var(--amber-50);
}
.more-link:hover { background: var(--amber-100); }

/* person cell */
.person-cell { display: flex; align-items: center; gap: 9px; }
.person-avatar {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem;
}
.person-avatar.amber { background: var(--amber-100); color: var(--amber-600); }
.person-avatar.teal  { background: var(--teal-50); color: var(--teal-600); }
.person-name { font-weight: 700; font-size: .83rem; }

/* badges */
.badge-code {
  background: var(--slate-100); color: var(--slate-500);
  padding: 3px 8px; border-radius: 5px;
  font-size: .73rem; font-weight: 700; font-family: monospace;
}
.badge-ke {
  background: linear-gradient(135deg, var(--teal-700), var(--teal-500));
  color: #fff; padding: 3px 8px; border-radius: 5px;
  font-size: .73rem; font-weight: 700;
}
.badge-pending-tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--amber-100); color: #92400e;
  border: 1px solid var(--amber-400);
  padding: 2px 7px; border-radius: 20px;
  font-size: .7rem; font-weight: 700;
}

/* action buttons */
.btn-proses {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--green-500); color: #fff;
  border: none; border-radius: 6px; padding: 5px 12px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: .76rem; font-weight: 700;
  text-decoration: none; cursor: pointer;
  transition: background .15s;
}
.btn-proses:hover { background: var(--green-600); color: #fff; }
.btn-detail {
  display: inline-flex; align-items: center; gap: 5px;
  background: transparent; color: var(--red-500);
  border: 1px solid var(--red-400); border-radius: 6px;
  padding: 5px 10px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: .76rem; font-weight: 700;
  text-decoration: none; cursor: pointer;
  transition: all .15s;
}
.btn-detail:hover { background: var(--red-500); color: #fff; border-color: var(--red-500); }
.btn-bayar {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--teal-600); color: #fff;
  border: none; border-radius: 6px; padding: 5px 12px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: .76rem; font-weight: 700;
  text-decoration: none; cursor: pointer;
  transition: background .15s;
}
.btn-bayar:hover { background: var(--teal-700); color: #fff; }

/* ── Content Grid ── */
.pin-content-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 18px;
  margin-bottom: 20px;
}

/* ── Card box shared ── */
.pin-card {
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--slate-200);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}
.pin-card-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px;
  background: linear-gradient(90deg, var(--teal-50), #fff);
  border-bottom: 1px solid rgba(13,148,136,.1);
}
.pin-card-head h5 {
  margin: 0; font-size: .95rem; font-weight: 800;
  color: var(--slate-900);
  display: flex; align-items: center; gap: 8px;
}
.pin-card-head h5 i { color: var(--teal-600); }
.pin-card-head h5.danger { color: var(--red-600); }
.pin-card-head h5.danger i { color: var(--red-500); }
.card-date-pill {
  background: var(--teal-50); color: var(--teal-700);
  border: 1px solid rgba(13,148,136,.2);
  padding: 4px 10px; border-radius: 20px;
  font-size: .74rem; font-weight: 700;
}
.pin-card-body { padding: 16px; }

/* ── Angsuran list ── */
.angsuran-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--slate-200);
  border-radius: 10px; margin-bottom: 9px;
  transition: all .15s;
}
.angsuran-item:last-child { margin-bottom: 0; }
.angsuran-item:hover { border-color: var(--teal-400); background: var(--teal-50); }
.angsuran-item.is-pending { border-color: var(--amber-400); background: var(--amber-50); }
.angsuran-item.is-pending:hover { background: var(--amber-100); }
.angsuran-info { flex: 1; min-width: 0; }
.angsuran-name { font-weight: 700; font-size: .84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.angsuran-meta { font-size: .74rem; color: var(--slate-400); margin-top: 2px; }
.angsuran-right { text-align: right; flex-shrink: 0; }
.angsuran-amount { font-size: .9rem; font-weight: 800; color: var(--teal-700); }
.angsuran-amount.amber { color: var(--amber-600); }

/* ── Macet list ── */
.macet-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 13px;
  border: 1px solid #fee2e2;
  background: #fff5f5;
  border-radius: 10px; margin-bottom: 9px;
}
.macet-item:last-child { margin-bottom: 0; }
.macet-avatar {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  background: #fee2e2; color: var(--red-500);
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem;
}
.macet-info { flex: 1; min-width: 0; }
.macet-name { font-size: .84rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.macet-code { font-size: .73rem; color: var(--slate-400); margin-top: 1px; }

/* ── Empty state ── */
.pin-empty { padding: 40px 20px; text-align: center; color: var(--slate-400); }
.pin-empty .ei {
  width: 60px; height: 60px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; margin: 0 auto 12px;
}
.pin-empty .ei.teal  { background: var(--teal-50);  color: var(--teal-400); }
.pin-empty .ei.green { background: #d1fae5; color: var(--green-500); }
.pin-empty p { font-size: .82rem; margin: 0; }

/* ── Quick Menu ── */
.pin-quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.pin-quick-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 9px; padding: 20px 12px;
  border-radius: 12px; border: 1.5px solid var(--slate-200);
  text-decoration: none; color: var(--slate-700);
  transition: all .2s; background: #fff; text-align: center;
  position: relative;
}
.pin-quick-item:hover {
  border-color: var(--teal-400); color: var(--teal-700);
  background: var(--teal-50); transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(13,148,136,.12);
}
.pin-quick-item i { font-size: 1.6rem; }
.pin-quick-item.q-teal i  { color: var(--teal-600); }
.pin-quick-item.q-green i { color: var(--green-500); }
.pin-quick-item.q-blue i  { color: var(--blue-500); }
.pin-quick-item.q-amber i { color: var(--amber-500); }
.pin-quick-item span { font-size: .78rem; font-weight: 700; }
.quick-notif {
  position: absolute; top: -7px; right: -7px;
  background: var(--red-500); color: #fff;
  font-size: .68rem; font-weight: 800;
  padding: 2px 6px; border-radius: 20px;
  border: 2px solid #fff;
}

/* ── Skeleton ── */
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 10px;
}
@keyframes shimmer { 0%{background-position:-200% 0} 100%{background-position:200% 0} }

/* ── Animations ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}
.pin-summary-grid { animation: fadeUp .35s ease both; }
.pin-pending-wrap { animation: fadeUp .4s .1s ease both; }
.pin-content-grid { animation: fadeUp .4s .18s ease both; }
.pin-card-quick   { animation: fadeUp .4s .24s ease both; }

/* ══════════ RESPONSIVE ══════════ */
@media (max-width: 991px) {
  .pin-summary-grid { grid-template-columns: repeat(2, 1fr); }
  .pin-content-grid { grid-template-columns: 1fr; }
  .pin-quick-grid   { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 767px) {
  .pin-summary-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .pin-summary-card .sc-value { font-size: 1.1rem; }
  .pin-summary-card .sc-icon { width: 42px; height: 42px; font-size: 1.1rem; right: 12px; }
  .pin-table { min-width: 600px; }
  .alert-verifikasi { flex-wrap: wrap; }
  .alert-verifikasi .btn-verifikasi-now { width: 100%; justify-content: center; }
  .ar-page-header { flex-direction: column; align-items: flex-start; }
  .btn-ajukan { width: 100%; justify-content: center; }
}

@media (max-width: 500px) {
  .pin-summary-grid { grid-template-columns: 1fr 1fr; }
  .pin-quick-grid   { grid-template-columns: 1fr 1fr; }
  .pin-card-body    { padding: 12px; }
}
</style>

<div class="pin-wrapper">

  <!-- ── Page Header ── -->
  <div class="ar-page-header">
    <div class="ar-header-left">
      <h4>
        <span class="hi"><i class="bi bi-cash-coin"></i></span>
        Dashboard Pinjaman
      </h4>
      <div class="ar-breadcrumb">
        <a href="<?php echo base_url('dashboard'); ?>">Dashboard</a>
        <span class="sep">/</span>
        <span>Pinjaman</span>
      </div>
    </div>
      <div style="display:flex; gap:8px; flex-wrap:wrap;">
       <?php if(!is_warga()): ?>
  <a href="<?php echo base_url('pinjaman/jenis_pinjaman'); ?>" class="btn-ajukan">
      <i class="bi bi-plus-circle-fill"></i> Jenis Pinjaman
      <?php endif; ?>

    <a href="<?php echo base_url('pinjaman/ajukan'); ?>" class="btn-ajukan">
      <i class="bi bi-plus-circle-fill"></i> Ajukan Pinjaman
    </a>
  </div>
       </div>



     

  <!-- ── Alert Verifikasi (Admin) ── -->
  <?php if(!is_warga() && isset($total_pending_verifikasi) && $total_pending_verifikasi > 0): ?>
  <div class="alert-verifikasi">
    <i class="bi bi-exclamation-triangle-fill av-icon"></i>
    <div class="av-text">
      <strong><?php echo $total_pending_verifikasi; ?> Pembayaran Online Menunggu Verifikasi</strong>
      <small>Segera proses agar saldo kas tercatat dengan benar.</small>
    </div>
    <a href="<?php echo base_url('pinjaman/verifikasi_pembayaran_list'); ?>" class="btn-verifikasi-now">
      <i class="bi bi-arrow-right"></i> Verifikasi Sekarang
    </a>
  </div>
  <?php endif; ?>

  <!-- ── Summary Cards ── -->
  <!-- Semua card sekarang menggunakan tag <a> agar bisa diklik -->
  <div class="pin-summary-grid">

    <!-- Total Piutang -->
    <a href="<?php echo base_url('pinjaman/data_pinjaman'); ?>" class="pin-summary-card sc-teal">
      <div class="sc-label"><i class="bi bi-cash-stack me-1"></i>Total Piutang</div>
      <div class="sc-value"><small>Rp </small><?php echo number_format($total_piutang, 0, ',', '.'); ?></div>
      <div class="sc-sub">Seluruh pinjaman berjalan</div>
      <div class="sc-icon"><i class="bi bi-cash-stack"></i></div>
    </a>

    <!-- Pinjaman Aktif -->
    <a href="<?php echo base_url('pinjaman/data_pinjaman'); ?>" class="pin-summary-card sc-green">
      <div class="sc-label"><i class="bi bi-check-circle me-1"></i>Pinjaman Aktif</div>
      <div class="sc-value"><?php echo number_format($total_pinjaman_aktif); ?></div>
      <div class="sc-sub">Pinjaman sedang berjalan</div>
      <div class="sc-icon"><i class="bi bi-check-circle-fill"></i></div>
    </a>

    <!-- Pengajuan Pending -->
    <a href="<?php echo base_url('pinjaman/pengajuan'); ?>" class="pin-summary-card sc-orange">
      <div class="sc-label"><i class="bi bi-file-earmark-text me-1"></i>Pengajuan Pending</div>
      <div class="sc-value"><?php echo number_format($total_pengajuan_pending); ?></div>
      <div class="sc-sub">Menunggu persetujuan</div>
      <div class="sc-icon"><i class="bi bi-file-earmark-text-fill"></i></div>
    </a>

    <!-- Card ke-4: Sesuai role -->
    <?php if(!is_warga()): ?>
      <?php $has_pending = isset($total_pending_verifikasi) && $total_pending_verifikasi > 0; ?>
      <a href="<?php echo base_url('pinjaman/verifikasi_pembayaran_list'); ?>"
         class="pin-summary-card <?php echo $has_pending ? 'sc-amber' : 'sc-muted'; ?>"
         style="position:relative;">
        <?php if($has_pending): ?>
          <span class="sc-badge"><?php echo $total_pending_verifikasi; ?></span>
        <?php endif; ?>
        <div class="sc-label"><i class="bi bi-credit-card me-1"></i>Bayar Online Pending</div>
        <div class="sc-value"><?php echo isset($total_pending_verifikasi) ? number_format($total_pending_verifikasi) : '0'; ?></div>
        <div class="sc-sub"><?php echo $has_pending ? 'Menunggu diverifikasi' : 'Tidak ada pending'; ?></div>
        <div class="sc-icon"><i class="bi bi-credit-card-fill"></i></div>
        <?php if($has_pending): ?>
          <span class="sc-action">
            <i class="bi bi-arrow-right me-1"></i>Proses Verifikasi
          </span>
        <?php endif; ?>
      </a>
    <?php else: ?>
      <a href="<?php echo base_url('pinjaman/laporan'); ?>" class="pin-summary-card sc-blue">
        <div class="sc-label"><i class="bi bi-calendar-check me-1"></i>Angsuran Bulan Ini</div>
        <div class="sc-value"><small>Rp </small><?php echo number_format($angsuran_bulan_ini, 0, ',', '.'); ?></div>
        <div class="sc-sub"><?php echo date('F Y'); ?></div>
        <div class="sc-icon"><i class="bi bi-calendar-check-fill"></i></div>
      </a>
    <?php endif; ?>

  </div>

  <!-- ── Tabel Pending Verifikasi (Admin) ── -->
  <?php if(!is_warga() && isset($pending_payments_global) && !empty($pending_payments_global)): ?>
  <div class="pin-pending-wrap">
    <div class="pin-pending-head">
      <h5>
        <i class="bi bi-clock-history"></i>
        Pembayaran Menunggu Verifikasi
        <span class="pending-count-pill"><?php echo count($pending_payments_global); ?></span>
      </h5>
      <a href="<?php echo base_url('pinjaman/verifikasi_pembayaran_list'); ?>" class="btn-lihat-semua">
        <i class="bi bi-list-check"></i> Lihat Semua
      </a>
    </div>
    <div class="pin-table-wrap">
      <table class="pin-table">
        <thead>
          <tr>
            <th>Warga</th>
            <th>Kode Pinjaman</th>
            <th>Angsuran</th>
            <th class="text-end">Nominal</th>
            <th>Metode</th>
            <th>Waktu Upload</th>
            <th class="text-center">Aksi</th>
          </tr>
        </thead>
        <tbody>
          <?php foreach(array_slice($pending_payments_global, 0, 5) as $pp): ?>
          <tr class="row-pending">
            <td>
              <div class="person-cell">
                <div class="person-avatar amber"><i class="bi bi-person-fill"></i></div>
                <span class="person-name"><?php echo htmlspecialchars($pp->nama_lengkap); ?></span>
              </div>
            </td>
            <td><span class="badge-code"><?php echo htmlspecialchars($pp->kode_pinjaman); ?></span></td>
            <td><span class="badge-ke">Ke-<?php echo $pp->angsuran_ke; ?></span></td>
            <td class="text-end" style="font-weight:700;">Rp <?php echo number_format($pp->nominal_bayar, 0, ',', '.'); ?></td>
            <td style="font-size:.82rem;"><?php echo ucfirst(str_replace('_', ' ', $pp->metode_bayar)); ?></td>
            <td><small style="color:var(--slate-400);"><?php echo date('d M Y H:i', strtotime($pp->created_at)); ?></small></td>
            <td class="text-center">
              <a href="<?php echo base_url('pinjaman/verifikasi_pembayaran/'.$pp->id); ?>" class="btn-proses">
                <i class="bi bi-check-lg"></i> Proses
              </a>
            </td>
          </tr>
          <?php endforeach; ?>
        </tbody>
      </table>
    </div>
    <?php if(count($pending_payments_global) > 5): ?>
    <a href="<?php echo base_url('pinjaman/verifikasi_pembayaran_list'); ?>" class="more-link">
      Lihat <?php echo count($pending_payments_global) - 5; ?> pembayaran lainnya <i class="bi bi-arrow-right"></i>
    </a>
    <?php endif; ?>
  </div>
  <?php endif; ?>

  <!-- ── Content Grid: Angsuran + Macet ── -->
  <div class="pin-content-grid">

    <!-- Jadwal Angsuran Hari Ini -->
    <div class="pin-card">
      <div class="pin-card-head">
        <h5><i class="bi bi-calendar2-check-fill"></i> Jadwal Angsuran Hari Ini</h5>
        <span class="card-date-pill"><?php echo date('d F Y'); ?></span>
      </div>
      <div class="pin-card-body" id="angsuranHariIni">
        <div class="skeleton mb-3" style="height:58px;"></div>
        <div class="skeleton mb-3" style="height:58px;"></div>
        <div class="skeleton" style="height:58px;"></div>
      </div>
    </div>

    <!-- Pinjaman Bermasalah -->
    <div class="pin-card">
      <div class="pin-card-head">
        <h5 class="danger"><i class="bi bi-exclamation-triangle-fill"></i> Pinjaman Bermasalah</h5>
      </div>
      <div class="pin-card-body">
        <?php if(empty($pinjaman_macet)): ?>
          <div class="pin-empty">
            <div class="ei green"><i class="bi bi-shield-check"></i></div>
            <p>Semua pinjaman dalam kondisi baik</p>
          </div>
        <?php else: ?>
          <?php foreach($pinjaman_macet as $pm): ?>
          <div class="macet-item">
            <div class="macet-avatar"><i class="bi bi-exclamation-triangle-fill"></i></div>
            <div class="macet-info">
              <div class="macet-name"><?php echo htmlspecialchars($pm->nama_lengkap); ?></div>
              <div class="macet-code"><?php echo htmlspecialchars($pm->kode_pinjaman); ?></div>
            </div>
            <a href="<?php echo base_url('pinjaman/detail/'.$pm->id); ?>" class="btn-detail">Detail</a>
          </div>
          <?php endforeach; ?>
        <?php endif; ?>
      </div>
    </div>

  </div>

  <!-- ── Quick Menu ── -->
  <div class="pin-card pin-card-quick">
    <div class="pin-card-head">
      <h5><i class="bi bi-grid-fill"></i> Menu Cepat</h5>
    </div>
    <div class="pin-card-body">
      <div class="pin-quick-grid">
        <a href="<?php echo base_url('pinjaman/pengajuan'); ?>" class="pin-quick-item q-teal">
          <i class="bi bi-file-earmark-text-fill"></i>
          <span>Data Pengajuan</span>
        </a>
        <a href="<?php echo base_url('pinjaman/data_pinjaman'); ?>" class="pin-quick-item q-green">
          <i class="bi bi-wallet2"></i>
          <span>Pinjaman Aktif</span>
        </a>
        <a href="<?php echo base_url('pinjaman/laporan'); ?>" class="pin-quick-item q-blue">
          <i class="bi bi-graph-up-arrow"></i>
          <span>Laporan</span>
        </a>
        <a href="<?php echo base_url('pinjaman/verifikasi_pembayaran_list'); ?>" class="pin-quick-item q-amber">
          <?php if(!is_warga() && isset($total_pending_verifikasi) && $total_pending_verifikasi > 0): ?>
            <span class="quick-notif"><?php echo $total_pending_verifikasi; ?></span>
          <?php endif; ?>
          <i class="bi bi-credit-card-fill"></i>
          <span>Verifikasi Bayar</span>
        </a>
      </div>
    </div>
  </div>

</div>

<script>
fetch('<?php echo base_url('pinjaman/cek_angsuran_hari_ini'); ?>')
  .then(r => r.json())
  .then(data => {
    const el = document.getElementById('angsuranHariIni');
    if (!data || !data.length) {
      el.innerHTML = `
        <div class="pin-empty">
          <div class="ei green"><i class="bi bi-check-circle-fill"></i></div>
          <p>Tidak ada angsuran jatuh tempo hari ini</p>
        </div>`;
      return;
    }

    let html = '';
    data.forEach(item => {
      const isPending = item.is_pending;
      const pendingTag = isPending
        ? `<span class="badge-pending-tag ms-1"><i class="bi bi-clock-history"></i> Menunggu Verifikasi</span>`
        : '';
      const btn = isPending
        ? `<a href="<?php echo base_url('pinjaman/verifikasi_pembayaran/'); ?>${item.pending_id}" class="btn-proses mt-1"><i class="bi bi-check-lg"></i> Verifikasi</a>`
        : `<a href="<?php echo base_url('pinjaman/bayar_angsuran/'); ?>${item.id}" class="btn-bayar mt-1"><i class="bi bi-cash-coin"></i> Bayar</a>`;

      html += `
        <div class="angsuran-item ${isPending ? 'is-pending' : ''}">
          <div class="person-avatar ${isPending ? 'amber' : 'teal'}">
            <i class="bi bi-person-fill"></i>
          </div>
          <div class="angsuran-info">
            <div class="angsuran-name">${item.nama_lengkap} ${pendingTag}</div>
            <div class="angsuran-meta">${item.kode_pinjaman} &bull; Angsuran ke-${item.angsuran_ke}</div>
          </div>
          <div class="angsuran-right">
            <div class="angsuran-amount ${isPending ? 'amber' : ''}">
              Rp ${parseInt(item.nominal_angsuran).toLocaleString('id-ID')}
            </div>
            ${btn}
          </div>
        </div>`;
    });

    el.innerHTML = html;
  })
  .catch(() => {
    document.getElementById('angsuranHariIni').innerHTML = `
      <div class="pin-empty">
        <div class="ei teal"><i class="bi bi-wifi-off"></i></div>
        <p>Gagal memuat data. Coba refresh halaman.</p>
      </div>`;
  });
</script>