                <section class="eep-settings-panel" id="eep-tab-notifications-alerts" data-tab="notifications" data-subtab="alerts">
                    <h2><?php esc_html_e('Admin Alerts', 'nexdirectory'); ?></h2>
                    <p class="eep-settings-subheading"><?php esc_html_e('Choose who receives notification alerts and when each trigger runs.', 'nexdirectory'); ?></p>

                    <div class="eep-settings-grid">
                        <div class="eep-settings-field eep-full">
                            <input type="hidden" id="eep_enable_pending_admin_notifications" name="eep_enable_pending_admin_notifications" value="<?php echo esc_attr(((string) $pending_badge_toggle_value === '1' || (string) $pending_email_toggle_value === '1') ? '1' : '0'); ?>">
                            <div class="eep-settings-toggle-list">
                                <div class="eep-settings-toggle-item">
                                    <input type="hidden" name="eep_notify_admin_pending_badge" value="0">
                                    <label><input type="checkbox" name="eep_notify_admin_pending_badge" value="1" <?php checked((string) $pending_badge_toggle_value, '1'); ?>> <?php esc_html_e('Admin dashboard badge for moderation queue', 'nexdirectory'); ?></label>
                                    <p class="description"><?php esc_html_e('Shows a red badge count in WordPress admin menu for pending submissions.', 'nexdirectory'); ?></p>
                                </div>
                                <div class="eep-settings-toggle-item">
                                    <input type="hidden" name="eep_notify_admin_pending_email" value="0">
                                    <label><input type="checkbox" name="eep_notify_admin_pending_email" value="1" <?php checked((string) $pending_email_toggle_value, '1'); ?>> <?php esc_html_e('Email admin on new pending submission', 'nexdirectory'); ?></label>
                                    <p class="description"><?php esc_html_e('Recipient: site admin email. Trigger: when a user submits a listing for moderation.', 'nexdirectory'); ?></p>
                                </div>
                                <div class="eep-settings-toggle-item">
                                    <input type="hidden" name="eep_notify_admin_claim_email" value="0">
                                    <label><input type="checkbox" name="eep_notify_admin_claim_email" value="1" <?php checked((string) get_option('eep_notify_admin_claim_email', '1'), '1'); ?>> <?php esc_html_e('Email admin on new claim request', 'nexdirectory'); ?></label>
                                    <p class="description"><?php esc_html_e('Recipient: site admin email. Trigger: a user submits a listing claim request.', 'nexdirectory'); ?></p>
                                </div>
                            </div>
                        </div>

                        <div class="eep-settings-field eep-full">
                            <h3 class="eep-settings-core-title"><span class="dashicons dashicons-email-alt" aria-hidden="true"></span><?php esc_html_e('System & User Triggers', 'nexdirectory'); ?></h3>
                            <div class="eep-settings-toggle-list">
                                <div class="eep-settings-toggle-item">
                                    <input type="hidden" name="eep_notify_extension_potential_owner" value="0">
                                    <label><input type="checkbox" name="eep_notify_extension_potential_owner" value="1" <?php checked((string) get_option('eep_notify_extension_potential_owner', '0'), '1'); ?>> <?php esc_html_e('Notify potential owner after extension import', 'nexdirectory'); ?></label>
                                    <p class="description"><?php esc_html_e('Recipient: imported contact email.', 'nexdirectory'); ?></p>
                                </div>
                                <div class="eep-settings-toggle-item">
                                    <input type="hidden" name="eep_notify_author_confirmation" value="0">
                                    <label><input type="checkbox" name="eep_notify_author_confirmation" value="1" <?php checked((string) get_option('eep_notify_author_confirmation', '1'), '1'); ?>> <?php esc_html_e('Submission confirmation to listing owner', 'nexdirectory'); ?></label>
                                    <p class="description"><?php esc_html_e('Trigger: listing enters Pending Review.', 'nexdirectory'); ?></p>
                                </div>
                                <div class="eep-settings-toggle-item">
                                    <input type="hidden" name="eep_notify_author_update" value="0">
                                    <label><input type="checkbox" name="eep_notify_author_update" value="1" <?php checked((string) get_option('eep_notify_author_update', '1'), '1'); ?>> <?php esc_html_e('Approval/update email to listing owner', 'nexdirectory'); ?></label>
                                    <p class="description"><?php esc_html_e('Trigger: listing is approved or admin requests update.', 'nexdirectory'); ?></p>
                                </div>
                                <div class="eep-settings-toggle-item">
                                    <input type="hidden" name="eep_notify_author_cancellation" value="0">
                                    <label><input type="checkbox" name="eep_notify_author_cancellation" value="1" <?php checked((string) get_option('eep_notify_author_cancellation', '1'), '1'); ?>> <?php esc_html_e('Rejection/cancellation email to listing owner', 'nexdirectory'); ?></label>
                                    <p class="description"><?php esc_html_e('Trigger: listing is rejected or cancelled.', 'nexdirectory'); ?></p>
                                </div>
                                <div class="eep-settings-toggle-item">
                                    <input type="hidden" name="eep_notify_author_reminder" value="0">
                                    <label><input type="checkbox" name="eep_notify_author_reminder" value="1" <?php checked((string) get_option('eep_notify_author_reminder', '1'), '1'); ?>> <?php esc_html_e('Reminder emails to saved/following users', 'nexdirectory'); ?></label>
                                    <p class="description"><?php esc_html_e('Trigger: reminder cron before listing start date.', 'nexdirectory'); ?></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>

                <section class="eep-settings-panel" id="eep-tab-notifications-email" data-tab="notifications" data-subtab="email">
                    <h2><?php esc_html_e('Email Templates', 'nexdirectory'); ?></h2>
                    <p class="eep-settings-subheading"><?php esc_html_e('Edit message templates for each lifecycle email sent by the platform. Click tokens to copy.', 'nexdirectory'); ?></p>

                    <?php
                    $subject_confirmation = trim((string) get_option('eep_email_subject_confirmation', (string) ($email_template_defaults['eep_email_subject_confirmation'] ?? '')));
                    if ($subject_confirmation === '') {
                        $subject_confirmation = (string) ($email_template_defaults['eep_email_subject_confirmation'] ?? '');
                    }
                    $body_confirmation = trim((string) get_option('eep_email_body_confirmation', (string) ($email_template_defaults['eep_email_body_confirmation'] ?? '')));
                    if ($body_confirmation === '') {
                        $body_confirmation = (string) ($email_template_defaults['eep_email_body_confirmation'] ?? '');
                    }

                    $subject_reminder = trim((string) get_option('eep_email_subject_reminder', (string) ($email_template_defaults['eep_email_subject_reminder'] ?? '')));
                    if ($subject_reminder === '') {
                        $subject_reminder = (string) ($email_template_defaults['eep_email_subject_reminder'] ?? '');
                    }
                    $body_reminder = trim((string) get_option('eep_email_body_reminder', (string) ($email_template_defaults['eep_email_body_reminder'] ?? '')));
                    if ($body_reminder === '') {
                        $body_reminder = (string) ($email_template_defaults['eep_email_body_reminder'] ?? '');
                    }

                    $subject_ticket_confirmation = trim((string) get_option('eep_email_subject_ticket_confirmation', (string) ($email_template_defaults['eep_email_subject_ticket_confirmation'] ?? '')));
                    if ($subject_ticket_confirmation === '') {
                        $subject_ticket_confirmation = (string) ($email_template_defaults['eep_email_subject_ticket_confirmation'] ?? __('Ticket confirmation: {event_title}', 'nexdirectory'));
                    }
                    $body_ticket_confirmation = trim((string) get_option('eep_email_body_ticket_confirmation', (string) ($email_template_defaults['eep_email_body_ticket_confirmation'] ?? '')));
                    if ($body_ticket_confirmation === '') {
                        $body_ticket_confirmation = (string) ($email_template_defaults['eep_email_body_ticket_confirmation'] ?? '');
                    }

                    $subject_update = trim((string) get_option('eep_email_subject_update', (string) ($email_template_defaults['eep_email_subject_update'] ?? '')));
                    if ($subject_update === '') {
                        $subject_update = (string) ($email_template_defaults['eep_email_subject_update'] ?? '');
                    }
                    $body_update = trim((string) get_option('eep_email_body_update', (string) ($email_template_defaults['eep_email_body_update'] ?? '')));
                    if ($body_update === '') {
                        $body_update = (string) ($email_template_defaults['eep_email_body_update'] ?? '');
                    }

                    $subject_cancellation = trim((string) get_option('eep_email_subject_cancellation', (string) ($email_template_defaults['eep_email_subject_cancellation'] ?? '')));
                    if ($subject_cancellation === '') {
                        $subject_cancellation = (string) ($email_template_defaults['eep_email_subject_cancellation'] ?? '');
                    }
                    $body_cancellation = trim((string) get_option('eep_email_body_cancellation', (string) ($email_template_defaults['eep_email_body_cancellation'] ?? '')));
                    if ($body_cancellation === '') {
                        $body_cancellation = (string) ($email_template_defaults['eep_email_body_cancellation'] ?? '');
                    }

                    $subject_extension_owner = trim((string) get_option('eep_email_subject_extension_potential_owner', (string) ($email_template_defaults['eep_email_subject_extension_potential_owner'] ?? '')));
                    if ($subject_extension_owner === '') {
                        $subject_extension_owner = (string) ($email_template_defaults['eep_email_subject_extension_potential_owner'] ?? '');
                    }
                    $body_extension_owner = trim((string) get_option('eep_email_body_extension_potential_owner', (string) ($email_template_defaults['eep_email_body_extension_potential_owner'] ?? '')));
                    if ($body_extension_owner === '') {
                        $body_extension_owner = (string) ($email_template_defaults['eep_email_body_extension_potential_owner'] ?? '');
                    }
                    ?>

                    <div class="eep-settings-grid">
                        <div class="eep-settings-field eep-full">
                            <p class="description" style="margin-bottom:8px;"><?php esc_html_e('Available tokens:', 'nexdirectory'); ?></p>
                            <div class="eep-shortcode-actions">
                                <?php foreach (['{listing_title}', '{listing_date}', '{listing_url}', '{status}', '{moderator_note}', '{site_name}', '{claim_url}'] as $token) : ?>
                                    <button type="button" class="button button-small eep-copy-shortcode" data-shortcode="<?php echo esc_attr($token); ?>"><?php echo esc_html($token); ?></button>
                                <?php endforeach; ?>
                            </div>
                        </div>

                        <div class="eep-settings-field eep-full eep-settings-toggle-item">
                            <label for="eep_email_subject_confirmation"><?php esc_html_e('Confirmation Template', 'nexdirectory'); ?></label>
                            <p class="description"><?php esc_html_e('Trigger: listing submitted to pending. Recipient: listing owner.', 'nexdirectory'); ?></p>
                            <input type="text" id="eep_email_subject_confirmation" name="eep_email_subject_confirmation" value="<?php echo esc_attr($subject_confirmation); ?>">
                            <textarea id="eep_email_body_confirmation" name="eep_email_body_confirmation" rows="5"><?php echo esc_textarea($body_confirmation); ?></textarea>
                        </div>

                        <div class="eep-settings-field eep-full eep-settings-toggle-item">
                            <label for="eep_email_subject_reminder"><?php esc_html_e('Reminder Template', 'nexdirectory'); ?></label>
                            <p class="description"><?php esc_html_e('Trigger: reminder cron before start date. Recipient: saved/RSVP attendees.', 'nexdirectory'); ?></p>
                            <input type="text" id="eep_email_subject_reminder" name="eep_email_subject_reminder" value="<?php echo esc_attr($subject_reminder); ?>">
                            <textarea id="eep_email_body_reminder" name="eep_email_body_reminder" rows="5"><?php echo esc_textarea($body_reminder); ?></textarea>
                        </div>

                        <div class="eep-settings-field eep-full eep-settings-toggle-item">
                            <label for="eep_email_subject_ticket_confirmation"><?php esc_html_e('Ticket Confirmation Template', 'nexdirectory'); ?></label>
                            <p class="description"><?php esc_html_e('Trigger: successful ticket checkout. Recipient: attendee.', 'nexdirectory'); ?></p>
                            <div class="eep-shortcode-actions">
                                <?php foreach (['{ticket_total}', '{ticket_currency}', '{ticket_price}', '{ticket_id}', '{ticket_verification_url}', '{attendee_name}'] as $token) : ?>
                                    <button type="button" class="button button-small eep-copy-shortcode" data-shortcode="<?php echo esc_attr($token); ?>"><?php echo esc_html($token); ?></button>
                                <?php endforeach; ?>
                            </div>
                            <input type="text" id="eep_email_subject_ticket_confirmation" name="eep_email_subject_ticket_confirmation" value="<?php echo esc_attr($subject_ticket_confirmation); ?>">
                            <textarea id="eep_email_body_ticket_confirmation" name="eep_email_body_ticket_confirmation" rows="6"><?php echo esc_textarea($body_ticket_confirmation); ?></textarea>
                            <p class="description"><?php esc_html_e('Available tokens: {event_title}, {event_date}, {event_url}, {ticket_total}, {ticket_currency}, {ticket_price}, {ticket_gateway}, {ticket_payment_method}, {ticket_status}, {ticket_id}, {ticket_purchase_date}, {ticket_verification_url}, {ticket_qr_image_url}, {attendee_name}, {attendee_email}, {site_name}.', 'nexdirectory'); ?></p>
                        </div>

                        <div class="eep-settings-field eep-full eep-settings-toggle-item">
                            <label for="eep_email_subject_update"><?php esc_html_e('Update / Approval Template', 'nexdirectory'); ?></label>
                            <p class="description"><?php esc_html_e('Trigger: moderation approval or admin update. Recipient: listing owner.', 'nexdirectory'); ?></p>
                            <input type="text" id="eep_email_subject_update" name="eep_email_subject_update" value="<?php echo esc_attr($subject_update); ?>">
                            <textarea id="eep_email_body_update" name="eep_email_body_update" rows="5"><?php echo esc_textarea($body_update); ?></textarea>
                        </div>

                        <div class="eep-settings-field eep-full eep-settings-toggle-item">
                            <label for="eep_email_subject_cancellation"><?php esc_html_e('Cancellation / Rejection Template', 'nexdirectory'); ?></label>
                            <p class="description"><?php esc_html_e('Trigger: moderation rejection. Recipient: listing owner.', 'nexdirectory'); ?></p>
                            <input type="text" id="eep_email_subject_cancellation" name="eep_email_subject_cancellation" value="<?php echo esc_attr($subject_cancellation); ?>">
                            <textarea id="eep_email_body_cancellation" name="eep_email_body_cancellation" rows="4"><?php echo esc_textarea($body_cancellation); ?></textarea>
                            <p class="description"><?php esc_html_e('Available tokens: {listing_title}, {listing_date}, {listing_url}, {status}, {moderator_note}. Legacy compatibility tokens also work: {event_title}, {event_date}, {event_url}.', 'nexdirectory'); ?></p>
                        </div>

                        <div class="eep-settings-field eep-full eep-settings-toggle-item">
                            <label for="eep_email_subject_extension_potential_owner"><?php esc_html_e('Extension Potential Owner Template', 'nexdirectory'); ?></label>
                            <p class="description"><?php esc_html_e('Trigger: listing imported from Chrome extension. Recipient: imported contact email.', 'nexdirectory'); ?></p>
                            <input type="text" id="eep_email_subject_extension_potential_owner" name="eep_email_subject_extension_potential_owner" value="<?php echo esc_attr($subject_extension_owner); ?>">
                            <textarea id="eep_email_body_extension_potential_owner" name="eep_email_body_extension_potential_owner" rows="5"><?php echo esc_textarea($body_extension_owner); ?></textarea>
                            <p class="description"><?php esc_html_e('Available tokens: {listing_title}, {listing_url}, {claim_url}, {source_url}, {site_name}. Legacy tokens like {event_title}/{event_url} still work.', 'nexdirectory'); ?></p>
                        </div>
                    </div>
                </section>
