<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound, WordPress.WP.GlobalVariablesOverride.Prohibited -- False positives: locally-scoped variables (template view-vars via TemplateLoader::render() extract+include within a method, or closure locals), not plugin globals.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/**
 * System Status page.
 *
 * @var array  $db_status
 * @var array  $cron_status
 * @var array  $api_status
 * @var array  $integration_status
 * @var array  $settings_status
 * @var array  $dashboard_status
 * @var array  $environment_status
 * @var array  $license_status
 * @var array  $generic_status
 * @var array  $services_cache_status
 * @var array  $support_checks
 * @var array  $launch_readiness
 * @var string $support_share_summary
 * @var string $launch_blocker_quick_summary
 * @var string $launch_blocker_summary
 * @var string $launch_handoff_subject
 * @var string $launch_handoff_message
 * @var string $report
 * @var string $export_json
 * @var string $support_bundle_json
 * @var array  $generic_readiness_summary
 * @var array  $lane_summary
 */
$support_checks = ( isset( $support_checks ) && is_array( $support_checks ) ) ? $support_checks : [];
$generic_validation_prompt = ( isset( $generic_validation_prompt ) && is_array( $generic_validation_prompt ) ) ? $generic_validation_prompt : [];
$generic_readiness_summary = ( isset( $generic_readiness_summary ) && is_array( $generic_readiness_summary ) ) ? $generic_readiness_summary : [];
$generic_readiness_state = sanitize_key( (string) ( $generic_readiness_summary['state'] ?? 'info' ) );
if ( ! in_array( $generic_readiness_state, [ 'ok', 'warn', 'error', 'info' ], true ) ) {
    $generic_readiness_state = 'info';
}
$generic_readiness_state_label = trim( (string) ( $generic_readiness_summary['state_label'] ?? '' ) );
if ( '' === $generic_readiness_state_label ) {
    $generic_readiness_state_labels = [
        'ok' => __( 'Ready', 'mybookaro' ),
        'warn' => __( 'Review needed', 'mybookaro' ),
        'error' => __( 'Blocked', 'mybookaro' ),
        'info' => __( 'Info', 'mybookaro' ),
    ];
    $generic_readiness_state_label = (string) ( $generic_readiness_state_labels[ $generic_readiness_state ] ?? __( 'Info', 'mybookaro' ) );
}
$generic_readiness_compact_summary = trim( (string) ( $generic_readiness_summary['summary'] ?? '' ) );
$generic_readiness_validation_level = sanitize_key( (string) ( $generic_readiness_summary['validation_state_level'] ?? 'info' ) );
if ( ! in_array( $generic_readiness_validation_level, [ 'ok', 'warn', 'error', 'info' ], true ) ) {
    $generic_readiness_validation_level = 'info';
}
$generic_validation_refresh_required = ! empty( $generic_validation_prompt['needs_validation'] );
$support_failed_count = count( array_filter(
    $support_checks,
    static function ( array $check ): bool {
        return ! empty( $check['needs_fix'] );
    }
) );
$generic_validation_failed_count = count( array_filter(
    $support_checks,
    static function ( array $check ): bool {
        if ( ! is_array( $check ) ) {
            return false;
        }
        $check_id = sanitize_key( (string) ( $check['id'] ?? '' ) );
        if ( 0 !== strpos( $check_id, 'generic_validation_' ) ) {
            return false;
        }
        $state = sanitize_key( (string) ( $check['state'] ?? '' ) );
        if ( ! in_array( $state, [ 'warn', 'error' ], true ) ) {
            return false;
        }
        return ! empty( $check['needs_fix'] );
    }
) );
$schema_ok = ! empty( $db_status['schema_ok'] );
$schema_label = $schema_ok ? __( 'OK', 'mybookaro' ) : __( 'Upgrade required', 'mybookaro' );
$schema_class = $schema_ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--error';
$wp_cron_ok = empty( $cron_status['wp_cron_disabled'] );
$wp_cron_label = $wp_cron_ok ? __( 'Enabled', 'mybookaro' ) : __( 'Disabled', 'mybookaro' );
$wp_cron_class = $wp_cron_ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--error';
$auto_complete_ok = ! empty( $cron_status['auto_complete_scheduled'] );
$auto_complete_label = $auto_complete_ok ? __( 'Scheduled', 'mybookaro' ) : __( 'Not scheduled', 'mybookaro' );
$auto_complete_class = $auto_complete_ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--warn';
$rest_ok = ! empty( $api_status['rest_ok'] );
$rest_label = $rest_ok ? __( 'Reachable', 'mybookaro' ) : __( 'Unreachable', 'mybookaro' );
$rest_class = $rest_ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--error';
$ajax_ok = ! empty( $api_status['ajax_ok'] );
$ajax_label = $ajax_ok ? __( 'Available', 'mybookaro' ) : __( 'Unavailable', 'mybookaro' );
$ajax_class = $ajax_ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--error';
$mylisting_active = ! empty( $integration_status['mylisting_detected'] );
$mylisting_hook_ok = ! empty( $integration_status['mylisting_hook_ok'] );
$mylisting_label = $mylisting_active ? __( 'Active', 'mybookaro' ) : __( 'Not detected', 'mybookaro' );
$mylisting_class = $mylisting_active ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--warn';
$repeater_configured = ! empty( $integration_status['mylisting_repeater_class_configured'] );
$woocommerce_required = ! empty( $integration_status['payments_enabled'] );
$woocommerce_ok = ! empty( $integration_status['woocommerce_ok'] );
$woocommerce_label = $woocommerce_required
    ? ( $woocommerce_ok ? __( 'Detected', 'mybookaro' ) : __( 'Missing', 'mybookaro' ) )
    : __( 'Not required', 'mybookaro' );
$woocommerce_class = $woocommerce_required
    ? ( $woocommerce_ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--error' )
    : 'bookaro-status-pill--info';
$timezone_ok = ! empty( $settings_status['timezone_ok'] );
$timezone_class = $timezone_ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--warn';
$frontend_enabled = ! empty( $settings_status['frontend_enabled'] );
$frontend_class = $frontend_enabled ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--warn';
$dashboard_ui_mode = $dashboard_status['ui_mode']
    ?? ( function_exists( 'bookaro_get_ui_mode' ) ? (string) bookaro_get_ui_mode() : 'woocommerce' );
$dashboard_ui_label = ( 'shortcodes' === $dashboard_ui_mode ) ? __( 'Shortcodes', 'mybookaro' ) : __( 'WooCommerce My Account', 'mybookaro' );
$dashboard_ui_meta = ( 'shortcodes' === $dashboard_ui_mode )
    ? __( 'Dashboards are placed on selected pages.', 'mybookaro' )
    : __( 'Dashboards live under WooCommerce My Account.', 'mybookaro' );
$provider_page_id = absint( $dashboard_status['provider_page_id'] ?? 0 );
$customer_page_id = absint( $dashboard_status['customer_page_id'] ?? 0 );
$provider_page_title = $dashboard_status['provider_page_title'] ?? '';
if ( $provider_page_id > 0 && $provider_page_title === '' ) {
    /* translators: %d: numeric value */
    $provider_page_title = sprintf( __( 'Page #%d', 'mybookaro' ), $provider_page_id );
}
$customer_page_title = $dashboard_status['customer_page_title'] ?? '';
if ( $customer_page_id > 0 && $customer_page_title === '' ) {
    /* translators: %d: numeric value */
    $customer_page_title = sprintf( __( 'Page #%d', 'mybookaro' ), $customer_page_id );
}
$provider_page_edit = $dashboard_status['provider_page_edit'] ?? '';
$customer_page_edit = $dashboard_status['customer_page_edit'] ?? '';
$provider_page_ok = $provider_page_id > 0 && ! empty( $dashboard_status['provider_page_exists'] );
$customer_page_ok = $customer_page_id > 0 && ! empty( $dashboard_status['customer_page_exists'] );
$provider_role_label = $dashboard_status['provider_role_label'] ?? __( 'MyBookaro Provider', 'mybookaro' );
$customer_role_label = $dashboard_status['customer_role_label'] ?? __( 'MyBookaro Customer', 'mybookaro' );
$provider_role_key = $dashboard_status['provider_role_key'] ?? '';
$customer_role_key = $dashboard_status['customer_role_key'] ?? '';
$provider_role_ok = ! empty( $dashboard_status['provider_role_has_cap'] );
$customer_role_ok = ! empty( $dashboard_status['customer_role_has_cap'] );
$provider_role_status = $provider_role_ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--warn';
$customer_role_status = $customer_role_ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--warn';
$settings_url = admin_url( 'admin.php?page=bookaro-booking-settings&tab=general' );
$roles_url = admin_url( 'admin.php?page=bookaro-booking-settings&tab=roles' );
$env_wp_version = $environment_status['wp_version'] ?? '';
$env_php_version = $environment_status['php_version'] ?? '';
$env_bookaro_version = $environment_status['bookaro_version'] ?? '';
$env_bookaro_pro_version = $environment_status['bookaro_pro_version'] ?? '';
$env_theme_name = $environment_status['theme_name'] ?? '';
$env_theme_version = $environment_status['theme_version'] ?? '';
$env_theme_parent = $environment_status['theme_parent'] ?? '';
$env_active_plugins = $environment_status['active_plugins_excerpt'] ?? [];
$env_active_plugins_count = (int) ( $environment_status['active_plugins_count'] ?? 0 );
$env_active_plugins_more = max( 0, $env_active_plugins_count - count( $env_active_plugins ) );
$allowed_types = $generic_status['allowed_listing_type_labels'] ?? [];
$allowed_types_ok = ! empty( $allowed_types );
$allowed_types_class = $allowed_types_ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--warn';
$allowed_pages = $generic_status['allowed_listing_page_labels'] ?? [];
$allowed_pages_class = empty( $allowed_pages ) ? 'bookaro-status-pill--info' : 'bookaro-status-pill--ok';
$resolved_mode = sanitize_key( (string) ( $generic_status['integration_resolved'] ?? '' ) );
$site_type = sanitize_key( (string) ( $generic_status['site_type'] ?? 'directory' ) );
$lane_label = (string) ( $generic_status['lane_label'] ?? '' );
$lane_blueprint = is_array( $generic_status['lane_blueprint'] ?? null ) ? $generic_status['lane_blueprint'] : [];
$lane_provider_mapping = (string) ( $lane_blueprint['provider_mapping'] ?? '' );
$lane_services_model = (string) ( $lane_blueprint['services_model'] ?? '' );
$lane_placement_model = (string) ( $lane_blueprint['placement_model'] ?? '' );
$lane_pages_required = (string) ( $lane_blueprint['pages_required'] ?? '' );
$site_type_labels = [
    'directory' => __( 'Directory', 'mybookaro' ),
    'single_business' => __( 'Single Business', 'mybookaro' ),
    'advanced_mapping' => __( 'Generic Directory (advanced compatibility active)', 'mybookaro' ),
];
$site_type_label = $site_type_labels[ $site_type ] ?? __( 'Directory', 'mybookaro' );
$single_business_mode = ( 'single_business' === $site_type );
$getting_started_url = admin_url( 'admin.php?page=bookaro-getting-started' );
$operational_summary_url = $getting_started_url . '#bookaro-operational-summary';
$support_snapshot_url = '#bookaro-support-snapshot';
$support_bundle_url = '#bookaro-support-bundle';
$single_business_default_provider_url = admin_url( 'admin.php?page=bookaro-setup-wizard&step=listings' );
$single_business_pages_url = admin_url( 'admin.php?page=bookaro-setup-wizard&step=pages' );
$generic_mode_active = ( 'generic' === $resolved_mode );
$generic_confirmation_required = ! empty( $generic_status['generic_confirmation_required'] );
$generic_legacy_fallback_active = ! empty( $generic_status['generic_legacy_fallback_active'] );
$generic_confirmation_url = admin_url( 'admin.php?page=bookaro-setup-wizard&step=modes' );
$generic_validation_url = admin_url( 'admin.php?page=bookaro-system-status#bookaro-support-check-generic_validation_provider_resolution_sample' );
$generic_launch_blocked = $generic_mode_active && ( $generic_confirmation_required || $generic_legacy_fallback_active || $generic_validation_refresh_required || $generic_validation_failed_count > 0 );
$generic_launch_blocked_message = '';
$generic_launch_gate_state = ( $generic_validation_failed_count > 0 || $generic_confirmation_required ) ? 'error' : 'warn';
$generic_launch_gate_state_label = ( 'error' === $generic_launch_gate_state ) ? __( 'Fail', 'mybookaro' ) : __( 'Warn', 'mybookaro' );
$generic_launch_gate_title = $generic_confirmation_required
    ? __( 'Generic confirmation required', 'mybookaro' )
    : ( $generic_legacy_fallback_active ? __( 'Legacy Generic fallback review required', 'mybookaro' ) : ( $generic_validation_failed_count > 0 ? __( 'Generic launch blocked', 'mybookaro' ) : __( 'Generic revalidation required', 'mybookaro' ) ) );
$generic_launch_gate_action_label = $generic_confirmation_required
    ? __( 'Confirm Generic in Setup Wizard', 'mybookaro' )
    : ( $generic_legacy_fallback_active ? __( 'Review Generic confirmation', 'mybookaro' ) : ( $generic_validation_failed_count > 0 ? __( 'Open Generic validation checks', 'mybookaro' ) : __( 'Run Generic validation now', 'mybookaro' ) ) );
$generic_launch_gate_action_url = ( $generic_confirmation_required || $generic_legacy_fallback_active ) ? $generic_confirmation_url : $generic_validation_url;
$generic_launch_gate_detail = '';
if ( $generic_launch_blocked ) {
    if ( $generic_confirmation_required ) {
        $generic_launch_blocked_message = __( 'MyListing is not detected. Generic is available, but an admin must explicitly confirm the Generic setup path before launch readiness checks can pass.', 'mybookaro' );
        $generic_launch_gate_detail = __( 'Next step: Open Setup Wizard > Mode, confirm Generic, then run validation before launch.', 'mybookaro' );
    } elseif ( $generic_legacy_fallback_active ) {
        $generic_launch_blocked_message = __( 'MyListing is not detected. Generic compatibility is active via legacy Auto fallback markers, but explicit confirmation metadata is missing.', 'mybookaro' );
        $generic_launch_gate_detail = __( 'Next step: Open Setup Wizard > Mode and save once to record explicit confirmation metadata, then re-run validation before launch.', 'mybookaro' );
    } else {
        $generic_launch_blocked_message = $generic_validation_failed_count > 0
            ? sprintf(
                /* translators: %d: number of Generic validation checks needing attention */
                _n(
                    'Launch is blocked: %d Generic validation check needs attention.',
                    'Launch is blocked: %d Generic validation checks need attention.',
                    (int) $generic_validation_failed_count,
                    'mybookaro'
                ),
                (int) $generic_validation_failed_count
            )
            : __( 'Generic configuration changed since the last validation snapshot. Re-run Generic validation before launch.', 'mybookaro' );
        if ( $generic_validation_refresh_required ) {
            $generic_launch_blocked_message .= ' ' . __( 'Complete a fresh validation pass and clear every Warn/Fail check before launch.', 'mybookaro' );
        }

        $generic_launch_gate_detail = $generic_validation_failed_count > 0
            ? sprintf(
                /* translators: %d: number of Generic validation checks needing attention */
                _n(
                    '%d Generic validation check still needs attention.',
                    '%d Generic validation checks still need attention.',
                    (int) $generic_validation_failed_count,
                    'mybookaro'
                ),
                (int) $generic_validation_failed_count
            )
            : __( 'Generic configuration changed since the last completed validation snapshot.', 'mybookaro' );
        if ( $generic_validation_refresh_required ) {
            $generic_launch_gate_detail .= ' ' . __( 'Re-run validation and clear every Warn/Fail check before launch.', 'mybookaro' );
        }
    }
}
$services_cache_status = ( isset( $services_cache_status ) && is_array( $services_cache_status ) ) ? $services_cache_status : [];
$services_cache_enabled = ! empty( $services_cache_status['cache_enabled'] );
$services_cache_ttl = absint( $services_cache_status['cache_ttl'] ?? 0 );
$services_cache_global_version = absint( $services_cache_status['global_version'] ?? 0 );
$services_cache_global_timestamp = absint( $services_cache_status['global_version_timestamp'] ?? 0 );
$services_cache_hooks_ok = ! empty( $services_cache_status['invalidation_hooks_ok'] );
$services_cache_missing_hooks = is_array( $services_cache_status['missing_invalidation_hooks'] ?? null )
    ? array_values( array_filter( array_map( 'sanitize_key', $services_cache_status['missing_invalidation_hooks'] ) ) )
    : [];
$services_cache_meta_key = sanitize_key( (string) ( $services_cache_status['listing_buster_meta_key'] ?? 'bookaro_services_cache_buster' ) );
$services_cache_mode = sanitize_key( (string) ( $services_cache_status['mode'] ?? '' ) );
$state_label_map = [
    'ok' => __( 'Pass', 'mybookaro' ),
    'warn' => __( 'Warn', 'mybookaro' ),
    'error' => __( 'Fail', 'mybookaro' ),
    'info' => __( 'Info', 'mybookaro' ),
];
$launch_readiness = ( isset( $launch_readiness ) && is_array( $launch_readiness ) ) ? $launch_readiness : [];
$launch_status = sanitize_key( (string) ( $launch_readiness['status'] ?? 'info' ) );
if ( ! in_array( $launch_status, [ 'ok', 'warn', 'error', 'info' ], true ) ) {
    $launch_status = 'info';
}
$launch_status_label = (string) ( $launch_readiness['status_label'] ?? '' );
if ( '' === $launch_status_label ) {
    $launch_status_label = $state_label_map[ $launch_status ] ?? __( 'Info', 'mybookaro' );
}
$launch_mode_label = (string) ( $launch_readiness['mode_label'] ?? __( 'Unknown mode', 'mybookaro' ) );
$launch_summary = (string) ( $launch_readiness['summary'] ?? '' );
$launch_detail = (string) ( $launch_readiness['detail'] ?? '' );
$launch_blocker_count = absint( $launch_readiness['blocker_count'] ?? 0 );
$launch_error_count = absint( $launch_readiness['error_count'] ?? 0 );
$launch_warn_count = absint( $launch_readiness['warn_count'] ?? 0 );
$launch_top_blockers = ( isset( $launch_readiness['top_blockers'] ) && is_array( $launch_readiness['top_blockers'] ) ) ? $launch_readiness['top_blockers'] : [];
$launch_action_url = (string) ( $launch_readiness['action_url'] ?? '' );
$launch_action_label = (string) ( $launch_readiness['action_label'] ?? '' );
$launch_status_class = 'bookaro-status-pill--' . $launch_status;
$support_share_summary = isset( $support_share_summary ) ? (string) $support_share_summary : '';
$support_share_summary_lines = 0;
if ( '' !== $support_share_summary ) {
    $support_share_summary_lines = substr_count( str_replace( [ "\r\n", "\r" ], "\n", $support_share_summary ), "\n" ) + 1;
}
$launch_blocker_quick_summary = isset( $launch_blocker_quick_summary ) ? (string) $launch_blocker_quick_summary : '';
$launch_blocker_quick_summary_lines = 0;
if ( '' !== $launch_blocker_quick_summary ) {
    $launch_blocker_quick_summary_lines = substr_count( str_replace( [ "\r\n", "\r" ], "\n", $launch_blocker_quick_summary ), "\n" ) + 1;
}
$launch_blocker_summary = isset( $launch_blocker_summary ) ? (string) $launch_blocker_summary : '';
$launch_blocker_summary_lines = 0;
if ( '' !== $launch_blocker_summary ) {
    $launch_blocker_summary_lines = substr_count( str_replace( [ "\r\n", "\r" ], "\n", $launch_blocker_summary ), "\n" ) + 1;
}
$launch_handoff_subject = isset( $launch_handoff_subject ) ? trim( (string) $launch_handoff_subject ) : '';
$launch_handoff_message = isset( $launch_handoff_message ) ? (string) $launch_handoff_message : '';
$launch_handoff_message_lines = 0;
if ( '' !== $launch_handoff_message ) {
    $launch_handoff_message_lines = substr_count( str_replace( [ "\r\n", "\r" ], "\n", $launch_handoff_message ), "\n" ) + 1;
}
$lane_summary = ( isset( $lane_summary ) && is_array( $lane_summary ) ) ? $lane_summary : [];
?>
<div class="wrap bookaro-admin bookaro-system-status">
    <div class="bookaro-card bookaro-hero bookaro-system-hero">
        <div class="bookaro-hero__content">
            <div class="bookaro-hero__brand">
                <img src="<?php echo esc_url( BOOKARO_PLUGIN_URL . 'assets/img/mb-logo.svg' ); ?>" alt="<?php esc_attr_e( 'MyBookaro', 'mybookaro' ); ?>" width="120" height="36" />
            </div>
            <h1><?php esc_html_e( 'System Status', 'mybookaro' ); ?></h1>
            <p class="description">
                <?php
                printf(
                    /* translators: %1$s: dynamic string, %2$s: dynamic string, %3$s: dynamic string */
                    wp_kses_post( __( 'Before opening support requests, review the <a href="%1$s">operational summary</a>, resolve blockers on this page, then copy the <a href="%2$s">masked support snapshot</a>. Share the <a href="%3$s">Support Bundle</a> only when deeper diagnostics are needed.', 'mybookaro' ) ),
                    esc_url( $operational_summary_url ),
                    esc_url( $support_snapshot_url ),
                    esc_url( $support_bundle_url )
                );
                ?>
            </p>
            <?php if ( $single_business_mode ) : ?>
                <p class="description"><?php esc_html_e( 'Single Business requires no listings. Follow this launch order: Default Provider -> booking/services/dashboard pages -> first service -> preview booking flow.', 'mybookaro' ); ?></p>
            <?php endif; ?>
        </div>
        <div class="bookaro-hero__actions">
            <a class="button button-secondary" href="<?php echo esc_url( $getting_started_url ); ?>">
                <?php esc_html_e( 'Open Getting Started', 'mybookaro' ); ?>
            </a>
            <a class="button button-secondary" href="<?php echo esc_url( $operational_summary_url ); ?>">
                <?php esc_html_e( 'Open operational summary', 'mybookaro' ); ?>
            </a>
            <a class="button button-secondary" href="<?php echo esc_url( admin_url( 'admin.php?page=bookaro-booking-settings&tab=general' ) ); ?>">
                <?php esc_html_e( 'Open settings', 'mybookaro' ); ?>
            </a>
            <a class="button button-secondary" href="<?php echo esc_url( $support_snapshot_url ); ?>">
                <?php esc_html_e( 'Open masked snapshot', 'mybookaro' ); ?>
            </a>
            <a class="button button-secondary" href="<?php echo esc_url( $support_bundle_url ); ?>">
                <?php esc_html_e( 'Open Support Bundle', 'mybookaro' ); ?>
            </a>
            <?php if ( $single_business_mode ) : ?>
                <a class="button button-secondary" href="<?php echo esc_url( $single_business_default_provider_url ); ?>">
                    <?php esc_html_e( 'Review Default Provider', 'mybookaro' ); ?>
                </a>
                <a class="button button-secondary" href="<?php echo esc_url( $single_business_pages_url ); ?>">
                    <?php esc_html_e( 'Assign pages', 'mybookaro' ); ?>
                </a>
            <?php endif; ?>
            <?php if ( $generic_mode_active ) : ?>
                <a class="button button-primary" href="<?php echo esc_url( ( $generic_confirmation_required || $generic_legacy_fallback_active ) ? $generic_confirmation_url : $generic_validation_url ); ?>">
                    <?php echo esc_html( $generic_confirmation_required ? __( 'Confirm Generic in Setup Wizard', 'mybookaro' ) : ( $generic_legacy_fallback_active ? __( 'Review Generic confirmation', 'mybookaro' ) : __( 'Run Generic validation', 'mybookaro' ) ) ); ?>
                </a>
            <?php endif; ?>
        </div>
    </div>

    <?php \Bookaro\Utils\TemplateLoader::render( 'admin/components/lane-summary-banner.php', [ 'lane_summary' => $lane_summary ] ); ?>

    <div class="bookaro-card bookaro-system-card">
        <div class="bookaro-card__header">
            <h2><?php esc_html_e( 'Launch & support shortcuts', 'mybookaro' ); ?></h2>
            <p class="description"><?php esc_html_e( 'Use these existing tools before go-live and before opening support requests.', 'mybookaro' ); ?></p>
        </div>
        <div class="bookaro-status-list">
            <div class="bookaro-status-item">
                <div class="bookaro-status-item__label"><?php esc_html_e( 'Operational summary', 'mybookaro' ); ?></div>
                <div class="bookaro-status-item__value">
                    <?php esc_html_e( 'Review the existing Getting Started operational summary for anti-spam, duplicate blocking, buffers, reminders, and lifecycle defaults.', 'mybookaro' ); ?>
                    <div class="bookaro-status-item__actions">
                        <a class="button button-small" href="<?php echo esc_url( $operational_summary_url ); ?>">
                            <?php esc_html_e( 'Open operational summary', 'mybookaro' ); ?>
                        </a>
                    </div>
                </div>
            </div>
            <div class="bookaro-status-item">
                <div class="bookaro-status-item__label"><?php esc_html_e( 'Masked support snapshot', 'mybookaro' ); ?></div>
                <div class="bookaro-status-item__value">
                    <?php esc_html_e( 'Start with the compact masked snapshot for tickets, comments, and chat. It highlights blockers without exposing personal data.', 'mybookaro' ); ?>
                    <div class="bookaro-status-item__actions">
                        <a class="button button-small" href="<?php echo esc_url( $support_snapshot_url ); ?>">
                            <?php esc_html_e( 'Open support snapshot', 'mybookaro' ); ?>
                        </a>
                    </div>
                </div>
            </div>
            <div class="bookaro-status-item">
                <div class="bookaro-status-item__label"><?php esc_html_e( 'Support Bundle', 'mybookaro' ); ?></div>
                <div class="bookaro-status-item__value">
                    <?php esc_html_e( 'Use the existing Support Bundle export when support needs the full diagnostic package after you already shared the masked snapshot.', 'mybookaro' ); ?>
                    <div class="bookaro-status-item__actions">
                        <a class="button button-small" href="<?php echo esc_url( $support_bundle_url ); ?>">
                            <?php esc_html_e( 'Open Support Bundle', 'mybookaro' ); ?>
                        </a>
                    </div>
                </div>
            </div>
            <?php if ( $single_business_mode ) : ?>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Single Business no-listing path', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <?php esc_html_e( 'No listings required. Sequence: Set Default Provider in Setup Wizard > Listings -> assign booking/services/dashboard pages in Setup Wizard > Pages -> create first service -> preview one booking flow.', 'mybookaro' ); ?>
                        <div class="bookaro-status-item__actions">
                            <a class="button button-small" href="<?php echo esc_url( $single_business_default_provider_url ); ?>">
                                <?php esc_html_e( 'Review Default Provider', 'mybookaro' ); ?>
                            </a>
                            <a class="button button-small" href="<?php echo esc_url( $single_business_pages_url ); ?>">
                                <?php esc_html_e( 'Assign pages', 'mybookaro' ); ?>
                            </a>
                        </div>
                    </div>
                </div>
            <?php endif; ?>
        </div>
    </div>

    <div class="bookaro-card bookaro-system-card">
        <div class="bookaro-card__header">
            <h2><?php esc_html_e( 'Product lane', 'mybookaro' ); ?></h2>
            <p class="description"><?php esc_html_e( 'This lane defines the expected provider mapping, services model, placement model, and required pages.', 'mybookaro' ); ?></p>
        </div>
        <div class="bookaro-status-list">
            <div class="bookaro-status-item">
                <div class="bookaro-status-item__label"><?php esc_html_e( 'Active lane', 'mybookaro' ); ?></div>
                <div class="bookaro-status-item__value">
                    <span class="bookaro-status-pill bookaro-status-pill--info"><?php echo esc_html( $lane_label !== '' ? $lane_label : __( 'Generic Directory', 'mybookaro' ) ); ?></span>
                    <span class="bookaro-status-pill bookaro-status-pill--info">
                        <?php
                        echo esc_html(
                            sprintf(
                                /* translators: %s: site type label */
                                __( 'Site type: %s', 'mybookaro' ),
                                $site_type_label
                            )
                        );
                        ?>
                    </span>
                </div>
            </div>
            <div class="bookaro-status-item">
                <div class="bookaro-status-item__label"><?php esc_html_e( 'Provider mapping', 'mybookaro' ); ?></div>
                <div class="bookaro-status-item__value"><?php echo esc_html( $lane_provider_mapping ); ?></div>
            </div>
            <div class="bookaro-status-item">
                <div class="bookaro-status-item__label"><?php esc_html_e( 'Services model', 'mybookaro' ); ?></div>
                <div class="bookaro-status-item__value"><?php echo esc_html( $lane_services_model ); ?></div>
            </div>
            <div class="bookaro-status-item">
                <div class="bookaro-status-item__label"><?php esc_html_e( 'Placement model', 'mybookaro' ); ?></div>
                <div class="bookaro-status-item__value"><?php echo esc_html( $lane_placement_model ); ?></div>
            </div>
            <div class="bookaro-status-item">
                <div class="bookaro-status-item__label"><?php esc_html_e( 'Pages and dashboards', 'mybookaro' ); ?></div>
                <div class="bookaro-status-item__value"><?php echo esc_html( $lane_pages_required ); ?></div>
            </div>
        </div>
    </div>

    <?php if ( $generic_launch_blocked ) : ?>
        <div class="bookaro-card bookaro-system-card bookaro-system-generic-launch-card">
            <div class="bookaro-card__header">
                <h2><?php echo esc_html( $generic_launch_gate_title ); ?></h2>
                <p class="description"><?php echo esc_html( $generic_launch_blocked_message ); ?></p>
            </div>
            <div class="bookaro-launch-overview">
                <div class="bookaro-launch-overview__meta">
                    <span class="bookaro-status-pill <?php echo esc_attr( 'bookaro-status-pill--' . $generic_launch_gate_state ); ?>"><?php echo esc_html( $generic_launch_gate_state_label ); ?></span>
                    <span class="bookaro-status-pill bookaro-status-pill--info"><?php esc_html_e( 'Generic mode', 'mybookaro' ); ?></span>
                    <?php if ( $generic_validation_refresh_required ) : ?>
                        <span class="bookaro-status-pill bookaro-status-pill--warn"><?php esc_html_e( 'Validation snapshot stale', 'mybookaro' ); ?></span>
                    <?php endif; ?>
                </div>
                <?php if ( '' !== $generic_launch_gate_detail ) : ?>
                    <div class="bookaro-launch-overview__counts"><?php echo esc_html( $generic_launch_gate_detail ); ?></div>
                <?php endif; ?>
                <a class="button button-primary" href="<?php echo esc_url( $generic_launch_gate_action_url ); ?>">
                    <?php echo esc_html( $generic_launch_gate_action_label ); ?>
                </a>
            </div>
        </div>
    <?php endif; ?>

    <?php if ( $generic_mode_active && ! empty( $generic_readiness_summary['active'] ) ) : ?>
        <div class="bookaro-card bookaro-system-card" id="bookaro-generic-readiness-summary">
            <div class="bookaro-card__header">
                <h2><?php esc_html_e( 'Generic readiness summary', 'mybookaro' ); ?></h2>
                <p class="description">
                    <?php
                    echo esc_html(
                        '' !== $generic_readiness_compact_summary
                            ? $generic_readiness_compact_summary
                            : __( 'Validation-focused Generic launch summary.', 'mybookaro' )
                    );
                    ?>
                </p>
                <p class="description"><?php esc_html_e( 'Use the lane summary banner above for the compact model, main blocker, and required next step snapshot.', 'mybookaro' ); ?></p>
            </div>
            <div class="bookaro-status-list">
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Launch status', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( 'bookaro-status-pill--' . $generic_readiness_state ); ?>">
                            <?php echo esc_html( $generic_readiness_state_label ); ?>
                        </span>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Validation state', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( 'bookaro-status-pill--' . $generic_readiness_validation_level ); ?>">
                            <?php echo esc_html( (string) ( $generic_readiness_summary['validation_state'] ?? '' ) ); ?>
                        </span>
                        <?php if ( ! empty( $generic_readiness_summary['validation_detail'] ) ) : ?>
                            <div class="bookaro-status-item__meta"><?php echo esc_html( (string) $generic_readiness_summary['validation_detail'] ); ?></div>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Required next step', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <?php if ( ! empty( $generic_readiness_summary['top_next_action']['detail'] ) ) : ?>
                            <div class="bookaro-status-item__meta"><?php echo esc_html( (string) $generic_readiness_summary['top_next_action']['detail'] ); ?></div>
                        <?php endif; ?>
                        <?php if ( ! empty( $generic_readiness_summary['top_next_action']['url'] ) && ! empty( $generic_readiness_summary['top_next_action']['label'] ) ) : ?>
                            <div class="bookaro-status-item__actions">
                                <a class="button button-small" href="<?php echo esc_url( (string) $generic_readiness_summary['top_next_action']['url'] ); ?>">
                                    <?php echo esc_html( (string) $generic_readiness_summary['top_next_action']['label'] ); ?>
                                </a>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Last validation run', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <div class="bookaro-status-item__meta"><?php echo esc_html( (string) ( $generic_readiness_summary['last_validation_run'] ?? __( 'Never', 'mybookaro' ) ) ); ?></div>
                    </div>
                </div>
            </div>
        </div>
    <?php endif; ?>

    <div class="bookaro-card bookaro-system-card bookaro-system-launch-card">
        <div class="bookaro-card__header">
            <h2><?php esc_html_e( 'Launch readiness', 'mybookaro' ); ?></h2>
            <?php if ( '' !== $launch_summary ) : ?>
                <p class="description"><?php echo esc_html( $launch_summary ); ?></p>
            <?php endif; ?>
            <?php if ( '' !== $launch_detail ) : ?>
                <p class="description"><?php echo esc_html( $launch_detail ); ?></p>
            <?php endif; ?>
        </div>
        <div class="bookaro-launch-overview">
            <div class="bookaro-launch-overview__meta">
                <span class="bookaro-status-pill <?php echo esc_attr( $launch_status_class ); ?>"><?php echo esc_html( $launch_status_label ); ?></span>
                <span class="bookaro-status-pill bookaro-status-pill--info">
                    <?php
                    echo esc_html(
                        sprintf(
                            /* translators: %s: resolved integration mode label */
                            __( 'Mode: %s', 'mybookaro' ),
                            $launch_mode_label
                        )
                    );
                    ?>
                </span>
            </div>
            <div class="bookaro-launch-overview__counts">
                <?php
                echo esc_html(
                    sprintf(
                        /* translators: 1: blockers count, 2: error count, 3: warning count */
                        __( '%1$d blockers (%2$d errors, %3$d warnings)', 'mybookaro' ),
                        $launch_blocker_count,
                        $launch_error_count,
                        $launch_warn_count
                    )
                );
                ?>
            </div>
            <?php if ( '' !== $launch_action_url && '' !== $launch_action_label ) : ?>
                <a class="button button-secondary" href="<?php echo esc_url( $launch_action_url ); ?>">
                    <?php echo esc_html( $launch_action_label ); ?>
                </a>
            <?php endif; ?>
        </div>

        <?php if ( ! empty( $launch_top_blockers ) ) : ?>
            <ol class="bookaro-launch-blockers">
                <?php foreach ( $launch_top_blockers as $blocker ) : ?>
                    <?php
                    $blocker_state = sanitize_key( (string) ( $blocker['state'] ?? 'info' ) );
                    if ( ! in_array( $blocker_state, [ 'ok', 'warn', 'error', 'info' ], true ) ) {
                        $blocker_state = 'info';
                    }
                    $blocker_status_class = 'bookaro-status-pill--' . $blocker_state;
                    $blocker_state_label = $state_label_map[ $blocker_state ] ?? __( 'Info', 'mybookaro' );
                    $blocker_summary = trim( (string) ( $blocker['summary'] ?? '' ) );
                    if ( '' === $blocker_summary ) {
                        $blocker_summary = trim( (string) ( $blocker['next_step'] ?? '' ) );
                    }
                    if ( '' === $blocker_summary ) {
                        $blocker_summary = trim( (string) ( $blocker['fix'] ?? '' ) );
                    }
                    if ( '' === $blocker_summary ) {
                        $blocker_summary = trim( (string) ( $blocker['detail'] ?? '' ) );
                    }
                    $blocker_action_url = (string) ( $blocker['action_url'] ?? '' );
                    $blocker_action_label = (string) ( $blocker['action_label'] ?? '' );
                    ?>
                    <li class="bookaro-launch-blocker">
                        <div class="bookaro-launch-blocker__head">
                            <strong><?php echo esc_html( (string) ( $blocker['label'] ?? '' ) ); ?></strong>
                            <span class="bookaro-status-pill <?php echo esc_attr( $blocker_status_class ); ?>"><?php echo esc_html( $blocker_state_label ); ?></span>
                        </div>
                        <?php if ( '' !== $blocker_summary ) : ?>
                            <div class="bookaro-status-item__meta"><?php echo esc_html( $blocker_summary ); ?></div>
                        <?php endif; ?>
                        <?php if ( '' !== $blocker_action_url && '' !== $blocker_action_label ) : ?>
                            <div class="bookaro-status-item__actions">
                                <a class="button button-small" href="<?php echo esc_url( $blocker_action_url ); ?>">
                                    <?php echo esc_html( $blocker_action_label ); ?>
                                </a>
                            </div>
                        <?php endif; ?>
                    </li>
                <?php endforeach; ?>
            </ol>
            <?php if ( $launch_blocker_count > count( $launch_top_blockers ) ) : ?>
                <div class="bookaro-status-item__meta">
                    <?php
                    echo esc_html(
                        sprintf(
                            /* translators: %d: additional blockers count */
                            __( '+%d additional blockers in Support assistant checks below.', 'mybookaro' ),
                            $launch_blocker_count - count( $launch_top_blockers )
                        )
                    );
                    ?>
                </div>
            <?php endif; ?>
        <?php endif; ?>
    </div>

    <div class="bookaro-card bookaro-system-card bookaro-system-support-card">
        <div class="bookaro-card__header">
            <h2><?php esc_html_e( 'Support assistant checks', 'mybookaro' ); ?></h2>
            <p class="description">
                <?php
                if ( $support_failed_count > 0 ) {
                    echo esc_html(
                        sprintf(
                            /* translators: %d: number of checks needing attention */
                            __( '%d checks need attention. Use the suggested fix on each item.', 'mybookaro' ),
                            (int) $support_failed_count
                        )
                    );
                } else {
                    esc_html_e( 'All key diagnostics are passing.', 'mybookaro' );
                }
                ?>
            </p>
            <p class="description"><?php esc_html_e( 'Use this page as your default support handoff. Resolve Fail/Warn checks here, then share the masked support snapshot or Support Bundle from Support report.', 'mybookaro' ); ?></p>
            <?php if ( $generic_mode_active ) : ?>
                <p class="description">
                    <?php esc_html_e( 'Lane diagnostics include pass/warn/fail checks with suggested fixes for mapping, placement, and page readiness.', 'mybookaro' ); ?>
                </p>
            <?php endif; ?>
        </div>
        <div class="bookaro-status-list">
            <?php foreach ( $support_checks as $check ) : ?>
                <?php
                $check_id = sanitize_html_class( (string) ( $check['id'] ?? '' ) );
                $item_id = '' !== $check_id ? 'bookaro-support-check-' . $check_id : '';
                $state = sanitize_key( (string) ( $check['state'] ?? 'info' ) );
                if ( ! in_array( $state, [ 'ok', 'warn', 'error', 'info' ], true ) ) {
                    $state = 'info';
                }
                $pill_class = 'bookaro-status-pill--' . $state;
                $state_label = $state_label_map[ $state ] ?? __( 'Info', 'mybookaro' );
                $pill_label = (string) ( $check['value'] ?? '' );
                $show_value_pill = '' !== $pill_label && strtolower( $pill_label ) !== strtolower( $state_label );
                $needs_fix = ! empty( $check['needs_fix'] );
                $detail = (string) ( $check['detail'] ?? '' );
                $fix = (string) ( $check['fix'] ?? '' );
                $next_step = (string) ( $check['next_step'] ?? '' );
                $action_url = (string) ( $check['action_url'] ?? '' );
                $action_label = (string) ( $check['action_label'] ?? '' );
                ?>
                <div<?php echo '' !== $item_id ? ' id="' . esc_attr( $item_id ) . '"' : ''; ?> class="bookaro-status-item <?php echo esc_attr( $needs_fix ? 'bookaro-status-item--needs-fix' : '' ); ?>">
                    <div class="bookaro-status-item__label"><?php echo esc_html( (string) ( $check['label'] ?? '' ) ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $pill_class ); ?>"><?php echo esc_html( $state_label ); ?></span>
                        <?php if ( $show_value_pill ) : ?>
                            <span class="bookaro-status-pill bookaro-status-pill--info"><?php echo esc_html( $pill_label ); ?></span>
                        <?php endif; ?>
                        <?php if ( '' !== $detail ) : ?>
                            <div class="bookaro-status-item__meta"><?php echo esc_html( $detail ); ?></div>
                        <?php endif; ?>
                        <?php if ( $needs_fix && '' !== $fix ) : ?>
                            <div class="bookaro-status-item__meta bookaro-status-item__fix">
                                <?php
                                echo esc_html(
                                    sprintf(
                                        /* translators: %s: suggested fix text */
                                        __( 'Suggested fix: %s', 'mybookaro' ),
                                        $fix
                                    )
                                );
                                ?>
                            </div>
                        <?php endif; ?>
                        <?php if ( $needs_fix && '' !== $next_step ) : ?>
                            <div class="bookaro-status-item__meta bookaro-status-item__fix">
                                <?php echo esc_html( $next_step ); ?>
                            </div>
                        <?php endif; ?>
                        <div class="bookaro-status-item__actions">
                            <?php if ( '' !== $action_url && '' !== $action_label ) : ?>
                                <a class="button button-small" href="<?php echo esc_url( $action_url ); ?>">
                                    <?php echo esc_html( $action_label ); ?>
                                </a>
                            <?php endif; ?>
                            <?php if ( $needs_fix ) : ?>
                                <button type="button" class="button button-small bookaro-copy-bundle-button">
                                    <?php esc_html_e( 'Copy support bundle', 'mybookaro' ); ?>
                                </button>
                                <span class="description bookaro-copy-bundle-status" aria-live="polite"></span>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    </div>

    <div class="bookaro-system-status__grid">
        <div class="bookaro-card bookaro-system-card">
            <div class="bookaro-card__header">
                <h2><?php esc_html_e( 'Database', 'mybookaro' ); ?></h2>
                <p class="description"><?php esc_html_e( 'Schema version and core tables.', 'mybookaro' ); ?></p>
            </div>
            <div class="bookaro-status-list">
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Schema version', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $schema_class ); ?>"><?php echo esc_html( $schema_label ); ?></span>
                        <div class="bookaro-status-item__meta">
                            <?php
                            echo esc_html( sprintf(
                                /* translators: %1$d: numeric value, %2$d: numeric value */
                                __( 'Installed %1$d / Expected %2$d', 'mybookaro' ),
                                (int) $db_status['schema_installed'],
                                (int) $db_status['schema_expected']
                            ) );
                            ?>
                        </div>
                        <?php if ( ! $schema_ok ) : ?>
                            <div class="bookaro-status-item__actions">
                                <a class="button button-secondary" href="<?php echo esc_url( admin_url( 'admin.php?page=bookaro-upgrade' ) ); ?>">
                                    <?php esc_html_e( 'Run upgrade', 'mybookaro' ); ?>
                                </a>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
                <?php foreach ( $db_status['tables'] as $name => $ok ) : ?>
                    <?php
                    $table_label = ucfirst( $name ) . ' ' . __( 'table', 'mybookaro' );
                    $table_class = $ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--error';
                    ?>
                    <div class="bookaro-status-item">
                        <div class="bookaro-status-item__label"><?php echo esc_html( $table_label ); ?></div>
                        <div class="bookaro-status-item__value">
                            <span class="bookaro-status-pill <?php echo esc_attr( $table_class ); ?>">
                                <?php echo esc_html( $ok ? __( 'OK', 'mybookaro' ) : __( 'Missing', 'mybookaro' ) ); ?>
                            </span>
                            <?php if ( ! $ok ) : ?>
                                <div class="bookaro-status-item__meta"><?php esc_html_e( 'Reactivate the plugin or run upgrade.', 'mybookaro' ); ?></div>
                            <?php endif; ?>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </div>

        <div class="bookaro-card bookaro-system-card">
            <div class="bookaro-card__header">
                <h2><?php esc_html_e( 'Cron', 'mybookaro' ); ?></h2>
                <p class="description"><?php esc_html_e( 'Scheduled tasks that keep bookings in sync.', 'mybookaro' ); ?></p>
            </div>
            <div class="bookaro-status-list">
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'WP-Cron', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $wp_cron_class ); ?>"><?php echo esc_html( $wp_cron_label ); ?></span>
                        <?php if ( ! $wp_cron_ok ) : ?>
                            <div class="bookaro-status-item__actions">
                                <a class="button button-secondary" href="<?php echo esc_url( admin_url( 'site-health.php' ) ); ?>">
                                    <?php esc_html_e( 'View Site Health', 'mybookaro' ); ?>
                                </a>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Auto-complete bookings', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $auto_complete_class ); ?>"><?php echo esc_html( $auto_complete_label ); ?></span>
                        <div class="bookaro-status-item__meta">
                            <?php if ( ! empty( $cron_status['auto_complete_next'] ) ) : ?>
                                <?php echo esc_html( date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $cron_status['auto_complete_next'] ) ); ?>
                            <?php else : ?>
                                <?php esc_html_e( 'Run upgrade or reactivate the plugin to schedule.', 'mybookaro' ); ?>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="bookaro-system-status__grid">
        <div class="bookaro-card bookaro-system-card">
            <div class="bookaro-card__header">
                <h2><?php esc_html_e( 'API', 'mybookaro' ); ?></h2>
                <p class="description"><?php esc_html_e( 'Connectivity for REST and AJAX endpoints.', 'mybookaro' ); ?></p>
            </div>
            <div class="bookaro-status-list">
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'REST API', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $rest_class ); ?>"><?php echo esc_html( $rest_label ); ?></span>
                        <div class="bookaro-status-item__meta"><?php echo esc_html( $api_status['rest_url_masked'] ?? $api_status['rest_url'] ); ?></div>
                        <?php if ( ! empty( $api_status['rest_http_code'] ) || ! empty( $api_status['rest_access_error'] ) ) : ?>
                            <div class="bookaro-status-item__meta">
                                <?php
                                $parts = [];
                                if ( ! empty( $api_status['rest_http_code'] ) ) {
                                    /* translators: %d: numeric value */
                                    $parts[] = sprintf( __( 'HTTP %d', 'mybookaro' ), (int) $api_status['rest_http_code'] );
                                }
                                if ( ! empty( $api_status['rest_access_error'] ) ) {
                                    $parts[] = (string) $api_status['rest_access_error'];
                                }
                                echo esc_html( implode( ' | ', $parts ) );
                                ?>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'AJAX endpoint', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $ajax_class ); ?>"><?php echo esc_html( $ajax_label ); ?></span>
                        <div class="bookaro-status-item__meta"><?php echo esc_html( $api_status['ajax_url_masked'] ?? $api_status['ajax_url'] ); ?></div>
                        <?php if ( ! empty( $api_status['ajax_http_code'] ) || ! empty( $api_status['ajax_access_error'] ) ) : ?>
                            <div class="bookaro-status-item__meta">
                                <?php
                                $parts = [];
                                if ( ! empty( $api_status['ajax_http_code'] ) ) {
                                    /* translators: %d: numeric value */
                                    $parts[] = sprintf( __( 'HTTP %d', 'mybookaro' ), (int) $api_status['ajax_http_code'] );
                                }
                                if ( ! empty( $api_status['ajax_access_error'] ) ) {
                                    $parts[] = (string) $api_status['ajax_access_error'];
                                }
                                echo esc_html( implode( ' | ', $parts ) );
                                ?>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>

        <div class="bookaro-card bookaro-system-card">
            <div class="bookaro-card__header">
                <h2><?php esc_html_e( 'Integrations', 'mybookaro' ); ?></h2>
                <p class="description"><?php esc_html_e( 'Theme and commerce plugins detected.', 'mybookaro' ); ?></p>
            </div>
            <div class="bookaro-status-list">
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'MyListing', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $mylisting_class ); ?>"><?php echo esc_html( $mylisting_label ); ?></span>
                        <?php if ( ! $mylisting_active ) : ?>
                            <div class="bookaro-status-item__meta"><?php esc_html_e( 'Install and activate the MyListing theme to enable the booking button hook.', 'mybookaro' ); ?></div>
                        <?php elseif ( ! $mylisting_hook_ok ) : ?>
                            <div class="bookaro-status-item__meta"><?php esc_html_e( 'MyListing is active, but the sidebar booking hook was not detected.', 'mybookaro' ); ?></div>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'MyListing repeater', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $repeater_configured ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--warn' ); ?>">
                            <?php echo esc_html( $repeater_configured ? __( 'Configured', 'mybookaro' ) : __( 'Fallback', 'mybookaro' ) ); ?>
                        </span>
                        <div class="bookaro-status-item__meta">
                            <?php
                            $repeater_class = $integration_status['mylisting_repeater_class'] ?? 'mybookaro_services';
                            /* translators: %s: dynamic string */
                            echo esc_html( sprintf( __( 'Row CSS class: %s', 'mybookaro' ), $repeater_class ) );
                            ?>
                        </div>
                        <?php if ( ! $repeater_configured ) : ?>
                            <div class="bookaro-status-item__meta"><?php esc_html_e( 'Set a custom class in Settings if your MyListing row class differs.', 'mybookaro' ); ?></div>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'WooCommerce', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $woocommerce_class ); ?>"><?php echo esc_html( $woocommerce_label ); ?></span>
                        <?php if ( $woocommerce_required && ! $woocommerce_ok ) : ?>
                            <div class="bookaro-status-item__actions">
                                <a class="button button-secondary" href="<?php echo esc_url( admin_url( 'plugin-install.php?tab=search&s=woocommerce' ) ); ?>">
                                    <?php esc_html_e( 'Install WooCommerce', 'mybookaro' ); ?>
                                </a>
                            </div>
                        <?php else : ?>
                            <?php if ( ! $woocommerce_required ) : ?>
                                <div class="bookaro-status-item__meta"><?php esc_html_e( 'Payments are disabled. WooCommerce not required.', 'mybookaro' ); ?></div>
                            <?php endif; ?>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="bookaro-system-status__grid">
        <div class="bookaro-card bookaro-system-card">
            <div class="bookaro-card__header">
                <h2><?php esc_html_e( 'Environment', 'mybookaro' ); ?></h2>
                <p class="description"><?php esc_html_e( 'Server, theme, and plugin versions.', 'mybookaro' ); ?></p>
            </div>
            <div class="bookaro-status-list">
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'WordPress', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value"><?php echo esc_html( $env_wp_version ); ?></div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'PHP', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value"><?php echo esc_html( $env_php_version ); ?></div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'MyBookaro', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value"><?php echo esc_html( $env_bookaro_version ); ?></div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'MyBookaro Pro', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value"><?php echo esc_html( $env_bookaro_pro_version !== '' ? $env_bookaro_pro_version : __( 'Not installed', 'mybookaro' ) ); ?></div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Theme', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <?php if ( $env_theme_name !== '' ) : ?>
                            <div><?php echo esc_html( trim( $env_theme_name . ' ' . $env_theme_version ) ); ?></div>
                            <?php if ( $env_theme_parent !== '' ) : ?>
                                <div class="bookaro-status-item__meta"><?php
                                /* translators: %s: parent theme name */
                                echo esc_html( sprintf( __( 'Child of %s', 'mybookaro' ), $env_theme_parent ) ); ?></div>
                            <?php endif; ?>
                        <?php else : ?>
                            <div class="bookaro-status-item__meta"><?php esc_html_e( 'Unknown theme', 'mybookaro' ); ?></div>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Active plugins', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <?php if ( ! empty( $env_active_plugins ) ) : ?>
                            <div class="bookaro-status-item__meta"><?php echo esc_html( implode( ', ', $env_active_plugins ) ); ?></div>
                            <?php if ( $env_active_plugins_more > 0 ) : ?>
                                <div class="bookaro-status-item__meta">
                                    <?php
                                    printf(
                                        /* translators: %d: number of additional plugins */
                                        esc_html__( '+%d more active plugins', 'mybookaro' ),
                                        (int) $env_active_plugins_more
                                    );
                                    ?>
                                </div>
                            <?php endif; ?>
                        <?php else : ?>
                            <div class="bookaro-status-item__meta"><?php esc_html_e( 'No active plugins detected.', 'mybookaro' ); ?></div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>

        <?php
        /**
         * Pro license / update diagnostics are owned and rendered by the
         * separate MyBookaro Pro plugin, which can hook this action to add its
         * own card here. Lite ships no license UI.
         */
        do_action( 'bookaro_system_status_license_card' );
        ?>
    </div>

    <div class="bookaro-system-status__grid">
        <div class="bookaro-card bookaro-system-card">
            <div class="bookaro-card__header">
                <h2><?php esc_html_e( 'Settings', 'mybookaro' ); ?></h2>
                <p class="description"><?php esc_html_e( 'Core configuration that affects booking flow.', 'mybookaro' ); ?></p>
            </div>
            <div class="bookaro-status-list">
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Timezone', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $timezone_class ); ?>"><?php echo esc_html( $settings_status['timezone'] ); ?></span>
                        <?php if ( ! $timezone_ok ) : ?>
                            <div class="bookaro-status-item__actions">
                                <a class="button button-secondary" href="<?php echo esc_url( admin_url( 'options-general.php' ) ); ?>">
                                    <?php esc_html_e( 'Set timezone', 'mybookaro' ); ?>
                                </a>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Frontend enabled', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $frontend_class ); ?>">
                            <?php echo esc_html( $frontend_enabled ? __( 'Enabled', 'mybookaro' ) : __( 'Disabled', 'mybookaro' ) ); ?>
                        </span>
                        <?php if ( ! $frontend_enabled ) : ?>
                            <div class="bookaro-status-item__actions">
                                <a class="button button-secondary" href="<?php echo esc_url( admin_url( 'admin.php?page=bookaro-booking-settings&tab=general' ) ); ?>">
                                    <?php esc_html_e( 'Enable frontend', 'mybookaro' ); ?>
                                </a>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>

        <div class="bookaro-card bookaro-system-card">
            <div class="bookaro-card__header">
                <h2><?php esc_html_e( 'Dashboards', 'mybookaro' ); ?></h2>
                <p class="description"><?php esc_html_e( 'Where dashboards live and who can access them.', 'mybookaro' ); ?></p>
            </div>
            <div class="bookaro-status-list">
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'UI mode', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill bookaro-status-pill--info"><?php echo esc_html( $dashboard_ui_label ); ?></span>
                        <div class="bookaro-status-item__meta"><?php echo esc_html( $dashboard_ui_meta ); ?></div>
                        <?php if ( ! $frontend_enabled ) : ?>
                            <div class="bookaro-status-item__meta"><?php esc_html_e( 'Frontend UI is disabled, so dashboards are hidden.', 'mybookaro' ); ?></div>
                        <?php endif; ?>
                        <div class="bookaro-status-item__actions">
                            <a class="button button-secondary" href="<?php echo esc_url( $settings_url ); ?>">
                                <?php esc_html_e( 'Open settings', 'mybookaro' ); ?>
                            </a>
                        </div>
                    </div>
                </div>

                <?php if ( 'shortcodes' === $dashboard_ui_mode ) : ?>
                    <div class="bookaro-status-item">
                        <div class="bookaro-status-item__label"><?php esc_html_e( 'Provider dashboard page', 'mybookaro' ); ?></div>
                        <div class="bookaro-status-item__value">
                            <span class="bookaro-status-pill <?php echo esc_attr( $provider_page_ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--warn' ); ?>">
                                <?php echo esc_html( $provider_page_ok ? __( 'Set', 'mybookaro' ) : __( 'Not set', 'mybookaro' ) ); ?>
                            </span>
                            <div class="bookaro-status-item__meta">
                                <?php
                                echo esc_html(
                                    $provider_page_ok
                                        /* translators: %s: dynamic string */
                                        ? sprintf( __( 'Page: %s', 'mybookaro' ), $provider_page_title )
                                        : __( 'Select a provider dashboard page in Setup.', 'mybookaro' )
                                );
                                ?>
                            </div>
                            <?php if ( $provider_page_ok && ! empty( $dashboard_status['provider_page_embed_label'] ) ) : ?>
                                <div class="bookaro-status-item__meta">
                                    <?php
                                    echo esc_html(
                                        sprintf(
                                            /* translators: %s: dynamic string */
                                            __( 'Content check: %s', 'mybookaro' ),
                                            (string) $dashboard_status['provider_page_embed_label']
                                        )
                                    );
                                    ?>
                                </div>
                            <?php endif; ?>
                            <?php if ( $provider_page_ok && $provider_page_edit ) : ?>
                                <div class="bookaro-status-item__actions">
                                    <a class="button button-small" href="<?php echo esc_url( $provider_page_edit ); ?>">
                                        <?php esc_html_e( 'Edit page', 'mybookaro' ); ?>
                                    </a>
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>

                    <div class="bookaro-status-item">
                        <div class="bookaro-status-item__label"><?php esc_html_e( 'Customer dashboard page', 'mybookaro' ); ?></div>
                        <div class="bookaro-status-item__value">
                            <span class="bookaro-status-pill <?php echo esc_attr( $customer_page_ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--warn' ); ?>">
                                <?php echo esc_html( $customer_page_ok ? __( 'Set', 'mybookaro' ) : __( 'Not set', 'mybookaro' ) ); ?>
                            </span>
                            <div class="bookaro-status-item__meta">
                                <?php
                                echo esc_html(
                                    $customer_page_ok
                                        /* translators: %s: dynamic string */
                                        ? sprintf( __( 'Page: %s', 'mybookaro' ), $customer_page_title )
                                        : __( 'Select a customer dashboard page in Setup.', 'mybookaro' )
                                );
                                ?>
                            </div>
                            <?php if ( $customer_page_ok && ! empty( $dashboard_status['customer_page_embed_label'] ) ) : ?>
                                <div class="bookaro-status-item__meta">
                                    <?php
                                    echo esc_html(
                                        sprintf(
                                            /* translators: %s: dynamic string */
                                            __( 'Content check: %s', 'mybookaro' ),
                                            (string) $dashboard_status['customer_page_embed_label']
                                        )
                                    );
                                    ?>
                                </div>
                            <?php endif; ?>
                            <?php if ( $customer_page_ok && $customer_page_edit ) : ?>
                                <div class="bookaro-status-item__actions">
                                    <a class="button button-small" href="<?php echo esc_url( $customer_page_edit ); ?>">
                                        <?php esc_html_e( 'Edit page', 'mybookaro' ); ?>
                                    </a>
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>
                <?php else : ?>
                    <div class="bookaro-status-item">
                        <div class="bookaro-status-item__label"><?php esc_html_e( 'Shortcodes pages', 'mybookaro' ); ?></div>
                        <div class="bookaro-status-item__value">
                            <span class="bookaro-status-pill bookaro-status-pill--info"><?php esc_html_e( 'Not required', 'mybookaro' ); ?></span>
                            <div class="bookaro-status-item__meta"><?php esc_html_e( 'Dashboards render in WooCommerce My Account.', 'mybookaro' ); ?></div>
                        </div>
                    </div>
                <?php endif; ?>

                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Provider role', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $provider_role_status ); ?>">
                            <?php echo esc_html( $provider_role_ok ? __( 'Ready', 'mybookaro' ) : __( 'Needs sync', 'mybookaro' ) ); ?>
                        </span>
                        <div class="bookaro-status-item__meta">
                            <?php
                            /* translators: 1: provider role display label, 2: provider role internal key */
                            echo esc_html( sprintf( __( '%1$s (%2$s)', 'mybookaro' ), $provider_role_label, $provider_role_key ) ); ?>
                        </div>
                    </div>
                </div>

                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Customer role', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $customer_role_status ); ?>">
                            <?php echo esc_html( $customer_role_ok ? __( 'Ready', 'mybookaro' ) : __( 'Needs sync', 'mybookaro' ) ); ?>
                        </span>
                        <div class="bookaro-status-item__meta">
                            <?php
                            /* translators: 1: customer role display label, 2: customer role internal key */
                            echo esc_html( sprintf( __( '%1$s (%2$s)', 'mybookaro' ), $customer_role_label, $customer_role_key ) ); ?>
                        </div>
                        <div class="bookaro-status-item__actions">
                            <a class="button button-small" href="<?php echo esc_url( $roles_url ); ?>">
                                <?php esc_html_e( 'Open Access tab', 'mybookaro' ); ?>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="bookaro-card bookaro-system-card">
            <div class="bookaro-card__header">
                <h2><?php esc_html_e( 'Generic mode', 'mybookaro' ); ?></h2>
                <p class="description"><?php esc_html_e( 'Review how Generic mode is currently mapped for listings and providers.', 'mybookaro' ); ?></p>
            </div>
            <div class="bookaro-status-list">
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Integration mode', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <?php
                        $mode_setting = $generic_status['integration_setting'] ?? 'auto';
                        $mode_resolved = $generic_status['integration_resolved'] ?? $mode_setting;
                        $generic_explicit = ! empty( $generic_status['generic_setup_explicitly_confirmed'] );
                        ?>
                        <?php if ( 'mylisting' === $mode_resolved ) : ?>
                            <span class="bookaro-status-pill bookaro-status-pill--info"><?php esc_html_e( 'Generic confirmation not required', 'mybookaro' ); ?></span>
                        <?php elseif ( $generic_confirmation_required ) : ?>
                            <span class="bookaro-status-pill bookaro-status-pill--error"><?php esc_html_e( 'Generic confirmation required', 'mybookaro' ); ?></span>
                        <?php elseif ( $generic_legacy_fallback_active ) : ?>
                            <span class="bookaro-status-pill bookaro-status-pill--warn"><?php esc_html_e( 'Legacy fallback review required', 'mybookaro' ); ?></span>
                        <?php elseif ( $generic_explicit ) : ?>
                            <span class="bookaro-status-pill bookaro-status-pill--ok"><?php esc_html_e( 'Generic explicitly confirmed', 'mybookaro' ); ?></span>
                        <?php endif; ?>
                        <div class="bookaro-status-item__meta"><?php echo esc_html( $mode_setting ); ?></div>
                        <?php if ( $mode_setting !== $mode_resolved ) : ?>
                            <div class="bookaro-status-item__meta"><?php
                            /* translators: %s: resolved integration mode label */
                            echo esc_html( sprintf( __( 'Resolved: %s', 'mybookaro' ), $mode_resolved ) ); ?></div>
                        <?php endif; ?>
                        <?php if ( ! empty( $generic_status['integration_reason'] ) ) : ?>
                            <div class="bookaro-status-item__meta"><?php echo esc_html( $generic_status['integration_reason'] ); ?></div>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Allowed listing types', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $allowed_types_class ); ?>">
                            <?php echo esc_html( $allowed_types_ok ? __( 'Configured', 'mybookaro' ) : __( 'Missing', 'mybookaro' ) ); ?>
                        </span>
                        <div class="bookaro-status-item__meta">
                            <?php
                            if ( empty( $allowed_types ) ) {
                                esc_html_e( 'None configured', 'mybookaro' );
                            } else {
                                echo esc_html( implode( ', ', $allowed_types ) );
                            }
                            ?>
                        </div>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Allowed listing pages', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $allowed_pages_class ); ?>">
                            <?php echo esc_html( empty( $allowed_pages ) ? __( 'All pages', 'mybookaro' ) : __( 'Restricted', 'mybookaro' ) ); ?>
                        </span>
                        <div class="bookaro-status-item__meta">
                            <?php
                            if ( empty( $allowed_pages ) ) {
                                esc_html_e( 'No restrictions applied', 'mybookaro' );
                            } else {
                                echo esc_html( implode( ', ', $allowed_pages ) );
                            }
                            ?>
                        </div>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Provider mapping', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <div class="bookaro-status-item__meta">
                            <?php
                            $mapping = $generic_status['provider_resolution_mode'] ?? 'author';
                            echo esc_html( $mapping );
                            $meta_key = $generic_status['provider_meta_key'] ?? '';
                            if ( $meta_key !== '' ) {
                                /* translators: %s: dynamic string */
                                echo ' ' . esc_html( sprintf( __( '(meta key: %s)', 'mybookaro' ), $meta_key ) );
                            }
                            ?>
                        </div>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Services mode', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <div class="bookaro-status-item__meta"><?php echo esc_html( $generic_status['services_mode'] ?? 'provider_only' ); ?></div>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Listing services cache', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <span class="bookaro-status-pill <?php echo esc_attr( $services_cache_enabled ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--info' ); ?>">
                            <?php echo esc_html( $services_cache_enabled ? __( 'Enabled', 'mybookaro' ) : __( 'Disabled', 'mybookaro' ) ); ?>
                        </span>
                        <span class="bookaro-status-pill <?php echo esc_attr( $services_cache_hooks_ok ? 'bookaro-status-pill--ok' : 'bookaro-status-pill--warn' ); ?>">
                            <?php echo esc_html( $services_cache_hooks_ok ? __( 'Invalidation hooks ready', 'mybookaro' ) : __( 'Invalidation hooks missing', 'mybookaro' ) ); ?>
                        </span>
                        <div class="bookaro-status-item__meta">
                            <?php
                            echo esc_html(
                                sprintf(
                                    /* translators: 1: cache ttl in seconds, 2: global cache version stamp */
                                    __( 'TTL: %1$d seconds | Global version: %2$d', 'mybookaro' ),
                                    $services_cache_ttl,
                                    $services_cache_global_version
                                )
                            );
                            ?>
                        </div>
                        <?php if ( $services_cache_global_timestamp > 0 ) : ?>
                            <div class="bookaro-status-item__meta">
                                <?php
                                echo esc_html(
                                    sprintf(
                                        /* translators: %s: datetime of last global cache bump */
                                        __( 'Last global bump: %s', 'mybookaro' ),
                                        wp_date( 'M j, Y H:i', $services_cache_global_timestamp )
                                    )
                                );
                                ?>
                            </div>
                        <?php else : ?>
                            <div class="bookaro-status-item__meta"><?php esc_html_e( 'No global cache bump recorded yet.', 'mybookaro' ); ?></div>
                        <?php endif; ?>
                        <div class="bookaro-status-item__meta">
                            <?php
                            echo esc_html(
                                sprintf(
                                    /* translators: 1: integration mode slug, 2: listing cache buster meta key */
                                    __( 'Mode: %1$s | Listing buster meta key: %2$s', 'mybookaro' ),
                                    $services_cache_mode !== '' ? $services_cache_mode : 'generic',
                                    $services_cache_meta_key
                                )
                            );
                            ?>
                        </div>
                        <div class="bookaro-status-item__meta">
                            <?php esc_html_e( 'Invalidation triggers: listing save, service save/update, service delete/trash/restore, and listing/service meta changes.', 'mybookaro' ); ?>
                        </div>
                        <div class="bookaro-status-item__meta">
                            <?php esc_html_e( 'After editing listings or services, save changes and refresh the affected listing. If stale services persist beyond TTL, clear page/object/CDN caches and re-test.', 'mybookaro' ); ?>
                        </div>
                        <?php if ( ! empty( $services_cache_missing_hooks ) ) : ?>
                            <div class="bookaro-status-item__meta">
                                <?php
                                echo esc_html(
                                    sprintf(
                                        /* translators: %s: comma-separated list of missing hook names */
                                        __( 'Missing invalidation hooks: %s', 'mybookaro' ),
                                        implode( ', ', $services_cache_missing_hooks )
                                    )
                                );
                                ?>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Page overrides', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <?php
                        $global_pages = $generic_status['global_pages'] ?? [];
                        $booking_id = absint( $global_pages['booking'] ?? 0 );
                        $provider_id = absint( $global_pages['provider_dashboard'] ?? 0 );
                        $customer_id = absint( $global_pages['customer_dashboard'] ?? 0 );
                        $meta_parts = [];
                        if ( $booking_id > 0 ) {
                            /* translators: %d: numeric value */
                            $meta_parts[] = sprintf( __( 'Booking: #%d', 'mybookaro' ), $booking_id );
                        }
                        if ( $provider_id > 0 ) {
                            /* translators: %d: numeric value */
                            $meta_parts[] = sprintf( __( 'Provider: #%d', 'mybookaro' ), $provider_id );
                        }
                        if ( $customer_id > 0 ) {
                            /* translators: %d: numeric value */
                            $meta_parts[] = sprintf( __( 'Customer: #%d', 'mybookaro' ), $customer_id );
                        }
                        ?>
                        <div class="bookaro-status-item__meta">
                            <?php
                            if ( empty( $meta_parts ) ) {
                                esc_html_e( 'Not set', 'mybookaro' );
                            } else {
                                echo esc_html( implode( ' | ', $meta_parts ) );
                            }
                            ?>
                        </div>
                        <?php
                        $per_type = $generic_status['listing_type_pages'] ?? [];
                        $rows = [];
                        if ( is_array( $per_type ) ) {
                            foreach ( $per_type as $post_type => $contexts ) {
                                if ( ! is_array( $contexts ) ) {
                                    continue;
                                }
                                $parts = [];
                                foreach ( [ 'booking', 'provider_dashboard', 'customer_dashboard' ] as $context ) {
                                    $page_id = absint( $contexts[ $context ] ?? 0 );
                                    if ( $page_id > 0 ) {
                                        $parts[] = $context . ': #' . $page_id;
                                    }
                                }
                                if ( ! empty( $parts ) ) {
                                    $rows[] = sanitize_key( $post_type ) . ' (' . implode( ', ', $parts ) . ')';
                                }
                            }
                        }
                        ?>
                        <div class="bookaro-status-item__meta">
                            <?php
                            if ( empty( $rows ) ) {
                                esc_html_e( 'Per-type overrides: none', 'mybookaro' );
                            } else {
                                echo esc_html( 'Per-type: ' . implode( '; ', $rows ) );
                            }
                            ?>
                        </div>
                    </div>
                </div>
                <div class="bookaro-status-item">
                    <div class="bookaro-status-item__label"><?php esc_html_e( 'Default provider', 'mybookaro' ); ?></div>
                    <div class="bookaro-status-item__value">
                        <div class="bookaro-status-item__meta">
                            <?php
                            $default_provider = $generic_status['default_provider'] ?? null;
                            if ( ! empty( $default_provider['label'] ) ) {
                                echo esc_html( $default_provider['label'] . ' (#' . (int) $default_provider['id'] . ')' );
                            } else {
                                esc_html_e( 'Not set', 'mybookaro' );
                            }
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="bookaro-card bookaro-system-report" id="bookaro-support-report">
        <div class="bookaro-card__header">
            <h2><?php esc_html_e( 'Support report', 'mybookaro' ); ?></h2>
            <p class="description"><?php esc_html_e( 'Check this section before opening support requests. Copy the compact masked snapshot first, then attach the Support Bundle if support needs the full diagnostic export.', 'mybookaro' ); ?></p>
        </div>
        <div class="bookaro-report-grid">
            <div id="bookaro-support-snapshot">
                <div class="bookaro-report-label"><?php esc_html_e( 'Support snapshot (masked, compact)', 'mybookaro' ); ?></div>
                <p class="description">
                    <?php
                    echo esc_html(
                        sprintf(
                            /* translators: %d: compact support snapshot line count */
                            __( 'Share-ready masked snapshot (%d lines) for tickets, comments, and chat.', 'mybookaro' ),
                            max( 0, (int) $support_share_summary_lines )
                        )
                    );
                    ?>
                </p>
                <textarea id="bookaro-support-share-summary" rows="9" class="large-text code" readonly spellcheck="false"><?php echo esc_textarea( $support_share_summary ); ?></textarea>
                <div class="bookaro-report-actions">
                    <button type="button" class="button button-primary" id="bookaro-copy-support-share-summary"><?php esc_html_e( 'Copy support snapshot', 'mybookaro' ); ?></button>
                    <button type="button" class="button" id="bookaro-select-support-share-summary"><?php esc_html_e( 'Select support snapshot', 'mybookaro' ); ?></button>
                    <span id="bookaro-copy-support-share-summary-status" class="description"></span>
                </div>
            </div>
            <div>
                <div class="bookaro-report-label"><?php esc_html_e( 'Ticket starter (subject + handoff)', 'mybookaro' ); ?></div>
                <p class="description">
                    <?php
                    echo esc_html(
                        sprintf(
                            /* translators: %d: ticket starter line count */
                            __( 'Copy-ready starter block (%d lines) for support tickets or internal handoff notes.', 'mybookaro' ),
                            max( 0, (int) $launch_handoff_message_lines )
                        )
                    );
                    ?>
                </p>
                <textarea id="bookaro-launch-handoff-message" rows="12" class="large-text code" readonly spellcheck="false"><?php echo esc_textarea( $launch_handoff_message ); ?></textarea>
                <input type="hidden" id="bookaro-launch-handoff-subject" value="<?php echo esc_attr( $launch_handoff_subject ); ?>">
                <div class="bookaro-report-actions">
                    <button type="button" class="button button-secondary" id="bookaro-copy-launch-handoff-message"><?php esc_html_e( 'Copy ticket starter', 'mybookaro' ); ?></button>
                    <button type="button" class="button" id="bookaro-select-launch-handoff-message"><?php esc_html_e( 'Select ticket starter', 'mybookaro' ); ?></button>
                    <button type="button" class="button" id="bookaro-copy-launch-handoff-subject"><?php esc_html_e( 'Copy subject only', 'mybookaro' ); ?></button>
                    <span id="bookaro-copy-launch-handoff-message-status" class="description"></span>
                </div>
            </div>
            <div>
                <div class="bookaro-report-label"><?php esc_html_e( 'Launch handoff (quick paste)', 'mybookaro' ); ?></div>
                <p class="description">
                    <?php
                    echo esc_html(
                        sprintf(
                            /* translators: %d: quick launch handoff line count */
                            __( 'Masked quick handoff block (%d lines) for comments, chat, and internal notes.', 'mybookaro' ),
                            max( 0, (int) $launch_blocker_quick_summary_lines )
                        )
                    );
                    ?>
                </p>
                <textarea id="bookaro-launch-blocker-quick-summary" rows="10" class="large-text code" readonly spellcheck="false"><?php echo esc_textarea( $launch_blocker_quick_summary ); ?></textarea>
                <div class="bookaro-report-actions">
                    <button type="button" class="button button-secondary" id="bookaro-copy-launch-quick-summary"><?php esc_html_e( 'Copy quick summary', 'mybookaro' ); ?></button>
                    <button type="button" class="button" id="bookaro-select-launch-quick-summary"><?php esc_html_e( 'Select quick summary', 'mybookaro' ); ?></button>
                    <span id="bookaro-copy-launch-quick-summary-status" class="description"></span>
                </div>
            </div>
            <div>
                <div class="bookaro-report-label"><?php esc_html_e( 'Launch handoff (detailed)', 'mybookaro' ); ?></div>
                <p class="description">
                    <?php
                    echo esc_html(
                        sprintf(
                            /* translators: %d: launch handoff line count */
                            __( 'Paste-ready support handoff block (%d lines). Copy from BEGIN to END markers.', 'mybookaro' ),
                            max( 0, (int) $launch_blocker_summary_lines )
                        )
                    );
                    ?>
                </p>
                <textarea id="bookaro-launch-blocker-summary" rows="14" class="large-text code" readonly spellcheck="false"><?php echo esc_textarea( $launch_blocker_summary ); ?></textarea>
                <div class="bookaro-report-actions">
                    <button type="button" class="button button-secondary" id="bookaro-copy-launch-summary"><?php esc_html_e( 'Copy detailed handoff', 'mybookaro' ); ?></button>
                    <button type="button" class="button" id="bookaro-select-launch-summary"><?php esc_html_e( 'Select detailed handoff', 'mybookaro' ); ?></button>
                    <button type="button" class="button" id="bookaro-copy-launch-summary-report"><?php esc_html_e( 'Copy detailed handoff + report', 'mybookaro' ); ?></button>
                    <span id="bookaro-copy-launch-summary-status" class="description"></span>
                </div>
            </div>
            <div>
                <div class="bookaro-report-label"><?php esc_html_e( 'Text report', 'mybookaro' ); ?></div>
                <textarea id="bookaro-system-report" rows="10" class="large-text code" readonly><?php echo esc_textarea( $report ); ?></textarea>
                <div class="bookaro-report-actions">
                    <button type="button" class="button button-secondary" id="bookaro-copy-report"><?php esc_html_e( 'Copy report', 'mybookaro' ); ?></button>
                    <span id="bookaro-copy-status" class="description"></span>
                </div>
            </div>
            <div id="bookaro-support-bundle">
                <div class="bookaro-report-label"><?php esc_html_e( 'JSON export', 'mybookaro' ); ?></div>
                <textarea id="bookaro-system-report-json" rows="10" class="large-text code" readonly><?php echo esc_textarea( $export_json ?? '' ); ?></textarea>
                <div class="bookaro-report-actions">
                    <button type="button" class="button button-secondary" id="bookaro-copy-json"><?php esc_html_e( 'Copy JSON', 'mybookaro' ); ?></button>
                    <button type="button" class="button" id="bookaro-download-json"><?php esc_html_e( 'Download JSON', 'mybookaro' ); ?></button>
                    <button type="button" class="button button-primary" id="bookaro-download-bundle"><?php esc_html_e( 'Download Support Bundle', 'mybookaro' ); ?></button>
                    <span class="description bookaro-support-bundle-hint"><?php esc_html_e( 'Attach this file after the masked snapshot when support needs the full diagnostic package.', 'mybookaro' ); ?></span>
                    <span id="bookaro-copy-json-status" class="description"></span>
                </div>
            </div>
        </div>
        <textarea id="bookaro-system-report-bundle" rows="8" class="bookaro-hidden" readonly><?php echo esc_textarea( $support_bundle_json ?? '' ); ?></textarea>
    </div>
</div>
