<!-- ================================================================= -->
            <!-- 5. RSVP                                                           -->
            <!-- ================================================================= -->
            <?php if (isset($sectionMap['rsvp'])): 
                $rsvpConfig = $sectionMap['rsvp'];
                $rsvpClosesAt = $rsvpConfig['rsvp_closes_at'] ?? null;
                $rsvpAllowEdit = (bool) ($rsvpConfig['rsvp_allow_edit'] ?? true);
                $notesEnabled = (bool) ($rsvpConfig['notes_enabled'] ?? true);
                
                $isDeadlinePassed = false;
                if (!empty($rsvpClosesAt)) {
                    $isDeadlinePassed = (time() > strtotime((string) $rsvpClosesAt));
                }
                $canEdit = ($rsvp === null) || ($rsvpAllowEdit && !$isDeadlinePassed);
            ?>
                <section class="py-16 md:py-20 lg:py-24 px-6 md:px-12 text-center space-y-8 border-b <?= $style['borderColor'] ?>">
                    <?php
                    $headerEmoji = '💌';
                    $headerTitle = 'RSVP & Attendance Confirmation';
                    require __DIR__ . '/../partials/section_header.php';
                    ?>
                    <div class="text-center mt-2">
                        <?php if (!empty($rsvpClosesAt)): ?>
                            <p class="text-xxs <?= $style['subText'] ?> uppercase tracking-wider font-semibold pt-1">
                                Deadline: <?= date('d M Y, H:i', strtotime((string) $rsvpClosesAt)) ?>
                            </p>
                        <?php endif; ?>
                    </div>

                    <!-- Responsive Event-Based RSVP Cards Grid -->
                    <div class="grid grid-cols-1 <?= count($events) === 1 ? 'max-w-md mx-auto' : (count($events) === 2 ? 'md:grid-cols-2' : 'md:grid-cols-2 lg:grid-cols-3') ?> gap-6 items-stretch text-left">
                        <?php foreach ($events as $idx => $evt): 
                            $evtId = (int) ($evt['id'] ?? $idx);
                            $evtName = $evt['event_name'] ?? 'Ceremony';
                            $evtDateObj = !empty($evt['event_date']) ? new \DateTime($evt['event_date']) : new \DateTime();
                            $formattedDate = $evtDateObj->format('l, d F Y');
                            $formattedTime = $evtDateObj->format('H:i') . ' WIB';
                            $venueName = $evt['venue_name'] ?? 'Venue';
                            $venueAddr = $evt['venue_address'] ?? '';
                        ?>
                            <div class="<?= $style['cardBg'] ?> rounded-3xl border <?= $style['borderColor'] ?> shadow-sm p-6 flex flex-col justify-between space-y-5 hover:border-amber-400/60 transition">
                                
                                <div class="space-y-3 border-b <?= $style['borderColor'] ?> pb-4">
                                    <div class="flex items-center justify-between">
                                        <h3 class="text-lg font-bold <?= $style['textColor'] ?> <?= $style['fontSerif'] ?>">
                                            RSVP <?= escape_html($evtName) ?>
                                        </h3>
                                        <span class="text-[10px] font-bold uppercase tracking-wider text-amber-700 <?= $style['accentBg'] ?> px-2.5 py-1 rounded-full border border-amber-200/60">
                                            Event <?= $idx + 1 ?>
                                        </span>
                                    </div>

                                    <div class="text-xs text-slate-600 space-y-1.5 pt-1">
                                        <p class="flex items-center gap-2">
                                            <span>📅</span> <strong>Date:</strong> <?= escape_html($formattedDate) ?>
                                        </p>
                                        <p class="flex items-center gap-2">
                                            <span>🕒</span> <strong>Time:</strong> <?= escape_html($formattedTime) ?>
                                        </p>
                                        <p class="flex items-start gap-2">
                                            <span>📍</span>
                                            <span>
                                                <strong>Venue:</strong> <?= escape_html($venueName) ?>
                                                <?php if (!empty($venueAddr)): ?>
                                                    <br><span class="text-slate-400 text-xxs leading-relaxed inline-block mt-0.5"><?= escape_html($venueAddr) ?></span>
                                                <?php endif; ?>
                                            </span>
                                        </p>
                                    </div>
                                </div>

                                <?php if ($rsvp !== null && !$canEdit): ?>
                                    <div class="bg-slate-50 border border-slate-100 rounded-2xl p-4 space-y-2 text-center">
                                        <p class="text-xs uppercase tracking-wider text-slate-400 font-semibold">Submitted Response</p>
                                        <p class="text-sm font-bold <?= $style['textColor'] ?>">
                                            <?php if ($rsvp['response'] === 'attending'): ?>
                                                🎉 Attending (<?= (int) $rsvp['confirmed_pax'] ?> Pax)
                                            <?php else: ?>
                                                🕊️ Unable to Attend
                                            <?php endif; ?>
                                        </p>
                                        <?php if (!empty($rsvp['message'])): ?>
                                            <p class="text-xs italic <?= $style['subText'] ?> font-serif-fancy">"<?= escape_html($rsvp['message']) ?>"</p>
                                        <?php endif; ?>
                                    </div>
                                <?php elseif ($live_preview): ?>
                                    <div class="bg-amber-50/60 border border-amber-200/80 text-amber-800 rounded-2xl p-4 text-xs font-semibold flex items-center gap-3">
                                        <span>🔒</span>
                                        <span>RSVP submission is disabled in Live Preview.</span>
                                    </div>
                                <?php else: ?>
                                    <form action="<?= url('/' . escape_html($workspace['slug']) . '/i/' . escape_html($guestToken) . '/rsvp') ?>" method="POST" class="space-y-4 flex-1 flex flex-col justify-between">
                                        <?= csrf_field() ?>
                                        <input type="hidden" name="event_id" value="<?= $evtId ?>">

                                        <div class="space-y-4">
                                            <div>
                                                <label for="rsvp_response_<?= $evtId ?>" class="block text-xxs uppercase tracking-wider text-slate-400 font-bold mb-1">Attendance Status</label>
                                                <select id="rsvp_response_<?= $evtId ?>" name="response" onchange="togglePaxInputEvent(<?= $evtId ?>)" class="w-full text-xs p-2.5 bg-slate-50 border <?= $style['borderColor'] ?> rounded-xl text-slate-700 focus:outline-none focus:border-amber-400" required>
                                                    <option value="">-- Confirm Attendance --</option>
                                                    <option value="attending" <?php if ($rsvp && $rsvp['response'] === 'attending'): ?>selected<?php endif; ?>>Yes, I will attend</option>
                                                    <option value="declined" <?php if ($rsvp && $rsvp['response'] === 'declined'): ?>selected<?php endif; ?>>No, I cannot attend</option>
                                                </select>
                                            </div>

                                            <div id="pax-container-<?= $evtId ?>" class="<?php if (!$rsvp || $rsvp['response'] !== 'attending'): ?>hidden<?php endif; ?>">
                                                <label for="rsvp_pax_<?= $evtId ?>" class="block text-xxs uppercase tracking-wider text-slate-400 font-bold mb-1">Number of Guests (Max: <?= $pax ?>)</label>
                                                <select id="rsvp_pax_<?= $evtId ?>" name="confirmed_pax" class="w-full text-xs p-2.5 bg-slate-50 border <?= $style['borderColor'] ?> rounded-xl text-slate-700 focus:outline-none focus:border-amber-400">
                                                    <?php for ($i = 1; $i <= $pax; $i++): ?>
                                                        <?php $selected = ($rsvp && (int)$rsvp['confirmed_pax'] === $i) ? 'selected' : ($i === 1 ? 'selected' : ''); ?>
                                                        <option value="<?= $i ?>" <?= $selected ?>><?= $i ?> Person<?= $i > 1 ? 's' : '' ?></option>
                                                    <?php endfor; ?>
                                                </select>
                                            </div>

                                            <?php if ($notesEnabled): ?>
                                                <div>
                                                    <label for="rsvp_notes_<?= $evtId ?>" class="block text-xxs uppercase tracking-wider text-slate-400 font-bold mb-1">Remarks / Note (Optional)</label>
                                                    <textarea 
                                                        id="rsvp_notes_<?= $evtId ?>" 
                                                        name="notes" 
                                                        rows="2" 
                                                        maxlength="500" 
                                                        placeholder="e.g. Dietary preferences, expected arrival..." 
                                                        class="w-full text-xs p-2.5 bg-slate-50 border <?= $style['borderColor'] ?> rounded-xl text-slate-700 focus:outline-none focus:border-amber-400"
                                                    ><?= $rsvp && !empty($rsvp['message']) ? escape_html($rsvp['message']) : '' ?></textarea>
                                                </div>
                                            <?php endif; ?>
                                        </div>

                                        <button type="submit" class="w-full inline-flex justify-center items-center px-4 py-2.5 border border-transparent text-xs font-bold rounded-xl <?= $style['primaryBtn'] ?> transition shadow-sm mt-3">
                                            Submit <?= escape_html($evtName) ?> RSVP
                                        </button>
                                    </form>
                                <?php endif; ?>

                            </div>
                        <?php endforeach; ?>
                    </div>
                </section>
            <?php endif; ?>
