<!-- CEK STATUS LAPORAN -->
<div style="background:linear-gradient(135deg,var(--clr-primary-d),var(--clr-primary));color:#fff;padding:40px 32px;text-align:center">
  <h1 style="font-size:1.8rem;font-weight:800">🔍 Cek Status Laporan</h1>
  <p style="color:rgba(255,255,255,0.75)">Masukkan kode laporan yang Anda terima saat mengirim laporan</p>
</div>

<div class="public-container" style="padding-top:36px;padding-bottom:60px;max-width:600px">
  <?= flashMessage() ?>

  <div class="card" style="margin-bottom:24px">
    <div class="card-body">
      <form method="POST" action="<?= APP_URL ?>/cek-laporan">
        <?= csrfField() ?>
        <div style="display:flex;gap:12px">
          <input type="text" name="kode_laporan" class="form-control"
                 placeholder="Contoh: LPR-20240501-0001" required
                 value="<?= e($kode ?? '') ?>" style="font-family:monospace;font-weight:600;letter-spacing:0.05em">
          <button type="submit" class="btn btn-primary" style="white-space:nowrap">🔍 Cek</button>
        </div>
      </form>
    </div>
  </div>

  <?php if (isset($laporan) && !$laporan && isset($kode) && $kode): ?>
  <div class="card">
    <div class="card-body" style="text-align:center;padding:40px">
      <div style="font-size:3rem">❓</div>
      <h3 style="margin:12px 0 6px">Laporan Tidak Ditemukan</h3>
      <p style="color:var(--clr-text-muted)">Kode laporan <strong><?= e($kode) ?></strong> tidak ditemukan. Pastikan kode sudah benar.</p>
    </div>
  </div>
  <?php elseif (isset($laporan) && $laporan): ?>
  <div class="card">
    <div class="card-header"><span class="card-icon">📋</span><h3>Hasil Pencarian</h3></div>
    <div class="card-body">
      <!-- Status Bar -->
      <?php
      $steps = ['menunggu'=>1,'diproses'=>2,'terverifikasi'=>3,'ditolak'=>-1];
      $cur = $steps[$laporan['status']] ?? 1;
      $colors = ['menunggu'=>'#d97706','diproses'=>'#0284c7','terverifikasi'=>'#16a34a','ditolak'=>'#dc2626'];
      $icons  = ['menunggu'=>'⏳','diproses'=>'🔄','terverifikasi'=>'✅','ditolak'=>'❌'];
      ?>
      <div style="text-align:center;margin-bottom:24px">
        <div style="font-size:2.5rem;margin-bottom:8px"><?= $icons[$laporan['status']] ?? '❓' ?></div>
        <div style="font-size:1.1rem;font-weight:800;color:<?= $colors[$laporan['status']] ?? '#6b7280' ?>">
          <?= ucfirst($laporan['status']) ?>
        </div>
        <div style="font-size:0.82rem;color:var(--clr-text-muted);margin-top:4px">
          Kode: <strong style="font-family:monospace"><?= e($laporan['kode_laporan']) ?></strong>
        </div>
      </div>

      <?php if ($laporan['status'] !== 'ditolak'): ?>
      <!-- Progress Steps -->
      <div style="display:flex;align-items:center;gap:0;margin-bottom:24px">
        <?php $stepLabels = ['Laporan Dikirim','Sedang Diproses','Terverifikasi']; ?>
        <?php foreach ($stepLabels as $i => $sl): ?>
        <div style="flex:1;text-align:center">
          <div style="width:32px;height:32px;border-radius:50%;margin:0 auto 4px;display:flex;align-items:center;justify-content:center;font-weight:700;font-size:0.85rem;
            background:<?= $i+1<=$cur?'var(--clr-success)':'#e2e8f0' ?>;
            color:<?= $i+1<=$cur?'#fff':'#94a3b8' ?>">
            <?= $i+1<=$cur?'✓':($i+1) ?>
          </div>
          <div style="font-size:0.72rem;color:<?= $i+1<=$cur?'var(--clr-success)':'#94a3b8' ?>;font-weight:<?= $i+1<=$cur?'600':'400' ?>">
            <?= $sl ?>
          </div>
        </div>
        <?php if ($i < 2): ?>
        <div style="flex:1;height:2px;background:<?= $i+1<$cur?'var(--clr-success)':'#e2e8f0' ?>;margin-bottom:20px"></div>
        <?php endif; ?>
        <?php endforeach; ?>
      </div>
      <?php endif; ?>

      <!-- Detail -->
      <div style="display:grid;gap:10px">
        <?php $rows = [
          ['Nama Warga', $laporan['nama_warga']],
          ['Wilayah', ($laporan['kelurahan']??'').", ".($laporan['kecamatan']??'')],
          ['Tanggal Laporan', formatTanggal($laporan['created_at'],true)],
          ['Tanggal Verifikasi', $laporan['tanggal_verifikasi'] ? formatTanggal($laporan['tanggal_verifikasi'],true) : '—'],
        ]; foreach($rows as [$l,$v]): ?>
        <div style="display:flex;gap:12px;padding:8px 0;border-bottom:1px solid #f1f5f9">
          <div style="font-size:0.8rem;color:var(--clr-text-muted);min-width:130px"><?= $l ?></div>
          <div style="font-size:0.875rem;font-weight:500"><?= e($v) ?></div>
        </div>
        <?php endforeach; ?>
        <?php if ($laporan['catatan_verifikator']): ?>
        <div style="margin-top:8px;padding:12px;background:#f8fafc;border-radius:8px;border-left:3px solid var(--clr-primary)">
          <div style="font-size:0.75rem;color:var(--clr-text-muted);margin-bottom:4px">Catatan Petugas:</div>
          <div style="font-size:0.875rem"><?= nl2br(e($laporan['catatan_verifikator'])) ?></div>
        </div>
        <?php endif; ?>
      </div>
    </div>
  </div>
  <?php endif; ?>

  <div style="margin-top:20px;text-align:center">
    <a href="<?= APP_URL ?>/lapor" style="color:var(--clr-text-muted);font-size:0.85rem">Buat laporan baru →</a>
  </div>
</div>
