<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<style>
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body { font-family: 'DejaVu Sans', Arial, sans-serif; font-size: 11pt; color: #1e293b; }

  /* HEADER SURAT */
  .kop-surat {
    text-align: center;
    border-bottom: 3px solid #0d9488;
    padding-bottom: 12px;
    margin-bottom: 18px;
  }
  .kop-title { font-size: 16pt; font-weight: bold; color: #0b5a52; margin-bottom: 2px; }
  .kop-sub   { font-size: 10pt; color: #64748b; }
  .kop-rt    { font-size: 11pt; font-weight: bold; color: #0d9488; margin-bottom: 4px; }

  /* JUDUL NOTULEN */
  .notulen-title-box {
    background: #0b5a52;
    color: white;
    padding: 14px 18px;
    border-radius: 6px;
    margin-bottom: 16px;
  }
  .notulen-title-box h1 { font-size: 14pt; font-weight: bold; margin-bottom: 4px; }
  .notulen-title-box .meta { font-size: 9pt; opacity: 0.85; }

  /* INFO TABLE */
  .info-table { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
  .info-table td { padding: 7px 10px; font-size: 10pt; vertical-align: top; }
  .info-table td:first-child { width: 140px; color: #64748b; font-weight: bold; }
  .info-table tr { border-bottom: 1px solid #f1f5f9; }

  /* SECTION */
  .section-title {
    font-size: 11pt; font-weight: bold; color: #0d9488;
    border-left: 4px solid #0d9488;
    padding: 4px 10px;
    background: #f0fdfa;
    margin-bottom: 10px;
    margin-top: 18px;
  }

  /* HADIR TABLE */
  .hadir-table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
  .hadir-table th {
    background: #0d9488; color: white;
    font-size: 9.5pt; padding: 7px 10px; text-align: left;
  }
  .hadir-table td { padding: 7px 10px; font-size: 10pt; border-bottom: 1px solid #e2e8f0; }
  .hadir-table tr:nth-child(even) td { background: #f8fafc; }
  .badge-hadir { background: #dcfce7; color: #166534; padding: 2px 8px; border-radius: 10px; font-size: 8.5pt; font-weight: bold; }
  .badge-tidak { background: #fee2e2; color: #991b1b; padding: 2px 8px; border-radius: 10px; font-size: 8.5pt; font-weight: bold; }
  .badge-izin  { background: #fef3c7; color: #92400e;  padding: 2px 8px; border-radius: 10px; font-size: 8.5pt; font-weight: bold; }

  /* POIN TABLE */
  .poin-table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
  .poin-table th {
    background: #0d9488; color: white;
    font-size: 9.5pt; padding: 7px 10px; text-align: left;
  }
  .poin-table td { padding: 8px 10px; font-size: 10pt; border-bottom: 1px solid #e2e8f0; vertical-align: middle; }
  .poin-table tr:nth-child(even) td { background: #f8fafc; }
  .num-circle {
    display: inline-block; width: 22px; height: 22px; border-radius: 50%;
    text-align: center; line-height: 22px;
    font-size: 8.5pt; font-weight: bold; color: white;
  }
  .num-tinggi { background: #dc2626; }
  .num-sedang { background: #f59e0b; }
  .num-rendah { background: #94a3b8; }
  .badge-tinggi { background: #fee2e2; color: #991b1b; padding: 2px 8px; border-radius: 10px; font-size: 8.5pt; font-weight: bold; }
  .badge-sedang { background: #fef3c7; color: #92400e;  padding: 2px 8px; border-radius: 10px; font-size: 8.5pt; font-weight: bold; }
  .badge-rendah { background: #f1f5f9; color: #64748b;  padding: 2px 8px; border-radius: 10px; font-size: 8.5pt; font-weight: bold; }

  /* STATUS */
  .status-pill {
    display: inline-block; padding: 3px 12px; border-radius: 20px;
    font-size: 9pt; font-weight: bold;
  }
  .s-draft    { background: #f1f5f9; color: #64748b; }
  .s-menunggu { background: #fef3c7; color: #92400e; }
  .s-final    { background: #dcfce7; color: #166534; }

  /* CATATAN */
  .catatan-box {
    background: #f0fdfa; border: 1px solid #ccfbf1;
    border-radius: 6px; padding: 12px; font-size: 10pt;
    line-height: 1.7; color: #334155; margin-top: 4px;
  }

  /* TTD SECTION */
  .ttd-section { margin-top: 30px; }
  .ttd-table { width: 100%; border-collapse: collapse; }
  .ttd-table td { padding: 10px; text-align: center; width: 33%; }
  .ttd-box {
    border: 1.5px solid #e2e8f0; border-radius: 8px;
    padding: 12px 10px; min-height: 90px;
  }
  .ttd-label { font-size: 9.5pt; font-weight: bold; color: #64748b; margin-bottom: 55px; }
  .ttd-name  { font-size: 10pt; font-weight: bold; border-top: 1px solid #334155; padding-top: 6px; margin-top: 4px; }

  /* FOOTER */
  .pdf-footer {
    margin-top: 24px; padding-top: 10px;
    border-top: 1px solid #e2e8f0;
    font-size: 8.5pt; color: #94a3b8; text-align: center;
  }

  .divider { border: none; border-top: 1px solid #e2e8f0; margin: 14px 0; }
  .hadir-summary { font-size: 9.5pt; color: #64748b; margin-bottom: 8px; }
</style>
</head>
<body>

  <!-- KOP SURAT -->
  <div class="kop-surat">
    <div class="kop-title">NOTULEN RAPAT</div>
    <div class="kop-rt">RT 05 / RW 02 – Kelurahan Harapan Jaya</div>
    <div class="kop-sub">Dokumen Resmi — Dicetak <?= date('d F Y H:i') ?> WIB</div>
  </div>

  <!-- JUDUL -->
  <div class="notulen-title-box">
    <h1><?= htmlspecialchars($n->judul_rapat) ?></h1>
    <div class="meta">
      Tim: <?= htmlspecialchars($n->tim) ?> &nbsp;|&nbsp;
      <?= date('l, d F Y', strtotime($n->tanggal)) ?> &nbsp;|&nbsp;
      <?= $n->waktu_mulai ? date('H:i', strtotime($n->waktu_mulai)) : '-' ?>
      <?= $n->waktu_selesai ? '–' . date('H:i', strtotime($n->waktu_selesai)) : '' ?> WIB
    </div>
  </div>

  <!-- INFO RAPAT -->
  <table class="info-table">
    <tr>
      <td>Tanggal</td>
      <td>: <?= date('l, d F Y', strtotime($n->tanggal)) ?></td>
      <td>Waktu</td>
      <td>: <?= $n->waktu_mulai ? date('H:i', strtotime($n->waktu_mulai)) : '-' ?>
             <?= $n->waktu_selesai ? '–' . date('H:i', strtotime($n->waktu_selesai)) : '' ?> WIB</td>
    </tr>
    <tr>
      <td>Tempat</td>
      <td>: <?= htmlspecialchars($n->tempat) ?></td>
      <td>Tim / Proyek</td>
      <td>: <?= htmlspecialchars($n->tim) ?></td>
    </tr>
    <tr>
      <td>Moderator</td>
      <td>: <?= htmlspecialchars($n->moderator) ?></td>
      <td>Notulis</td>
      <td>: <?= htmlspecialchars($n->notulis) ?></td>
    </tr>
    <tr>
      <td>Status</td>
      <td colspan="3">:
        <?php if ($n->status === 'draft'): ?>
          <span class="status-pill s-draft">Draft</span>
        <?php elseif ($n->status === 'menunggu'): ?>
          <span class="status-pill s-menunggu">Menunggu Persetujuan</span>
        <?php else: ?>
          <span class="status-pill s-final">Final / Disetujui</span>
        <?php endif; ?>
      </td>
    </tr>
  </table>

  <!-- DAFTAR HADIR -->
  <div class="section-title">I. Daftar Hadir</div>
  <?php
  $jml_hadir = count(array_filter($peserta, fn($p) => $p->kehadiran === 'hadir'));
  $jml_tidak = count(array_filter($peserta, fn($p) => $p->kehadiran === 'tidak'));
  $jml_izin  = count(array_filter($peserta, fn($p) => $p->kehadiran === 'izin'));
  ?>
  <div class="hadir-summary">
    Total: <?= count($peserta) ?> peserta &nbsp;|&nbsp;
    Hadir: <?= $jml_hadir ?> &nbsp;|&nbsp;
    Tidak Hadir: <?= $jml_tidak ?> &nbsp;|&nbsp;
    Izin: <?= $jml_izin ?>
  </div>
  <table class="hadir-table">
    <thead>
      <tr>
        <th style="width:36px;">No</th>
        <th>Nama</th>
        <th>Jabatan</th>
        <th style="width:110px;">Kehadiran</th>
      </tr>
    </thead>
    <tbody>
      <?php foreach ($peserta as $idx => $p): ?>
      <tr>
        <td style="text-align:center;"><?= $idx + 1 ?></td>
        <td><?= htmlspecialchars($p->nama) ?></td>
        <td><?= htmlspecialchars($p->jabatan) ?></td>
        <td>
          <?php if ($p->kehadiran === 'hadir'): ?>
            <span class="badge-hadir">Hadir</span>
          <?php elseif ($p->kehadiran === 'tidak'): ?>
            <span class="badge-tidak">Tidak Hadir</span>
          <?php else: ?>
            <span class="badge-izin">Izin</span>
          <?php endif; ?>
        </td>
      </tr>
      <?php endforeach; ?>
    </tbody>
  </table>

  <!-- POIN PEMBAHASAN -->
  <div class="section-title">II. Poin Pembahasan</div>
  <table class="poin-table">
    <thead>
      <tr>
        <th style="width:36px;">No</th>
        <th>Topik Pembahasan</th>
        <th style="width:100px;">Prioritas</th>
      </tr>
    </thead>
    <tbody>
      <?php foreach ($poin as $idx => $p):
        $num_cls = 'num-' . $p->prioritas;
        $badge_cls = 'badge-' . $p->prioritas;
        $pr_label = $p->prioritas === 'tinggi' ? 'Tinggi' : ($p->prioritas === 'sedang' ? 'Sedang' : 'Rendah');
      ?>
      <tr>
        <td style="text-align:center;">
          <span class="num-circle <?= $num_cls ?>"><?= $idx + 1 ?></span>
        </td>
        <td><?= htmlspecialchars($p->teks) ?></td>
        <td><span class="<?= $badge_cls ?>"><?= $pr_label ?></span></td>
      </tr>
      <?php endforeach; ?>
    </tbody>
  </table>

  <!-- CATATAN / KESIMPULAN -->
  <?php if ($n->catatan): ?>
  <div class="section-title">III. Catatan &amp; Kesimpulan</div>
  <div class="catatan-box"><?= nl2br(htmlspecialchars($n->catatan)) ?></div>
  <?php endif; ?>

  <!-- TANDA TANGAN -->
  <div class="ttd-section">
    <div class="section-title">IV. Pengesahan</div>
    <table class="ttd-table">
      <tr>
        <td>
          <div class="ttd-box">
            <div class="ttd-label">Notulis</div>
            <div class="ttd-name"><?= htmlspecialchars($n->notulis) ?></div>
          </div>
        </td>
        <td>
          <div class="ttd-box">
            <div class="ttd-label">Moderator / Pimpinan Rapat</div>
            <div class="ttd-name"><?= htmlspecialchars($n->moderator) ?></div>
          </div>
        </td>
        <td>
          <div class="ttd-box">
            <div class="ttd-label">Mengetahui, Ketua RT</div>
            <div class="ttd-name">________________________</div>
          </div>
        </td>
      </tr>
    </table>
  </div>

  <!-- FOOTER -->
  <div class="pdf-footer">
    Dokumen ini dicetak secara otomatis dari Sistem Informasi RT 05 &nbsp;•&nbsp;
    <?= date('d F Y H:i') ?> WIB &nbsp;•&nbsp;
    Halaman ini bersifat resmi apabila telah ditandatangani
  </div>

</body>
</html>
