<?php
/**
 * VMPFence Tools View
 *
 * @package VMPFence
 * @since 1.0.0
 * @since 2.0.0 Updated to reflect VMP WordPress Security branding.
 * @since 2.1.0 Integrated with Live Traffic and Audit Log features.
 * @since 2.2.0 Integrated Diagnostics UI and Functionality and Export/Import Options
 * @since 2.2.1 Updated text-domain to vmpfence-security
 * @since 2.2.2 Updated to reflect VMP Security branding, improved UI/UX design.
 * @since 2.2.4 URL normalize for live traffic in the tab
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

// Get current traffic logging mode
$traffic_logging_mode = get_option('vmpfence_traffic_logging_mode', 'security_only');

// Detect active tab from URL parameter
$active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'live-traffic';

// Enqueue tools assets
wp_enqueue_style('vmpfence-tools-css', plugin_dir_url(dirname(__FILE__)) . 'assets/css/tools.css', array(), '2.0.0');

// Enqueue toast notification system
wp_enqueue_style('vmpfence-toast-notifications', plugin_dir_url(dirname(__FILE__)) . 'assets/css/toast-notifications.css', array(), '1.0.3');
wp_enqueue_script('vmpfence-toast-notifications', plugin_dir_url(dirname(__FILE__)) . 'assets/js/toast-notifications.js', array('jquery'), '1.0.3', true);

// Enqueue audit log assets (needed for Audit Log tab)
wp_enqueue_style('vmpfence-audit-log-css', plugin_dir_url(dirname(__FILE__)) . 'assets/css/audit-log.css', array(), '2.0.0');
wp_enqueue_script('vmpfence-audit-log-js', plugin_dir_url(dirname(__FILE__)) . 'assets/js/audit-log.js', array('jquery', 'vmpfence-toast-notifications'), '2.0.0', true);

// Enqueue diagnostics assets (needed for Diagnostics tab)
wp_enqueue_script('vmpfence-diagnostics-js', VMPFENCE_PLUGIN_URL . 'tools/assets/js/diagnostics.js', array('jquery'), '2.0.0', true);

// Localize diagnostics script
wp_localize_script('vmpfence-diagnostics-js', 'vmpfence_diagnostics', array(
    'nonce' => wp_create_nonce('vmpfence_diagnostics'),
    'ajaxurl' => admin_url('admin-ajax.php')
));

// Enqueue jQuery UI Datepicker and Slider (built into WordPress)
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script('jquery-ui-slider');
wp_enqueue_style('jquery-ui-css', 'https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css', array(), '1.12.1');

// Enqueue timepicker addon
wp_enqueue_script('jquery-ui-timepicker-addon', 'https://cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.6.3/jquery-ui-timepicker-addon.min.js', array('jquery', 'jquery-ui-datepicker', 'jquery-ui-slider'), '1.6.3', true);
wp_enqueue_style('jquery-ui-timepicker-addon-css', 'https://cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.6.3/jquery-ui-timepicker-addon.min.css', array('jquery-ui-css'), '1.6.3');

wp_enqueue_script('vmpfence-tools-js', plugin_dir_url(dirname(__FILE__)) . 'assets/js/tools.js', array('jquery', 'jquery-ui-datepicker', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), '2.0.0', true);

// Localize scripts
wp_localize_script('vmpfence-tools-js', 'vmpfenceToolsData', array(
    'nonce' => wp_create_nonce('vmpfence_tools_nonce'),
    'ajaxurl' => admin_url('admin-ajax.php')
));

wp_localize_script('vmpfence-diagnostics-js', 'vmpfenceTools', array(
    'nonce' => wp_create_nonce('vmpfence_tools_nonce'),
    'adminEmail' => get_option('admin_email')
));

wp_localize_script('vmpfence-audit-log-js', 'vmpfenceAuditLog', array(
    'nonce' => wp_create_nonce('vmpfence_audit_log_nonce'),
    'ajaxUrl' => admin_url('admin-ajax.php')
));

// Localize admin script for pause live updates functionality
wp_localize_script('vmpfence-admin', 'vmpfence_admin', array(
    'pause_live_updates' => VMPFence_Config::get('pause_live_updates', 1),
    'update_interval' => VMPFence_Config::get('update_interval', 10),
    'nonce' => wp_create_nonce('vmpfence_admin_nonce')
));
?>

<!-- WordPress Admin Notices Container (must be in .wrap for WordPress notices to display correctly) -->
<div class="wrap">
    <?php settings_errors(); ?>
</div>

<div class="vmpfence-tools-container">
    <!-- Tabs Navigation -->
    <div class="vmpfence-tabs">
        <div class="nav-tab-wrapper" style="max-width: 1300px;">
            <img src="<?php echo esc_url( VMPFENCE_PLUGIN_URL . 'admin/assets/images/VMP-logo.svg' ); ?>" alt="VMP Security" style="width: 36px; height: 36px; vertical-align: middle; margin-right: 2px; margin-left: 4px; display: inline-block; float: left; margin-top: 4px; padding-bottom: 7px;">
            <a href="?page=vmpfence-tools&tab=live-traffic" class="nav-tab <?php echo ($active_tab === 'live-traffic') ? 'nav-tab-active' : ''; ?>" style="padding: 8px 12px; border-radius: 6px 6px 0 0;<?php echo ($active_tab === 'live-traffic') ? ' color: #191970;' : ''; ?>"><?php echo esc_html__('Live Traffic', 'vmpfence-security'); ?></a>
            <a href="?page=vmpfence-tools&tab=audit-log" class="nav-tab <?php echo ($active_tab === 'audit-log') ? 'nav-tab-active' : ''; ?>" style="padding: 8px 12px; border-radius: 6px 6px 0 0;<?php echo ($active_tab === 'audit-log') ? ' color: #191970;' : ''; ?>"><?php echo esc_html__('Audit Log', 'vmpfence-security'); ?></a>
            <a href="?page=vmpfence-tools&tab=whois-lookup" class="nav-tab <?php echo ($active_tab === 'whois-lookup') ? 'nav-tab-active' : ''; ?>" style="padding: 8px 12px; border-radius: 6px 6px 0 0;<?php echo ($active_tab === 'whois-lookup') ? ' color: #191970;' : ''; ?>"><?php echo esc_html__('Whois Lookup', 'vmpfence-security'); ?></a>
            <a href="?page=vmpfence-tools&tab=import-export" class="nav-tab <?php echo ($active_tab === 'import-export') ? 'nav-tab-active' : ''; ?>" style="padding: 8px 12px; border-radius: 6px 6px 0 0;<?php echo ($active_tab === 'import-export') ? ' color: #191970;' : ''; ?>"><?php echo esc_html__('Import/Export Options', 'vmpfence-security'); ?></a>
            <a href="?page=vmpfence-tools&tab=diagnostics" class="nav-tab <?php echo ($active_tab === 'diagnostics') ? 'nav-tab-active' : ''; ?>" style="padding: 8px 12px; border-radius: 6px 6px 0 0;<?php echo ($active_tab === 'diagnostics') ? ' color: #191970;' : ''; ?>"><?php echo esc_html__('Diagnostics', 'vmpfence-security'); ?></a>
        </div>

        <!-- Live Traffic Tab -->
        <div id="live-traffic" class="vmpfence-tab-content <?php echo ($active_tab === 'live-traffic') ? 'active' : ''; ?>">
            
            <!-- Live Traffic Info -->
            <div class="vmpfence-traffic-logging-infor" style="margin-bottom: 15px; padding: 30px !important; background-color: #f9f9f9;">
                <p><?php echo esc_html__("VMP Security Live Traffic shows you what is happening on your site in real-time, including user logins, hack attempts, and requests that were blocked by the VMP Security Firewall. You can choose to log security-related traffic only or all traffic. Traffic is logged directly on the server, which means it includes visits that don't execute JavaScript. Google and other JavaScript-based analytics packages typically only show visits from browsers that are operated by a human, while Live Traffic can show visits from crawlers like Google and Bing.", 'vmpfence-security'); ?></p>
            </div>
            <!-- Collapsible Live Traffic Options -->
            <div class="vmpfence-options-panel" style="padding: 0 !important;">
                <div class="vmpfence-options-header-traffic" id="live-traffic-options-toggle">
                    <h3><?php echo esc_html__('Live Traffic Options', 'vmpfence-security'); ?></h3>
                    <span class="vmpfence-toggle-icon">▶</span>
                </div>
                
                <div class="vmpfence-options-content" id="live-traffic-options-content" style="display: none;">
                    <div class="vmpfence-options-description">
                        <p><?php echo esc_html__('These options let you choose which traffic to log and to ignore certain types of visitors, based on their level of access, usernames, IP address, or browser type. If you run a high-traffic website where it is not feasible to see your visitors in real-time, simply change the', 'vmpfence-security'); ?> <strong><?php echo esc_html__('Traffic logging mode', 'vmpfence-security'); ?></strong> <?php echo esc_html__('to "Security Only."', 'vmpfence-security'); ?></p>
                    </div>

                    <div class="vmpfence-options-buttons">
                        <button type="button" class="vmpfence-btn vmpfence-btn-default" id="restore-defaults"><?php echo esc_html__('RESTORE DEFAULTS', 'vmpfence-security'); ?></button>
                        <button type="button" class="vmpfence-btn vmpfence-btn-secondary" id="cancel-changes"><?php echo esc_html__('CANCEL CHANGES', 'vmpfence-security'); ?></button>
                        <button type="button" class="vmpfence-btn vmpfence-btn-primary" id="save-changes"><?php echo esc_html__('SAVE CHANGES', 'vmpfence-security'); ?></button>
                    </div>

                    <form id="vmpfence-live-traffic-options-form">
                        <!-- Traffic logging mode -->
                        <div class="vmpfence-option-row">
                            <label class="vmpfence-option-label">
                                <?php echo esc_html__('Traffic logging mode', 'vmpfence-security'); ?>
                                <span class="vmpfence-help-icon" title="<?php echo esc_attr__('Choose between security-only or all traffic logging', 'vmpfence-security'); ?>">?</span>
                            </label>
                            <div class="vmpfence-option-control">
                                <div class="vmpfence-button-group">
                                    <button type="button" class="vmpfence-mode-btn active" data-value="security_only"><?php echo esc_html__('SECURITY ONLY', 'vmpfence-security'); ?></button>
                                    <button type="button" class="vmpfence-mode-btn" data-value="all_traffic"><?php echo esc_html__('ALL TRAFFIC', 'vmpfence-security'); ?></button>
                                </div>
                                <input type="hidden" name="traffic_logging_mode" id="traffic_logging_mode" value="security_only">
                            </div>
                        </div>

                        <!-- Don't log signed-in users -->
                        <div class="vmpfence-option-row">
                            <label class="vmpfence-option-label">
                                    <input type="checkbox" name="ignore_publishing_users" id="ignore_publishing_users" value="1" style="margin: 0 !important;">
                                    <?php echo esc_html__("Don't log signed-in users with publishing access", 'vmpfence-security'); ?>
                            </label>
                            <div class="vmpfence-option-control">
                                <label class="vmpfence-checkbox-label">

                                </label>
                            </div>
                        </div>

                        <!-- Usernames to ignore -->
                        <div class="vmpfence-option-row">
                            <label class="vmpfence-option-label" for="ignore_usernames">
                                <?php echo esc_html__('List of comma separated usernames to ignore', 'vmpfence-security'); ?>
                            </label>
                            <div class="vmpfence-option-control">
                                <textarea name="ignore_usernames" id="ignore_usernames" rows="3" class="vmpfence-textarea"></textarea>
                            </div>
                        </div>

                        <!-- IP addresses to ignore -->
                        <div class="vmpfence-option-row">
                            <label class="vmpfence-option-label" for="ignore_ips">
                                <?php echo esc_html__('List of comma separated IP addresses to ignore', 'vmpfence-security'); ?>
                            </label>
                            <div class="vmpfence-option-control">
                                <textarea name="ignore_ips" id="ignore_ips" rows="3" class="vmpfence-textarea"></textarea>
                            </div>
                        </div>

                        <!-- User agent to ignore -->
                        <div class="vmpfence-option-row">
                            <label class="vmpfence-option-label" for="ignore_user_agent">
                                <?php echo esc_html__('Browser user-agent to ignore', 'vmpfence-security'); ?>
                            </label>
                            <div class="vmpfence-option-control">
                                <input type="text" name="ignore_user_agent" id="ignore_user_agent" class="vmpfence-input">
                            </div>
                        </div>

                        <!-- Amount of data to store -->
                        <div class="vmpfence-option-row">
                            <label class="vmpfence-option-label" for="max_traffic_rows">
                                <?php echo esc_html__('Amount of Live Traffic data to store (number of rows)', 'vmpfence-security'); ?>
                            </label>
                            <div class="vmpfence-option-control">
                                <input type="number" name="max_traffic_rows" id="max_traffic_rows" value="2000" min="100" max="50000" class="vmpfence-input-small">
                            </div>
                        </div>

                        <!-- Maximum days to keep data -->
                        <div class="vmpfence-option-row">
                            <label class="vmpfence-option-label" for="max_traffic_days">
                                <?php echo esc_html__('Maximum days to keep Live Traffic data (1-30 days)', 'vmpfence-security'); ?>
                            </label>
                            <div class="vmpfence-option-control">
                                <input type="number" name="max_traffic_days" id="max_traffic_days" value="30" min="1" max="30" class="vmpfence-input-small">
                            </div>
                        </div>

                        <!-- Display Live Traffic menu option -->
                        <div class="vmpfence-option-row">
                            <label class="vmpfence-option-label">
                                <input type="checkbox" name="display_live_traffic_menu" id="display_live_traffic_menu" value="1" style="margin: 0 !important;" checked>
                                <?php echo esc_html__('Display Live Traffic menu option', 'vmpfence-security'); ?>
                            </label>
                            <div class="vmpfence-option-control">
                                <label class="vmpfence-checkbox-label">
                                    
                                </label>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

            <!-- Traffic logging mode indicator -->
            <div class="vmpfence-traffic-logging-indicator">
                <p><?php 
                if ($traffic_logging_mode === 'all_traffic') {
                    echo '<strong>' . esc_html__('Traffic logging mode: All traffic.', 'vmpfence-security') . '</strong> ' . esc_html__('Regular traffic and security-related traffic will appear below.', 'vmpfence-security');
                } else {
                    echo '<strong>' . esc_html__('Traffic logging mode: Security-related traffic only.', 'vmpfence-security') . '</strong> ' . esc_html__('Login and firewall activity will appear below.', 'vmpfence-security');
                }
                ?></p>
            </div>

            <!-- Filter controls -->
            <div class="vmpfence-filter-controls">
                <div class="vmpfence-filter-section">
                    <label class="vmpfence-filter-label"><?php echo esc_html__('Filter Traffic:', 'vmpfence-security'); ?></label>
                    <div class="vmpfence-filter-dropdown">
                        <button type="button" class="vmpfence-filter-selected" id="vmpfence-filter-toggle">
                            <span class="vmpfence-filter-text"><?php echo esc_html__('All Hits', 'vmpfence-security'); ?></span>
                            <span class="vmpfence-filter-arrow">▼</span>
                        </button>
                        <div class="vmpfence-filter-list-wrapper" id="vmpfence-filter-list" style="display: none;">
                            <div class="vmpfence-filter-search">
                                <input type="text" class="vmpfence-filter-search-input" id="vmpfence-filter-search" placeholder="<?php echo esc_attr__('Search...', 'vmpfence-security'); ?>">
                            </div>
                            <ul class="vmpfence-filter-list-items">
                                <li data-value="all" class="selected"><?php echo esc_html__('All Hits', 'vmpfence-security'); ?></li>
                                <li data-value="humans"><?php echo esc_html__('Humans', 'vmpfence-security'); ?></li>
                                <li data-value="registered_users"><?php echo esc_html__('Registered Users', 'vmpfence-security'); ?></li>
                                <li data-value="crawlers"><?php echo esc_html__('Crawlers', 'vmpfence-security'); ?></li>
                                <li data-value="google_crawlers"><?php echo esc_html__('Google Crawlers', 'vmpfence-security'); ?></li>
                                <li data-value="pages_not_found"><?php echo esc_html__('Pages Not Found', 'vmpfence-security'); ?></li>
                                <li data-value="logins_logouts"><?php echo esc_html__('Logins and Logouts', 'vmpfence-security'); ?></li>
                                <li data-value="locked_out"><?php echo esc_html__('Locked Out', 'vmpfence-security'); ?></li>
                                <li data-value="blocked"><?php echo esc_html__('Blocked', 'vmpfence-security'); ?></li>
                                <li data-value="blocked_by_firewall"><?php echo esc_html__('Blocked By Firewall', 'vmpfence-security'); ?></li>
                            </ul>
                        </div>
                    </div>
                </div>

                <label>
                    <input type="checkbox" id="vmpfence-show-advanced-filters">
                    <?php echo esc_html__('Show Advanced Filters', 'vmpfence-security'); ?>
                </label>

                <label>
                    <input type="checkbox" id="vmpfence-expand-results">
                    <?php echo esc_html__('Expand All Results', 'vmpfence-security'); ?>
                </label>
            </div>

            <!-- Advanced Filter Builder -->
            <div id="vmpfence-advanced-filters" class="vmpfence-advanced-filters" style="display: none;">
                <div class="vmpfence-advanced-filters-header">
                    <h4><?php echo esc_html__('Advanced Filters', 'vmpfence-security'); ?></h4>
                </div>

                <div class="vmpfence-advanced-filters-layout">
                    <!-- Left Column: Filters -->
                    <div class="vmpfence-advanced-filters-left">
                        <!-- Filter Items Container -->
                        <div id="vmpfence-filter-items" class="vmpfence-filter-items">
                            <!-- Filter items will be added here dynamically -->
                        </div>

                        <!-- Filter Item Template (hidden) -->
                        <div id="vmpfence-filter-template" class="vmpfence-filter-item" style="display: none;">
                            <select class="vmpfence-filter-param">
                                <option value=""><?php echo esc_html__('Filter...', 'vmpfence-security'); ?></option>
                                <!-- Options populated via AJAX -->
                            </select>

                            <select class="vmpfence-filter-operator" style="display: none;">
                                <option value="=">=</option>
                                <option value="!=">!=</option>
                                <option value="contains"><?php echo esc_html__('contains', 'vmpfence-security'); ?></option>
                                <option value="notcontains"><?php echo esc_html__('does not contain', 'vmpfence-security'); ?></option>
                                <option value="regexp"><?php echo esc_html__('matches regexp', 'vmpfence-security'); ?></option>
                            </select>

                            <input type="text" class="vmpfence-filter-value" placeholder="<?php echo esc_attr__('Value', 'vmpfence-security'); ?>" style="display: none;">

                            <button type="button" class="vmpfence-btn-icon vmpfence-filter-remove" title="<?php echo esc_attr__('Remove filter', 'vmpfence-security'); ?>">
                                <span class="dashicons dashicons-no-alt"></span>
                            </button>
                        </div>

                        <!-- Add Filter Button -->
                        <button type="button" class="vmpfence-btn vmpfence-btn-secondary" id="vmpfence-add-filter">
                            <?php echo esc_html__('ADD FILTER', 'vmpfence-security'); ?>
                        </button>
                    </div>

                    <!-- Right Column: Date Range & Group By -->
                    <div class="vmpfence-advanced-filters-right">
                        <!-- Date Range Inputs -->
                        <div class="vmpfence-filter-date-section">
                            <label>
                                <strong><?php echo esc_html__('From:', 'vmpfence-security'); ?></strong>
                                <div class="vmpfence-date-input-group">
                                    <input type="text" id="vmpfence-filter-start-date" class="vmpfence-input-date vmpfence-datetimepicker" placeholder="<?php echo esc_attr__('Start date', 'vmpfence-security'); ?>" readonly>
                                    <button type="button" class="vmpfence-btn-sm vmpfence-btn-clear" id="vmpfence-clear-start-date"><?php echo esc_html__('CLEAR', 'vmpfence-security'); ?></button>
                                </div>
                            </label>

                            <label>
                                <strong><?php echo esc_html__('To:', 'vmpfence-security'); ?></strong>
                                <div class="vmpfence-date-input-group">
                                    <input type="text" id="vmpfence-filter-end-date" class="vmpfence-input-date vmpfence-datetimepicker" placeholder="<?php echo esc_attr__('End date', 'vmpfence-security'); ?>" readonly>
                                    <button type="button" class="vmpfence-btn-sm vmpfence-btn-clear" id="vmpfence-clear-end-date"><?php echo esc_html__('CLEAR', 'vmpfence-security'); ?></button>
                                </div>
                            </label>
                        </div>

                        <!-- Group By Dropdown -->
                        <div class="vmpfence-filter-groupby-section">
                            <label>
                                <strong><?php echo esc_html__('Group By:', 'vmpfence-security'); ?></strong>
                                <select id="vmpfence-filter-groupby" class="vmpfence-select">
                                    <option value=""><?php echo esc_html__('None', 'vmpfence-security'); ?></option>
                                    <!-- Options populated via AJAX -->
                                </select>
                            </label>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Traffic table -->
            <div id="live-traffic-table-container" class="vmpfence-traffic-table-container">
                <div class="vmpfence-loading"></div>
            </div>
        </div>

        <!-- Audit Log Tab -->
        <div id="audit-log" class="vmpfence-tab-content <?php echo ($active_tab === 'audit-log') ? 'active' : ''; ?>">
            <?php
            // Include the complete audit log page
            include VMPFENCE_PLUGIN_DIR . 'admin/views/audit-log.php';
            ?>
        </div>

        <!-- Whois Lookup Tab -->
        <div id="whois-lookup" class="vmpfence-tab-content <?php echo ($active_tab === 'whois-lookup') ? 'active' : ''; ?>">
            <div class="whois-lookup-container">
                <!-- Header -->
                <div class="whois-header">
                    <h2><?php echo esc_html__('Whois Lookup', 'vmpfence-security'); ?></h2>
                    <a href="https://en.wikipedia.org/wiki/WHOIS" target="_blank" rel="noopener noreferrer" class="whois-learn-more">
                        <?php echo esc_html__('Learn more about Whois Lookup', 'vmpfence-security'); ?>
                        <span class="dashicons dashicons-external"></span>
                    </a>
                </div>

                <!-- Description -->
                <div class="whois-description">
                    <p><?php echo esc_html__('The whois service gives you a way to look up who owns an IP address or domain name that is visiting your website or is engaging in malicious activity on your website.', 'vmpfence-security'); ?></p>
                    <p class="whois-note"><?php echo esc_html__('Note: Each lookup may query both IPv4 and IPv6 addresses if the domain has both records.', 'vmpfence-security'); ?></p>
                </div>

                <!-- Lookup Form -->
                <div class="whois-lookup-form">
                    <input type="text" 
                           id="whois-input" 
                           class="whois-input" 
                           placeholder="<?php echo esc_attr__('Enter IP address or domain name...', 'vmpfence-security'); ?>"
                    />
                    <button type="button" class="whois-button" id="whois-lookup-btn">
                        <span class="button-text"><?php echo esc_html__('LOOK UP IP OR DOMAIN', 'vmpfence-security'); ?></span>
                        <span class="dashicons dashicons-search"></span>
                    </button>
                </div>

                <!-- Results -->
                <div class="whois-results" id="whois-results" style="display: none;">
                    <div class="whois-results-content">
                        <!-- Results will be displayed here when feature is implemented -->
                    </div>
                </div>
            </div>
        </div>

        <!-- Import/Export Tab -->
        <div id="import-export" class="vmpfence-tab-content <?php echo ($active_tab === 'import-export') ? 'active' : ''; ?>">
            <div class="import-export-container">
                <!-- Header -->
                <div class="import-export-header">
                    <h2><?php echo esc_html__('Import/Export Options', 'vmpfence-security'); ?></h2>
                    <!-- <a href="#" target="_blank" rel="noopener noreferrer" class="import-export-learn-more">
                        <?php echo esc_html__('Learn more about importing and exporting options', 'vmpfence-security'); ?>
                        <span class="dashicons dashicons-external"></span>
                    </a> -->
                </div>

                <!-- Description -->
                <div class="import-export-description">
                    <p><?php echo esc_html__('To clone one site\'s configuration to another, use the import/export tools below.', 'vmpfence-security'); ?></p>
                    <p class="import-export-note"><?php echo esc_html__('Note: Sensitive data (API keys, licenses) will not be exported.', 'vmpfence-security'); ?></p>
                </div>

                <!-- Import/Export Options Panel -->
                <div class="import-export-panel">
                    <h3 class="import-export-panel-title"><?php echo esc_html__('Import/Export Options', 'vmpfence-security'); ?></h3>

                    <!-- Export Section -->
                    <div class="import-export-section">
                        <div class="import-export-section-content">
                            <label class="import-export-label">
                                <?php echo esc_html__('Export this site\'s VMP Security options for import on another site', 'vmpfence-security'); ?>
                                <span class="dashicons dashicons-editor-help import-export-help-icon" title="<?php echo esc_attr__('Generate a token to export your settings', 'vmpfence-security'); ?>"></span>
                            </label>
                            <button type="button" class="import-export-button" id="export-config-btn" onclick="vmpfenceExportConfig()">
                                <?php echo esc_html__('EXPORT OPTIONS', 'vmpfence-security'); ?>
                            </button>
                            <div id="export-result" class="import-export-result" style="display: none;"></div>
                        </div>
                    </div>

                    <!-- Import Section -->
                    <div class="import-export-section">
                        <div class="import-export-section-content">
                            <label class="import-export-label">
                                <?php echo esc_html__('Import VMP Security options from another site using a token', 'vmpfence-security'); ?>
                                <span class="dashicons dashicons-editor-help import-export-help-icon" title="<?php echo esc_attr__('Enter the token from another site to import settings', 'vmpfence-security'); ?>"></span>
                            </label>
                            <div class="import-export-input-group">
                                <textarea 
                                    id="import-token" 
                                    class="import-export-textarea" 
                                    rows="3"
                                    placeholder="<?php echo esc_attr__('Paste token here...', 'vmpfence-security'); ?>"
                                ></textarea>
                            </div>
                            <button type="button" class="import-export-button" id="import-config-btn" onclick="vmpfenceImportConfig()">
                                <?php echo esc_html__('IMPORT OPTIONS', 'vmpfence-security'); ?>
                            </button>
                            <div id="import-result" class="import-export-result" style="display: none;"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Diagnostics Tab -->
        <div id="diagnostics" class="vmpfence-tab-content <?php echo ($active_tab === 'diagnostics') ? 'active' : ''; ?>">
            <div class="diagnostics-container">
                <!-- Header -->
                <div class="diagnostics-header">
                    <h2><?php echo esc_html__('Diagnostics', 'vmpfence-security'); ?></h2>
                </div>

                <!-- Description and Actions -->
                <div class="diagnostics-top-section">
                    <div class="diagnostics-description">
                        <p><?php echo esc_html__('This page shows information that can be used for troubleshooting conflicts, configuration issues, or compatibility with other plugins, themes, or a host\'s environment. Failing tests are not always a sign of something that you need to fix, but can help the VMP Security team when troubleshooting a problem.', 'vmpfence-security'); ?> 
                        <!-- <a href="#" target="_blank" rel="noopener noreferrer"><?php echo esc_html__('(Learn More)', 'vmpfence-security'); ?></a> -->
                        </p>
                    </div>
                    <div class="diagnostics-actions">
                        <button type="button" id="vmpfence-export-diagnostics" class="diagnostics-button diagnostics-button-primary">
                            <?php echo esc_html__('EXPORT', 'vmpfence-security'); ?>
                        </button>
                        <button type="button" id="vmpfence-email-diagnostics" class="diagnostics-button diagnostics-button-primary">
                            <?php echo esc_html__('SEND REPORT BY EMAIL', 'vmpfence-security'); ?>
                        </button>
                        <button type="button" id="vmpfence-expand-all-diagnostics" class="diagnostics-button diagnostics-button-secondary">
                            <?php echo esc_html__('EXPAND ALL DIAGNOSTICS', 'vmpfence-security'); ?>
                        </button>
                    </div>

                    <!-- Email Report Form (hidden by default) -->
                    <div id="vmpfence-email-form" style="display: none; margin-top: 20px; padding: 20px; background: #f9f9f9; border: 1px solid #ddd; border-radius: 4px;">
                        <h3 style="margin-top: 0;"><?php echo esc_html__('Send Report by Email', 'vmpfence-security'); ?></h3>
                        <table class="form-table">
                            <tr>
                                <th scope="row">
                                    <label for="vmpfence-email-address"><?php echo esc_html__('Email address:', 'vmpfence-security'); ?></label>
                                </th>
                                <td>
                                    <input type="email" id="vmpfence-email-address" class="regular-text" value="<?php echo esc_attr(get_option('admin_email')); ?>" style="width: 100%; max-width: 500px;" />
                                </td>
                            </tr>
                            <tr>
                                <th scope="row">
                                    <label for="vmpfence-ticket-number"><?php echo esc_html__('Ticket Number/Forum Username:', 'vmpfence-security'); ?></label>
                                </th>
                                <td>
                                    <input type="text" id="vmpfence-ticket-number" class="regular-text" value="" style="width: 100%; max-width: 500px;" />
                                </td>
                            </tr>
                        </table>
                        <p class="submit" style="margin-top: 15px; padding-top: 0;">
                            <button type="button" id="vmpfence-send-email-btn" class="button button-primary">
                                <?php echo esc_html__('SEND', 'vmpfence-security'); ?>
                            </button>
                            <button type="button" id="vmpfence-cancel-email-btn" class="button" style="margin-left: 10px;">
                                <?php echo esc_html__('CANCEL', 'vmpfence-security'); ?>
                            </button>
                        </p>
                    </div>
                </div>

                <!-- Diagnostic Accordion Items -->
                <div class="diagnostics-accordion" id="vmpfence-diagnostics-section">
                    
                    <!-- VMP Security Status -->
                    <div class="diagnostics-accordion-item" id="vmpfence-status">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('VMP Security Status', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('General information about the VMP Security installation.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- Filesystem -->
                    <div class="diagnostics-accordion-item" id="filesystem-permissions">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('Filesystem', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('Ability to read/write various files.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- VMP Security Config -->
                    <div class="diagnostics-accordion-item" id="config-files">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('VMP Security Config', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('Ability to save VMP Security settings to the database.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- VMP Security Firewall -->
                    <div class="diagnostics-accordion-item" id="firewall-rules">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('VMP Security Firewall', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('Current WAF configuration.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- MySQL -->
                    <div class="diagnostics-accordion-item" id="mysql-version">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('MySQL', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('Database version and privileges.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- PHP Environment -->
                    <div class="diagnostics-accordion-item" id="php-environment">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('PHP Environment', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('PHP version, important PHP extensions.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- Connectivity (with warning) -->
                    <div class="diagnostics-accordion-item" id="connectivity">
                        <div class="diagnostics-accordion-header">
                            <span class="diagnostics-status-icon diagnostics-status-warning">⚠</span>
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('Connectivity', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('Ability to connect to the VMP Security servers and your own site.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- Time -->
                    <div class="diagnostics-accordion-item" id="time-synchronization">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('Time', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('Server time accuracy and applied offsets.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- IP Detection -->
                    <div class="diagnostics-accordion-item" id="ip-detection">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('IP Detection', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('Methods of detecting a visitor\'s IP address.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- WordPress Settings -->
                    <div class="diagnostics-accordion-item" id="wordpress-settings">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('WordPress Settings', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('WordPress version and internal settings/constants.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- WordPress Plugins -->
                    <div class="diagnostics-accordion-item" id="wordpress-plugins">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('WordPress Plugins', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('Status of installed plugins.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- Must-Use WordPress Plugins -->
                    <div class="diagnostics-accordion-item" id="mu-plugins">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('Must-Use WordPress Plugins', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('WordPress "mu-plugins" that are always active, including those provided by hosts.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- Drop-in WordPress Plugins -->
                    <div class="diagnostics-accordion-item" id="dropin-plugins">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('Drop-in WordPress Plugins', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('WordPress "drop-in" plugins that are active.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- Themes -->
                    <div class="diagnostics-accordion-item" id="wordpress-themes">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('Themes', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('Status of installed themes.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <p class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></p>
                        </div>
                    </div>

                    <!-- Cron Jobs -->
                    <div class="diagnostics-accordion-item" id="cron-jobs">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('Cron Jobs', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('List of WordPress cron jobs scheduled by WordPress, plugins, or themes.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <div class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></div>
                        </div>
                    </div>

                    <!-- Database Tables -->
                    <div class="diagnostics-accordion-item" id="database-tables">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('Database Tables', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('Database table names, sizes, timestamps, and other metadata.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <div class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></div>
                        </div>
                    </div>

                    <!-- Log Files -->
                    <div class="diagnostics-accordion-item" id="log-files">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('Log Files', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('PHP error logs generated by your site, if enabled by your host.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <div class="diagnostics-loading"><?php echo esc_html__('Loading...', 'vmpfence-security'); ?></div>
                        </div>
                    </div>

                    <!-- Other Tests -->
                    <div class="diagnostics-accordion-item" id="other-tests">
                        <div class="diagnostics-accordion-header">
                            <div class="diagnostics-accordion-title-section">
                                <strong class="diagnostics-accordion-title"><?php echo esc_html__('Other Tests', 'vmpfence-security'); ?></strong>
                                <span class="diagnostics-accordion-description"><?php echo esc_html__('System configuration, memory test, send test email from this server.', 'vmpfence-security'); ?></span>
                            </div>
                            <span class="diagnostics-accordion-arrow">›</span>
                        </div>
                        <div class="diagnostics-accordion-content" style="display: none;">
                            <table class="diagnostics-results-table">
                                <tr>
                                    <td style="text-align:left;">
                                        <a href="<?php echo site_url(); ?>?_vmpfsf=sysinfo&nonce=<?php echo wp_create_nonce('wp-ajax'); ?>" target="_blank" rel="noopener noreferrer" style="text-decoration: none;">
                                            <?php echo esc_html__('Click to view your system\'s configuration in a new window', 'vmpfence-security'); ?>
                                        </a>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align:left;">
                                        <a href="<?php echo site_url(); ?>?_vmpfsf=testmem&nonce=<?php echo wp_create_nonce('wp-ajax'); ?>" target="_blank" rel="noopener noreferrer" style="text-decoration: none;">
                                            <?php echo esc_html__('Test your WordPress host\'s available memory', 'vmpfence-security'); ?>
                                        </a>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 40%;">
                                        <?php echo esc_html__('Send a test email from this WordPress server to an email address:', 'vmpfence-security'); ?>
                                    </td>
                                    <td style="width: 60%; text-align: left;">
                                        <input type="email" id="vmpfence-test-email-input" placeholder="email@example.com" size="25" style="margin-right: 10px;" />
                                        <button type="button" class="button button-primary" id="vmpfence-send-test-email">
                                            <?php echo esc_html__('SEND TEST EMAIL', 'vmpfence-security'); ?>
                                        </button>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 40%;">
                                        <?php echo esc_html__('Send a test activity report email:', 'vmpfence-security'); ?>
                                    </td>
                                    <td style="width: 60%; text-align: left;">
                                        <input type="email" id="vmpfence-activity-report-email-input" placeholder="email@example.com" size="25" style="margin-right: 10px;" />
                                        <button type="button" class="button button-primary" id="vmpfence-send-activity-report">
                                            <?php echo esc_html__('SEND TEST ACTIVITY REPORT', 'vmpfence-security'); ?>
                                        </button>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<!-- Whois Lookup Modal -->
<div id="vmpfence-whois-modal" class="vmpfence-notification-modal vmpfence-whois-modal" style="display:none;">
    <div class="vmpfence-notification-modal-overlay"></div>
    <div class="vmpfence-whois-modal-content">
        <!-- Modal Header -->
        <div class="vmpfence-whois-modal-header">
            <h2 class="vmpfence-whois-modal-title">
                <span class="dashicons dashicons-search"></span>
                <?php echo esc_html__('Whois Lookup Results', 'vmpfence-security'); ?>
            </h2>
            <button type="button" class="vmpfence-whois-modal-close" title="<?php echo esc_attr__('Close', 'vmpfence-security'); ?>">
                <span class="dashicons dashicons-no-alt"></span>
            </button>
        </div>
        
        <!-- Modal Body -->
        <div class="vmpfence-whois-modal-body">
            <!-- Loading State -->
            <div class="vmpfence-whois-modal-loading" style="display:none;">
                <div class="vmpfence-whois-loading-spinner"></div>
                <p><?php echo esc_html__('Performing Whois lookup...', 'vmpfence-security'); ?></p>
            </div>
            
            <!-- Results Container -->
            <div id="vmpfence-whois-modal-results" class="vmpfence-whois-modal-results">
                <!-- Results will be dynamically inserted here -->
            </div>
        </div>
        
        <!-- Modal Footer -->
        <div class="vmpfence-whois-modal-footer">
            <button type="button" class="vmpfence-btn vmpfence-btn-secondary vmpfence-whois-modal-close-btn">
                <?php echo esc_html__('Close', 'vmpfence-security'); ?>
            </button>
        </div>
    </div>
</div>

<!-- Recent Traffic Modal -->
<div id="vmpfence-recent-traffic-modal" class="vmpfence-notification-modal vmpfence-recent-traffic-modal" style="display:none;">
    <div class="vmpfence-notification-modal-overlay"></div>
    <div class="vmpfence-recent-traffic-modal-content">
        <!-- Modal Header -->
        <div class="vmpfence-recent-traffic-modal-header">
            <h2 class="vmpfence-recent-traffic-modal-title">
                <span class="dashicons dashicons-clock"></span>
                <span class="modal-title-text"><?php echo esc_html__('Recent Activity', 'vmpfence-security'); ?></span>
            </h2>
            <button type="button" class="vmpfence-recent-traffic-modal-close" title="<?php echo esc_attr__('Close', 'vmpfence-security'); ?>">
                <span class="dashicons dashicons-no-alt"></span>
            </button>
        </div>
        
        <!-- Modal Body -->
        <div class="vmpfence-recent-traffic-modal-body">
            <!-- Loading State -->
            <div class="vmpfence-recent-traffic-modal-loading" style="display:none;">
                <div class="vmpfence-recent-traffic-loading-spinner"></div>
                <p><?php echo esc_html__('Loading recent activity...', 'vmpfence-security'); ?></p>
            </div>
            
            <!-- Results Container -->
            <div id="vmpfence-recent-traffic-modal-results" class="vmpfence-recent-traffic-modal-results">
                <!-- Results will be dynamically inserted here -->
            </div>
        </div>
        
        <!-- Modal Footer -->
        <div class="vmpfence-recent-traffic-modal-footer">
            <button type="button" class="vmpfence-btn vmpfence-btn-secondary vmpfence-recent-traffic-modal-close-btn">
                <?php echo esc_html__('Close', 'vmpfence-security'); ?>
            </button>
        </div>
    </div>
</div>

<script>
jQuery(document).ready(function($) {
    // Update URL to include tab parameter if missing
    if (window.location.search.indexOf('tab=') === -1 && window.location.search.indexOf('page=vmpfence-tools') !== -1) {
        var newUrl = window.location.href + '&tab=live-traffic';
        window.history.replaceState({path: newUrl}, '', newUrl);
    }
});
</script>
