                <section class="eep-settings-panel is-active" id="eep-tab-pages" data-tab="general" data-subtab="setup">
                    <h2><?php esc_html_e('General Setup', 'nexdirectory'); ?></h2>
                    <p class="eep-settings-subheading"><?php esc_html_e('Configure platform behavior, operating mode, and page generation.', 'nexdirectory'); ?></p>

                    <div class="eep-settings-grid">
                        <div class="eep-settings-field eep-full">
                            <h3 class="eep-settings-core-title"><span class="dashicons dashicons-admin-site-alt3" aria-hidden="true"></span><?php esc_html_e('Core Setup', 'nexdirectory'); ?></h3>

                            <div class="eep-settings-field-grid">
                                <div>
                                    <label for="eep_site_profile"><?php esc_html_e('Directory Template Mode', 'nexdirectory'); ?></label>
                                    <select id="eep_site_profile" name="eep_site_profile">
                                        <?php foreach ($site_profile_catalog as $profile_key => $profile_config) : ?>
                                            <?php
                                            $profile_key = sanitize_key((string) $profile_key);
                                            if ($profile_key === '') {
                                                continue;
                                            }
                                            $profile_label = sanitize_text_field((string) ($profile_config['label'] ?? $profile_key));
                                            $profile_description = sanitize_text_field((string) ($profile_config['description'] ?? ''));
                                            $profile_available = $profile_key === 'events';
                                            if (!$profile_available) {
                                                $profile_label .= ' (' . __('Coming Soon', 'nexdirectory') . ')';
                                            }
                                            ?>
                                            <option value="<?php echo esc_attr($profile_key); ?>" <?php selected($site_profile_value, $profile_key); ?> <?php disabled(!$profile_available); ?>>
                                                <?php echo esc_html($profile_label); ?>
                                                <?php if ($profile_description !== '') : ?>
                                                    <?php echo esc_html(' - ' . $profile_description); ?>
                                                <?php endif; ?>
                                            </option>
                                        <?php endforeach; ?>
                                    </select>
                                    <p class="description"><?php esc_html_e('Mode 0 currently supports Events only. Other templates are visible for roadmap preview and will unlock in upcoming updates.', 'nexdirectory'); ?></p>
                                </div>

                                <div>
                                    <label for="eep_platform_mode"><?php esc_html_e('Platform Operating Mode', 'nexdirectory'); ?></label>
                                    <select id="eep_platform_mode" name="eep_platform_mode">
                                        <option value="user_generated" <?php selected($platform_mode_value, 'user_generated'); ?>><?php esc_html_e('User-Generated Event Platforms (Default)', 'nexdirectory'); ?></option>
                                        <option value="single_organisation" <?php selected($platform_mode_value, 'single_organisation'); ?>><?php esc_html_e('Single-Organisation Event Sites', 'nexdirectory'); ?></option>
                                    </select>
                                    <p class="description"><?php esc_html_e('Single-Organisation mode hides self-publishing for members and switches event pages to ticket-driven registration only.', 'nexdirectory'); ?></p>
                                </div>

                                <div class="eep-settings-toggle-item">
                                    <input type="hidden" name="eep_onboarding_complete" value="0">
                                    <label><input type="checkbox" name="eep_onboarding_complete" value="1" <?php checked((string) get_option('eep_onboarding_complete', '0'), '1'); ?>> <?php esc_html_e('Onboarding completed', 'nexdirectory'); ?></label>
                                    <p class="description"><?php esc_html_e('Controls whether the onboarding wizard is treated as complete for this site.', 'nexdirectory'); ?></p>
                                </div>
                            </div>

                            <div class="eep-settings-core-actions">
                                <button type="submit" class="button button-secondary" form="eep-generate-pages-form"><?php esc_html_e('Generate Missing Pages', 'nexdirectory'); ?></button>
                                <p class="description"><?php esc_html_e('Creates missing platform pages and injects their default shortcode automatically.', 'nexdirectory'); ?></p>
                            </div>
                        </div>
                    </div>
                </section>

                <section class="eep-settings-panel" id="eep-tab-routing" data-tab="general" data-subtab="routing">
                    <h2><?php esc_html_e('Routing & Page URLs', 'nexdirectory'); ?></h2>
                    <p class="eep-settings-subheading"><?php esc_html_e('Map each frontend page URL and verify shortcode routing.', 'nexdirectory'); ?></p>

                    <div class="eep-settings-grid">
                        <?php $is_connected = !empty($settings_routing_health['connected']); ?>
                        <div class="eep-settings-field eep-full">
                            <div class="eep-settings-section-card eep-connection-card">
                                <div class="eep-connection-header">
                                    <h3><span class="dashicons dashicons-randomize"></span><?php esc_html_e('Routing Connection Status', 'nexdirectory'); ?></h3>
                                    <span class="eep-connection-badge <?php echo $is_connected ? 'is-connected' : 'is-disconnected'; ?>">
                                        <?php echo esc_html($is_connected ? __('Connected', 'nexdirectory') : __('Not connected', 'nexdirectory')); ?>
                                    </span>
                                </div>
                                <p class="description"><?php echo esc_html((string) ($settings_routing_health['summary'] ?? __('Creates missing frontend pages and injects default shortcodes for configured routes.', 'nexdirectory'))); ?></p>
                                <div class="eep-settings-actions eep-connection-actions">
                                    <button type="submit" class="button button-secondary" form="eep-test-routing-form"><?php esc_html_e('Test Routing', 'nexdirectory'); ?></button>
                                    <button type="submit" class="button button-secondary" form="eep-generate-pages-form"><?php esc_html_e('Generate Missing Pages', 'nexdirectory'); ?></button>
                                </div>
                            </div>
                        </div>

                        <?php
                        $url_fields = [
                            ['id' => 'eep_page_events_url', 'label' => sprintf(__('%s Page URL', 'nexdirectory'), (string) ($site_profile_ui['plural'] ?? __('Listings', 'nexdirectory'))), 'val' => $settings_events_page_url, 'ph' => $this->get_profile_route_default_url('events', $site_profile_value)],
                            ['id' => 'eep_login_redirect_url', 'label' => __('Post-Login Redirect URL', 'nexdirectory'), 'val' => get_option('eep_login_redirect_url', ''), 'ph' => home_url('/account/')],
                            ['id' => 'eep_page_events_map_url', 'label' => __('Map Page URL', 'nexdirectory'), 'val' => $settings_map_page_url, 'ph' => $this->get_profile_route_default_url('map', $site_profile_value)],
                            ['id' => 'eep_page_events_calendar_url', 'label' => __('Calendar Page URL', 'nexdirectory'), 'val' => $settings_calendar_page_url, 'ph' => $this->get_profile_route_default_url('calendar', $site_profile_value)],
                            ['id' => 'eep_page_submit_event_url', 'label' => sprintf(__('Add %s Page URL', 'nexdirectory'), (string) ($site_profile_ui['singular'] ?? __('Listing', 'nexdirectory'))), 'val' => $settings_submit_page_url, 'ph' => $this->get_profile_route_default_url('submit', $site_profile_value)],
                            ['id' => 'eep_page_my_events_url', 'label' => sprintf(__('My %s Page URL', 'nexdirectory'), (string) ($site_profile_ui['plural'] ?? __('Listings', 'nexdirectory'))), 'val' => $settings_my_items_page_url, 'ph' => $this->get_profile_route_default_url('my_items', $site_profile_value)],
                            ['id' => 'eep_page_boost_posts_url', 'label' => __('Boost Post Page URL', 'nexdirectory'), 'val' => $settings_boost_page_url, 'ph' => $this->get_profile_route_default_url('boost', $site_profile_value)],
                            ['id' => 'eep_page_owner_analytics_url', 'label' => __('Owner Analytics Page URL', 'nexdirectory'), 'val' => $settings_owner_analytics_page_url, 'ph' => $this->get_profile_route_default_url('analytics', $site_profile_value)],
                            ['id' => 'eep_page_my_tickets_url', 'label' => sprintf(__('%s Page URL', 'nexdirectory'), (string) ($site_profile_ui['attending_title'] ?? __('Saved Listings', 'nexdirectory'))), 'val' => $settings_saved_page_url, 'ph' => $this->get_profile_route_default_url('attending', $site_profile_value)],
                            ['id' => 'eep_page_whos_attending_url', 'label' => __('Who\'s Attending Page URL', 'nexdirectory'), 'val' => $settings_whos_attending_page_url, 'ph' => $this->get_profile_route_default_url('attendees', $site_profile_value)],
                            ['id' => 'eep_page_event_webapp_url', 'label' => __('Event Web App Page URL', 'nexdirectory'), 'val' => $settings_event_webapp_page_url, 'ph' => home_url('/event-app/')],
                            ['id' => 'eep_page_whats_new_url', 'label' => __('What\'s New Page URL', 'nexdirectory'), 'val' => $settings_whats_new_page_url, 'ph' => home_url('/whats-new/')],
                            ['id' => 'eep_page_account_url', 'label' => __('My Account Page URL', 'nexdirectory'), 'val' => $settings_account_page_url, 'ph' => $this->get_profile_route_default_url('account', $site_profile_value)],
                            ['id' => 'eep_page_login_signup_url', 'label' => __('Login/Signup Page URL', 'nexdirectory'), 'val' => $settings_auth_page_url, 'ph' => $this->get_profile_route_default_url('auth', $site_profile_value), 'desc' => __('Set custom URLs so redirects and CTA buttons always target your correct frontend pages.', 'nexdirectory')],
                            ['id' => 'eep_claim_listing_page_url', 'label' => __('Claim Listing Page URL', 'nexdirectory'), 'val' => $settings_claim_page_url, 'ph' => $this->get_profile_route_default_url('claim', $site_profile_value)],
                        ];
                        ?>
                        <?php foreach ($url_fields as $field) : ?>
                            <div class="eep-settings-field">
                                <label for="<?php echo esc_attr($field['id']); ?>"><?php echo esc_html($field['label']); ?></label>
                                <input
                                    type="url"
                                    id="<?php echo esc_attr($field['id']); ?>"
                                    name="<?php echo esc_attr($field['id']); ?>"
                                    value="<?php echo esc_attr((string) $field['val']); ?>"
                                    placeholder="<?php echo esc_attr((string) $field['ph']); ?>"
                                >
                                <?php if (isset($field['desc'])) : ?>
                                    <p class="description"><?php echo esc_html((string) $field['desc']); ?></p>
                                <?php endif; ?>
                            </div>
                        <?php endforeach; ?>

                        <div class="eep-settings-field eep-full">
                            <h3 class="eep-settings-core-title"><span class="dashicons dashicons-editor-code" aria-hidden="true"></span><?php esc_html_e('Page Routing Shortcodes', 'nexdirectory'); ?></h3>
                            <p class="description"><?php esc_html_e('Copy-ready shortcode references for each mapped page.', 'nexdirectory'); ?></p>

                            <?php
                            $route_shortcodes = [
                                ['label' => sprintf(__('%s Page', 'nexdirectory'), (string) ($site_profile_ui['plural'] ?? __('Listings', 'nexdirectory'))), 'code' => '[eep_listings_archive]'],
                                ['label' => __('Map Page', 'nexdirectory'), 'code' => '[eep_listings_map]'],
                                ['label' => __('Calendar Page', 'nexdirectory'), 'code' => '[eep_listings_calendar]'],
                                ['label' => __('Submit Listing Page', 'nexdirectory'), 'code' => '[eep_submit]'],
                                ['label' => __('User Dashboard Page', 'nexdirectory'), 'code' => '[eep_my_listings]'],
                                ['label' => __('Boost Post Page', 'nexdirectory'), 'code' => '[eep_boost_posts]'],
                                ['label' => (string) ($site_profile_ui['attending_title'] ?? __('Saved Listings', 'nexdirectory')), 'code' => '[eep_saved_listings]'],
                                ['label' => __('Who\'s Attending Page', 'nexdirectory'), 'code' => '[eep_whos_attending]'],
                                ['label' => __('Event Web App Page', 'nexdirectory'), 'code' => '[eep_event_webapp]'],
                                ['label' => __('What\'s New Page', 'nexdirectory'), 'code' => '[eep_whats_new]'],
                                ['label' => (string) ($site_profile_ui['owner_analytics_title'] ?? __('Analytics', 'nexdirectory')), 'code' => '[eep_owner_analytics]'],
                                ['label' => __('Account Setup Page', 'nexdirectory'), 'code' => '[eep_account]'],
                                ['label' => __('Login/Signup Page', 'nexdirectory'), 'code' => '[eep_auth]'],
                                ['label' => __('Auth Buttons / Account Menu', 'nexdirectory'), 'code' => '[eep_auth_links]'],
                                ['label' => __('Claim Listing Page', 'nexdirectory'), 'code' => '[eep_claim_listing]'],
                            ];
                            ?>
                            <div class="eep-settings-route-grid">
                                <?php foreach ($route_shortcodes as $rs) : ?>
                                    <div class="eep-settings-route-row">
                                        <strong><?php echo esc_html((string) $rs['label']); ?></strong>
                                        <div class="eep-shortcode-inline"><input type="text" readonly value="<?php echo esc_attr((string) $rs['code']); ?>"></div>
                                        <button type="button" class="button eep-copy-shortcode" data-shortcode="<?php echo esc_attr((string) $rs['code']); ?>"><?php esc_html_e('Copy', 'nexdirectory'); ?></button>
                                    </div>
                                <?php endforeach; ?>
                            </div>
                        </div>
                    </div>
                </section>

                <section class="eep-settings-panel" id="eep-tab-navbar" data-tab="general" data-subtab="navbar">
                    <h2><?php esc_html_e('Navbar', 'nexdirectory'); ?></h2>
                    <p class="eep-settings-subheading"><?php esc_html_e('Configure sticky navbar visibility, branding, and navigation menus for guest/member/admin/role states.', 'nexdirectory'); ?></p>

                    <div class="eep-settings-grid">
                        <div class="eep-settings-field eep-full">
                            <h3 class="eep-settings-core-title"><span class="dashicons dashicons-menu" aria-hidden="true"></span><?php esc_html_e('Sticky Navbar Behavior', 'nexdirectory'); ?></h3>

                            <div class="eep-settings-toggle-list">
                                <div class="eep-settings-toggle-item">
                                    <input type="hidden" name="eep_enable_frontend_sticky_nav" value="0">
                                    <label><input type="checkbox" name="eep_enable_frontend_sticky_nav" value="1" <?php checked((string) get_option('eep_enable_frontend_sticky_nav', '1'), '1'); ?>> <?php esc_html_e('Enable sticky navbar on frontend plugin pages', 'nexdirectory'); ?></label>
                                </div>
                            </div>

                            <div class="eep-settings-grid" style="margin-top:10px;">
                                <div class="eep-settings-field">
                                    <label for="eep_frontend_sticky_nav_behavior"><?php esc_html_e('Navbar behavior', 'nexdirectory'); ?></label>
                                    <select id="eep_frontend_sticky_nav_behavior" name="eep_frontend_sticky_nav_behavior">
                                        <option value="sticky" <?php selected($sticky_nav_behavior, 'sticky'); ?>><?php esc_html_e('Sticky (always visible)', 'nexdirectory'); ?></option>
                                        <option value="smart" <?php selected($sticky_nav_behavior, 'smart'); ?>><?php esc_html_e('Smart (hide on scroll down)', 'nexdirectory'); ?></option>
                                        <option value="static" <?php selected($sticky_nav_behavior, 'static'); ?>><?php esc_html_e('Static (not sticky)', 'nexdirectory'); ?></option>
                                    </select>
                                </div>
                                <div class="eep-settings-field">
                                    <label for="eep_nav_side_padding_desktop"><?php esc_html_e('Desktop Padding (L/R)', 'nexdirectory'); ?></label>
                                    <input type="text" id="eep_nav_side_padding_desktop" name="eep_nav_side_padding_desktop" value="<?php echo esc_attr($nav_side_padding_desktop_value); ?>" placeholder="0%">
                                    <p class="description"><?php esc_html_e('Default 0%. If empty, inherits Page Padding.', 'nexdirectory'); ?></p>
                                </div>
                            </div>

                            <div class="eep-settings-grid" style="margin-top:10px;">
                                <div class="eep-settings-field">
                                    <input type="hidden" name="eep_frontend_sticky_nav_show_for_guests" value="0">
                                    <label><input type="checkbox" name="eep_frontend_sticky_nav_show_for_guests" value="1" <?php checked((string) get_option('eep_frontend_sticky_nav_show_for_guests', '1'), '1'); ?>> <?php esc_html_e('Show for logged-out users', 'nexdirectory'); ?></label>
                                </div>
                                <div class="eep-settings-field">
                                    <input type="hidden" name="eep_frontend_sticky_nav_show_for_members" value="0">
                                    <label><input type="checkbox" name="eep_frontend_sticky_nav_show_for_members" value="1" <?php checked((string) get_option('eep_frontend_sticky_nav_show_for_members', '1'), '1'); ?>> <?php esc_html_e('Show for logged-in users', 'nexdirectory'); ?></label>
                                </div>
                                <div class="eep-settings-field">
                                    <input type="hidden" name="eep_frontend_sticky_nav_include_auth_cta" value="0">
                                    <label><input type="checkbox" name="eep_frontend_sticky_nav_include_auth_cta" value="1" <?php checked((string) get_option('eep_frontend_sticky_nav_include_auth_cta', '1'), '1'); ?>> <?php esc_html_e('Show auth CTA buttons in navbar', 'nexdirectory'); ?></label>
                                </div>
                                <div class="eep-settings-field">
                                    <input type="hidden" name="eep_frontend_sticky_nav_show_logo" value="0">
                                    <label><input type="checkbox" name="eep_frontend_sticky_nav_show_logo" value="1" <?php checked((string) get_option('eep_frontend_sticky_nav_show_logo', '1'), '1'); ?>> <?php esc_html_e('Show logo in navbar', 'nexdirectory'); ?></label>
                                </div>
                                <div class="eep-settings-field eep-full">
                                    <input type="hidden" name="eep_show_frontend_auth_links" value="0">
                                    <label><input type="checkbox" name="eep_show_frontend_auth_links" value="1" <?php checked((string) get_option('eep_show_frontend_auth_links', '1'), '1'); ?>> <?php esc_html_e('Render frontend auth links block automatically', 'nexdirectory'); ?></label>
                                </div>
                            </div>
                        </div>

                        <div class="eep-settings-field eep-full">
                            <h3 class="eep-settings-core-title"><span class="dashicons dashicons-format-image" aria-hidden="true"></span><?php esc_html_e('Brand Logo', 'nexdirectory'); ?></h3>
                            <div class="eep-settings-grid">
                                <div class="eep-settings-field eep-full">
                                    <label for="eep_frontend_sticky_nav_logo_url"><?php esc_html_e('Logo image', 'nexdirectory'); ?></label>
                                    <input type="hidden" id="eep_frontend_sticky_nav_logo_url" name="eep_frontend_sticky_nav_logo_url" value="<?php echo esc_attr((string) $sticky_nav_logo_url); ?>">
                                    <div class="eep-media-picker" data-eep-media-picker data-eep-media-target="#eep_frontend_sticky_nav_logo_url" data-eep-media-multiple="0" data-eep-upload-target="cover">
                                        <button type="button" class="eep-media-dropzone" data-eep-media-open>
                                            <span class="dashicons dashicons-format-image" aria-hidden="true"></span>
                                            <strong><?php esc_html_e('Choose logo image', 'nexdirectory'); ?></strong>
                                            <span><?php esc_html_e('Use Media Library or drag and drop', 'nexdirectory'); ?></span>
                                        </button>
                                        <input type="file" accept="image/*" hidden data-eep-media-file-input>
                                        <div class="eep-fallback-preview-single eep-media-gallery" id="eep-sticky-nav-logo-preview">
                                            <?php if ($sticky_nav_logo_url !== '') : ?>
                                                <div class="eep-media-tile" data-eep-media-url="<?php echo esc_attr($sticky_nav_logo_url); ?>">
                                                    <img src="<?php echo esc_url($sticky_nav_logo_url); ?>" alt="<?php esc_attr_e('Sticky nav logo', 'nexdirectory'); ?>">
                                                    <button type="button" class="eep-media-remove" data-eep-media-remove aria-label="<?php esc_attr_e('Remove logo image', 'nexdirectory'); ?>">&times;</button>
                                                </div>
                                            <?php endif; ?>
                                        </div>
                                        <p class="description eep-media-feedback" data-eep-media-feedback></p>
                                    </div>
                                </div>
                                <div class="eep-settings-field">
                                    <label for="eep_frontend_sticky_nav_logo_link_url"><?php esc_html_e('Logo link URL', 'nexdirectory'); ?></label>
                                    <input type="url" id="eep_frontend_sticky_nav_logo_link_url" name="eep_frontend_sticky_nav_logo_link_url" value="<?php echo esc_attr((string) $sticky_nav_logo_link_url); ?>" placeholder="<?php echo esc_attr(home_url('/')); ?>">
                                </div>
                                <div class="eep-settings-field">
                                    <label for="eep_frontend_sticky_nav_logo_size"><?php esc_html_e('Logo size', 'nexdirectory'); ?></label>
                                    <input type="text" id="eep_frontend_sticky_nav_logo_size" name="eep_frontend_sticky_nav_logo_size" value="<?php echo esc_attr($this->sanitize_sticky_nav_logo_size_option((string) get_option('eep_frontend_sticky_nav_logo_size', '66px'))); ?>" placeholder="66px">
                                    <p class="description"><?php esc_html_e('Height format (px/rem/em). Between 18px to 96px.', 'nexdirectory'); ?></p>
                                </div>
                            </div>
                        </div>

                        <div class="eep-settings-field eep-full">
                            <h3 class="eep-settings-core-title"><span class="dashicons dashicons-admin-links" aria-hidden="true"></span><?php esc_html_e('WP Menu Source', 'nexdirectory'); ?></h3>
                            <input type="hidden" name="eep_frontend_sticky_nav_use_wp_menus" value="0">
                            <label><input type="checkbox" name="eep_frontend_sticky_nav_use_wp_menus" value="1" <?php checked($sticky_nav_use_wp_menus); ?>> <?php esc_html_e('Use WordPress Menus for navbar dropdowns', 'nexdirectory'); ?></label>
                            <p class="description"><?php esc_html_e('When enabled, selected WordPress menus replace auto-generated nav links. Parent/child menu items are used as dropdown structure.', 'nexdirectory'); ?></p>
                            <?php if (empty($sticky_nav_wp_menus)) : ?>
                                <?php if ($sticky_nav_use_wp_menus) : ?>
                                    <p class="description">
                                        <?php
                                        echo wp_kses_post(
                                            sprintf(
                                                __('No WordPress menus found. <a href="%s">Open Appearance &gt; Menus</a> to create one.', 'nexdirectory'),
                                                esc_url(admin_url('themes.php?page=eep-wp-menu-source'))
                                            )
                                        );
                                        ?>
                                    </p>
                                <?php else : ?>
                                    <p class="description"><?php esc_html_e('No WordPress menus found yet. Enable WP Menu Source and save to unlock Appearance > Menus access for menu setup.', 'nexdirectory'); ?></p>
                                <?php endif; ?>
                            <?php endif; ?>

                            <div class="eep-settings-grid" style="margin-top:10px;">
                                <div class="eep-settings-field">
                                    <label for="eep_frontend_sticky_nav_wp_menu_guest"><?php esc_html_e('Menu: Logged-out', 'nexdirectory'); ?></label>
                                    <select id="eep_frontend_sticky_nav_wp_menu_guest" name="eep_frontend_sticky_nav_wp_menu_guest">
                                        <option value="0"><?php esc_html_e('Auto-generated links', 'nexdirectory'); ?></option>
                                        <?php foreach ($sticky_nav_wp_menus as $menu_obj) : ?>
                                            <?php $menu_id = isset($menu_obj->term_id) ? absint((int) $menu_obj->term_id) : 0; if ($menu_id <= 0) { continue; } ?>
                                            <option value="<?php echo esc_attr((string) $menu_id); ?>" <?php selected($sticky_nav_wp_menu_guest, $menu_id); ?>><?php echo esc_html((string) $menu_obj->name); ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                                <div class="eep-settings-field">
                                    <label for="eep_frontend_sticky_nav_wp_menu_member"><?php esc_html_e('Menu: Members', 'nexdirectory'); ?></label>
                                    <select id="eep_frontend_sticky_nav_wp_menu_member" name="eep_frontend_sticky_nav_wp_menu_member">
                                        <option value="0"><?php esc_html_e('Auto-generated links', 'nexdirectory'); ?></option>
                                        <?php foreach ($sticky_nav_wp_menus as $menu_obj) : ?>
                                            <?php $menu_id = isset($menu_obj->term_id) ? absint((int) $menu_obj->term_id) : 0; if ($menu_id <= 0) { continue; } ?>
                                            <option value="<?php echo esc_attr((string) $menu_id); ?>" <?php selected($sticky_nav_wp_menu_member, $menu_id); ?>><?php echo esc_html((string) $menu_obj->name); ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                                <div class="eep-settings-field">
                                    <label for="eep_frontend_sticky_nav_wp_menu_admin"><?php esc_html_e('Menu: Admins', 'nexdirectory'); ?></label>
                                    <select id="eep_frontend_sticky_nav_wp_menu_admin" name="eep_frontend_sticky_nav_wp_menu_admin">
                                        <option value="0"><?php esc_html_e('Auto-generated links', 'nexdirectory'); ?></option>
                                        <?php foreach ($sticky_nav_wp_menus as $menu_obj) : ?>
                                            <?php $menu_id = isset($menu_obj->term_id) ? absint((int) $menu_obj->term_id) : 0; if ($menu_id <= 0) { continue; } ?>
                                            <option value="<?php echo esc_attr((string) $menu_id); ?>" <?php selected($sticky_nav_wp_menu_admin, $menu_id); ?>><?php echo esc_html((string) $menu_obj->name); ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>

                            <details class="eep-settings-accordion">
                                <summary><?php esc_html_e('Advanced: Menu overrides by specific user role', 'nexdirectory'); ?></summary>
                                <p class="description"><?php esc_html_e('Optional: assign a menu to a specific role. Role menu takes priority over the standard member menu.', 'nexdirectory'); ?></p>
                                <div class="eep-settings-grid">
                                    <?php foreach ($sticky_nav_role_options as $role_slug => $role_data) : ?>
                                        <?php
                                        $role_slug = sanitize_key((string) $role_slug);
                                        if ($role_slug === '') {
                                            continue;
                                        }
                                        $role_label = isset($role_data['name']) ? translate_user_role((string) $role_data['name']) : ucfirst($role_slug);
                                        $selected_menu_id = isset($sticky_nav_wp_menu_roles[$role_slug]) ? absint((int) $sticky_nav_wp_menu_roles[$role_slug]) : 0;
                                        ?>
                                        <div class="eep-settings-field">
                                            <label for="eep_frontend_sticky_nav_wp_menu_role_<?php echo esc_attr($role_slug); ?>"><?php echo esc_html($role_label); ?></label>
                                            <select id="eep_frontend_sticky_nav_wp_menu_role_<?php echo esc_attr($role_slug); ?>" name="eep_frontend_sticky_nav_wp_menu_roles[<?php echo esc_attr($role_slug); ?>]">
                                                <option value="0"><?php esc_html_e('No role override', 'nexdirectory'); ?></option>
                                                <?php foreach ($sticky_nav_wp_menus as $menu_obj) : ?>
                                                    <?php $menu_id = isset($menu_obj->term_id) ? absint((int) $menu_obj->term_id) : 0; if ($menu_id <= 0) { continue; } ?>
                                                    <option value="<?php echo esc_attr((string) $menu_id); ?>" <?php selected($selected_menu_id, $menu_id); ?>><?php echo esc_html((string) $menu_obj->name); ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                    <?php endforeach; ?>
                                </div>
                            </details>

                            <div style="margin-top:10px;">
                                <label for="eep_frontend_sticky_nav_custom_links"><?php esc_html_e('Custom Hardcoded Links (Optional)', 'nexdirectory'); ?></label>
                                <textarea id="eep_frontend_sticky_nav_custom_links" name="eep_frontend_sticky_nav_custom_links" rows="6" placeholder="<?php echo esc_attr("Label|https://example.com|all|More\nTeam|/team/|member|Workspace"); ?>"><?php echo esc_textarea($sticky_nav_custom_links_value); ?></textarea>
                                <p class="description"><?php esc_html_e('Format per line: Label|URL|Audience|Group. Audience can be all, guest, or member. Group becomes dropdown label for auto-generated nav mode.', 'nexdirectory'); ?></p>
                            </div>
                        </div>
                    </div>
                </section>

                <section class="eep-settings-panel" id="eep-tab-footer" data-tab="general" data-subtab="footer">
                    <h2><?php esc_html_e('Footer', 'nexdirectory'); ?></h2>
                    <p class="eep-settings-subheading"><?php esc_html_e('Configure the default platform footer with brand logo, responsive menu columns, and legal info.', 'nexdirectory'); ?></p>

                    <div class="eep-settings-grid">
                        <div class="eep-settings-field eep-full">
                            <h3 class="eep-settings-core-title"><span class="dashicons dashicons-editor-kitchensink" aria-hidden="true"></span><?php esc_html_e('Footer Behavior', 'nexdirectory'); ?></h3>

                            <div class="eep-settings-grid">
                                <div class="eep-settings-field">
                                    <input type="hidden" name="eep_enable_frontend_footer" value="0">
                                    <label><input type="checkbox" name="eep_enable_frontend_footer" value="1" <?php checked($footer_enabled); ?>> <?php esc_html_e('Enable platform footer on frontend plugin pages', 'nexdirectory'); ?></label>
                                </div>
                                <div class="eep-settings-field">
                                    <input type="hidden" name="eep_frontend_footer_show_logo" value="0">
                                    <label><input type="checkbox" name="eep_frontend_footer_show_logo" value="1" <?php checked($footer_show_logo); ?>> <?php esc_html_e('Show logo / brand block in footer', 'nexdirectory'); ?></label>
                                </div>
                                <div class="eep-settings-field">
                                    <input type="hidden" name="eep_frontend_footer_show_privacy_link" value="0">
                                    <label><input type="checkbox" name="eep_frontend_footer_show_privacy_link" value="1" <?php checked($footer_show_privacy_link); ?>> <?php esc_html_e('Show Privacy Policy link in footer legal row', 'nexdirectory'); ?></label>
                                </div>
                                <div class="eep-settings-field">
                                    <label for="eep_frontend_footer_menu_count"><?php esc_html_e('Footer Menu Columns (Desktop)', 'nexdirectory'); ?></label>
                                    <select id="eep_frontend_footer_menu_count" name="eep_frontend_footer_menu_count">
                                        <?php for ($i = 1; $i <= 5; $i++) : ?>
                                            <option value="<?php echo esc_attr((string) $i); ?>" <?php selected($footer_menu_count, $i); ?>>
                                                <?php
                                                echo esc_html(
                                                    sprintf(
                                                        _n('%d column', '%d columns', $i, 'nexdirectory'),
                                                        $i
                                                    )
                                                );
                                                ?>
                                            </option>
                                        <?php endfor; ?>
                                    </select>
                                    <p class="description"><?php esc_html_e('Mobile footer menu layout always uses two columns.', 'nexdirectory'); ?></p>
                                </div>
                                <div class="eep-settings-field eep-full">
                                    <label for="eep_frontend_footer_bottom_text"><?php esc_html_e('Footer Bottom Text (Optional)', 'nexdirectory'); ?></label>
                                    <input type="text" id="eep_frontend_footer_bottom_text" name="eep_frontend_footer_bottom_text" value="<?php echo esc_attr($footer_bottom_text); ?>" placeholder="<?php esc_attr_e('Example: Built for engineers, by engineers.', 'nexdirectory'); ?>">
                                </div>
                            </div>
                        </div>

                        <div class="eep-settings-field eep-full">
                            <h3 class="eep-settings-core-title"><span class="dashicons dashicons-format-image" aria-hidden="true"></span><?php esc_html_e('Footer Brand Logo', 'nexdirectory'); ?></h3>
                            <div class="eep-settings-grid">
                                <div class="eep-settings-field eep-full">
                                    <label for="eep_frontend_footer_logo_url"><?php esc_html_e('Footer logo image', 'nexdirectory'); ?></label>
                                    <input type="hidden" id="eep_frontend_footer_logo_url" name="eep_frontend_footer_logo_url" value="<?php echo esc_attr((string) $footer_logo_url); ?>">
                                    <div class="eep-media-picker" data-eep-media-picker data-eep-media-target="#eep_frontend_footer_logo_url" data-eep-media-multiple="0" data-eep-upload-target="cover">
                                        <button type="button" class="eep-media-dropzone" data-eep-media-open>
                                            <span class="dashicons dashicons-format-image" aria-hidden="true"></span>
                                            <strong><?php esc_html_e('Choose footer logo', 'nexdirectory'); ?></strong>
                                            <span><?php esc_html_e('Use Media Library or drag and drop', 'nexdirectory'); ?></span>
                                        </button>
                                        <input type="file" accept="image/*" hidden data-eep-media-file-input>
                                        <div class="eep-fallback-preview-single eep-media-gallery" id="eep-footer-logo-preview">
                                            <?php if ($footer_logo_url !== '') : ?>
                                                <div class="eep-media-tile" data-eep-media-url="<?php echo esc_attr($footer_logo_url); ?>">
                                                    <img src="<?php echo esc_url($footer_logo_url); ?>" alt="<?php esc_attr_e('Footer logo', 'nexdirectory'); ?>">
                                                    <button type="button" class="eep-media-remove" data-eep-media-remove aria-label="<?php esc_attr_e('Remove footer logo image', 'nexdirectory'); ?>">&times;</button>
                                                </div>
                                            <?php endif; ?>
                                        </div>
                                        <p class="description eep-media-feedback" data-eep-media-feedback></p>
                                    </div>
                                </div>
                                <div class="eep-settings-field">
                                    <label for="eep_frontend_footer_logo_link_url"><?php esc_html_e('Footer logo link URL', 'nexdirectory'); ?></label>
                                    <input type="url" id="eep_frontend_footer_logo_link_url" name="eep_frontend_footer_logo_link_url" value="<?php echo esc_attr((string) $footer_logo_link_url); ?>" placeholder="<?php echo esc_attr(home_url('/')); ?>">
                                </div>
                            </div>
                        </div>

                        <div class="eep-settings-field eep-full">
                            <h3 class="eep-settings-core-title"><span class="dashicons dashicons-admin-links" aria-hidden="true"></span><?php esc_html_e('WP Menu Source', 'nexdirectory'); ?></h3>
                            <input type="hidden" name="eep_frontend_footer_use_wp_menus" value="0">
                            <label><input type="checkbox" name="eep_frontend_footer_use_wp_menus" value="1" <?php checked($footer_use_wp_menus); ?>> <?php esc_html_e('Use WordPress Menus for footer columns', 'nexdirectory'); ?></label>
                            <p class="description"><?php esc_html_e('Select up to 5 menu columns. Footer auto-spaces columns based on your selected column count, and empty columns fall back to generated links.', 'nexdirectory'); ?></p>
                            <?php if (empty($sticky_nav_wp_menus)) : ?>
                                <?php if ($footer_use_wp_menus) : ?>
                                    <p class="description">
                                        <?php
                                        echo wp_kses_post(
                                            sprintf(
                                                __('No WordPress menus found. <a href="%s">Open Appearance &gt; Menus</a> to create one.', 'nexdirectory'),
                                                esc_url(admin_url('themes.php?page=eep-wp-menu-source'))
                                            )
                                        );
                                        ?>
                                    </p>
                                <?php else : ?>
                                    <p class="description"><?php esc_html_e('No WordPress menus found yet. Enable WP Menu Source and save to unlock Appearance > Menus access for menu setup.', 'nexdirectory'); ?></p>
                                <?php endif; ?>
                            <?php endif; ?>

                            <div class="eep-settings-grid" style="margin-top:10px;">
                                <?php for ($i = 0; $i < 5; $i++) : ?>
                                    <?php $selected_menu_id = isset($footer_wp_menu_ids[$i]) ? absint((int) $footer_wp_menu_ids[$i]) : 0; ?>
                                    <div class="eep-settings-field">
                                        <label for="eep_frontend_footer_wp_menus_<?php echo esc_attr((string) ($i + 1)); ?>">
                                            <?php
                                            echo esc_html(
                                                sprintf(
                                                    __('Footer Column %d Menu', 'nexdirectory'),
                                                    $i + 1
                                                )
                                            );
                                            ?>
                                        </label>
                                        <select id="eep_frontend_footer_wp_menus_<?php echo esc_attr((string) ($i + 1)); ?>" name="eep_frontend_footer_wp_menus[<?php echo esc_attr((string) $i); ?>]">
                                            <option value="0"><?php esc_html_e('Auto-generated links', 'nexdirectory'); ?></option>
                                            <?php foreach ($sticky_nav_wp_menus as $menu_obj) : ?>
                                                <?php $menu_id = isset($menu_obj->term_id) ? absint((int) $menu_obj->term_id) : 0; if ($menu_id <= 0) { continue; } ?>
                                                <option value="<?php echo esc_attr((string) $menu_id); ?>" <?php selected($selected_menu_id, $menu_id); ?>><?php echo esc_html((string) $menu_obj->name); ?></option>
                                            <?php endforeach; ?>
                                        </select>
                                    </div>
                                <?php endfor; ?>
                            </div>
                        </div>
                    </div>
                </section>

                <section class="eep-settings-panel" id="eep-tab-shortcodes" data-tab="general" data-subtab="shortcodes">
                    <h2><?php esc_html_e('Available Shortcodes', 'nexdirectory'); ?></h2>
                    <p class="eep-settings-subheading"><?php esc_html_e('Reference all frontend shortcodes and aliases with one-click copy.', 'nexdirectory'); ?></p>
                    <p class="description"><?php esc_html_e('Use these in Gutenberg, classic editor, and builder HTML/text widgets.', 'nexdirectory'); ?></p>

                    <table class="widefat striped eep-shortcode-table">
                        <thead>
                            <tr>
                                <th><?php esc_html_e('Shortcode', 'nexdirectory'); ?></th>
                                <th><?php esc_html_e('Purpose', 'nexdirectory'); ?></th>
                                <th class="eep-shortcode-copy-cell"><?php esc_html_e('Action', 'nexdirectory'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($shortcodes as $shortcode) : ?>
                                <tr>
                                    <td><code><?php echo esc_html((string) $shortcode['code']); ?></code></td>
                                    <td><?php echo esc_html((string) $shortcode['usage']); ?></td>
                                    <td class="eep-shortcode-copy-cell">
                                        <button type="button" class="button eep-copy-shortcode" data-shortcode="<?php echo esc_attr((string) $shortcode['code']); ?>"><?php esc_html_e('Copy', 'nexdirectory'); ?></button>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>

                    <details class="eep-settings-accordion">
                        <summary><?php esc_html_e('Show Builder Compatibility Aliases (Legacy)', 'nexdirectory'); ?></summary>
                        <p class="description"><?php esc_html_e('Aliases exist for legacy templates. You only need one shortcode set, not both.', 'nexdirectory'); ?></p>
                        <table class="widefat striped eep-shortcode-table">
                            <thead>
                                <tr>
                                    <th><?php esc_html_e('Shortcode', 'nexdirectory'); ?></th>
                                    <th><?php esc_html_e('Purpose', 'nexdirectory'); ?></th>
                                    <th class="eep-shortcode-copy-cell"><?php esc_html_e('Action', 'nexdirectory'); ?></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($shortcode_aliases as $shortcode) : ?>
                                    <tr>
                                        <td><code><?php echo esc_html((string) $shortcode['code']); ?></code></td>
                                        <td><?php echo esc_html((string) $shortcode['usage']); ?></td>
                                        <td class="eep-shortcode-copy-cell">
                                            <button type="button" class="button eep-copy-shortcode" data-shortcode="<?php echo esc_attr((string) $shortcode['code']); ?>"><?php esc_html_e('Copy', 'nexdirectory'); ?></button>
                                        </td>
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </details>
                </section>
