<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Templates use local variables supplied by the render context.
if (!defined('ABSPATH')) {
    exit;
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Account template reads query parameters only to choose the visible tab.

// Global Variables
$user = wp_get_current_user();
$home_url = esc_url(home_url('/'));
$logout_nav_url = esc_url(wp_logout_url($home_url));
$page_kicker = sanitize_text_field((string) $this->get_event_hero_kicker_text());

// Setup UI Labels
$ui_labels = isset($ui_labels) && is_array($ui_labels) ? $ui_labels : [];
$profile_key = sanitize_key((string) ($ui_labels['profile_key'] ?? ''));
$available_tabs = isset($available_tabs) && is_array($available_tabs) ? array_values(array_filter(array_map('sanitize_key', $available_tabs))) : ['account', 'analytics', 'listings', 'submit', 'inbox', 'saved'];
if (empty($available_tabs)) {
    $available_tabs = ['account', 'analytics', 'listings', 'submit', 'inbox', 'saved'];
}
$advanced_analytics_enabled = function_exists('nexdirectory_is_pro_feature_enabled')
    && nexdirectory_is_pro_feature_enabled('advanced_analytics');
$ticketing_pro_enabled = function_exists('nexdirectory_is_pro_feature_enabled')
    && nexdirectory_is_pro_feature_enabled('ticketing');
if (!$advanced_analytics_enabled) {
    $available_tabs = array_values(array_diff($available_tabs, ['analytics']));
}
$show_analytics_tab = in_array('analytics', $available_tabs, true);
$show_listings_tab = in_array('listings', $available_tabs, true);
$show_submit_tab = in_array('submit', $available_tabs, true);
$show_inbox_tab = in_array('inbox', $available_tabs, true);
$show_saved_tab = in_array('saved', $available_tabs, true);
$show_account_tab = in_array('account', $available_tabs, true);
$initial_tab = sanitize_key((string) ($initial_tab ?? 'account'));
if (!in_array($initial_tab, $available_tabs, true)) {
    $initial_tab = $show_account_tab ? 'account' : (string) ($available_tabs[0] ?? 'analytics');
}
$requested_tab = isset($_GET['nexdirectory_tab']) ? sanitize_key((string) wp_unslash($_GET['nexdirectory_tab'])) : '';
if ($requested_tab !== '' && in_array($requested_tab, $available_tabs, true)) {
    $initial_tab = $requested_tab;
}
$is_events_profile = (string) ($ui_labels['is_events_profile'] ?? '1') === '1';
$team_access_enabled = !empty($team_access_enabled)
    && has_action('nexdirectory_render_extension_account_team_access');

// Account Specific Variables
$account_description = isset($account_description) ? (string) $account_description : (string) ($ui_labels['account_description'] ?? __('Update your profile and manage your listing activity.', 'nexdirectory'));
$gdpr_marketing_opt_in = !empty($gdpr_marketing_opt_in);
$event_messages_enabled = !isset($event_messages_enabled) || !empty($event_messages_enabled);
$gdpr_terms_accepted_label = isset($gdpr_terms_accepted_label) ? sanitize_text_field((string) $gdpr_terms_accepted_label) : '';
$team_access_events = isset($team_access_events) && is_array($team_access_events) ? $team_access_events : [];
$selected_team_access_event_id = isset($selected_team_access_event_id) ? absint((int) $selected_team_access_event_id) : 0;
$team_access_members = isset($team_access_members) && is_array($team_access_members) ? $team_access_members : [];
$team_access_followers = isset($team_access_followers) && is_array($team_access_followers) ? $team_access_followers : [];
$team_access_can_manage_selected = !empty($team_access_can_manage_selected);
$team_access_manage_action = isset($team_access_manage_action) ? esc_url((string) $team_access_manage_action) : esc_url(admin_url('admin-post.php'));
$team_access_base_url = isset($team_access_base_url) ? esc_url((string) $team_access_base_url) : esc_url(nexdirectory_add_query_arg(['nexdirectory_tab' => 'account', 'account_subtab' => 'team-access'], $home_url) . '#account');
$team_access_selected_url = isset($team_access_selected_url) ? esc_url((string) $team_access_selected_url) : $team_access_base_url;
$initial_account_subtab = isset($_GET['account_subtab']) ? sanitize_key((string) wp_unslash($_GET['account_subtab'])) : 'profile';
$allowed_account_subtabs = ['profile'];
if ($team_access_enabled) {
    $allowed_account_subtabs[] = 'team-access';
}
if (!in_array($initial_account_subtab, $allowed_account_subtabs, true)) {
    $initial_account_subtab = 'profile';
}
$plan_notice_class = 'nexdirectory-account-plan-notice--pro';
$plan_notice_title = __('Nex Directory Free: Unlimited submissions', 'nexdirectory');
$plan_notice_text = __('The WordPress.org version is fully functional and does not limit listing creation.', 'nexdirectory');
$plan_notice_badge = __('Unlimited', 'nexdirectory');
$plan_notice_tooltip = __('Unlimited core publishing is included.', 'nexdirectory');
$plan_show_cta = false;

echo wp_kses_post($this->render_notice());
?>


<?php $this->enqueue_local_style_asset('templates-frontend-account-app-php-style-1', 'assets/generated/templates-frontend-account-app-php-style-1.css'); ?>

<?php ob_start(); ?>
    document.addEventListener('alpine:init', () => {
        const initialTab = <?php echo wp_json_encode($initial_tab); ?>;
        const allowedTabs = <?php echo wp_json_encode($available_tabs); ?>;
        const normalizeTab = (candidate) => {
            const tab = String(candidate || '').toLowerCase();
            return allowedTabs.includes(tab) ? tab : initialTab;
        };
        const getTabFromUrl = () => {
            const params = new URLSearchParams(window.location.search || '');
            const fromQuery = params.get('nexdirectory_tab');
            if (fromQuery && allowedTabs.includes(String(fromQuery).toLowerCase())) {
                return String(fromQuery).toLowerCase();
            }
            if (window.location.hash) {
                return normalizeTab(window.location.hash.substring(1));
            }
            return initialTab;
        };
        const setTabInUrl = (tab) => {
            const url = new URL(window.location.href);
            url.searchParams.set('nexdirectory_tab', tab);
            if (url.hash) {
                url.hash = '';
            }
            window.history.replaceState({}, '', url.toString());
        };

        Alpine.data('accountApp', () => ({
            activeTab: normalizeTab(getTabFromUrl()),
            coverImage: '',
            galleryImages: [],
            galleryTextarea: '',
            videoUrlsTextarea: '',
            videoEmbeds: [''],
            sessions: [],
            keySpeakers: [],
            startValue: '',
            startTimeValue: '',
            endValue: '',
            endTimeValue: '',
            cityValue: '',
            countryValue: '',
            latValue: '',
            lngValue: '',
            streamUrl: '',
            titleValue: '',
            excerptValue: '',
            metaTitleValue: '',
            metaDescriptionValue: '',
            serpUrl: '',
            dateError: '',
            dateWarning: '',
            timeWarning: '',
            excerptError: '',
            titleError: '',
            autosaveMessage: '',
            noop() {},
            validateDates() { return true; },
            hasBlockingErrors() { return false; },
            queueAutosave() {},
            syncGalleryTextarea() {
                this.galleryTextarea = Array.isArray(this.galleryImages) ? this.galleryImages.join('\n') : '';
            },
            addSession() {
                this.sessions = Array.isArray(this.sessions) ? this.sessions : [];
                this.sessions.push({ title: '', start: '', end: '', location: '', speaker: '', day: '', notes: '', attachments: '' });
            },
            removeSession(index) {
                if (Array.isArray(this.sessions)) {
                    this.sessions.splice(index, 1);
                }
            },
            addKeySpeaker() {
                this.keySpeakers = Array.isArray(this.keySpeakers) ? this.keySpeakers : [];
                this.keySpeakers.push({ name: '', profession: '', subject: '', image: '', details: '' });
            },
            removeKeySpeaker(index) {
                if (Array.isArray(this.keySpeakers)) {
                    this.keySpeakers.splice(index, 1);
                }
            },
            removeCover() { this.coverImage = ''; },
            removeGallery(index) {
                if (Array.isArray(this.galleryImages)) {
                    this.galleryImages.splice(index, 1);
                    this.syncGalleryTextarea();
                }
            },
            removeSpeakerImage(index) {
                if (Array.isArray(this.keySpeakers) && this.keySpeakers[index]) {
                    this.keySpeakers[index].image = '';
                }
            },
            handleDrop() {},
            handleFileSelect() {},
            openMedia() {},
            handleSessionAttachmentUpload() {},
            openSessionAttachmentMediaPicker() {},
            triggerSessionAttachmentInput() {},
            handleSpeakerImageUpload() {},
            openSpeakerImageMediaPicker() {},
            triggerSpeakerImageInput() {},
            titleCounterText() { return String(String(this.titleValue || '').trim().length) + ' chars'; },
            excerptCounterText() { return String(String(this.excerptValue || '').length) + ' chars'; },
            seoTitleCount() { return String(this.metaTitleValue || '').trim().length; },
            seoDescriptionCount() { return String(this.metaDescriptionValue || '').trim().length; },
            seoTitleStatusText() { return this.seoTitleCount() ? 'Optional' : 'Optional'; },
            seoDescriptionStatusText() { return this.seoDescriptionCount() ? 'Optional' : 'Optional'; },
            seoTitleStatusClass() { return 'text-gray-500'; },
            seoDescriptionStatusClass() { return 'text-gray-500'; },
            fillSeoFromContent() {},
            serpUrlPreview() { return String(this.serpUrl || ''); },
            serpTitlePreview() { return String(this.metaTitleValue || this.titleValue || 'Untitled Listing'); },
            serpDescriptionPreview() { return String(this.metaDescriptionValue || this.excerptValue || 'Add a concise summary to improve discovery.'); },
            init() {
                window.addEventListener('popstate', () => {
                    this.activeTab = normalizeTab(getTabFromUrl());
                });
                window.addEventListener('nexdirectory:account:set-tab', (event) => {
                    const requested = event && event.detail ? event.detail.tab : '';
                    this.setTab(requested);
                });
                this.$watch('activeTab', value => {
                    const normalized = normalizeTab(value);
                    setTabInUrl(normalized);
                });
            },
            setTab(tab) {
                const normalized = normalizeTab(tab);
                if (normalized !== this.activeTab) {
                    const submitUrl = new URL(window.location.href);
                    submitUrl.searchParams.set('nexdirectory_tab', normalized);
                    submitUrl.searchParams.delete('edit_event_id');
                    submitUrl.hash = normalized;
                    window.location.assign(submitUrl.toString());
                    return;
                }
                this.activeTab = normalized;
            }
        }))
    });
<?php $this->enqueue_inline_script_asset('nexdirectory-account-app', ob_get_clean()); ?>

<div class="nexdirectory-account-dashboard bg-gray-50 text-gray-800 font-sans antialiased selection:bg-brand-100 selection:text-brand-700 min-h-screen flex flex-col md:flex-row pb-24 md:pb-0" x-data="accountApp()">

    <aside class="hidden md:flex w-64 flex-col bg-white border-r border-gray-200 h-screen sticky top-0 shrink-0 z-40 shadow-sm">
        <div class="p-6 border-b border-gray-100">
            <p class="text-[10px] font-semibold text-brand-500 uppercase tracking-wider mb-0.5"><?php echo esc_html($page_kicker); ?></p>
            <a href="<?php echo esc_url($home_url); ?>" class="font-bold text-xl tracking-tighter text-gray-900 active:scale-95 transition-transform duration-200">
                Workspace
            </a>
            <p class="text-xs text-gray-500 mt-1 truncate">Welcome, <?php echo esc_html($user->display_name); ?></p>
        </div>
        <nav class="flex-1 p-4 space-y-1 overflow-y-auto">
            <?php if ($show_analytics_tab) : ?>
            <button type="button" @click="setTab('analytics')" :class="activeTab === 'analytics' ? 'bg-brand-50 text-brand-600 font-semibold' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'" class="w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-[13px] transition-all text-left">
                <svg class="w-5 h-5" :class="activeTab === 'analytics' ? 'text-brand-500' : 'text-gray-400'" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"></path></svg>
                <span>Dashboard</span>
            </button>
            <?php endif; ?>
            <?php if ($show_listings_tab) : ?>
            <button type="button" @click="setTab('listings')" :class="activeTab === 'listings' ? 'bg-brand-50 text-brand-600 font-semibold' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'" class="w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-[13px] transition-all text-left">
                <svg class="w-5 h-5" :class="activeTab === 'listings' ? 'text-brand-500' : 'text-gray-400'" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 10h16M4 14h16M4 18h16"></path></svg>
                <span>My Listings</span>
            </button>
            <?php endif; ?>
            <?php if ($show_submit_tab) : ?>
            <button type="button" @click="setTab('submit')" :class="activeTab === 'submit' ? 'bg-brand-50 text-brand-600 font-semibold' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'" class="w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-[13px] transition-all text-left">
                <svg class="w-5 h-5" :class="activeTab === 'submit' ? 'text-brand-500' : 'text-gray-400'" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path></svg>
                <span>Add New</span>
            </button>
            <?php endif; ?>
            <?php if ($show_inbox_tab) : ?>
            <button type="button" @click="setTab('inbox')" :class="activeTab === 'inbox' ? 'bg-brand-50 text-brand-600 font-semibold' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'" class="w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-[13px] transition-all text-left">
                <svg class="w-5 h-5" :class="activeTab === 'inbox' ? 'text-brand-500' : 'text-gray-400'" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path></svg>
                <span>Messages</span>
            </button>
            <?php endif; ?>
            <?php if ($show_saved_tab) : ?>
            <button type="button" @click="setTab('saved')" :class="activeTab === 'saved' ? 'bg-brand-50 text-brand-600 font-semibold' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'" class="w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-[13px] transition-all text-left">
                <svg class="w-5 h-5" :class="activeTab === 'saved' ? 'text-brand-500' : 'text-gray-400'" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z"></path></svg>
                <span>Saved & Attending</span>
            </button>
            <?php endif; ?>
            <?php if ($show_account_tab) : ?>
            <button type="button" @click="setTab('account')" :class="activeTab === 'account' ? 'bg-brand-50 text-brand-600 font-semibold' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'" class="w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-[13px] transition-all text-left">
                <svg class="w-5 h-5" :class="activeTab === 'account' ? 'text-brand-500' : 'text-gray-400'" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path></svg>
                <span>Account Settings</span>
            </button>
            <?php endif; ?>
        </nav>
        <div class="p-4 border-t border-gray-100">
            <a href="<?php echo esc_url($logout_nav_url); ?>" class="nexdirectory-force-accent-action w-full flex items-center justify-center gap-2 py-2.5 px-4 bg-gray-100 hover:bg-gray-200 text-gray-700 text-sm font-semibold rounded-xl transition-all shadow-sm">
                Logout
            </a>
        </div>
    </aside>

    <header class="md:hidden bg-white/90 backdrop-blur-md border-b border-gray-200 sticky top-0 z-40 px-4 py-3 flex items-center justify-between">
        <h1 class="font-bold text-lg text-gray-900 capitalize" x-text="activeTab.replace('-', ' ')">Workspace</h1>
        <div class="w-8 h-8 rounded-full bg-brand-100 text-brand-600 flex items-center justify-center font-bold text-xs uppercase shadow-sm border border-brand-200">
            <?php echo esc_html(substr($user->display_name, 0, 2)); ?>
        </div>
    </header>

    <main class="nexdirectory-workspace-main flex-1 min-w-0 w-full max-w-none p-4 sm:p-6 lg:p-8">

        <?php if ($show_account_tab) : ?>
        <section class="nexdirectory-account-view nexdirectory-account-view--account" x-show="activeTab === 'account'" x-transition.opacity.duration.300ms x-cloak x-data="{ accountSubTab: '<?php echo esc_attr($initial_account_subtab); ?>' }">
            
            <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-8'" class="transition-all duration-700 ease-out mb-6 sm:mb-8">
                <h2 class="text-2xl sm:text-3xl font-bold text-gray-900 tracking-tight mb-2"><?php esc_html_e('Account Management', 'nexdirectory'); ?></h2>
                <p class="text-sm sm:text-base text-gray-500 max-w-2xl"><?php echo esc_html($account_description); ?></p>
            </div>

            <div class="nexdirectory-account-subtabs flex items-center gap-2 mb-4 p-1 bg-gray-200/50 rounded-xl inline-flex w-full sm:w-auto overflow-x-auto scrollbar-hide">
                <button type="button" @click="accountSubTab = 'profile'" :class="accountSubTab === 'profile' ? 'bg-white text-gray-900 shadow-sm font-semibold' : 'text-gray-500 hover:text-gray-700 font-medium'" class="flex-1 sm:flex-none px-4 py-2 rounded-lg text-sm transition-all whitespace-nowrap">
                    <?php esc_html_e('Profile', 'nexdirectory'); ?>
                </button>
                <?php if ($team_access_enabled && has_action('nexdirectory_render_extension_account_team_access_tab')) : ?>
                    <?php do_action('nexdirectory_render_extension_account_team_access_tab'); ?>
                <?php endif; ?>
            </div>

            <div x-show="accountSubTab === 'profile'" x-transition.opacity.duration.300ms>
                <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-8'" class="transition-all duration-700 ease-out delay-100 bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden max-w-3xl">
                    <div class="border-b border-gray-100 px-5 sm:px-6 py-4 sm:py-5 bg-gray-50/50 flex items-center justify-between">
                        <h3 class="text-lg font-bold text-gray-900 flex items-center gap-2">
                            <svg class="w-5 h-5 text-brand-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path></svg>
                            <?php esc_html_e('Profile Details', 'nexdirectory'); ?>
                        </h3>
                    </div>

                    <div class="p-5 sm:p-6">
                        <form method="post" action="<?php echo esc_url(nexdirectory_add_query_arg('nexdirectory_tab', 'account', admin_url('admin-post.php'))); ?>#account" class="space-y-6">
                            <input type="hidden" name="action" value="nexdirectory_account_update">
                            <?php wp_nonce_field('nexdirectory_account_update_nonce', 'nexdirectory_account_nonce'); ?>

                            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4 sm:gap-6">
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-1.5"><?php esc_html_e('Username', 'nexdirectory'); ?></label>
                                    <input type="text" value="<?php echo esc_attr($user->user_login); ?>" disabled class="w-full px-4 py-3 rounded-xl border border-gray-200 bg-gray-50 text-gray-500 cursor-not-allowed outline-none text-sm shadow-sm">
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-1.5"><?php esc_html_e('Display Name', 'nexdirectory'); ?></label>
                                    <input type="text" name="display_name" value="<?php echo esc_attr($user->display_name); ?>" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none text-sm transition-all shadow-sm">
                                </div>
                            </div>

                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1.5"><?php esc_html_e('Email Address', 'nexdirectory'); ?></label>
                                <input type="email" name="user_email" value="<?php echo esc_attr($user->user_email); ?>" required class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none text-sm transition-all shadow-sm">
                            </div>

                            <div class="rounded-2xl border border-gray-200 overflow-hidden">
                                <div class="px-4 sm:px-5 py-4 bg-gray-50 border-b border-gray-100">
                                    <h4 class="font-bold text-gray-900"><?php esc_html_e('Public organizer profile', 'nexdirectory'); ?></h4>
                                    <p class="text-xs sm:text-sm text-gray-500 mt-1"><?php esc_html_e('Create a polished public profile while keeping contact details private unless you explicitly share them.', 'nexdirectory'); ?></p>
                                </div>
                                <div class="p-4 sm:p-5 space-y-4">
                                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                                        <div>
                                            <label class="block text-sm font-medium text-gray-700 mb-1.5" for="nexdirectory_profile_public_name"><?php esc_html_e('Public name', 'nexdirectory'); ?></label>
                                            <input id="nexdirectory_profile_public_name" type="text" name="nexdirectory_profile_public_name" value="<?php echo esc_attr((string) get_user_meta($user->ID, 'nexdirectory_profile_public_name', true)); ?>" placeholder="<?php esc_attr_e('Your name or organization', 'nexdirectory'); ?>" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none text-sm shadow-sm">
                                        </div>
                                        <div>
                                            <label class="block text-sm font-medium text-gray-700 mb-1.5" for="nexdirectory_profile_tagline"><?php esc_html_e('Tagline', 'nexdirectory'); ?></label>
                                            <input id="nexdirectory_profile_tagline" type="text" name="nexdirectory_profile_tagline" value="<?php echo esc_attr((string) get_user_meta($user->ID, 'nexdirectory_profile_tagline', true)); ?>" placeholder="<?php esc_attr_e('What you organize or offer', 'nexdirectory'); ?>" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none text-sm shadow-sm">
                                        </div>
                                    </div>
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 mb-1.5" for="nexdirectory_profile_bio"><?php esc_html_e('About you', 'nexdirectory'); ?></label>
                                        <textarea id="nexdirectory_profile_bio" name="nexdirectory_profile_bio" rows="4" maxlength="1200" placeholder="<?php esc_attr_e('Tell visitors what makes your work useful, trusted, or distinctive.', 'nexdirectory'); ?>" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none text-sm shadow-sm"><?php echo esc_textarea((string) get_user_meta($user->ID, 'nexdirectory_profile_bio', true)); ?></textarea>
                                    </div>
                                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                                        <div>
                                            <label class="block text-sm font-medium text-gray-700 mb-1.5" for="nexdirectory_profile_location"><?php esc_html_e('Public location', 'nexdirectory'); ?></label>
                                            <input id="nexdirectory_profile_location" type="text" name="nexdirectory_profile_location" value="<?php echo esc_attr((string) get_user_meta($user->ID, 'nexdirectory_profile_location', true)); ?>" placeholder="<?php esc_attr_e('e.g. Bristol, UK', 'nexdirectory'); ?>" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none text-sm shadow-sm">
                                        </div>
                                        <div>
                                            <label class="block text-sm font-medium text-gray-700 mb-1.5" for="nexdirectory_profile_avatar_url"><?php esc_html_e('Profile image URL', 'nexdirectory'); ?></label>
                                            <input id="nexdirectory_profile_avatar_url" type="url" name="nexdirectory_profile_avatar_url" value="<?php echo esc_attr((string) get_user_meta($user->ID, 'nexdirectory_profile_avatar_url', true)); ?>" placeholder="https://" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none text-sm shadow-sm">
                                        </div>
                                    </div>
                                    <div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
                                        <div>
                                            <label class="block text-sm font-medium text-gray-700 mb-1.5" for="nexdirectory_profile_website_url"><?php esc_html_e('Website', 'nexdirectory'); ?></label>
                                            <input id="nexdirectory_profile_website_url" type="url" name="nexdirectory_profile_website_url" value="<?php echo esc_attr((string) get_user_meta($user->ID, 'nexdirectory_profile_website_url', true)); ?>" placeholder="https://" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none text-sm shadow-sm">
                                        </div>
                                        <div>
                                            <label class="block text-sm font-medium text-gray-700 mb-1.5" for="nexdirectory_profile_linkedin_url"><?php esc_html_e('LinkedIn', 'nexdirectory'); ?></label>
                                            <input id="nexdirectory_profile_linkedin_url" type="url" name="nexdirectory_profile_linkedin_url" value="<?php echo esc_attr((string) get_user_meta($user->ID, 'nexdirectory_profile_linkedin_url', true)); ?>" placeholder="https://" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none text-sm shadow-sm">
                                        </div>
                                        <div>
                                            <label class="block text-sm font-medium text-gray-700 mb-1.5" for="nexdirectory_profile_instagram_url"><?php esc_html_e('Instagram', 'nexdirectory'); ?></label>
                                            <input id="nexdirectory_profile_instagram_url" type="url" name="nexdirectory_profile_instagram_url" value="<?php echo esc_attr((string) get_user_meta($user->ID, 'nexdirectory_profile_instagram_url', true)); ?>" placeholder="https://" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none text-sm shadow-sm">
                                        </div>
                                    </div>
                                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                                        <div>
                                            <label class="block text-sm font-medium text-gray-700 mb-1.5" for="nexdirectory_profile_public_email"><?php esc_html_e('Public contact email', 'nexdirectory'); ?></label>
                                            <input id="nexdirectory_profile_public_email" type="email" name="nexdirectory_profile_public_email" value="<?php echo esc_attr((string) get_user_meta($user->ID, 'nexdirectory_profile_public_email', true)); ?>" placeholder="<?php esc_attr_e('Optional', 'nexdirectory'); ?>" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none text-sm shadow-sm">
                                        </div>
                                        <div>
                                            <label class="block text-sm font-medium text-gray-700 mb-1.5" for="nexdirectory_profile_public_phone"><?php esc_html_e('Public phone', 'nexdirectory'); ?></label>
                                            <input id="nexdirectory_profile_public_phone" type="tel" name="nexdirectory_profile_public_phone" value="<?php echo esc_attr((string) get_user_meta($user->ID, 'nexdirectory_profile_public_phone', true)); ?>" placeholder="<?php esc_attr_e('Optional', 'nexdirectory'); ?>" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none text-sm shadow-sm">
                                        </div>
                                    </div>
                                    <div class="rounded-xl bg-amber-50 border border-amber-100 p-4 space-y-3">
                                        <p class="text-xs font-bold uppercase tracking-wider text-amber-800"><?php esc_html_e('Explicit sharing controls', 'nexdirectory'); ?></p>
                                        <input type="hidden" name="nexdirectory_profile_show_email" value="0">
                                        <label class="flex items-start gap-3 cursor-pointer">
                                            <input type="checkbox" name="nexdirectory_profile_show_email" value="1" <?php checked((string) get_user_meta($user->ID, 'nexdirectory_profile_show_email', true), '1'); ?> class="mt-0.5 w-4 h-4 text-brand-600 border-gray-300 rounded focus:ring-brand-500">
                                            <span class="text-sm text-gray-700"><?php esc_html_e('Publish my contact email on my organizer profile.', 'nexdirectory'); ?></span>
                                        </label>
                                        <input type="hidden" name="nexdirectory_profile_show_phone" value="0">
                                        <label class="flex items-start gap-3 cursor-pointer">
                                            <input type="checkbox" name="nexdirectory_profile_show_phone" value="1" <?php checked((string) get_user_meta($user->ID, 'nexdirectory_profile_show_phone', true), '1'); ?> class="mt-0.5 w-4 h-4 text-brand-600 border-gray-300 rounded focus:ring-brand-500">
                                            <span class="text-sm text-gray-700"><?php esc_html_e('Publish my phone number on my organizer profile.', 'nexdirectory'); ?></span>
                                        </label>
                                        <input type="hidden" name="nexdirectory_profile_show_member_since" value="0">
                                        <label class="flex items-start gap-3 cursor-pointer">
                                            <input type="checkbox" name="nexdirectory_profile_show_member_since" value="1" <?php checked((string) get_user_meta($user->ID, 'nexdirectory_profile_show_member_since', true), '1'); ?> class="mt-0.5 w-4 h-4 text-brand-600 border-gray-300 rounded focus:ring-brand-500">
                                            <span class="text-sm text-gray-700"><?php esc_html_e('Show when I joined this site.', 'nexdirectory'); ?></span>
                                        </label>
                                    </div>
                                    <div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
                                        <div>
                                            <label class="block text-sm font-medium text-gray-700 mb-1.5" for="nexdirectory_profile_visibility"><?php esc_html_e('Profile visibility', 'nexdirectory'); ?></label>
                                            <?php $profile_visibility = sanitize_key((string) get_user_meta($user->ID, 'nexdirectory_profile_visibility', true)) ?: 'unlisted'; ?>
                                            <select id="nexdirectory_profile_visibility" name="nexdirectory_profile_visibility" class="w-full px-4 py-3 rounded-xl border border-gray-200 bg-white focus:ring-2 focus:ring-brand-500 text-sm shadow-sm">
                                                <option value="public" <?php selected($profile_visibility, 'public'); ?>><?php esc_html_e('Public directory', 'nexdirectory'); ?></option>
                                                <option value="unlisted" <?php selected($profile_visibility, 'unlisted'); ?>><?php esc_html_e('Direct link only', 'nexdirectory'); ?></option>
                                                <option value="private" <?php selected($profile_visibility, 'private'); ?>><?php esc_html_e('Private', 'nexdirectory'); ?></option>
                                            </select>
                                        </div>
                                        <div>
                                            <label class="block text-sm font-medium text-gray-700 mb-1.5" for="nexdirectory_calendar_visibility"><?php esc_html_e('Organizer calendar', 'nexdirectory'); ?></label>
                                            <?php $calendar_visibility = sanitize_key((string) get_user_meta($user->ID, 'nexdirectory_calendar_visibility', true)) ?: 'private'; ?>
                                            <select id="nexdirectory_calendar_visibility" name="nexdirectory_calendar_visibility" class="w-full px-4 py-3 rounded-xl border border-gray-200 bg-white focus:ring-2 focus:ring-brand-500 text-sm shadow-sm">
                                                <option value="public" <?php selected($calendar_visibility, 'public'); ?>><?php esc_html_e('Public subscription', 'nexdirectory'); ?></option>
                                                <option value="private" <?php selected($calendar_visibility, 'private'); ?>><?php esc_html_e('Hidden', 'nexdirectory'); ?></option>
                                            </select>
                                        </div>
                                        <div>
                                            <label class="block text-sm font-medium text-gray-700 mb-1.5" for="nexdirectory_attendee_visibility"><?php esc_html_e('My RSVP name', 'nexdirectory'); ?></label>
                                            <?php $attendee_visibility = sanitize_key((string) get_user_meta($user->ID, 'nexdirectory_attendee_visibility', true)) ?: 'members'; ?>
                                            <select id="nexdirectory_attendee_visibility" name="nexdirectory_attendee_visibility" class="w-full px-4 py-3 rounded-xl border border-gray-200 bg-white focus:ring-2 focus:ring-brand-500 text-sm shadow-sm">
                                                <option value="public" <?php selected($attendee_visibility, 'public'); ?>><?php esc_html_e('Visible publicly', 'nexdirectory'); ?></option>
                                                <option value="members" <?php selected($attendee_visibility, 'members'); ?>><?php esc_html_e('Signed-in members', 'nexdirectory'); ?></option>
                                                <option value="private" <?php selected($attendee_visibility, 'private'); ?>><?php esc_html_e('Only me & organizer', 'nexdirectory'); ?></option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="bg-gray-50 rounded-xl p-4 sm:p-5 border border-gray-100">
                                <h4 class="font-semibold text-gray-900 mb-2"><?php esc_html_e('Communication & GDPR', 'nexdirectory'); ?></h4>
                                <p class="text-xs sm:text-sm text-gray-500 mb-4"><?php esc_html_e('Essential event-account emails (verification, moderation, RSVP/system updates) remain enabled for platform operation.', 'nexdirectory'); ?></p>
                                
                                <label class="flex items-start gap-3 cursor-pointer group mb-3">
                                    <div class="mt-0.5">
                                        <input type="checkbox" name="nexdirectory_gdpr_marketing_opt_in" value="1" <?php checked($gdpr_marketing_opt_in, true); ?> class="w-4 h-4 text-brand-600 border-gray-300 rounded focus:ring-brand-500">
                                    </div>
                                    <span class="text-sm text-gray-700 group-hover:text-gray-900 transition-colors"><?php esc_html_e('Allow organizer announcements and platform news emails (non-essential).', 'nexdirectory'); ?></span>
                                </label>

                                <?php if ($is_events_profile) : ?>
                                    <input type="hidden" name="nexdirectory_event_messages_enabled" value="0">
                                    <label class="flex items-start gap-3 cursor-pointer group">
                                        <div class="mt-0.5">
                                            <input type="checkbox" name="nexdirectory_event_messages_enabled" value="1" <?php checked($event_messages_enabled, true); ?> class="w-4 h-4 text-brand-600 border-gray-300 rounded focus:ring-brand-500">
                                        </div>
                                        <span class="text-sm text-gray-700 group-hover:text-gray-900 transition-colors"><?php esc_html_e('Show the Message button on my event pages.', 'nexdirectory'); ?></span>
                                    </label>
                                    <p class="text-xs text-gray-500 mt-2"><?php esc_html_e('If disabled, visitors will no longer see Message and the Visit Event Site button will expand to full width.', 'nexdirectory'); ?></p>
                                <?php endif; ?>

                                <?php if ($gdpr_terms_accepted_label !== '') : ?>
                                    <p class="text-xs text-brand-600 font-medium bg-brand-50 inline-block px-2.5 py-1 rounded-md border border-brand-100">
                                        <?php /* translators: %s: Placeholder value. */ ?>
                                        <?php echo esc_html(sprintf(__('GDPR acceptance recorded: %s', 'nexdirectory'), $gdpr_terms_accepted_label)); ?>
                                    </p>
                                <?php endif; ?>
                            </div>

                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1.5"><?php esc_html_e('New Password (optional)', 'nexdirectory'); ?></label>
                                <input type="password" name="new_pass" autocomplete="new-password" placeholder="••••••••" class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none text-sm transition-all shadow-sm">
                            </div>

                            <div class="pt-4 border-t border-gray-100 flex items-center justify-end">
                                <button type="submit" class="nexdirectory-force-accent-action w-full sm:w-auto bg-gray-900 hover:bg-black active:scale-95 text-white px-8 py-3 rounded-xl text-sm font-semibold transition-all shadow-sm">
                                    <?php esc_html_e('Save Account Settings', 'nexdirectory'); ?>
                                </button>
                            </div>
                        </form>

                        <?php
                        $personal_calendar_pro_enabled = function_exists('nexdirectory_is_pro_feature_enabled')
                            && nexdirectory_is_pro_feature_enabled('subscribable_calendars');
                        ?>
                        <?php if ($personal_calendar_pro_enabled) : ?>
                        <section class="mt-8 pt-7 border-t border-gray-100" aria-labelledby="nexdirectory-personal-calendar-title">
                            <div class="mb-4">
                                <h4 id="nexdirectory-personal-calendar-title" class="font-bold text-gray-900"><?php esc_html_e('My attending calendar', 'nexdirectory'); ?></h4>
                                <p class="text-sm text-gray-500 mt-1 max-w-xl"><?php esc_html_e('Keep confirmed events in sync with a private live calendar subscription.', 'nexdirectory'); ?></p>
                            </div>
                            <?php if (has_action('nexdirectory_render_extension_private_calendar_controls')) : ?>
                                <?php do_action('nexdirectory_render_extension_private_calendar_controls', $this, (int) $user->ID); ?>
                            <?php else : ?>
                                <div class="rounded-xl border border-gray-200 bg-gray-50 px-4 py-3 text-sm text-gray-600">
                                    <?php esc_html_e('The private calendar module is temporarily unavailable. No calendar data was changed.', 'nexdirectory'); ?>
                                </div>
                            <?php endif; ?>
                        </section>
                        <?php endif; ?>
                    </div>
                </div>
            </div>

            <?php if ($team_access_enabled && has_action('nexdirectory_render_extension_account_team_access')) : ?>
                <?php do_action('nexdirectory_render_extension_account_team_access', $this, [
                    'team_access_events' => $team_access_events,
                    'selected_team_access_event_id' => $selected_team_access_event_id,
                    'team_access_members' => $team_access_members,
                    'team_access_followers' => $team_access_followers,
                    'team_access_can_manage_selected' => $team_access_can_manage_selected,
                    'team_access_manage_action' => $team_access_manage_action,
                    'team_access_base_url' => $team_access_base_url,
                    'team_access_selected_url' => $team_access_selected_url,
                    'my_events_url' => isset($my_events_url) ? (string) $my_events_url : home_url('/'),
                ]); ?>
            <?php endif; ?>
        </section>
        <?php endif; ?>

<?php
        $analytics_title = isset($analytics_title) ? (string) $analytics_title : sanitize_text_field((string) ($ui_labels['owner_analytics_title'] ?? __('Analytics', 'nexdirectory')));
        $analytics_description = isset($analytics_description) ? (string) $analytics_description : sanitize_text_field((string) ($ui_labels['owner_analytics_description'] ?? __('Review listing views, clicks, enquiries, and discovery performance.', 'nexdirectory')));
        $days = isset($days) ? absint((int) $days) : 30;
        $events_url = isset($events_url) ? (string) $events_url : $this->get_profile_route_default_url('events', $profile_key);
        ?>
        <?php if ($show_analytics_tab) : ?>
        <section class="nexdirectory-account-view nexdirectory-account-view--analytics" x-show="activeTab === 'analytics'" x-transition.opacity.duration.300ms x-cloak>
            <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-8'" class="transition-all duration-700 ease-out mb-6 sm:mb-8">
                <h2 class="text-2xl sm:text-3xl font-bold text-gray-900 tracking-tight mb-2"><?php echo esc_html($analytics_title); ?></h2>
                <p class="text-sm sm:text-base text-gray-500 max-w-2xl"><?php echo esc_html($analytics_description); ?></p>
            </div>

            <?php if ($advanced_analytics_enabled) : ?>
                <?php if (has_action('nexdirectory_render_extension_owner_analytics')) : ?>
                    <?php
                    do_action('nexdirectory_render_extension_owner_analytics', $this, [
                        'user_id' => (int) $user->ID,
                        'days' => $days,
                        'events_url' => $events_url,
                        'ui_labels' => $ui_labels,
                    ]);
                    ?>
                <?php else : ?>
                    <div class="rounded-2xl border border-gray-200 bg-white p-6 text-sm text-gray-600 shadow-sm">
                        <?php esc_html_e('Advanced analytics is licensed. Activate the Nex Directory Pro analytics module to display reporting here.', 'nexdirectory'); ?>
                    </div>
                <?php endif; ?>
            <?php endif; ?>
        </section>
        <?php endif; ?>
<?php
        // My Listings Variables
        $my_items_title = sanitize_text_field((string) ($ui_labels['my_items_title'] ?? __('My Listings', 'nexdirectory')));
        $my_items_description = sanitize_text_field((string) ($ui_labels['my_items_description'] ?? __('Manage submissions, update details, and monitor moderation status.', 'nexdirectory')));
        $plural_label = sanitize_text_field((string) ($ui_labels['plural'] ?? __('Listings', 'nexdirectory')));
        $singular_label = sanitize_text_field((string) ($ui_labels['singular'] ?? __('Listing', 'nexdirectory')));
        /* translators: %s: Placeholder value. */
        $delete_prompt = $is_events_profile ? __('Delete this event?', 'nexdirectory') : sprintf(__('Delete this %s?', 'nexdirectory'), strtolower((string) $singular_label));
        $attendees_heading = $is_events_profile ? __('Attendees', 'nexdirectory') : __('Followers', 'nexdirectory');
        $edit_action_label = sanitize_text_field((string) ($ui_labels['single_edit_cta'] ?? __('Edit', 'nexdirectory')));
        
        $boosts_enabled = function_exists('nexdirectory_is_pro_feature_enabled')
            && (
                nexdirectory_is_pro_feature_enabled('boost_packages')
                || nexdirectory_is_pro_feature_enabled('monetization')
            );
        $webapp_enabled = !empty($event_webapp_studio_enabled)
            && has_action('nexdirectory_render_extension_account_event_webapp');
        
        $my_events_url = isset($my_events_url) ? (string) $my_events_url : $this->get_platform_page_url('nexdirectory_page_my_events_url', $this->get_profile_route_slugs('my_items'), $this->get_profile_route_default_url('my_items'));
        $attendees_panel = isset($attendees_panel) && is_array($attendees_panel) ? $attendees_panel : null;
        $initial_listings_subtab = sanitize_key((string) ($initial_listings_subtab ?? 'manage'));
        $allowed_listings_subtabs = ['manage'];
        if ($boosts_enabled) {
            $allowed_listings_subtabs[] = 'boosts';
        }
        if ($is_events_profile && $webapp_enabled) {
            $allowed_listings_subtabs[] = 'webapp';
        }
        if (!in_array($initial_listings_subtab, $allowed_listings_subtabs, true)) {
            $initial_listings_subtab = 'manage';
        }
        $webapp_event_options = isset($webapp_event_options) && is_array($webapp_event_options) ? $webapp_event_options : [];
        $selected_webapp_event_id = isset($selected_webapp_event_id) ? absint((int) $selected_webapp_event_id) : 0;
        $webapp_settings = isset($webapp_settings) && is_array($webapp_settings) ? $webapp_settings : [];
        $webapp_manage_page_url = isset($webapp_manage_page_url) ? (string) $webapp_manage_page_url : nexdirectory_add_query_arg([
            'nexdirectory_tab' => 'listings',
            'listings_subtab' => 'webapp',
        ], $my_events_url) . '#listings';
        $webapp_selected_manage_url = isset($webapp_selected_manage_url) ? (string) $webapp_selected_manage_url : $webapp_manage_page_url;
        $selected_event_webapp_url = isset($selected_event_webapp_url) ? esc_url_raw((string) $selected_event_webapp_url) : '';
        $selected_event_manifest_url = isset($selected_event_manifest_url) ? esc_url_raw((string) $selected_event_manifest_url) : '';
        $selected_event_service_worker_url = isset($selected_event_service_worker_url) ? esc_url_raw((string) $selected_event_service_worker_url) : '';
        $selected_event_service_worker_scope = isset($selected_event_service_worker_scope) ? sanitize_text_field((string) $selected_event_service_worker_scope) : '';
        ?>

        <?php if ($show_listings_tab) : ?>
        <section class="nexdirectory-account-view nexdirectory-account-view--listings" x-show="activeTab === 'listings'" x-transition.opacity.duration.300ms x-cloak x-data="{
            subTab: '<?php echo esc_attr($initial_listings_subtab); ?>',
            attendeesOpen: <?php echo !empty($attendees_panel) ? 'true' : 'false'; ?>,
            closeAttendees() {
                this.attendeesOpen = false;
                document.body.classList.remove('nexdirectory-lightbox-open');
                try {
                    const url = new URL(window.location.href);
                    url.searchParams.delete('attendees_event');
                    window.history.replaceState({}, document.title, url.toString());
                } catch (_error) {}
            }
        }">
            
            <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-8'" class="transition-all duration-700 ease-out mb-6">
                <div class="flex flex-col sm:flex-row sm:items-end justify-between gap-4">
                    <div>
                        <h2 class="text-2xl sm:text-3xl font-bold text-gray-900 tracking-tight mb-2"><?php echo esc_html($my_items_title); ?></h2>
                        <p class="text-sm sm:text-base text-gray-500 max-w-2xl"><?php echo esc_html($my_items_description); ?></p>
                    </div>
                    <?php if ($show_submit_tab) : ?>
                    <button type="button" @click="setTab('submit')" class="nexdirectory-force-accent-action w-full sm:w-auto bg-brand-600 hover:bg-brand-700 text-white px-5 py-2.5 rounded-xl text-sm font-semibold active:scale-95 transition-all shadow-sm flex items-center justify-center gap-2">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path></svg>
                        <?php esc_html_e('Add New', 'nexdirectory'); ?>
                    </button>
                    <?php endif; ?>
                </div>
                <div class="nexdirectory-account-plan-notice <?php echo esc_attr($plan_notice_class); ?> mt-5" title="<?php echo esc_attr($plan_notice_tooltip); ?>">
                    <div>
                        <strong><?php echo esc_html($plan_notice_title); ?></strong>
                        <p><?php echo esc_html($plan_notice_text); ?></p>
                    </div>
                    <div class="nexdirectory-account-plan-actions">
                        <span class="nexdirectory-account-plan-badge"><?php echo esc_html($plan_notice_badge); ?> <span aria-label="<?php echo esc_attr($plan_notice_tooltip); ?>">?</span></span>
                        <?php if ($plan_show_cta) : ?>
                            <a class="nexdirectory-account-action-btn" href="<?php echo esc_url($plan_cta_url); ?>" <?php echo $plan_cta_external ? 'target="_blank" rel="noopener noreferrer"' : ''; ?>><?php echo esc_html($plan_cta_label); ?></a>
                        <?php endif; ?>
                    </div>
                </div>

                <?php $listings_subtab_count = 1 + (($is_events_profile && $webapp_enabled) ? 1 : 0) + ($boosts_enabled ? 1 : 0); ?>
                <div class="nexdirectory-listings-subtabs mt-6 p-2 bg-gray-200/50 rounded-2xl grid gap-2 w-full scrollbar-hide" style="grid-template-columns: repeat(<?php echo esc_attr((string) max(1, (int) $listings_subtab_count)); ?>, minmax(0, 1fr));">
                    <button @click="subTab = 'manage'" :class="subTab === 'manage' ? 'bg-white text-gray-900 shadow-sm font-semibold' : 'text-gray-500 hover:text-gray-700 font-medium'" class="w-full min-h-[52px] px-5 py-3 rounded-xl text-sm sm:text-base transition-all whitespace-nowrap text-center">
                        <?php esc_html_e('Active Listings', 'nexdirectory'); ?>
                    </button>
                    <?php if ($is_events_profile && $webapp_enabled && has_action('nexdirectory_render_extension_account_event_webapp_tab')) : ?>
                        <?php do_action('nexdirectory_render_extension_account_event_webapp_tab'); ?>
                    <?php endif; ?>
                    <?php if ($boosts_enabled) : ?>
                    <button @click="subTab = 'boosts'" :class="subTab === 'boosts' ? 'bg-white text-brand-600 shadow-sm font-semibold' : 'text-gray-500 hover:text-gray-700 font-medium'" class="w-full min-h-[52px] px-5 py-3 rounded-xl text-sm sm:text-base transition-all whitespace-nowrap flex items-center justify-center gap-1.5">
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path></svg>
                        <?php esc_html_e('Boost Hub', 'nexdirectory'); ?>
                    </button>
                    <?php endif; ?>
                </div>
            </div>

            <div x-show="subTab === 'manage'" x-transition.opacity.duration.300ms>
                <?php if (isset($query) && $query instanceof WP_Query && $query->have_posts()) : ?>
                    <div class="space-y-4">
                        <?php while ($query->have_posts()) : $query->the_post(); ?>
                            <?php 
                            $event_status = (string) get_post_status(get_the_ID()); 
                            $edit_target_id = (int) get_the_ID();
                            $edit_base_url = (string) ($submit_event_url ?? '');
                            if ($edit_base_url === '') {
                                $edit_base_url = (string) ($my_events_url ?? home_url('/'));
                            }
                            $edit_event_url = nexdirectory_add_query_arg([
                                'nexdirectory_tab' => 'submit',
                                'edit_event_id' => $edit_target_id,
                            ], $edit_base_url) . '#submit';
                            $can_edit_target = is_callable([$this, 'user_can_edit_event']) ? (bool) $this->user_can_edit_event($edit_target_id) : true;
                            $is_demo_locked_target = is_callable([$this, 'is_demo_event_edit_locked']) ? (bool) $this->is_demo_event_edit_locked($edit_target_id, (int) get_current_user_id()) : false;
                            $duplicate_event_url = wp_nonce_url(
                                nexdirectory_add_query_arg([
                                    'action' => 'nexdirectory_duplicate_event',
                                    'post' => (int) $edit_target_id,
                                ], admin_url('admin.php')),
                                'nexdirectory_duplicate_event_' . (int) $edit_target_id
                            );
                            $view_event_url = (string) get_permalink(get_the_ID());
                            $view_event_label = __('View', 'nexdirectory');

                            if ($event_status !== 'publish' && $can_edit_target) {
                                $preview_url = get_preview_post_link($edit_target_id);
                                if ((!is_string($preview_url) || $preview_url === '') && $edit_target_id > 0) {
                                    $preview_url = nexdirectory_add_query_arg(['p' => $edit_target_id, 'post_type' => $this::POST_TYPE, 'preview' => 'true'], home_url('/'));
                                }
                                if (is_string($preview_url) && $preview_url !== '') {
                                    $view_event_url = $preview_url;
                                } elseif (is_string($edit_event_url) && $edit_event_url !== '') {
                                    $view_event_url = $edit_event_url;
                                }
                                $view_event_label = __('Preview', 'nexdirectory');
                            }

                            $can_toggle_live_draft = $this->can_manage_event_team($edit_target_id, get_current_user_id()) || $this->user_can_moderate_events(get_current_user_id());
                            $toggle_redirect_url = (string) ($my_events_url ?? home_url('/'));
                            if ($toggle_redirect_url === '') {
                                $toggle_redirect_url = home_url('/');
                            }
                            $toggle_redirect_url = nexdirectory_add_query_arg('nexdirectory_tab', 'listings', $toggle_redirect_url) . '#listings';
                            ?>
                            <div class="nexdirectory-dashboard-listing-card bg-white rounded-2xl border border-gray-100 p-5 shadow-sm hover:border-brand-200 transition-colors flex flex-col lg:flex-row gap-5 lg:items-center justify-between">
                                <div class="flex-1 min-w-0">
                                    <div class="flex items-center gap-2 mb-1.5 flex-wrap">
                                        <h3 class="font-bold text-gray-900 text-lg truncate"><a href="<?php echo esc_url($view_event_url); ?>" class="hover:text-brand-600 transition-colors"><?php the_title(); ?></a></h3>
                                        <span class="px-2.5 py-0.5 rounded-full text-[10px] font-bold uppercase tracking-wider border <?php echo $event_status === 'publish' ? 'bg-green-50 text-green-700 border-green-200' : 'bg-amber-50 text-amber-700 border-amber-200'; ?>">
                                            <?php echo esc_html(method_exists($this, 'event_status_badge') ? nexdirectory_strip_all_tags($this->event_status_badge($event_status)) : ucfirst($event_status)); ?>
                                        </span>
                                    </div>
                                    <p class="text-sm text-gray-500 flex items-center gap-2">
                                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"></path></svg>
                                        <?php echo esc_html(method_exists($this, 'format_event_date') ? $this->format_event_date(get_the_ID()) : get_the_date()); ?>
                                    </p>
                                    <?php $moderation_note = get_post_meta(get_the_ID(), 'nexdirectory_moderation_note', true); ?>
                                    <?php if ($moderation_note) : ?>
                                        <p class="text-xs text-red-500 mt-3 bg-red-50 px-3 py-2 rounded-lg border border-red-100"><?php echo esc_html($moderation_note); ?></p>
                                    <?php endif; ?>
                                </div>

                                <div class="nexdirectory-dashboard-listing-actions flex flex-col sm:flex-row items-stretch sm:items-center gap-2 sm:gap-3 shrink-0">
                                    <?php if ($can_toggle_live_draft) : ?>
                                        <form method="post" action="<?php echo esc_url(nexdirectory_add_query_arg('nexdirectory_tab', 'listings', admin_url('admin-post.php'))); ?>#listings" class="nexdirectory-inline-form nexdirectory-live-toggle-form w-full sm:w-auto">
                                            <input type="hidden" name="action" value="nexdirectory_toggle_event_live_draft">
                                            <input type="hidden" name="post_id" value="<?php echo esc_attr(get_the_ID()); ?>">
                                            <input type="hidden" name="redirect_to" value="<?php echo esc_attr($toggle_redirect_url); ?>">
                                            <input type="hidden" name="desired_state" value="draft">
                                            <input type="hidden" name="nexdirectory_toggle_event_live_draft_nonce" value="<?php echo esc_attr(wp_create_nonce('nexdirectory_toggle_event_live_draft')); ?>">
                                            <label class="nexdirectory-live-toggle" title="<?php esc_attr_e('Toggle between Live and Draft status', 'nexdirectory'); ?>">
                                                <input type="checkbox" name="desired_state" value="live" <?php checked($event_status, 'publish'); ?> data-nexdirectory-live-toggle-input="1" onchange="if(this.form){if(this.form.requestSubmit){this.form.requestSubmit();}else{this.form.submit();}}">
                                                <span class="nexdirectory-live-toggle-track" aria-hidden="true"></span>
                                                <span class="nexdirectory-live-toggle-label nexdirectory-live-toggle-label-live"><?php esc_html_e('Live', 'nexdirectory'); ?></span>
                                                <span class="nexdirectory-live-toggle-label nexdirectory-live-toggle-label-draft"><?php esc_html_e('Draft', 'nexdirectory'); ?></span>
                                            </label>
                                            <?php if ($event_status === 'pending') : ?>
                                                <small class="nexdirectory-live-toggle-meta"><?php esc_html_e('Pending moderation', 'nexdirectory'); ?></small>
                                            <?php endif; ?>
                                        </form>
                                    <?php endif; ?>
                                    <div class="nexdirectory-dashboard-action-group">
                                        <a href="<?php echo esc_url($view_event_url); ?>" class="nexdirectory-account-action-btn w-full sm:w-36 active:scale-95"><?php echo esc_html($view_event_label); ?></a>
                                        <?php if ($can_edit_target) : ?>
                                            <a href="<?php echo esc_url($edit_event_url); ?>" class="nexdirectory-account-action-btn w-full sm:w-36 active:scale-95"><?php echo esc_html($edit_action_label); ?></a>
                                        <?php elseif ($is_demo_locked_target) : ?>
                                            <?php $demo_locked_edit_tip = __('Demo listing. Duplicate it to create a separate editable copy.', 'nexdirectory'); ?>
                                            <span role="button" aria-disabled="true" title="<?php echo esc_attr($demo_locked_edit_tip); ?>" class="nexdirectory-account-action-btn w-full sm:w-36 opacity-60 cursor-not-allowed select-none"><?php echo esc_html($edit_action_label); ?></span>
                                            <a href="<?php echo esc_url($duplicate_event_url); ?>" title="<?php echo esc_attr($demo_locked_edit_tip); ?>" class="nexdirectory-account-action-btn w-full sm:w-36 active:scale-95"><?php esc_html_e('Duplicate', 'nexdirectory'); ?></a>
                                        <?php endif; ?>
                                    </div>
                                    <div class="nexdirectory-dashboard-action-group">
                                        <a href="<?php echo esc_url(nexdirectory_add_query_arg('attendees_event', (string) get_the_ID(), $my_events_url)); ?>#listings" class="nexdirectory-account-action-btn w-full sm:w-36 active:scale-95">
                                            <?php echo esc_html($attendees_heading); ?>
                                        </a>
                                        <?php $can_delete_event = (int) get_post_field('post_author', get_the_ID()) === (int) get_current_user_id() || $this->user_can_moderate_events(); ?>
                                        <?php if ($can_delete_event) : ?>
                                            <form method="post" action="<?php echo esc_url(nexdirectory_add_query_arg('nexdirectory_tab', 'listings', admin_url('admin-post.php'))); ?>#listings" data-nexdirectory-delete-confirm="1" data-nexdirectory-delete-title="<?php echo esc_attr(get_the_title()); ?>" data-nexdirectory-delete-message="<?php echo esc_attr($delete_prompt); ?>" class="nexdirectory-inline-form nexdirectory-dashboard-delete-form w-full sm:w-36">
                                                <input type="hidden" name="action" value="nexdirectory_delete_event">
                                                <input type="hidden" name="post_id" value="<?php echo esc_attr(get_the_ID()); ?>">
                                                <input type="hidden" name="nexdirectory_delete_nonce" value="<?php echo esc_attr(wp_create_nonce('nexdirectory_delete_event_' . get_the_ID())); ?>">
                                                <button type="submit" class="nexdirectory-account-action-btn nexdirectory-account-action-btn-danger nexdirectory-account-delete-btn w-full active:scale-95" aria-label="<?php echo esc_attr($delete_prompt); ?>">
                                                    <?php esc_html_e('Delete', 'nexdirectory'); ?>
                                                </button>
                                            </form>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        <?php endwhile; ?>
                        <?php wp_reset_postdata(); ?>
                        <?php if ($query instanceof WP_Query) { $query->rewind_posts(); } ?>
                    </div>
                <?php else : ?>
                    <div class="bg-white rounded-2xl border border-gray-100 p-10 text-center shadow-sm">
                        <div class="w-16 h-16 bg-gray-50 text-gray-400 rounded-full flex items-center justify-center mx-auto mb-4">
                            <svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 002 2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path></svg>
                        </div>
                        <h3 class="text-lg font-bold text-gray-900"><?php esc_html_e('No listings found', 'nexdirectory'); ?></h3>
                        <?php /* translators: %s: Placeholder value. */ ?>
                        <p class="text-gray-500 text-sm mt-1 mb-5"><?php echo esc_html(sprintf(__('You have not submitted any %s yet.', 'nexdirectory'), strtolower((string) $plural_label))); ?></p>
                        <?php if ($show_submit_tab) : ?>
                            <button type="button" @click="setTab('submit')" class="nexdirectory-force-accent-action inline-block bg-brand-600 text-white px-6 py-2.5 rounded-xl text-sm font-semibold hover:bg-brand-700 transition-colors active:scale-95 shadow-sm">Create Listing</button>
                        <?php endif; ?>
                    </div>
                <?php endif; ?>
            </div>

            <?php if ($is_events_profile && $webapp_enabled && has_action('nexdirectory_render_extension_account_event_webapp')) : ?>
                <?php do_action('nexdirectory_render_extension_account_event_webapp', $this, [
                    'webapp_event_options' => $webapp_event_options,
                    'selected_webapp_event_id' => $selected_webapp_event_id,
                    'webapp_settings' => $webapp_settings,
                    'my_events_url' => $my_events_url,
                    'webapp_manage_page_url' => $webapp_manage_page_url,
                    'webapp_selected_manage_url' => $webapp_selected_manage_url,
                    'selected_event_webapp_url' => $selected_event_webapp_url,
                    'selected_event_manifest_url' => $selected_event_manifest_url,
                    'selected_event_service_worker_url' => $selected_event_service_worker_url,
                    'selected_event_service_worker_scope' => $selected_event_service_worker_scope,
                    'show_submit_tab' => $show_submit_tab,
                ]); ?>
            <?php endif; ?>

            <?php if ($boosts_enabled) : ?>
            <div x-show="subTab === 'boosts'" x-transition.opacity.duration.300ms style="display: none;">
                <?php if (has_action('nexdirectory_render_extension_account_boosts')) : ?>
                    <?php
                    do_action('nexdirectory_render_extension_account_boosts', $this, [
                        'user_id' => (int) $user->ID,
                        'query' => isset($query) && $query instanceof WP_Query ? $query : null,
                        'my_events_url' => $my_events_url,
                        'ui_labels' => $ui_labels,
                    ]);
                    ?>
                <?php else : ?>
                    <div class="rounded-2xl border border-gray-200 bg-white p-6 text-sm text-gray-600 shadow-sm">
                        <?php esc_html_e('Boosts are licensed. Activate the Nex Directory Pro monetization module to manage boost packages and orders.', 'nexdirectory'); ?>
                    </div>
                <?php endif; ?>
            </div>
            <?php endif; ?>

            <?php if (!empty($attendees_panel)) : ?>
            <div id="nexdirectory-attendees-modal" class="fixed inset-0 z-[2147483600] flex items-center justify-center p-3 sm:p-6 bg-gray-900/60 backdrop-blur-sm" x-show="attendeesOpen" x-cloak role="dialog" aria-modal="true" aria-labelledby="nexdirectory-attendees-modal-title" :aria-hidden="attendeesOpen ? 'false' : 'true'" @click.self="closeAttendees()" @keydown.escape.window="if (attendeesOpen) closeAttendees()" x-effect="document.body.classList.toggle('nexdirectory-lightbox-open', attendeesOpen)" x-init="$nextTick(() => attendeesOpen && $refs.attendeesClose && $refs.attendeesClose.focus())">
                <div class="relative w-full bg-white rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[88vh] sm:max-h-[90vh]" style="max-width:min(1040px,90vw);">
                    <div class="sticky top-0 z-10 flex items-center justify-between p-5 border-b border-gray-100 bg-gray-50/95 backdrop-blur">
                        <div>
                            <h3 id="nexdirectory-attendees-modal-title" class="text-lg font-bold text-gray-900"><?php echo esc_html($attendees_heading); ?>: <?php echo esc_html((string) ($attendees_panel['event_title'] ?? '')); ?></h3>
                            <p class="text-xs text-gray-500 mt-1 font-medium">Confirmed: <?php echo (int)($attendees_panel['yes_count'] ?? 0); ?> • Waitlist: <?php echo (int)($attendees_panel['waitlist_count'] ?? 0); ?></p>
                        </div>
                        <button type="button" x-ref="attendeesClose" @click="closeAttendees()" aria-label="<?php esc_attr_e('Close attendees dialog', 'nexdirectory'); ?>" class="text-gray-400 hover:text-gray-900 transition-colors p-2 rounded-lg hover:bg-gray-200">
                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
                        </button>
                    </div>

                    <div class="p-5 sm:p-6 overflow-y-auto flex-1 bg-white space-y-6">
                        <div class="bg-gray-50 border border-gray-200 rounded-xl p-5">
                            <div class="flex flex-col sm:flex-row sm:items-start justify-between mb-4 gap-3">
                                <div>
                                    <h4 class="font-bold text-gray-900"><?php esc_html_e('Message Attendees', 'nexdirectory'); ?></h4>
                                    <p class="text-xs text-gray-500 mt-1 max-w-lg"><?php esc_html_e('Only attendees who opted into comms will receive this update.', 'nexdirectory'); ?></p>
                                </div>
                                <form method="post" action="<?php echo esc_url((string) ($attendees_panel['export_action'] ?? admin_url('admin-post.php'))); ?>">
                                    <input type="hidden" name="action" value="nexdirectory_export_event_attendees">
                                    <input type="hidden" name="event_id" value="<?php echo esc_attr((string) ($attendees_panel['event_id'] ?? '0')); ?>">
                                    <input type="hidden" name="nexdirectory_export_attendees_nonce" value="<?php echo esc_attr((string) ($attendees_panel['export_nonce'] ?? '')); ?>">
                                    <button type="submit" class="w-full sm:w-auto text-xs font-semibold bg-white border border-gray-200 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-100 active:scale-95 transition-all shadow-sm">Export CSV</button>
                                </form>
                            </div>

                            <form method="post" action="<?php echo esc_url((string) ($attendees_panel['email_action'] ?? admin_url('admin-post.php'))); ?>" class="space-y-4">
                                <input type="hidden" name="action" value="nexdirectory_email_event_attendees">
                                <input type="hidden" name="event_id" value="<?php echo esc_attr((string) ($attendees_panel['event_id'] ?? '0')); ?>">
                                <input type="hidden" name="nexdirectory_email_attendees_nonce" value="<?php echo esc_attr((string) ($attendees_panel['email_nonce'] ?? '')); ?>">
                                
                                <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                                    <select name="audience" class="w-full px-3 py-2.5 bg-white border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-brand-500 outline-none shadow-sm">
                                        <option value="confirmed"><?php esc_html_e('Confirmed only', 'nexdirectory'); ?></option>
                                        <option value="waitlist"><?php esc_html_e('Waitlist only', 'nexdirectory'); ?></option>
                                        <option value="all"><?php esc_html_e('Confirmed + Waitlist', 'nexdirectory'); ?></option>
                                    </select>
                                    <input type="text" name="subject" required placeholder="Email Subject..." class="w-full px-3 py-2.5 bg-white border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-brand-500 outline-none shadow-sm">
                                </div>
                                <textarea name="message" rows="3" required placeholder="Type your message here..." class="w-full px-3 py-2.5 bg-white border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-brand-500 outline-none shadow-sm resize-none"></textarea>
                                <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
                                    <label class="flex items-center gap-2 cursor-pointer">
                                        <input type="checkbox" name="send_copy" value="1" class="w-4 h-4 rounded border-gray-300 text-brand-600 focus:ring-brand-500">
                                        <span class="text-sm font-medium text-gray-700">Send me a copy</span>
                                    </label>
                                    <button type="submit" class="w-full sm:w-auto bg-brand-600 hover:bg-brand-700 text-white px-6 py-2.5 rounded-lg text-sm font-semibold transition-all active:scale-95 shadow-sm" style="background:var(--nexdirectory-primary,#FF5E14) !important; color:#ffffff !important;">Send Update</button>
                                </div>
                            </form>
                        </div>

                        <?php if (!empty($attendees_panel['rows'])) : ?>
                            <div class="border border-gray-200 rounded-xl overflow-hidden shadow-sm">
                                <div class="overflow-x-auto scrollbar-hide">
                                    <table class="w-full text-left text-sm text-gray-600 whitespace-nowrap">
                                        <thead class="bg-gray-50/50 text-xs uppercase text-gray-400 font-semibold border-b border-gray-100">
                                            <tr>
                                                <th class="px-5 py-3">Name</th>
                                                <th class="px-5 py-3">Email</th>
                                                <th class="px-5 py-3">Status</th>
                                                <th class="px-5 py-3">Comms</th>
                                            </tr>
                                        </thead>
                                        <tbody class="divide-y divide-gray-50">
                                            <?php foreach ((array) $attendees_panel['rows'] as $row) : ?>
                                                <tr class="hover:bg-gray-50/50 transition-colors">
                                                    <td class="px-5 py-3 font-medium text-gray-900"><?php echo esc_html((string) ($row['name'] ?? '')); ?></td>
                                                    <td class="px-5 py-3"><a href="mailto:<?php echo esc_attr((string) ($row['email'] ?? '')); ?>" class="text-brand-600 hover:text-brand-700 font-medium"><?php echo esc_html((string) ($row['email'] ?? '')); ?></a></td>
                                                    <td class="px-5 py-3"><span class="px-2.5 py-1 rounded-full text-[10px] font-bold uppercase tracking-wider bg-gray-100 text-gray-600 border border-gray-200"><?php echo esc_html((string) ($row['status_label'] ?? '')); ?></span></td>
                                                    <td class="px-5 py-3">
                                                        <?php echo (string) ($row['communication_opt_in'] ?? '0') === '1' ? '<span class="text-green-600 font-bold text-xs uppercase tracking-wide">Yes</span>' : '<span class="text-gray-400 font-bold text-xs uppercase tracking-wide">No</span>'; ?>
                                                    </td>
                                                </tr>
                                            <?php endforeach; ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
            <?php endif; ?>

        </section>
        <?php endif; ?>
<?php
        $prefill = isset($prefill) && is_array($prefill) ? $prefill : [];
        $is_edit_mode = !empty($prefill['is_edit']);
        $singular_lower = sanitize_text_field((string) ($ui_labels['singular_lower'] ?? strtolower($singular_label)));
        $is_job_profile = (string) ($ui_labels['is_job_profile'] ?? '0') === '1';
        $is_directory_profile = (string) ($ui_labels['is_directory_profile'] ?? '0') === '1';
        $is_marketplace_profile = (string) ($ui_labels['is_marketplace_profile'] ?? '0') === '1';

        $show_schedule_builder = $is_events_profile;
        $show_event_mode_toggle = $is_events_profile;
        $show_price_range_toggle = $is_events_profile;
        $show_capacity_field = $is_events_profile;
        $show_official_classification = $is_events_profile;
        $show_date_block = $is_events_profile;
        $show_video_embeds_section = $is_events_profile || $is_marketplace_profile || $is_directory_profile;
        $show_stream_field = $is_events_profile;

        // Dynamic Labels setup (condensed for space)
        $submit_add_title = $is_job_profile ? __('Add Job', 'nexdirectory') : ($is_directory_profile ? __('Add Listing', 'nexdirectory') : ($is_marketplace_profile ? __('Add Listing', 'nexdirectory') : __('Add Event', 'nexdirectory')));
        $submit_edit_title = str_replace('Add', 'Edit', $submit_add_title);
        $submit_primary_cta = $is_edit_mode ? str_replace('Add', 'Update', $submit_add_title) : str_replace('Add', 'Submit', $submit_add_title);
        
        $submit_recaptcha_required = !empty($submit_recaptcha_required);
        $use_rich_editor = isset($use_rich_editor) ? $use_rich_editor : true;
        
        $custom_form_fields = isset($custom_form_fields) && is_array($custom_form_fields) ? $custom_form_fields : [];
        $custom_fields_enabled = isset($custom_fields_enabled) && (bool) $custom_fields_enabled;
        $per_event_email_templates_enabled = isset($per_event_email_templates_enabled) && (bool) $per_event_email_templates_enabled;
        $organizer_event_seo_enabled = isset($organizer_event_seo_enabled) ? (bool) $organizer_event_seo_enabled : ((string) get_option('nexdirectory_enable_event_seo_fields', '1') === '1');
        $serp_preview_url = '';
        $editing_event_id = !empty($prefill['edit_event_id']) ? absint((int) $prefill['edit_event_id']) : 0;
        if ($is_edit_mode && $editing_event_id > 0) {
            if (trim((string) ($prefill['post_title'] ?? '')) === '') {
                $prefill['post_title'] = (string) $this->recover_existing_event_title_value($editing_event_id, (string) get_the_title($editing_event_id));
                if (trim((string) $prefill['post_title']) === '') {
                    /* translators: %d: Placeholder value. */
                    $prefill['post_title'] = sprintf(__('Untitled Listing #%d', 'nexdirectory'), $editing_event_id);
                }
            }
            if (trim((string) ($prefill['nexdirectory_start_raw'] ?? '')) === '') {
                $prefill['nexdirectory_start_raw'] = (string) $this->recover_existing_event_datetime_value($editing_event_id, 'nexdirectory_start');
            }
            if (trim((string) ($prefill['nexdirectory_end_raw'] ?? '')) === '') {
                $prefill['nexdirectory_end_raw'] = (string) $this->recover_existing_event_datetime_value($editing_event_id, 'nexdirectory_end');
            }
            if (trim((string) ($prefill['nexdirectory_cover_image_url'] ?? '')) === '') {
                $prefill['nexdirectory_cover_image_url'] = (string) $this->get_event_cover_image_url($editing_event_id, 'full', 'thumbnail');
                if (trim((string) $prefill['nexdirectory_cover_image_url']) === '' && has_post_thumbnail($editing_event_id)) {
                    $prefill['nexdirectory_cover_image_url'] = esc_url_raw((string) get_the_post_thumbnail_url($editing_event_id, 'full'));
                }
            }
        }
        if (!empty($prefill['edit_event_id'])) {
            $serp_preview_url = (string) get_permalink((int) $prefill['edit_event_id']);
        }
        if (!is_string($serp_preview_url) || $serp_preview_url === '') {
            $serp_preview_url = isset($events_url) && is_string($events_url) && $events_url !== '' ? (string) $events_url : (string) home_url('/events/');
        }
        $serp_preview_url = esc_url_raw($serp_preview_url);

        // Date Parsing for Prefill
        $prefill_start_raw = str_replace('T', ' ', (string) ($prefill['nexdirectory_start_raw'] ?? $prefill['nexdirectory_start_local'] ?? ''));
        $prefill_end_raw = str_replace('T', ' ', (string) ($prefill['nexdirectory_end_raw'] ?? $prefill['nexdirectory_end_local'] ?? ''));
        $prefill_start_date = preg_match('/^(\d{4}-\d{2}-\d{2})/', $prefill_start_raw, $m) ? $m[1] : '';
        $prefill_start_time = preg_match('/\b(\d{2}:\d{2})\b/', $prefill_start_raw, $m) ? $m[1] : '';
        $prefill_end_date = preg_match('/^(\d{4}-\d{2}-\d{2})/', $prefill_end_raw, $m) ? $m[1] : '';
        $prefill_end_time = preg_match('/\b(\d{2}:\d{2})\b/', $prefill_end_raw, $m) ? $m[1] : '';

        // Alpine JSON setup
        $alpine_prefill = [
            'titleValue' => (string) ($prefill['post_title'] ?? ''),
            'excerptValue' => (string) ($prefill['post_excerpt'] ?? ''),
            'coverImage' => (string) ($prefill['nexdirectory_cover_image_url'] ?? ''),
            'galleryImages' => array_values(array_filter(array_map('trim', preg_split('/\r\n|\r|\n/', (string) ($prefill['nexdirectory_gallery_urls'] ?? '')) ?: []))),
            'videoUrlsTextarea' => $show_video_embeds_section ? (string) ($prefill['nexdirectory_video_urls'] ?? '') : '',
            'videoEmbeds' => $show_video_embeds_section ? array_values(array_filter(array_map('trim', preg_split('/\r\n|\r|\n/', (string) ($prefill['nexdirectory_video_urls'] ?? '')) ?: []))) ?: [''] : [],
            'startValue' => $prefill_start_date, 'startTimeValue' => $prefill_start_time,
            'endValue' => $prefill_end_date, 'endTimeValue' => $prefill_end_time,
            'cityValue' => (string) ($prefill['nexdirectory_city'] ?? ''), 'countryValue' => (string) ($prefill['nexdirectory_country'] ?? ''),
            'latValue' => (string) ($prefill['nexdirectory_lat'] ?? ''), 'lngValue' => (string) ($prefill['nexdirectory_lng'] ?? ''),
            'streamUrl' => $show_stream_field ? (string) ($prefill['nexdirectory_event_stream_url'] ?? '') : '',
            'metaTitleValue' => (string) ($prefill['nexdirectory_meta_title'] ?? ''),
            'metaDescriptionValue' => (string) ($prefill['nexdirectory_meta_description'] ?? ''),
            'serpUrl' => $serp_preview_url,
            'modeOption' => (string) ($prefill['nexdirectory_event_mode_option'] ?? 'in-person'),
            'isRecurring' => (string) ($prefill['nexdirectory_is_recurring'] ?? '0') === '1' ? '1' : '0',
            'sessions' => is_array($prefill['sessions'] ?? null) ? array_values((array) $prefill['sessions']) : [],
            'keySpeakers' => is_array($prefill['key_speakers'] ?? null) ? array_values((array) $prefill['key_speakers']) : [],
            'recurrenceUntil' => (string) ($prefill['nexdirectory_recurrence_until'] ?? ''),
        ];
        $alpine_json_flags = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
        if (defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
            $alpine_json_flags |= JSON_INVALID_UTF8_SUBSTITUTE;
        }
        $alpine_prefill_json = wp_json_encode($alpine_prefill, $alpine_json_flags);
        ?>

        <?php if ($show_submit_tab) : ?>
        <section class="nexdirectory-account-view nexdirectory-account-view--submit" x-show="activeTab === 'submit'" x-transition.opacity.duration.300ms x-cloak>
            
            <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-8'" class="transition-all duration-700 ease-out mb-6 sm:mb-8">
                <h2 class="text-2xl sm:text-3xl font-bold text-gray-900 tracking-tight mb-2"><?php echo esc_html($is_edit_mode ? $submit_edit_title : $submit_add_title); ?></h2>
                <p class="text-sm sm:text-base text-gray-500 max-w-2xl">
                    <?php echo esc_html($is_edit_mode 
                        ? __('Update your details using the form below. Changes may require moderation.', 'nexdirectory') 
                        : __('Submit your details for review and publication.', 'nexdirectory')); ?>
                </p>
                <div class="nexdirectory-account-plan-notice <?php echo esc_attr($plan_notice_class); ?> mt-5" title="<?php echo esc_attr($plan_notice_tooltip); ?>">
                    <div>
                        <strong><?php echo esc_html($plan_notice_title); ?></strong>
                        <p><?php echo esc_html($plan_notice_text); ?></p>
                    </div>
                    <div class="nexdirectory-account-plan-actions">
                        <span class="nexdirectory-account-plan-badge"><?php echo esc_html($plan_notice_badge); ?> <span aria-label="<?php echo esc_attr($plan_notice_tooltip); ?>">?</span></span>
                        <?php if ($plan_show_cta) : ?>
                            <a class="nexdirectory-account-action-btn" href="<?php echo esc_url($plan_cta_url); ?>" <?php echo $plan_cta_external ? 'target="_blank" rel="noopener noreferrer"' : ''; ?>><?php echo esc_html($plan_cta_label); ?></a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>

            <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-8'" class="transition-all duration-700 ease-out delay-100">
                <form method="post" action="<?php echo esc_url(nexdirectory_add_query_arg('nexdirectory_tab', 'submit', admin_url('admin-post.php'))); ?>#submit" enctype="multipart/form-data" id="nexdirectory-submit-form" class="space-y-6 sm:space-y-8" 
                      x-data='nexdirectorySubmitForm(<?php echo esc_attr($alpine_prefill_json ?: '{}'); ?>)' 
                      data-nexdirectory-editing="<?php echo $is_edit_mode ? '1' : '0'; ?>" 
                      data-nexdirectory-requires-address="<?php echo ($is_events_profile || $is_directory_profile) ? '1' : '0'; ?>"
                      data-nexdirectory-initial-sessions="<?php echo esc_attr(wp_json_encode((array) ($prefill['sessions'] ?? []))); ?>" 
                      data-nexdirectory-recurrence-until="<?php echo esc_attr((string) ($prefill['nexdirectory_recurrence_until'] ?? '')); ?>">
                    
                    <input type="hidden" name="action" value="nexdirectory_submit_event">
                    <input type="hidden" name="nexdirectory_edit_post_id" value="<?php echo esc_attr((string) ($prefill['edit_event_id'] ?? '0')); ?>">
                    <?php wp_nonce_field('nexdirectory_submit_event_nonce', 'nexdirectory_nonce'); ?>
                    <input type="hidden" name="nexdirectory_website" class="nexdirectory-honeypot" tabindex="-1" autocomplete="off" aria-hidden="true">
                    <input type="hidden" name="nexdirectory_recaptcha_token" class="<?php echo $submit_recaptcha_required ? 'nexdirectory-recaptcha-token' : ''; ?>" value="">
                    
                    <input type="hidden" name="nexdirectory_sessions" :value="JSON.stringify(sessions)">
                    <input type="hidden" name="nexdirectory_key_speakers" :value="JSON.stringify(keySpeakers)">
                    <input type="hidden" name="nexdirectory_autosave_post_id" x-model="autosavePostId">
                    <input type="hidden" name="nexdirectory_recurrence" :value="isRecurring === '1' ? 'custom' : 'none'">
                    <input type="hidden" name="nexdirectory_recurrence_until" :value="recurrenceUntil">
                    <input type="hidden" name="nexdirectory_lat" id="nexdirectory-lat-input" x-model="latValue" value="<?php echo esc_attr((string) ($prefill['nexdirectory_lat'] ?? '')); ?>">
                    <input type="hidden" name="nexdirectory_lng" id="nexdirectory-lng-input" x-model="lngValue" value="<?php echo esc_attr((string) ($prefill['nexdirectory_lng'] ?? '')); ?>">
                    <input type="hidden" name="nexdirectory_country" x-model="countryValue" value="<?php echo esc_attr((string) ($prefill['nexdirectory_country'] ?? '')); ?>">

                    <div class="bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden">
                        <div class="p-5 border-b border-gray-100 bg-gray-50/50">
                            <h3 class="font-bold text-gray-900 flex items-center gap-2">
                                <svg class="w-5 h-5 text-brand-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg>
                                <?php esc_html_e('General Information', 'nexdirectory'); ?>
                            </h3>
                        </div>
                        <div class="p-5 sm:p-6 space-y-5">
                            <div>
                                <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Title', 'nexdirectory'); ?></label>
                                <input type="text" name="post_title" required x-model="titleValue" value="<?php echo esc_attr((string) ($prefill['post_title'] ?? '')); ?>" @input.debounce.150ms="validateTitle" placeholder="<?php esc_attr_e('Listing name...', 'nexdirectory'); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none transition-all shadow-sm">
                                <p class="text-[11px] text-gray-500 mt-1" x-text="titleCounterText()"></p>
                                <p class="text-xs text-red-500 mt-1" x-show="titleError" x-text="titleError" x-cloak></p>
                            </div>

                            <div>
                                <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Description', 'nexdirectory'); ?></label>
                                <?php if ($use_rich_editor && function_exists('wp_editor')) : ?>
                                    <div class="border border-gray-200 rounded-xl overflow-hidden focus-within:ring-2 focus-within:ring-brand-500 focus-within:border-brand-500 transition-all shadow-sm">
                                        <?php wp_editor((string) ($prefill['post_content'] ?? ''), 'nexdirectory_post_content_editor', ['textarea_name' => 'post_content', 'textarea_rows' => 8, 'media_buttons' => false, 'teeny' => true, 'tinymce' => ['wpautop' => true]]); ?>
                                    </div>
                                <?php else : ?>
                                    <textarea name="post_content" rows="6" required class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none transition-all shadow-sm resize-y"></textarea>
                                <?php endif; ?>
                            </div>

                            <div>
                                <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Short Summary (Optional)', 'nexdirectory'); ?></label>
                                <textarea name="post_excerpt" rows="2" maxlength="220" x-model="excerptValue" @input="validateExcerpt" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none transition-all shadow-sm resize-none"><?php echo esc_textarea((string) ($prefill['post_excerpt'] ?? '')); ?></textarea>
                                <p class="text-[11px] text-gray-500 mt-1" x-text="excerptCounterText()"></p>
                                <p class="text-xs text-red-500 mt-1" x-show="excerptError" x-text="excerptError" x-cloak></p>
                            </div>

                            <?php if ($organizer_event_seo_enabled) : ?>
                            <div class="rounded-2xl border border-amber-200 bg-amber-50/60 p-4 sm:p-5 space-y-4">
                                <div class="flex items-start justify-between gap-3">
                                    <div>
                                        <h4 class="text-sm sm:text-base font-bold text-gray-900"><?php esc_html_e('SEO Snippet Preview', 'nexdirectory'); ?></h4>
                                        <p class="text-xs text-gray-600"><?php esc_html_e('Control how this event appears in Google results.', 'nexdirectory'); ?></p>
                                    </div>
                                    <button type="button" @click="fillSeoFromContent()" class="inline-flex items-center justify-center px-3 py-2 rounded-lg border border-amber-300 text-amber-700 hover:bg-amber-100 text-xs font-semibold transition-colors">
                                        <?php esc_html_e('Use Title + Summary', 'nexdirectory'); ?>
                                    </button>
                                </div>

                                <div class="grid grid-cols-1 gap-4">
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Meta Title', 'nexdirectory'); ?></label>
                                        <input type="text" name="nexdirectory_meta_title" maxlength="60" x-model="metaTitleValue" @input="queueAutosave(220)" placeholder="<?php esc_attr_e('Best between 50 and 60 characters', 'nexdirectory'); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none transition-all shadow-sm">
                                        <div class="mt-1 flex items-center justify-between gap-3">
                                            <p class="text-[11px] text-gray-600"><span x-text="seoTitleCount()"></span> / 60</p>
                                            <p class="text-[11px] font-medium" :class="seoTitleStatusClass()" x-text="seoTitleStatusText()"></p>
                                        </div>
                                    </div>

                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Meta Description', 'nexdirectory'); ?></label>
                                        <textarea name="nexdirectory_meta_description" rows="3" maxlength="158" x-model="metaDescriptionValue" @input="queueAutosave(220)" placeholder="<?php esc_attr_e('Best between 120 and 158 characters', 'nexdirectory'); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none transition-all shadow-sm resize-y"></textarea>
                                        <div class="mt-1 flex items-center justify-between gap-3">
                                            <p class="text-[11px] text-gray-600"><span x-text="seoDescriptionCount()"></span> / 158</p>
                                            <p class="text-[11px] font-medium" :class="seoDescriptionStatusClass()" x-text="seoDescriptionStatusText()"></p>
                                        </div>
                                    </div>
                                </div>

                                <div class="rounded-xl bg-white border border-gray-200 p-4 shadow-sm">
                                    <p class="text-xs text-green-700 truncate" x-text="serpUrlPreview()"></p>
                                    <p class="text-lg leading-6 text-[#1a0dab] hover:underline cursor-pointer mt-1" x-text="serpTitlePreview()"></p>
                                    <p class="text-sm text-[#4d5156] mt-1 leading-5" x-text="serpDescriptionPreview()"></p>
                                </div>
                            </div>
                            <?php endif; ?>
                        </div>
                    </div>

                    <div class="bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden">
                        <div class="p-5 border-b border-gray-100 bg-gray-50/50">
                            <h3 class="font-bold text-gray-900 flex items-center gap-2">
                                <svg class="w-5 h-5 text-brand-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"></path></svg>
                                <?php esc_html_e('Media & Images', 'nexdirectory'); ?>
                            </h3>
                        </div>
                        <div class="p-5 sm:p-6 space-y-6">
                            
                            <input type="file" name="nexdirectory_cover_file" x-ref="coverFileInput" accept="image/*" style="display:none;" @change="handleFileSelect($event, 'cover')">
                            <input type="file" name="nexdirectory_gallery_files[]" x-ref="galleryFileInput" accept="image/*" multiple style="display:none;" @change="handleFileSelect($event, 'gallery')">
                            
                            <div>
                                <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Cover Image', 'nexdirectory'); ?></label>
                                <div class="relative border-2 border-dashed border-gray-300 rounded-2xl hover:border-brand-400 bg-gray-50 hover:bg-brand-50 transition-colors cursor-pointer overflow-hidden min-h-[160px] flex items-center justify-center group" @dragover.prevent @drop.prevent="handleDrop($event, 'cover')" @click="openMedia('cover')">
                                    <template x-if="coverImage">
                                        <div class="absolute inset-0">
                                            <img :src="coverImage" class="w-full h-full object-cover">
                                            <div class="absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center">
                                                <span class="text-white font-semibold text-sm bg-black/50 px-3 py-1.5 rounded-lg">Change Image</span>
                                            </div>
                                            <button type="button" @click.stop="removeCover()" class="absolute top-2 right-2 bg-red-500 text-white rounded-full p-1.5 hover:bg-red-600 transition-colors shadow-sm">
                                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
                                            </button>
                                        </div>
                                    </template>
                                    <template x-if="!coverImage">
                                        <div class="text-center p-6 pointer-events-none">
                                            <svg class="mx-auto h-10 w-10 text-gray-400 mb-2" stroke="currentColor" fill="none" viewBox="0 0 48 48"><path d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
                                            <p class="text-sm text-gray-600 font-medium">Click to upload or drag and drop</p>
                                            <p class="text-[11px] text-gray-400 mt-1">PNG, JPG up to 10MB</p>
                                        </div>
                                    </template>
                                </div>
                                <input type="hidden" name="nexdirectory_cover_image_url" x-model="coverImage">
                            </div>

                            <div>
                                <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Gallery Images (Optional)', 'nexdirectory'); ?></label>
                                <div class="relative border-2 border-dashed border-gray-300 rounded-2xl hover:border-brand-400 bg-gray-50 hover:bg-brand-50 transition-colors cursor-pointer py-6 flex items-center justify-center group" @dragover.prevent @drop.prevent="handleDrop($event, 'gallery')" @click="openMedia('gallery')">
                                    <div class="text-center pointer-events-none">
                                        <p class="text-sm text-gray-600 font-medium">Add to gallery (multiple allowed)</p>
                                    </div>
                                </div>
                                <div class="grid grid-cols-2 sm:grid-cols-4 gap-3 mt-4" x-show="galleryImages.length" x-cloak>
                                    <template x-for="(url, index) in galleryImages" :key="index">
                                        <div class="relative aspect-square rounded-xl overflow-hidden border border-gray-200 shadow-sm group">
                                            <img :src="url" class="w-full h-full object-cover">
                                            <button type="button" @click.stop="removeGallery(index)" class="absolute top-1 right-1 bg-red-500/90 text-white rounded-full p-1 hover:bg-red-600 transition-colors shadow-sm opacity-0 group-hover:opacity-100">
                                                <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
                                            </button>
                                        </div>
                                    </template>
                                </div>
                                <textarea name="nexdirectory_gallery_urls" x-model="galleryTextarea" style="display:none;"></textarea>
                            </div>
                        </div>
                    </div>

                    <div class="bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden">
                        <div class="p-5 border-b border-gray-100 bg-gray-50/50">
                            <h3 class="font-bold text-gray-900 flex items-center gap-2">
                                <svg class="w-5 h-5 text-brand-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path></svg>
                                <?php esc_html_e('Contact & Location', 'nexdirectory'); ?>
                            </h3>
                        </div>
                        <div class="p-5 sm:p-6 space-y-6">
                            
                            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4 sm:gap-6">
                                <div>
                                    <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Phone Number (Optional)', 'nexdirectory'); ?></label>
                                    <input type="text" name="nexdirectory_contact_phone" value="<?php echo esc_attr((string) ($prefill['nexdirectory_contact_phone'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none transition-all shadow-sm">
                                </div>
                                <div>
                                    <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Contact Email (Optional)', 'nexdirectory'); ?></label>
                                    <input type="email" name="nexdirectory_contact_email" value="<?php echo esc_attr((string) ($prefill['nexdirectory_contact_email'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none transition-all shadow-sm">
                                </div>
                            </div>

                            <hr class="border-gray-100">

                            <div>
                                <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Address', 'nexdirectory'); ?></label>
                                <input type="text" name="nexdirectory_address" id="nexdirectory-address-input" list="nexdirectory-address-suggestions" value="<?php echo esc_attr((string) ($prefill['nexdirectory_address'] ?? '')); ?>" placeholder="Start typing to search..." <?php echo ($is_events_profile || $is_directory_profile) ? 'required' : ''; ?> class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none transition-all shadow-sm">
                                <datalist id="nexdirectory-address-suggestions"></datalist>
                            </div>

                            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4 sm:gap-6">
                                <div>
                                    <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('City / Area', 'nexdirectory'); ?></label>
                                    <input type="text" name="nexdirectory_city" x-model="cityValue" value="<?php echo esc_attr((string) ($prefill['nexdirectory_city'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none transition-all shadow-sm bg-gray-50">
                                </div>
                                <div>
                                    <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Venue Name (Optional)', 'nexdirectory'); ?></label>
                                    <input type="text" name="nexdirectory_venue" value="<?php echo esc_attr((string) ($prefill['nexdirectory_venue'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none transition-all shadow-sm">
                                </div>
                            </div>

                            <button type="button" id="nexdirectory-geocode-btn" class="w-full sm:w-auto px-5 py-2.5 bg-gray-100 hover:bg-gray-200 text-gray-800 text-sm font-semibold rounded-xl transition-all shadow-sm active:scale-95 border border-gray-200">
                                <?php esc_html_e('Preview Location on Map', 'nexdirectory'); ?>
                            </button>
                            <div id="nexdirectory-location-preview" class="w-full h-48 sm:h-64 bg-gray-100 rounded-xl border border-gray-200 overflow-hidden shadow-inner hidden"></div>

                        </div>
                    </div>

                    <div class="bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden">
                        <div class="p-5 border-b border-gray-100 bg-gray-50/50">
                            <h3 class="font-bold text-gray-900 flex items-center gap-2">
                                <svg class="w-5 h-5 text-brand-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg>
                                <?php esc_html_e('Listing Specific Details', 'nexdirectory'); ?>
                            </h3>
                        </div>
                        <div class="p-5 sm:p-6 space-y-6">

                            <?php if ($is_job_profile) : ?>
                                <div class="grid grid-cols-1 sm:grid-cols-2 gap-4 sm:gap-6">
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Company Name</label>
                                        <input type="text" name="nexdirectory_company_name" required value="<?php echo esc_attr((string) ($prefill['nexdirectory_company_name'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                    </div>
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Employment Type</label>
                                        <select name="nexdirectory_job_type" required class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all appearance-none cursor-pointer">
                                            <option value="">Select type</option>
                                            <?php foreach (['Full-time', 'Part-time', 'Contract', 'Internship', 'Temporary', 'Freelance'] as $opt) : ?>
                                                <option value="<?php echo esc_attr($opt); ?>" <?php selected((string) ($prefill['nexdirectory_job_type'] ?? ''), $opt); ?>><?php echo esc_html($opt); ?></option>
                                            <?php endforeach; ?>
                                        </select>
                                    </div>
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Work Location Type</label>
                                        <select name="nexdirectory_job_work_mode" required class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all appearance-none cursor-pointer">
                                            <option value="">Select location type</option>
                                            <option value="on-site" <?php selected((string) ($prefill['nexdirectory_job_work_mode'] ?? ''), 'on-site'); ?>>On-site</option>
                                            <option value="hybrid" <?php selected((string) ($prefill['nexdirectory_job_work_mode'] ?? ''), 'hybrid'); ?>>Hybrid</option>
                                            <option value="remote" <?php selected((string) ($prefill['nexdirectory_job_work_mode'] ?? ''), 'remote'); ?>>Remote</option>
                                        </select>
                                    </div>
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Salary Range</label>
                                        <input type="text" name="nexdirectory_job_salary" required placeholder="e.g. £55,000 - £72,000" value="<?php echo esc_attr((string) ($prefill['nexdirectory_job_salary'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                    </div>
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Application Deadline</label>
                                        <input type="date" name="nexdirectory_job_closing_date" required value="<?php echo esc_attr((string) ($prefill['nexdirectory_job_closing_date'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                    </div>
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Application URL</label>
                                        <input type="url" name="nexdirectory_job_apply_url" placeholder="https://..." value="<?php echo esc_attr((string) ($prefill['nexdirectory_job_apply_url'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                    </div>
                                </div>
                            
                            <?php elseif ($is_directory_profile) : ?>
                                <div class="grid grid-cols-1 sm:grid-cols-2 gap-4 sm:gap-6">
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Business Name</label>
                                        <input type="text" name="nexdirectory_company_name" required value="<?php echo esc_attr((string) ($prefill['nexdirectory_company_name'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                    </div>
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Business Type</label>
                                        <select name="nexdirectory_directory_business_type" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all appearance-none cursor-pointer">
                                            <option value="independent-business">Independent Business</option>
                                            <option value="agency">Agency</option>
                                            <option value="private-owner">Private Owner</option>
                                        </select>
                                    </div>
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Service Area (Optional)</label>
                                        <input type="text" name="nexdirectory_directory_service_area" placeholder="London + 25 miles..." value="<?php echo esc_attr((string) ($prefill['nexdirectory_directory_service_area'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                    </div>
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Operating Hours (Optional)</label>
                                        <input type="text" name="nexdirectory_directory_operating_hours" placeholder="Mon-Fri 09:00-18:00" value="<?php echo esc_attr((string) ($prefill['nexdirectory_directory_operating_hours'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                    </div>
                                </div>
                            
                            <?php elseif ($is_marketplace_profile) : ?>
                                <div class="grid grid-cols-1 sm:grid-cols-2 gap-4 sm:gap-6">
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Condition</label>
                                        <select name="nexdirectory_market_condition" required class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all appearance-none cursor-pointer">
                                            <option value="">Select condition</option>
                                            <?php foreach (['New', 'Like New', 'Used', 'Refurbished', 'For Parts'] as $opt) : ?>
                                                <option value="<?php echo esc_attr($opt); ?>" <?php selected((string) ($prefill['nexdirectory_market_condition'] ?? ''), $opt); ?>><?php echo esc_html($opt); ?></option>
                                            <?php endforeach; ?>
                                        </select>
                                    </div>
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Asking Price</label>
                                        <input type="text" name="nexdirectory_price" required placeholder="e.g. £120" value="<?php echo esc_attr((string) ($prefill['nexdirectory_price'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                    </div>
                                </div>
                                
                            <?php else : ?>
                                <div class="grid grid-cols-1 md:grid-cols-3 gap-4 sm:gap-6">
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Start Date</label>
                                        <input type="date" name="nexdirectory_start_date" required x-model="startValue" value="<?php echo esc_attr((string) $prefill_start_date); ?>" @input="validateDates" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                        <label class="block text-sm font-semibold text-gray-900 mt-3 mb-1.5">Start Time (Optional)</label>
                                        <input type="time" name="nexdirectory_start_time" x-model="startTimeValue" value="<?php echo esc_attr((string) $prefill_start_time); ?>" @input="validateDates" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                    </div>
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">End Date</label>
                                        <input type="date" name="nexdirectory_end_date" x-model="endValue" value="<?php echo esc_attr((string) $prefill_end_date); ?>" @input="validateDates" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                        <label class="block text-sm font-semibold text-gray-900 mt-3 mb-1.5">End Time (Optional)</label>
                                        <input type="time" name="nexdirectory_end_time" x-model="endTimeValue" value="<?php echo esc_attr((string) $prefill_end_time); ?>" @input="validateDates" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                    </div>
                                    <div>
                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5">Capacity (Optional)</label>
                                        <input type="number" name="nexdirectory_capacity" min="0" value="<?php echo esc_attr((string) ($prefill['nexdirectory_capacity'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                    </div>
                                </div>
                                <p class="text-xs text-red-500 font-medium" x-show="dateError" x-text="dateError" x-cloak></p>

                                <?php if ($ticketing_pro_enabled) : ?>
                                    <?php do_action('nexdirectory_render_extension_submit_ticket_fields', $this, $prefill, 'account'); ?>
                                <?php endif; ?>
                            <?php endif; ?>

                            <?php if ($is_events_profile) : ?>
                                <div class="space-y-4 border border-gray-200 rounded-2xl p-4 sm:p-5 bg-gray-50/40">
                                    <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
                                        <div>
                                            <h4 class="text-base sm:text-lg font-bold text-gray-900"><?php esc_html_e('Event Itinerary', 'nexdirectory'); ?></h4>
                                            <p class="text-xs text-gray-500"><?php esc_html_e('Add schedule rows with date/day, speaker, notes, and attachment links.', 'nexdirectory'); ?></p>
                                        </div>
                                    </div>

                                    <p class="text-xs text-gray-500" x-show="!sessions.length" x-cloak><?php esc_html_e('No itinerary rows yet. Add one below.', 'nexdirectory'); ?></p>

                                    <div class="relative" x-show="sessions.length" x-cloak>
                                        <template x-for="(session, index) in sessions" :key="'session-' + index">
                                            <div class="relative pl-10 pb-6 last:pb-0">
                                                <span class="absolute left-0 top-6 flex w-5 h-5 items-center justify-center rounded-full bg-brand-500 border-4 border-white shadow-sm"></span>
                                                <span class="absolute left-[9px] top-11 bottom-0 w-px bg-gradient-to-b from-brand-200 via-gray-200 to-gray-200" x-show="index < (sessions.length - 1)" x-cloak></span>

                                                <div class="bg-white border border-gray-200 rounded-xl p-4 shadow-sm space-y-4">
                                                    <div class="flex items-center justify-between gap-3">
                                                        <h5 class="text-sm font-bold text-gray-900" x-text="'Session ' + (index + 1)"></h5>
                                                        <button type="button" @click="removeSession(index)" class="inline-flex items-center gap-1.5 px-3 py-1.5 border border-red-200 text-red-600 bg-red-50 hover:bg-red-100 rounded-lg text-xs font-semibold transition-colors active:scale-95">
                                                            <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
                                                            <?php esc_html_e('Remove', 'nexdirectory'); ?>
                                                        </button>
                                                    </div>

                                                    <div class="space-y-3">
                                                        <div class="relative pl-7 pb-3">
                                                            <span class="absolute left-0 top-3 w-2.5 h-2.5 rounded-full bg-brand-400"></span>
                                                            <span class="absolute left-[4px] top-5 bottom-0 w-px bg-gray-200"></span>
                                                            <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Session Name', 'nexdirectory'); ?></label>
                                                            <input type="text" x-model="sessions[index].title" placeholder="<?php esc_attr_e('Opening Ceremony', 'nexdirectory'); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                                        </div>

                                                        <div class="relative pl-7 pb-3">
                                                            <span class="absolute left-0 top-3 w-2.5 h-2.5 rounded-full bg-brand-400"></span>
                                                            <span class="absolute left-[4px] top-5 bottom-0 w-px bg-gray-200"></span>
                                                            <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Start Time', 'nexdirectory'); ?></label>
                                                            <input type="datetime-local" x-model="sessions[index].start" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                                        </div>

                                                        <div class="relative pl-7 pb-3">
                                                            <span class="absolute left-0 top-3 w-2.5 h-2.5 rounded-full bg-brand-400"></span>
                                                            <span class="absolute left-[4px] top-5 bottom-0 w-px bg-gray-200"></span>
                                                            <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('End Time', 'nexdirectory'); ?></label>
                                                            <input type="datetime-local" x-model="sessions[index].end" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                                        </div>

                                                        <div class="relative pl-7 pb-3">
                                                            <span class="absolute left-0 top-3 w-2.5 h-2.5 rounded-full bg-brand-400"></span>
                                                            <span class="absolute left-[4px] top-5 bottom-0 w-px bg-gray-200"></span>
                                                            <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Location', 'nexdirectory'); ?></label>
                                                            <input type="text" x-model="sessions[index].location" placeholder="<?php esc_attr_e('Main Hall', 'nexdirectory'); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                                        </div>

                                                        <div class="relative pl-7">
                                                            <span class="absolute left-0 top-3 w-2.5 h-2.5 rounded-full bg-brand-400"></span>
                                                            <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Speaker', 'nexdirectory'); ?></label>
                                                            <input type="text" x-model="sessions[index].speaker" placeholder="<?php esc_attr_e('Speaker Name', 'nexdirectory'); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                                        </div>

                                                        <div class="relative pl-7">
                                                            <span class="absolute left-0 top-3 w-2.5 h-2.5 rounded-full bg-brand-400"></span>
                                                            <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Day Label (Optional)', 'nexdirectory'); ?></label>
                                                            <input type="text" x-model="sessions[index].day" placeholder="<?php esc_attr_e('Day 1 or Jun 9, 2026', 'nexdirectory'); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                                        </div>

                                                        <div class="relative pl-7">
                                                            <span class="absolute left-0 top-3 w-2.5 h-2.5 rounded-full bg-brand-400"></span>
                                                            <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Notes (Optional)', 'nexdirectory'); ?></label>
                                                            <textarea x-model="sessions[index].notes" rows="3" placeholder="<?php esc_attr_e('Add session notes, reminders, or key points.', 'nexdirectory'); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all resize-y"></textarea>
                                                        </div>

                                                        <div class="relative pl-7">
                                                            <span class="absolute left-0 top-3 w-2.5 h-2.5 rounded-full bg-brand-400"></span>
                                                            <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Attachment URLs (Optional)', 'nexdirectory'); ?></label>
                                                            <textarea x-model="sessions[index].attachments" rows="3" placeholder="<?php esc_attr_e('One URL per line (file URL, image URL, or YouTube URL)', 'nexdirectory'); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all resize-y"></textarea>
                                                            <p class="mt-1.5 text-xs text-gray-500"><?php esc_html_e('Upload files, pick from media library, or paste direct links and YouTube URLs.', 'nexdirectory'); ?></p>
                                                            <div class="mt-2 flex flex-wrap gap-2">
                                                                <button type="button" @click="triggerSessionAttachmentInput(index)" class="inline-flex items-center gap-1.5 px-3 py-2 border border-gray-300 text-gray-700 bg-white hover:bg-gray-50 rounded-lg text-xs font-semibold transition-colors">
                                                                    <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1M8 12l4-4m0 0l4 4m-4-4v12"></path></svg>
                                                                    <?php esc_html_e('Upload File', 'nexdirectory'); ?>
                                                                </button>
                                                                <button type="button" @click="openSessionAttachmentMediaPicker(index)" class="inline-flex items-center gap-1.5 px-3 py-2 border border-gray-300 text-gray-700 bg-white hover:bg-gray-50 rounded-lg text-xs font-semibold transition-colors">
                                                                    <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7h18M3 12h18M3 17h18"></path></svg>
                                                                    <?php esc_html_e('Media Library', 'nexdirectory'); ?>
                                                                </button>
                                                            </div>
                                                            <input type="file" class="nexdirectory-session-attachment-upload" :id="'nexdirectory-session-attachment-upload-' + index" @change="handleSessionAttachmentUpload($event, index)" multiple accept="image/*,video/*,.pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx,.txt,.zip,.csv,.json,.rtf,.odt,.ods,.odp,.mp4,.mov,.webm,.m4v,.avi,.mkv" hidden>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </template>
                                    </div>

                                    <div class="pt-1 pl-0 sm:pl-10">
                                        <button type="button" @click="addSession()" class="inline-flex items-center justify-center gap-2 px-4 py-2.5 bg-brand-50 hover:bg-brand-100 border border-brand-200 text-brand-700 text-sm font-semibold rounded-xl transition-all shadow-sm active:scale-95">
                                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path></svg>
                                            <?php esc_html_e('Add Itinerary Row', 'nexdirectory'); ?>
                                        </button>
                                    </div>
                                </div>

                                <div class="space-y-4 border border-gray-200 rounded-2xl p-4 sm:p-5 bg-gray-50/40">
                                    <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
                                        <div>
                                            <h4 class="text-base sm:text-lg font-bold text-gray-900"><?php esc_html_e('Key Speakers', 'nexdirectory'); ?></h4>
                                            <p class="text-xs text-gray-500"><?php esc_html_e('Add featured speakers with their role, topic, and profile image.', 'nexdirectory'); ?></p>
                                        </div>
                                        <button type="button" @click="addKeySpeaker()" class="inline-flex items-center justify-center gap-2 px-4 py-2.5 bg-brand-50 hover:bg-brand-100 border border-brand-200 text-brand-700 text-sm font-semibold rounded-xl transition-all shadow-sm active:scale-95">
                                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path></svg>
                                            <?php esc_html_e('Add Key Speaker', 'nexdirectory'); ?>
                                        </button>
                                    </div>

                                    <p class="text-xs text-gray-500" x-show="!keySpeakers.length" x-cloak><?php esc_html_e('No key speakers added yet.', 'nexdirectory'); ?></p>

                                    <div class="space-y-4" x-show="keySpeakers.length" x-cloak>
                                        <template x-for="(speaker, index) in keySpeakers" :key="'speaker-' + index">
                                            <div class="bg-white border border-gray-200 rounded-xl p-4 shadow-sm space-y-4">
                                                <div class="flex items-center justify-between gap-3">
                                                    <h5 class="text-sm font-bold text-gray-900" x-text="'Speaker ' + (index + 1)"></h5>
                                                    <button type="button" @click="removeKeySpeaker(index)" class="inline-flex items-center gap-1.5 px-3 py-1.5 border border-red-200 text-red-600 bg-red-50 hover:bg-red-100 rounded-lg text-xs font-semibold transition-colors active:scale-95">
                                                        <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
                                                        <?php esc_html_e('Remove', 'nexdirectory'); ?>
                                                    </button>
                                                </div>

                                                <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                                                    <div>
                                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Name', 'nexdirectory'); ?></label>
                                                        <input type="text" x-model="keySpeakers[index].name" placeholder="<?php esc_attr_e('Jane Smith', 'nexdirectory'); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                                    </div>
                                                    <div>
                                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Profession', 'nexdirectory'); ?></label>
                                                        <input type="text" x-model="keySpeakers[index].profession" placeholder="<?php esc_attr_e('Civil Engineer', 'nexdirectory'); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                                    </div>
                                                    <div>
                                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Subject', 'nexdirectory'); ?></label>
                                                        <input type="text" x-model="keySpeakers[index].subject" placeholder="<?php esc_attr_e('Future of Infrastructure', 'nexdirectory'); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                                                    </div>
                                                    <div class="sm:col-span-2">
                                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Speaker Image', 'nexdirectory'); ?></label>
                                                        <input type="hidden" x-model="keySpeakers[index].image">
                                                        <input type="file" class="nexdirectory-speaker-image-upload" :id="'nexdirectory-speaker-image-upload-' + index" @change="handleSpeakerImageUpload($event, index)" accept="image/*" hidden>
                                                        <div class="border border-dashed border-gray-300 rounded-xl p-3 bg-gray-50">
                                                            <template x-if="keySpeakers[index].image">
                                                                <div class="mb-3">
                                                                    <img :src="keySpeakers[index].image" class="w-20 h-20 rounded-lg object-cover border border-gray-200 shadow-sm" alt="">
                                                                </div>
                                                            </template>
                                                            <div class="flex flex-wrap gap-2">
                                                                <button type="button" @click="triggerSpeakerImageInput(index)" class="inline-flex items-center gap-1.5 px-3 py-2 border border-gray-300 text-gray-700 bg-white hover:bg-gray-50 rounded-lg text-xs font-semibold transition-colors">
                                                                    <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1M8 12l4-4m0 0l4 4m-4-4v12"></path></svg>
                                                                    <?php esc_html_e('Upload Image', 'nexdirectory'); ?>
                                                                </button>
                                                                <button type="button" @click="openSpeakerImageMediaPicker(index)" class="inline-flex items-center gap-1.5 px-3 py-2 border border-gray-300 text-gray-700 bg-white hover:bg-gray-50 rounded-lg text-xs font-semibold transition-colors">
                                                                    <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7h18M3 12h18M3 17h18"></path></svg>
                                                                    <?php esc_html_e('Media Library', 'nexdirectory'); ?>
                                                                </button>
                                                                <button type="button" @click="removeSpeakerImage(index)" x-show="keySpeakers[index].image" x-cloak class="inline-flex items-center gap-1.5 px-3 py-2 border border-red-200 text-red-600 bg-red-50 hover:bg-red-100 rounded-lg text-xs font-semibold transition-colors">
                                                                    <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
                                                                    <?php esc_html_e('Remove', 'nexdirectory'); ?>
                                                                </button>
                                                            </div>
                                                            <p class="mt-2 text-xs text-gray-500"><?php esc_html_e('Upload a new image or pick one from your media library.', 'nexdirectory'); ?></p>
                                                        </div>
                                                    </div>
                                                    <div class="sm:col-span-2">
                                                        <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Details (Optional)', 'nexdirectory'); ?></label>
                                                        <textarea x-model="keySpeakers[index].details" rows="3" placeholder="<?php esc_attr_e('Short bio or speaking notes.', 'nexdirectory'); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all resize-y"></textarea>
                                                    </div>
                                                </div>
                                            </div>
                                        </template>
                                    </div>
                                </div>
                            <?php endif; ?>

                            <div>
                                <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Category (Optional)', 'nexdirectory'); ?></label>
                                <div class="relative">
                                    <?php
                                    wp_dropdown_categories([
                                        'taxonomy' => $this::TAX_TYPE ?? 'category',
                                        'name' => 'event_type',
                                        'show_option_none' => __('Select Category', 'nexdirectory'),
                                        'hide_empty' => false,
                                        'selected' => (int) ($prefill['event_type_term_id'] ?? 0),
                                        'class' => 'w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all appearance-none cursor-pointer',
                                    ]);
                                    ?>
                                </div>
                            </div>
                            
                            <div>
                                <label class="block text-sm font-semibold text-gray-900 mb-1.5"><?php esc_html_e('Tags (Optional)', 'nexdirectory'); ?></label>
                                <input type="text" name="event_tags" placeholder="Comma separated..." value="<?php echo esc_attr((string) ($prefill['event_tags'] ?? '')); ?>" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 shadow-sm outline-none transition-all">
                            </div>

                        </div>
                    </div>

                    <div class="fixed md:sticky bottom-[70px] md:bottom-0 left-0 right-0 z-30 bg-white/95 backdrop-blur-md border-t border-gray-200 p-4 shadow-[0_-4px_6px_-1px_rgba(0,0,0,0.05)] md:rounded-t-2xl mt-8 flex flex-col-reverse sm:flex-row items-center justify-between gap-4">
                        <span class="text-xs text-gray-500 font-medium" x-text="autosaveMessage"></span>
                        
                        <div class="flex items-center gap-3 w-full sm:w-auto">
                            <button type="submit" name="nexdirectory_intent" value="draft" class="flex-1 sm:flex-none px-6 py-3 bg-gray-100 hover:bg-gray-200 text-gray-800 text-sm font-semibold rounded-xl transition-all shadow-sm active:scale-95 border border-gray-200 text-center">
                                <?php esc_html_e('Save Draft', 'nexdirectory'); ?>
                            </button>
                            <button type="submit" name="nexdirectory_intent" value="preview" class="flex-1 sm:flex-none px-6 py-3 bg-white hover:bg-gray-50 text-gray-800 text-sm font-semibold rounded-xl transition-all shadow-sm active:scale-95 border border-gray-200 text-center">
                                <?php /* translators: %s: Placeholder value. */ ?>
                                <?php echo esc_html(sprintf(__('Preview %s', 'nexdirectory'), $singular_label)); ?>
                            </button>
                            <button type="submit" name="nexdirectory_intent" value="pending" :disabled="hasBlockingErrors()" :class="{ 'opacity-50 cursor-not-allowed': hasBlockingErrors() }" class="nexdirectory-force-accent-action flex-1 sm:flex-none px-6 py-3 bg-brand-600 hover:bg-brand-700 text-white text-sm font-bold rounded-xl transition-all shadow-sm active:scale-95 text-center">
                                <?php echo esc_html($submit_primary_cta); ?>
                            </button>
                        </div>
                    </div>

                </form>
            </div>

        </section>
        <?php endif; ?>
<?php
        // Inbox specific variables mapping
        $notifications_title = sanitize_text_field((string) ($notifications_title ?? __('Inbox', 'nexdirectory')));
        $notifications_description = sanitize_text_field((string) ($notifications_description ?? __('View and reply to inbox messages.', 'nexdirectory')));
        $threads = isset($threads) && is_array($threads) ? $threads : [];
        $active_thread_id = isset($active_thread_id) ? absint((int) $active_thread_id) : 0;
        $active_thread = isset($active_thread) && is_array($active_thread) ? $active_thread : [];
        $active_messages = isset($active_messages) && is_array($active_messages) ? $active_messages : [];
        $active_subject = sanitize_text_field((string) ($active_subject ?? ''));
        $active_event_title = sanitize_text_field((string) ($active_event_title ?? ''));
        $active_event_url = isset($active_event_url) ? esc_url((string) $active_event_url) : '';
        $active_other_name = sanitize_text_field((string) ($active_other_name ?? __('Member', 'nexdirectory')));
        $reply_action = isset($reply_action) ? esc_url((string) $reply_action) : esc_url(admin_url('admin-post.php'));
        $reply_nonce = sanitize_text_field((string) ($reply_nonce ?? ''));
        $reply_subject = sanitize_text_field((string) ($reply_subject ?? $active_subject));
        $unread_count = isset($unread_count) ? absint((int) $unread_count) : 0;
        
        // Alpine variable to determine mobile view state
        $has_active_thread = $active_thread_id > 0 ? 'true' : 'false';
        ?>
        <?php if ($show_inbox_tab) : ?>
        <section class="nexdirectory-account-view nexdirectory-account-view--inbox" x-show="activeTab === 'inbox'" x-transition.opacity.duration.300ms x-cloak x-data="{ viewThread: <?php echo esc_attr($has_active_thread); ?> }" @nexdirectory-inbox-open-thread.window="viewThread = true" data-nexdirectory-inbox-section="1">
            
            <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-8'" class="transition-all duration-700 ease-out mb-6">
                <div class="flex items-end justify-between">
                    <div>
                        <h2 class="text-2xl sm:text-3xl font-bold text-gray-900 tracking-tight mb-2"><?php echo esc_html($notifications_title); ?></h2>
                        <p class="text-sm sm:text-base text-gray-500 max-w-2xl"><?php echo esc_html($notifications_description); ?></p>
                    </div>
                    <?php if ($unread_count > 0) : ?>
                        <span class="hidden sm:flex items-center gap-1.5 px-3 py-1 bg-brand-50 text-brand-700 rounded-full text-sm font-bold shadow-sm border border-brand-100">
                            <span class="relative flex h-2.5 w-2.5">
                                <span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-brand-400 opacity-75"></span>
                                <span class="relative inline-flex rounded-full h-2.5 w-2.5 bg-brand-500"></span>
                            </span>
                            <?php /* translators: 1: Placeholder value 1, 2: Placeholder value 2. */ ?>
                            <?php echo esc_html(sprintf(_n('%d New', '%d New', $unread_count, 'nexdirectory'), $unread_count)); ?>
                        </span>
                    <?php endif; ?>
                </div>
            </div>

            <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-8'" class="transition-all duration-700 ease-out delay-75 mb-6">
                <section
                    class="nexdirectory-notification-center nexdirectory-notification-center--page"
                    data-nexdirectory-notification-center="page"
                    aria-labelledby="nexdirectory-account-notifications-title"
                >
                    <div class="nexdirectory-notification-center__header">
                        <div>
                            <p class="nexdirectory-notification-center__eyebrow"><?php esc_html_e('Activity feed', 'nexdirectory'); ?></p>
                            <h3 id="nexdirectory-account-notifications-title"><?php esc_html_e('Latest notifications', 'nexdirectory'); ?></h3>
                            <p class="nexdirectory-meta"><?php esc_html_e('Messages, claims, moderation, RSVPs, waitlist changes and compatible extension notices appear here.', 'nexdirectory'); ?></p>
                        </div>
                        <button type="button" class="nexdirectory-notification-center__mark-all" data-nexdirectory-notification-mark-all disabled>
                            <?php esc_html_e('Mark all as read', 'nexdirectory'); ?>
                        </button>
                    </div>
                    <div
                        class="nexdirectory-notification-center__list"
                        data-nexdirectory-notification-list
                        role="feed"
                        aria-live="polite"
                        aria-busy="true"
                    ></div>
                    <div class="nexdirectory-notification-center__empty" data-nexdirectory-notification-empty hidden>
                        <span class="nexdirectory-notification-center__empty-icon" aria-hidden="true">✓</span>
                        <strong><?php esc_html_e('You are all caught up', 'nexdirectory'); ?></strong>
                        <span><?php esc_html_e('New account activity will appear here.', 'nexdirectory'); ?></span>
                    </div>
                </section>
            </div>

            <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-8'" class="transition-all duration-700 ease-out delay-100 bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden flex flex-col md:flex-row h-[650px] max-h-[75vh]" data-nexdirectory-inbox-shell="1">
                
                <div class="w-full md:w-1/3 md:min-w-[320px] border-r border-gray-100 flex flex-col h-full bg-gray-50/50" :class="viewThread ? 'hidden md:flex' : 'flex'">
                    <div class="p-4 border-b border-gray-100 bg-white shrink-0 flex items-center justify-between">
                        <h3 class="font-bold text-gray-900"><?php esc_html_e('Conversations', 'nexdirectory'); ?></h3>
                        <?php if ($unread_count > 0) : ?>
                            <span class="md:hidden flex items-center justify-center bg-brand-500 text-white text-[10px] font-bold h-5 w-5 rounded-full">
                                <?php echo esc_html($unread_count); ?>
                            </span>
                        <?php endif; ?>
                    </div>
                    
                    <div class="flex-1 overflow-y-auto scrollbar-hide">
                        <?php if (!empty($threads)) : ?>
                            <div class="divide-y divide-gray-100" data-nexdirectory-inbox-thread-list="1">
                                <?php foreach ($threads as $thread_row) : ?>
                                    <?php
                                    $thread_row_id = absint((int) ($thread_row['thread_id'] ?? 0));
                                    $thread_subject = sanitize_text_field((string) ($thread_row['subject'] ?? ''));
                                    if ($thread_subject === '') $thread_subject = sanitize_text_field((string) ($thread_row['event_title'] ?? __('Conversation', 'nexdirectory')));
                                    $thread_url = esc_url((string) ($thread_row['thread_url'] ?? '#'));
                                    $other_name = sanitize_text_field((string) ($thread_row['other_name'] ?? __('Member', 'nexdirectory')));
                                    $last_body = sanitize_text_field((string) ($thread_row['last_body'] ?? ''));
                                    $last_time = sanitize_text_field((string) ($thread_row['last_time'] ?? ''));
                                    $unread = absint((int) ($thread_row['unread_count'] ?? 0));
                                    $is_active = $thread_row_id === $active_thread_id;
                                    ?>
                                    <a href="<?php echo esc_url($thread_url); ?>" data-nexdirectory-inbox-thread-link="1" data-nexdirectory-thread-id="<?php echo esc_attr((string) $thread_row_id); ?>" class="nexdirectory-inbox-thread-item block p-4 transition-colors relative <?php echo $is_active ? 'bg-white border-l-4 border-l-brand-500' : 'bg-transparent border-l-4 border-l-transparent hover:bg-white'; ?>">
                                        <div class="flex justify-between items-start mb-1">
                                            <h4 class="font-bold text-sm text-gray-900 truncate pr-2 <?php echo $unread > 0 ? 'text-black' : ''; ?>"><?php echo esc_html($other_name); ?></h4>
                                            <span class="text-[10px] text-gray-400 whitespace-nowrap shrink-0"><?php echo esc_html($last_time); ?></span>
                                        </div>
                                        <p class="text-xs font-semibold text-gray-800 truncate mb-0.5"><?php echo esc_html($thread_subject); ?></p>
                                        <p class="text-xs text-gray-500 truncate <?php echo $unread > 0 ? 'font-medium text-gray-700' : ''; ?>"><?php echo esc_html($last_body); ?></p>
                                        
                                        <?php if ($unread > 0) : ?>
                                            <div class="absolute right-4 bottom-4 h-2.5 w-2.5 bg-brand-500 rounded-full shadow-sm border border-white"></div>
                                        <?php endif; ?>
                                    </a>
                                <?php endforeach; ?>
                            </div>
                        <?php else : ?>
                            <div class="p-8 text-center flex flex-col items-center justify-center h-full opacity-60">
                                <svg class="w-10 h-10 text-gray-400 mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"></path></svg>
                                <p class="text-sm font-medium text-gray-500"><?php esc_html_e('No messages yet.', 'nexdirectory'); ?></p>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>

                <div class="flex-1 flex flex-col h-full bg-white relative" data-nexdirectory-inbox-panel="1" :class="viewThread ? 'flex' : 'hidden md:flex'">
                    
                    <?php if (!empty($active_thread)) : ?>
                        <div class="p-4 border-b border-gray-100 bg-white shadow-sm z-10 shrink-0 flex items-center gap-3">
                            <button @click="viewThread = false" class="md:hidden p-2 -ml-2 text-gray-500 hover:text-gray-900 bg-gray-50 rounded-full transition-colors active:scale-95">
                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path></svg>
                            </button>
                            <div class="flex-1 min-w-0">
                                <h3 class="font-bold text-gray-900 truncate"><?php echo esc_html($active_subject !== '' ? $active_subject : __('Conversation', 'nexdirectory')); ?></h3>
                                <div class="flex items-center gap-2 mt-0.5 text-xs">
                                    <?php /* translators: %s: Placeholder value. */ ?>
                                    <span class="text-gray-500"><?php echo esc_html(sprintf(__('With %s', 'nexdirectory'), $active_other_name)); ?></span>
                                    <?php if ($active_event_title !== '' && $active_event_url !== '') : ?>
                                        <span class="text-gray-300">•</span>
                                        <a href="<?php echo esc_url($active_event_url); ?>" class="text-brand-600 hover:text-brand-700 font-medium truncate"><?php echo esc_html($active_event_title); ?></a>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>

                        <div class="flex-1 overflow-y-auto p-4 sm:p-6 space-y-5 bg-gray-50/30" id="nexdirectory-chat-scroll-area">
                            <?php foreach ($active_messages as $message_row) : ?>
                                <?php
                                $is_mine = !empty($message_row['is_mine']);
                                $sender_name = sanitize_text_field((string) ($message_row['sender_name'] ?? __('Member', 'nexdirectory')));
                                $body = nexdirectory_sanitize_textarea((string) ($message_row['body'] ?? ''));
                                $attachment_url = esc_url((string) ($message_row['attachment_url'] ?? ''));
                                $created_label = sanitize_text_field((string) ($message_row['created_label'] ?? ''));
                                ?>
                                <div class="flex flex-col <?php echo $is_mine ? 'items-end' : 'items-start'; ?>">
                                    <span class="text-[10px] font-medium text-gray-400 mb-1 px-1">
                                        <?php echo esc_html($is_mine ? __('You', 'nexdirectory') : $sender_name); ?> • <?php echo esc_html($created_label); ?>
                                    </span>
                                    <div class="relative max-w-[85%] sm:max-w-[75%] p-3.5 sm:p-4 text-sm shadow-sm <?php echo $is_mine ? 'bg-gray-900 text-white rounded-2xl rounded-tr-sm' : 'bg-white border border-gray-100 text-gray-800 rounded-2xl rounded-tl-sm'; ?>">
                                        <?php echo nl2br(esc_html($body)); ?>
                                        <?php if ($attachment_url !== '') : ?>
                                            <a href="<?php echo esc_url($attachment_url); ?>" target="_blank" rel="noopener noreferrer" class="mt-3 inline-flex items-center gap-1.5 text-xs font-semibold px-3 py-2 rounded-lg bg-black/10 hover:bg-black/20 transition-colors <?php echo $is_mine ? 'text-white' : 'text-brand-700 bg-brand-50 hover:bg-brand-100'; ?>">
                                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"></path></svg>
                                                <?php esc_html_e('View attachment', 'nexdirectory'); ?>
                                            </a>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>

                        <div class="p-4 border-t border-gray-100 bg-white shrink-0">
                            <form method="post" action="<?php echo esc_url($reply_action); ?>#inbox" class="flex flex-col sm:flex-row gap-3" data-nexdirectory-inbox-reply-form="1">
                                <input type="hidden" name="action" value="nexdirectory_inbox_reply">
                                <input type="hidden" name="thread_id" value="<?php echo esc_attr((string) $active_thread_id); ?>">
                                <input type="hidden" name="nexdirectory_inbox_reply_nonce" value="<?php echo esc_attr($reply_nonce); ?>">
                                <input type="hidden" name="subject" value="<?php echo esc_attr($reply_subject); ?>">
                                <input type="hidden" name="redirect_to" value="<?php echo esc_attr($this->build_inbox_thread_url($active_thread_id, 0)); ?>">
                                
                                <textarea name="message" rows="2" required placeholder="<?php esc_attr_e('Write your reply...', 'nexdirectory'); ?>" class="flex-1 px-4 py-3 bg-gray-50 border border-gray-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-brand-500 focus:bg-white transition-all shadow-sm resize-none"></textarea>
                                <button type="submit" class="nexdirectory-force-accent-action sm:self-end w-full sm:w-auto bg-brand-600 hover:bg-brand-700 active:scale-95 text-white px-6 py-3 rounded-xl text-sm font-bold transition-all shadow-sm flex items-center justify-center gap-2" style="color:#ffffff !important; -webkit-text-fill-color:#ffffff !important;">
                                    <span><?php esc_html_e('Send', 'nexdirectory'); ?></span>
                                    <svg class="w-4 h-4 transform rotate-90" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8"></path></svg>
                                </button>
                            </form>
                        </div>
                        
                        <?php $this->enqueue_local_script_asset('templates-frontend-account-app-php-script-1', 'assets/generated/templates-frontend-account-app-php-script-1.js'); ?>

                    <?php else : ?>
                        <div class="flex-1 flex flex-col items-center justify-center p-8 text-center bg-gray-50/50">
                            <div class="w-16 h-16 bg-white border border-gray-100 text-brand-300 rounded-full flex items-center justify-center mb-4 shadow-sm">
                                <svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"></path></svg>
                            </div>
                            <h3 class="text-lg font-bold text-gray-900"><?php esc_html_e('No conversation selected', 'nexdirectory'); ?></h3>
                            <p class="text-sm text-gray-500 mt-1 max-w-xs"><?php esc_html_e('Choose a conversation from the left to read and reply to messages.', 'nexdirectory'); ?></p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </section>
        <?php endif; ?>
<?php
        // Saved and attending variables.
        $saved_rows = isset($saved_rows) && is_array($saved_rows) ? $saved_rows : [];
        $events_url = isset($events_url) ? (string) $events_url : $this->get_profile_route_default_url('events');
        $attending_title = sanitize_text_field((string) ($ui_labels['attending_title'] ?? __('Events I\'m Attending', 'nexdirectory')));
        $attending_description = sanitize_text_field((string) ($ui_labels['attending_description'] ?? __('Manage your event plans, personal itinerary, and notes in one place.', 'nexdirectory')));
        $attending_empty_heading = sanitize_text_field((string) ($ui_labels['attending_empty_heading'] ?? __('No listings yet', 'nexdirectory')));
        $attending_empty_description = sanitize_text_field((string) ($ui_labels['attending_empty_description'] ?? __('You have not saved any listings yet.', 'nexdirectory')));
        $attending_browse_cta = sanitize_text_field((string) ($ui_labels['attending_browse_cta'] ?? __('Browse Listings', 'nexdirectory')));
        $single_rsvp_cancel = sanitize_text_field((string) ($ui_labels['single_rsvp_cancel'] ?? __('Cancel RSVP', 'nexdirectory')));
        ?>
        <?php if ($show_saved_tab) : ?>
        <section class="nexdirectory-account-view nexdirectory-account-view--saved" x-show="activeTab === 'saved'" x-transition.opacity.duration.300ms x-cloak>
            
            <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-8'" class="transition-all duration-700 ease-out mb-6 sm:mb-8">
                <h2 class="text-2xl sm:text-3xl font-bold text-gray-900 tracking-tight mb-2"><?php echo esc_html($attending_title); ?></h2>
                <p class="text-sm sm:text-base text-gray-500 max-w-2xl"><?php echo esc_html($attending_description); ?></p>
            </div>

            <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-8'" class="transition-all duration-700 ease-out delay-100">
                <?php if (!empty($saved_rows)) : ?>
                    <div class="space-y-4">
                        <?php foreach ($saved_rows as $row) : ?>
                            <?php 
                            $status_class = (string) ($row['status'] ?? '') === 'waitlist' ? 'bg-amber-50 text-amber-700 border-amber-200' : 'bg-green-50 text-green-700 border-green-200'; 
                            $row_post_id = absint((int) ($row['post_id'] ?? 0));
                            $row_sessions = isset($row['sessions']) && is_array($row['sessions']) ? array_values($row['sessions']) : [];
                            $row_map_link = esc_url((string) ($row['map_link'] ?? ''));
                            ?>
                            <div class="bg-white rounded-2xl border border-gray-100 p-5 shadow-sm hover:border-brand-200 transition-colors" x-data="{
                                open: false,
                                noteText: '',
                                savedSessions: [],
                                sessionNotes: {},
                                noteStorageKey: 'nexdirectory_attending_note_<?php echo esc_js((string) $row_post_id . '_u' . (string) get_current_user_id()); ?>',
                                sessionsStorageKey: 'nexdirectory_itinerary_list_<?php echo esc_js((string) $row_post_id . '_u' . (string) get_current_user_id()); ?>',
                                sessionNotesStorageKey: 'nexdirectory_itinerary_notes_<?php echo esc_js((string) $row_post_id . '_u' . (string) get_current_user_id()); ?>',
                                init() {
                                    try {
                                        this.noteText = String(window.localStorage.getItem(this.noteStorageKey) || '');
                                        const parsed = JSON.parse(window.localStorage.getItem(this.sessionsStorageKey) || '[]');
                                        this.savedSessions = Array.isArray(parsed) ? parsed.map((item) => String(item || '').trim()).filter((item) => item !== '') : [];
                                        const parsedNotes = JSON.parse(window.localStorage.getItem(this.sessionNotesStorageKey) || '{}');
                                        this.sessionNotes = parsedNotes && typeof parsedNotes === 'object' ? parsedNotes : {};
                                    } catch (e) {
                                        this.noteText = '';
                                        this.savedSessions = [];
                                        this.sessionNotes = {};
                                    }
                                },
                                saveNote() {
                                    try { window.localStorage.setItem(this.noteStorageKey, this.noteText || ''); } catch (e) {}
                                },
                                persistSessions() {
                                    try { window.localStorage.setItem(this.sessionsStorageKey, JSON.stringify(this.savedSessions)); } catch (e) {}
                                },
                                toggleSession(id) {
                                    const key = String(id || '').trim();
                                    if (!key) return;
                                    const currentItems = Array.isArray(this.savedSessions) ? this.savedSessions : [];
                                    if (currentItems.includes(key)) {
                                        this.savedSessions = currentItems.filter((item) => item !== key);
                                    } else {
                                        this.savedSessions = [...currentItems, key];
                                    }
                                    this.persistSessions();
                                },
                                isSavedSession(id) {
                                    const key = String(id || '').trim();
                                    return key !== '' && this.savedSessions.includes(key);
                                },
                                sessionNote(id) {
                                    const key = String(id || '').trim();
                                    if (!key || !this.sessionNotes || typeof this.sessionNotes !== 'object') return '';
                                    return String(this.sessionNotes[key] || '');
                                }
                            }">
                                
                                <div class="flex flex-col sm:flex-row gap-5 sm:items-center justify-between">
                                    <div class="flex-1 min-w-0">
                                        <div class="flex items-center gap-2 mb-1.5 flex-wrap">
                                            <h3 class="font-bold text-gray-900 text-lg truncate"><a href="<?php echo esc_url((string) ($row['url'] ?? '#')); ?>" class="hover:text-brand-600 transition-colors"><?php echo esc_html((string) ($row['title'] ?? '')); ?></a></h3>
                                            <span class="px-2.5 py-0.5 rounded-full text-[10px] font-bold uppercase tracking-wider border <?php echo esc_attr($status_class); ?>">
                                                <?php echo esc_html((string) ($row['status_label'] ?? '')); ?>
                                            </span>
                                            <?php if (!empty($row['event_status_label'])) : ?>
                                                <span class="px-2.5 py-0.5 rounded-full text-[10px] font-bold uppercase tracking-wider bg-gray-100 text-gray-600 border border-gray-200">
                                                    <?php echo esc_html((string) $row['event_status_label']); ?>
                                                </span>
                                            <?php endif; ?>
                                        </div>

                                        <div class="flex flex-col sm:flex-row sm:items-center gap-1 sm:gap-4 text-sm text-gray-500">
                                            <div class="flex items-center gap-1.5">
                                                <svg class="w-4 h-4 shrink-0 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"></path></svg>
                                                <span class="truncate"><?php echo esc_html((string) ($row['event_date_label'] ?? ($row['start_label'] ?? ''))); ?></span>
                                            </div>
                                            <div class="flex items-center gap-1.5">
                                                <svg class="w-4 h-4 shrink-0 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path></svg>
                                                <span class="truncate max-w-[240px]"><?php echo esc_html((string) ($row['location'] ?? '')); ?></span>
                                            </div>
                                        </div>

                                        <?php if ($ticketing_pro_enabled) : ?>
                                            <?php do_action('nexdirectory_render_extension_saved_item_ticket_details', $this, $row); ?>
                                        <?php endif; ?>
                                    </div>

                                    <div class="flex flex-col sm:flex-row items-stretch sm:items-center gap-2 sm:gap-3 shrink-0">
                                        <button type="button" @click="open = !open" class="nexdirectory-account-action-btn w-full sm:w-36 active:scale-95">
                                            <span x-show="!open"><?php esc_html_e('View details', 'nexdirectory'); ?></span>
                                            <span x-show="open" style="display:none;"><?php esc_html_e('Hide details', 'nexdirectory'); ?></span>
                                        </button>
                                        <a href="<?php echo esc_url((string) ($row['url'] ?? '#')); ?>" class="nexdirectory-account-action-btn w-full sm:w-36 active:scale-95">
                                            <?php /* translators: %s: Placeholder value. */ ?>
                                            <?php echo esc_html(sprintf(__('Open %s', 'nexdirectory'), $singular_label)); ?>
                                        </a>
                                        <?php if ($ticketing_pro_enabled) : ?>
                                            <?php do_action('nexdirectory_render_extension_saved_item_ticket_actions', $this, $row); ?>
                                        <?php endif; ?>
                                        
                                        <?php if (!empty($row['can_cancel'])) : ?>
                                            <form method="post" action="<?php echo esc_url(nexdirectory_add_query_arg('nexdirectory_tab', 'saved', admin_url('admin-post.php'))); ?>#saved" class="w-full sm:w-36">
                                                <input type="hidden" name="action" value="nexdirectory_rsvp_event">
                                                <input type="hidden" name="post_id" value="<?php echo esc_attr((string) ($row['post_id'] ?? '0')); ?>">
                                                <input type="hidden" name="intent" value="leave">
                                                <input type="hidden" name="nexdirectory_rsvp_nonce" value="<?php echo esc_attr((string) ($row['rsvp_nonce'] ?? '')); ?>">
                                                <button type="submit" class="nexdirectory-account-action-btn nexdirectory-account-action-btn-danger w-full active:scale-95">
                                                    <?php echo esc_html($single_rsvp_cancel); ?>
                                                </button>
                                            </form>
                                        <?php endif; ?>
                                    </div>
                                </div>

                                <div x-show="open" x-collapse class="mt-5 pt-5 border-t border-gray-100 space-y-4">
                                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-3 text-sm">
                                        <div class="rounded-xl border border-gray-200 bg-gray-50 p-3">
                                            <p class="text-xs uppercase tracking-wide text-gray-500 font-semibold mb-1"><?php esc_html_e('Event Dates', 'nexdirectory'); ?></p>
                                            <p class="font-semibold text-gray-900"><?php echo esc_html((string) ($row['event_date_label'] ?? ($row['start_label'] ?? ''))); ?></p>
                                        </div>
                                        <div class="rounded-xl border border-gray-200 bg-gray-50 p-3">
                                            <p class="text-xs uppercase tracking-wide text-gray-500 font-semibold mb-1"><?php esc_html_e('Map', 'nexdirectory'); ?></p>
                                            <?php if ($row_map_link !== '') : ?>
                                                <a href="<?php echo esc_url($row_map_link); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" class="font-semibold text-brand-700 hover:text-brand-800"><?php esc_html_e('Open location map', 'nexdirectory'); ?></a>
                                            <?php else : ?>
                                                <p class="text-gray-500"><?php esc_html_e('Map not available for this event.', 'nexdirectory'); ?></p>
                                            <?php endif; ?>
                                        </div>
                                    </div>

                                    <div class="rounded-xl border border-gray-200 bg-white p-4">
                                        <h4 class="font-bold text-gray-900 mb-3"><?php esc_html_e('Your Custom Itinerary', 'nexdirectory'); ?></h4>
                                        <?php if (!empty($row_sessions)) : ?>
                                            <div class="space-y-3">
                                                <?php foreach ($row_sessions as $session_index => $session_row) : ?>
                                                    <?php
                                                    $session_uid = sanitize_key((string) ($session_row['session_uid'] ?? ''));
                                                    if ($session_uid === '') {
                                                        $session_uid = sanitize_key('e' . (string) $row_post_id . '-s' . substr(md5((string) $row_post_id . '|' . (string) $session_index . '|' . (string) ($session_row['title'] ?? '') . '|' . (string) ($session_row['time'] ?? '')), 0, 24));
                                                    }
                                                    $session_title = sanitize_text_field((string) ($session_row['title'] ?? ''));
                                                    $session_time = sanitize_text_field((string) ($session_row['time'] ?? ''));
                                                    $session_day = sanitize_text_field((string) ($session_row['day_label'] ?? ''));
                                                    $session_speaker = sanitize_text_field((string) ($session_row['speaker'] ?? ''));
                                                    $session_location = sanitize_text_field((string) ($session_row['location'] ?? ''));
                                                    ?>
                                                    <article :class="isSavedSession('<?php echo esc_js($session_uid); ?>') ? 'border-l-4 border-l-green-500 border-green-100 bg-green-50/40' : 'border-gray-200 bg-gray-50'" class="rounded-lg border p-3">
                                                        <div class="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-2">
                                                            <div class="min-w-0">
                                                                <p class="font-semibold text-gray-900"><?php echo esc_html($session_title !== '' ? $session_title : __('Session', 'nexdirectory')); ?></p>
                                                                <p class="text-xs text-gray-500"><?php echo esc_html(trim((string) implode(' • ', array_filter([$session_day, $session_time])))); ?></p>
                                                                <?php if ($session_speaker !== '') : ?>
                                                                    <?php /* translators: %s: Placeholder value. */ ?>
                                                                    <p class="text-xs text-gray-500 mt-1"><?php echo esc_html(sprintf(__('Speaker: %s', 'nexdirectory'), $session_speaker)); ?></p>
                                                                <?php endif; ?>
                                                                <?php if ($session_location !== '') : ?>
                                                                    <?php /* translators: %s: Placeholder value. */ ?>
                                                                    <p class="text-xs text-gray-500"><?php echo esc_html(sprintf(__('Location: %s', 'nexdirectory'), $session_location)); ?></p>
                                                                <?php endif; ?>
                                                            </div>
                                                            <button type="button" @click.prevent.stop="toggleSession('<?php echo esc_js($session_uid); ?>')" :class="isSavedSession('<?php echo esc_js($session_uid); ?>') ? 'bg-green-50 text-green-700 border-green-200' : 'bg-white text-gray-700 border-gray-300'" class="inline-flex items-center gap-1 px-3 py-1.5 rounded-md text-xs font-semibold border transition-colors">
                                                                <span x-show="!isSavedSession('<?php echo esc_js($session_uid); ?>')"><?php esc_html_e('Add to list', 'nexdirectory'); ?></span>
                                                                <span x-show="isSavedSession('<?php echo esc_js($session_uid); ?>')" style="display:none;"><?php esc_html_e('Saved', 'nexdirectory'); ?></span>
                                                            </button>
                                                        </div>
                                                        <template x-if="sessionNote('<?php echo esc_js($session_uid); ?>') !== ''">
                                                            <div class="mt-2 p-2.5 rounded-md border border-yellow-200 bg-yellow-50 text-xs text-yellow-900 whitespace-pre-wrap" x-text="sessionNote('<?php echo esc_js($session_uid); ?>')"></div>
                                                        </template>
                                                    </article>
                                                <?php endforeach; ?>
                                            </div>
                                        <?php else : ?>
                                            <p class="text-sm text-gray-500"><?php esc_html_e('No itinerary has been published for this event yet.', 'nexdirectory'); ?></p>
                                        <?php endif; ?>
                                    </div>

                                    <div class="rounded-xl border border-gray-200 bg-white p-4">
                                        <h4 class="font-bold text-gray-900 mb-2"><?php esc_html_e('Personal Notes', 'nexdirectory'); ?></h4>
                                        <textarea x-model="noteText" @blur="saveNote()" rows="3" placeholder="<?php esc_attr_e('Add travel reminders, meetup plans, or your own checklist.', 'nexdirectory'); ?>" class="w-full px-3 py-2.5 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none resize-y"></textarea>
                                        <p class="mt-2 text-xs text-gray-500"><?php esc_html_e('Notes are saved in this browser for quick access.', 'nexdirectory'); ?></p>
                                    </div>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                <?php else : ?>
                    <div class="bg-white rounded-2xl border border-gray-100 p-10 text-center shadow-sm flex flex-col items-center justify-center">
                        <div class="w-16 h-16 bg-brand-50 text-brand-500 rounded-full flex items-center justify-center mb-4 shadow-sm border border-brand-100">
                            <svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z"></path></svg>
                        </div>
                        <h3 class="text-lg font-bold text-gray-900"><?php echo esc_html($attending_empty_heading); ?></h3>
                        <p class="text-gray-500 text-sm mt-1 mb-5 max-w-sm"><?php echo esc_html($attending_empty_description); ?></p>
                        <a href="<?php echo esc_url($events_url); ?>" class="nexdirectory-force-accent-action inline-block bg-gray-900 hover:bg-black text-white px-6 py-2.5 rounded-xl text-sm font-semibold transition-all active:scale-95 shadow-sm">
                            <?php echo esc_html($attending_browse_cta); ?>
                        </a>
                    </div>
                <?php endif; ?>
            </div>

        </section>
        <?php endif; ?>
        </main>

    <nav class="nexdirectory-account-mobile-nav md:hidden fixed bottom-0 w-full bg-white/90 backdrop-blur-md border-t border-gray-200 z-50 pb-safe shadow-[0_-10px_15px_-3px_rgba(0,0,0,0.05)]" aria-label="<?php esc_attr_e('Account navigation', 'nexdirectory'); ?>">
        <div class="flex items-center px-1 overflow-x-auto">
            <?php if ($show_analytics_tab) : ?>
            <button type="button" @click="setTab('analytics')" :aria-current="activeTab === 'analytics' ? 'page' : null" class="flex flex-1 min-w-[48px] flex-col items-center justify-center py-3" :class="activeTab === 'analytics' ? 'text-brand-600' : 'text-gray-500 hover:text-gray-900'">
                <svg class="w-6 h-6 mb-1 transition-transform" :class="activeTab === 'analytics' ? 'scale-110' : ''" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"></path></svg>
                <span class="text-[10px] font-medium">Stats</span>
            </button>
            <?php endif; ?>
            <?php if ($show_listings_tab) : ?>
            <button type="button" @click="setTab('listings')" :aria-current="activeTab === 'listings' ? 'page' : null" class="flex flex-1 min-w-[48px] flex-col items-center justify-center py-3" :class="activeTab === 'listings' ? 'text-brand-600' : 'text-gray-500 hover:text-gray-900'">
                <svg class="w-6 h-6 mb-1 transition-transform" :class="activeTab === 'listings' ? 'scale-110' : ''" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 10h16M4 14h16M4 18h16"></path></svg>
                <span class="text-[10px] font-medium">Listings</span>
            </button>
            <?php endif; ?>
            <?php if ($show_submit_tab) : ?>
            <div class="relative flex flex-1 min-w-[48px] justify-center pb-2">
                <button type="button" @click="setTab('submit')" aria-label="<?php esc_attr_e('Add a new listing', 'nexdirectory'); ?>" :aria-current="activeTab === 'submit' ? 'page' : null" class="nexdirectory-account-mobile-add absolute -top-5 flex items-center justify-center w-14 h-14 bg-brand-500 text-white rounded-full shadow-lg border-4 border-white active:scale-95 transition-transform" :class="activeTab === 'submit' ? 'bg-brand-600' : ''">
                    <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M12 4v16m8-8H4"></path></svg>
                </button>
            </div>
            <?php endif; ?>
            <?php if ($show_inbox_tab) : ?>
            <button type="button" @click="setTab('inbox')" :aria-current="activeTab === 'inbox' ? 'page' : null" class="flex flex-1 min-w-[48px] flex-col items-center justify-center py-3 relative" :class="activeTab === 'inbox' ? 'text-brand-600' : 'text-gray-500 hover:text-gray-900'">
                <svg class="w-6 h-6 mb-1 transition-transform" :class="activeTab === 'inbox' ? 'scale-110' : ''" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path></svg>
                <span class="text-[10px] font-medium">Inbox</span>
            </button>
            <?php endif; ?>
            <?php if ($show_saved_tab) : ?>
            <button type="button" @click="setTab('saved')" aria-label="<?php esc_attr_e('Saved and attending', 'nexdirectory'); ?>" :aria-current="activeTab === 'saved' ? 'page' : null" class="flex flex-1 min-w-[48px] flex-col items-center justify-center py-3" :class="activeTab === 'saved' ? 'text-brand-600' : 'text-gray-500 hover:text-gray-900'">
                <svg class="w-6 h-6 mb-1 transition-transform" :class="activeTab === 'saved' ? 'scale-110' : ''" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z"></path></svg>
                <span class="text-[10px] font-medium"><?php esc_html_e('Saved', 'nexdirectory'); ?></span>
            </button>
            <?php endif; ?>
            <?php if ($show_account_tab) : ?>
            <button type="button" @click="setTab('account')" :aria-current="activeTab === 'account' ? 'page' : null" class="flex flex-1 min-w-[48px] flex-col items-center justify-center py-3" :class="activeTab === 'account' ? 'text-brand-600' : 'text-gray-500 hover:text-gray-900'">
                <svg class="w-6 h-6 mb-1 transition-transform" :class="activeTab === 'account' ? 'scale-110' : ''" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path></svg>
                <span class="text-[10px] font-medium">Profile</span>
            </button>
            <?php endif; ?>
        </div>
    </nav>
</div>
