<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Templates use local variables supplied by the render context.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}
?>
                <section class="nexdirectory-settings-panel is-active" id="nexdirectory-tab-pages" data-tab="general" data-subtab="setup">
                    <h2><?php esc_html_e('General setup', 'nexdirectory'); ?></h2>
                    <p class="nexdirectory-settings-subheading"><?php esc_html_e('Choose the type of directory you are building, who can add listings, and whether Nex Directory should create missing pages for you.', 'nexdirectory'); ?></p>

                    <?php if (!empty($starter_blueprints)) : ?>
                        <div class="nexdirectory-settings-grid">
                            <div class="nexdirectory-settings-field nexdirectory-full">
                                <h3 class="nexdirectory-settings-core-title"><span class="dashicons dashicons-layout" aria-hidden="true"></span><?php esc_html_e('Setup templates', 'nexdirectory'); ?></h3>
                                <p class="description"><?php esc_html_e('Choose a ready-made starting point. Each setup updates your labels and design, creates any missing pages, refreshes links, and can add safe sample content. Existing listings are never deleted.', 'nexdirectory'); ?></p>

                                <div class="nexdirectory-blueprint-grid">
                                    <?php foreach ($starter_blueprints as $blueprint_key => $blueprint) : ?>
                                        <?php
                                        $blueprint_key = sanitize_key((string) $blueprint_key);
                                        $blueprint = is_array($blueprint) ? $blueprint : [];
                                        if ($blueprint_key === '') {
                                            continue;
                                        }
                                        $blueprint_label = sanitize_text_field((string) ($blueprint['label'] ?? $blueprint_key));
                                        $blueprint_description = sanitize_text_field((string) ($blueprint['description'] ?? ''));
                                        $blueprint_features = array_values(array_filter(array_map('sanitize_text_field', (array) ($blueprint['features'] ?? []))));
                                        $blueprint_form_id = 'nexdirectory-blueprint-form-' . $blueprint_key;
                                        $is_active_blueprint = $active_starter_blueprint === $blueprint_key;
                                        $blueprint_icon = sanitize_html_class((string) ($blueprint['icon'] ?? 'layer-group'), 'layer-group');
                                        $blueprint_sample_count = max(0, min(12, (int) ($blueprint['sample_count'] ?? 6)));
                                        $confirmation_message = sprintf(
                                            /* translators: 1: Starter blueprint label. 2: Number of sample listings. */
                                            __('Use the %1$s setup? This updates your labels, selected design, feature defaults, pages, and links. It can also add up to %2$d sample listings. Existing listings will not be deleted.', 'nexdirectory'),
                                            $blueprint_label,
                                            $blueprint_sample_count
                                        );
                                        /* translators: %s: Starter blueprint label. */
                                        $blueprint_confirm_title = sprintf(__('Use the %s setup?', 'nexdirectory'), $blueprint_label);
                                        if ($is_active_blueprint) {
                                            /* translators: %s: Starter blueprint label. */
                                            $blueprint_action_label = sprintf(__('Apply %s again', 'nexdirectory'), $blueprint_label);
                                        } else {
                                            /* translators: %s: Starter blueprint label. */
                                            $blueprint_action_label = sprintf(__('Use %s', 'nexdirectory'), $blueprint_label);
                                        }
                                        ?>
                                        <article class="nexdirectory-blueprint-card <?php echo $is_active_blueprint ? 'is-active' : ''; ?>">
                                            <div class="nexdirectory-blueprint-card__header">
                                                <span class="nexdirectory-blueprint-card__icon"><i class="fas fa-<?php echo esc_attr($blueprint_icon); ?>" aria-hidden="true"></i></span>
                                                <div>
                                                    <h4 class="nexdirectory-blueprint-card__title">
                                                        <?php echo esc_html($blueprint_label); ?>
                                                        <?php if ($is_active_blueprint) : ?>
                                                            <span class="nexdirectory-blueprint-card__badge"><?php esc_html_e('Active', 'nexdirectory'); ?></span>
                                                        <?php endif; ?>
                                                    </h4>
                                                    <?php if ($blueprint_description !== '') : ?>
                                                        <p class="nexdirectory-blueprint-card__description"><?php echo esc_html($blueprint_description); ?></p>
                                                    <?php endif; ?>
                                                </div>
                                            </div>

                                            <?php if (!empty($blueprint_features)) : ?>
                                                <ul class="nexdirectory-blueprint-card__features">
                                                    <?php foreach ($blueprint_features as $feature) : ?>
                                                        <li><span class="dashicons dashicons-yes-alt" aria-hidden="true"></span><span><?php echo esc_html($feature); ?></span></li>
                                                    <?php endforeach; ?>
                                                </ul>
                                            <?php endif; ?>

                                            <div class="nexdirectory-blueprint-card__actions">
                                                <small>
                                                    <?php
                                                    echo esc_html(
                                                        $blueprint_sample_count > 0
                                                            ? sprintf(
                                                                /* translators: %d: Number of sample listings. */
                                                                _n( 'Pages + settings + %d sample', 'Pages + settings + %d samples', $blueprint_sample_count, 'nexdirectory' ),
                                                                $blueprint_sample_count
                                                            )
                                                            : __( 'Pages + settings; no samples', 'nexdirectory' )
                                                    );
                                                    ?>
                                                </small>
                                                <button
                                                    type="button"
                                                    class="button <?php echo $is_active_blueprint ? 'button-secondary' : 'button-primary'; ?>"
                                                    data-nexdirectory-blueprint-trigger
                                                    data-blueprint-form-id="<?php echo esc_attr($blueprint_form_id); ?>"
                                                    data-blueprint-confirm-title="<?php echo esc_attr($blueprint_confirm_title); ?>"
                                                    data-blueprint-confirm-message="<?php echo esc_attr($confirmation_message); ?>"
                                                    data-blueprint-confirm-label="<?php echo esc_attr($blueprint_action_label); ?>"
                                                ><?php echo esc_html($blueprint_action_label); ?></button>
                                            </div>
                                        </article>
                                    <?php endforeach; ?>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>

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

                            <div class="nexdirectory-settings-field-grid">
                                <div>
                                    <label for="nexdirectory_site_profile"><?php esc_html_e('Directory type', 'nexdirectory'); ?></label>
                                    <select id="nexdirectory_site_profile" name="nexdirectory_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'] ?? ''));
                                            ?>
                                            <option value="<?php echo esc_attr($profile_key); ?>" <?php selected($site_profile_value, $profile_key); ?>>
                                                <?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('Choose the wording and page structure used across public pages, dashboards, submissions, and accounts.', 'nexdirectory'); ?></p>
                                </div>

                                <div>
                                    <label for="nexdirectory_platform_mode"><?php esc_html_e('Who can add listings?', 'nexdirectory'); ?></label>
                                    <select id="nexdirectory_platform_mode" name="nexdirectory_platform_mode">
                                        <option value="user_generated" <?php selected($platform_mode_value, 'user_generated'); ?>><?php esc_html_e('Members can submit listings (default)', 'nexdirectory'); ?></option>
                                        <option value="single_organisation" <?php selected($platform_mode_value, 'single_organisation'); ?>><?php esc_html_e('Only admins can manage listings', 'nexdirectory'); ?></option>
                                    </select>
                                    <p class="description"><?php esc_html_e('Choose whether this is a community directory or a site managed only by your team.', 'nexdirectory'); ?></p>
                                </div>

                                <div class="nexdirectory-settings-toggle-item">
                                    <input type="hidden" name="nexdirectory_onboarding_complete" value="0">
                                    <label><input type="checkbox" name="nexdirectory_onboarding_complete" value="1" <?php checked((string) get_option('nexdirectory_onboarding_complete', '0'), '1'); ?>> <?php esc_html_e('Onboarding completed', 'nexdirectory'); ?></label>
                                    <p class="description"><?php esc_html_e('Turn this off if you want the setup guide to appear again.', 'nexdirectory'); ?></p>
                                </div>
                            </div>

                            <div class="nexdirectory-settings-core-actions">
                                <button type="submit" class="button button-secondary" form="nexdirectory-generate-pages-form"><?php esc_html_e('Create missing pages', 'nexdirectory'); ?></button>
                                <p class="description"><?php esc_html_e('Adds any missing public pages and places the correct shortcode on each one.', 'nexdirectory'); ?></p>
                            </div>
                        </div>
                    </div>
                </section>

                <section class="nexdirectory-settings-panel" id="nexdirectory-tab-routing" data-tab="general" data-subtab="routing">
                    <h2><?php esc_html_e('Pages and URLs', 'nexdirectory'); ?></h2>
                    <p class="nexdirectory-settings-subheading"><?php esc_html_e('Tell Nex Directory which public pages to use for listings, maps, accounts, submissions, and login links.', 'nexdirectory'); ?></p>

                    <div class="nexdirectory-settings-grid">
                        <?php $is_connected = !empty($settings_routing_health['connected']); ?>
                        <div class="nexdirectory-settings-field nexdirectory-full">
                            <div class="nexdirectory-settings-section-card nexdirectory-connection-card">
                                <div class="nexdirectory-connection-header">
                                    <h3><span class="dashicons dashicons-randomize"></span><?php esc_html_e('Page link status', 'nexdirectory'); ?></h3>
                                    <span class="nexdirectory-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 public pages and adds the default shortcodes.', 'nexdirectory'))); ?></p>
                                <div class="nexdirectory-settings-actions nexdirectory-connection-actions">
                                    <button type="submit" class="button button-secondary" form="nexdirectory-test-routing-form"><?php esc_html_e('Check page links', 'nexdirectory'); ?></button>
                                    <button type="submit" class="button button-secondary" form="nexdirectory-generate-pages-form"><?php esc_html_e('Create missing pages', 'nexdirectory'); ?></button>
                                </div>
                            </div>
                        </div>

                        <?php
                        $url_fields = [
                            /* translators: %s: Placeholder value. */
                            ['id' => 'nexdirectory_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' => 'nexdirectory_login_redirect_url', 'label' => __('Post-Login Redirect URL', 'nexdirectory'), 'val' => get_option('nexdirectory_login_redirect_url', ''), 'ph' => home_url('/account/')],
                            ['id' => 'nexdirectory_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' => 'nexdirectory_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)],
                            /* translators: %s: Placeholder value. */
                            ['id' => 'nexdirectory_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)],
                            /* translators: %s: Placeholder value. */
                            ['id' => 'nexdirectory_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)],
                            /* translators: %s: Placeholder value. */
                            ['id' => 'nexdirectory_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' => 'nexdirectory_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' => 'nexdirectory_page_whats_new_url', 'label' => __('What\'s New Page URL', 'nexdirectory'), 'val' => $settings_whats_new_page_url, 'ph' => home_url('/whats-new/')],
                            ['id' => 'nexdirectory_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' => 'nexdirectory_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' => 'nexdirectory_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="nexdirectory-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="nexdirectory-settings-field nexdirectory-full">
                            <h3 class="nexdirectory-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('Use these shortcodes if you want to place a Nex Directory screen on a custom page.', 'nexdirectory'); ?></p>

                            <?php
                            $route_shortcodes = [
                                /* translators: %s: Placeholder value. */
                                ['label' => sprintf(__('%s Page', 'nexdirectory'), (string) ($site_profile_ui['plural'] ?? __('Listings', 'nexdirectory'))), 'code' => '[nexdirectory_listings_archive]'],
                                ['label' => __('Map Page', 'nexdirectory'), 'code' => '[nexdirectory_listings_map]'],
                                ['label' => __('Calendar Page', 'nexdirectory'), 'code' => '[nexdirectory_listings_calendar]'],
                                ['label' => __('Submit Listing Page', 'nexdirectory'), 'code' => '[nexdirectory_submit]'],
                                ['label' => __('User Dashboard Page', 'nexdirectory'), 'code' => '[nexdirectory_my_listings]'],
                                ['label' => (string) ($site_profile_ui['attending_title'] ?? __('Saved Listings', 'nexdirectory')), 'code' => '[nexdirectory_saved_listings]'],
                                ['label' => __('Who\'s Attending Page', 'nexdirectory'), 'code' => '[nexdirectory_whos_attending]'],
                                ['label' => __('What\'s New Page', 'nexdirectory'), 'code' => '[nexdirectory_whats_new]'],
                                ['label' => __('Account Setup Page', 'nexdirectory'), 'code' => '[nexdirectory_account]'],
                                ['label' => __('Login/Signup Page', 'nexdirectory'), 'code' => '[nexdirectory_auth]'],
                                ['label' => __('Auth Buttons / Account Menu', 'nexdirectory'), 'code' => '[nexdirectory_auth_links]'],
                                ['label' => __('Claim Listing Page', 'nexdirectory'), 'code' => '[nexdirectory_claim_listing]'],
                            ];
                            ?>
                            <div class="nexdirectory-settings-route-grid">
                                <?php foreach ($route_shortcodes as $rs) : ?>
                                    <div class="nexdirectory-settings-route-row">
                                        <strong><?php echo esc_html((string) $rs['label']); ?></strong>
                                        <div class="nexdirectory-shortcode-inline"><input type="text" readonly value="<?php echo esc_attr((string) $rs['code']); ?>"></div>
                                        <button type="button" class="button nexdirectory-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="nexdirectory-settings-panel" id="nexdirectory-tab-navbar" data-tab="general" data-subtab="navbar">
                    <h2><?php esc_html_e('Navbar', 'nexdirectory'); ?></h2>
                    <p class="nexdirectory-settings-subheading"><?php esc_html_e('Configure sticky navbar visibility, branding, and navigation menus for guest/member/admin/role states.', 'nexdirectory'); ?></p>

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

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

                            <div class="nexdirectory-settings-grid" style="margin-top:10px;">
                                <div class="nexdirectory-settings-field">
                                    <label for="nexdirectory_frontend_sticky_nav_behavior"><?php esc_html_e('Navbar behavior', 'nexdirectory'); ?></label>
                                    <select id="nexdirectory_frontend_sticky_nav_behavior" name="nexdirectory_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="nexdirectory-settings-field">
                                    <label for="nexdirectory_nav_side_padding_desktop"><?php esc_html_e('Desktop Padding (L/R)', 'nexdirectory'); ?></label>
                                    <input type="text" id="nexdirectory_nav_side_padding_desktop" name="nexdirectory_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="nexdirectory-settings-grid" style="margin-top:10px;">
                                <div class="nexdirectory-settings-field">
                                    <input type="hidden" name="nexdirectory_frontend_sticky_nav_show_for_guests" value="0">
                                    <label><input type="checkbox" name="nexdirectory_frontend_sticky_nav_show_for_guests" value="1" <?php checked((string) get_option('nexdirectory_frontend_sticky_nav_show_for_guests', '1'), '1'); ?>> <?php esc_html_e('Show for logged-out users', 'nexdirectory'); ?></label>
                                </div>
                                <div class="nexdirectory-settings-field">
                                    <input type="hidden" name="nexdirectory_frontend_sticky_nav_show_for_members" value="0">
                                    <label><input type="checkbox" name="nexdirectory_frontend_sticky_nav_show_for_members" value="1" <?php checked((string) get_option('nexdirectory_frontend_sticky_nav_show_for_members', '1'), '1'); ?>> <?php esc_html_e('Show for logged-in users', 'nexdirectory'); ?></label>
                                </div>
                                <div class="nexdirectory-settings-field">
                                    <input type="hidden" name="nexdirectory_frontend_sticky_nav_include_auth_cta" value="0">
                                    <label><input type="checkbox" name="nexdirectory_frontend_sticky_nav_include_auth_cta" value="1" <?php checked((string) get_option('nexdirectory_frontend_sticky_nav_include_auth_cta', '1'), '1'); ?>> <?php esc_html_e('Show auth CTA buttons in navbar', 'nexdirectory'); ?></label>
                                </div>
                                <div class="nexdirectory-settings-field">
                                    <input type="hidden" name="nexdirectory_frontend_sticky_nav_show_logo" value="0">
                                    <label><input type="checkbox" name="nexdirectory_frontend_sticky_nav_show_logo" value="1" <?php checked((string) get_option('nexdirectory_frontend_sticky_nav_show_logo', '1'), '1'); ?>> <?php esc_html_e('Show logo in navbar', 'nexdirectory'); ?></label>
                                </div>
                                <div class="nexdirectory-settings-field nexdirectory-full">
                                    <input type="hidden" name="nexdirectory_show_frontend_auth_links" value="0">
                                    <label><input type="checkbox" name="nexdirectory_show_frontend_auth_links" value="1" <?php checked((string) get_option('nexdirectory_show_frontend_auth_links', '1'), '1'); ?>> <?php esc_html_e('Render frontend auth links block automatically', 'nexdirectory'); ?></label>
                                </div>
                            </div>
                        </div>

                        <div class="nexdirectory-settings-field nexdirectory-full">
                            <h3 class="nexdirectory-settings-core-title"><span class="dashicons dashicons-format-image" aria-hidden="true"></span><?php esc_html_e('Brand Logo', 'nexdirectory'); ?></h3>
                            <div class="nexdirectory-settings-grid">
                                <div class="nexdirectory-settings-field nexdirectory-full">
                                    <label for="nexdirectory_frontend_sticky_nav_logo_url"><?php esc_html_e('Logo image', 'nexdirectory'); ?></label>
                                    <input type="hidden" id="nexdirectory_frontend_sticky_nav_logo_url" name="nexdirectory_frontend_sticky_nav_logo_url" value="<?php echo esc_attr((string) $sticky_nav_logo_url); ?>">
                                    <div class="nexdirectory-media-picker" data-nexdirectory-media-picker data-nexdirectory-media-target="#nexdirectory_frontend_sticky_nav_logo_url" data-nexdirectory-media-multiple="0" data-nexdirectory-upload-target="cover">
                                        <button type="button" class="nexdirectory-media-dropzone" data-nexdirectory-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-nexdirectory-media-file-input>
                                        <div class="nexdirectory-fallback-preview-single nexdirectory-media-gallery" id="nexdirectory-sticky-nav-logo-preview">
                                            <?php if ($sticky_nav_logo_url !== '') : ?>
                                                <div class="nexdirectory-media-tile" data-nexdirectory-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="nexdirectory-media-remove" data-nexdirectory-media-remove aria-label="<?php esc_attr_e('Remove logo image', 'nexdirectory'); ?>">&times;</button>
                                                </div>
                                            <?php endif; ?>
                                        </div>
                                        <p class="description nexdirectory-media-feedback" data-nexdirectory-media-feedback></p>
                                    </div>
                                </div>
                                <div class="nexdirectory-settings-field">
                                    <label for="nexdirectory_frontend_sticky_nav_logo_link_url"><?php esc_html_e('Logo link URL', 'nexdirectory'); ?></label>
                                    <input type="url" id="nexdirectory_frontend_sticky_nav_logo_link_url" name="nexdirectory_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="nexdirectory-settings-field">
                                    <label for="nexdirectory_frontend_sticky_nav_logo_size"><?php esc_html_e('Logo size', 'nexdirectory'); ?></label>
                                    <input type="text" id="nexdirectory_frontend_sticky_nav_logo_size" name="nexdirectory_frontend_sticky_nav_logo_size" value="<?php echo esc_attr($this->sanitize_sticky_nav_logo_size_option((string) get_option('nexdirectory_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="nexdirectory-settings-field nexdirectory-full">
                            <h3 class="nexdirectory-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="nexdirectory_frontend_sticky_nav_use_wp_menus" value="0">
                            <label><input type="checkbox" name="nexdirectory_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(
                                                /* translators: %s: Placeholder value. */
                                                __('No WordPress menus found. <a href="%s">Open Appearance &gt; Menus</a> to create one.', 'nexdirectory'),
                                                esc_url(admin_url('themes.php?page=nexdirectory-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="nexdirectory-settings-grid" style="margin-top:10px;">
                                <div class="nexdirectory-settings-field">
                                    <label for="nexdirectory_frontend_sticky_nav_wp_menu_guest"><?php esc_html_e('Menu: Logged-out', 'nexdirectory'); ?></label>
                                    <select id="nexdirectory_frontend_sticky_nav_wp_menu_guest" name="nexdirectory_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="nexdirectory-settings-field">
                                    <label for="nexdirectory_frontend_sticky_nav_wp_menu_member"><?php esc_html_e('Menu: Members', 'nexdirectory'); ?></label>
                                    <select id="nexdirectory_frontend_sticky_nav_wp_menu_member" name="nexdirectory_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="nexdirectory-settings-field">
                                    <label for="nexdirectory_frontend_sticky_nav_wp_menu_admin"><?php esc_html_e('Menu: Admins', 'nexdirectory'); ?></label>
                                    <select id="nexdirectory_frontend_sticky_nav_wp_menu_admin" name="nexdirectory_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="nexdirectory-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="nexdirectory-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="nexdirectory-settings-field">
                                            <label for="nexdirectory_frontend_sticky_nav_wp_menu_role_<?php echo esc_attr($role_slug); ?>"><?php echo esc_html($role_label); ?></label>
                                            <select id="nexdirectory_frontend_sticky_nav_wp_menu_role_<?php echo esc_attr($role_slug); ?>" name="nexdirectory_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="nexdirectory_frontend_sticky_nav_custom_links"><?php esc_html_e('Custom Hardcoded Links (Optional)', 'nexdirectory'); ?></label>
                                <textarea id="nexdirectory_frontend_sticky_nav_custom_links" name="nexdirectory_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="nexdirectory-settings-panel" id="nexdirectory-tab-footer" data-tab="general" data-subtab="footer">
                    <h2><?php esc_html_e('Footer', 'nexdirectory'); ?></h2>
                    <p class="nexdirectory-settings-subheading"><?php esc_html_e('Configure the default platform footer with brand logo, responsive menu columns, and legal info.', 'nexdirectory'); ?></p>

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

                            <div class="nexdirectory-settings-grid">
                                <div class="nexdirectory-settings-field">
                                    <input type="hidden" name="nexdirectory_enable_frontend_footer" value="0">
                                    <label><input type="checkbox" name="nexdirectory_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="nexdirectory-settings-field">
                                    <input type="hidden" name="nexdirectory_frontend_footer_show_logo" value="0">
                                    <label><input type="checkbox" name="nexdirectory_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="nexdirectory-settings-field">
                                    <input type="hidden" name="nexdirectory_frontend_footer_show_privacy_link" value="0">
                                    <label><input type="checkbox" name="nexdirectory_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="nexdirectory-settings-field">
                                    <label for="nexdirectory_frontend_footer_menu_count"><?php esc_html_e('Footer Menu Columns (Desktop)', 'nexdirectory'); ?></label>
                                    <select id="nexdirectory_frontend_footer_menu_count" name="nexdirectory_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(
                                                        /* translators: 1: Placeholder value 1, 2: Placeholder value 2. */
                                                        _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="nexdirectory-settings-field nexdirectory-full">
                                    <label for="nexdirectory_frontend_footer_bottom_text"><?php esc_html_e('Footer Bottom Text (Optional)', 'nexdirectory'); ?></label>
                                    <input type="text" id="nexdirectory_frontend_footer_bottom_text" name="nexdirectory_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="nexdirectory-settings-field nexdirectory-full">
                            <h3 class="nexdirectory-settings-core-title"><span class="dashicons dashicons-format-image" aria-hidden="true"></span><?php esc_html_e('Footer Brand Logo', 'nexdirectory'); ?></h3>
                            <div class="nexdirectory-settings-grid">
                                <div class="nexdirectory-settings-field nexdirectory-full">
                                    <label for="nexdirectory_frontend_footer_logo_url"><?php esc_html_e('Footer logo image', 'nexdirectory'); ?></label>
                                    <input type="hidden" id="nexdirectory_frontend_footer_logo_url" name="nexdirectory_frontend_footer_logo_url" value="<?php echo esc_attr((string) $footer_logo_url); ?>">
                                    <div class="nexdirectory-media-picker" data-nexdirectory-media-picker data-nexdirectory-media-target="#nexdirectory_frontend_footer_logo_url" data-nexdirectory-media-multiple="0" data-nexdirectory-upload-target="cover">
                                        <button type="button" class="nexdirectory-media-dropzone" data-nexdirectory-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-nexdirectory-media-file-input>
                                        <div class="nexdirectory-fallback-preview-single nexdirectory-media-gallery" id="nexdirectory-footer-logo-preview">
                                            <?php if ($footer_logo_url !== '') : ?>
                                                <div class="nexdirectory-media-tile" data-nexdirectory-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="nexdirectory-media-remove" data-nexdirectory-media-remove aria-label="<?php esc_attr_e('Remove footer logo image', 'nexdirectory'); ?>">&times;</button>
                                                </div>
                                            <?php endif; ?>
                                        </div>
                                        <p class="description nexdirectory-media-feedback" data-nexdirectory-media-feedback></p>
                                    </div>
                                </div>
                                <div class="nexdirectory-settings-field">
                                    <label for="nexdirectory_frontend_footer_logo_link_url"><?php esc_html_e('Footer logo link URL', 'nexdirectory'); ?></label>
                                    <input type="url" id="nexdirectory_frontend_footer_logo_link_url" name="nexdirectory_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="nexdirectory-settings-field nexdirectory-full">
                            <h3 class="nexdirectory-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="nexdirectory_frontend_footer_use_wp_menus" value="0">
                            <label><input type="checkbox" name="nexdirectory_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(
                                                /* translators: %s: Placeholder value. */
                                                __('No WordPress menus found. <a href="%s">Open Appearance &gt; Menus</a> to create one.', 'nexdirectory'),
                                                esc_url(admin_url('themes.php?page=nexdirectory-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="nexdirectory-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="nexdirectory-settings-field">
                                        <label for="nexdirectory_frontend_footer_wp_menus_<?php echo esc_attr((string) ($i + 1)); ?>">
                                            <?php
                                            echo esc_html(
                                                sprintf(
                                                    /* translators: %d: Placeholder value. */
                                                    __('Footer Column %d Menu', 'nexdirectory'),
                                                    $i + 1
                                                )
                                            );
                                            ?>
                                        </label>
                                        <select id="nexdirectory_frontend_footer_wp_menus_<?php echo esc_attr((string) ($i + 1)); ?>" name="nexdirectory_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="nexdirectory-settings-panel" id="nexdirectory-tab-shortcodes" data-tab="general" data-subtab="shortcodes">
                    <h2><?php esc_html_e('Available Shortcodes', 'nexdirectory'); ?></h2>
                    <p class="nexdirectory-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 nexdirectory-shortcode-table">
                        <thead>
                            <tr>
                                <th><?php esc_html_e('Shortcode', 'nexdirectory'); ?></th>
                                <th><?php esc_html_e('Purpose', 'nexdirectory'); ?></th>
                                <th class="nexdirectory-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="nexdirectory-shortcode-copy-cell">
                                        <button type="button" class="button nexdirectory-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="nexdirectory-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 nexdirectory-shortcode-table">
                            <thead>
                                <tr>
                                    <th><?php esc_html_e('Shortcode', 'nexdirectory'); ?></th>
                                    <th><?php esc_html_e('Purpose', 'nexdirectory'); ?></th>
                                    <th class="nexdirectory-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="nexdirectory-shortcode-copy-cell">
                                            <button type="button" class="button nexdirectory-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>
