<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Templates use local variables supplied by the render context.
// phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Template config keys named meta_value are not WP_Query meta queries.
if (!defined('ABSPATH')) {
    exit;
}
// [PRESERVED DYNAMIC VARIABLES]
$hero_layout = in_array((string) ($hero_layout ?? 'cinematic'), ['cinematic', 'compact', 'split', 'minimal', 'immersive', 'spotlight'], true) ? (string) $hero_layout : 'cinematic';
$page_layout = sanitize_key((string) ($page_layout ?? 'modern'));
if (in_array($page_layout, ['balanced', 'compact-aside', 'cards-heavy'], true)) {
    $page_layout = 'fifty-fifty';
}
$page_layout = in_array($page_layout, ['modern', 'single-column', 'editorial', 'fifty-fifty', 'left-sidebar', 'zig-zag', 'full3', 'zen'], true) ? $page_layout : 'modern';
$hero_template_defaults = [
    'container' => 'transition-all duration-700 ease-out relative sm:rounded-2xl overflow-hidden mb-6 sm:mb-8 shadow-sm group bg-gray-900 flex flex-col justify-end min-h-[60vh] sm:min-h-[450px]',
    'image' => 'absolute inset-0 w-full h-full object-cover transition-transform duration-1000 sm:group-hover:scale-105 opacity-80 sm:opacity-100',
    'fallback' => 'absolute inset-0 w-full h-full bg-gradient-to-br from-gray-800 to-gray-950 transition-transform duration-1000 sm:group-hover:scale-105',
    'overlay' => 'absolute inset-0 bg-gradient-to-t from-gray-900 via-gray-900/60 to-transparent',
    'content' => 'relative z-10 p-5 sm:p-8 lg:p-12 w-full mt-auto',
    'kicker' => 'inline-flex items-center px-2.5 py-1 rounded-full bg-brand-500/20 text-white text-xs font-semibold uppercase tracking-wider backdrop-blur-sm border border-brand-500/30',
    'title' => 'text-3xl sm:text-4xl md:text-5xl lg:text-6xl font-bold text-white mb-3 sm:mb-4 leading-tight tracking-tight drop-shadow-md',
    'subtitle' => 'text-gray-300 text-base sm:text-lg max-w-2xl mb-6 leading-relaxed line-clamp-2 sm:line-clamp-none',
    'meta_wrap' => 'flex flex-col sm:flex-row gap-3 sm:gap-6 lg:gap-8 text-white',
    'meta_card' => 'flex items-center bg-white/10 backdrop-blur-md rounded-xl p-3 sm:p-4 border border-white/10 hover:bg-white/20 transition-colors duration-300 cursor-default',
    'meta_icon' => 'p-2.5 sm:p-3 bg-brand-500 rounded-lg mr-3 shadow-sm shrink-0',
    'meta_label' => 'text-[10px] sm:text-xs text-brand-100 font-semibold uppercase tracking-wider',
    'meta_value' => 'font-semibold text-base sm:text-lg',
];
$hero_template = [];
$hero_template_file = __DIR__ . '/hero/' . $hero_layout . '.php';
if (is_readable($hero_template_file)) {
    $hero_template_candidate = require $hero_template_file;
    if (is_array($hero_template_candidate)) {
        $hero_template = $hero_template_candidate;
    }
}
$hero_template = array_merge($hero_template_defaults, $hero_template);

$page_template_defaults = [
    'grid' => 'grid grid-cols-1 lg:grid-cols-3 gap-6 sm:gap-8 px-4 sm:px-0',
    'main' => 'lg:col-span-2 space-y-6 sm:space-y-8',
    'aside' => 'lg:col-span-1 space-y-6',
    'aside_inner' => 'sticky top-24 space-y-6',
];
$page_template = [];
$page_template_file = __DIR__ . '/layout/' . $page_layout . '.php';
if (is_readable($page_template_file)) {
    $page_template_candidate = require $page_template_file;
    if (is_array($page_template_candidate)) {
        $page_template = $page_template_candidate;
    }
}
$page_template = array_merge($page_template_defaults, $page_template);
$video_count = isset($video_cards) && is_array($video_cards) ? count($video_cards) : 0;
$event_gallery_type = isset($event_gallery_type) ? sanitize_key((string) $event_gallery_type) : 'default';
if (!in_array($event_gallery_type, ['default', 'carousel', 'wall'], true)) {
    $event_gallery_type = 'default';
}
$gallery_images_all = isset($gallery_images) && is_array($gallery_images) ? array_values(array_filter(array_map('esc_url', $gallery_images))) : [];
$gallery_images_visible = array_slice($gallery_images_all, 0, 3);
$gallery_hidden_count = max(0, count($gallery_images_all) - 3);
$gallery_items_json = esc_attr(wp_json_encode($gallery_images_all ?: []));
$gallery_button_label = static function ($index) use ($event_title) {
    return sprintf(
        /* translators: 1: Gallery image number. 2: Listing title. */
        __('Open gallery image %1$d for %2$s', 'nexdirectory'),
        ((int) $index) + 1,
        (string) $event_title
    );
};
$gallery_image_alt = static function ($index) use ($event_title) {
    return sprintf(
        /* translators: 1: Gallery image number. 2: Listing title. */
        __('Gallery image %1$d for %2$s', 'nexdirectory'),
        ((int) $index) + 1,
        (string) $event_title
    );
};
$show_event_overview = !isset($show_event_overview) || !empty($show_event_overview);
$ui_labels = isset($ui_labels) && is_array($ui_labels) ? $ui_labels : [];
$single_overview_heading = isset($single_overview_heading) ? (string) $single_overview_heading : (string) ($ui_labels['single_overview_heading'] ?? __('Overview', 'nexdirectory'));
$single_timeline_heading = isset($single_timeline_heading) ? (string) $single_timeline_heading : (string) ($ui_labels['single_timeline_heading'] ?? __('Timeline', 'nexdirectory'));
$single_key_speakers_heading = isset($single_key_speakers_heading) ? (string) $single_key_speakers_heading : (string) ($ui_labels['single_key_speakers_heading'] ?? __('Key Speakers', 'nexdirectory'));
$single_gallery_heading = isset($single_gallery_heading) ? (string) $single_gallery_heading : (string) ($ui_labels['single_gallery_heading'] ?? __('Gallery', 'nexdirectory'));
$single_videos_heading = isset($single_videos_heading) ? (string) $single_videos_heading : (string) ($ui_labels['single_videos_heading'] ?? __('Videos', 'nexdirectory'));
$single_cta_heading = isset($single_cta_heading) ? (string) $single_cta_heading : (string) ($ui_labels['single_cta_heading'] ?? __('Event actions', 'nexdirectory'));
$single_cta_copy = isset($single_cta_copy) ? (string) $single_cta_copy : (string) ($ui_labels['single_cta_copy'] ?? __('Secure your spot before they sell out.', 'nexdirectory'));
$single_visit_site_cta = isset($single_visit_site_cta) ? (string) $single_visit_site_cta : (string) ($ui_labels['single_visit_site_cta'] ?? __('Visit Website', 'nexdirectory'));
$single_report_cta = isset($single_report_cta) ? (string) $single_report_cta : (string) ($ui_labels['single_report_cta'] ?? __('Report Listing', 'nexdirectory'));
$single_report_placeholder = isset($single_report_placeholder) ? (string) $single_report_placeholder : (string) ($ui_labels['single_report_placeholder'] ?? __('Tell us what is wrong with this listing.', 'nexdirectory'));
$single_contact_login = isset($single_contact_login) ? (string) $single_contact_login : (string) ($ui_labels['single_contact_login'] ?? __('Please log in to contact the listing holder.', 'nexdirectory'));
$single_owner_items_cta = isset($single_owner_items_cta) ? (string) $single_owner_items_cta : (string) ($ui_labels['single_owner_items_cta'] ?? __('View all user listings', 'nexdirectory'));
$single_login_rsvp = isset($single_login_rsvp) ? (string) $single_login_rsvp : (string) ($ui_labels['single_login_rsvp'] ?? __('Log In', 'nexdirectory'));
$single_edit_cta = isset($single_edit_cta) ? (string) $single_edit_cta : (string) ($ui_labels['single_edit_cta'] ?? __('Edit Listing', 'nexdirectory'));
$single_calendar_download_cta = isset($single_calendar_download_cta) ? (string) $single_calendar_download_cta : (string) ($ui_labels['single_calendar_download_cta'] ?? __('Download ICS', 'nexdirectory'));
$single_google_calendar_cta = isset($single_google_calendar_cta) ? (string) $single_google_calendar_cta : (string) ($ui_labels['single_google_calendar_cta'] ?? __('Google Calendar', 'nexdirectory'));
$single_status_label = isset($single_status_label) ? (string) $single_status_label : (string) ($ui_labels['single_status_label'] ?? __('Status', 'nexdirectory'));
$single_contact_section_heading = isset($single_contact_section_heading) ? (string) $single_contact_section_heading : (string) ($ui_labels['single_contact_section_heading'] ?? __('Direct Message', 'nexdirectory'));
$single_documents_heading = isset($single_documents_heading) ? (string) $single_documents_heading : (string) ($ui_labels['single_documents_heading'] ?? __('Documents', 'nexdirectory'));
$single_additional_heading = isset($single_additional_heading) ? (string) $single_additional_heading : (string) ($ui_labels['single_additional_heading'] ?? __('Additional Information', 'nexdirectory'));
$single_location_heading = isset($single_location_heading) ? (string) $single_location_heading : (string) ($ui_labels['single_location_heading'] ?? __('Location', 'nexdirectory'));
$single_date_meta_label = isset($single_date_meta_label) ? (string) $single_date_meta_label : (string) ($ui_labels['single_date_meta_label'] ?? __('Date', 'nexdirectory'));
$single_location_meta_label = isset($single_location_meta_label) ? (string) $single_location_meta_label : (string) ($ui_labels['single_location_meta_label'] ?? __('Location', 'nexdirectory'));
$single_open_map_cta = isset($single_open_map_cta) ? (string) $single_open_map_cta : (string) ($ui_labels['single_open_map_cta'] ?? __('Open Map', 'nexdirectory'));
$single_email_inline_label = isset($single_email_inline_label) ? (string) $single_email_inline_label : (string) ($ui_labels['single_email_inline_label'] ?? __('Contact Email', 'nexdirectory'));
$single_phone_inline_label = isset($single_phone_inline_label) ? (string) $single_phone_inline_label : (string) ($ui_labels['single_phone_inline_label'] ?? __('Phone', 'nexdirectory'));
$owner_heading = sanitize_text_field((string) ($ui_labels['owner_singular'] ?? __('Organizer', 'nexdirectory')));
$singular_label = sanitize_text_field((string) ($ui_labels['singular'] ?? __('Listing', 'nexdirectory')));
$plural_label = sanitize_text_field((string) ($ui_labels['plural'] ?? __('Events', 'nexdirectory')));
$market_accept_offers = isset($market_accept_offers) ? (bool) $market_accept_offers : true;
$organizer_id = isset($organizer_id) ? absint((int) $organizer_id) : absint((int) get_post_field('post_author', (int) $post_id));
$can_contact_owner = $organizer_id > 0;
$organizer_member_since = isset($organizer_member_since) ? sanitize_text_field((string) $organizer_member_since) : '';
$organizer_listing_count = isset($organizer_listing_count) ? absint((int) $organizer_listing_count) : 0;
$is_events_profile = isset($is_events_profile) ? (bool) $is_events_profile : ((string) ($ui_labels['is_events_profile'] ?? '1') === '1');
$is_job_profile = isset($is_job_profile) ? (bool) $is_job_profile : ((string) ($ui_labels['is_job_profile'] ?? '0') === '1');
$is_directory_profile = isset($is_directory_profile) ? (bool) $is_directory_profile : ((string) ($ui_labels['is_directory_profile'] ?? '0') === '1');
$is_marketplace_profile = isset($is_marketplace_profile) ? (bool) $is_marketplace_profile : ((string) ($ui_labels['is_marketplace_profile'] ?? '0') === '1');
$owner_event_messages_enabled = !isset($owner_event_messages_enabled) || !empty($owner_event_messages_enabled);
$show_hero_date_card = isset($show_hero_date_card) ? (bool) $show_hero_date_card : !$is_marketplace_profile;
$viewer_logged_in = isset($viewer_logged_in) ? (bool) $viewer_logged_in : is_user_logged_in();
$viewer_user_id = $viewer_logged_in ? get_current_user_id() : 0;
$itinerary_storage_scope = $viewer_user_id > 0 ? ('u' . (string) $viewer_user_id) : 'guest';
$show_rsvp_actions = isset($show_rsvp_actions) ? (bool) $show_rsvp_actions : $is_events_profile;
$show_calendar_actions = isset($show_calendar_actions) ? (bool) $show_calendar_actions : $is_events_profile;
$single_org_mode = !empty($single_org_mode);
$show_organizer_card = !isset($show_organizer_card) || !empty($show_organizer_card);
$ticketing_pro_enabled = function_exists('nexdirectory_is_pro_feature_enabled')
    && nexdirectory_is_pro_feature_enabled('ticketing');
if (!$ticketing_pro_enabled && stripos($single_cta_heading, 'ticket') !== false) {
    $single_cta_heading = $is_events_profile
        ? __('Join this event', 'nexdirectory')
        : __('Next steps', 'nexdirectory');
}
$show_autogenerated_disclaimer = !empty($show_autogenerated_disclaimer);
$autogenerated_disclaimer_text = nexdirectory_sanitize_textarea((string) ($autogenerated_disclaimer_text ?? ''));
$autogenerated_source_url = esc_url((string) ($autogenerated_source_url ?? ''));
$sessions = isset($sessions) && is_array($sessions) ? array_values($sessions) : [];
$key_speakers = isset($key_speakers) && is_array($key_speakers) ? array_values($key_speakers) : [];
$show_timeline = isset($show_timeline) ? (bool) $show_timeline : (($is_events_profile || $is_job_profile) && !empty($sessions));
$show_key_speakers = isset($show_key_speakers) ? (bool) $show_key_speakers : ($is_events_profile && !empty($key_speakers));
$timeline_preview_limit = 3;
$sessions_grouped = [];
$session_group_order = 0;
foreach ($sessions as $session_index => $session_row) {
    if (!is_array($session_row)) {
        continue;
    }
    // Session-level notes are treated as personal itinerary notes; do not expose globally.
    $session_row['notes'] = '';
    $session_key = sanitize_key((string) ($session_row['session_key'] ?? ''));
    if ($session_key === '') {
        $session_key = sanitize_key('s' . substr(md5((string) $post_id . '|' . (string) $session_index . '|' . (string) ($session_row['title'] ?? '') . '|' . (string) ($session_row['start_raw'] ?? '') . '|' . (string) ($session_row['end_raw'] ?? '')), 0, 24));
    }
    $session_row['session_uid'] = sanitize_key('e' . (string) $post_id . '-' . $session_key);
    $day_label = sanitize_text_field((string) ($session_row['day_label'] ?? ''));
    $day_key = sanitize_text_field((string) ($session_row['day_key'] ?? ''));
    if ($day_key === '' && $day_label !== '' && preg_match('/^\d{4}\-\d{2}\-\d{2}$/', $day_label)) {
        $day_key = $day_label;
    }
    if ($day_label === '' && $day_key !== '' && preg_match('/^\d{4}\-\d{2}\-\d{2}$/', $day_key)) {
        $day_ts = strtotime($day_key . ' 00:00:00');
        if ($day_ts) {
            $day_label = wp_date(get_option('date_format'), (int) $day_ts);
        }
    }
    if ($day_label === '') {
        $day_label = __('General Schedule', 'nexdirectory');
    }
    if ($day_key === '') {
        $day_key = 'day-' . ((int) $session_index + 1);
    }
    if (!isset($sessions_grouped[$day_key])) {
        $sessions_grouped[$day_key] = [
            'day_key' => $day_key,
            'day_label' => $day_label,
            'group_order' => $session_group_order,
            'sessions' => [],
        ];
        $session_group_order++;
    }
    $sessions_grouped[$day_key]['sessions'][] = $session_row;
}
$sessions_grouped = array_values($sessions_grouped);
usort($sessions_grouped, static function ($a, $b) {
    $a_ts = isset($a['day_key']) && preg_match('/^\d{4}\-\d{2}\-\d{2}$/', (string) $a['day_key']) ? strtotime((string) $a['day_key'] . ' 00:00:00') : false;
    $b_ts = isset($b['day_key']) && preg_match('/^\d{4}\-\d{2}\-\d{2}$/', (string) $b['day_key']) ? strtotime((string) $b['day_key'] . ' 00:00:00') : false;
    if ($a_ts && $b_ts) {
        return $a_ts <=> $b_ts;
    }
    if ($a_ts) {
        return -1;
    }
    if ($b_ts) {
        return 1;
    }
    return ((int) ($a['group_order'] ?? 0)) <=> ((int) ($b['group_order'] ?? 0));
});
$key_speakers_visible = array_slice($key_speakers, 0, 3);
$has_more_key_speakers = count($key_speakers) > 3;
$default_timeline_heading = $is_events_profile ? __('Event Itinerary', 'nexdirectory') : __('Timeline', 'nexdirectory');
if ($is_events_profile && $single_timeline_heading === __('Timeline', 'nexdirectory')) {
    $single_timeline_heading = $default_timeline_heading;
}
$job_application_deadline = isset($job_application_deadline) ? sanitize_text_field((string) $job_application_deadline) : '';
$share_permalink = (string) get_permalink((int) $post_id);
$share_encoded_url = $share_permalink !== '' ? rawurlencode($share_permalink) : '';
$share_encoded_title = rawurlencode((string) $event_title);
$share_facebook_url = $share_encoded_url !== '' ? 'https://www.facebook.com/sharer/sharer.php?u=' . $share_encoded_url : '';
$share_x_url = $share_encoded_url !== '' ? 'https://twitter.com/intent/tweet?text=' . $share_encoded_title . '&url=' . $share_encoded_url : '';
$share_linkedin_url = $share_encoded_url !== '' ? 'https://www.linkedin.com/sharing/share-offsite/?url=' . $share_encoded_url : '';
$share_whatsapp_url = $share_permalink !== '' ? 'https://wa.me/?text=' . rawurlencode((string) $event_title . ' ' . $share_permalink) : '';
$primary_action_url = esc_url((string) ($primary_action_url ?? ''));
$primary_action_label = sanitize_text_field((string) ($primary_action_label ?? ''));
$primary_action_metric = sanitize_key((string) ($primary_action_metric ?? ''));
$external_click_metric = sanitize_key((string) ($external_click_metric ?? 'click_website'));
$edit_event_url = esc_url((string) ($edit_event_url ?? ''));
$edit_event_is_duplicate = !empty($edit_event_is_duplicate);
$calendar_url = esc_url((string) ($calendar_url ?? ''));
$google_url = esc_url((string) ($google_url ?? ''));
$directory_appointment_url = esc_url((string) ($directory_appointment_url ?? ''));
$directory_whatsapp_url = esc_url((string) ($directory_whatsapp_url ?? ''));
$directory_contact_person = sanitize_text_field((string) ($directory_contact_person ?? ''));
$whos_attending_url = esc_url((string) ($whos_attending_url ?? ''));
$event_webapp_url = esc_url((string) ($event_webapp_url ?? ''));
$event_webapp_enabled = !empty($event_webapp_enabled) && $event_webapp_url !== '';
$single_open_event_app_cta = isset($single_open_event_app_cta) ? (string) $single_open_event_app_cta : (string) ($ui_labels['single_open_event_app_cta'] ?? __('Download App', 'nexdirectory'));
$event_webapp_download_visible = false; // Hidden for MVP; web app entry points will return in a later release.
$directory_book_cta = sanitize_text_field((string) ($ui_labels['single_directory_book_cta'] ?? __('Book Appointment', 'nexdirectory')));
$directory_whatsapp_cta = sanitize_text_field((string) ($ui_labels['single_directory_whatsapp_cta'] ?? __('Message on WhatsApp', 'nexdirectory')));
$map_link = esc_url((string) ($map_link ?? ''));
$map_embed_url = esc_url((string) ($map_embed_url ?? ''));
$map_iframe_title = sprintf(
    /* translators: %s: Venue or listing name. */
    __('Map showing %s', 'nexdirectory'),
    (string) ($venue_label ?? $event_title)
);
$has_primary_action = $primary_action_url !== '' && $primary_action_label !== '';
$primary_cta_metric = $has_primary_action && $primary_action_metric !== '' ? $primary_action_metric : $external_click_metric;
$has_calendar_actions = !empty($show_calendar_actions) && ($calendar_url !== '' || $google_url !== '');
$calendar_primary_url = $google_url !== '' ? $google_url : $calendar_url;
$calendar_primary_label = $google_url !== '' ? $single_google_calendar_cta : $single_calendar_download_cta;
$calendar_secondary_url = '';
$calendar_secondary_label = '';
if ($google_url !== '' && $calendar_url !== '') {
    $calendar_secondary_url = $calendar_url;
    $calendar_secondary_label = $single_calendar_download_cta;
}
$hero_calendar_interactive = $has_calendar_actions && $calendar_primary_url !== '';
$hero_map_interactive = $map_link !== '' && $map_embed_url !== '';
$has_share_actions = $share_facebook_url !== '' || $share_x_url !== '' || $share_linkedin_url !== '' || $share_whatsapp_url !== '';
$owner_display_name = $directory_contact_person !== '' ? $directory_contact_person : sanitize_text_field((string) ($organizer_name ?? ''));

$rsvp_count = isset($rsvp_count) ? absint((int) $rsvp_count) : 0; 

if ($is_job_profile) {
    $owner_heading = __('Posted by', 'nexdirectory');
} elseif ($is_directory_profile) {
    $owner_heading = __('Owner', 'nexdirectory');
} elseif ($is_marketplace_profile) {
    $owner_heading = __('Seller', 'nexdirectory');
}

$home_url = esc_url(home_url('/'));
$events_nav_url = esc_url($this->get_platform_page_url('nexdirectory_page_events_url', $this->get_profile_route_slugs('events'), $this->get_profile_route_default_url('events')));
$workspace_nav_url = esc_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')));
$submit_nav_url = esc_url($this->get_platform_page_url('nexdirectory_page_submit_event_url', $this->get_profile_route_slugs('submit'), $this->get_profile_route_default_url('submit')));
$account_nav_url = esc_url($this->get_platform_page_url('nexdirectory_page_account_url', $this->get_profile_route_slugs('account'), $this->get_profile_route_default_url('account')));
$logout_nav_url = esc_url(wp_logout_url($events_nav_url !== '' ? $events_nav_url : $home_url));
$messages_nav_url = $account_nav_url !== '' ? esc_url(nexdirectory_add_query_arg(['tab' => 'messages'], $account_nav_url)) : '';
$login_url = isset($login_url) ? esc_url((string) $login_url) : '';
if ($login_url === '') {
    $login_url = esc_url(wp_login_url((string) get_permalink((int) $post_id)));
}
$hero_image_url = esc_url((string) ($hero_image ?? ''));
if ($hero_image_url === '') {
    $hero_image_url = esc_url($this->get_default_image_url('hero', (int) $post_id));
}
$hero_image_style_attr = $hero_layout === 'immersive'
    ? 'display:block;width:100%;height:100%;object-fit:cover;'
    : '';

// Extract tags
$clickable_badges = [];
$overview_chip_labels = [];
if (!empty($overview_chips) && is_array($overview_chips)) {
    foreach ($overview_chips as $chip) {
        $chip_label = sanitize_text_field((string) ($chip['label'] ?? ''));
        $chip_url = esc_url((string) ($chip['url'] ?? ''));
        if ($chip_label !== '') {
            $overview_chip_labels[] = $chip_label;
            if (!isset($clickable_badges[$chip_label])) {
                $clickable_badges[$chip_label] = $chip_url;
            }
        }
    }
}
$overview_chip_labels = array_values(array_unique($overview_chip_labels));
$overview_badges = array_slice($overview_chip_labels, 0, 5);
$clickable_badges = array_slice($clickable_badges, 0, 5, true);

$listed_on_label = get_the_date('M j, Y', (int) $post_id);
$updated_on_label = get_the_modified_date('M j, Y', (int) $post_id);
$owner_initials_source = trim((string) ($owner_display_name !== '' ? $owner_display_name : $owner_heading));
$owner_initials_parts = preg_split('/\s+/u', $owner_initials_source) ?: [];
$owner_initials = '';
foreach ($owner_initials_parts as $part) {
    if ($part === '') continue;
    $owner_initials .= strtoupper((string) substr($part, 0, 1));
    if (strlen($owner_initials) >= 2) break;
}
if ($owner_initials === '') $owner_initials = 'OW';
$phone_href = preg_replace('/[^0-9\+]/', '', (string) $contact_phone);
$external_url_full = trim((string) $external_url);
$external_url_display = $external_url_full;
if ($external_url_display !== '') {
    if (function_exists('mb_strlen') && function_exists('mb_substr')) {
        if (mb_strlen($external_url_display) > 50) {
            $external_url_display = mb_substr($external_url_display, 0, 47) . '...';
        }
    } elseif (strlen($external_url_display) > 50) {
        $external_url_display = substr($external_url_display, 0, 47) . '...';
    }
}
$current_user_id = get_current_user_id();
$can_message_owner = $viewer_logged_in && $organizer_id > 0 && $current_user_id > 0 && $organizer_id !== $current_user_id;
$is_listing_owner = $viewer_logged_in && $organizer_id > 0 && $current_user_id > 0 && $organizer_id === $current_user_id;
$message_targets_admin = $viewer_logged_in && $is_events_profile;
/* translators: %s: Placeholder value. */
$message_default_subject = sprintf(__('Message about %s', 'nexdirectory'), (string) $event_title);
$waitlist_count = isset($waitlist_count) ? absint((int) $waitlist_count) : 0;
$message_button_mode = 'none';
$message_button_url = '';
$message_button_label = __('Message', 'nexdirectory');
$message_button_target = '';
$message_button_rel = '';
$claimable = !empty($claimable);
$claim_status = sanitize_key((string) ($claim_status ?? ''));
$claim_url = esc_url((string) ($claim_url ?? ''));
if ($claim_status === '' || !in_array($claim_status, ['pending', 'approved', 'rejected'], true)) {
    $claim_status = '';
}
if ($is_events_profile && !$owner_event_messages_enabled) {
    $message_button_mode = 'none';
} elseif ($message_targets_admin) {
    $message_button_mode = 'modal';
    $message_button_label = __('Message Admin', 'nexdirectory');
} elseif ($can_message_owner) {
    $message_button_mode = 'modal';
} elseif (!$viewer_logged_in && $login_url !== '') {
    $message_button_mode = 'link';
    $message_button_url = esc_url((string) $login_url);
    $message_button_label = __('Log In to Message', 'nexdirectory');
} elseif ($directory_whatsapp_url !== '' && !$is_events_profile) {
    $message_button_mode = 'link';
    $message_button_url = $directory_whatsapp_url;
    $message_button_label = $directory_whatsapp_cta !== '' ? $directory_whatsapp_cta : __('Message on WhatsApp', 'nexdirectory');
    $message_button_target = '_blank';
    $message_button_rel = 'noopener noreferrer nofollow ugc';
} elseif (is_email((string) $contact_email) && !$is_events_profile) {
    $message_button_mode = 'link';
    $message_button_url = 'mailto:' . sanitize_email((string) $contact_email) . '?subject=' . rawurlencode($message_default_subject);
}
$has_message_button = $message_button_mode === 'modal' || ($message_button_mode === 'link' && $message_button_url !== '');
$show_edit_event_button = $edit_event_url !== '' && ($edit_event_is_duplicate || $is_listing_owner || current_user_can('edit_post', (int) $post_id));
$edit_event_button_label = $edit_event_is_duplicate
    ? __('Create Editable Copy', 'nexdirectory')
    : ($is_events_profile ? __('Edit Event', 'nexdirectory') : $single_edit_cta);
$primary_cta_text = $single_visit_site_cta;
if ($show_rsvp_actions && $viewer_logged_in) {
    $primary_cta_text = (string) ($rsvp_button_label ?? __('RSVP', 'nexdirectory'));
} elseif ($show_rsvp_actions && !$viewer_logged_in) {
    $primary_cta_text = $single_login_rsvp;
} elseif ($has_primary_action && $primary_action_label !== '') {
    $primary_cta_text = $primary_action_label;
}
?>

<div class="nexdirectory-single-app-root overflow-x-hidden bg-gray-50 text-gray-800 font-sans antialiased selection:bg-brand-100 selection:text-brand-700 pb-44 md:pb-8 min-h-screen"
     data-nexdirectory-event-id="<?php echo esc_attr((string) $post_id); ?>"
     data-nexdirectory-track-view="1"
     data-nexdirectory-hero-layout="<?php echo esc_attr($hero_layout); ?>"
     data-nexdirectory-page-layout="<?php echo esc_attr($page_layout); ?>"
     x-data="{
        showMapModal: false,
        showCalendarModal: false,
        showItineraryModal: false,
        itineraryModalDay: '',
        showSpeakersModal: false,
        messageModalOpen: false,
        itineraryNoteModalOpen: false,
        itineraryActiveSessionId: '',
        itineraryNoteText: '',
        itinerarySavedItems: [],
        itineraryNotesMap: {},
        viewerLoggedIn: <?php echo $viewer_logged_in ? 'true' : 'false'; ?>,
        itineraryListStorageKey: 'nexdirectory_itinerary_list_<?php echo esc_js((string) $post_id . '_' . $itinerary_storage_scope); ?>',
        itineraryNotesStorageKey: 'nexdirectory_itinerary_notes_<?php echo esc_js((string) $post_id . '_' . $itinerary_storage_scope); ?>',
        init() {
          if (!this.viewerLoggedIn) {
            this.itinerarySavedItems = [];
            this.itineraryNotesMap = {};
            return;
          }
          try {
            const savedItemsRaw = window.localStorage.getItem(this.itineraryListStorageKey) || '[]';
            const parsedSavedItems = JSON.parse(savedItemsRaw);
            this.itinerarySavedItems = Array.isArray(parsedSavedItems)
              ? Array.from(new Set(parsedSavedItems.map(function (item) {
                  return String(item || '').trim();
                }).filter(function (item) {
                  return item !== '';
                })))
              : [];
          } catch (_err) {
            this.itinerarySavedItems = [];
          }
          try {
            const notesRaw = window.localStorage.getItem(this.itineraryNotesStorageKey) || '{}';
            const parsedNotes = JSON.parse(notesRaw);
            this.itineraryNotesMap = parsedNotes && typeof parsedNotes === 'object' ? parsedNotes : {};
          } catch (_err) {
            this.itineraryNotesMap = {};
          }
        },
        persistItineraryState() {
          if (!this.viewerLoggedIn) {
            return;
          }
          try {
            window.localStorage.setItem(this.itineraryListStorageKey, JSON.stringify(this.itinerarySavedItems || []));
            window.localStorage.setItem(this.itineraryNotesStorageKey, JSON.stringify(this.itineraryNotesMap || {}));
          } catch (_err) {
            // ignore storage errors
          }
        },
        toggleItinerarySave(sessionId) {
          const key = String(sessionId || '').trim();
          if (!key) {
            return;
          }
          if (!this.viewerLoggedIn) {
            return;
          }
          const currentItems = Array.isArray(this.itinerarySavedItems) ? this.itinerarySavedItems : [];
          if (currentItems.includes(key)) {
            this.itinerarySavedItems = currentItems.filter(function (item) { return item !== key; });
          } else {
            this.itinerarySavedItems = [...currentItems, key];
          }
          this.persistItineraryState();
        },
        isItinerarySaved(sessionId) {
          const key = String(sessionId || '').trim();
          return this.viewerLoggedIn && key !== '' && this.itinerarySavedItems.includes(key);
        },
        getItineraryNote(sessionId) {
          const key = String(sessionId || '').trim();
          if (!this.viewerLoggedIn || !key || !this.itineraryNotesMap || typeof this.itineraryNotesMap !== 'object') {
            return '';
          }
          return String(this.itineraryNotesMap[key] || '');
        },
        hasItineraryNote(sessionId) {
          return this.getItineraryNote(sessionId).trim() !== '';
        },
        openItineraryNoteModal(sessionId) {
          const key = String(sessionId || '').trim();
          if (!this.viewerLoggedIn || !key) {
            return;
          }
          this.itineraryActiveSessionId = key;
          this.itineraryNoteText = this.getItineraryNote(key);
          this.itineraryNoteModalOpen = true;
        },
        closeItineraryNoteModal() {
          this.itineraryNoteModalOpen = false;
          this.itineraryActiveSessionId = '';
          this.itineraryNoteText = '';
        },
        saveItineraryNote() {
          if (!this.viewerLoggedIn) {
            this.closeItineraryNoteModal();
            return;
          }
          const key = String(this.itineraryActiveSessionId || '').trim();
          if (!key) {
            this.closeItineraryNoteModal();
            return;
          }
          const cleanText = String(this.itineraryNoteText || '').trim();
          if (cleanText === '') {
            if (this.itineraryNotesMap && typeof this.itineraryNotesMap === 'object') {
              delete this.itineraryNotesMap[key];
            }
          } else {
            this.itineraryNotesMap[key] = cleanText;
          }
          this.persistItineraryState();
          this.closeItineraryNoteModal();
        }
      }">

    <main class="max-w-7xl mx-auto px-0 sm:px-6 lg:px-8 py-0 sm:py-8 pb-24 md:pb-8">
        <?php if ($show_edit_event_button) : ?>
            <div class="sticky top-0 z-50 md:hidden px-4 pt-3 pb-2 bg-white/90 backdrop-blur-xl border-b border-gray-200/70 shadow-sm">
                <a href="<?php echo esc_url((string) $edit_event_url); ?>" class="w-full flex items-center justify-center gap-2 bg-brand-600 hover:bg-brand-700 active:bg-brand-800 active:scale-95 text-white text-sm font-bold rounded-xl py-3 transition-all duration-200 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="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.828L12.828 14H9v-3.828l8.586-8.586z"></path></svg>
                    <span><?php echo esc_html((string) $edit_event_button_label); ?></span>
                </a>
            </div>
        <?php endif; ?>
        
        <?php
        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Breadcrumb markup is sanitized by esc_nexdirectory_plugin_markup() against the plugin-owned allow-list.
        echo esc_nexdirectory_plugin_markup((string) $this->render_platform_breadcrumbs(
            (string) $event_title,
            $plural_label,
            $events_nav_url !== '' ? $events_nav_url : esc_url(home_url('/events/'))
        ));
        ?>

        <?php if ($show_autogenerated_disclaimer && $autogenerated_disclaimer_text !== '') : ?>
            <section
                data-nexdirectory-autogenerated-disclaimer="1"
                data-nexdirectory-event-id="<?php echo esc_attr((string) $post_id); ?>"
                data-nexdirectory-disclaimer-message="<?php echo esc_attr((string) $autogenerated_disclaimer_text); ?>"
                data-nexdirectory-disclaimer-source-url="<?php echo esc_url($autogenerated_source_url); ?>"
                hidden
                aria-hidden="true"
            >
                <noscript>
                    <div class="mx-4 sm:mx-0 mb-5 sm:mb-6 rounded-xl border border-amber-200 bg-amber-50/90 text-amber-900 shadow-sm px-4 py-3 sm:px-5 sm:py-4">
                        <p class="text-xs font-semibold uppercase tracking-wide text-amber-700"><?php esc_html_e('Imported Listing Notice', 'nexdirectory'); ?></p>
                        <p class="mt-1 text-sm leading-relaxed"><?php echo esc_html($autogenerated_disclaimer_text); ?></p>
                        <?php if ($autogenerated_source_url !== '') : ?>
                            <p class="mt-2 text-xs sm:text-sm">
                                <a
                                    href="<?php echo esc_url($autogenerated_source_url); ?>"
                                    target="_blank"
                                    rel="noopener noreferrer nofollow ugc"
                                    class="font-medium underline decoration-amber-400 underline-offset-2 hover:text-amber-800"
                                >
                                    <?php esc_html_e('Source', 'nexdirectory'); ?>
                                </a>
                            </p>
                        <?php endif; ?>
                    </div>
                </noscript>
            </section>
        <?php endif; ?>

        <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 scale-100' : 'opacity-0 scale-[0.98]'" class="<?php echo esc_attr((string) $hero_template['container']); ?>">
            <?php if ($hero_image_url !== '') : ?>
                <img src="<?php echo esc_url($hero_image_url); ?>" alt="<?php echo esc_attr((string) $event_title); ?>" class="<?php echo esc_attr((string) $hero_template['image']); ?>"<?php if ($hero_image_style_attr !== '') : ?> style="<?php echo esc_attr($hero_image_style_attr); ?>"<?php endif; ?>>
            <?php else : ?>
                <div class="<?php echo esc_attr((string) $hero_template['fallback']); ?>"></div>
            <?php endif; ?>
            
            <div class="<?php echo esc_attr((string) $hero_template['overlay']); ?>"></div>
            
            <div class="<?php echo esc_attr((string) $hero_template['content']); ?>">
                <div class="flex flex-wrap items-center gap-2 mb-3">
                    <span class="<?php echo esc_attr((string) $hero_template['kicker']); ?> nexdirectory-single-hero-kicker" style="color:#ffffff;">
                        <?php echo esc_html((string) ($hero_kicker_text ?? ($this->get_white_label_brand_name() . ' ' . $singular_label))); ?>
                    </span>
                    <?php if ($status_text !== '') : ?>
                        <span class="inline-flex sm:hidden items-center px-2.5 py-1 rounded-full bg-green-500/20 text-green-300 text-xs font-semibold uppercase tracking-wider backdrop-blur-sm border border-green-500/30">
                            <?php echo esc_html((string) $status_text); ?>
                        </span>
                    <?php endif; ?>
                </div>
                
                <h1 class="<?php echo esc_attr((string) $hero_template['title']); ?>">
                    <?php echo esc_html((string) $event_title); ?>
                </h1>
                
                <?php if ($event_subtitle !== '') : ?>
                    <p class="<?php echo esc_attr((string) $hero_template['subtitle']); ?>">
                        <?php echo esc_html((string) $event_subtitle); ?>
                    </p>
                <?php endif; ?>
                
                <div class="<?php echo esc_attr((string) $hero_template['meta_wrap']); ?>">
                    <?php if ($show_hero_date_card && !empty($hero_date_label)) : ?>
                        <?php if ($hero_calendar_interactive) : ?>
                            <button type="button" @click.prevent="showCalendarModal = true" class="<?php echo esc_attr((string) $hero_template['meta_card']); ?> focus:outline-none focus:ring-2 focus:ring-white/60">
                                <div class="<?php echo esc_attr((string) $hero_template['meta_icon']); ?>">
                                    <svg class="w-5 h-5 sm:w-6 sm:h-6 text-white" 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>
                                </div>
                                <div class="text-left">
                                    <p class="<?php echo esc_attr((string) $hero_template['meta_label']); ?>"><?php echo esc_html($single_date_meta_label); ?></p>
                                    <p class="<?php echo esc_attr((string) $hero_template['meta_value']); ?>"><?php echo esc_html((string) $hero_date_label); ?></p>
                                </div>
                            </button>
                        <?php else : ?>
                            <div class="<?php echo esc_attr((string) $hero_template['meta_card']); ?>">
                                <div class="<?php echo esc_attr((string) $hero_template['meta_icon']); ?>">
                                    <svg class="w-5 h-5 sm:w-6 sm:h-6 text-white" 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>
                                </div>
                                <div>
                                    <p class="<?php echo esc_attr((string) $hero_template['meta_label']); ?>"><?php echo esc_html($single_date_meta_label); ?></p>
                                    <p class="<?php echo esc_attr((string) $hero_template['meta_value']); ?>"><?php echo esc_html((string) $hero_date_label); ?></p>
                                </div>
                            </div>
                        <?php endif; ?>
                    <?php endif; ?>
                    
                    <?php if (!empty($hero_location_label)) : ?>
                        <?php if ($hero_map_interactive) : ?>
                            <button type="button" @click.prevent="showMapModal = true" class="<?php echo esc_attr((string) $hero_template['meta_card']); ?> focus:outline-none focus:ring-2 focus:ring-white/60">
                                <div class="<?php echo esc_attr((string) $hero_template['meta_icon']); ?>">
                                    <svg class="w-5 h-5 sm:w-6 sm:h-6 text-white" 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>
                                </div>
                                <div class="truncate text-left">
                                    <p class="<?php echo esc_attr((string) $hero_template['meta_label']); ?>"><?php echo esc_html($single_location_meta_label); ?></p>
                                    <p class="<?php echo esc_attr((string) $hero_template['meta_value'] . ' truncate'); ?>"><?php echo esc_html((string) $hero_location_label); ?></p>
                                </div>
                            </button>
                        <?php else : ?>
                            <div class="<?php echo esc_attr((string) $hero_template['meta_card']); ?>">
                                <div class="<?php echo esc_attr((string) $hero_template['meta_icon']); ?>">
                                    <svg class="w-5 h-5 sm:w-6 sm:h-6 text-white" 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>
                                </div>
                                <div class="truncate">
                                    <p class="<?php echo esc_attr((string) $hero_template['meta_label']); ?>"><?php echo esc_html($single_location_meta_label); ?></p>
                                    <p class="<?php echo esc_attr((string) $hero_template['meta_value'] . ' truncate'); ?>"><?php echo esc_html((string) $hero_location_label); ?></p>
                                </div>
                            </div>
                        <?php endif; ?>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <div class="<?php echo esc_attr((string) $page_template['grid']); ?>">
            
            <div class="<?php echo esc_attr((string) $page_template['main']); ?>">
                
                <?php if ($show_event_overview) : ?>
                    <section 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">
                        <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">
                            <h2 class="text-lg sm:text-xl 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="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
                                <?php echo esc_html($single_overview_heading); ?>
                            </h2>
                            <div class="hidden sm:flex gap-2">
                                <?php if ($status_text !== '') : ?>
                                    <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800 border border-green-200"><?php echo esc_html((string) $status_text); ?></span>
                                <?php endif; ?>
                                <?php if (!empty($overview_badges[0])) : ?>
                                    <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-brand-100 text-brand-800 border border-brand-200"><?php echo esc_html((string) $overview_badges[0]); ?></span>
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="p-5 sm:p-6">
                            <div class="text-gray-600 text-sm sm:text-base leading-relaxed mb-6 prose max-w-none">
                                <?php echo wp_kses_post((string) $content_html); ?>
                            </div>
                            
                            <?php if (!empty($clickable_badges)) : ?>
                                <div class="flex overflow-x-auto scrollbar-hide gap-2 mb-8 -mx-5 px-5 sm:mx-0 sm:px-0 sm:flex-wrap">
                                    <?php foreach ($clickable_badges as $badge_label => $badge_url) : ?>
                                        <?php if ($badge_url !== '') : ?>
                                            <a href="<?php echo esc_url($badge_url); ?>" class="shrink-0 px-3 py-1.5 sm:py-1 bg-brand-50 text-brand-700 hover:bg-brand-100 active:scale-95 text-xs font-medium rounded-full border border-brand-100 transition-all duration-200"><?php echo esc_html($badge_label); ?></a>
                                        <?php else : ?>
                                            <span class="shrink-0 px-3 py-1.5 sm:py-1 bg-brand-50 text-brand-700 text-xs font-medium rounded-full border border-brand-100"><?php echo esc_html($badge_label); ?></span>
                                        <?php endif; ?>
                                    <?php endforeach; ?>
                                </div>
                            <?php endif; ?>

                            <div class="grid grid-cols-2 md:grid-cols-4 gap-y-6 gap-x-4 sm:gap-x-8 text-sm bg-gray-50 rounded-xl p-4 sm:p-5 border border-gray-100 mb-6 sm:mb-0 hover:border-brand-200 transition-colors duration-300 cursor-default">
                                <div>
                                    <p class="text-gray-500 font-medium text-[10px] sm:text-xs uppercase tracking-wider mb-1"><?php esc_html_e('Listing ID', 'nexdirectory'); ?></p>
                                    <p class="font-semibold text-gray-900">#<?php echo esc_html((string) $post_id); ?></p>
                                </div>
                                <div>
                                    <p class="text-gray-500 font-medium text-[10px] sm:text-xs uppercase tracking-wider mb-1"><?php esc_html_e('Listed On', 'nexdirectory'); ?></p>
                                    <p class="font-semibold text-gray-900"><?php echo esc_html((string) $listed_on_label); ?></p>
                                </div>
                                <div>
                                    <p class="text-gray-500 font-medium text-[10px] sm:text-xs uppercase tracking-wider mb-1"><?php esc_html_e('Updated', 'nexdirectory'); ?></p>
                                    <p class="font-semibold text-gray-900"><?php echo esc_html((string) $updated_on_label); ?></p>
                                </div>
                                <div>
                                    <p class="text-gray-500 font-medium text-[10px] sm:text-xs uppercase tracking-wider mb-1"><?php esc_html_e('Categories', 'nexdirectory'); ?></p>
                                    <p class="font-semibold text-gray-900 truncate"><?php echo esc_html(!empty($overview_badges) ? implode(', ', $overview_badges) : __('General', 'nexdirectory')); ?></p>
                                </div>
                            </div>
                            
                            <?php if ($contact_email !== '' || $contact_phone !== '' || $external_url !== '') : ?>
                                <div class="pt-0 sm:pt-6 sm:border-t border-gray-100 grid grid-cols-1 sm:grid-cols-2 gap-4 mt-6">
                                    <?php if ($contact_phone !== '') : ?>
                                        <div class="flex items-start gap-3 bg-white border sm:border-0 border-gray-100 p-3 sm:p-0 rounded-xl sm:rounded-none shadow-sm sm:shadow-none hover:bg-gray-50 transition-colors sm:hover:bg-transparent duration-200">
                                            <div class="p-2 bg-brand-50 sm:bg-gray-50 rounded-lg text-brand-500 sm:text-gray-400 shrink-0">
                                                <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="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"></path></svg>
                                            </div>
                                            <div x-data="{ show: false }" class="flex-1">
                                                <p class="text-gray-400 font-medium text-xs uppercase tracking-wider mb-0.5"><?php echo esc_html($single_phone_inline_label); ?></p>
                                                <button type="button" @click="show = true" x-show="!show" class="text-brand-600 font-medium hover:text-brand-700 transition-colors text-sm sm:text-base py-1 active:scale-95 origin-left"><?php esc_html_e('Reveal Number', 'nexdirectory'); ?></button>
                                                <?php if ($phone_href !== '') : ?>
                                                    <a x-show="show" x-cloak href="<?php echo esc_url('tel:' . (string) $phone_href); ?>" class="font-medium text-gray-900 hover:text-brand-600 transition-colors block text-sm sm:text-base py-1"><?php echo esc_html((string) $contact_phone); ?></a>
                                                <?php else: ?>
                                                    <span x-show="show" x-cloak class="font-medium text-gray-900 block text-sm sm:text-base py-1"><?php echo esc_html((string) $contact_phone); ?></span>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    <?php endif; ?>
                                    
                                    <?php if ($contact_email !== '') : ?>
                                        <div class="flex items-start gap-3 bg-white border sm:border-0 border-gray-100 p-3 sm:p-0 rounded-xl sm:rounded-none shadow-sm sm:shadow-none hover:bg-gray-50 transition-colors sm:hover:bg-transparent duration-200">
                                            <div class="p-2 bg-brand-50 sm:bg-gray-50 rounded-lg text-brand-500 sm:text-gray-400 shrink-0">
                                                <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="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>
                                            </div>
                                            <div class="flex-1 overflow-hidden">
                                                <p class="text-gray-400 font-medium text-xs uppercase tracking-wider mb-0.5"><?php echo esc_html($single_email_inline_label); ?></p>
                                                <?php if (is_email((string) $contact_email)) : ?>
                                                    <a href="mailto:<?php echo esc_attr(sanitize_email((string) $contact_email)); ?>" class="font-medium text-brand-600 hover:text-brand-700 transition-colors truncate block text-sm sm:text-base py-1"><?php echo esc_html((string) $contact_email); ?></a>
                                                <?php else : ?>
                                                    <p class="font-medium text-gray-900 block text-sm sm:text-base py-1"><?php echo esc_html((string) $contact_email); ?></p>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    <?php endif; ?>
                                    
                                    <?php if ($external_url !== '') : ?>
                                        <div class="sm:col-span-2 flex items-start gap-3 bg-white border sm:border-0 border-gray-100 p-3 sm:p-0 rounded-xl sm:rounded-none shadow-sm sm:shadow-none hover:bg-gray-50 transition-colors sm:hover:bg-transparent duration-200">
                                            <div class="p-2 bg-brand-50 sm:bg-gray-50 rounded-lg text-brand-500 sm:text-gray-400 shrink-0">
                                                <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="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"></path></svg>
                                            </div>
                                            <div class="flex-1 overflow-hidden">
                                                <p class="text-gray-400 font-medium text-xs uppercase tracking-wider mb-0.5"><?php esc_html_e('Website', 'nexdirectory'); ?></p>
                                                <a href="<?php echo esc_url((string) $external_url_full); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" title="<?php echo esc_attr((string) $external_url_full); ?>" class="font-medium text-brand-600 hover:text-brand-700 transition-colors truncate block text-sm sm:text-base py-1"><?php echo esc_html((string) $external_url_display); ?></a>
                                            </div>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            <?php endif; ?>
                        </div>
                    </section>
                <?php endif; ?>

                <?php if (!empty($custom_fields_display)) : ?>
                    <section x-data="{ shown: false, expanded: true }" 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-150 bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden">
                        <button type="button" @click="expanded = !expanded" :aria-expanded="expanded ? 'true' : 'false'" aria-controls="nexdirectory-additional-information-<?php echo esc_attr((string) $post_id); ?>" class="w-full border-b border-gray-100 px-5 sm:px-6 py-4 sm:py-5 bg-gray-50/50 flex items-center justify-between transition-colors hover:bg-gray-100/50 focus:outline-none">
                            <h2 class="text-lg sm:text-xl 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 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
                                <?php echo esc_html($single_additional_heading); ?>
                            </h2>
                            <svg class="w-5 h-5 text-gray-400 transform transition-transform duration-300" :class="expanded ? 'rotate-180' : ''" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>
                        </button>
                        <div id="nexdirectory-additional-information-<?php echo esc_attr((string) $post_id); ?>" x-show="expanded" x-collapse class="p-5 sm:p-6">
                            <div class="space-y-3 sm:space-y-4">
                                <?php foreach ($custom_fields_display as $index => $row) : ?>
                                    <?php
                                    $render_type = sanitize_key((string) ($row['render_type'] ?? 'text'));
                                    $label = sanitize_text_field((string) ($row['label'] ?? ''));
                                    ?>
                                    <div class="flex flex-col sm:flex-row sm:items-center justify-between p-3 sm:p-4 bg-gray-50 rounded-xl border border-gray-100 hover:border-brand-200 transition-colors duration-200">
                                        <span class="text-xs sm:text-sm font-medium text-gray-500 mb-1 sm:mb-0"><?php echo esc_html((string) $label); ?></span>
                                        
                                        <?php if ($render_type === 'html') : ?>
                                            <span class="text-sm font-semibold text-gray-900 text-right"><?php echo wp_kses_post((string) ($row['value'] ?? '')); ?></span>
                                        <?php elseif ($render_type === 'link') : ?>
                                            <a target="_blank" rel="noopener noreferrer nofollow ugc" href="<?php echo esc_url((string) ($row['url'] ?? '')); ?>" class="text-sm font-medium text-brand-600 hover:text-brand-700 truncate"><?php echo esc_html((string) ($row['value'] ?? '')); ?></a>
                                        <?php elseif ($render_type === 'image') : ?>
                                            <img src="<?php echo esc_url((string) ($row['value'] ?? '')); ?>" alt="<?php echo esc_attr((string) $label); ?>" class="max-h-16 object-cover rounded-lg shadow-sm">
                                        <?php elseif ($render_type === 'gallery') : ?>
                                            <div class="flex gap-2 justify-end overflow-x-auto scrollbar-hide">
                                                <?php foreach ((array) ($row['gallery'] ?? []) as $gallery_item) : ?>
                                                    <img src="<?php echo esc_url((string) $gallery_item); ?>" alt="<?php echo esc_attr((string) $label); ?>" class="h-10 w-10 object-cover rounded-md shadow-sm border border-gray-200 shrink-0">
                                                <?php endforeach; ?>
                                            </div>
                                        <?php else : ?>
                                            <span class="text-sm font-semibold text-gray-900"><?php echo esc_html((string) ($row['value'] ?? '')); ?></span>
                                        <?php endif; ?>
                                    </div>
                                <?php endforeach; ?>
                            </div>
                        </div>
                    </section>
                <?php endif; ?>

                <?php if ($show_timeline && !empty($sessions_grouped)) : ?>
                    <section 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-200 bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden">
                        <div class="border-b border-gray-100 px-5 sm:px-6 py-4 sm:py-5 bg-gray-50/50">
                            <h2 class="text-lg sm:text-xl 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 echo esc_html($single_timeline_heading); ?>
                            </h2>
                        </div>
                        <div class="p-5 sm:p-6">
                            <div class="space-y-6">
                                <?php foreach ($sessions_grouped as $day_group_index => $day_group) : ?>
                                    <?php
                                    $day_key = sanitize_text_field((string) ($day_group['day_key'] ?? ('day-' . ((int) $day_group_index + 1))));
                                    $day_label = sanitize_text_field((string) ($day_group['day_label'] ?? __('Schedule', 'nexdirectory')));
                                    $day_sessions = isset($day_group['sessions']) && is_array($day_group['sessions']) ? array_values($day_group['sessions']) : [];
                                    $preview_sessions = array_slice($day_sessions, 0, $timeline_preview_limit);
                                    $has_more_day_sessions = count($day_sessions) > $timeline_preview_limit;
                                    ?>
                                    <article class="border border-gray-100 rounded-2xl p-4 sm:p-5 bg-gray-50/40">
                                        <div class="flex items-center justify-between gap-3 mb-4">
                                            <h3 class="text-sm sm:text-base font-bold text-gray-900"><?php echo esc_html($day_label); ?></h3>
                                            <span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-semibold bg-brand-50 text-brand-700 border border-brand-100"><?php echo esc_html((string) count($day_sessions)); ?> <?php esc_html_e('sessions', 'nexdirectory'); ?></span>
                                        </div>

                                        <div class="relative">
                                            <?php if (count($preview_sessions) > 1) : ?>
                                                <span class="pointer-events-none absolute left-[9px] top-8 bottom-8 w-px bg-gradient-to-b from-brand-300 via-brand-200 to-brand-100"></span>
                                            <?php endif; ?>
                                            <?php foreach ($preview_sessions as $session_index => $session_row) : ?>
                                                <?php
                                                $session_title = sanitize_text_field((string) ($session_row['title'] ?? ''));
                                                if ($session_title === '') {
                                                    /* translators: %d: Placeholder value. */
                                                    $session_title = sprintf(__('Session %d', 'nexdirectory'), ((int) $session_index) + 1);
                                                }
                                                $session_uid = sanitize_key((string) ($session_row['session_uid'] ?? ''));
                                                $session_time = sanitize_text_field((string) ($session_row['time'] ?? ''));
                                                $session_location = sanitize_text_field((string) ($session_row['location'] ?? ''));
                                                $session_speaker = sanitize_text_field((string) ($session_row['speaker'] ?? ''));
                                                $session_attachments = isset($session_row['attachments']) && is_array($session_row['attachments']) ? array_values(array_filter(array_map('esc_url', $session_row['attachments']))) : [];
                                                ?>
                                                <div class="relative pl-10 pb-6 last:pb-0">
                                                    <span class="absolute left-0 top-6 z-10 flex w-5 h-5 items-center justify-center rounded-full bg-brand-500 border-4 border-white shadow-sm"></span>
                                                    <div :class="isItinerarySaved('<?php echo esc_js($session_uid); ?>') ? 'border-l-4 border-l-green-500 border-green-100 bg-green-50/40' : 'border-gray-200 bg-white'" class="relative z-[1] rounded-xl border p-4 sm:p-5 shadow-sm hover:border-brand-200 hover:-translate-y-0.5 hover:shadow-md transition-all duration-300">
                                                        <div class="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-3">
                                                            <h4 class="text-base sm:text-lg font-bold text-gray-900"><?php echo esc_html($session_title); ?></h4>
                                                            <div class="flex flex-wrap items-center gap-2">
                                                                <?php if ($viewer_logged_in) : ?>
                                                                    <button type="button" @click.prevent.stop="toggleItinerarySave('<?php echo esc_js($session_uid); ?>')" :class="isItinerarySaved('<?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="!isItinerarySaved('<?php echo esc_js($session_uid); ?>')"><?php esc_html_e('Add to list', 'nexdirectory'); ?></span>
                                                                        <span x-show="isItinerarySaved('<?php echo esc_js($session_uid); ?>')" style="display:none;"><?php esc_html_e('Saved', 'nexdirectory'); ?></span>
                                                                    </button>
                                                                    <button type="button" @click="openItineraryNoteModal('<?php echo esc_js($session_uid); ?>')" :class="hasItineraryNote('<?php echo esc_js($session_uid); ?>') ? 'bg-amber-50 text-amber-700 border-amber-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="!hasItineraryNote('<?php echo esc_js($session_uid); ?>')"><?php esc_html_e('Add note', 'nexdirectory'); ?></span>
                                                                        <span x-show="hasItineraryNote('<?php echo esc_js($session_uid); ?>')" style="display:none;"><?php esc_html_e('Edit note', 'nexdirectory'); ?></span>
                                                                    </button>
                                                                <?php else : ?>
                                                                    <a href="<?php echo esc_url($login_url); ?>" class="inline-flex items-center gap-1 px-3 py-1.5 rounded-md text-xs font-semibold border border-brand-200 bg-brand-50 text-brand-700 hover:bg-brand-100 transition-colors">
                                                                        <?php esc_html_e('Sign in to save itinerary', 'nexdirectory'); ?>
                                                                    </a>
                                                                <?php endif; ?>
                                                            </div>
                                                        </div>
                                                        <div class="mt-3 space-y-2 text-sm text-gray-600">
                                                            <?php if ($session_time !== '') : ?>
                                                                <p><span class="font-semibold text-gray-900"><?php esc_html_e('Time:', 'nexdirectory'); ?></span> <?php echo esc_html($session_time); ?></p>
                                                            <?php endif; ?>
                                                            <?php if ($session_location !== '') : ?>
                                                                <p><span class="font-semibold text-gray-900"><?php esc_html_e('Location:', 'nexdirectory'); ?></span> <?php echo esc_html($session_location); ?></p>
                                                            <?php endif; ?>
                                                            <?php if ($session_speaker !== '') : ?>
                                                                <p><span class="font-semibold text-gray-900"><?php esc_html_e('Speaker:', 'nexdirectory'); ?></span> <?php echo esc_html($session_speaker); ?></p>
                                                            <?php endif; ?>
                                                        </div>

                                                        <template x-if="viewerLoggedIn && hasItineraryNote('<?php echo esc_js($session_uid); ?>')">
                                                            <div class="mt-3 p-3 rounded-lg border border-yellow-200 bg-yellow-50/80 text-sm text-yellow-900 whitespace-pre-wrap" x-text="getItineraryNote('<?php echo esc_js($session_uid); ?>')"></div>
                                                        </template>

                                                        <?php if (!empty($session_attachments)) : ?>
                                                            <div class="mt-3 flex flex-wrap gap-2" data-nexdirectory-custom-gallery="session-<?php echo esc_attr($day_key . '-' . $session_index); ?>">
                                                                <?php foreach ($session_attachments as $attachment_index => $attachment_url) : ?>
                                                                    <?php
                                                                    $attachment_path = strtolower((string) wp_parse_url($attachment_url, PHP_URL_PATH));
                                                                    $attachment_ext = strtolower((string) pathinfo($attachment_path, PATHINFO_EXTENSION));
                                                                    $attachment_name = sanitize_text_field((string) basename($attachment_path));
                                                                    if ($attachment_name === '') {
                                                                        /* translators: %d: Placeholder value. */
                                                                        $attachment_name = sprintf(__('Attachment %d', 'nexdirectory'), $attachment_index + 1);
                                                                    }
                                                                    $is_image_attachment = in_array($attachment_ext, ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'avif', 'svg'], true);
                                                                    $is_embedded_video_attachment = (bool) preg_match('/(youtube\.com|youtu\.be|vimeo\.com)/i', (string) $attachment_url);
                                                                    $is_video_attachment = in_array($attachment_ext, ['mp4', 'webm', 'ogg', 'mov', 'm4v'], true) || $is_embedded_video_attachment;
                                                                    if ($is_embedded_video_attachment) {
                                                                        $attachment_name = __('Watch video', 'nexdirectory');
                                                                    }
                                                                    $is_pdf_attachment = $attachment_ext === 'pdf';
                                                                    ?>
                                                                    <?php if ($is_image_attachment) : ?>
                                                                        <button type="button" class="nexdirectory-gallery-item inline-flex items-center px-3 py-1.5 rounded-lg border border-gray-200 bg-gray-50 text-xs font-medium text-gray-700 hover:bg-gray-100 transition-colors" data-nexdirectory-lightbox="<?php echo esc_url($attachment_url); ?>">
                                                                            <?php echo esc_html($attachment_name); ?>
                                                                        </button>
                                                                    <?php elseif ($is_video_attachment) : ?>
                                                                        <button type="button" class="inline-flex items-center px-3 py-1.5 rounded-lg border border-gray-200 bg-gray-50 text-xs font-medium text-gray-700 hover:bg-gray-100 transition-colors" data-nexdirectory-video-url="<?php echo esc_url($attachment_url); ?>">
                                                                            <?php echo esc_html($attachment_name); ?>
                                                                        </button>
                                                                    <?php else : ?>
                                                                        <button type="button" class="inline-flex items-center px-3 py-1.5 rounded-lg border border-gray-200 bg-gray-50 text-xs font-medium text-gray-700 hover:bg-gray-100 transition-colors" data-nexdirectory-doc-url="<?php echo esc_url($attachment_url); ?>" data-nexdirectory-doc-title="<?php echo esc_attr($attachment_name); ?>" data-nexdirectory-doc-embed="<?php echo $is_pdf_attachment ? esc_url($attachment_url) : ''; ?>">
                                                                            <?php echo esc_html($attachment_name); ?>
                                                                        </button>
                                                                    <?php endif; ?>
                                                                <?php endforeach; ?>
                                                            </div>
                                                        <?php endif; ?>
                                                    </div>
                                                </div>
                                            <?php endforeach; ?>
                                        </div>

                                        <?php if ($has_more_day_sessions) : ?>
                                            <div class="mt-2 pl-10">
                                                <button type="button" @click="itineraryModalDay = '<?php echo esc_js($day_key); ?>'; showItineraryModal = true" class="inline-flex items-center gap-2 px-4 py-2 rounded-lg bg-brand-50 text-brand-700 border border-brand-100 text-sm font-semibold hover:bg-brand-100 transition-colors">
                                                    <?php esc_html_e('View Full Day Itinerary', 'nexdirectory'); ?>
                                                    <span class="text-xs">(+<?php echo esc_html((string) (count($day_sessions) - $timeline_preview_limit)); ?>)</span>
                                                </button>
                                            </div>
                                        <?php endif; ?>
                                    </article>
                                <?php endforeach; ?>
                            </div>
                        </div>
                    </section>
                <?php endif; ?>

                <?php if ($show_key_speakers && !empty($key_speakers)) : ?>
                    <section 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-200 bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden">
                        <div class="border-b border-gray-100 px-5 sm:px-6 py-4 sm:py-5 bg-gray-50/50">
                            <h2 class="text-lg sm:text-xl 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 echo esc_html($single_key_speakers_heading); ?>
                            </h2>
                        </div>
                        <div class="p-5 sm:p-6">
                            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                                <?php foreach ($key_speakers_visible as $speaker_row) : ?>
                                    <?php
                                    $speaker_name = sanitize_text_field((string) ($speaker_row['name'] ?? ''));
                                    $speaker_profession = sanitize_text_field((string) ($speaker_row['profession'] ?? ''));
                                    $speaker_subject = sanitize_text_field((string) ($speaker_row['subject'] ?? ''));
                                    $speaker_details = nexdirectory_sanitize_textarea((string) ($speaker_row['details'] ?? ''));
                                    $speaker_image = esc_url((string) ($speaker_row['image'] ?? ''));
                                    if ($speaker_name === '' && $speaker_profession === '' && $speaker_subject === '' && $speaker_details === '' && $speaker_image === '') {
                                        continue;
                                    }
                                    ?>
                                    <article class="rounded-xl border border-gray-200 bg-gray-50/60 p-4 sm:p-5 shadow-sm hover:border-brand-200 hover:-translate-y-0.5 hover:shadow-md transition-all duration-300">
                                        <div class="flex items-start gap-3">
                                            <?php if ($speaker_image !== '') : ?>
                                                <img src="<?php echo esc_url($speaker_image); ?>" alt="<?php echo esc_attr($speaker_name !== '' ? $speaker_name : __('Speaker', 'nexdirectory')); ?>" class="w-14 h-14 rounded-xl object-cover border border-gray-200 shadow-sm shrink-0">
                                            <?php else : ?>
                                                <div class="w-14 h-14 rounded-xl bg-brand-50 text-brand-600 border border-brand-100 shadow-sm shrink-0 flex items-center justify-center">
                                                    <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" 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>
                                                </div>
                                            <?php endif; ?>
                                            <div class="min-w-0 flex-1">
                                                <?php if ($speaker_name !== '') : ?>
                                                    <h3 class="text-base font-bold text-gray-900 leading-tight"><?php echo esc_html($speaker_name); ?></h3>
                                                <?php endif; ?>
                                                <?php if ($speaker_profession !== '') : ?>
                                                    <p class="text-sm text-gray-500 mt-1"><?php echo esc_html($speaker_profession); ?></p>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                        <?php if ($speaker_subject !== '') : ?>
                                            <p class="mt-3 inline-flex items-center px-2.5 py-1 rounded-full text-xs font-semibold text-brand-700 bg-brand-50 border border-brand-100"><?php echo esc_html($speaker_subject); ?></p>
                                        <?php endif; ?>
                                        <?php if ($speaker_details !== '') : ?>
                                            <p class="mt-3 text-sm text-gray-600 leading-relaxed"><?php echo esc_html($speaker_details); ?></p>
                                        <?php endif; ?>
                                    </article>
                                <?php endforeach; ?>
                            </div>
                            <?php if ($has_more_key_speakers) : ?>
                                <div class="mt-4">
                                    <button type="button" @click="showSpeakersModal = true" class="inline-flex items-center gap-2 px-4 py-2 rounded-lg bg-brand-50 text-brand-700 border border-brand-100 text-sm font-semibold hover:bg-brand-100 transition-colors">
                                        <?php esc_html_e('View All Speakers', 'nexdirectory'); ?>
                                        <span class="text-xs">(+<?php echo esc_html((string) (count($key_speakers) - count($key_speakers_visible))); ?>)</span>
                                    </button>
                                </div>
                            <?php endif; ?>
                        </div>
                    </section>
                <?php endif; ?>

                <?php if (!empty($gallery_images_all) && !$is_job_profile) : ?>
                    <section 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-200 bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden">
                        <div class="border-b border-gray-100 px-5 sm:px-6 py-4 sm:py-5 bg-gray-50/50 flex justify-between items-center">
                            <h2 class="text-lg sm:text-xl 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 echo esc_html($single_gallery_heading); ?>
                            </h2>
                            <?php if ($event_gallery_type === 'carousel') : ?>
                                <span class="text-xs font-semibold text-brand-600 bg-brand-50 px-2.5 py-1 rounded-full"><?php esc_html_e('Carousel', 'nexdirectory'); ?></span>
                            <?php elseif ($event_gallery_type === 'wall') : ?>
                                <span class="text-xs font-semibold text-brand-600 bg-brand-50 px-2.5 py-1 rounded-full"><?php esc_html_e('Wall', 'nexdirectory'); ?></span>
                            <?php else : ?>
                                <span class="text-xs font-semibold text-brand-600 bg-brand-50 px-2.5 py-1 rounded-full md:hidden"><?php esc_html_e('Swipe', 'nexdirectory'); ?></span>
                            <?php endif; ?>
                        </div>
                        <?php if ($event_gallery_type === 'carousel') : ?>
                            <div class="p-5 sm:p-6 nexdirectory-event-gallery-grid" data-nexdirectory-gallery-grid="1" data-nexdirectory-gallery-items="<?php echo esc_attr((string) $gallery_items_json); ?>">
                                <?php if (count($gallery_images_all) > 1) : ?>
                                    <div class="hidden sm:flex justify-end gap-2 mb-3">
                                        <button type="button" @click="$refs.galleryCarousel.scrollBy({ left: -Math.max(280, $refs.galleryCarousel.clientWidth * 0.75), behavior: 'smooth' })" class="inline-flex items-center justify-center w-9 h-9 rounded-full border border-gray-200 bg-white text-gray-600 hover:bg-gray-50 transition-colors" aria-label="<?php esc_attr_e('Previous gallery image', 'nexdirectory'); ?>">
                                            <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 19l-7-7 7-7"></path></svg>
                                        </button>
                                        <button type="button" @click="$refs.galleryCarousel.scrollBy({ left: Math.max(280, $refs.galleryCarousel.clientWidth * 0.75), behavior: 'smooth' })" class="inline-flex items-center justify-center w-9 h-9 rounded-full border border-gray-200 bg-white text-gray-600 hover:bg-gray-50 transition-colors" aria-label="<?php esc_attr_e('Next gallery image', 'nexdirectory'); ?>">
                                            <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="M9 5l7 7-7 7"></path></svg>
                                        </button>
                                    </div>
                                <?php endif; ?>
                                <div class="flex overflow-x-auto snap-x snap-mandatory scrollbar-hide gap-4 pb-2 -mx-5 px-5 sm:mx-0 sm:px-0" x-ref="galleryCarousel">
                                    <?php foreach ($gallery_images_all as $i => $img) : ?>
                                        <button type="button" class="nexdirectory-gallery-item snap-start shrink-0 w-[84vw] sm:w-[520px] lg:w-[620px] relative rounded-xl overflow-hidden aspect-[16/10] bg-gray-100 border border-gray-200 outline-none shadow-sm hover:shadow-md transition-shadow" data-nexdirectory-lightbox="<?php echo esc_url((string) $img); ?>" data-nexdirectory-gallery-index="<?php echo esc_attr((string) $i); ?>" aria-label="<?php echo esc_attr($gallery_button_label($i)); ?>">
                                            <img src="<?php echo esc_url((string) $img); ?>" alt="<?php echo esc_attr($gallery_image_alt($i)); ?>" loading="lazy" class="w-full h-full object-cover block">
                                        </button>
                                    <?php endforeach; ?>
                                    <div class="snap-start shrink-0 w-[1px] opacity-0 pointer-events-none" aria-hidden="true"></div>
                                </div>
                            </div>
                        <?php elseif ($event_gallery_type === 'wall') : ?>
                            <div class="p-5 sm:p-6 nexdirectory-event-gallery-grid" data-nexdirectory-gallery-grid="1" data-nexdirectory-gallery-items="<?php echo esc_attr((string) $gallery_items_json); ?>">
                                <div class="columns-1 sm:columns-2 lg:columns-3 gap-4">
                                    <?php foreach ($gallery_images_all as $i => $img) : ?>
                                        <button type="button" class="nexdirectory-gallery-item mb-4 block w-full break-inside-avoid rounded-xl overflow-hidden bg-gray-100 border border-gray-200 outline-none shadow-sm hover:shadow-md transition-shadow" data-nexdirectory-lightbox="<?php echo esc_url((string) $img); ?>" data-nexdirectory-gallery-index="<?php echo esc_attr((string) $i); ?>" aria-label="<?php echo esc_attr($gallery_button_label($i)); ?>">
                                            <img src="<?php echo esc_url((string) $img); ?>" alt="<?php echo esc_attr($gallery_image_alt($i)); ?>" loading="lazy" class="w-full h-auto block">
                                        </button>
                                    <?php endforeach; ?>
                                </div>
                            </div>
                        <?php else : ?>
                            <div class="hidden md:block p-5 sm:p-6" data-nexdirectory-gallery-grid="1" data-nexdirectory-gallery-items="<?php echo esc_attr((string) $gallery_items_json); ?>">
                                <div class="grid grid-cols-3 gap-4 auto-rows-min">
                                    <?php if (isset($gallery_images_visible[0])): ?>
                                        <button type="button" class="nexdirectory-gallery-item col-span-2 row-span-2 group relative rounded-xl overflow-hidden aspect-auto h-full min-h-[400px] bg-gray-100 border border-gray-200 flex outline-none cursor-pointer focus:ring-2 focus:ring-brand-500 shadow-sm hover:shadow-md transition-shadow" data-nexdirectory-lightbox="<?php echo esc_url((string) $gallery_images_visible[0]); ?>" data-nexdirectory-gallery-index="0" aria-label="<?php echo esc_attr($gallery_button_label(0)); ?>">
                                            <img src="<?php echo esc_url((string) $gallery_images_visible[0]); ?>" alt="<?php echo esc_attr($gallery_image_alt(0)); ?>" loading="lazy" class="w-full h-full object-cover transition-transform duration-500 md:group-hover:scale-105 block">
                                            <div class="absolute inset-0 bg-black/0 md:group-hover:bg-black/10 transition-colors flex items-center justify-center">
                                                <svg class="w-10 h-10 text-white opacity-0 md:group-hover:opacity-100 transition-opacity transform scale-50 md:group-hover:scale-100 duration-300 drop-shadow-md" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0zM10 7v3m0 0v3m0-3h3m-3 0H7"></path></svg>
                                            </div>
                                        </button>
                                    <?php endif; ?>
                                    <?php if (isset($gallery_images_visible[1])): ?>
                                        <button type="button" class="nexdirectory-gallery-item col-span-1 group relative rounded-xl overflow-hidden aspect-[4/3] bg-gray-100 border border-gray-200 flex outline-none cursor-pointer focus:ring-2 focus:ring-brand-500 shadow-sm hover:shadow-md transition-shadow" data-nexdirectory-lightbox="<?php echo esc_url((string) $gallery_images_visible[1]); ?>" data-nexdirectory-gallery-index="1" aria-label="<?php echo esc_attr($gallery_button_label(1)); ?>">
                                            <img src="<?php echo esc_url((string) $gallery_images_visible[1]); ?>" alt="<?php echo esc_attr($gallery_image_alt(1)); ?>" loading="lazy" class="w-full h-full object-cover transition-transform duration-500 md:group-hover:scale-105 block">
                                            <div class="absolute inset-0 bg-black/0 md:group-hover:bg-black/10 transition-colors flex items-center justify-center">
                                                <svg class="w-8 h-8 text-white opacity-0 md:group-hover:opacity-100 transition-opacity transform scale-50 md:group-hover:scale-100 duration-300 drop-shadow-md" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0zM10 7v3m0 0v3m0-3h3m-3 0H7"></path></svg>
                                            </div>
                                        </button>
                                    <?php endif; ?>
                                    <?php if (isset($gallery_images_visible[2])): ?>
                                        <button type="button" class="nexdirectory-gallery-item col-span-1 group relative rounded-xl overflow-hidden aspect-[4/3] bg-gray-100 border border-gray-200 flex outline-none cursor-pointer focus:ring-2 focus:ring-brand-500 shadow-sm hover:shadow-md transition-shadow" data-nexdirectory-lightbox="<?php echo esc_url((string) $gallery_images_visible[2]); ?>" data-nexdirectory-gallery-index="2" aria-label="<?php echo esc_attr($gallery_button_label(2)); ?>">
                                            <img src="<?php echo esc_url((string) $gallery_images_visible[2]); ?>" alt="<?php echo esc_attr($gallery_image_alt(2)); ?>" loading="lazy" class="w-full h-full object-cover transition-transform duration-500 md:group-hover:scale-105 block">
                                            <div class="absolute inset-0 bg-black/0 md:group-hover:bg-black/10 transition-colors flex items-center justify-center">
                                                <svg class="w-8 h-8 text-white opacity-0 md:group-hover:opacity-100 transition-opacity transform scale-50 md:group-hover:scale-100 duration-300 drop-shadow-md" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0zM10 7v3m0 0v3m0-3h3m-3 0H7"></path></svg>
                                            </div>
                                        </button>
                                    <?php endif; ?>
                                    <?php if ($gallery_hidden_count > 0): ?>
                                        <button type="button" class="nexdirectory-gallery-item col-span-1 group relative rounded-xl overflow-hidden aspect-[4/3] border border-gray-200 flex flex-col items-center justify-center bg-gray-50 md:hover:bg-gray-100 transition-colors cursor-pointer outline-none focus:ring-2 focus:ring-brand-500 shadow-sm" data-nexdirectory-lightbox="<?php echo isset($gallery_images_all[3]) ? esc_url((string) $gallery_images_all[3]) : '#'; ?>" data-nexdirectory-gallery-index="3">
                                            <div class="w-10 h-10 rounded-full bg-brand-100 text-brand-600 flex items-center justify-center mb-2 md:group-hover:scale-110 transition-transform duration-300 shadow-sm">
                                                <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>
                                            </div>
                                            <span class="text-gray-600 font-semibold text-sm"><?php echo esc_html($gallery_hidden_count); ?> <?php esc_html_e('More', 'nexdirectory'); ?></span>
                                        </button>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <div class="md:hidden flex overflow-x-auto snap-x snap-mandatory scrollbar-hide gap-4 pb-4 -mx-5 px-5" data-nexdirectory-mobile-gallery-slider="1" data-nexdirectory-gallery-items="<?php echo esc_attr((string) $gallery_items_json); ?>">
                                <?php foreach ($gallery_images_visible as $i => $img): ?>
                                    <button type="button" class="nexdirectory-gallery-item snap-center shrink-0 w-[85vw] relative rounded-xl overflow-hidden aspect-[4/3] bg-gray-100 border border-gray-200 outline-none shadow-sm" data-nexdirectory-lightbox="<?php echo esc_url((string) $img); ?>" data-nexdirectory-gallery-index="<?php echo esc_attr((string) $i); ?>" aria-label="<?php echo esc_attr($gallery_button_label($i)); ?>">
                                        <img src="<?php echo esc_url((string) $img); ?>" alt="<?php echo esc_attr($gallery_image_alt($i)); ?>" loading="lazy" class="w-full h-full object-cover block">
                                    </button>
                                <?php endforeach; ?>
                                <?php if ($gallery_hidden_count > 0): ?>
                                    <button type="button" class="nexdirectory-gallery-item snap-center shrink-0 w-[85vw] relative rounded-xl overflow-hidden aspect-[4/3] border border-gray-200 flex flex-col items-center justify-center bg-gray-50 outline-none shadow-sm" data-nexdirectory-lightbox="<?php echo isset($gallery_images_all[3]) ? esc_url((string) $gallery_images_all[3]) : '#'; ?>" data-nexdirectory-gallery-index="3">
                                        <div class="w-12 h-12 rounded-full bg-brand-100 text-brand-600 flex items-center justify-center mb-2 shadow-sm">
                                            <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" d="M12 4v16m8-8H4"></path></svg>
                                        </div>
                                        <span class="text-gray-600 font-semibold text-base"><?php echo esc_html($gallery_hidden_count); ?> <?php esc_html_e('More Images', 'nexdirectory'); ?></span>
                                    </button>
                                <?php endif; ?>
                                <div class="snap-center shrink-0 w-[1vw] opacity-0 pointer-events-none"></div>
                            </div>
                        <?php endif; ?>
                    </section>
                <?php endif; ?>
                
                <?php if (!empty($video_cards) && !$is_job_profile) : ?>
                    <section 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-200 flex overflow-x-auto snap-x snap-mandatory scrollbar-hide gap-4 pb-2 sm:pb-0 sm:flex-col sm:gap-4 -mx-4 px-4 sm:mx-0 sm:px-0">
                        <?php foreach ($video_cards as $index => $video) : ?>
                            <?php
                            $embed_url = esc_url((string) ($video['embed_url'] ?? ''));
                            $video_url = esc_url((string) ($video['url'] ?? ''));
                            $thumb_url = esc_url((string) ($video['thumb'] ?? ''));
                            $video_title = sanitize_text_field((string) ($video['title'] ?? 'Video'));
                            ?>
                            <?php if ($embed_url !== '' || $video_url !== '') : ?>
                                <button type="button" class="snap-center shrink-0 w-[85vw] sm:w-full group cursor-pointer active:scale-[0.98] hover:shadow-md transition-all duration-300 text-left block p-0 bg-transparent border-none appearance-none outline-none focus:ring-2 focus:ring-brand-500 rounded-2xl" data-nexdirectory-video-embed="<?php echo esc_url($embed_url); ?>" data-nexdirectory-video-url="<?php echo esc_url($video_url); ?>" data-nexdirectory-video-title="<?php echo esc_attr($video_title); ?>" data-nexdirectory-video-index="<?php echo esc_attr((string) $index); ?>" aria-label="<?php echo esc_attr($video_title); ?>">
                                    <div class="relative w-full rounded-2xl overflow-hidden shadow-sm aspect-video bg-gray-900 flex border border-gray-100">
                                        <?php if ($thumb_url !== '') : ?>
                                            <img src="<?php echo esc_url($thumb_url); ?>" alt="<?php echo esc_attr($video_title); ?>" loading="lazy" class="w-full h-full object-cover opacity-80 transition-opacity md:group-hover:opacity-100 block">
                                        <?php else : ?>
                                            <div class="w-full h-full bg-gradient-to-br from-gray-700 to-gray-900 flex-1"></div>
                                        <?php endif; ?>
                                        <div class="absolute inset-0 flex items-center justify-center pointer-events-none">
                                            <div class="w-14 h-14 sm:w-16 sm:h-16 bg-brand-500/90 backdrop-blur-sm text-white rounded-full flex items-center justify-center shadow-lg transform transition-transform duration-300 md:group-hover:scale-110">
                                                <svg class="w-6 h-6 sm:w-8 sm:h-8 ml-1" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z" clip-rule="evenodd"></path></svg>
                                            </div>
                                        </div>
                                        <div class="absolute top-3 left-3 sm:top-4 sm:left-4 pointer-events-none z-10">
                                            <span class="px-2.5 py-1 bg-black/60 text-white text-[10px] sm:text-xs font-bold uppercase tracking-wider rounded backdrop-blur-md"><?php echo esc_html('VIDEO ' . (string) ($index + 1)); ?></span>
                                        </div>
                                    </div>
                                </button>
                            <?php endif; ?>
                        <?php endforeach; ?>
                    </section>
                <?php endif; ?>

                <?php if (!empty($supporting_documents)) : ?>
                    <section x-data="{ shown: false, docExpanded: true }" 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-200 bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden">
                        <button type="button" @click="docExpanded = !docExpanded" :aria-expanded="docExpanded ? 'true' : 'false'" aria-controls="nexdirectory-supporting-documents-<?php echo esc_attr((string) $post_id); ?>" class="w-full border-b border-gray-100 px-5 sm:px-6 py-4 sm:py-5 bg-gray-50/50 flex items-center justify-between transition-colors hover:bg-gray-100/50 focus:outline-none">
                            <h2 class="text-lg sm:text-xl 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="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"></path></svg>
                                <?php echo esc_html($single_documents_heading); ?>
                            </h2>
                            <svg class="w-5 h-5 text-gray-400 transform transition-transform duration-300 md:hidden" :class="docExpanded ? 'rotate-180' : ''" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>
                        </button>
                        <div id="nexdirectory-supporting-documents-<?php echo esc_attr((string) $post_id); ?>" x-show="docExpanded" x-collapse class="p-5 sm:p-6">
                            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                                <?php foreach ((array) $supporting_documents as $doc_index => $doc) : ?>
                                    <?php 
                                    $doc_url_raw = (string) ($doc['url'] ?? '');
                                    $doc_url = esc_url($doc_url_raw);
                                    $doc_ext = strtoupper((string) ($doc['extension'] ?? 'FILE'));
                                    $badge_class = $doc_ext === 'PDF' ? 'bg-red-50 text-red-600' : 'bg-blue-50 text-blue-600';
                                    $doc_title = sanitize_text_field((string) ($doc['title'] ?? 'Document'));
                                    $doc_embed_url = esc_url((string) ($doc['embed_url'] ?? ''));
                                    if ($doc_embed_url === '' && $doc_url_raw !== '') {
                                        if (strtolower((string) $doc_ext) === 'pdf') {
                                            $doc_embed_url = esc_url($doc_url_raw);
                                        } else {
                                            $doc_embed_url = esc_url('https://docs.google.com/gview?embedded=1&url=' . rawurlencode($doc_url_raw));
                                        }
                                    }
                                    ?>
                                    <button type="button" class="border border-gray-200 rounded-xl p-4 flex flex-col justify-between active:scale-[0.98] active:bg-gray-50 md:hover:-translate-y-1 md:hover:shadow-md md:hover:border-brand-300 transition-all duration-300 group cursor-pointer bg-white text-left" data-nexdirectory-doc-url="<?php echo esc_url($doc_url); ?>" data-nexdirectory-doc-embed="<?php echo esc_url($doc_embed_url); ?>" data-nexdirectory-doc-title="<?php echo esc_attr($doc_title); ?>" data-nexdirectory-doc-index="<?php echo esc_attr((string) $doc_index); ?>">
                                        <div class="flex items-start justify-between mb-4">
                                            <div>
                                                <span class="inline-block px-2.5 py-1 <?php echo esc_attr($badge_class); ?> text-[10px] font-bold uppercase tracking-wider rounded mb-2"><?php echo esc_html($doc_ext); ?></span>
                                                <h3 class="font-semibold text-gray-900 text-base"><?php echo esc_html($doc_title); ?></h3>
                                                <p class="text-xs text-gray-500 mt-0.5 truncate max-w-[150px]"><?php echo esc_html((string) ($doc['file_name'] ?? 'Document')); ?></p>
                                            </div>
                                            <div class="p-2.5 bg-gray-50 rounded-xl text-gray-400 md:group-hover:bg-brand-50 md:group-hover:text-brand-500 transition-colors">
                                                <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" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"></path></svg>
                                            </div>
                                        </div>
                                        <span class="w-full py-2.5 px-4 bg-gray-50 md:hover:bg-brand-50 md:hover:text-brand-700 text-gray-700 text-sm font-medium rounded-lg transition-colors border border-gray-200 flex items-center justify-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="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path></svg>
                                            <?php esc_html_e('Preview', 'nexdirectory'); ?>
                                        </span>
                                    </button>
                                <?php endforeach; ?>
                            </div>
                        </div>
                    </section>
                <?php endif; ?>

                <?php if ($map_link !== '') : ?>
                    <section 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-300 bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden mb-6 sm:mb-0">
                        <div class="border-b border-gray-100 px-5 sm:px-6 py-4 sm:py-5 bg-gray-50/50">
                            <h2 class="text-lg sm:text-xl 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 echo esc_html($single_location_heading); ?>
                            </h2>
                        </div>
                        <div class="p-5 sm:p-6">
                            <?php if (!empty($map_embed_url)) : ?>
                                <div class="rounded-xl overflow-hidden border border-gray-200 mb-5 relative h-48 sm:h-64 bg-gray-100 cursor-pointer flex group active:scale-[0.98] transition-transform duration-300" role="button" tabindex="0" aria-label="<?php esc_attr_e('Open larger map', 'nexdirectory'); ?>" @click.prevent="showMapModal = true" @keydown.enter.prevent="showMapModal = true" @keydown.space.prevent="showMapModal = true">
                                    <iframe loading="lazy" src="<?php echo esc_url((string) $map_embed_url); ?>" title="<?php echo esc_attr($map_iframe_title); ?>" allowfullscreen class="w-full h-full border-0 pointer-events-none block group-hover:opacity-90 transition-opacity"></iframe>
                                    <div class="absolute inset-0 flex items-center justify-center pointer-events-none">
                                        <div class="bg-white/95 backdrop-blur text-gray-900 font-bold px-4 py-2 rounded-lg shadow-md text-sm transform transition-transform group-hover:scale-105">Click to expand</div>
                                    </div>
                                </div>
                            <?php endif; ?>
                            
                            <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
                                <div>
                                    <h3 class="font-bold text-gray-900 text-base sm:text-lg mb-1"><?php echo esc_html((string) $venue_label); ?></h3>
                                    <?php if ($location_full !== '') : ?>
                                        <p class="text-gray-500 text-sm"><?php echo esc_html((string) $location_full); ?></p>
                                    <?php endif; ?>
                                </div>
                                <button type="button" @click.prevent="showMapModal = true" class="w-full sm:w-auto px-6 py-3 sm:py-2.5 bg-gray-900 hover:bg-gray-800 active:scale-95 text-white text-sm font-medium rounded-xl sm:rounded-lg transition-all duration-200 shadow-sm hover:shadow whitespace-nowrap text-center">
                                    <?php echo esc_html($single_open_map_cta); ?>
                                </button>
                            </div>
                        </div>
                    </section>
                <?php endif; ?>
            </div>

            <div class="<?php echo esc_attr((string) $page_template['aside']); ?>">
                <div class="<?php echo esc_attr((string) $page_template['aside_inner']); ?>">
                    
                    <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-x-0' : 'opacity-0 translate-x-8'" class="hidden md:block bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden relative transition-all duration-700 ease-out">
                        <div class="h-2 w-full bg-brand-500"></div>
                        <div class="p-6">
                            <h3 class="text-xl font-bold text-gray-900 mb-2"><?php echo esc_html($single_cta_heading); ?></h3>
                            <p class="text-sm text-gray-500 mb-5"><?php echo esc_html($single_cta_copy); ?></p>
                            
                            <div class="space-y-3">
                                <?php if ($show_edit_event_button) : ?>
                                    <a href="<?php echo esc_url((string) $edit_event_url); ?>" class="w-full flex items-center justify-center gap-2 py-2.5 px-4 bg-brand-600 hover:bg-brand-700 active:bg-brand-800 active:scale-95 text-white text-sm font-semibold rounded-xl transition-all 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="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.828L12.828 14H9v-3.828l8.586-8.586z"></path></svg>
                                        <?php echo esc_html((string) $edit_event_button_label); ?>
                                    </a>
                                <?php endif; ?>

                                <?php if ($ticketing_pro_enabled) : ?>
                                    <?php do_action('nexdirectory_render_extension_single_ticket_cta', $this, (int) $post_id, 'sidebar'); ?>
                                <?php endif; ?>

                                <?php if ($show_rsvp_actions) : ?>
                                    <div class="bg-gray-50 border border-gray-100 rounded-xl p-4 mb-1">
                                        <div class="flex items-center justify-between mb-3">
                                            <span class="font-bold text-gray-900 text-sm">Attend this event</span>
                                            <span class="nexdirectory-rsvp-meta bg-brand-100 text-brand-700 text-[11px] font-bold px-2 py-1 rounded-full flex items-center gap-1 shadow-sm <?php echo ($rsvp_count <= 0 && $waitlist_count <= 0) ? 'hidden' : ''; ?>"
                                                  data-post-id="<?php echo esc_attr((string) $post_id); ?>"
                                                  data-primary-label="<?php echo esc_attr($is_events_profile ? __('RSVP', 'nexdirectory') : __('Saved', 'nexdirectory')); ?>"
                                                  data-secondary-label="<?php echo esc_attr($is_events_profile ? __('Waitlist', 'nexdirectory') : ''); ?>">
                                                    <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path></svg>
                                                    <span>
                                                        <?php
                                                        if ($is_events_profile) {
                                                            /* translators: 1: Placeholder value 1, 2: Placeholder value 2. */
                                                            echo esc_html(sprintf(__('RSVP: %1$d | Waitlist: %2$d', 'nexdirectory'), (int) $rsvp_count, (int) $waitlist_count));
                                                        } else {
                                                            /* translators: %d: Placeholder value. */
                                                            echo esc_html(sprintf(__('Saved: %d', 'nexdirectory'), (int) $rsvp_count));
                                                        }
                                                        ?>
                                                    </span>
                                            </span>
                                        </div>
                                        
                                        <?php if ($viewer_logged_in) : ?>
                                            <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" class="nexdirectory-rsvp-form" data-nexdirectory-rsvp-post-id="<?php echo esc_attr((string) $post_id); ?>">
                                                <input type="hidden" name="action" value="nexdirectory_rsvp_event">
                                                <input type="hidden" name="post_id" value="<?php echo esc_attr((string) $post_id); ?>">
                                                <input type="hidden" name="intent" value="<?php echo esc_attr((string) $rsvp_intent); ?>">
                                                <?php echo wp_kses((string) $rsvp_nonce_html, NEXDIRECTORY_Escaping::allowed_html()); ?>
                                                <button type="submit" class="w-full flex items-center justify-center gap-2 py-2.5 px-4 bg-brand-600 hover:bg-brand-700 active:bg-brand-800 active:scale-95 text-white text-sm font-semibold rounded-lg transition-all shadow-sm">
                                                    <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="M5 13l4 4L19 7"></path></svg>
                                                    <span data-nexdirectory-rsvp-label="1"><?php echo esc_html((string) $rsvp_button_label); ?></span>
                                                </button>
                                            </form>
                                        <?php else : ?>
                                            <a href="<?php echo esc_url((string) $login_url); ?>" class="w-full flex items-center justify-center gap-2 py-2.5 px-4 bg-brand-600 hover:bg-brand-700 active:bg-brand-800 active:scale-95 text-white text-sm font-semibold rounded-lg transition-all shadow-sm">
                                                <?php echo esc_html($single_login_rsvp); ?>
                                            </a>
                                        <?php endif; ?>
                                    </div>
                                <?php endif; ?>

                                <?php if ($has_calendar_actions && $calendar_primary_url !== '') : ?>
                                    <a href="<?php echo esc_url($calendar_primary_url); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" class="w-full flex items-center justify-center gap-2 py-2.5 px-4 bg-white hover:bg-gray-50 border border-gray-200 text-gray-700 active:scale-95 text-sm font-semibold rounded-xl transition-all shadow-sm">
                                        <svg class="w-5 h-5 text-gray-500" 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 esc_html_e('Add to Calendar', 'nexdirectory'); ?>
                                    </a>
                                <?php endif; ?>

                                <?php if ($event_webapp_download_visible) : ?>
                                    <a href="<?php echo esc_url((string) $event_webapp_url); ?>" class="w-full flex items-center justify-center gap-2 py-2.5 px-4 bg-brand-50 hover:bg-brand-100 border border-brand-200 text-brand-700 active:scale-95 text-sm font-semibold rounded-xl transition-all shadow-sm">
                                        <svg class="w-5 h-5 text-brand-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 3.75h4.5A2.25 2.25 0 0116.5 6v12a2.25 2.25 0 01-2.25 2.25h-4.5A2.25 2.25 0 017.5 18V6a2.25 2.25 0 012.25-2.25zM10 17h4"></path></svg>
                                        <?php echo esc_html($single_open_event_app_cta); ?>
                                    </a>
                                <?php endif; ?>

                                <div class="<?php echo $has_message_button ? 'grid grid-cols-2 gap-3' : 'grid grid-cols-1 gap-3'; ?>">
                                    <?php if ($has_primary_action || $external_url !== '') : ?>
                                        <a target="_blank" rel="noopener noreferrer nofollow ugc" href="<?php echo esc_url($has_primary_action ? $primary_action_url : $external_url); ?>" data-nexdirectory-analytics-metric="<?php echo esc_attr($primary_cta_metric); ?>" data-nexdirectory-track-event-id="<?php echo esc_attr((string) $post_id); ?>" class="flex items-center justify-center gap-2 py-2.5 px-4 bg-gray-900 hover:bg-black active:scale-95 text-white text-sm font-semibold rounded-xl transition-all 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="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"></path></svg>
                                            <?php echo esc_html($has_primary_action ? $primary_action_label : $single_visit_site_cta); ?>
                                        </a>
                                    <?php endif; ?>
                                    
                                    <?php if ($message_button_mode === 'modal') : ?>
                                        <button type="button" @click.prevent.stop="messageModalOpen = true" class="flex items-center justify-center gap-2 py-2.5 px-4 bg-white hover:bg-brand-50 hover:text-brand-700 hover:border-brand-200 border border-gray-200 text-gray-700 text-sm font-semibold rounded-xl active:scale-95 transition-all 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="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>
                                            <?php echo esc_html((string) $message_button_label); ?>
                                        </button>
                                    <?php elseif ($message_button_mode === 'link' && $message_button_url !== '') : ?>
                                        <a href="<?php echo esc_url((string) $message_button_url); ?>" <?php if ($message_button_target !== '') : ?>target="<?php echo esc_attr((string) $message_button_target); ?>"<?php endif; ?> class="flex items-center justify-center gap-2 py-2.5 px-4 bg-white hover:bg-brand-50 hover:text-brand-700 hover:border-brand-200 border border-gray-200 text-gray-700 text-sm font-semibold rounded-xl active:scale-95 transition-all 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="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>
                                            <?php echo esc_html((string) $message_button_label); ?>
                                        </a>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>

                    <?php if ($show_organizer_card) : ?>
                    <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-x-0' : 'opacity-0 translate-x-8'" class="bg-white rounded-2xl shadow-sm border border-gray-100 p-5 sm:p-6 transition-all duration-700 ease-out delay-100">
                        <a href="<?php echo esc_url((string) $organizer_events_url); ?>" class="flex items-center gap-4 mb-6 group cursor-pointer rounded-xl focus:outline-none focus:ring-2 focus:ring-brand-500 focus:ring-offset-2">
                            <div class="w-14 h-14 rounded-full border-2 border-brand-100 bg-brand-500 flex items-center justify-center text-white font-bold text-xl group-hover:scale-105 transition-transform duration-300 shadow-sm">
                                <?php echo esc_html((string) $owner_initials); ?>
                            </div>
                            <div>
                                <p class="text-[10px] sm:text-xs font-semibold text-brand-500 uppercase tracking-wider mb-0.5"><?php echo esc_html($owner_heading); ?></p>
                                <h4 class="text-base sm:text-lg font-bold text-gray-900 leading-tight group-hover:text-brand-600 transition-colors"><?php echo esc_html((string) ($owner_display_name !== '' ? $owner_display_name : __('Listing Owner', 'nexdirectory'))); ?></h4>
                                <span class="text-sm text-gray-500 group-hover:text-brand-600 transition-colors py-1 block"><?php echo esc_html($single_owner_items_cta); ?> →</span>
                            </div>
                        </a>

                        <?php if ($has_share_actions) : ?>
                            <div class="mb-5">
                                <p class="text-[11px] font-semibold uppercase tracking-wider text-gray-500 mb-3"><?php esc_html_e('Share & Connect', 'nexdirectory'); ?></p>
                                <div class="flex gap-3">
                                    <?php if ($share_facebook_url !== '') : ?>
                                        <a href="<?php echo esc_url($share_facebook_url); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" class="w-10 h-10 flex items-center justify-center bg-gray-100 hover:bg-[#1877F2] text-gray-500 hover:text-white rounded-full transition-all duration-200 hover:scale-110 shadow-sm" aria-label="<?php esc_attr_e('Share on Facebook', 'nexdirectory'); ?>">
                                            <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24"><path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.469h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.469h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/></svg>
                                        </a>
                                    <?php endif; ?>
                                    <?php if ($share_x_url !== '') : ?>
                                        <a href="<?php echo esc_url($share_x_url); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" class="w-10 h-10 flex items-center justify-center bg-gray-100 hover:bg-black text-gray-500 hover:text-white rounded-full transition-all duration-200 hover:scale-110 shadow-sm" aria-label="<?php esc_attr_e('Share on X', 'nexdirectory'); ?>">
                                            <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>
                                        </a>
                                    <?php endif; ?>
                                    <?php if ($share_linkedin_url !== '') : ?>
                                        <a href="<?php echo esc_url($share_linkedin_url); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" class="w-10 h-10 flex items-center justify-center bg-gray-100 hover:bg-[#0A66C2] text-gray-500 hover:text-white rounded-full transition-all duration-200 hover:scale-110 shadow-sm" aria-label="<?php esc_attr_e('Share on LinkedIn', 'nexdirectory'); ?>">
                                            <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24"><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/></svg>
                                        </a>
                                    <?php endif; ?>
                                    <?php if ($share_whatsapp_url !== '') : ?>
                                        <a href="<?php echo esc_url($share_whatsapp_url); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" class="w-10 h-10 flex items-center justify-center bg-gray-100 hover:bg-[#25D366] text-gray-500 hover:text-white rounded-full transition-all duration-200 hover:scale-110 shadow-sm" aria-label="<?php esc_attr_e('Share on WhatsApp', 'nexdirectory'); ?>">
                                            <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51a12.8 12.8 0 0 0-.57-.01c-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 0 1-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 0 1-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 0 1 2.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0 0 12.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 0 0 5.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 0 0-3.48-8.413Z"/></svg>
                                        </a>
                                    <?php endif; ?>
                                </div>
                            </div>
                        <?php endif; ?>

                        <?php if ($claimable && $claim_url !== '') : ?>
                            <div class="mb-4">
                                <?php if ($claim_status === 'pending') : ?>
                                    <span class="inline-flex w-full items-center justify-center gap-2 rounded-xl border border-amber-200 bg-amber-50 px-4 py-2.5 text-sm font-semibold text-amber-700">
                                        <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
                                        <?php esc_html_e('Claim Pending Review', 'nexdirectory'); ?>
                                    </span>
                                <?php elseif ($claim_status === 'approved') : ?>
                                    <span class="inline-flex w-full items-center justify-center gap-2 rounded-xl border border-green-200 bg-green-50 px-4 py-2.5 text-sm font-semibold text-green-700">
                                        <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg>
                                        <?php esc_html_e('Claim Approved', 'nexdirectory'); ?>
                                    </span>
                                <?php else : ?>
                                    <a href="<?php echo esc_url($claim_url); ?>" class="inline-flex w-full items-center justify-center gap-2 rounded-xl border border-brand-200 bg-brand-50 px-4 py-2.5 text-sm font-semibold text-brand-700 hover:bg-brand-100 transition-colors">
                                        <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7h8m-8 4h8m-8 4h5M5 4h14a2 2 0 012 2v12a2 2 0 01-2 2H5a2 2 0 01-2-2V6a2 2 0 012-2z"></path></svg>
                                        <?php esc_html_e('Claim Listing', 'nexdirectory'); ?>
                                    </a>
                                <?php endif; ?>
                            </div>
                        <?php endif; ?>
                        
                        <?php if (!empty($reporting_enabled)) : ?>
                            <div class="text-left" x-data="{ reportOpen: false }">
                                <button type="button" @click="reportOpen = !reportOpen" :aria-expanded="reportOpen ? 'true' : 'false'" aria-controls="nexdirectory-report-panel-<?php echo esc_attr((string) $post_id); ?>" class="text-xs sm:text-sm font-medium text-gray-400 hover:text-red-500 transition-colors inline-flex items-center gap-1.5 py-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="M3 21v-4m0 0V5a2 2 0 012-2h6.5l1 1H21l-3 6 3 6h-8.5l-1-1H5a2 2 0 00-2 2zm9-13.5V9"></path></svg>
                                    <?php echo esc_html($single_report_cta); ?>
                                </button>
                                <div id="nexdirectory-report-panel-<?php echo esc_attr((string) $post_id); ?>" x-show="reportOpen" x-collapse class="pt-3">
                                    <?php if (is_user_logged_in()) : ?>
                                        <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" class="space-y-3">
                                            <input type="hidden" name="action" value="nexdirectory_report_event">
                                            <input type="hidden" name="post_id" value="<?php echo esc_attr((string) $post_id); ?>">
                                            <?php echo wp_kses((string) $report_nonce_html, NEXDIRECTORY_Escaping::allowed_html()); ?>
                                            <textarea name="reason" rows="3" required aria-label="<?php echo esc_attr($single_report_placeholder); ?>" placeholder="<?php echo esc_attr($single_report_placeholder); ?>" class="w-full px-4 py-3 sm:py-2.5 rounded-xl border border-gray-200 text-sm focus:ring-2 focus:ring-red-500 focus:border-red-500 outline-none"></textarea>
                                            <button type="submit" class="w-full py-2.5 px-4 bg-gray-900 hover:bg-red-600 active:scale-95 text-white text-sm font-semibold rounded-lg transition-all duration-200 shadow-sm"><?php esc_html_e('Send Report', 'nexdirectory'); ?></button>
                                        </form>
                                    <?php else : ?>
                                        <?php /* translators: %s: Placeholder value. */ ?>
                                        <p class="text-sm font-medium text-gray-500 text-center"><a href="<?php echo esc_url((string) $login_url); ?>" class="text-brand-500 hover:text-brand-600 font-bold transition-colors"><?php echo esc_html(sprintf(__('Log in to report this %s.', 'nexdirectory'), strtolower((string) $singular_label))); ?></a></p>
                                    <?php endif; ?>
                                </div>
                            </div>
                        <?php endif; ?>
                    </div>
                    <?php endif; ?>

                    <?php if ($has_share_actions && !$show_organizer_card) : ?>
                    <div x-data="{ shown: false }" x-intersect.once="shown = true" :class="shown ? 'opacity-100 translate-x-0' : 'opacity-0 translate-x-8'" class="bg-white rounded-2xl shadow-sm border border-gray-100 p-5 sm:p-6 transition-all duration-700 ease-out delay-150">
                        <p class="text-[11px] font-semibold uppercase tracking-wider text-gray-500 mb-3"><?php esc_html_e('Share & Connect', 'nexdirectory'); ?></p>
                        <div class="flex gap-3">
                            <?php if ($share_facebook_url !== '') : ?>
                                <a href="<?php echo esc_url($share_facebook_url); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" class="w-10 h-10 flex items-center justify-center bg-gray-100 hover:bg-[#1877F2] text-gray-500 hover:text-white rounded-full transition-all duration-200 hover:scale-110 shadow-sm" aria-label="<?php esc_attr_e('Share on Facebook', 'nexdirectory'); ?>">
                                    <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24"><path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.469h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.469h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/></svg>
                                </a>
                            <?php endif; ?>
                            <?php if ($share_x_url !== '') : ?>
                                <a href="<?php echo esc_url($share_x_url); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" class="w-10 h-10 flex items-center justify-center bg-gray-100 hover:bg-black text-gray-500 hover:text-white rounded-full transition-all duration-200 hover:scale-110 shadow-sm" aria-label="<?php esc_attr_e('Share on X', 'nexdirectory'); ?>">
                                    <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>
                                </a>
                            <?php endif; ?>
                            <?php if ($share_linkedin_url !== '') : ?>
                                <a href="<?php echo esc_url($share_linkedin_url); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" class="w-10 h-10 flex items-center justify-center bg-gray-100 hover:bg-[#0A66C2] text-gray-500 hover:text-white rounded-full transition-all duration-200 hover:scale-110 shadow-sm" aria-label="<?php esc_attr_e('Share on LinkedIn', 'nexdirectory'); ?>">
                                    <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24"><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/></svg>
                                </a>
                            <?php endif; ?>
                            <?php if ($share_whatsapp_url !== '') : ?>
                                <a href="<?php echo esc_url($share_whatsapp_url); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" class="w-10 h-10 flex items-center justify-center bg-gray-100 hover:bg-[#25D366] text-gray-500 hover:text-white rounded-full transition-all duration-200 hover:scale-110 shadow-sm" aria-label="<?php esc_attr_e('Share on WhatsApp', 'nexdirectory'); ?>">
                                    <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51a12.8 12.8 0 0 0-.57-.01c-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 0 1-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 0 1-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 0 1 2.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0 0 12.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 0 0 5.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 0 0-3.48-8.413Z"/></svg>
                                </a>
                            <?php endif; ?>
                        </div>
                    </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </main>

    <div class="fixed bottom-0 left-0 right-0 bg-white/95 backdrop-blur-md border-t border-gray-200 p-3 sm:p-4 flex gap-2 z-40 md:hidden pb-safe shadow-[0_-4px_6px_-1px_rgba(0,0,0,0.05)] transition-transform">
        <?php if ($ticketing_pro_enabled) : ?>
            <?php do_action('nexdirectory_render_extension_single_ticket_cta', $this, (int) $post_id, 'mobile'); ?>
        <?php endif; ?>

        <?php if ($show_rsvp_actions) : ?>
            <?php if ($viewer_logged_in) : ?>
                <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" class="flex-1 m-0 nexdirectory-rsvp-form" data-nexdirectory-rsvp-post-id="<?php echo esc_attr((string) $post_id); ?>">
                    <input type="hidden" name="action" value="nexdirectory_rsvp_event">
                    <input type="hidden" name="post_id" value="<?php echo esc_attr((string) $post_id); ?>">
                    <input type="hidden" name="intent" value="<?php echo esc_attr((string) $rsvp_intent); ?>">
                    <?php echo wp_kses((string) $rsvp_nonce_html, NEXDIRECTORY_Escaping::allowed_html()); ?>
                    <button type="submit" class="w-full flex items-center justify-center gap-1.5 bg-brand-600 active:bg-brand-700 active:scale-95 text-white font-bold text-sm rounded-xl py-3.5 transition-all duration-200 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="M5 13l4 4L19 7"></path></svg>
                        <span data-nexdirectory-rsvp-label="1"><?php echo esc_html((string) $rsvp_button_label); ?></span>
                    </button>
                </form>
            <?php else : ?>
                <a href="<?php echo esc_url((string) $login_url); ?>" class="flex-1 flex items-center justify-center gap-1.5 bg-brand-600 active:bg-brand-700 active:scale-95 text-white font-bold text-sm rounded-xl py-3.5 transition-all duration-200 shadow-sm">
                    <?php echo esc_html($single_login_rsvp); ?>
                </a>
            <?php endif; ?>
        <?php endif; ?>

        <?php if ($event_webapp_download_visible) : ?>
            <a href="<?php echo esc_url((string) $event_webapp_url); ?>" class="flex items-center justify-center w-12 bg-brand-50 border border-brand-200 active:bg-brand-100 active:scale-95 text-brand-700 font-bold rounded-xl py-3.5 transition-all duration-200 shadow-sm" aria-label="<?php echo esc_attr($single_open_event_app_cta); ?>">
                <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="M9.75 3.75h4.5A2.25 2.25 0 0116.5 6v12a2.25 2.25 0 01-2.25 2.25h-4.5A2.25 2.25 0 017.5 18V6a2.25 2.25 0 012.25-2.25zM10 17h4"></path></svg>
            </a>
        <?php endif; ?>

        <?php if ($message_button_mode === 'modal') : ?>
            <button type="button" @click.prevent.stop="messageModalOpen = true" class="flex items-center justify-center w-12 bg-gray-100 active:bg-gray-200 active:scale-95 text-gray-700 font-bold rounded-xl py-3.5 transition-all duration-200 shadow-sm" aria-label="<?php echo esc_attr((string) $message_button_label); ?>">
                <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="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>
            </button>
        <?php elseif ($message_button_mode === 'link' && $message_button_url !== '') : ?>
            <a href="<?php echo esc_url((string) $message_button_url); ?>" <?php if ($message_button_target !== '') : ?>target="<?php echo esc_attr((string) $message_button_target); ?>"<?php endif; ?> <?php if ($message_button_rel !== '') : ?>rel="<?php echo esc_attr((string) $message_button_rel); ?>"<?php endif; ?> class="flex items-center justify-center w-12 bg-gray-100 active:bg-gray-200 active:scale-95 text-gray-700 font-bold rounded-xl py-3.5 transition-all duration-200 shadow-sm" aria-label="<?php echo esc_attr((string) $message_button_label); ?>">
                <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="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>
            </a>
        <?php endif; ?>

        <?php if ($has_primary_action || $external_url !== '') : ?>
            <a href="<?php echo esc_url($has_primary_action ? $primary_action_url : $external_url); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" data-nexdirectory-analytics-metric="<?php echo esc_attr($primary_cta_metric); ?>" data-nexdirectory-track-event-id="<?php echo esc_attr((string) $post_id); ?>" aria-label="<?php echo esc_attr($has_primary_action ? $primary_action_label : $single_visit_site_cta); ?>" class="<?php echo $has_message_button ? 'flex items-center justify-center w-12 bg-gray-900 active:bg-black active:scale-95 text-white font-bold rounded-xl py-3.5 transition-all duration-200 shadow-sm' : 'flex-1 flex items-center justify-center gap-2 bg-gray-900 active:bg-black active:scale-95 text-white font-bold rounded-xl py-3.5 px-4 transition-all duration-200 shadow-sm'; ?>">
                <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="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 if (!$has_message_button) : ?>
                    <span><?php echo esc_html($has_primary_action ? $primary_action_label : $single_visit_site_cta); ?></span>
                <?php endif; ?>
            </a>
        <?php endif; ?>
    </div>

    <?php if ($hero_calendar_interactive) : ?>
    <div x-show="showCalendarModal" x-cloak hidden :hidden="!showCalendarModal" style="display: none;" class="fixed inset-0 z-[101] flex items-center justify-center p-4 sm:p-6">
        <div x-show="showCalendarModal" x-transition.opacity class="absolute inset-0 bg-gray-900/75 backdrop-blur-sm" @click="showCalendarModal = false"></div>
        <div x-show="showCalendarModal"
             x-transition:enter="transition ease-out duration-250"
             x-transition:enter-start="opacity-0 translate-y-4 scale-95"
             x-transition:enter-end="opacity-100 translate-y-0 scale-100"
             x-transition:leave="transition ease-in duration-200"
             x-transition:leave-start="opacity-100 translate-y-0 scale-100"
             x-transition:leave-end="opacity-0 translate-y-3 scale-95"
             class="relative w-full max-w-md bg-white rounded-2xl shadow-2xl border border-gray-100 overflow-hidden">
            <div class="flex items-center justify-between px-5 py-4 border-b border-gray-100 bg-gray-50">
                <h3 class="text-base sm:text-lg font-bold text-gray-900"><?php esc_html_e('Add to Calendar', 'nexdirectory'); ?></h3>
                <button type="button" @click="showCalendarModal = false" class="p-2 rounded-lg bg-white border border-gray-200 text-gray-500 hover:text-gray-900 hover:bg-gray-50 transition-colors" aria-label="<?php esc_attr_e('Close calendar options', 'nexdirectory'); ?>">
                    <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 space-y-3">
                <a href="<?php echo esc_url((string) $calendar_primary_url); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" class="w-full flex items-center justify-center gap-2 py-3 px-4 bg-brand-600 hover:bg-brand-700 active:scale-95 text-white text-sm font-semibold rounded-xl transition-all shadow-sm">
                    <svg class="w-5 h-5 text-white" 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((string) $calendar_primary_label); ?>
                </a>
                <?php if ($calendar_secondary_url !== '') : ?>
                    <a href="<?php echo esc_url((string) $calendar_secondary_url); ?>" target="_blank" rel="noopener noreferrer nofollow ugc" class="w-full flex items-center justify-center gap-2 py-3 px-4 bg-white hover:bg-gray-50 border border-gray-200 text-gray-700 active:scale-95 text-sm font-semibold rounded-xl transition-all shadow-sm">
                        <svg class="w-5 h-5 text-gray-500" 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((string) $calendar_secondary_label); ?>
                    </a>
                <?php endif; ?>
            </div>
        </div>
    </div>
    <?php endif; ?>

    <?php if ($map_link !== '' && !empty($map_embed_url)) : ?>
    <div x-show="showMapModal" x-cloak hidden :hidden="!showMapModal" style="display: none;" class="fixed inset-0 z-[100] flex items-center justify-center p-4 sm:p-6">
        <div x-show="showMapModal" x-transition.opacity class="absolute inset-0 bg-gray-900/80 backdrop-blur-sm" @click="showMapModal = false"></div>
        <div x-show="showMapModal" 
             x-transition:enter="transition ease-out duration-300" 
             x-transition:enter-start="opacity-0 scale-95" 
             x-transition:enter-end="opacity-100 scale-100"
             x-transition:leave="transition ease-in duration-200"
             x-transition:leave-start="opacity-100 scale-100"
             x-transition:leave-end="opacity-0 scale-95"
             class="relative w-full max-w-4xl h-[70vh] bg-white rounded-2xl shadow-2xl overflow-hidden flex flex-col">
            
            <div class="flex items-center justify-between p-4 border-b border-gray-100 absolute top-0 left-0 right-0 bg-white/95 backdrop-blur z-10">
                <h3 class="text-base font-bold text-gray-900 px-2 truncate"><?php echo esc_html((string) $venue_label); ?></h3>
                <div class="flex items-center gap-3 shrink-0">
                    <a target="_blank" rel="noopener noreferrer nofollow ugc" href="<?php echo esc_url((string) $map_link); ?>" class="hidden sm:inline-block text-xs font-bold text-brand-600 hover:text-brand-700 bg-brand-50 hover:bg-brand-100 px-4 py-2 rounded-lg transition-colors">Open in Google Maps</a>
                    <button type="button" @click="showMapModal = false" class="text-gray-400 hover:text-gray-900 transition-colors p-2 bg-gray-100 hover:bg-gray-200 rounded-lg" aria-label="<?php esc_attr_e('Close map', 'nexdirectory'); ?>">
                        <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>
            
            <iframe :src="showMapModal ? '<?php echo esc_url((string) $map_embed_url); ?>' : ''" title="<?php echo esc_attr($map_iframe_title); ?>" class="w-full h-full border-0 pt-[60px] block"></iframe>
        </div>
    </div>
    <?php endif; ?>

    <?php if ($show_timeline && !empty($sessions_grouped)) : ?>
    <div x-show="showItineraryModal" x-cloak hidden :hidden="!showItineraryModal" style="display: none;" class="fixed inset-0 z-[106] flex items-center justify-center p-4 sm:p-6">
        <div x-show="showItineraryModal" x-transition.opacity class="absolute inset-0 bg-gray-900/80 backdrop-blur-sm" @click="showItineraryModal = false"></div>
        <div x-show="showItineraryModal"
             x-transition:enter="transition ease-out duration-300"
             x-transition:enter-start="opacity-0 translate-y-4 scale-95"
             x-transition:enter-end="opacity-100 translate-y-0 scale-100"
             x-transition:leave="transition ease-in duration-200"
             x-transition:leave-start="opacity-100 translate-y-0 scale-100"
             x-transition:leave-end="opacity-0 translate-y-3 scale-95"
             class="relative w-full max-w-4xl max-h-[85vh] bg-white rounded-2xl shadow-2xl border border-gray-100 overflow-hidden flex flex-col">
            <div class="flex items-center justify-between px-5 py-4 border-b border-gray-100 bg-gray-50">
                <h3 class="text-base sm:text-lg font-bold text-gray-900"><?php esc_html_e('Full Itinerary', 'nexdirectory'); ?></h3>
                <button type="button" @click="showItineraryModal = false" class="p-2 rounded-lg bg-white border border-gray-200 text-gray-500 hover:text-gray-900 hover:bg-gray-50 transition-colors" aria-label="<?php esc_attr_e('Close itinerary', 'nexdirectory'); ?>">
                    <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 space-y-5">
                <?php foreach ($sessions_grouped as $day_group_index => $day_group) : ?>
                    <?php
                    $day_key = sanitize_text_field((string) ($day_group['day_key'] ?? ('day-' . ((int) $day_group_index + 1))));
                    $day_label = sanitize_text_field((string) ($day_group['day_label'] ?? __('Schedule', 'nexdirectory')));
                    $day_sessions = isset($day_group['sessions']) && is_array($day_group['sessions']) ? array_values($day_group['sessions']) : [];
                    ?>
                    <div x-show="itineraryModalDay === '<?php echo esc_js($day_key); ?>'" style="display: none;">
                        <h4 class="text-base sm:text-lg font-bold text-gray-900 mb-4"><?php echo esc_html($day_label); ?></h4>
                        <div class="space-y-4">
                            <?php foreach ($day_sessions as $session_index => $session_row) : ?>
                                <?php
                                $session_title = sanitize_text_field((string) ($session_row['title'] ?? ''));
                                if ($session_title === '') {
                                    /* translators: %d: Placeholder value. */
                                    $session_title = sprintf(__('Session %d', 'nexdirectory'), ((int) $session_index) + 1);
                                }
                                $session_uid = sanitize_key((string) ($session_row['session_uid'] ?? ''));
                                $session_time = sanitize_text_field((string) ($session_row['time'] ?? ''));
                                $session_location = sanitize_text_field((string) ($session_row['location'] ?? ''));
                                $session_speaker = sanitize_text_field((string) ($session_row['speaker'] ?? ''));
                                $session_attachments = isset($session_row['attachments']) && is_array($session_row['attachments']) ? array_values(array_filter(array_map('esc_url', $session_row['attachments']))) : [];
                                ?>
                                <article :class="isItinerarySaved('<?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/60'" class="rounded-xl border p-4 sm:p-5">
                                    <div class="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-3">
                                        <h5 class="text-base font-bold text-gray-900"><?php echo esc_html($session_title); ?></h5>
                                        <div class="flex flex-wrap items-center gap-2">
                                            <?php if ($viewer_logged_in) : ?>
                                                <button type="button" @click.prevent.stop="toggleItinerarySave('<?php echo esc_js($session_uid); ?>')" :class="isItinerarySaved('<?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="!isItinerarySaved('<?php echo esc_js($session_uid); ?>')"><?php esc_html_e('Add to list', 'nexdirectory'); ?></span>
                                                    <span x-show="isItinerarySaved('<?php echo esc_js($session_uid); ?>')" style="display:none;"><?php esc_html_e('Saved', 'nexdirectory'); ?></span>
                                                </button>
                                                <button type="button" @click="openItineraryNoteModal('<?php echo esc_js($session_uid); ?>')" :class="hasItineraryNote('<?php echo esc_js($session_uid); ?>') ? 'bg-amber-50 text-amber-700 border-amber-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="!hasItineraryNote('<?php echo esc_js($session_uid); ?>')"><?php esc_html_e('Add note', 'nexdirectory'); ?></span>
                                                    <span x-show="hasItineraryNote('<?php echo esc_js($session_uid); ?>')" style="display:none;"><?php esc_html_e('Edit note', 'nexdirectory'); ?></span>
                                                </button>
                                            <?php else : ?>
                                                <a href="<?php echo esc_url($login_url); ?>" class="inline-flex items-center gap-1 px-3 py-1.5 rounded-md text-xs font-semibold border border-brand-200 bg-brand-50 text-brand-700 hover:bg-brand-100 transition-colors">
                                                    <?php esc_html_e('Sign in to save itinerary', 'nexdirectory'); ?>
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="mt-2 space-y-1.5 text-sm text-gray-600">
                                        <?php if ($session_time !== '') : ?>
                                            <p><span class="font-semibold text-gray-900"><?php esc_html_e('Time:', 'nexdirectory'); ?></span> <?php echo esc_html($session_time); ?></p>
                                        <?php endif; ?>
                                        <?php if ($session_location !== '') : ?>
                                            <p><span class="font-semibold text-gray-900"><?php esc_html_e('Location:', 'nexdirectory'); ?></span> <?php echo esc_html($session_location); ?></p>
                                        <?php endif; ?>
                                        <?php if ($session_speaker !== '') : ?>
                                            <p><span class="font-semibold text-gray-900"><?php esc_html_e('Speaker:', 'nexdirectory'); ?></span> <?php echo esc_html($session_speaker); ?></p>
                                        <?php endif; ?>
                                    </div>
                                    <template x-if="viewerLoggedIn && hasItineraryNote('<?php echo esc_js($session_uid); ?>')">
                                        <div class="mt-3 p-3 rounded-lg border border-yellow-200 bg-yellow-50/80 text-sm text-yellow-900 whitespace-pre-wrap" x-text="getItineraryNote('<?php echo esc_js($session_uid); ?>')"></div>
                                    </template>
                                    <?php if (!empty($session_attachments)) : ?>
                                        <div class="mt-3 flex flex-wrap gap-2" data-nexdirectory-custom-gallery="session-modal-<?php echo esc_attr($day_key . '-' . $session_index); ?>">
                                            <?php foreach ($session_attachments as $attachment_index => $attachment_url) : ?>
                                                <?php
                                                $attachment_path = strtolower((string) wp_parse_url($attachment_url, PHP_URL_PATH));
                                                $attachment_ext = strtolower((string) pathinfo($attachment_path, PATHINFO_EXTENSION));
                                                $attachment_name = sanitize_text_field((string) basename($attachment_path));
                                                if ($attachment_name === '') {
                                                    /* translators: %d: Placeholder value. */
                                                    $attachment_name = sprintf(__('Attachment %d', 'nexdirectory'), $attachment_index + 1);
                                                }
                                                $is_image_attachment = in_array($attachment_ext, ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'avif', 'svg'], true);
                                                $is_embedded_video_attachment = (bool) preg_match('/(youtube\.com|youtu\.be|vimeo\.com)/i', (string) $attachment_url);
                                                $is_video_attachment = in_array($attachment_ext, ['mp4', 'webm', 'ogg', 'mov', 'm4v'], true) || $is_embedded_video_attachment;
                                                if ($is_embedded_video_attachment) {
                                                    $attachment_name = __('Watch video', 'nexdirectory');
                                                }
                                                $is_pdf_attachment = $attachment_ext === 'pdf';
                                                ?>
                                                <?php if ($is_image_attachment) : ?>
                                                    <button type="button" class="nexdirectory-gallery-item inline-flex items-center px-3 py-1.5 rounded-lg border border-gray-200 bg-gray-50 text-xs font-medium text-gray-700 hover:bg-gray-100 transition-colors" data-nexdirectory-lightbox="<?php echo esc_url($attachment_url); ?>">
                                                        <?php echo esc_html($attachment_name); ?>
                                                    </button>
                                                <?php elseif ($is_video_attachment) : ?>
                                                    <button type="button" class="inline-flex items-center px-3 py-1.5 rounded-lg border border-gray-200 bg-gray-50 text-xs font-medium text-gray-700 hover:bg-gray-100 transition-colors" data-nexdirectory-video-url="<?php echo esc_url($attachment_url); ?>">
                                                        <?php echo esc_html($attachment_name); ?>
                                                    </button>
                                                <?php else : ?>
                                                    <button type="button" class="inline-flex items-center px-3 py-1.5 rounded-lg border border-gray-200 bg-gray-50 text-xs font-medium text-gray-700 hover:bg-gray-100 transition-colors" data-nexdirectory-doc-url="<?php echo esc_url($attachment_url); ?>" data-nexdirectory-doc-title="<?php echo esc_attr($attachment_name); ?>" data-nexdirectory-doc-embed="<?php echo $is_pdf_attachment ? esc_url($attachment_url) : ''; ?>">
                                                        <?php echo esc_html($attachment_name); ?>
                                                    </button>
                                                <?php endif; ?>
                                            <?php endforeach; ?>
                                        </div>
                                    <?php endif; ?>
                                </article>
                            <?php endforeach; ?>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </div>
    </div>
    <?php endif; ?>

    <?php if ($show_timeline && !empty($sessions_grouped) && $viewer_logged_in) : ?>
    <div x-show="itineraryNoteModalOpen" x-cloak hidden :hidden="!itineraryNoteModalOpen" style="display: none;" class="fixed inset-0 z-[107] flex items-center justify-center p-4 sm:p-6">
        <div x-show="itineraryNoteModalOpen" x-transition.opacity class="absolute inset-0 bg-gray-900/70 backdrop-blur-sm" @click="closeItineraryNoteModal()"></div>
        <div x-show="itineraryNoteModalOpen"
             x-transition:enter="transition ease-out duration-250"
             x-transition:enter-start="opacity-0 translate-y-3 scale-95"
             x-transition:enter-end="opacity-100 translate-y-0 scale-100"
             x-transition:leave="transition ease-in duration-180"
             x-transition:leave-start="opacity-100 translate-y-0 scale-100"
             x-transition:leave-end="opacity-0 translate-y-2 scale-95"
             class="relative w-full max-w-xl bg-white rounded-2xl shadow-2xl border border-gray-100 overflow-hidden">
            <div class="flex items-center justify-between px-5 py-4 border-b border-gray-100 bg-gray-50">
                <h3 class="text-base sm:text-lg font-bold text-gray-900"><?php esc_html_e('Session Note', 'nexdirectory'); ?></h3>
                <button type="button" @click="closeItineraryNoteModal()" class="p-2 rounded-lg bg-white border border-gray-200 text-gray-500 hover:text-gray-900 hover:bg-gray-50 transition-colors" aria-label="<?php esc_attr_e('Close session note', 'nexdirectory'); ?>">
                    <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">
                <textarea x-model="itineraryNoteText" rows="6" placeholder="<?php esc_attr_e('Write your note for this session...', 'nexdirectory'); ?>" class="w-full px-4 py-3 border border-gray-200 rounded-xl text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500 outline-none resize-y"></textarea>
                <div class="mt-4 flex items-center justify-end gap-2">
                    <button type="button" @click="closeItineraryNoteModal()" class="inline-flex items-center justify-center px-4 py-2.5 bg-white border border-gray-200 text-gray-700 text-sm font-semibold rounded-xl hover:bg-gray-50 transition-colors">
                        <?php esc_html_e('Cancel', 'nexdirectory'); ?>
                    </button>
                    <button type="button" @click="saveItineraryNote()" class="inline-flex items-center justify-center px-4 py-2.5 bg-brand-600 border border-brand-600 text-white text-sm font-semibold rounded-xl hover:bg-brand-700 transition-colors">
                        <?php esc_html_e('Save Note', 'nexdirectory'); ?>
                    </button>
                </div>
            </div>
        </div>
    </div>
    <?php endif; ?>

    <?php if ($show_key_speakers && $has_more_key_speakers) : ?>
    <div x-show="showSpeakersModal" x-cloak hidden :hidden="!showSpeakersModal" style="display: none;" class="fixed inset-0 z-[106] flex items-center justify-center p-4 sm:p-6">
        <div x-show="showSpeakersModal" x-transition.opacity class="absolute inset-0 bg-gray-900/80 backdrop-blur-sm" @click="showSpeakersModal = false"></div>
        <div x-show="showSpeakersModal"
             x-transition:enter="transition ease-out duration-300"
             x-transition:enter-start="opacity-0 translate-y-4 scale-95"
             x-transition:enter-end="opacity-100 translate-y-0 scale-100"
             x-transition:leave="transition ease-in duration-200"
             x-transition:leave-start="opacity-100 translate-y-0 scale-100"
             x-transition:leave-end="opacity-0 translate-y-3 scale-95"
             class="relative w-full max-w-4xl max-h-[85vh] bg-white rounded-2xl shadow-2xl border border-gray-100 overflow-hidden flex flex-col">
            <div class="flex items-center justify-between px-5 py-4 border-b border-gray-100 bg-gray-50">
                <h3 class="text-base sm:text-lg font-bold text-gray-900"><?php echo esc_html($single_key_speakers_heading); ?></h3>
                <button type="button" @click="showSpeakersModal = false" class="p-2 rounded-lg bg-white border border-gray-200 text-gray-500 hover:text-gray-900 hover:bg-gray-50 transition-colors" aria-label="<?php esc_attr_e('Close speakers', 'nexdirectory'); ?>">
                    <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">
                <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                    <?php foreach ($key_speakers as $speaker_row) : ?>
                        <?php
                        $speaker_name = sanitize_text_field((string) ($speaker_row['name'] ?? ''));
                        $speaker_profession = sanitize_text_field((string) ($speaker_row['profession'] ?? ''));
                        $speaker_subject = sanitize_text_field((string) ($speaker_row['subject'] ?? ''));
                        $speaker_details = nexdirectory_sanitize_textarea((string) ($speaker_row['details'] ?? ''));
                        $speaker_image = esc_url((string) ($speaker_row['image'] ?? ''));
                        if ($speaker_name === '' && $speaker_profession === '' && $speaker_subject === '' && $speaker_details === '' && $speaker_image === '') {
                            continue;
                        }
                        ?>
                        <article class="rounded-xl border border-gray-200 bg-gray-50/60 p-4 sm:p-5 shadow-sm">
                            <div class="flex items-start gap-3">
                                <?php if ($speaker_image !== '') : ?>
                                    <img src="<?php echo esc_url($speaker_image); ?>" alt="<?php echo esc_attr($speaker_name !== '' ? $speaker_name : __('Speaker', 'nexdirectory')); ?>" class="w-14 h-14 rounded-xl object-cover border border-gray-200 shadow-sm shrink-0">
                                <?php else : ?>
                                    <div class="w-14 h-14 rounded-xl bg-brand-50 text-brand-600 border border-brand-100 shadow-sm shrink-0 flex items-center justify-center">
                                        <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" 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>
                                    </div>
                                <?php endif; ?>
                                <div class="min-w-0 flex-1">
                                    <?php if ($speaker_name !== '') : ?>
                                        <h3 class="text-base font-bold text-gray-900 leading-tight"><?php echo esc_html($speaker_name); ?></h3>
                                    <?php endif; ?>
                                    <?php if ($speaker_profession !== '') : ?>
                                        <p class="text-sm text-gray-500 mt-1"><?php echo esc_html($speaker_profession); ?></p>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <?php if ($speaker_subject !== '') : ?>
                                <p class="mt-3 inline-flex items-center px-2.5 py-1 rounded-full text-xs font-semibold text-brand-700 bg-brand-50 border border-brand-100"><?php echo esc_html($speaker_subject); ?></p>
                            <?php endif; ?>
                            <?php if ($speaker_details !== '') : ?>
                                <p class="mt-3 text-sm text-gray-600 leading-relaxed"><?php echo esc_html($speaker_details); ?></p>
                            <?php endif; ?>
                        </article>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
    </div>
    <?php endif; ?>

    <?php if ($ticketing_pro_enabled) : ?>
        <?php do_action('nexdirectory_render_extension_single_ticket_overlays', $this, (int) $post_id); ?>
    <?php endif; ?>

    <?php if ($message_button_mode === 'modal') : ?>
    <div x-show="messageModalOpen" x-cloak hidden :hidden="!messageModalOpen" style="display: none;" class="fixed inset-0 z-[105] flex items-center justify-center p-4 sm:p-6">
        <div x-show="messageModalOpen" x-transition.opacity class="absolute inset-0 bg-gray-900/70 backdrop-blur-sm" @click="messageModalOpen = false"></div>
        <div x-show="messageModalOpen"
             x-transition:enter="transition ease-out duration-250"
             x-transition:enter-start="opacity-0 translate-y-4 scale-95"
             x-transition:enter-end="opacity-100 translate-y-0 scale-100"
             x-transition:leave="transition ease-in duration-200"
             x-transition:leave-start="opacity-100 translate-y-0 scale-100"
             x-transition:leave-end="opacity-0 translate-y-3 scale-95"
             class="relative w-full max-w-lg bg-white rounded-2xl shadow-2xl border border-gray-100 overflow-hidden">
            <div class="flex items-center justify-between px-5 py-4 border-b border-gray-100 bg-gray-50">
                <div>
                    <h3 class="text-base sm:text-lg font-bold text-gray-900">
                        <?php
                        if ($message_targets_admin) {
                            esc_html_e('Message Admin Team', 'nexdirectory');
                        } else {
                            /* translators: %s: Placeholder value. */
                            echo esc_html(sprintf(__('Message %s', 'nexdirectory'), $owner_heading));
                        }
                        ?>
                    </h3>
                    <p class="text-xs text-gray-500 mt-0.5">
                        <?php
                        if ($message_targets_admin) {
                            esc_html_e('Send a private message to the platform admin inbox.', 'nexdirectory');
                        } else {
                            echo esc_html(sprintf(
                                /* translators: %s: Placeholder value. */
                                __('Directly contact %s', 'nexdirectory'),
                                (string) ($owner_display_name !== '' ? $owner_display_name : __('Listing Owner', 'nexdirectory'))
                            ));
                        }
                        ?>
                    </p>
                </div>
                <button type="button" @click="messageModalOpen = false" class="p-2 rounded-lg bg-white border border-gray-200 text-gray-500 hover:text-gray-900 hover:bg-gray-50 transition-colors" aria-label="<?php esc_attr_e('Close message form', 'nexdirectory'); ?>">
                    <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>
            <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" class="p-5 space-y-4" x-data="{ sending: false }" @submit="sending = true">
                <input type="hidden" name="action" value="nexdirectory_contact_holder">
                <input type="hidden" name="post_id" value="<?php echo esc_attr((string) $post_id); ?>">
                <input type="hidden" name="nexdirectory_recaptcha_token" class="nexdirectory-recaptcha-token" value="">
                <input type="hidden" name="nexdirectory_inbox_only" value="1">
                <input type="hidden" name="nexdirectory_contact_target" value="<?php echo esc_attr($message_targets_admin ? 'admin' : 'owner'); ?>">
                <?php echo wp_kses((string) $contact_nonce_html, NEXDIRECTORY_Escaping::allowed_html()); ?>
                <div>
                    <label class="block text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2" for="nexdirectory-contact-subject"><?php esc_html_e('Subject', 'nexdirectory'); ?></label>
                    <input id="nexdirectory-contact-subject" type="text" name="subject" maxlength="160" required value="<?php echo esc_attr((string) $message_default_subject); ?>" class="w-full px-4 py-2.5 rounded-xl border border-gray-200 text-sm focus:ring-2 focus:ring-brand-500/20 focus:border-brand-500 outline-none transition-colors">
                </div>
                <div>
                    <label class="block text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2" for="nexdirectory-contact-message"><?php esc_html_e('Message', 'nexdirectory'); ?></label>
                    <textarea id="nexdirectory-contact-message" name="message" rows="5" required placeholder="<?php esc_attr_e('Write your message...', 'nexdirectory'); ?>" class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm focus:ring-2 focus:ring-brand-500/20 focus:border-brand-500 outline-none transition-colors"></textarea>
                </div>
                <div class="flex items-center gap-3 pt-1">
                    <button type="submit" :disabled="sending" class="inline-flex items-center justify-center gap-2 px-4 py-2.5 bg-brand-500 hover:bg-brand-600 disabled:opacity-70 text-white text-sm font-semibold rounded-xl transition-colors">
                        <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 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.214-3.64A7.952 7.952 0 013 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"></path></svg>
                        <span x-show="!sending"><?php esc_html_e('Send Message', 'nexdirectory'); ?></span>
                        <span x-show="sending" style="display: none;"><?php esc_html_e('Sending...', 'nexdirectory'); ?></span>
                    </button>
                    <button type="button" @click="messageModalOpen = false" class="inline-flex items-center justify-center px-4 py-2.5 bg-white border border-gray-200 text-gray-700 text-sm font-semibold rounded-xl hover:bg-gray-50 transition-colors">
                        <?php esc_html_e('Cancel', 'nexdirectory'); ?>
                    </button>
                </div>
            </form>
        </div>
    </div>
    <?php endif; ?>

    <div id="nexdirectory-doc-lightbox" class="nexdirectory-lightbox fixed inset-0 z-[110] flex items-center justify-center p-4 sm:p-6 md:p-10 bg-gray-900/80 backdrop-blur-sm" hidden>
        <div class="relative w-full max-w-5xl h-[85vh] bg-gray-50 rounded-2xl shadow-2xl overflow-hidden flex flex-col">
            <div class="flex items-center justify-between p-4 border-b border-gray-200 bg-white z-10 relative">
                <div class="flex items-center gap-3 px-2 min-w-0">
                    <div class="w-10 h-10 rounded-lg bg-brand-50 text-brand-600 flex items-center justify-center shrink-0">
                        <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="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
                    </div>
                    <h3 id="nexdirectory-doc-lightbox-title" class="text-base font-bold text-gray-900 truncate max-w-[200px] sm:max-w-md">Document</h3>
                </div>
                <div class="flex items-center gap-3 shrink-0">
                    <button type="button" id="nexdirectory-doc-lightbox-prev" class="hidden sm:inline-flex items-center justify-center p-2 rounded-lg border border-gray-200 bg-white hover:bg-gray-50 text-gray-600" aria-label="<?php esc_attr_e('Previous document', 'nexdirectory'); ?>">
                        <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 19l-7-7 7-7"></path></svg>
                    </button>
                    <button type="button" id="nexdirectory-doc-lightbox-next" class="hidden sm:inline-flex items-center justify-center p-2 rounded-lg border border-gray-200 bg-white hover:bg-gray-50 text-gray-600" aria-label="<?php esc_attr_e('Next document', 'nexdirectory'); ?>">
                        <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="M9 5l7 7-7 7"></path></svg>
                    </button>
                    <a id="nexdirectory-doc-lightbox-download" data-nexdirectory-doc-download="1" href="#" download target="_blank" rel="noopener noreferrer nofollow ugc" class="hidden sm:flex items-center gap-2 text-sm font-semibold text-gray-700 bg-gray-100 hover:bg-gray-200 active:scale-95 px-4 py-2 rounded-lg transition-all duration-200 border border-gray-200 shadow-sm hover:shadow">
                        <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="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path></svg>
                        Download
                    </a>
                    <button type="button" id="nexdirectory-doc-lightbox-close" class="text-gray-400 hover:text-gray-900 transition-colors p-2 bg-gray-100 hover:bg-gray-200 rounded-lg border border-gray-200" aria-label="<?php esc_attr_e('Close document preview', 'nexdirectory'); ?>">
                        <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>
            <div class="flex-1 w-full bg-gray-200 relative overflow-hidden flex">
                <div class="absolute inset-0 flex items-center justify-center text-gray-400 pointer-events-none">
                    <svg class="animate-spin h-8 w-8" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>
                </div>
                <iframe id="nexdirectory-doc-lightbox-iframe" src="about:blank" title="<?php esc_attr_e('Document preview', 'nexdirectory'); ?>" class="absolute inset-0 w-full h-full border-0 z-10 bg-transparent block"></iframe>
            </div>
            <div class="sm:hidden p-4 bg-white border-t border-gray-200 z-10 shadow-[0_-4px_6px_-1px_rgba(0,0,0,0.05)]">
                <a data-nexdirectory-doc-download="1" href="#" download target="_blank" rel="noopener noreferrer nofollow ugc" class="flex w-full items-center justify-center gap-2 text-sm font-semibold text-gray-700 bg-gray-50 hover:bg-gray-100 active:scale-95 px-5 py-3 rounded-xl transition-all duration-200 border border-gray-200 shadow-sm">
                    <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="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path></svg>
                    Download Document
                </a>
            </div>
        </div>
    </div>

    <div id="nexdirectory-video-lightbox" class="nexdirectory-lightbox fixed inset-0 z-[110] flex items-center justify-center p-4 sm:p-6 md:p-10 bg-gray-900/95 backdrop-blur-sm" hidden>
        <div class="relative w-full max-w-5xl aspect-video bg-black rounded-2xl shadow-2xl overflow-hidden flex flex-col">
            <button type="button" id="nexdirectory-video-lightbox-close" class="absolute top-4 right-4 z-20 text-white/70 hover:text-white bg-black/50 hover:bg-black/70 rounded-full p-2 transition-colors focus:outline-none" aria-label="<?php esc_attr_e('Close video', 'nexdirectory'); ?>">
                <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" d="M6 18L18 6M6 6l12 12"></path></svg>
            </button>
            <button type="button" id="nexdirectory-video-lightbox-prev" class="absolute left-3 top-1/2 -translate-y-1/2 z-20 text-white/70 hover:text-white bg-black/50 hover:bg-black/70 rounded-full p-2 transition-colors focus:outline-none" aria-label="<?php esc_attr_e('Previous video', 'nexdirectory'); ?>">
                <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>
            <button type="button" id="nexdirectory-video-lightbox-next" class="absolute right-3 top-1/2 -translate-y-1/2 z-20 text-white/70 hover:text-white bg-black/50 hover:bg-black/70 rounded-full p-2 transition-colors focus:outline-none" aria-label="<?php esc_attr_e('Next video', 'nexdirectory'); ?>">
                <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="M9 5l7 7-7 7"></path></svg>
            </button>
            <div class="sm:hidden absolute inset-y-0 left-0 w-[34%] z-[15]" data-nexdirectory-video-swipe-zone="left" aria-hidden="true"></div>
            <div class="sm:hidden absolute inset-y-0 right-0 w-[34%] z-[15]" data-nexdirectory-video-swipe-zone="right" aria-hidden="true"></div>
            <iframe id="nexdirectory-video-lightbox-iframe" src="about:blank" title="<?php esc_attr_e('Video player', 'nexdirectory'); ?>" class="w-full h-full border-0 absolute inset-0 z-10 bg-black block" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        </div>
    </div>

    <div id="nexdirectory-lightbox" class="nexdirectory-lightbox fixed inset-0 z-[120] flex items-center justify-center bg-black/95 backdrop-blur-md p-4" hidden>
        <button type="button" id="nexdirectory-lightbox-close" class="absolute top-4 right-4 sm:top-6 sm:right-6 text-white/50 hover:text-white transition-colors z-20 focus:outline-none p-2 bg-white/5 hover:bg-white/10 rounded-full" aria-label="<?php esc_attr_e('Close image', 'nexdirectory'); ?>">
            <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="M6 18L18 6M6 6l12 12"></path></svg>
        </button>

        <button type="button" id="nexdirectory-lightbox-prev" class="absolute left-2 sm:left-6 top-1/2 -translate-y-1/2 text-white/50 hover:text-white transition-all z-20 focus:outline-none p-2 bg-black/20 hover:bg-black/40 rounded-full hover:scale-110 active:scale-95" aria-label="<?php esc_attr_e('Previous image', 'nexdirectory'); ?>">
            <svg class="w-8 h-8 sm:w-10 sm:h-10" 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>

        <button type="button" id="nexdirectory-lightbox-next" class="absolute right-2 sm:right-6 top-1/2 -translate-y-1/2 text-white/50 hover:text-white transition-all z-20 focus:outline-none p-2 bg-black/20 hover:bg-black/40 rounded-full hover:scale-110 active:scale-95" aria-label="<?php esc_attr_e('Next image', 'nexdirectory'); ?>">
            <svg class="w-8 h-8 sm:w-10 sm:h-10" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path></svg>
        </button>

        <div class="relative w-full h-full flex items-center justify-center pointer-events-none">
            <img id="nexdirectory-lightbox-image" src="<?php echo esc_url(plugins_url('assets/images/placeholder-hero.svg', NEXDIRECTORY_PLUGIN_FILE)); ?>" class="max-w-full max-h-full object-contain shadow-2xl pointer-events-auto rounded-lg" alt="<?php esc_attr_e('Gallery image preview', 'nexdirectory'); ?>">
        </div>
    </div>

</div>
