<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Notulen Rapat — <?php echo htmlspecialchars($n->judul_rapat); ?></title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --teal-900: #0b5a52;
  --teal-700: #0b7a6e;
  --teal-600: #0d9488;
  --teal-500: #14b8a6;
  --teal-100: #ccfbf1;
  --teal-50:  #f0fdfa;
  --navy:     #1e3a5f;
  --slate-900: #0f172a;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-400: #94a3b8;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-50:  #f8fafc;
  --amber-100: #fef3c7;
  --amber-500: #f59e0b;
  --red-100:   #fee2e2;
  --red-700:   #991b1b;
  --green-100: #dcfce7;
  --green-700: #166534;
}

body {
  font-family: 'Inter', Arial, sans-serif;
  font-size: 12px;
  color: var(--slate-900);
  background: #eef2f7;
  line-height: 1.5;
}

.page-wrap {
  max-width: 820px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

/* ─── ACTION BAR (layar saja) ─── */
.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: #fff;
  border-radius: 12px;
  padding: 11px 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 6px rgba(0,0,0,.08);
}
.ab-left {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; font-weight: 800; color: var(--teal-900);
}
.ab-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--teal-600), var(--teal-500));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px;
}
.ab-right { display: flex; gap: 7px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 16px; border-radius: 50px; border: none;
  font-size: 11.5px; font-weight: 700; cursor: pointer;
  text-decoration: none; font-family: 'Inter', sans-serif;
  transition: all .15s; white-space: nowrap;
}
.btn-back  { background: var(--slate-100); color: var(--slate-700); border: 1.5px solid var(--slate-200); }
.btn-back:hover  { background: var(--slate-200); }
.btn-print { background: linear-gradient(135deg, var(--teal-700), var(--teal-500)); color: #fff; }
.btn-print:hover { transform: translateY(-1px); color: #fff; }

/* ─── DOC HEADER ─── */
.doc-header {
  background: #fff;
  border-radius: 12px;
  padding: 18px 20px 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
  border-top: 4px solid var(--teal-600);
}
.dh-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}
.dh-title {
  font-size: 17px; font-weight: 900;
  color: var(--teal-900); letter-spacing: -.3px;
  margin-bottom: 5px;
}
.dh-sub { font-size: 10.5px; color: var(--slate-500); line-height: 1.75; }
.dh-sub strong { color: var(--slate-700); }
.dh-right { text-align: right; font-size: 10.5px; color: var(--slate-500); line-height: 1.75; white-space: nowrap; }
.dh-right strong { color: var(--slate-700); }

.status-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 12px; border-radius: 999px;
  font-size: 10px; font-weight: 800;
}
.sp-draft    { background: var(--slate-100); color: var(--slate-600); }
.sp-menunggu { background: var(--amber-100); color: #92400e; }
.sp-final    { background: var(--green-100); color: var(--green-700); }

.meta-strip {
  display: flex; flex-wrap: wrap;
  border-top: 1px solid var(--slate-100);
  padding-top: 12px;
}
.meta-item {
  display: flex; align-items: flex-start; gap: 7px;
  flex: 0 0 33.33%; min-width: 140px;
  padding: 0 12px 10px 0;
}
.meta-item i { color: var(--teal-600); font-size: 13px; margin-top: 1px; flex-shrink: 0; }
.meta-label  { font-size: 9px; color: var(--slate-400); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 1px; }
.meta-value  { font-size: 11px; font-weight: 700; color: var(--slate-700); }

/* ─── SECTION CARDS ─── */
.section-card {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 8px rgba(0,0,0,.07);
  margin-bottom: 12px;
}
.sc-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(90deg, var(--teal-50), #fff);
  border-bottom: 1.5px solid rgba(13,148,136,.1);
}
.sc-title {
  font-size: 12px; font-weight: 800; color: var(--slate-900);
  display: flex; align-items: center; gap: 6px;
}
.sc-title i { color: var(--teal-600); }
.sc-pill {
  background: var(--teal-50); color: var(--teal-700);
  border: 1px solid var(--teal-100);
  padding: 3px 11px; border-radius: 999px;
  font-size: 10px; font-weight: 700;
}

/* ─── TABLE ─── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead tr { background: var(--navy); }
.data-table thead th {
  color: #fff; font-size: 8px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  padding: 9px 10px; text-align: left; white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,.07);
}
.data-table thead th:last-child { border-right: none; }
.data-table tbody tr { border-bottom: 1px solid #f0f4f8; }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--teal-50) !important; }
.data-table tbody td { padding: 8px 10px; vertical-align: middle; font-size: 11px; }

.tc  { text-align: center; }
.num { color: var(--slate-400); font-weight: 700; font-size: 9.5px; }
.nama-text { font-weight: 700; font-size: 11px; color: var(--slate-900); }

.hadir-badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 9px; border-radius: 999px; font-size: 9.5px; font-weight: 800;
}
.hb-hadir { background: var(--green-100); color: var(--green-700); }
.hb-tidak { background: var(--red-100);   color: var(--red-700); }
.hb-izin  { background: var(--amber-100); color: #92400e; }

.hc-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px; font-size: 10px; font-weight: 700;
}
.hc-hadir { background: var(--green-100); color: var(--green-700); }
.hc-tidak { background: var(--red-100);   color: var(--red-700); }
.hc-izin  { background: var(--amber-100); color: #92400e; }

/* ─── POIN ─── */
.poin-list { padding: 14px 16px; }
.poin-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 12px; border-radius: 9px;
  border: 1.5px solid var(--slate-200);
  background: var(--slate-50); margin-bottom: 8px;
}
.poin-item:last-child { margin-bottom: 0; }
.poin-num {
  min-width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 900; color: #fff; flex-shrink: 0;
}
.pn-tinggi { background: #dc2626; }
.pn-sedang { background: var(--amber-500); }
.pn-rendah { background: var(--slate-400); }
.poin-text { flex: 1; font-size: 11.5px; font-weight: 600; color: var(--slate-700); line-height: 1.55; }
.prio-badge {
  padding: 2px 9px; border-radius: 999px; font-size: 9.5px; font-weight: 800; flex-shrink: 0;
}
.pb-tinggi { background: var(--red-100);   color: var(--red-700); }
.pb-sedang { background: var(--amber-100); color: #92400e; }
.pb-rendah { background: var(--slate-100); color: var(--slate-600); }

/* ─── CATATAN ─── */
.catatan-wrap { padding: 14px 16px; }
.catatan-box {
  background: var(--teal-50); border: 1.5px solid var(--teal-100);
  border-radius: 10px; padding: 14px 16px;
  font-size: 11.5px; color: var(--slate-700); line-height: 1.75;
}

/* ─── TANDA TANGAN ─── */
.ttd-section {
  background: #fff; border-radius: 12px;
  padding: 16px 20px;
  box-shadow: 0 1px 6px rgba(0,0,0,.07); margin-bottom: 12px;
}
.ttd-title {
  font-size: 11px; font-weight: 800; color: var(--slate-500);
  text-transform: uppercase; letter-spacing: .07em; margin-bottom: 16px;
}
.ttd-grid  { display: flex; justify-content: space-around; }
.ttd-item  { flex: 1; text-align: center; padding: 0 10px; }
.ttd-role  { font-size: 10px; font-weight: 700; color: var(--slate-500); margin-bottom: 2px; }
.ttd-name  { font-size: 11.5px; font-weight: 800; color: var(--slate-700); }
.ttd-space { height: 52px; border-bottom: 1.5px solid var(--slate-300); margin: 10px 20px 4px; }
.ttd-date  { font-size: 9.5px; color: var(--slate-400); margin-top: 3px; }

/* ─── FOOTER ─── */
.doc-footer {
  margin-top: 14px;
  display: flex; justify-content: space-between; align-items: flex-start;
  flex-wrap: wrap; gap: 10px;
  background: #fff; border-radius: 10px; padding: 12px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  font-size: 10px; color: var(--slate-500); line-height: 1.7;
}
.doc-footer strong { color: var(--slate-700); }

/* ─── PRINT ─── */
@media print {
  @page { size: A4 portrait; margin: 10mm 8mm; }
  body { background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .action-bar  { display: none !important; }
  .page-wrap   { padding: 0; max-width: 100%; }
  .doc-header  { border-radius: 0; padding: 10px 12px 8px; margin-bottom: 8px; box-shadow: none; border-top: 3px solid var(--teal-600); }
  .dh-title    { font-size: 14px; }
  .dh-sub, .dh-right { font-size: 8.5px; }
  .meta-value  { font-size: 9.5px; }
  .meta-label  { font-size: 8px; }
  .section-card { border-radius: 0; box-shadow: none; border: 1px solid var(--slate-200); margin-bottom: 8px; }
  .sc-header   { padding: 6px 10px; }
  .sc-title    { font-size: 10px; }
  .data-table thead th { padding: 6px 7px; font-size: 7px; }
  .data-table tbody td { padding: 5px 7px; font-size: 9px; }
  .nama-text   { font-size: 9px; }
  .hadir-badge, .prio-badge { font-size: 8px; padding: 1px 6px; }
  .poin-list   { padding: 8px 10px; }
  .poin-item   { padding: 7px 9px; margin-bottom: 5px; }
  .poin-text   { font-size: 9.5px; }
  .poin-num    { min-width: 22px; height: 22px; font-size: 9px; }
  .catatan-wrap { padding: 8px 10px; }
  .catatan-box  { padding: 8px 12px; font-size: 9.5px; }
  .ttd-section { border-radius: 0; box-shadow: none; border: 1px solid var(--slate-200); padding: 10px 14px; margin-bottom: 8px; }
  .ttd-space   { height: 40px; }
  .doc-footer  { margin-top: 6px; padding: 7px 12px; border-radius: 0; box-shadow: none; border-top: 1px solid var(--slate-200); font-size: 7.5px; }
  tbody tr { page-break-inside: avoid; }
}
</style>
</head>
<body>
<?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'));
$total_peserta = count($peserta);

$status_label = ['draft' => 'Draft', 'menunggu' => 'Menunggu Persetujuan', 'final' => 'Final'];
$status_cls   = ['draft' => 'sp-draft', 'menunggu' => 'sp-menunggu', 'final' => 'sp-final'];
$status_icon  = ['draft' => 'pencil-square', 'menunggu' => 'hourglass-split', 'final' => 'check-circle-fill'];
$av_colors    = ['#0d9488','#3b82f6','#f59e0b','#10b981','#8b5cf6','#ef4444'];
?>

<div class="page-wrap">

  <!-- ACTION BAR (hanya tampil di layar) -->
  <div class="action-bar">
    <div class="ab-left">
      <div class="ab-icon"><i class="bi bi-journal-check"></i></div>
      Cetak Notulen Rapat
    </div>
    <div class="ab-right">
      <a href="<?php echo base_url('notulen/detail/' . $n->id); ?>" class="btn btn-back">
        <i class="bi bi-arrow-left"></i> Kembali
      </a>
      <button onclick="window.print()" class="btn btn-print">
        <i class="bi bi-printer-fill"></i> Cetak / PDF
      </button>
    </div>
  </div>

  <!-- DOC HEADER -->
  <div class="doc-header">
    <div class="dh-top">
      <div style="flex:1;min-width:0;">
        <div style="margin-bottom:6px;">
          <span class="status-pill <?php echo $status_cls[$n->status] ?? 'sp-draft'; ?>">
            <i class="bi bi-<?php echo $status_icon[$n->status] ?? 'pencil-square'; ?>"></i>
            <?php echo $status_label[$n->status] ?? ucfirst($n->status); ?>
          </span>
          &nbsp;
          <span style="font-size:10px;font-weight:700;color:var(--teal-600);background:var(--teal-50);border:1px solid var(--teal-100);padding:3px 10px;border-radius:999px;">
            <?php echo htmlspecialchars($n->tim); ?>
          </span>
        </div>
        <div class="dh-title"><?php echo htmlspecialchars($n->judul_rapat); ?></div>
        <div class="dh-sub">
          Moderator: <strong><?php echo htmlspecialchars($n->moderator); ?></strong>
          &nbsp;·&nbsp;
          Notulis: <strong><?php echo htmlspecialchars($n->notulis); ?></strong>
          &nbsp;·&nbsp;
          Peserta: <strong><?php echo $total_peserta; ?> orang</strong> (<?php echo $jml_hadir; ?> hadir)
        </div>
      </div>
      <div class="dh-right">
        Dicetak: <strong><?php echo date('d/m/Y H:i'); ?> WIB</strong><br>
        <?php echo date('l, d F Y', strtotime($n->tanggal)); ?>
      </div>
    </div>

    <div class="meta-strip">
      <div class="meta-item">
        <i class="bi bi-calendar3"></i>
        <div>
          <div class="meta-label">Tanggal</div>
          <div class="meta-value"><?php echo date('d F Y', strtotime($n->tanggal)); ?></div>
        </div>
      </div>
      <div class="meta-item">
        <i class="bi bi-clock"></i>
        <div>
          <div class="meta-label">Waktu</div>
          <div class="meta-value">
            <?php echo $n->waktu_mulai ? date('H:i', strtotime($n->waktu_mulai)) : '-'; ?>
            <?php echo $n->waktu_selesai ? ' – ' . date('H:i', strtotime($n->waktu_selesai)) : ''; ?>
          </div>
        </div>
      </div>
      <div class="meta-item">
        <i class="bi bi-geo-alt"></i>
        <div>
          <div class="meta-label">Tempat</div>
          <div class="meta-value"><?php echo htmlspecialchars($n->tempat); ?></div>
        </div>
      </div>
      <div class="meta-item">
        <i class="bi bi-tag"></i>
        <div>
          <div class="meta-label">Tim / Proyek</div>
          <div class="meta-value"><?php echo htmlspecialchars($n->tim); ?></div>
        </div>
      </div>
      <div class="meta-item">
        <i class="bi bi-person-workspace"></i>
        <div>
          <div class="meta-label">Moderator</div>
          <div class="meta-value"><?php echo htmlspecialchars($n->moderator); ?></div>
        </div>
      </div>
      <div class="meta-item">
        <i class="bi bi-journal-text"></i>
        <div>
          <div class="meta-label">Notulis</div>
          <div class="meta-value"><?php echo htmlspecialchars($n->notulis); ?></div>
        </div>
      </div>
    </div>
  </div>

  <!-- DAFTAR HADIR -->
  <div class="section-card">
    <div class="sc-header">
      <div class="sc-title">
        <i class="bi bi-person-check"></i> Daftar Hadir Peserta
      </div>
      <div style="display:flex;gap:6px;align-items:center;">
        <span class="hc-pill hc-hadir">✅ <?php echo $jml_hadir; ?> hadir</span>
        <?php if ($jml_tidak): ?>
        <span class="hc-pill hc-tidak">❌ <?php echo $jml_tidak; ?> tidak</span>
        <?php endif; ?>
        <?php if ($jml_izin): ?>
        <span class="hc-pill hc-izin">📝 <?php echo $jml_izin; ?> izin</span>
        <?php endif; ?>
      </div>
    </div>

    <?php if (!empty($peserta)): ?>
    <table class="data-table">
      <thead>
        <tr>
          <th style="width:36px;">No</th>
          <th>Nama Peserta</th>
          <th style="width:190px;">Jabatan / Peran</th>
          <th style="width:110px;" class="tc">Kehadiran</th>
        </tr>
      </thead>
      <tbody>
        <?php foreach ($peserta as $idx => $p):
          $words    = array_filter(explode(' ', $p->nama));
          $initials = implode('', array_map(fn($w) => strtoupper($w[0]), array_slice(array_values($words), 0, 2)));
          $bg       = $idx % 2 === 0 ? '#fff' : '#f8fafc';
        ?>
        <tr style="background:<?php echo $bg; ?>;">
          <td class="tc num"><?php echo $idx + 1; ?></td>
          <td>
            <div style="display:flex;align-items:center;gap:9px;">
              <div style="width:30px;height:30px;border-radius:50%;background:<?php echo $av_colors[$idx % count($av_colors)]; ?>;display:flex;align-items:center;justify-content:center;font-size:10px;font-weight:900;color:#fff;flex-shrink:0;">
                <?php echo htmlspecialchars($initials); ?>
              </div>
              <div class="nama-text"><?php echo htmlspecialchars($p->nama); ?></div>
            </div>
          </td>
          <td style="font-size:10.5px;color:var(--slate-600);"><?php echo htmlspecialchars($p->jabatan); ?></td>
          <td class="tc">
            <?php if ($p->kehadiran === 'hadir'): ?>
              <span class="hadir-badge hb-hadir">✅ Hadir</span>
            <?php elseif ($p->kehadiran === 'tidak'): ?>
              <span class="hadir-badge hb-tidak">❌ Tidak Hadir</span>
            <?php else: ?>
              <span class="hadir-badge hb-izin">📝 Izin</span>
            <?php endif; ?>
          </td>
        </tr>
        <?php endforeach; ?>
      </tbody>
    </table>
    <?php else: ?>
    <div style="padding:40px 20px;text-align:center;color:var(--slate-400);">
      <i class="bi bi-people" style="font-size:32px;display:block;margin-bottom:8px;opacity:.5;"></i>
      <div style="font-weight:700;color:var(--slate-500);">Belum ada peserta tercatat</div>
    </div>
    <?php endif; ?>
  </div>

  <!-- POIN PEMBAHASAN -->
  <div class="section-card">
    <div class="sc-header">
      <div class="sc-title">
        <i class="bi bi-list-ol"></i> Poin Pembahasan
      </div>
      <span class="sc-pill"><?php echo count($poin); ?> poin</span>
    </div>

    <?php if (!empty($poin)): ?>
    <div class="poin-list">
      <?php foreach ($poin as $idx => $p):
        $pn_cls   = 'pn-' . $p->prioritas;
        $pb_cls   = 'pb-' . $p->prioritas;
        $pr_label = $p->prioritas === 'tinggi' ? '🔴 Tinggi' : ($p->prioritas === 'sedang' ? '🟡 Sedang' : '⚪ Rendah');
      ?>
      <div class="poin-item">
        <div class="poin-num <?php echo $pn_cls; ?>"><?php echo $idx + 1; ?></div>
        <div class="poin-text"><?php echo htmlspecialchars($p->teks); ?></div>
        <span class="prio-badge <?php echo $pb_cls; ?>"><?php echo $pr_label; ?></span>
      </div>
      <?php endforeach; ?>
    </div>
    <?php else: ?>
    <div style="padding:40px 20px;text-align:center;color:var(--slate-400);">
      <i class="bi bi-list-ul" style="font-size:32px;display:block;margin-bottom:8px;opacity:.5;"></i>
      <div style="font-weight:700;color:var(--slate-500);">Belum ada poin pembahasan</div>
    </div>
    <?php endif; ?>
  </div>

  <!-- CATATAN & KESIMPULAN -->
  <?php if (!empty($n->catatan)): ?>
  <div class="section-card">
    <div class="sc-header">
      <div class="sc-title">
        <i class="bi bi-sticky"></i> Catatan &amp; Kesimpulan
      </div>
    </div>
    <div class="catatan-wrap">
      <div class="catatan-box"><?php echo nl2br(htmlspecialchars($n->catatan)); ?></div>
    </div>
  </div>
  <?php endif; ?>

  <!-- TANDA TANGAN -->
  <div class="ttd-section">
    <div class="ttd-title">Pengesahan</div>
    <div class="ttd-grid">
      <div class="ttd-item">
        <div class="ttd-role">Notulis</div>
        <div class="ttd-name"><?php echo htmlspecialchars($n->notulis); ?></div>
        <div class="ttd-space"></div>
        <div class="ttd-date">(____________________)</div>
      </div>
      <div class="ttd-item">
        <div class="ttd-role">Moderator / Pimpinan Rapat</div>
        <div class="ttd-name"><?php echo htmlspecialchars($n->moderator); ?></div>
        <div class="ttd-space"></div>
        <div class="ttd-date">(____________________)</div>
      </div>
      <div class="ttd-item">
        <div class="ttd-role">Mengetahui</div>
        <div class="ttd-name">&nbsp;</div>
        <div class="ttd-space"></div>
        <div class="ttd-date">(____________________)</div>
      </div>
    </div>
  </div>

  <!-- FOOTER -->
  <div class="doc-footer">
    <div>
      Notulen rapat ini dibuat secara otomatis oleh sistem.<br>
      <strong>Tim/Proyek:</strong> <?php echo htmlspecialchars($n->tim); ?>
      &nbsp;·&nbsp;
      <strong>Tanggal Rapat:</strong> <?php echo date('d F Y', strtotime($n->tanggal)); ?>
      &nbsp;·&nbsp;
      <strong>Total Peserta:</strong> <?php echo $total_peserta; ?> orang
    </div>
    <div style="text-align:right;">
      Dicetak: <?php echo date('d F Y, H:i'); ?> WIB<br>
      <strong><?php echo $jml_hadir; ?>/<?php echo $total_peserta; ?> hadir</strong>
    </div>
  </div>

</div>
</body>
</html>