<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Preview Modul Ajar - <?= esc($device['subject_name'] ?? '') ?></title>
    <style>
        @page { margin: 25mm 20mm 25mm 20mm; }
        * { box-sizing: border-box; margin: 0; padding: 0; }
        body {
            font-family: 'Times New Roman', Times, serif;
            font-size: 12pt;
            line-height: 1.5;
            color: #222;
            padding: 0;
        }
        .container {
            max-width: 210mm;
            margin: 0 auto;
            padding: 20px;
        }
        .header-center {
            text-align: center;
            margin-bottom: 20px;
            border-bottom: 3px double #222;
            padding-bottom: 15px;
        }
        .header-center h2 {
            font-size: 16pt;
            font-weight: bold;
            text-transform: uppercase;
            margin-bottom: 5px;
        }
        .header-center h1 {
            font-size: 18pt;
            font-weight: bold;
            text-transform: uppercase;
            margin-bottom: 5px;
        }
        .header-center h3 {
            font-size: 14pt;
            font-weight: bold;
            margin-bottom: 3px;
        }
        .header-center p {
            font-size: 11pt;
            margin-bottom: 2px;
        }
        .sub-header {
            display: flex;
            justify-content: space-between;
            flex-wrap: wrap;
            margin-bottom: 15px;
            padding: 8px 12px;
            border: 1px solid #222;
            background: #f9f9f9;
            font-size: 11pt;
        }
        .sub-header > div {
            flex: 1;
            min-width: 200px;
        }
        .section-title {
            font-size: 13pt;
            font-weight: bold;
            margin-top: 20px;
            margin-bottom: 10px;
            padding: 5px 10px;
            background: #e8e8e8;
            border-left: 4px solid #333;
            text-align: center;
        }
        .section-title-roman {
            font-size: 14pt;
            font-weight: bold;
            text-align: center;
            margin: 20px 0 10px;
            padding: 6px;
            background: #f0f0f0;
            border: 1px solid #999;
        }
        .subsection-title {
            font-size: 12pt;
            font-weight: bold;
            margin-top: 15px;
            margin-bottom: 6px;
            padding-left: 10px;
            border-left: 3px solid #555;
        }
        .content-box {
            background: #fafafa;
            border: 1px solid #ddd;
            padding: 10px 12px;
            margin-bottom: 12px;
            border-radius: 2px;
        }
        .content-box p { margin-bottom: 6px; text-align: justify; }
        .content-box ul, .content-box ol { padding-left: 25px; margin-bottom: 6px; }
        .content-box li { margin-bottom: 3px; text-align: justify; }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 12px;
            font-size: 11pt;
        }
        table th, table td {
            border: 1px solid #222;
            padding: 6px 8px;
            vertical-align: top;
            text-align: left;
        }
        table th {
            background: #e8e8e8;
            font-weight: bold;
            text-align: center;
        }
        .info-table td:first-child {
            width: 200px;
            font-weight: bold;
            background: #f5f5f5;
        }
        .info-table td {
            border: 1px solid #ccc;
            padding: 4px 10px;
        }
        .badge-dpl {
            display: inline-block;
            background: #e3f2fd;
            border: 1px solid #90caf9;
            padding: 2px 8px;
            border-radius: 12px;
            font-size: 10pt;
            margin: 2px 3px;
        }
        .badge-kbc {
            display: inline-block;
            background: #fce4ec;
            border: 1px solid #f48fb1;
            padding: 2px 8px;
            border-radius: 12px;
            font-size: 10pt;
            margin: 2px 3px;
        }
        .rubric-table td { text-align: center; font-weight: bold; }
        .rubric-table td.desc { text-align: left; font-weight: normal; }
        .footer-ttd {
            margin-top: 40px;
            display: flex;
            justify-content: space-between;
            text-align: center;
        }
        .footer-ttd > div { flex: 1; }
        .footer-ttd .line { margin-top: 60px; border-top: 1px solid #222; width: 200px; margin-left: auto; margin-right: auto; padding-top: 5px; }
        .page-break { page-break-after: always; }
        .small-text { font-size: 10pt; color: #555; }
        .deep-learning-tag {
            background: #fff3e0;
            border: 1px solid #ffcc80;
            padding: 3px 10px;
            border-radius: 4px;
            font-size: 10pt;
            display: inline-block;
        }
        @media print {
            .no-print { display: none !important; }
            body { padding: 0; }
            .container { padding: 0; max-width: 100%; }
            .section-title-roman { background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
            .section-title { background: #e8e8e8 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
            table th { background: #e8e8e8 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
            .content-box { background: #fafafa !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
            .sub-header { background: #f9f9f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
            .badge-dpl { background: #e3f2fd !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
            .badge-kbc { background: #fce4ec !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
        }
        .text-justify { text-align: justify; }
        .mt-20 { margin-top: 20px; }
        .mb-10 { margin-bottom: 10px; }
    </style>
</head>
<body>
<div class="container">

    <!-- ACTION BUTTONS -->
    <div class="no-print" style="text-align: right; margin-bottom: 15px;">
        <a href="/guru/learning-devices/rpm/<?= $device['id'] ?>/edit/<?= $chapterIndex ?>" class="btn btn-sm btn-secondary" style="padding: 6px 16px; background: #666; color: #fff; text-decoration: none; border-radius: 4px; font-size: 11pt;">← Kembali Edit</a>
        <a href="/guru/learning-devices/rpm/<?= $device['id'] ?>/export-doc/<?= $chapterIndex ?>" class="btn btn-sm btn-primary" style="padding: 6px 16px; background: #0d6efd; color: #fff; text-decoration: none; border-radius: 4px; font-size: 11pt; margin-left: 8px;">📥 Export DOCX</a>
        <button onclick="window.print()" class="btn btn-sm btn-danger" style="padding: 6px 16px; background: #dc3545; color: #fff; border: none; border-radius: 4px; font-size: 11pt; cursor: pointer; margin-left: 8px;">🖨️ Print</button>
    </div>

    <!-- ============================================================ -->
    <!-- COVER / HEADER -->
    <!-- ============================================================ -->
    <div class="header-center">
        <h2><?= esc($settings['school_name'] ?? 'SEKOLAH') ?></h2>
        <h1>MODUL AJAR</h1>
        <h3><?= strtoupper(esc($device['subject_name'] ?? '')) ?></h3>
        <p style="margin-top: 8px; font-weight: bold;"><?= strtoupper(esc($chapterName)) ?></p>
        <table style="width: auto; margin: 10px auto 0; border: none;">
            <tr>
                <td style="border: none; text-align: right; font-weight: bold; padding-right: 10px;">Kelas:</td>
                <td style="border: none; text-align: left;"><?= esc($device['grade_name'] ?? '-') ?> (Fase <?= esc($device['phase'] ?? '-') ?>)</td>
            </tr>
            <tr>
                <td style="border: none; text-align: right; font-weight: bold; padding-right: 10px;">Semester:</td>
                <td style="border: none; text-align: left;"><?= ($chapterTps[0]['semester'] ?? 1) == 1 ? 'Ganjil' : 'Genap' ?> | TA <?= esc($device['academic_year_name'] ?? '-') ?></td>
            </tr>
            <tr>
                <td style="border: none; text-align: right; font-weight: bold; padding-right: 10px;">Alokasi Waktu:</td>
                <td style="border: none; text-align: left;"><?= esc($totalJp) ?> JP (<?= $jumlahPertemuan ?> × pertemuan)</td>
            </tr>
        </table>
        <p style="margin-top: 10px; font-size: 11pt; font-style: italic;">
            Pendekatan Deep Learning | Kurikulum Merdeka <?= $device['school_type'] === 'madrasah' ? '| KMA 1503/2025' : '' ?>
        </p>
    </div>

    <!-- ============================================================ -->
    <!-- I. INFORMASI UMUM -->
    <!-- ============================================================ -->
    <div class="section-title-roman">I. INFORMASI UMUM</div>

    <div class="subsection-title">1. Identitas Modul</div>
    <table class="info-table">
        <tr><td>Nama Penyusun</td><td><?= esc($device['teacher_name'] ?? '-') ?></td></tr>
        <tr><td><?= esc(guess_id_label($device['teacher_nip'] ?? null)) ?></td><td><?= esc($device['teacher_nip'] ?? '-') ?></td></tr>
        <tr><td>Institusi</td><td><?= esc($settings['school_name'] ?? '-') ?></td></tr>
        <tr><td>Tahun Ajaran</td><td><?= esc($device['academic_year_name'] ?? '-') ?></td></tr>
        <tr><td>Jenjang</td><td><?php
            $phaseJenjang = $device['phase'] ?? '';
            if (($device['school_type'] ?? 'umum') === 'madrasah') {
                echo match($phaseJenjang) { 'A','B','C' => 'MI', 'D' => 'MTs', 'E','F' => 'MA', default => 'Madrasah' };
            } else {
                echo match($phaseJenjang) { 'A','B','C' => 'SD', 'D' => 'SMP', 'E','F' => 'SMA', default => 'Sekolah' };
            }
        ?></td></tr>
        <tr><td>Mata Pelajaran</td><td><?= esc($device['subject_name'] ?? '-') ?></td></tr>
        <tr><td>Fase / Kelas</td><td>Fase <?= esc($device['phase'] ?? '-') ?> / Kelas <?= esc($device['grade_name'] ?? '-') ?></td></tr>
        <tr><td>Semester</td><td><?= ($chapterTps[0]['semester'] ?? 1) == 1 ? 'Ganjil (1)' : 'Genap (2)' ?></td></tr>
        <tr><td>Bab / Materi</td><td><?= esc($chapterName) ?></td></tr>
        <tr><td>Sub Materi</td><td><?= esc($chapterName) ?></td></tr>
        <tr><td>Alokasi Waktu</td><td><?= esc($totalJp) ?> JP (<?= $jumlahPertemuan ?> pertemuan)</td></tr>
        <tr><td>Profil Lulusan</td><td>
            <?php
            if (!empty($dplChapterDisplay)):
                $dplArr = is_array($dplChapterDisplay) ? $dplChapterDisplay : explode(', ', $dplChapterDisplay);
                foreach ($dplArr as $d): ?>
                <span class="badge-dpl"><?= esc(trim($d)) ?></span>
            <?php endforeach;
            else:
                $dplList = json_decode($device['dpl'] ?? '[]', true);
                if (is_array($dplList) && !empty($dplList)): foreach ($dplList as $d): ?>
                    <span class="badge-dpl"><?= esc($d) ?></span>
                <?php endforeach; else: echo esc($device['dpl'] ?? '-');
                endif;
            endif; ?>
        </td></tr>
        <?php if (($device['school_type'] ?? 'umum') === 'madrasah'): ?>
        <tr><td>Topik KBC</td><td>
            <?php
            if (!empty($kbcChapterDisplay)):
                $kbcArr = is_array($kbcChapterDisplay) ? $kbcChapterDisplay : explode(', ', $kbcChapterDisplay);
                foreach ($kbcArr as $k): ?>
                <span class="badge-kbc"><?= esc(trim($k)) ?></span>
            <?php endforeach;
            else:
                $pcList = json_decode($device['panca_cinta'] ?? '[]', true);
                if (is_array($pcList) && !empty($pcList)): foreach ($pcList as $pc): ?>
                    <span class="badge-kbc"><?= esc($pc) ?></span>
                <?php endforeach; else: echo esc($device['panca_cinta'] ?? '-');
                endif;
            endif; ?>
        </td></tr>
        <?php endif; ?>
        <tr><td>Elemen CP</td><td><?= esc($cpElementsDisplay ?? '-') ?></td></tr>
    </table>

    <?php if (!empty($modul['kompetensi_awal'])): ?>
    <div class="subsection-title">2. Kompetensi Awal (Prasyarat)</div>
    <div class="content-box">
        <p><?= nl2br(esc($modul['kompetensi_awal'])) ?></p>
    </div>
    <?php endif; ?>

    <?php if (!empty($modul['sarana_prasarana'])): ?>
    <div class="subsection-title">3. Sarana & Prasarana</div>
    <div class="content-box">
        <p><?= nl2br(esc($modul['sarana_prasarana'])) ?></p>
    </div>
    <?php endif; ?>

    <?php if (!empty($modul['target_peserta_didik'])): ?>
    <div class="subsection-title">4. Target Peserta Didik</div>
    <div class="content-box">
        <p><?= nl2br(esc($modul['target_peserta_didik'])) ?></p>
    </div>
    <?php endif; ?>

    <?php if (!empty($modul['model_pembelajaran'])): ?>
    <div class="subsection-title">5. Model & Pendekatan Pembelajaran</div>
    <div class="content-box">
        <p><?= nl2br(esc($modul['model_pembelajaran'])) ?></p>
    </div>
    <?php endif; ?>

    <!-- ============================================================ -->
    <!-- II. KOMPONEN INTI -->
    <!-- ============================================================ -->
    <div class="section-title-roman">II. KOMPONEN INTI</div>

    <div class="subsection-title">1. Capaian Pembelajaran (CP)</div>
    <div class="content-box">
        <p><strong>Elemen: <?= esc($cpElementsDisplay ?? '-') ?></strong></p>
        <p style="margin-top: 6px;"><?= nl2br(esc($device['cp_content'] ?? '')) ?></p>
    </div>

    <div class="subsection-title">2. Tujuan Pembelajaran (TP) & Indikator Ketercapaian</div>
    <div class="content-box">
        <?php foreach ($chapterTps as $ctp): ?>
        <div class="mb-2 <?= $ctp !== end($chapterTps) ? 'border-bottom pb-2' : '' ?>">
            <p><strong><?= esc($ctp['code']) ?>:</strong> <?= esc($ctp['description']) ?></p>
            <?php
            $ctpKktp = null;
            if (!empty($kktpList)) {
                foreach ($kktpList as $k) {
                    if (isset($k['tp_id']) && $k['tp_id'] == $ctp['id']) {
                        $ctpKktp = $k;
                        break;
                    }
                }
            }
            ?>
            <?php if (!empty($ctpKktp['indicators'])): ?>
            <p style="margin-top: 4px;"><strong>Indikator Ketercapaian:</strong></p>
            <ul>
                <?php foreach (explode("\n", $ctpKktp['indicators']) as $ind): $ind = trim($ind); if (empty($ind)) continue; ?>
                <li><?= esc($ind) ?></li>
                <?php endforeach; ?>
            </ul>
            <?php endif; ?>
        </div>
        <?php endforeach; ?>
    </div>

    <?php if (!empty($modul['pemahaman_bermakna'])): ?>
    <div class="subsection-title">3. Pemahaman Bermakna</div>
    <div class="content-box">
        <p class="text-justify"><?= nl2br(esc($modul['pemahaman_bermakna'])) ?></p>
    </div>
    <?php endif; ?>

    <?php if (!empty($modul['pertanyaan_pemantik'])): ?>
    <div class="subsection-title">4. Pertanyaan Pemantik</div>
    <div class="content-box">
        <?= nl2br(esc($modul['pertanyaan_pemantik'])) ?>
    </div>
    <?php endif; ?>

    <?php if (!empty($modul['materi_esensial'])): ?>
    <div class="subsection-title">5. Materi Esensial / Pokok</div>
    <div class="content-box">
        <p class="text-justify"><?= nl2br(esc($modul['materi_esensial'])) ?></p>
    </div>
    <?php endif; ?>

    <!-- ============================================================ -->
    <!-- III. KEGIATAN PEMBELAJARAN -->
    <!-- ============================================================ -->
    <div class="section-title-roman">III. KEGIATAN PEMBELAJARAN</div>

    <?php if (!empty($skenario)): foreach ($skenario as $sk): ?>
    <div style="margin-bottom: 20px;">
        <div class="subsection-title" style="margin-top: 10px;">Pertemuan <?= esc($sk['pertemuan'] ?? '-') ?></div>

        <?php $materi = $sk['sub_materi'] ?? ''; if (!empty($materi)): ?>
        <div style="margin-bottom: 5px;">
            <p style="font-weight: bold; margin-bottom: 2px;">Materi</p>
            <p style="margin-top: 0;"><?= esc($materi) ?></p>
        </div>
        <?php endif; ?>

        <?php $iktps = $sk['iktp'] ?? []; if (!empty($iktps) && is_array($iktps)): ?>
        <div style="margin-bottom: 5px;">
            <p style="font-weight: bold; margin-bottom: 2px;">IKTP Pertemuan <?= esc($sk['pertemuan'] ?? '-') ?> :</p>
            <?php foreach ($iktps as $ik): ?>
            <p style="margin: 0 0 1px 15px;">- <?= esc($ik) ?></p>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>

        <?php if (!empty($sk['pendahuluan'])): ?>
        <div style="margin-bottom: 8px;">
            <p style="font-weight: bold; margin-bottom: 3px;">A. Pendahuluan</p>
            <div class="content-box" style="margin-bottom: 6px;">
                <p><?= nl2br(esc($sk['pendahuluan'])) ?></p>
            </div>
        </div>
        <?php endif; ?>

        <?php if (!empty($sk['inti'])): ?>
        <div style="margin-bottom: 8px;">
            <p style="font-weight: bold; margin-bottom: 3px;">B. Kegiatan Inti</p>
            <div class="content-box" style="margin-bottom: 6px;">
                <p><?= nl2br(esc($sk['inti'])) ?></p>
            </div>
        </div>
        <?php endif; ?>

        <?php if (!empty($sk['penutup'])): ?>
        <div style="margin-bottom: 8px;">
            <p style="font-weight: bold; margin-bottom: 3px;">C. Penutup</p>
            <div class="content-box" style="margin-bottom: 6px;">
                <p><?= nl2br(esc($sk['penutup'])) ?></p>
            </div>
        </div>
        <?php endif; ?>
    </div>
    <?php endforeach; else: ?>
    <p class="small-text" style="font-style: italic;">Belum ada kegiatan pembelajaran.</p>
    <?php endif; ?>

    <!-- ============================================================ -->
    <!-- IV. ASESMEN -->
    <!-- ============================================================ -->
    <div class="section-title-roman">IV. ASESMEN (PENILAIAN)</div>

    <?php if (!empty($modul['asesmen_diagnostik'])): ?>
    <div class="subsection-title">1. Asesmen Awal / Diagnostik</div>
    <div class="content-box">
        <p><?= nl2br(esc($modul['asesmen_diagnostik'])) ?></p>
    </div>
    <?php endif; ?>

    <?php if (!empty($modul['asesmen_formatif'])): ?>
    <div class="subsection-title">2. Asesmen Formatif (Proses) & Rubrik</div>
    <div class="content-box">
        <p><?= nl2br(esc($modul['asesmen_formatif'])) ?></p>
    </div>
    <?php endif; ?>

    <?php if (!empty($modul['asesmen_sumatif'])): ?>
    <div class="subsection-title">3. Asesmen Sumatif (Akhir)</div>
    <div class="content-box">
        <p><?= nl2br(esc($modul['asesmen_sumatif'])) ?></p>
    </div>
    <?php endif; ?>

    <!-- ============================================================ -->
    <!-- V. PENGAYAAN & REMEDIAL -->
    <!-- ============================================================ -->
    <div class="section-title-roman">V. PENGAYAAN & REMEDIAL</div>

    <?php if (!empty($modul['pengayaan'])): ?>
    <div class="subsection-title">1. Program Pengayaan</div>
    <div class="content-box">
        <p><?= nl2br(esc($modul['pengayaan'])) ?></p>
    </div>
    <?php endif; ?>

    <?php if (!empty($modul['remedial'])): ?>
    <div class="subsection-title">2. Program Remedial</div>
    <div class="content-box">
        <p><?= nl2br(esc($modul['remedial'])) ?></p>
    </div>
    <?php endif; ?>

    <!-- ============================================================ -->
    <!-- VI. LAMPIRAN -->
    <!-- ============================================================ -->
    <div class="section-title-roman">VI. LAMPIRAN</div>

    <?php
    // LKPD dari skenario per pertemuan
    $hasLkpd = false;
    foreach ((array)$skenario as $sk) {
        if (!empty($sk['lkpd_langkah']) || !empty($sk['lkpd_soal']) || !empty($sk['lkpd_kesimpulan'])) {
            $hasLkpd = true; break;
        }
    }
    ?>
    <?php if ($hasLkpd): ?>
    <div class="subsection-title">1. LKPD (Lembar Kerja Peserta Didik)</div>
        <?php foreach ((array)$skenario as $sk): if (empty($sk['lkpd_langkah']) && empty($sk['lkpd_soal']) && empty($sk['lkpd_kesimpulan'])) continue; ?>
        <div style="margin-bottom: 25px; page-break-inside: avoid;">
            <div style="font-weight: bold; font-size: 11pt; margin-bottom: 6px;">LEMBAR KERJA PESERTA DIDIK (LKPD)</div>
            <div style="font-size: 10pt; margin-bottom: 8px;">Pertemuan <?= esc($sk['pertemuan'] ?? '-') ?><?= !empty($sk['sub_materi']) ? ': ' . esc($sk['sub_materi']) : '' ?></div>

            <table style="width: 100%; border-collapse: collapse; margin-bottom: 8px;">
                <tr><td style="width: 100px; padding: 1px 0; font-size: 10pt;">Nama</td><td style="padding: 1px 0; font-size: 10pt;">: ........................................</td></tr>
                <tr><td style="padding: 1px 0; font-size: 10pt;">Kelas</td><td style="padding: 1px 0; font-size: 10pt;">: ........................................</td></tr>
                <tr><td style="padding: 1px 0; font-size: 10pt;">Pertemuan ke-</td><td style="padding: 1px 0; font-size: 10pt;">: ........................................</td></tr>
            </table>

            <?php
            $lkpdIktp = $sk['iktp'] ?? [];
            if (!empty($lkpdIktp)):
            ?>
            <div style="font-weight: bold; font-size: 10pt; margin-bottom: 4px;">Tujuan:</div>
            <ul style="margin: 0 0 8px 0; font-size: 10pt;">
                <?php foreach ($lkpdIktp as $ik): ?>
                <li><?= esc($ik) ?></li>
                <?php endforeach; ?>
            </ul>
            <?php endif; ?>

            <?php if (!empty($sk['lkpd_langkah'])): ?>
            <div style="font-weight: bold; font-size: 10pt; margin-bottom: 3px;">Langkah Kegiatan</div>
            <div style="font-size: 10pt; margin-bottom: 8px;"><?= nl2br(esc($sk['lkpd_langkah'])) ?></div>
            <?php endif; ?>

            <?php if (!empty($sk['lkpd_soal'])): ?>
            <div style="font-weight: bold; font-size: 10pt; margin-bottom: 3px;">Soal/Tugas</div>
            <div style="font-size: 10pt; margin-bottom: 8px;"><?= nl2br(esc($sk['lkpd_soal'])) ?></div>
            <?php endif; ?>

            <?php if (!empty($sk['lkpd_kesimpulan'])): ?>
            <div style="font-weight: bold; font-size: 10pt; margin-bottom: 3px;">Kesimpulan</div>
            <div style="font-size: 10pt; margin-bottom: 4px;"><?= nl2br(esc($sk['lkpd_kesimpulan'])) ?></div>
            <?php endif; ?>
        </div>
        <?php endforeach; ?>
    <?php endif; ?>

    <?php if (!empty($modul['glosarium'])): ?>
    <div class="subsection-title">2. Glosarium</div>
    <div class="content-box">
        <?= nl2br(esc($modul['glosarium'])) ?>
    </div>
    <?php endif; ?>

    <div class="subsection-title">3. Daftar Pustaka</div>
    <div class="content-box">
        <?= nl2br(esc($daftarPustaka ?? '')) ?>
    </div>

    <!-- ============================================================ -->
    <!-- LEMBAR PENGESAHAN -->
    <!-- ============================================================ -->
    <div class="section-title-roman">LEMBAR PENGESAHAN MODUL AJAR</div>
    <div class="footer-ttd">
        <div>
            <p style="font-weight: bold;">Dibuat Oleh,</p>
            <p>Guru <?= esc($device['subject_name'] ?? 'Mata Pelajaran') ?></p>
            <div class="line"><?= esc($device['teacher_name'] ?? '') ?></div>
            <p><?= esc(guess_id_label($device['teacher_nip'] ?? null)) ?>. <?= esc($device['teacher_nip'] ?? '') ?></p>
        </div>
        <div>
            <p style="font-weight: bold;">Diperiksa Oleh,</p>
            <p>Waka Kurikulum</p>
            <div class="line"></div>
            <p>NIP.</p>
        </div>
        <div>
            <p style="font-weight: bold;">Mengetahui,</p>
            <p>Kepala <?= esc($settings['school_name'] ?? 'Sekolah') ?></p>
            <div class="line"><?= esc($settings['principal_name'] ?? '') ?></div>
            <p>NIP. <?= esc($settings['principal_nip'] ?? '') ?></p>
        </div>
    </div>
    <p style="text-align: center; margin-top: 20px; font-size: 10pt; font-style: italic;">
        Disusun untuk <?= esc($settings['school_name'] ?? 'Sekolah') ?> | Tahun Ajaran <?= esc($device['academic_year_name'] ?? '-') ?>
    </p>
    <p style="text-align: center; font-size: 10pt; font-style: italic;">
        Kurikulum Merdeka | Deep Learning <?= $device['school_type'] === 'madrasah' ? '| KMA No. 1503 Tahun 2025' : '' ?>
    </p>

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