<?php
/**
 * Global Options Page - License Management & Settings
 *
 * @package VMPFence
 * @since 2.2.2
 * @since 2.2.3 - Improved license activation and deactivation handling, UI enhancements, Button navigation fix
 * @since 2.2.4 - Added immediate license refresh on page load, Added fallback check for license key in case of old bug clearing it, Added error handling and logging for license, Enqueued toast notification system for user feedback on license actions, Firewall Options, removed handle license activation by Ador
 * @since 2.2.5 - Added Firewall Options, Blocking Options, Scan Options, Live Traffic Options and Audit Log options
 */

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

// Ensure API client class is loaded
require_once VMPFENCE_PLUGIN_DIR . 'lib/class-api-client.php';

// Handle license deactivation
if (isset($_POST['deactivate_license'])) {
    // Verify nonce
    if (!check_admin_referer('vmpfence_api_management', 'vmpfence_api_management_nonce', false)) {
        wp_die('Security check failed. Please refresh the page and try again.');
    }
    
    $api_client = new VMPFence_API_Client();
    $license_key = VMPFence_Config::get('license_key', '');
    $site_url = home_url();
    
    $result = $api_client->deactivate_license($license_key, $site_url);
    
    if (!is_wp_error($result) && isset($result['success']) && $result['success']) {
        // Clear license refresh transient to force immediate update
        delete_transient('vmpfence_license_last_refresh');
        
        // CRITICAL: Clear premium cache to prevent stale "premium" status
        delete_transient('vmpfence_is_premium');
        delete_transient('vmpfence_license_status');
        
        // CRITICAL: Set manual deactivation flag to prevent auto-reactivation
        VMPFence_Config::set('license_manually_deactivated', true);
        
        // Extract FREE license key from server response
        $free_license_key = isset($result['new_free_license_key']) ? $result['new_free_license_key'] : '';
        
        VMPFence_Config::set('license_type', VMPFence_Constants::LICENSE_FREE);
        VMPFence_Config::set('license_key', $free_license_key);
        VMPFence_Config::set('firewall_license_tier', 'free');
        VMPFence_Config::set('scanner_license_tier', 'free');
        update_option('vmpfence_scanner_license_tier', 'free');
        update_option('vmpfence_license', array(
            'license_type' => 'free',
            'license_key' => $free_license_key,
            'deactivated_at' => current_time('mysql')
        ));
        // Also update license_status option
        update_option('vmpfence_license_status', array(
            'type' => 'free',
            'key' => $free_license_key,
            'updated_at' => current_time('mysql')
        ));
        
        // Use JavaScript redirect to avoid "headers already sent" error
        $redirect_url = add_query_arg(array(
            'page' => 'vmpfence-all-options',
            'license_deactivated' => '1',
            'cache_bust' => time()
        ), admin_url('admin.php'));
        
        echo '<script type="text/javascript">window.location.href = ' . wp_json_encode($redirect_url) . ';</script>';
        echo '<noscript><meta http-equiv="refresh" content="0;url=' . esc_url($redirect_url) . '"></noscript>';
        exit;
    } else {
        // Handle deactivation error
        $error_msg = is_wp_error($result) 
            ? $result->get_error_message() 
            : (isset($result['message']) ? $result['message'] : 'Unknown error occurred');
        
        // Store error in transient for display via toast
        set_transient('vmpfence_deactivation_error', $error_msg, 30);
        
        // Redirect back to show error
        wp_safe_redirect(add_query_arg(array(
            'page' => 'vmpfence-all-options',
            'deactivation_error' => '1',
            'cache_bust' => time()
        ), admin_url('admin.php')));
        exit;
    }
}

// Enqueue Toast Notification System
wp_enqueue_style('vmpfence-toast-notifications', VMPFENCE_PLUGIN_URL . 'admin/assets/css/toast-notifications.css', array(), VMPFENCE_VERSION);
wp_enqueue_script('vmpfence-toast-notifications', VMPFENCE_PLUGIN_URL . 'admin/assets/js/toast-notifications.js', array('jquery'), VMPFENCE_VERSION, true);

// Enqueue admin styles
wp_enqueue_style('vmpfence-admin', VMPFENCE_PLUGIN_URL . 'admin/assets/css/admin.css', array(), VMPFENCE_VERSION);

// Enqueue All Options styles and scripts
wp_enqueue_style('vmpfence-all-options', VMPFENCE_PLUGIN_URL . 'all-options/all-options.css', array(), VMPFENCE_VERSION);
wp_enqueue_script('vmpfence-all-options', VMPFENCE_PLUGIN_URL . 'all-options/all-options.js', array('jquery', 'vmpfence-toast-notifications'), VMPFENCE_VERSION . '-' . time(), true);

// Enqueue WAF optimization assets (for Optimize Firewall / Remove Extended Protection buttons)
wp_enqueue_style('vmpfence-waf-optimization-modals', VMPFENCE_PLUGIN_URL . 'admin/assets/css/waf-optimization-modals.css', array(), VMPFENCE_VERSION);
wp_enqueue_script('vmpfence-waf-optimization', VMPFENCE_PLUGIN_URL . 'admin/assets/js/waf-optimization.js', array('jquery'), VMPFENCE_VERSION, true);
wp_localize_script('vmpfence-waf-optimization', 'vmpfence_waf_ajax', array(
    'ajax_url' => admin_url('admin-ajax.php'),
    'waf_optimizer_nonce' => wp_create_nonce('vmpfence_waf_optimizer_nonce')
));

// Check for deactivation success/error and prepare toast notifications
$deactivation_success = isset($_GET['license_deactivated']) && $_GET['license_deactivated'] === '1';
$deactivation_error = isset($_GET['deactivation_error']) && $_GET['deactivation_error'] === '1';
$error_message = '';

if ($deactivation_error) {
    $error_message = get_transient('vmpfence_deactivation_error');
    delete_transient('vmpfence_deactivation_error');
    if (empty($error_message)) {
        $error_message = 'License deactivation failed. Please try again or contact support.';
    }
}

// Localize script for AJAX and notifications
wp_localize_script('vmpfence-all-options', 'vmpfenceAllOptions', array(
    'ajax_url' => admin_url('admin-ajax.php'),
    'nonce' => wp_create_nonce('vmpfence_all_options_save'),
    'deactivation_success' => $deactivation_success,
    'deactivation_error' => $deactivation_error,
    'error_message' => $error_message
));

// Get current view customization settings
$display_all_options = VMPFence_Config::get('display_all_options_menu', 1);
$display_blocking = VMPFence_Config::get('blocking_menu_display', 1);
$display_live_traffic = VMPFence_Config::get('display_live_traffic_menu', 0);
$display_audit_log = VMPFence_Config::get('display_audit_log_menu', 1);

?>

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

<div class="vmpfence-options-toolbar">
    <div class="vmpfence-search-container">
        <input type="text" id="vmpfence-options-search" class="vmpfence-search-input" placeholder="Search All Options" autocomplete="off">
        <div class="vmpfence-search-message" style="display: none;">Please enter 2 or more characters</div>
    </div>
    <div class="vmpfence-toolbar-buttons">
        <button type="button" class="button vmpfence-btn-restore">RESTORE DEFAULTS</button>
        <button type="button" class="button vmpfence-btn-cancel">CANCEL CHANGES</button>
        <button type="button" class="button button-primary vmpfence-btn-save">SAVE CHANGES</button>
    </div>
</div>

<div class="vmpfence-all-options-page">
    <div class="vmpfence-page-header">
        <h1><img src="<?php echo esc_url( VMPFENCE_PLUGIN_URL . 'admin/assets/images/VMP-logo.svg' ); ?>" alt="VMP Fence" style="width: 32px; height: 32px; vertical-align: middle; margin-right: 10px; margin-bottom: 8px;"> 
            <span style="font-weight: 600; font-size: 28px;">All Options</span></h1>
        <button type="button" class="button vmpfence-expand-all" id="vmpfence-expand-all">EXPAND ALL</button>
    </div>
    
    <p class="vmpfence-description">These options are also available throughout the plugin pages, in the relevant sections. This page is provided for easier setup for experienced VMP Security users.</p>
    
    <!-- VMP Security Global Options Section -->
    <div class="all-options-section" id="vmpfence-global-options">
        <h2 class="all-options-section-header">VMP Security Global Options</h2>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>VMP Security License</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                // ✅ CRITICAL FIX: Refresh license data when All Options page loads
                // This ensures license key is up-to-date even if user deactivated from website dashboard
                // We do this check here (instead of relying on hourly admin_init hook) to provide
                // immediate feedback when users manage licenses from the website
                if (class_exists('VMPFence_API_Client') && class_exists('VMPFence_License') && class_exists('VMPFence_Config')) {
                    try {
                        $api_key = VMPFence_Config::get('central_api_key', '');
                        if (!empty($api_key)) {
                            $api_client = new VMPFence_API_Client();
                            $license_data = $api_client->check_api_key($api_key);
                            if (!is_wp_error($license_data) && isset($license_data['license_key'])) {
                                VMPFence_License::update_license_settings($license_data);
                            }
                        }
                    } catch (Exception $e) {
                        // Silently fail - license refresh is not critical for page display
                    }
                }
                
                // Get license information
                $license_type = VMPFence_License::get_license_type();
                
                // ✅ CRITICAL FIX: Clear config cache for license_key to force fresh read from database
                // This ensures the All Options page always shows the latest license key
                // even after background sync updates it (sync happens AFTER page load)
                VMPFence_Config::clear_cache('license_key');
                
                $license_key = VMPFence_Config::get('license_key', '');
                $central_api_key = VMPFence_Config::get('central_api_key', '');
                $is_premium = ($license_type === VMPFence_Constants::LICENSE_PREMIUM);
                
                // ✅ FALLBACK: If license_key is empty, check vmpfence_license option (may have been cleared by old bug)
                if (empty($license_key)) {
                    $license_option = get_option('vmpfence_license', array());
                    if (!empty($license_option['license_key'])) {
                        $license_key = $license_option['license_key'];
                        // Restore it to VMPFence_Config for future use
                        VMPFence_Config::set('license_key', $license_key);
                    }
                }
                
                // Display license key
                $display_key = $license_key;
                ?>
                
                <div class="vmpfence-license-container">
                    <h3>Your VMP Security License</h3>
                    
                    <div class="vmpfence-license-key-group">
                        <label class="vmpfence-license-key-label">
                            License Key
                            <span class="vmpfence-license-key-help" title="Your unique license key identifier">?</span>
                        </label>
                        <input type="text" id="vmpfence-license-key-input" value="<?php echo esc_attr($display_key); ?>" onclick="this.select();">
                    </div>
                    
                    <div class="vmpfence-license-status-row">
                        <div>
                            <strong class="vmpfence-license-status-text">License Status:</strong>
                            <span class="vmpfence-license-status-value <?php echo $is_premium ? 'premium' : 'free'; ?>">
                                <?php echo $is_premium ? 'Premium License Active' : 'Free License Active'; ?>
                            </span>
                        </div>
                        <div class="vmpfence-license-actions">
                            <?php if ($is_premium): ?>
                                <form method="post" action="" id="vmpfence-deactivate-form">
                                    <?php wp_nonce_field('vmpfence_api_management', 'vmpfence_api_management_nonce'); ?>
                                    <input type="hidden" name="deactivate_license" value="1">
                                    <button type="submit" class="vmpfence-deactivate-btn">
                                        Reset site to a free license
                                    </button>
                                </form>
                                <a href="https://vmpsecurity.com/login-page/" target="_blank" class="vmpfence-license-link">
                                    Click here to manage your VMP Security licenses
                                </a>
                                <button type="button" class="button button-secondary" id="vmpfence-change-license-btn-premium" style="margin-top: 10px;">
                                    Install different license
                                </button>
                            <?php else: ?>
                                <a href="https://vmpsecurity.com/login-page/" target="_blank" class="vmpfence-license-link">
                                    Click here to manage your VMP Security licenses
                                </a>
                                <a href="https://vmpsecurity.com/products/" target="_blank" class="button button-primary vmpfence-upgrade-btn">
                                    Upgrade to Premium
                                </a>
                                <button type="button" class="button button-secondary vmpfence-change-license-btn" id="vmpfence-change-license-btn-free">
                                    Install different license
                                </button>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>View Customization</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <div class="vmpfence-view-customization">
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" name="display_all_options_menu" value="1" <?php checked($display_all_options, '1'); ?>>
                            <span>Display "All Options" menu item</span>
                        </label>
                    </div>
                    
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" name="display_blocking_menu" value="1" <?php checked($display_blocking, 1); ?>>
                            <span>Display "Blocking" menu item</span>
                        </label>
                    </div>
                    
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" name="display_live_traffic_menu" value="1" <?php checked($display_live_traffic, '1'); ?>>
                            <span>Display "Live Traffic" menu item</span>
                        </label>
                    </div>
                    
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" name="display_audit_log_menu" value="1" <?php checked($display_audit_log, '1'); ?>>
                            <span>Display "Audit Log" menu item</span>
                        </label>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>General VMP Security Options</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <div class="vmpfence-options-table" id="vmpfence-general-options">
                    <div class="vmpfence-option-row">
                        <div class="vmpfence-option-check">
                            <?php $auto_update_enabled = VMPFence_Config::get('auto_update', 0); ?>
                            <input type="checkbox" id="vmpfence_auto_update" <?php checked($auto_update_enabled, 1); ?> />
                        </div>
                        <div class="vmpfence-option-label">
                            <div class="vmpfence-option-title">
                                Update VMP Security automatically when a new version is released?
                                <span class="vmpfence-option-help" title="Enable automatic updates for VMP Security.">?</span>
                            </div>
                            <div class="vmpfence-option-desc">Automatically updates VMP Security to the newest version within 24 hours of a new release.</div>
                        </div>
                        <div class="vmpfence-option-input"></div>
                    </div>

                    <div class="vmpfence-option-row">
                        <div class="vmpfence-option-check"></div>
                        <div class="vmpfence-option-label">
                            <div class="vmpfence-option-title">
                                Where to email alerts
                                <span class="vmpfence-option-help" title="This is the email address where VMP Security sends its security alerts. You can add multiple email addresses separated by commas.">?</span>
                            </div>
                            <div class="vmpfence-option-desc">This should usually be your WordPress site administrator's email address, but you can add multiple email addresses here and separate them using commas.</div>
                        </div>
                        <div class="vmpfence-option-input">
                            <?php
                            // Toggle between two email sources:
                            // Option 1: Use plugin's notification_email (custom email set by user)
                            // Option 2: Use WordPress admin_email (default administrator email)
                            // Set $use_admin_email to true to use WordPress admin email as default
                            $use_admin_email = false; // Toggle: true = admin_email, false = notification_email
                            
                            if ($use_admin_email) {
                                // Use WordPress administrator email
                                $alert_email = VMPFence_Config::get('notification_email', get_option('admin_email'));
                            } else {
                                // Use plugin activation email (if available)
                                $activation_email = VMPFence_Config::get('license_email', '');
                                $alert_email = VMPFence_Config::get('notification_email', !empty($activation_email) ? $activation_email : get_option('admin_email'));
                            }
                            ?>
                            <input type="text" class="vmpfence-text-input" id="vmpfence_alert_email" value="<?php echo esc_attr($alert_email); ?>" placeholder="admin@example.com, security@example.com" />
                        </div>
                    </div>

                    <div class="vmpfence-option-row vmpfence-option-row--tall">
                        <div class="vmpfence-option-check"></div>
                        <div class="vmpfence-option-label">
                            <div class="vmpfence-option-title">
                                How does VMP Security get IPs
                                <span class="vmpfence-option-help" title="Choose how visitor IP addresses are detected.">?</span>
                            </div>

                            <?php
                            // Get saved IP detection method
                            $ip_method = VMPFence_Config::get('ip_detection_method', 'auto');
                            ?>
                            <div class="vmpfence-radio-group">
                                <label class="vmpfence-radio-item">
                                    <input type="radio" name="vmpfence_ip_method" value="auto" <?php checked($ip_method, 'auto'); ?> />
                                    <span>Let VMP Security use the most secure method to get visitor IP addresses. Prevents spoofing and works with most sites. <strong>(Recommended)</strong></span>
                                </label>
                                <label class="vmpfence-radio-item">
                                    <input type="radio" name="vmpfence_ip_method" value="REMOTE_ADDR" <?php checked($ip_method, 'REMOTE_ADDR'); ?> />
                                    <span>Use PHP's built in REMOTE_ADDR and don't use anything else. Very secure if this is compatible with your site.</span>
                                </label>
                                <label class="vmpfence-radio-item">
                                    <input type="radio" name="vmpfence_ip_method" value="HTTP_X_FORWARDED_FOR" <?php checked($ip_method, 'HTTP_X_FORWARDED_FOR'); ?> />
                                    <span>Use the X-Forwarded-For HTTP header. Only use if you have a front-end proxy or spoofing may result.</span>
                                </label>
                                <label class="vmpfence-radio-item">
                                    <input type="radio" name="vmpfence_ip_method" value="HTTP_X_REAL_IP" <?php checked($ip_method, 'HTTP_X_REAL_IP'); ?> />
                                    <span>Use the X-Real-IP HTTP header. Only use if you have a front-end proxy or spoofing may result.</span>
                                </label>
                                <label class="vmpfence-radio-item">
                                    <input type="radio" name="vmpfence_ip_method" value="HTTP_CF_CONNECTING_IP" <?php checked($ip_method, 'HTTP_CF_CONNECTING_IP'); ?> />
                                    <span>Use the Cloudflare "CF-Connecting-IP" HTTP header to get a visitor IP. Only use if you're using Cloudflare.</span>
                                </label>
                            </div>

                            <div class="vmpfence-option-note">
                                <?php
                                $detected_ip = VMPFence_Utils::get_real_ip();
                                $method_ip = VMPFence_Utils::get_ip_by_method($ip_method);
                                ?>
                                <div><strong>Detected IP(s):</strong> <?php echo esc_html($detected_ip); ?></div>
                                <div>Your IP with this setting: <?php echo esc_html($method_ip); ?></div>
                                <a class="vmpfence-inline-link vmpfence-edit-trusted-proxies" href="#" aria-expanded="false">+ Edit trusted proxies</a>

                                <div class="vmpfence-trusted-proxies-panel" aria-hidden="true">
                                    <div class="vmpfence-trusted-proxy-row">
                                        <div class="vmpfence-trusted-proxy-label">
                                            <div class="vmpfence-trusted-proxy-title">Trusted Proxies</div>
                                            <div class="vmpfence-trusted-proxy-desc">These IPs (or CIDR ranges) will be ignored when determining the requesting IP via the X-Forwarded-For HTTP header. Enter one IP or CIDR range per line.</div>
                                        </div>
                                        <div class="vmpfence-trusted-proxy-input">
                                            <?php
                                            $trusted_proxies = VMPFence_Config::get('trusted_proxies', '');
                                            ?>
                                            <textarea class="vmpfence-textarea" id="vmpfence_trusted_proxies" rows="4"><?php echo esc_textarea($trusted_proxies); ?></textarea>
                                        </div>
                                    </div>

                                    <div class="vmpfence-trusted-proxy-row">
                                        <div class="vmpfence-trusted-proxy-label">
                                            <div class="vmpfence-trusted-proxy-title">Trusted Proxy Preset</div>
                                            <div class="vmpfence-trusted-proxy-desc">In addition to the above list, the IPs (or CIDR ranges) in the selected preset will be ignored when determining the requesting IP via the X-Forwarded-For HTTP header.</div>
                                        </div>
                                        <div class="vmpfence-trusted-proxy-input">
                                            <?php
                                            // Load proxy presets
                                            require_once VMPFENCE_PLUGIN_DIR . 'all-options/class-proxy-presets.php';
                                            $preset_options = VMPFence_Proxy_Presets::get_preset_options();
                                            $selected_preset = VMPFence_Config::get('trusted_proxy_preset', '');
                                            ?>
                                            <select class="vmpfence-select" id="vmpfence_trusted_proxy_preset">
                                                <?php foreach ($preset_options as $value => $label): ?>
                                                    <option value="<?php echo esc_attr($value); ?>" <?php selected($selected_preset, $value); ?>>
                                                        <?php echo esc_html($label); ?>
                                                    </option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="vmpfence-option-input"></div>
                    </div>

                    <!-- <div class="vmpfence-option-row">
                        <div class="vmpfence-option-check">
                            <input type="checkbox" id="vmpfence_lookup_ip" checked />
                        </div>
                        <div class="vmpfence-option-label">
                            <div class="vmpfence-option-title">
                                Look up visitor IP locations via VMP Security servers
                                <span class="vmpfence-option-help" title="Enables IP geolocation lookups.">?</span>
                            </div>
                            <div class="vmpfence-option-desc">If this option is disabled, VMP Security can look up countries for visitor IP addresses using a local database, but cannot look up regions or cities.</div>
                        </div>
                        <div class="vmpfence-option-input"></div>
                    </div> -->

                    <div class="vmpfence-option-row">
                        <div class="vmpfence-option-check">
                            <?php $hide_wp_version = VMPFence_Config::get('hide_wp_version', 0); ?>
                            <input type="checkbox" id="vmpfence_hide_wp_version" <?php checked($hide_wp_version, 1); ?> />
                        </div>
                        <div class="vmpfence-option-label">
                            <div class="vmpfence-option-title">Hide WordPress version <span class="vmpfence-option-help" title="Hides the WordPress version from public output.">?</span></div>
                            <div class="vmpfence-option-desc">Removes WordPress version from HTML meta tags, RSS feeds, and asset URLs. Reduces information disclosure for attackers.</div>
                        </div>
                        <div class="vmpfence-option-input"></div>
                    </div>

                    <!-- This need to modify the .htaccess file, so disabled for now. Will be re-added later when .htaccess modifications can be better managed. -->
                    <!-- <div class="vmpfence-option-row">
                        <div class="vmpfence-option-check">
                            <input type="checkbox" id="vmpfence_disable_uploads_exec" />
                        </div>
                        <div class="vmpfence-option-label">
                            <div class="vmpfence-option-title">Disable Code Execution for Uploads directory <span class="vmpfence-option-help" title="Prevents PHP execution inside the uploads directory.">?</span></div>
                        </div>
                        <div class="vmpfence-option-input"></div>
                    </div> -->

                    <div class="vmpfence-option-row">
                        <div class="vmpfence-option-check">
                            <?php $pause_live_updates = VMPFence_Config::get('pause_live_updates', 1); ?>
                            <input type="checkbox" id="vmpfence_pause_live_updates" <?php checked($pause_live_updates, 1); ?> />
                        </div>
                        <div class="vmpfence-option-label">
                            <div class="vmpfence-option-title">Pause live updates when window loses focus <span class="vmpfence-option-help" title="Reduces CPU usage by pausing live updates.">?</span></div>
                        </div>
                        <div class="vmpfence-option-input"></div>
                    </div>

                    <div class="vmpfence-option-row">
                        <div class="vmpfence-option-check"></div>
                        <div class="vmpfence-option-label">
                            <div class="vmpfence-option-title">Update interval in seconds <span class="vmpfence-option-help" title="Controls how often the UI refreshes.">?</span></div>
                            <div class="vmpfence-option-desc">Setting higher will reduce browser traffic but slow scan starts, live traffic &amp; status updates.</div>
                        </div>
                        <div class="vmpfence-option-input">
                            <?php $update_interval = VMPFence_Config::get('update_interval', 10); ?>
                            <input type="number" class="vmpfence-text-input vmpfence-text-input--small" id="vmpfence_update_interval" value="<?php echo esc_attr($update_interval); ?>" min="1" step="1" />
                        </div>
                    </div>

                    <!-- <div class="vmpfence-option-row">
                        <div class="vmpfence-option-check">
                            <input type="checkbox" id="vmpfence_noabort" />
                        </div>
                        <div class="vmpfence-option-label">
                            <div class="vmpfence-option-title">Bypass the LiteSpeed "noabort" check <span class="vmpfence-option-help" title="Bypass compatibility check for specific server environments.">?</span></div>
                        </div>
                        <div class="vmpfence-option-input"></div>
                    </div> -->

                    <div class="vmpfence-option-row">
                        <div class="vmpfence-option-check">
                            <?php $enable_deactivation_choice = get_option('vmpfence_enable_deactivation_choice', 0); ?>
                            <input type="checkbox" id="vmpfence_enable_deactivation_choice" <?php checked($enable_deactivation_choice, 1); ?> />
                        </div>
                        <div class="vmpfence-option-label">
                            <div class="vmpfence-option-title">Enable data retention choice on deactivation <span class="vmpfence-option-help" title="Show option to keep or delete data when deactivating the plugin.">?</span></div>
                            <div class="vmpfence-option-desc">When enabled, you'll be asked whether to keep or delete VMP Security tables and data during plugin deactivation. Note: This does not include Login Security settings and tables.</div>
                        </div>
                        <div class="vmpfence-option-input"></div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Dashboard Notification Options</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                // Check if user is premium
                $is_premium = (VMPFence_License::get_license_type() === VMPFence_Constants::LICENSE_PREMIUM);
                
                // Get notification preferences
                $notify_updates = VMPFence_Config::get('notify_updates_needed', 1);
                $notify_scan_status = VMPFence_Config::get('notify_scan_status', 1);
                $notify_security_alerts = VMPFence_Config::get('notify_security_alerts', 1);
                $notify_promotions = VMPFence_Config::get('notify_promotions', 1);
                $notify_blog_highlights = VMPFence_Config::get('notify_blog_highlights', 1);
                $notify_product_updates = VMPFence_Config::get('notify_product_updates', 1);
                ?>
                
                <div class="vmpfence-dashboard-notifications">
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" id="vmpfence_notify_updates_needed" <?php checked($notify_updates, 1); ?> />
                            Updates Needed (Plugin, Theme, or Core)
                        </label>
                    </div>
                    
                    <?php if ($is_premium): ?>
                        <div class="vmpfence-checkbox-item">
                            <label>
                                <input type="checkbox" id="vmpfence_notify_security_alerts" <?php checked($notify_security_alerts, 1); ?> />
                                Security Alerts
                            </label>
                        </div>
                        
                        <div class="vmpfence-checkbox-item">
                            <label>
                                <input type="checkbox" id="vmpfence_notify_promotions" <?php checked($notify_promotions, 1); ?> />
                                Promotions
                            </label>
                        </div>
                        
                        <div class="vmpfence-checkbox-item">
                            <label>
                                <input type="checkbox" id="vmpfence_notify_blog_highlights" <?php checked($notify_blog_highlights, 1); ?> />
                                Blog Highlights
                            </label>
                        </div>
                        
                        <div class="vmpfence-checkbox-item">
                            <label>
                                <input type="checkbox" id="vmpfence_notify_product_updates" <?php checked($notify_product_updates, 1); ?> />
                                Product Updates
                            </label>
                        </div>
                    <?php endif; ?>
                    
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" id="vmpfence_notify_scan_status" <?php checked($notify_scan_status, 1); ?> />
                            Scan Status
                        </label>
                    </div>
                    
                    <?php if (!$is_premium): ?>
                        <div class="vmpfence-premium-notice" style="margin-top: 15px; padding: 15px; background: #f5f5f5; border-left: 4px solid #191970;">
                            <p style="margin: 0 0 15px 0;">Dashboard notifications will also be displayed for Security Alerts, Promotions, Blog Highlights, and Product Updates. These notifications can be disabled by upgrading to a premium license.</p>
                            <div style="display: flex; gap: 10px;">
                                <a href="#" class="button button-primary">UPGRADE TO PREMIUM</a>
                                <a href="#" class="button">LEARN MORE</a>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Email Alert Preferences</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                // Get email alert preferences
                $alert_on_auto_update = VMPFence_Config::get('alert_on_auto_update', 0);
                $alert_on_deactivation = VMPFence_Config::get('alert_on_deactivation', 1);
                $alert_on_waf_disabled = VMPFence_Config::get('alert_on_waf_disabled', 1);
                $alert_on_scan_results = VMPFence_Config::get('alert_on_scan_results', 1);
                $alert_scan_severity = VMPFence_Config::get('alert_scan_severity', 'low');
                $alert_on_ip_blocked = VMPFence_Config::get('alert_on_ip_blocked', 1);
                $alert_on_lockout = VMPFence_Config::get('alert_on_lockout', 1);
                $alert_on_breached_password = VMPFence_Config::get('alert_on_breached_password', 1);
                $alert_on_lost_password = VMPFence_Config::get('alert_on_lost_password', 1);
                $alert_on_admin_login = VMPFence_Config::get('alert_on_admin_login', 1);
                $alert_admin_login_new_device = VMPFence_Config::get('alert_admin_login_new_device', 0);
                $alert_on_user_login = VMPFence_Config::get('alert_on_user_login', 0);
                $alert_user_login_new_device = VMPFence_Config::get('alert_user_login_new_device', 0);
                $alert_on_attack_increase = VMPFence_Config::get('alert_on_attack_increase', 1);
                $max_email_alerts_per_hour = VMPFence_Config::get('max_email_alerts_per_hour', 0);
                ?>
                
                <div class="vmpfence-email-alerts">
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" id="vmpfence_alert_on_auto_update" <?php checked($alert_on_auto_update, 1); ?> />
                            Email me when VMP Security is automatically updated
                        </label>
                        <div class="vmpfence-option-desc" style="margin-left: 24px; color: #666;">If you have automatic updates enabled (see above), you'll get an email when an update occurs.</div>
                    </div>
                    
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" id="vmpfence_alert_on_deactivation" <?php checked($alert_on_deactivation, 1); ?> />
                            Email me if VMP Security is deactivated
                        </label>
                    </div>
                    
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" id="vmpfence_alert_on_waf_disabled" <?php checked($alert_on_waf_disabled, 1); ?> />
                            Email me if the VMP Security Web Application Firewall is turned off
                        </label>
                    </div>
                    
                    <div class="vmpfence-checkbox-item" style="display: flex; align-items: center; justify-content: space-between;">
                        <label style="margin: 0; display: flex; align-items: center;">
                            <input type="checkbox" id="vmpfence_alert_on_scan_results" <?php checked($alert_on_scan_results, 1); ?> />
                            Alert me with scan results of this severity level or greater:
                        </label>
                        <select class="vmpfence-select" id="vmpfence_alert_scan_severity" style="width: 150px;">
                            <option value="critical" <?php selected($alert_scan_severity, 'critical'); ?>>Critical</option>
                            <option value="high" <?php selected($alert_scan_severity, 'high'); ?>>High</option>
                            <option value="medium" <?php selected($alert_scan_severity, 'medium'); ?>>Medium</option>
                            <option value="low" <?php selected($alert_scan_severity, 'low'); ?>>Low</option>
                        </select>
                    </div>
                    
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" id="vmpfence_alert_on_ip_blocked" <?php checked($alert_on_ip_blocked, 1); ?> />
                            Alert when an IP address is blocked
                        </label>
                    </div>
                    
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" id="vmpfence_alert_on_lockout" <?php checked($alert_on_lockout, 1); ?> />
                            Alert when someone is locked out from login
                        </label>
                    </div>
                    
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" id="vmpfence_alert_on_breached_password" <?php checked($alert_on_breached_password, 1); ?> />
                            Alert when someone is blocked from logging in for using a password found in a breach
                        </label>
                    </div>
                    
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" id="vmpfence_alert_on_lost_password" <?php checked($alert_on_lost_password, 1); ?> />
                            Alert when the "lost password" form is used for a valid user
                        </label>
                    </div>
                    
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" id="vmpfence_alert_on_admin_login" <?php checked($alert_on_admin_login, 1); ?> />
                            Alert me when someone with administrator access signs in
                        </label>
                        <div style="margin-left: 40px; margin-top: 15px;">
                            <label>
                                <input type="checkbox" id="vmpfence_alert_admin_login_new_device" <?php checked($alert_admin_login_new_device, 1); ?> />
                                Only alert me when that administrator signs in from a new device
                            </label>
                        </div>
                    </div>
                    
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" id="vmpfence_alert_on_user_login" <?php checked($alert_on_user_login, 1); ?> />
                            Alert me when a non-admin user signs in
                        </label>
                        <div style="margin-left: 40px; margin-top: 15px;">
                            <label>
                                <input type="checkbox" id="vmpfence_alert_user_login_new_device" <?php checked($alert_user_login_new_device, 1); ?> />
                                Only alert me when that user signs in from a new device
                            </label>
                        </div>
                    </div>
                    
                    <div class="vmpfence-checkbox-item">
                        <label>
                            <input type="checkbox" id="vmpfence_alert_on_attack_increase" <?php checked($alert_on_attack_increase, 1); ?> />
                            Alert me when there's a large increase in attacks detected on my site
                        </label>
                    </div>
                    
                    <div class="vmpfence-option-row" style="margin-top: 15px; display: flex; align-items: center; justify-content: space-between;">
                        <div class="vmpfence-option-label">
                            <div class="vmpfence-option-title">Maximum email alerts to send per hour</div>
                            <div class="vmpfence-option-desc">0 means unlimited alerts will be sent.</div>
                        </div>
                        <div class="vmpfence-option-input">
                            <input type="number" class="vmpfence-text-input vmpfence-text-input--small" id="vmpfence_max_email_alerts_per_hour" value="<?php echo esc_attr($max_email_alerts_per_hour); ?>" min="0" step="1" style="width: 80px;" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Activity Report</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                // Get activity report settings
                $enable_email_summary = VMPFence_Config::get('enable_email_summary', 1);
                $email_summary_frequency = VMPFence_Config::get('email_summary_frequency', 'weekly');
                $exclude_directories_raw = VMPFence_Config::get('exclude_directories', "wp-content/cache\nwp-content/wflogs");
                // Ensure newlines are preserved (convert spaces to newlines if needed for old data)
                $exclude_directories = str_replace(' ', "\n", $exclude_directories_raw);
                $enable_activity_widget = VMPFence_Config::get('enable_activity_widget', 1);
                ?>
                
                <div class="vmpfence-activity-report">
                    <div class="vmpfence-checkbox-item" style="display: flex; align-items: center; justify-content: space-between;">
                        <label style="margin: 0; display: flex; align-items: center;">
                            <input type="checkbox" id="vmpfence_enable_email_summary" <?php checked($enable_email_summary, 1); ?> />
                            Enable email summary
                        </label>
                        <select class="vmpfence-select" id="vmpfence_email_summary_frequency" style="width: 200px;">
                            <option value="daily" <?php selected($email_summary_frequency, 'daily'); ?>>Once a day</option>
                            <option value="weekly" <?php selected($email_summary_frequency, 'weekly'); ?>>Once a week</option>
                            <option value="monthly" <?php selected($email_summary_frequency, 'monthly'); ?>>Once a month</option>
                        </select>
                    </div>
                    
                    <div class="vmpfence-option-row" style="margin-top: 20px; display: flex; align-items: flex-start; justify-content: space-between;">
                        <div class="vmpfence-option-label">
                            <div class="vmpfence-option-title">List of directories to exclude from recently modified file list</div>
                        </div>
                        <div class="vmpfence-option-input" style="flex: 0 0 400px;">
                            <textarea class="vmpfence-textarea" id="vmpfence_exclude_directories" rows="4" style="width: 100%; font-family: monospace;"><?php echo esc_textarea($exclude_directories); ?></textarea>
                        </div>
                    </div>
                    
                    <div class="vmpfence-checkbox-item" style="margin-top: 20px;">
                        <label>
                            <input type="checkbox" id="vmpfence_enable_activity_widget" <?php checked($enable_activity_widget, 1); ?> />
                            Enable activity report widget on the WordPress dashboard
                        </label>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Firewall Options Section -->
    <div class="all-options-section">
        <h2 class="all-options-section-header">Firewall Options</h2>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Basic Firewall Options</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                $waf_enabled = VMPFence_Config::get('waf_enabled', 1);
                $waf_protection_level = VMPFence_Config::get('waf_protection_level', 'basic');
                $realtime_ip_blocklist_enabled = VMPFence_Config::get('realtime_ip_blocklist_enabled', 0);
                ?>
                <div class="vmpfence-firewall-grid">
                    <!-- WAF Status -->
                    <div class="vmpfence-firewall-box">
                        <h3>Web Application Firewall Status</h3>
                        <select id="vmpfence_waf_enabled" class="vmpfence-select">
                            <option value="1"<?php selected($waf_enabled, 1); ?>>Enabled and Protecting</option>
                            <option value="0"<?php selected($waf_enabled, 0); ?>>Disabled</option>
                        </select>
                        <p style="font-size: 16px; color: #666; line-height: 1.5;">The Web Application Firewall actively blocks malicious requests matching known attack patterns.</p>
                    </div>

                    <!-- Protection Level -->
                    <div class="vmpfence-firewall-box">
                        <h3>Protection Level</h3>
                        <?php if ($waf_protection_level === 'extended'): ?>
                            <p style="font-size: 16px; color: #666; line-height: 1.5;"><strong>Extended Protection:</strong> All PHP requests will be processed by the firewall prior to running.</p>
                            <p style="font-size: 14px; color: #666; line-height: 1.5;">If you're moving to a new host or a new installation location, you may need to temporarily disable extended protection to avoid any file not found errors.</p>
                            <button class="vmpfence-btn-outline" id="vmpfence-ao-remove-extended-protection">REMOVE EXTENDED PROTECTION</button>
                        <?php else: ?>
                            <p style="font-size: 16px; color: #666; line-height: 1.5;"><strong>Basic WordPress Protection:</strong> The plugin will load as a regular plugin after WordPress has been loaded, and while it can block many malicious requests, some vulnerable plugins or WordPress itself may run vulnerable code before all plugins are loaded.</p>
                            <button class="vmpfence-btn-primary" id="vmpfence-ao-optimize-firewall">OPTIMIZE THE VMP FIREWALL</button>
                        <?php endif; ?>
                    </div>

                    <!-- Real-Time IP Blocklist -->
                    <div class="vmpfence-firewall-box">
                        <h3>Real-Time IP Blocklist</h3>
                        <p>This feature blocks all traffic from IPs with a high volume of recent malicious activity using VMP Security's real-time blocklist.</p>
                        <div class="vmpfence-btn-group">
                            <input type="hidden" id="vmpfence_realtime_ip_blocklist" value="<?php echo esc_attr($realtime_ip_blocklist_enabled); ?>">
                            <button type="button" class="vmpfence-toggle-btn <?php echo !$realtime_ip_blocklist_enabled ? 'vmpfence-toggle-btn-active' : ''; ?>" data-value="off">DISABLED</button>
                            <button type="button" class="vmpfence-toggle-btn <?php echo $realtime_ip_blocklist_enabled ? 'vmpfence-toggle-btn-active' : ''; ?>" data-value="on">ENABLED</button>
                        </div>
                        <p style="font-weight: 500; font-size: 12px; color: #666; line-height: 1.5; margin-top: 40px;">When enabled, the plugin automatically syncs blocked IPs from the API server every hour.</p>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Advanced Firewall Options</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                $whitelisted_ips_bypass = VMPFence_Config::get('whitelisted_ips_bypass', '');
                $whitelisted_services_json = VMPFence_Config::get('whitelisted_services', '{}');
                $blocked_urls = VMPFence_Config::get('blocked_urls', '');

                $whitelisted_services = array();
                if (!empty($whitelisted_services_json)) {
                    $decoded = json_decode($whitelisted_services_json, true);
                    if (is_array($decoded)) {
                        $whitelisted_services = $decoded;
                    }
                }

                // WAF Rules
                $waf_rules = class_exists('VMPFence_WAF_Rule') ? VMPFence_WAF_Rule::get_all() : array();
                if (!is_array($waf_rules)) {
                    $waf_rules = array();
                }

                $waf_category_descriptions = array(
                    'xss' => 'Cross-Site Scripting (XSS) attacks attempt to inject malicious scripts into web pages viewed by other users.',
                    'sqli' => 'SQL Injection attacks try to manipulate database queries by inserting malicious SQL code.',
                    'rfi' => 'Remote File Inclusion attacks attempt to include and execute files from remote servers.',
                    'lfi' => 'Local File Inclusion attacks try to include and execute local files on the server.',
                    'rce' => 'Remote Code Execution attacks attempt to execute arbitrary code on the server.',
                    'command_injection' => 'Command Injection attacks try to execute system commands through vulnerable application inputs.',
                    'file_upload' => 'Malicious File Upload attacks attempt to upload dangerous files that can compromise the server.',
                    'ldap_injection' => 'LDAP Injection attacks manipulate LDAP queries to bypass authentication or access unauthorized data.',
                    'null_byte' => 'Null Byte attacks use null characters to bypass security filters and access restricted files.',
                    'protocol' => 'Protocol-level attacks target vulnerabilities in network protocols and communication.',
                    'scanner' => 'Automated Security Scanners that probe for vulnerabilities should be detected and blocked.',
                    'wordpress' => 'WordPress-specific attacks target common vulnerabilities in WordPress core, plugins, and themes.',
                    'malware' => 'Malware detection rules identify known malicious code patterns and signatures.',
                    'spam' => 'Spam protection rules block automated spam submissions and bot activity.',
                    'traversal' => 'Directory Traversal attacks try to access files outside the intended directory structure.',
                    'xxe' => 'XML External Entity (XXE) attacks exploit vulnerabilities in XML parsers to access sensitive data.'
                );

                $category_mapping = array(
                    'local_file_inclusion' => 'lfi',
                    'sql_injection' => 'sqli',
                    'sql' => 'sqli',
                    'remote_file_inclusion' => 'rfi',
                    'directory_traversal' => 'traversal',
                    'protocol_violation' => 'protocol',
                    'server_misconfig' => 'configuration',
                    'command_injection' => 'rce',
                );

                $waf_categories_data = array();
                $ao_category_to_db = array();

                foreach ($waf_rules as $rule) {
                    if (!isset($rule['category']) || empty($rule['category'])) continue;
                    $original_category = trim($rule['category']);
                    $category = strtolower($original_category);
                    if (isset($category_mapping[$category])) {
                        $category = $category_mapping[$category];
                    }
                    if (!isset($ao_category_to_db[$category])) {
                        $ao_category_to_db[$category] = array();
                    }
                    if (!in_array($original_category, $ao_category_to_db[$category])) {
                        $ao_category_to_db[$category][] = $original_category;
                    }
                    if (!isset($waf_categories_data[$category])) {
                        $waf_categories_data[$category] = array(
                            'total' => 0,
                            'enabled' => 0,
                            'description' => isset($waf_category_descriptions[$category]) ? $waf_category_descriptions[$category] : 'Security rules for ' . ucfirst(str_replace('_', ' ', $category)) . '.'
                        );
                    }
                    $waf_categories_data[$category]['total']++;
                    if (isset($rule['enabled']) && $rule['enabled'] == 1) {
                        $waf_categories_data[$category]['enabled']++;
                    }
                }
                ksort($waf_categories_data);
                ?>

                <!-- Allowlisted IP Addresses -->
                <div class="vmpfence-advanced-option">
                    <label class="vmpfence-label-main">
                        Allowlisted IP addresses that bypass all rules <span class="vmpfence-help-icon">?</span>
                    </label>
                    <textarea id="vmpfence_whitelisted_ips_bypass" rows="6" class="vmpfence-textarea-full" placeholder=""><?php echo esc_textarea(implode("\n", array_map('trim', preg_split('/[,\s]+/', $whitelisted_ips_bypass, -1, PREG_SPLIT_NO_EMPTY)))); ?></textarea>
                    <p class="vmpfence-help-description">
                        Allowlisted IPs must be separated by commas or placed on separate lines. Supports both IPv4 and IPv6. You can specify ranges using the following formats: IPv4: 127.0.0.1/24, 127.0.0.[1-100], or 127.0.0.1-127.0.0.100; IPv6: 2001:db8::/32. 
                        VMP Security automatically allowlists <a href="https://en.wikipedia.org/wiki/Private_network" target="_blank" rel="noopener noreferrer">private networks</a> because these are not routable on the public Internet.
                    </p>
                </div>

                <!-- Allowlisted Services -->
                <div class="vmpfence-advanced-option">
                    <label class="vmpfence-label-main">
                        Allowlisted services <span class="vmpfence-help-icon">?</span>
                    </label>
                    <div class="vmpfence-services-grid">
                        <label class="vmpfence-service-checkbox">
                            <input type="checkbox" id="vmpfence_service_sucuri" <?php checked(!empty($whitelisted_services['sucuri'])); ?>>
                            <span>Sucuri</span>
                        </label>
                        <label class="vmpfence-service-checkbox">
                            <input type="checkbox" id="vmpfence_service_facebook" <?php checked(!empty($whitelisted_services['facebook'])); ?>>
                            <span>Facebook</span>
                        </label>
                        <label class="vmpfence-service-checkbox">
                            <input type="checkbox" id="vmpfence_service_uptime" <?php checked(!empty($whitelisted_services['uptime'])); ?>>
                            <span>Uptime Robot</span>
                        </label>
                        <label class="vmpfence-service-checkbox">
                            <input type="checkbox" id="vmpfence_service_statuscake" <?php checked(!empty($whitelisted_services['statuscake'])); ?>>
                            <span>StatusCake</span>
                        </label>
                        <label class="vmpfence-service-checkbox">
                            <input type="checkbox" id="vmpfence_service_managewp" <?php checked(!empty($whitelisted_services['managewp'])); ?>>
                            <span>ManageWP</span>
                        </label>
                        <label class="vmpfence-service-checkbox">
                            <input type="checkbox" id="vmpfence_service_seznam" <?php checked(!empty($whitelisted_services['seznam'])); ?>>
                            <span>Seznam Search Engine</span>
                        </label>
                        <label class="vmpfence-service-checkbox">
                            <input type="checkbox" id="vmpfence_service_google" <?php checked(!empty($whitelisted_services['google'])); ?>>
                            <span>Google Search Engine</span>
                        </label>
                    </div>
                </div>

                <!-- Immediately Block IPs -->
                <div class="vmpfence-advanced-option">
                    <label class="vmpfence-label-main">
                        Immediately block IPs that access these URLs <span class="vmpfence-help-icon" title="When blocked via this option, an IP address will be blocked for the duration you have specified with the option 'How long is an IP address blocked' when it breaks a rule found under the Rate Limiting rules.">?</span>
                    </label>
                    <textarea id="vmpfence_blocked_urls" rows="6" class="vmpfence-textarea-full" placeholder=""><?php echo esc_textarea(implode("\n", array_map('trim', preg_split('/[,\s]+/', $blocked_urls, -1, PREG_SPLIT_NO_EMPTY)))); ?></textarea>
                    <p class="vmpfence-help-description">
                        Separate multiple URLs with commas or place them on separate lines. Asterisks are wildcards, but use with care. All URLs must start with a "/" without quotes and must be relative, e.g. /badURL/one/, /bannedPage.html, /starts/with-*, */starts-with-*, *ends-with-*
                    </p>
                </div>

                <!-- WAF Rules -->
                <?php if (!empty($waf_categories_data)): ?>
                <div class="vmpfence-advanced-option" style="display: block;">
                    <label class="vmpfence-label-main">
                        Rules <span class="vmpfence-help-icon">?</span>
                    </label>
                    <table class="wp-list-table widefat fixed striped vmpfence-waf-categories-table" style="margin-top: 10px;">
                        <thead>
                            <tr>
                                <th style="width: 80px; text-align: center;">Enable</th>
                                <th style="width: 200px;">Category</th>
                                <th>Description</th>
                                <th style="width: 120px; text-align: center;">Rules Count</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($waf_categories_data as $category => $data): ?>
                            <tr>
                                <td style="text-align: center;">
                                    <label class="vmpfence-ao-category-toggle">
                                        <input type="checkbox" 
                                               class="ao-category-toggle-checkbox" 
                                               data-category="<?php echo esc_attr($category); ?>"
                                               data-db-categories="<?php echo esc_attr(json_encode($ao_category_to_db[$category])); ?>"
                                               data-total="<?php echo esc_attr($data['total']); ?>"
                                               data-enabled="<?php echo esc_attr($data['enabled']); ?>"
                                               <?php checked($data['enabled'] == $data['total'] && $data['total'] > 0); ?>>
                                        <span class="vmpfence-ao-toggle-slider"></span>
                                    </label>
                                </td>
                                <td>
                                    <span class="badge badge-<?php echo esc_attr(strtolower($category)); ?>">
                                        <?php echo esc_html(strtoupper(str_replace('_', ' ', $category))); ?>
                                    </span>
                                </td>
                                <td><?php echo esc_html($data['description']); ?></td>
                                <td style="text-align: center;">
                                    <?php if ($data['enabled'] == $data['total']): ?>
                                    <strong style="color: #46b450;"><?php echo esc_html($data['enabled'] . '/' . $data['total']); ?> Enabled</strong>
                                    <?php elseif ($data['enabled'] == 0): ?>
                                    <strong style="color: #dc3232;"><?php echo esc_html($data['enabled'] . '/' . $data['total']); ?> Disabled</strong>
                                    <?php else: ?>
                                    <strong style="color: #f0b849;"><?php echo esc_html($data['enabled'] . '/' . $data['total']); ?> Partial</strong>
                                    <?php endif; ?>
                                </td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                    
                    <div class="vmpfence-rules-footer" style="margin-top: 20px; display: flex; justify-content: space-between; align-items: center;">
                        <button type="button" class="vmpfence-btn-outline" id="vmpfence-ao-sync-waf-rules"
                                data-nonce="<?php echo wp_create_nonce('vmpfence_sync_waf_rules'); ?>">
                            MANUALLY REFRESH RULES
                        </button>
                        <span class="vmpfence-update-info" id="vmpfence-ao-sync-status"></span>
                    </div>
                </div>
                <?php endif; ?>
            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Brute Force Protection</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                $bf_enabled = VMPFence_Config::get('brute_force_enabled', 1);
                $bf_max_login = VMPFence_Config::get('max_login_attempts', 20);
                $bf_max_forgot = VMPFence_Config::get('max_forgot_password_attempts', 20);
                $bf_failures_window = VMPFence_Config::get('count_failures_window', 240);
                $bf_lockout_duration = VMPFence_Config::get('lockout_duration', 240);
                $bf_lock_invalid = VMPFence_Config::get('lock_invalid_usernames', 0);
                $bf_blocked_usernames = VMPFence_Config::get('blocked_usernames', array());
                $bf_blocked_usernames_text = is_array($bf_blocked_usernames) ? implode("\n", $bf_blocked_usernames) : '';
                $bf_enforce_strong = VMPFence_Config::get('enforce_strong_passwords', 1);
                $bf_strong_scope = VMPFence_Config::get('strong_passwords_scope', 'recommended');
                $bf_dont_reveal = VMPFence_Config::get('dont_reveal_users', 1);
                $bf_prevent_admin = VMPFence_Config::get('prevent_admin_username', 1);
                $bf_prevent_discovery = VMPFence_Config::get('prevent_username_discovery', 1);
                $bf_disable_app_pw = VMPFence_Config::get('disable_app_passwords', 1);
                $bf_block_post = VMPFence_Config::get('block_post_requests', 0);
                $bf_custom_block_text = VMPFence_Config::get('custom_block_text', '');
                $bf_check_pw_strength = VMPFence_Config::get('check_password_strength', 1);
                $bf_participate_network = VMPFence_Config::get('participate_security_network', 1);
                ?>

                <!-- Enable Brute Force Protection -->
                <div class="vmpfence-bf-option vmpfence-bf-option-toggle">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">Enable brute force protection <span class="vmpfence-help-icon" title="This option enables all Brute Force Protection options, including strong password enforcement and invalid login throttling.">?</span></label>
                        <p class="vmpfence-help-description" style="margin-top: 5px;">This option enables all "Brute Force Protection" options, including strong password enforcement and invalid login throttling. You can modify individual options below.</p>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <div class="vmpfence-btn-group">
                            <input type="hidden" id="vmpfence_bf_enabled" value="<?php echo esc_attr($bf_enabled); ?>">
                            <button type="button" class="vmpfence-toggle-btn <?php echo !$bf_enabled ? 'vmpfence-toggle-btn-active' : ''; ?>" data-value="off">OFF</button>
                            <button type="button" class="vmpfence-toggle-btn <?php echo $bf_enabled ? 'vmpfence-toggle-btn-active' : ''; ?>" data-value="on">ON</button>
                        </div>
                    </div>
                </div>

                <!-- Max Login Failures -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">Lock out after how many login failures <span class="vmpfence-help-icon" title="This setting controls the maximum number of failed login attempts before the user is locked out.">?</span></label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <select id="vmpfence_bf_max_login" class="vmpfence-select">
                            <?php foreach (array(2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100,200,300,400,500) as $v): ?>
                            <option value="<?php echo $v; ?>"<?php selected($bf_max_login, $v); ?>><?php echo $v; ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </div>

                <!-- Forgot Password Attempts -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">Lock out after how many forgot password attempts <span class="vmpfence-help-icon" title="This setting controls the maximum number of failed password reset attempts before the user is locked out.">?</span></label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <select id="vmpfence_bf_max_forgot" class="vmpfence-select">
                            <?php foreach (array(1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100,200,300,400,500) as $v): ?>
                            <option value="<?php echo $v; ?>"<?php selected($bf_max_forgot, $v); ?>><?php echo $v; ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </div>

                <!-- Count Failures Time Period -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">Count failures over what time period <span class="vmpfence-help-icon" title="This setting controls the time window for counting failed login attempts.">?</span></label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <select id="vmpfence_bf_failures_window" class="vmpfence-select">
                            <option value="5"<?php selected($bf_failures_window, 5); ?>>5 minutes</option>
                            <option value="10"<?php selected($bf_failures_window, 10); ?>>10 minutes</option>
                            <option value="30"<?php selected($bf_failures_window, 30); ?>>30 minutes</option>
                            <option value="60"<?php selected($bf_failures_window, 60); ?>>1 hour</option>
                            <option value="120"<?php selected($bf_failures_window, 120); ?>>2 hours</option>
                            <option value="240"<?php selected($bf_failures_window, 240); ?>>4 hours</option>
                            <option value="360"<?php selected($bf_failures_window, 360); ?>>6 hours</option>
                            <option value="720"<?php selected($bf_failures_window, 720); ?>>12 hours</option>
                            <option value="1440"<?php selected($bf_failures_window, 1440); ?>>1 day</option>
                        </select>
                    </div>
                </div>

                <!-- Lockout Duration -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">Amount of time a user is locked out <span class="vmpfence-help-icon" title="This setting controls how long a user is locked out after exceeding the maximum number of login attempts.">?</span></label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <select id="vmpfence_bf_lockout_duration" class="vmpfence-select">
                            <option value="5"<?php selected($bf_lockout_duration, 5); ?>>5 minutes</option>
                            <option value="10"<?php selected($bf_lockout_duration, 10); ?>>10 minutes</option>
                            <option value="30"<?php selected($bf_lockout_duration, 30); ?>>30 minutes</option>
                            <option value="60"<?php selected($bf_lockout_duration, 60); ?>>1 hour</option>
                            <option value="120"<?php selected($bf_lockout_duration, 120); ?>>2 hours</option>
                            <option value="240"<?php selected($bf_lockout_duration, 240); ?>>4 hours</option>
                            <option value="360"<?php selected($bf_lockout_duration, 360); ?>>6 hours</option>
                            <option value="720"<?php selected($bf_lockout_duration, 720); ?>>12 hours</option>
                            <option value="1440"<?php selected($bf_lockout_duration, 1440); ?>>1 day</option>
                            <option value="2880"<?php selected($bf_lockout_duration, 2880); ?>>2 days</option>
                            <option value="7200"<?php selected($bf_lockout_duration, 7200); ?>>5 days</option>
                            <option value="14400"<?php selected($bf_lockout_duration, 14400); ?>>10 days</option>
                            <option value="28800"<?php selected($bf_lockout_duration, 28800); ?>>20 days</option>
                            <option value="43200"<?php selected($bf_lockout_duration, 43200); ?>>1 month</option>
                            <option value="86400"<?php selected($bf_lockout_duration, 86400); ?>>2 months</option>
                        </select>
                    </div>
                </div>

                <!-- Lock Out Invalid Usernames -->
                <div class="vmpfence-bf-option vmpfence-bf-option-checkbox">
                    <label class="vmpfence-checkbox-label">
                        <input type="checkbox" id="vmpfence_bf_lock_invalid" <?php checked($bf_lock_invalid, 1); ?>>
                        <span>Immediately lock out invalid usernames <span class="vmpfence-help-icon" title="When enabled, any IP that tries to login with a username that doesn't exist will be immediately blocked for the configured lockout duration.">?</span></span>
                    </label>
                </div>

                <!-- Blocked Usernames -->
                <div class="vmpfence-bf-option vmpfence-bf-option-textarea">
                    <label class="vmpfence-label-main">Immediately block the IP of users who try to sign in as these usernames <span class="vmpfence-help-icon" title="Any IP that tries to login with a blocked username will be immediately blocked for the configured lockout duration.">?</span></label>
                    <textarea id="vmpfence_bf_blocked_usernames" rows="3" class="vmpfence-textarea-full" placeholder="Enter usernames, one per line"><?php echo esc_textarea($bf_blocked_usernames_text); ?></textarea>
                    <p class="vmpfence-help-description">Hit enter to add a username. One username per line.</p>
                </div>

                <!-- Additional Options Subsection -->
                <div class="vmpfence-bf-subsection-header">
                    <h3>Additional Options</h3>
                </div>

                <!-- Enforce Strong Passwords -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-checkbox-label">
                            <input type="checkbox" id="vmpfence_bf_enforce_strong" <?php checked($bf_enforce_strong, 1); ?>>
                            <span>Enforce strong passwords <span class="vmpfence-help-icon" title="Enforce strong passwords for users.">?</span></span>
                        </label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <select id="vmpfence_bf_strong_scope" class="vmpfence-select">
                            <option value="recommended"<?php selected($bf_strong_scope, 'recommended'); ?>>Force admins and publishers to use strong passwords (recommended)</option>
                            <option value="all"<?php selected($bf_strong_scope, 'all'); ?>>Force all members to use strong passwords</option>
                        </select>
                    </div>
                </div>

                <!-- Don't Let WordPress Reveal Valid Users -->
                <div class="vmpfence-bf-option vmpfence-bf-option-checkbox">
                    <label class="vmpfence-checkbox-label">
                        <input type="checkbox" id="vmpfence_bf_dont_reveal" <?php checked($bf_dont_reveal, 1); ?>>
                        <span>Don't let WordPress reveal valid users in login errors <span class="vmpfence-help-icon" title="Prevent WordPress from revealing valid usernames in login error messages.">?</span></span>
                    </label>
                </div>

                <!-- Prevent Admin Username -->
                <div class="vmpfence-bf-option vmpfence-bf-option-checkbox">
                    <label class="vmpfence-checkbox-label">
                        <input type="checkbox" id="vmpfence_bf_prevent_admin" <?php checked($bf_prevent_admin, 1); ?>>
                        <span>Prevent users registering 'admin' username if it doesn't exist <span class="vmpfence-help-icon" title="Prevent users from registering the 'admin' username if it doesn't already exist.">?</span></span>
                    </label>
                </div>

                <!-- Prevent Username Discovery -->
                <div class="vmpfence-bf-option vmpfence-bf-option-checkbox">
                    <label class="vmpfence-checkbox-label">
                        <input type="checkbox" id="vmpfence_bf_prevent_discovery" <?php checked($bf_prevent_discovery, 1); ?>>
                        <span>Prevent discovery of usernames through '/?author=N' scans, the oEmbed API, the WordPress REST API, and WordPress XML Sitemaps <span class="vmpfence-help-icon" title="Block username enumeration via author scans, REST API, oEmbed, and XML sitemaps.">?</span></span>
                    </label>
                </div>

                <!-- Disable Application Passwords -->
                <div class="vmpfence-bf-option vmpfence-bf-option-checkbox">
                    <label class="vmpfence-checkbox-label">
                        <input type="checkbox" id="vmpfence_bf_disable_app_pw" <?php checked($bf_disable_app_pw, 1); ?>>
                        <span>Disable WordPress application passwords <span class="vmpfence-help-icon" title="Disable the WordPress application passwords feature.">?</span></span>
                    </label>
                </div>

                <!-- Block POST Requests -->
                <div class="vmpfence-bf-option vmpfence-bf-option-checkbox">
                    <label class="vmpfence-checkbox-label">
                        <input type="checkbox" id="vmpfence_bf_block_post" <?php checked($bf_block_post, 1); ?>>
                        <span>Block IPs who send POST requests with blank User-Agent and Referer <span class="vmpfence-help-icon" title="If you use external services that may send POST requests without these headers, do not use this option.">?</span></span>
                    </label>
                    <p class="vmpfence-help-description" style="margin-left: 28px;">If you use external services that may send POST requests without these headers, do not use this option, as they will be blocked.</p>
                </div>

                <!-- Custom Block Text -->
                <div class="vmpfence-bf-option vmpfence-bf-option-textarea">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">Custom text shown on block pages <span class="vmpfence-help-icon" title="Custom text displayed when a user is blocked.">?</span></label>
                    </div>
                    <textarea id="vmpfence_bf_custom_block_text" rows="4" class="vmpfence-textarea-full" placeholder=""><?php echo esc_textarea($bf_custom_block_text); ?></textarea>
                    <p class="vmpfence-help-description">HTML tags will be stripped prior to output and line breaks will be converted into the appropriate tags.</p>
                </div>

                <!-- Check Password Strength -->
                <div class="vmpfence-bf-option vmpfence-bf-option-checkbox">
                    <label class="vmpfence-checkbox-label">
                        <input type="checkbox" id="vmpfence_bf_check_pw_strength" <?php checked($bf_check_pw_strength, 1); ?>>
                        <span>Check password strength on profile update <span class="vmpfence-help-icon" title="Check password strength when users update their profile.">?</span></span>
                    </label>
                </div>

                <!-- Participate in Security Network -->
                <div class="vmpfence-bf-option vmpfence-bf-option-checkbox">
                    <label class="vmpfence-checkbox-label">
                        <input type="checkbox" id="vmpfence_bf_participate_network" <?php checked($bf_participate_network, 1); ?>>
                        <span>Participate in the Real-Time VMP Security Network <span class="vmpfence-help-icon" title="Share anonymized attack data to help protect other sites.">?</span></span>
                    </label>
                </div>
            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Rate Limiting</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                $rl_enabled = VMPFence_Config::get('rate_limiting_enabled', 0);
                $rl_google_crawler = VMPFence_Config::get('google_crawler_treatment', 'verified_google');
                $rl_global_limit = VMPFence_Config::get('global_rate_limit', 'unlimited');
                $rl_global_action = VMPFence_Config::get('global_rate_action', 'throttle');
                $rl_crawler_limit = VMPFence_Config::get('crawler_rate_limit', 'unlimited');
                $rl_crawler_action = VMPFence_Config::get('crawler_rate_action', 'throttle');
                $rl_crawler_404_limit = VMPFence_Config::get('crawler_404_limit', 'unlimited');
                $rl_crawler_404_action = VMPFence_Config::get('crawler_404_action', 'throttle');
                $rl_human_limit = VMPFence_Config::get('human_rate_limit', 'unlimited');
                $rl_human_action = VMPFence_Config::get('human_rate_action', 'throttle');
                $rl_human_404_limit = VMPFence_Config::get('human_404_limit', 'unlimited');
                $rl_human_404_action = VMPFence_Config::get('human_404_action', 'throttle');
                $rl_block_duration = VMPFence_Config::get('rate_block_duration', 5);
                $rl_throttle_behavior = VMPFence_Config::get('throttle_behavior', 'show_503');
                $rl_throttle_delay = VMPFence_Config::get('throttle_delay_duration', 5);
                $rl_allowlisted_404 = VMPFence_Config::get('allowlisted_404_urls', array());
                $rl_allowlisted_404_text = is_array($rl_allowlisted_404) ? implode("\n", $rl_allowlisted_404) : $rl_allowlisted_404;

                // Rate limit options for reuse
                $rate_limit_options = array(
                    'unlimited' => 'Unlimited',
                    '1920' => '1920 per minute',
                    '960' => '960 per minute',
                    '480' => '480 per minute',
                    '240' => '240 per minute',
                    '120' => '120 per minute',
                    '60' => '60 per minute',
                    '30' => '30 per minute',
                    '15' => '15 per minute',
                    '10' => '10 per minute',
                    '5' => '5 per minute',
                    '4' => '4 per minute',
                    '3' => '3 per minute',
                    '2' => '2 per minute',
                    '1' => '1 per minute'
                );
                ?>

                <!-- Enable Rate Limiting -->
                <div class="vmpfence-bf-option vmpfence-bf-option-toggle">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">Enable Rate Limiting and Advanced Blocking <span class="vmpfence-help-icon" title="This checkbox enables ALL blocking/throttling functions including IP, country and advanced blocking, and the Rate Limiting Rules below.">?</span></label>
                        <p class="vmpfence-help-description" style="margin-top: 5px;"><strong>NOTE:</strong> This checkbox enables ALL blocking/throttling functions including IP, country and advanced blocking, and the "Rate Limiting Rules" below.</p>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <div class="vmpfence-btn-group">
                            <input type="hidden" id="vmpfence_rl_enabled" value="<?php echo esc_attr($rl_enabled); ?>">
                            <button type="button" class="vmpfence-toggle-btn <?php echo !$rl_enabled ? 'vmpfence-toggle-btn-active' : ''; ?>" data-value="off">OFF</button>
                            <button type="button" class="vmpfence-toggle-btn <?php echo $rl_enabled ? 'vmpfence-toggle-btn-active' : ''; ?>" data-value="on">ON</button>
                        </div>
                    </div>
                </div>

                <!-- Google Crawler Treatment -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">How should we treat Google's crawlers <span class="vmpfence-help-icon" title="Controls how Google crawlers are identified and whether they are rate-limited.">?</span></label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <select id="vmpfence_rl_google_crawler" class="vmpfence-select">
                            <option value="verified_google"<?php selected($rl_google_crawler, 'verified_google'); ?>>Verified Google crawlers will not be rate-limited</option>
                            <option value="no_verification"<?php selected($rl_google_crawler, 'no_verification'); ?>>Anyone claiming to be Google will not be rate-limited</option>
                            <option value="treat_as_crawler"<?php selected($rl_google_crawler, 'treat_as_crawler'); ?>>Treat Google like any other Crawler</option>
                        </select>
                    </div>
                </div>

                <!-- If anyone's requests exceed -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">If anyone's requests exceed <span class="vmpfence-help-icon" title="Rate limit for all requests from any single IP.">?</span></label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <div class="vmpfence-rl-rule-selects">
                            <select id="vmpfence_rl_global_limit" class="vmpfence-select">
                                <?php foreach ($rate_limit_options as $val => $label): ?>
                                <option value="<?php echo esc_attr($val); ?>"<?php selected($rl_global_limit, $val); ?>><?php echo esc_html($label); ?></option>
                                <?php endforeach; ?>
                            </select>
                            <span>then</span>
                            <select id="vmpfence_rl_global_action" class="vmpfence-select">
                                <option value="throttle"<?php selected($rl_global_action, 'throttle'); ?>>throttle it</option>
                                <option value="block"<?php selected($rl_global_action, 'block'); ?>>block it</option>
                            </select>
                        </div>
                    </div>
                </div>

                <!-- If a crawler's page views exceed -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">If a crawler's page views exceed <span class="vmpfence-help-icon" title="Rate limit for page views from identified crawlers/bots.">?</span></label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <div class="vmpfence-rl-rule-selects">
                            <select id="vmpfence_rl_crawler_limit" class="vmpfence-select">
                                <?php foreach ($rate_limit_options as $val => $label): ?>
                                <option value="<?php echo esc_attr($val); ?>"<?php selected($rl_crawler_limit, $val); ?>><?php echo esc_html($label); ?></option>
                                <?php endforeach; ?>
                            </select>
                            <span>then</span>
                            <select id="vmpfence_rl_crawler_action" class="vmpfence-select">
                                <option value="throttle"<?php selected($rl_crawler_action, 'throttle'); ?>>throttle it</option>
                                <option value="block"<?php selected($rl_crawler_action, 'block'); ?>>block it</option>
                            </select>
                        </div>
                    </div>
                </div>

                <!-- If a crawler's pages not found (404s) exceed -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">If a crawler's pages not found (404s) exceed <span class="vmpfence-help-icon" title="Rate limit for 404 responses to identified crawlers/bots.">?</span></label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <div class="vmpfence-rl-rule-selects">
                            <select id="vmpfence_rl_crawler_404_limit" class="vmpfence-select">
                                <?php foreach ($rate_limit_options as $val => $label): ?>
                                <option value="<?php echo esc_attr($val); ?>"<?php selected($rl_crawler_404_limit, $val); ?>><?php echo esc_html($label); ?></option>
                                <?php endforeach; ?>
                            </select>
                            <span>then</span>
                            <select id="vmpfence_rl_crawler_404_action" class="vmpfence-select">
                                <option value="throttle"<?php selected($rl_crawler_404_action, 'throttle'); ?>>throttle it</option>
                                <option value="block"<?php selected($rl_crawler_404_action, 'block'); ?>>block it</option>
                            </select>
                        </div>
                    </div>
                </div>

                <!-- If a human's page views exceed -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">If a human's page views exceed <span class="vmpfence-help-icon" title="Rate limit for page views from human visitors.">?</span></label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <div class="vmpfence-rl-rule-selects">
                            <select id="vmpfence_rl_human_limit" class="vmpfence-select">
                                <?php foreach ($rate_limit_options as $val => $label): ?>
                                <option value="<?php echo esc_attr($val); ?>"<?php selected($rl_human_limit, $val); ?>><?php echo esc_html($label); ?></option>
                                <?php endforeach; ?>
                            </select>
                            <span>then</span>
                            <select id="vmpfence_rl_human_action" class="vmpfence-select">
                                <option value="throttle"<?php selected($rl_human_action, 'throttle'); ?>>throttle it</option>
                                <option value="block"<?php selected($rl_human_action, 'block'); ?>>block it</option>
                            </select>
                        </div>
                    </div>
                </div>

                <!-- If a human's pages not found (404s) exceed -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">If a human's pages not found (404s) exceed <span class="vmpfence-help-icon" title="Rate limit for 404 responses to human visitors.">?</span></label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <div class="vmpfence-rl-rule-selects">
                            <select id="vmpfence_rl_human_404_limit" class="vmpfence-select">
                                <?php foreach ($rate_limit_options as $val => $label): ?>
                                <option value="<?php echo esc_attr($val); ?>"<?php selected($rl_human_404_limit, $val); ?>><?php echo esc_html($label); ?></option>
                                <?php endforeach; ?>
                            </select>
                            <span>then</span>
                            <select id="vmpfence_rl_human_404_action" class="vmpfence-select">
                                <option value="throttle"<?php selected($rl_human_404_action, 'throttle'); ?>>throttle it</option>
                                <option value="block"<?php selected($rl_human_404_action, 'block'); ?>>block it</option>
                            </select>
                        </div>
                    </div>
                </div>

                <!-- How long is an IP address blocked -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">How long is an IP address blocked when it breaks a rule <span class="vmpfence-help-icon" title="Duration an IP address is blocked after violating a rate limiting rule.">?</span></label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <select id="vmpfence_rl_block_duration" class="vmpfence-select">
                            <option value="1"<?php selected($rl_block_duration, 1); ?>>1 minute</option>
                            <option value="5"<?php selected($rl_block_duration, 5); ?>>5 minutes</option>
                            <option value="30"<?php selected($rl_block_duration, 30); ?>>30 minutes</option>
                            <option value="60"<?php selected($rl_block_duration, 60); ?>>1 hour</option>
                            <option value="120"<?php selected($rl_block_duration, 120); ?>>2 hours</option>
                            <option value="360"<?php selected($rl_block_duration, 360); ?>>6 hours</option>
                            <option value="720"<?php selected($rl_block_duration, 720); ?>>12 hours</option>
                            <option value="1440"<?php selected($rl_block_duration, 1440); ?>>1 day</option>
                            <option value="2880"<?php selected($rl_block_duration, 2880); ?>>2 days</option>
                            <option value="7200"<?php selected($rl_block_duration, 7200); ?>>5 days</option>
                            <option value="8640"<?php selected($rl_block_duration, 8640); ?>>10 days</option>
                            <option value="43200"<?php selected($rl_block_duration, 43200); ?>>1 month</option>
                        </select>
                    </div>
                </div>

                <!-- How should Throttle behave -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select" id="vmpfence_throttle_behavior_option" style="display: none;">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">How should Throttle behave? <span class="vmpfence-help-icon" title="Choose how throttled requests are handled.">?</span></label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <select id="vmpfence_rl_throttle_behavior" class="vmpfence-select">
                            <option value="slow_down"<?php selected($rl_throttle_behavior, 'slow_down'); ?>>Slow Down Page Loading</option>
                            <option value="show_503"<?php selected($rl_throttle_behavior, 'show_503'); ?>>Show 503 Unavailable Page</option>
                        </select>
                    </div>
                </div>

                <!-- Throttle delay duration -->
                <div class="vmpfence-bf-option vmpfence-bf-option-select" id="vmpfence_throttle_delay_option" style="display: none;">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">Page load delay duration (seconds) <span class="vmpfence-help-icon" title="How many seconds to delay page loading when throttling.">?</span></label>
                    </div>
                    <div class="vmpfence-bf-option-right">
                        <input type="number" id="vmpfence_rl_throttle_delay" class="vmpfence-input" value="<?php echo esc_attr($rl_throttle_delay); ?>" min="1" max="100" style="width: 100px;">
                        <span style="margin-left: 8px; color: #666; font-size: 13px;">seconds</span>
                    </div>
                </div>

                <!-- Allowlisted 404 URLs -->
                <div class="vmpfence-bf-option vmpfence-bf-option-textarea">
                    <div class="vmpfence-bf-option-left">
                        <label class="vmpfence-label-main">Allowlisted 404 URLs <span class="vmpfence-help-icon" title="These URL patterns will be excluded from the throttling rules used to limit crawlers.">?</span></label>
                        <p class="vmpfence-help-description" style="margin-top: 5px;">These URL patterns will be excluded from the throttling rules used to limit crawlers.</p>
                    </div>
                    <textarea id="vmpfence_rl_allowlisted_404" rows="4" class="vmpfence-textarea-full"><?php echo esc_textarea($rl_allowlisted_404_text); ?></textarea>
                </div>
            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Allowlisted URLs</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php wp_nonce_field('vmpfence_allowlist_nonce', 'ao_vmpfence_allowlist_nonce'); ?>

                <!-- Add Allowlisted URL/Param Section -->
                <div class="vmpfence-ao-allowlist-form">
                    <h3 style="margin-bottom: 8px; font-size: 14px; font-weight: 600;">Add Allowlisted URL/Param <span class="vmpfence-help-icon" title="The URL/parameters in this table will not be tested by the firewall. They are typically added while the firewall is in Learning Mode or by an admin who identifies a particular action/request as a false positive.">?</span></h3>
                    <p style="margin-bottom: 15px; font-size: 13px; color: #555; line-height: 1.4;">
                        The URL/parameters in this table will not be tested by the firewall. They are typically added while the firewall is in Learning Mode or by an admin who identifies a particular action/request as a false positive.
                    </p>
                    
                    <div class="vmpfence-ao-allowlist-row">
                        <input type="text" id="ao_allowlist_url" placeholder="URL" class="vmpfence-ao-allowlist-input" style="width: 200px;">
                        <select id="ao_allowlist_param_type" class="vmpfence-ao-allowlist-select" style="width: 180px;">
                            <option value="POST Body">POST Body</option>
                            <option value="Query String">Query String</option>
                            <option value="Cookie">Cookie</option>
                            <option value="File Name">File Name</option>
                            <option value="Header">Header</option>
                        </select>
                        <input type="text" id="ao_allowlist_param_name" placeholder="Param Name" class="vmpfence-ao-allowlist-input" style="width: 150px;">
                        <button type="button" class="vmpfence-ao-btn-add">ADD</button>
                    </div>
                </div>

                <!-- Action and Filter Section -->
                <div class="vmpfence-ao-allowlist-toolbar">
                    <div class="vmpfence-ao-allowlist-actions">
                        <button type="button" class="vmpfence-ao-btn-action vmpfence-ao-btn-delete">DELETE</button>
                        <button type="button" class="vmpfence-ao-btn-action vmpfence-ao-btn-enable">ENABLE</button>
                        <button type="button" class="vmpfence-ao-btn-action vmpfence-ao-btn-disable">DISABLE</button>
                    </div>
                    <div class="vmpfence-ao-allowlist-filter">
                        <select class="vmpfence-ao-filter-select" id="ao_allowlist_filter_type">
                            <option value="url">URL</option>
                            <option value="param">Param</option>
                            <option value="source">Source</option>
                            <option value="user">User</option>
                            <option value="ip">IP</option>
                        </select>
                        <input type="text" class="vmpfence-ao-filter-input" id="ao_allowlist_filter_value" placeholder="Filter Value">
                        <button type="button" class="vmpfence-ao-btn-filter">FILTER</button>
                    </div>
                </div>

                <!-- Allowlisted URLs Table -->
                <div class="vmpfence-ao-allowlist-table-wrapper">
                    <table class="vmpfence-ao-allowlist-table">
                        <thead>
                            <tr>
                                <th style="width: 30px;"><input type="checkbox" class="vmpfence-ao-select-all"></th>
                                <th style="width: 60px;">Enabled</th>
                                <th style="width: 120px;">URL</th>
                                <th style="width: 100px;">Param</th>
                                <th style="width: 120px;">Created</th>
                                <th style="width: 100px;">Source</th>
                                <th style="width: 60px;">User</th>
                                <th style="width: 80px;">IP</th>
                            </tr>
                        </thead>
                        <tbody>
                            <!-- Table rows populated via AJAX -->
                        </tbody>
                    </table>
                </div>

                <!-- Monitor Background Requests Section -->
                <div class="vmpfence-ao-monitor-section">
                    <h3 style="margin: 0 0 10px 0; font-size: 14px; font-weight: 600; color: #333;">
                        Monitor background requests from an administrator's web browser for false positives 
                        <span class="vmpfence-help-icon" title="When enabled, the plugin will monitor admin browsing and notify if a legitimate request would be blocked by the firewall.">?</span>
                    </h3>
                    <div style="display: flex; gap: 20px; align-items: center;">
                        <label class="vmpfence-checkbox-label" style="display: flex; align-items: center; font-size: 13px; color: #333;">
                            <input type="checkbox" id="ao_monitor_frontend" checked style="margin-right: 8px;">
                            <span>Front-end Website</span>
                        </label>
                        <label class="vmpfence-checkbox-label" style="display: flex; align-items: center; font-size: 13px; color: #333;">
                            <input type="checkbox" id="ao_monitor_admin" checked style="margin-right: 8px;">
                            <span>Admin Panel</span>
                        </label>
                    </div>
                </div>

            </div>
        </div>
    </div>
    
    <!-- Blocking Options Section -->
    <div class="all-options-section">
        <h2 class="all-options-section-header">Blocking Options</h2>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Advanced Country Blocking Options</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                $cb_is_premium = (VMPFence_License::get_license_type() === VMPFence_Constants::LICENSE_PREMIUM);
                $cb_disabled = !$cb_is_premium ? 'disabled' : '';
                $cb_action = VMPFence_Config::get('country_block_action', 'message');
                $cb_redirect_url = get_option('vmpfence_country_block_redirect', '');
                $cb_block_logged_in = VMPFence_Config::get('country_block_logged_in', 0);
                $cb_bypass_field = get_option('vmpfence_country_bypass_field', '');
                $cb_bypass_value = get_option('vmpfence_country_bypass_value', '');
                $cb_bypass_cookie = get_option('vmpfence_country_bypass_cookie', '');
                ?>

                <?php if (!$cb_is_premium): ?>
                <div class="vmpfence-ao-premium-banner">
                    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#f59e0b" stroke-width="2">
                        <circle cx="12" cy="12" r="10"></circle>
                        <path d="M12 6v6l4 2"></path>
                    </svg>
                    <span><strong>Premium Feature:</strong> Country blocking is available in VMPFence Premium. <a href="#" class="vmpfence-upgrade-premium">Upgrade now</a></span>
                </div>
                <?php endif; ?>

                <table class="vmpfence-ao-settings-table">
                    <tr>
                        <td class="vmpfence-ao-table-label">
                            What to do when we block someone
                            <span class="vmpfence-help-icon" title="Configure how blocked users are handled when accessing your site from a blocked country.">?</span>
                        </td>
                        <td class="vmpfence-ao-table-field">
                            <select id="vmpfence_cb_action" class="vmpfence-select" <?php echo $cb_disabled; ?>>
                                <option value="message"<?php selected($cb_action, 'message'); ?>>Show the standard VMP blocked message</option>
                                <option value="redirect"<?php selected($cb_action, 'redirect'); ?>>Redirect to custom URL</option>
                            </select>
                            <p class="vmpfence-ao-field-desc">Configure how blocked users are handled when accessing your site from a blocked country</p>
                        </td>
                    </tr>

                    <tr id="vmpfence_cb_redirect_row" style="<?php echo $cb_action !== 'redirect' ? 'display: none;' : ''; ?>">
                        <td class="vmpfence-ao-table-label">
                            URL to redirect blocked users to
                            <span class="vmpfence-help-icon" title="Enter a full URL to redirect blocked users.">?</span>
                        </td>
                        <td class="vmpfence-ao-table-field">
                            <input type="text" id="vmpfence_cb_redirect_url" class="vmpfence-ao-text-input" value="<?php echo esc_attr($cb_redirect_url); ?>" placeholder="e.g., http://example.com/blocked/" <?php echo $cb_disabled; ?>>
                            <p class="vmpfence-ao-field-desc">Enter a full URL (e.g., http://example.com/blocked/) to redirect blocked users</p>
                        </td>
                    </tr>

                    <tr>
                        <td class="vmpfence-ao-table-label">
                            Block countries even if they are logged in
                            <span class="vmpfence-help-icon" title="Block access even for authenticated users from blocked countries.">?</span>
                        </td>
                        <td class="vmpfence-ao-table-field">
                            <label class="vmpfence-ao-checkbox-inline">
                                <input type="checkbox" id="vmpfence_cb_block_logged_in" <?php checked($cb_block_logged_in, 1); ?> <?php echo $cb_disabled; ?>>
                                <span>Block access even for authenticated users from blocked countries</span>
                            </label>
                        </td>
                    </tr>

                    <tr>
                        <td class="vmpfence-ao-table-label">
                            Bypass Redirect
                            <span class="vmpfence-help-icon" title="Configure a URL parameter that allows users to bypass country blocking for 30 days.">?</span>
                        </td>
                        <td class="vmpfence-ao-table-field">
                            <p class="vmpfence-ao-bypass-text">If user visits with GET parameter named 
                                <input type="text" id="vmpfence_cb_bypass_field" class="vmpfence-ao-inline-input" value="<?php echo esc_attr($cb_bypass_field); ?>" placeholder="bypass_key" <?php echo $cb_disabled; ?>>
                            </p>
                            <p class="vmpfence-ao-bypass-text">having the value 
                                <input type="text" id="vmpfence_cb_bypass_value" class="vmpfence-ao-inline-input" value="<?php echo esc_attr($cb_bypass_value); ?>" placeholder="secret123" <?php echo $cb_disabled; ?>>
                            </p>
                            <p class="vmpfence-ao-field-desc">then a cookie will be set that bypasses country blocking for 30 days. Example: https://example.com/?bypass_key=secret123</p>
                        </td>
                    </tr>

                    <tr>
                        <td class="vmpfence-ao-table-label">
                            Bypass Cookie
                            <span class="vmpfence-help-icon" title="Cookie value to check for bypass. Leave empty for auto-generated.">?</span>
                        </td>
                        <td class="vmpfence-ao-table-field">
                            <p class="vmpfence-ao-field-desc" style="margin-top: 0;">Cookie value to check for bypass (leave empty for auto-generated)</p>
                            <input type="text" id="vmpfence_cb_bypass_cookie" class="vmpfence-ao-text-input" value="<?php echo esc_attr($cb_bypass_cookie); ?>" placeholder="auto-generated" <?php echo $cb_disabled; ?>>
                            <p class="vmpfence-ao-field-desc">This cookie value will be set when bypass conditions are met and checked on future visits.</p>
                        </td>
                    </tr>
                </table>

            </div>
        </div>
    </div>
    
    <!-- Scan Options Section -->
    <div class="all-options-section">
        <h2 class="all-options-section-header">Scan Options</h2>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Scan Scheduling</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                $so_sched_enabled = VMPFence_Config::get('scheduledScansEnabled', 1);
                $so_sched_mode = VMPFence_Config::get('schedMode', 'auto');
                $so_manual_pattern = VMPFence_Config::get('manualScanType', 'once_daily');
                $so_start_hour = VMPFence_Config::get('schedStartHour', 2);
                $so_timezone = VMPFence_Config::get('scheduleTimezone', wp_timezone_string());
                $so_random_offset = VMPFence_Config::get('randomOffset', '0');
                ?>

                <table class="vmpfence-ao-settings-table">
                    <tr>
                        <td class="vmpfence-ao-table-label">
                            Schedule VMP Security Scans
                            <span class="vmpfence-help-icon" title="Enable or disable automatic scheduled scanning.">?</span>
                        </td>
                        <td class="vmpfence-ao-table-field">
                            <div class="vmpfence-btn-group">
                                <input type="hidden" id="vmpfence_so_sched_enabled" value="<?php echo esc_attr($so_sched_enabled); ?>">
                                <button type="button" class="vmpfence-toggle-btn <?php echo !$so_sched_enabled ? 'vmpfence-toggle-btn-active' : ''; ?>" data-value="off">DISABLED</button>
                                <button type="button" class="vmpfence-toggle-btn <?php echo $so_sched_enabled ? 'vmpfence-toggle-btn-active' : ''; ?>" data-value="on">ENABLED</button>
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td class="vmpfence-ao-table-label">
                            Scheduling Mode
                            <span class="vmpfence-help-icon" title="Choose whether VMP Security picks the best scan time or you set it manually.">?</span>
                        </td>
                        <td class="vmpfence-ao-table-field">
                            <label class="vmpfence-ao-checkbox-inline" style="margin-bottom: 10px;">
                                <input type="radio" name="vmpfence_so_sched_mode" value="auto" id="vmpfence_so_sched_auto" style="margin-top: 2px" <?php checked($so_sched_mode, 'auto'); ?>>
                                <span>Let VMP Security choose when to scan my site <em style="color: #28a745;">(recommended)</em></span>
                            </label>
                            <label class="vmpfence-ao-checkbox-inline">
                                <input type="radio" name="vmpfence_so_sched_mode" value="manual" id="vmpfence_so_sched_manual" style="margin-top: 2px" <?php checked($so_sched_mode, 'manual'); ?>>
                                <span>Manually schedule scans</span>
                            </label>
                        </td>
                    </tr>

                    <tr class="vmpfence-so-manual-row" style="<?php echo $so_sched_mode !== 'manual' ? 'display: none;' : ''; ?>">
                        <td class="vmpfence-ao-table-label">
                            Schedule Pattern
                            <span class="vmpfence-help-icon" title="Choose how frequently you want scans to run.">?</span>
                        </td>
                        <td class="vmpfence-ao-table-field">
                            <select id="vmpfence_so_manual_pattern" class="vmpfence-select">
                                <option value="once_daily" <?php selected($so_manual_pattern, 'once_daily'); ?>>Once Daily</option>
                                <option value="twice_daily" <?php selected($so_manual_pattern, 'twice_daily'); ?>>Twice Daily</option>
                                <option value="every_other_day" <?php selected($so_manual_pattern, 'every_other_day'); ?>>Every Other Day</option>
                                <option value="weekdays" <?php selected($so_manual_pattern, 'weekdays'); ?>>Weekdays Only</option>
                                <option value="weekends" <?php selected($so_manual_pattern, 'weekends'); ?>>Weekends Only</option>
                                <option value="odd_days_weekends" <?php selected($so_manual_pattern, 'odd_days_weekends'); ?>>Mon/Wed/Fri + Weekends</option>
                            </select>
                            <p class="vmpfence-ao-field-desc">Choose how frequently you want scans to run.</p>
                        </td>
                    </tr>

                    <tr class="vmpfence-so-manual-row" style="<?php echo $so_sched_mode !== 'manual' ? 'display: none;' : ''; ?>">
                        <td class="vmpfence-ao-table-label">
                            Preferred Start Time
                            <span class="vmpfence-help-icon" title="Choose the hour when you prefer scans to start.">?</span>
                        </td>
                        <td class="vmpfence-ao-table-field">
                            <select id="vmpfence_so_start_hour" class="vmpfence-select">
                                <?php for ($hour = 0; $hour < 24; $hour++): ?>
                                    <option value="<?php echo esc_attr($hour); ?>" <?php selected($hour, $so_start_hour); ?>>
                                        <?php echo esc_html(sprintf('%02d:00 (%s)', $hour, $hour < 12 ? 'AM' : 'PM')); ?>
                                    </option>
                                <?php endfor; ?>
                            </select>
                            <p class="vmpfence-ao-field-desc">Choose the hour when you prefer scans to start.</p>
                        </td>
                    </tr>

                    <tr class="vmpfence-so-manual-row" style="<?php echo $so_sched_mode !== 'manual' ? 'display: none;' : ''; ?>">
                        <td class="vmpfence-ao-table-label">
                            Timezone
                            <span class="vmpfence-help-icon" title="All scan times will use this timezone.">?</span>
                        </td>
                        <td class="vmpfence-ao-table-field">
                            <select id="vmpfence_so_timezone" class="vmpfence-select">
                                <?php
                                $timezone_identifiers = timezone_identifiers_list();
                                foreach ($timezone_identifiers as $tz) {
                                    echo '<option value="' . esc_attr($tz) . '"' . selected($tz, $so_timezone, false) . '>' . esc_html($tz) . '</option>';
                                }
                                ?>
                            </select>
                            <p class="vmpfence-ao-field-desc">All scan times will use this timezone.</p>
                        </td>
                    </tr>

                    <tr class="vmpfence-so-manual-row" style="<?php echo $so_sched_mode !== 'manual' ? 'display: none;' : ''; ?>">
                        <td class="vmpfence-ao-table-label">
                            Random Offset
                            <span class="vmpfence-help-icon" title="Adds a random delay (0-60 minutes) to prevent all sites from scanning at the same time.">?</span>
                        </td>
                        <td class="vmpfence-ao-table-field">
                            <label class="vmpfence-ao-checkbox-inline">
                                <input type="checkbox" id="vmpfence_so_random_offset" <?php checked($so_random_offset, '1'); ?>>
                                <span>Add random offset (0-60 minutes)</span>
                            </label>
                            <p class="vmpfence-ao-field-desc">Adds a random delay (0-60 minutes) to prevent all sites from scanning at the same time.</p>
                        </td>
                    </tr>
                </table>

            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Basic Scan Type Options</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                require_once VMPFENCE_PLUGIN_DIR . 'lib/class-vmpfence-scan-config.php';
                $so_scan_type = VMPFence_Config::get('scanType', 'standard');
                ?>

                <div class="vmpfence-ao-scan-types-grid">
                    <div class="vmpfence-ao-scan-type-card <?php echo ($so_scan_type === 'limited') ? 'vmpfence-ao-scan-type-selected' : ''; ?>">
                        <div class="vmpfence-ao-scan-type-header">
                            <input type="checkbox" name="vmpfence_so_scan_type" value="limited" id="vmpfence_so_scan_limited" <?php echo ($so_scan_type === 'limited') ? 'checked' : ''; ?>>
                            <label for="vmpfence_so_scan_limited" class="vmpfence-ao-scan-type-title">Limited Scan</label>
                        </div>
                        <p class="vmpfence-ao-scan-type-desc">For entry-level hosting plans. Provides limited detection capability with very low resource utilization.</p>
                    </div>

                    <div class="vmpfence-ao-scan-type-card <?php echo ($so_scan_type === 'standard') ? 'vmpfence-ao-scan-type-selected' : ''; ?>">
                        <div class="vmpfence-ao-scan-type-header">
                            <input type="checkbox" name="vmpfence_so_scan_type" value="standard" id="vmpfence_so_scan_standard" <?php echo ($so_scan_type === 'standard') ? 'checked' : ''; ?>>
                            <label for="vmpfence_so_scan_standard" class="vmpfence-ao-scan-type-title">Standard Scan</label>
                        </div>
                        <p class="vmpfence-ao-scan-type-desc">Our recommendation for all websites. Provides the best detection capability in the industry.</p>
                    </div>

                    <div class="vmpfence-ao-scan-type-card <?php echo ($so_scan_type === 'high_sensitivity') ? 'vmpfence-ao-scan-type-selected' : ''; ?>">
                        <div class="vmpfence-ao-scan-type-header">
                            <input type="checkbox" name="vmpfence_so_scan_type" value="high_sensitivity" id="vmpfence_so_scan_high" <?php echo ($so_scan_type === 'high_sensitivity') ? 'checked' : ''; ?>>
                            <label for="vmpfence_so_scan_high" class="vmpfence-ao-scan-type-title">High Sensitivity</label>
                        </div>
                        <p class="vmpfence-ao-scan-type-desc">For site owners who think they may have been hacked. More thorough but may produce false positives.</p>
                    </div>

                    <div class="vmpfence-ao-scan-type-card <?php echo ($so_scan_type === 'custom') ? 'vmpfence-ao-scan-type-selected' : ''; ?>">
                        <div class="vmpfence-ao-scan-type-header">
                            <input type="checkbox" name="vmpfence_so_scan_type" value="custom" id="vmpfence_so_scan_custom" style="display: none;" <?php echo ($so_scan_type === 'custom') ? 'checked' : ''; ?>>
                            <label for="vmpfence_so_scan_custom" class="vmpfence-ao-scan-type-title">Custom Scan</label>
                        </div>
                        <p class="vmpfence-ao-scan-type-desc">Selected automatically when General Options have been customized for this website.</p>
                    </div>
                </div>

            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>General Options</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                $so_current_type = VMPFence_Config::get('scanType', 'standard');
                $so_general_opts = VMPFence_Scan_Config::getScanOptions($so_current_type);
                ?>

                <div class="vmpfence-ao-general-options-list">
                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_checkGSB" value="1" <?php echo !empty($so_general_opts['scansEnabled_checkGSB']) ? 'checked' : ''; ?>>
                            <span>Check if this website is on a domain blocklist</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_spamvertizeCheck" value="1" <?php echo !empty($so_general_opts['spamvertizeCheck']) ? 'checked' : ''; ?>>
                            <span>Check if this website is being "Spamvertised"</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_checkSpamIP" value="1" <?php echo !empty($so_general_opts['checkSpamIP']) ? 'checked' : ''; ?>>
                            <span>Check if this website IP is generating spam</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_checkHowGetIPs" value="1" <?php echo !empty($so_general_opts['scansEnabled_checkHowGetIPs']) ? 'checked' : ''; ?>>
                            <span>Scan for misconfigured How does VMP Security get IPs</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_checkReadableConfig" value="1" <?php echo !empty($so_general_opts['scansEnabled_checkReadableConfig']) ? 'checked' : ''; ?>>
                            <span>Scan for publicly accessible configuration, backup, or log files</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_suspectedFiles" value="1" <?php echo !empty($so_general_opts['scansEnabled_suspectedFiles']) ? 'checked' : ''; ?>>
                            <span>Scan for publicly accessible quarantined files</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_core" value="1" <?php echo !empty($so_general_opts['scansEnabled_core']) ? 'checked' : ''; ?>>
                            <span>Scan core files against repository versions for changes</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_themes" value="1" <?php echo !empty($so_general_opts['scansEnabled_themes']) ? 'checked' : ''; ?>>
                            <span>Scan theme files against repository versions for changes</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_plugins" value="1" <?php echo !empty($so_general_opts['scansEnabled_plugins']) ? 'checked' : ''; ?>>
                            <span>Scan plugin files against repository versions for changes</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_coreUnknown" value="1" <?php echo !empty($so_general_opts['scansEnabled_coreUnknown']) ? 'checked' : ''; ?>>
                            <span>Scan wp-admin and wp-includes for files not bundled with WordPress</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_malware" value="1" <?php echo !empty($so_general_opts['scansEnabled_malware']) ? 'checked' : ''; ?>>
                            <span>Scan for signatures of known malicious files</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_fileContents" value="1" <?php echo !empty($so_general_opts['scansEnabled_fileContents']) ? 'checked' : ''; ?>>
                            <span>Scan file contents for backdoors, trojans and suspicious code</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_fileContentsGSB" value="1" <?php echo !empty($so_general_opts['scansEnabled_fileContentsGSB']) ? 'checked' : ''; ?>>
                            <span>Scan file contents for malicious URLs</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_posts" value="1" <?php echo !empty($so_general_opts['scansEnabled_posts']) ? 'checked' : ''; ?>>
                            <span>Scan posts for known dangerous URLs and suspicious content</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_comments" value="1" <?php echo !empty($so_general_opts['scansEnabled_comments']) ? 'checked' : ''; ?>>
                            <span>Scan comments for known dangerous URLs and suspicious content</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_suspiciousOptions" value="1" <?php echo !empty($so_general_opts['scansEnabled_suspiciousOptions']) ? 'checked' : ''; ?>>
                            <span>Scan WordPress core, plugin, and theme options for known dangerous URLs and suspicious content</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_oldVersions" value="1" <?php echo !empty($so_general_opts['scansEnabled_oldVersions']) ? 'checked' : ''; ?>>
                            <span>Scan for out of date, abandoned, and vulnerable plugins, themes, and WordPress versions</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_suspiciousAdminUsers" value="1" <?php echo !empty($so_general_opts['scansEnabled_suspiciousAdminUsers']) ? 'checked' : ''; ?>>
                            <span>Scan for suspicious admin users created outside of WordPress</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_passwds" value="1" <?php echo !empty($so_general_opts['scansEnabled_passwds']) ? 'checked' : ''; ?>>
                            <span>Check the strength of passwords</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_diskSpace" value="1" <?php echo !empty($so_general_opts['scansEnabled_diskSpace']) ? 'checked' : ''; ?>>
                            <span>Monitor disk space</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_wafStatus" value="1" <?php echo !empty($so_general_opts['scansEnabled_wafStatus']) ? 'checked' : ''; ?>>
                            <span>Monitor Web Application Firewall status</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_other_scanOutside" value="1" <?php echo !empty($so_general_opts['other_scanOutside']) ? 'checked' : ''; ?>>
                            <span>Scan files outside your WordPress installation</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" name="vmpfence_go_scansEnabled_scanImages" value="1" <?php echo !empty($so_general_opts['scansEnabled_scanImages']) ? 'checked' : ''; ?>>
                            <span>Scan images, binary, and other files as if they were executable</span>
                        </label>
                    </div>
                </div>

            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Performance Options</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                $po_low_resource = VMPFence_Config::get('lowResourceScansEnabled', 0);
                $po_max_issues = VMPFence_Config::get('scan_maxIssues', 0);
                $po_max_duration = VMPFence_Config::get('scan_maxDuration', 0);
                $po_max_mem = VMPFence_Config::get('maxMem', 256);
                $po_max_exec_time = VMPFence_Config::get('scan_maxExecTime', 0);
                ?>

                <div class="vmpfence-ao-general-options-list">
                    <div class="vmpfence-ao-gen-opt-item">
                        <label class="vmpfence-ao-gen-opt-label">
                            <input type="checkbox" id="vmpfence_po_low_resource" <?php checked($po_low_resource, 1); ?>>
                            <span>Use low resource scanning (reduces server load by lengthening the scan duration)</span>
                        </label>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <div class="vmpfence-ao-perf-opt-row">
                            <span class="vmpfence-ao-perf-opt-text">Limit the number of issues sent in the scan results email</span>
                            <input type="number" id="vmpfence_po_max_issues" class="vmpfence-ao-perf-number" value="<?php echo esc_attr($po_max_issues); ?>" min="0">
                        </div>
                        <p class="vmpfence-ao-perf-opt-desc">0 or empty means unlimited issues will be sent</p>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <div class="vmpfence-ao-perf-opt-row">
                            <span class="vmpfence-ao-perf-opt-text">Time limit that a scan can run in seconds</span>
                            <input type="number" id="vmpfence_po_max_duration" class="vmpfence-ao-perf-number" value="<?php echo esc_attr($po_max_duration); ?>" min="0">
                        </div>
                        <p class="vmpfence-ao-perf-opt-desc">0 or empty means the default of 3 hours will be used</p>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <div class="vmpfence-ao-perf-opt-row">
                            <span class="vmpfence-ao-perf-opt-text">How much memory should VMP Security request when scanning</span>
                            <input type="number" id="vmpfence_po_max_mem" class="vmpfence-ao-perf-number" value="<?php echo esc_attr($po_max_mem); ?>" min="64">
                        </div>
                        <p class="vmpfence-ao-perf-opt-desc">Memory size in megabytes</p>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <div class="vmpfence-ao-perf-opt-row">
                            <span class="vmpfence-ao-perf-opt-text">Maximum execution time for each scan stage</span>
                            <input type="number" id="vmpfence_po_max_exec_time" class="vmpfence-ao-perf-number" value="<?php echo esc_attr($po_max_exec_time); ?>" min="0">
                        </div>
                        <p class="vmpfence-ao-perf-opt-desc">0 for default. Must be 8 or greater and 10-20 or higher is recommended for most servers</p>
                    </div>
                </div>

            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Advanced Scan Options</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                $aso_exclude = VMPFence_Config::get('scan_exclude', '');
                $aso_include_extra = VMPFence_Config::get('scan_include_extra', '');
                $aso_force_ipv4 = VMPFence_Config::get('scan_force_ipv4_start', 0);
                $aso_max_resume = VMPFence_Config::get('scan_max_resume_attempts', 3);
                ?>

                <div class="vmpfence-ao-general-options-list">
                    <div class="vmpfence-ao-gen-opt-item">
                        <div class="vmpfence-ao-adv-opt-row">
                            <span class="vmpfence-ao-adv-opt-label">Exclude files from scan that match these wildcard patterns (one per line)</span>
                            <textarea id="vmpfence_aso_exclude" rows="4" class="vmpfence-ao-adv-textarea" placeholder="e.g., *.log"><?php echo esc_textarea($aso_exclude); ?></textarea>
                        </div>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <div class="vmpfence-ao-adv-opt-row">
                            <span class="vmpfence-ao-adv-opt-label">Additional scan signatures (one per line)</span>
                            <textarea id="vmpfence_aso_include_extra" rows="4" class="vmpfence-ao-adv-textarea" placeholder="One signature per line"><?php echo esc_textarea($aso_include_extra); ?></textarea>
                        </div>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <div class="vmpfence-ao-adv-opt-row">
                            <label class="vmpfence-ao-gen-opt-label">
                                <input type="checkbox" id="vmpfence_aso_force_ipv4" style="margin-left: 30px !important;" <?php checked($aso_force_ipv4, 1); ?>>
                                <span>Use only IPv4 to start scans</span>
                            </label>
                            <p class="vmpfence-ao-adv-opt-desc">This option requires cURL. (This may have no effect on some old PHP or cURL versions.)</p>
                        </div>
                    </div>

                    <div class="vmpfence-ao-gen-opt-item">
                        <div class="vmpfence-ao-adv-opt-row">
                            <span class="vmpfence-ao-adv-opt-label">Maximum number of attempts to resume each scan stage</span>
                            <select id="vmpfence_aso_max_resume" class="vmpfence-ao-adv-select">
                                <option value="1" <?php selected($aso_max_resume, 1); ?>>1</option>
                                <option value="2" <?php selected($aso_max_resume, 2); ?>>2</option>
                                <option value="3" <?php selected($aso_max_resume, 3); ?>>3</option>
                                <option value="4" <?php selected($aso_max_resume, 4); ?>>4</option>
                                <option value="5" <?php selected($aso_max_resume, 5); ?>>5</option>
                                <option value="10" <?php selected($aso_max_resume, 10); ?>>10</option>
                                <option value="20" <?php selected($aso_max_resume, 20); ?>>20</option>
                            </select>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
    
    <!-- Tool Options Section -->
    <div class="all-options-section">
        <h2 class="all-options-section-header">Tool Options</h2>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Live Traffic Options</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                $lt_logging_mode = get_option('vmpfence_traffic_logging_mode', 'security_only');
                $lt_ignore_publishing = get_option('vmpfence_ignore_publishing_users', '0');
                $lt_ignore_usernames = get_option('vmpfence_ignore_usernames', '');
                $lt_ignore_ips = get_option('vmpfence_ignore_ips', '');
                $lt_ignore_ua = get_option('vmpfence_ignore_user_agent', '');
                $lt_max_rows = get_option('vmpfence_max_traffic_rows', '2000');
                $lt_max_days = get_option('vmpfence_max_traffic_days', '30');
                ?>

                <!-- Traffic logging mode -->
                <div class="vmpfence-ao-lt-row">
                    <label class="vmpfence-ao-lt-label">
                        Traffic logging mode
                        <span class="vmpfence-help-icon" title="Choose between security-only or all traffic logging.">?</span>
                    </label>
                    <div class="vmpfence-ao-lt-control">
                        <div class="vmpfence-ao-lt-btn-group">
                            <button type="button" class="vmpfence-ao-lt-mode-btn <?php echo $lt_logging_mode === 'security_only' ? 'active' : ''; ?>" data-value="security_only">SECURITY ONLY</button>
                            <button type="button" class="vmpfence-ao-lt-mode-btn <?php echo $lt_logging_mode === 'all_traffic' ? 'active' : ''; ?>" data-value="all_traffic">ALL TRAFFIC</button>
                        </div>
                        <input type="hidden" id="vmpfence_lt_logging_mode" value="<?php echo esc_attr($lt_logging_mode); ?>">
                    </div>
                </div>

                <!-- Don't log signed-in users -->
                <div class="vmpfence-ao-lt-row">
                    <label class="vmpfence-ao-lt-label">
                        <input type="checkbox" id="vmpfence_lt_ignore_publishing" value="1" style="margin: 0 !important;" <?php checked($lt_ignore_publishing, '1'); ?>>
                        Don't log signed-in users with publishing access
                    </label>
                    <div class="vmpfence-ao-lt-control"></div>
                </div>

                <!-- Usernames to ignore -->
                <div class="vmpfence-ao-lt-row">
                    <label class="vmpfence-ao-lt-label" for="vmpfence_lt_ignore_usernames">
                        List of comma separated usernames to ignore
                    </label>
                    <div class="vmpfence-ao-lt-control">
                        <textarea id="vmpfence_lt_ignore_usernames" rows="3" class="vmpfence-ao-lt-textarea" placeholder=""><?php echo esc_textarea($lt_ignore_usernames); ?></textarea>
                    </div>
                </div>

                <!-- IP addresses to ignore -->
                <div class="vmpfence-ao-lt-row">
                    <label class="vmpfence-ao-lt-label" for="vmpfence_lt_ignore_ips">
                        List of comma separated IP addresses to ignore
                    </label>
                    <div class="vmpfence-ao-lt-control">
                        <textarea id="vmpfence_lt_ignore_ips" rows="3" class="vmpfence-ao-lt-textarea" placeholder=""><?php echo esc_textarea($lt_ignore_ips); ?></textarea>
                    </div>
                </div>

                <!-- Browser user-agent to ignore -->
                <div class="vmpfence-ao-lt-row">
                    <label class="vmpfence-ao-lt-label" for="vmpfence_lt_ignore_ua">
                        Browser user-agent to ignore
                    </label>
                    <div class="vmpfence-ao-lt-control">
                        <input type="text" id="vmpfence_lt_ignore_ua" class="vmpfence-ao-lt-input" value="<?php echo esc_attr($lt_ignore_ua); ?>" placeholder="e.g., MyCustomBot/1.0">
                    </div>
                </div>

                <!-- Amount of data to store -->
                <div class="vmpfence-ao-lt-row">
                    <label class="vmpfence-ao-lt-label" for="vmpfence_lt_max_rows">
                        Amount of Live Traffic data to store (number of rows)
                    </label>
                    <div class="vmpfence-ao-lt-control">
                        <input type="number" id="vmpfence_lt_max_rows" class="vmpfence-ao-lt-input-small" value="<?php echo esc_attr($lt_max_rows); ?>" min="100" max="50000">
                    </div>
                </div>

                <!-- Maximum days to keep data -->
                <div class="vmpfence-ao-lt-row">
                    <label class="vmpfence-ao-lt-label" for="vmpfence_lt_max_days">
                        Maximum days to keep Live Traffic data (1-30 days)
                    </label>
                    <div class="vmpfence-ao-lt-control">
                        <input type="number" id="vmpfence_lt_max_days" class="vmpfence-ao-lt-input-small" value="<?php echo esc_attr($lt_max_days); ?>" min="1" max="30">
                    </div>
                </div>

            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Audit Log Options</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <?php
                $al_logging_mode = get_option('vmpfence_audit_log_logging_mode', 'preview');
                $al_display_menu = VMPFence_Config::get('display_audit_log_menu', 1);
                ?>

                <!-- Audit Log logging mode -->
                <div class="vmpfence-ao-al-row">
                    <label class="vmpfence-ao-al-label">
                        Audit Log logging mode
                        <span class="vmpfence-help-icon" title="Choose which events to log. 'Significant Events' logs all except content changes. 'All Events' includes content changes. 'Preview' and 'Disabled' do not send events to Central.">?</span>
                    </label>
                    <div class="vmpfence-ao-al-toggle-group">
                        <button type="button" class="vmpfence-ao-al-toggle-btn <?php echo $al_logging_mode === 'disabled' ? 'active' : ''; ?>" data-value="disabled">DISABLED</button>
                        <button type="button" class="vmpfence-ao-al-toggle-btn <?php echo $al_logging_mode === 'preview' ? 'active' : ''; ?>" data-value="preview">PREVIEW</button>
                        <button type="button" class="vmpfence-ao-al-toggle-btn <?php echo $al_logging_mode === 'significant' ? 'active' : ''; ?>" data-value="significant">SIGNIFICANT EVENTS</button>
                        <button type="button" class="vmpfence-ao-al-toggle-btn <?php echo $al_logging_mode === 'all' ? 'active' : ''; ?>" data-value="all">ALL EVENTS</button>
                    </div>
                    <input type="hidden" id="vmpfence_al_logging_mode" value="<?php echo esc_attr($al_logging_mode); ?>">
                </div>

                <!-- Display Audit Log menu option -->
                <div class="vmpfence-ao-al-row">
                    <label class="vmpfence-ao-al-checkbox-label">
                        <input type="checkbox" id="vmpfence_al_display_menu" value="1" <?php checked($al_display_menu, 1); ?>>
                        <span>Display Audit Log menu option</span>
                    </label>
                </div>

            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Import/Export Options</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <div class="vmpfence-ao-link-row">
                    <p class="vmpfence-accordion-note">Importing and exporting of options is available on the Tools page</p>
                    <a href="<?php echo esc_url(admin_url('admin.php?page=vmpfence-tools&tab=import-export')); ?>" class="button">IMPORT/EXPORT OPTIONS</a>
                </div>
            </div>
        </div>
        
        <div class="vmpfence-accordion-item">
            <div class="vmpfence-accordion-header">
                <span>Login Security Options</span>
                <span class="vmpfence-accordion-arrow">›</span>
            </div>
            <div class="vmpfence-accordion-content">
                <div class="vmpfence-ao-link-row">
                    <p class="vmpfence-accordion-note">Login Security options are available on the Login Security options page</p>
                    <a href="<?php echo esc_url(admin_url('admin.php?page=vmpfence-login-security')); ?>" class="button">LOGIN SECURITY OPTIONS</a>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- License Change Modal -->
<div id="vmpfence-license-change-modal" style="display:none;">
    <div class="vmpfence-license-modal-overlay"></div>
    <div class="vmpfence-license-modal-content">
        <span class="vmpfence-license-modal-close">&times;</span>
        <h2>Change License</h2>
        <p>Enter your license details to activate a different license on this site.</p>
        
        <form id="vmpfence-license-change-form">
            <?php wp_nonce_field('vmpfence_change_license', 'vmpfence_change_license_nonce'); ?>
            
            <div class="vmpfence-form-group">
                <label for="vmpfence-license-email">Email Address <span class="required">*</span></label>
                <input type="email" 
                       id="vmpfence-license-email" 
                       name="license_email" 
                       class="vmpfence-input" 
                       placeholder="Enter email used to register your license" 
                       required>
                <p class="vmpfence-field-description">Enter the email address you used when purchasing this license.</p>
            </div>
            
            <div class="vmpfence-form-group">
                <label for="vmpfence-modal-license-key">License Key <span class="required">*</span></label>
                <input type="text" 
                       id="vmpfence-modal-license-key" 
                       name="license_key" 
                       class="vmpfence-input" 
                       placeholder="FREE-XXXX-XXXX-XXXX or PREM-XXXX-XXXX-XXXX" 
                       pattern="^(FREE|PREM)-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$" 
                       maxlength="19" 
                       style="text-transform: uppercase;" 
                       required>
                <p class="vmpfence-field-description">Enter your license key (format: FREE-XXXX-XXXX-XXXX or PREM-XXXX-XXXX-XXXX).</p>
            </div>
            
            <div class="vmpfence-form-group">
                <label class="vmpfence-checkbox-label">
                    <input type="checkbox" 
                           id="vmpfence-email-alerts" 
                           name="email_alerts" 
                           value="1" 
                           <?php 
                           $email_alerts_enabled = VMPFence_Config::get('vmpfence_email_alerts_enabled', true);
                           // Handle case where get() returns null or empty string
                           $is_checked = ($email_alerts_enabled === null || $email_alerts_enabled === true || $email_alerts_enabled === '1' || $email_alerts_enabled === 1);
                           echo $is_checked ? 'checked' : ''; 
                           ?>>
                    <span>Enable email alerts for security events</span>
                </label>
            </div>
            
            <div id="vmpfence-license-error" class="vmpfence-error-message" style="display:none;"></div>
            
            <div class="vmpfence-modal-buttons">
                <button type="button" class="button" id="vmpfence-license-cancel-btn">Cancel</button>
                <button type="submit" class="button button-primary" id="vmpfence-license-submit-btn">Activate License</button>
            </div>
        </form>
    </div>
</div>

<?php
// Include WAF optimization modals (for Optimize Firewall / Remove Extended Protection)
require_once VMPFENCE_PLUGIN_DIR . 'firewall/views/waf-optimization-modal.php';
require_once VMPFENCE_PLUGIN_DIR . 'firewall/views/waf-removal-modal.php';
?>

<script type="text/javascript">
var vmpfence_firewall_ajax = {
    ajax_url: '<?php echo esc_js(admin_url('admin-ajax.php')); ?>',
    nonce: '<?php echo esc_js(wp_create_nonce('vmpfence_firewall_nonce')); ?>',
    protection_level_nonce: '<?php echo esc_js(wp_create_nonce('vmpfence_protection_level_nonce')); ?>'
};
</script>

<?php
// Include API & License Management Section content
// require_once VMPFENCE_PLUGIN_DIR . 'admin/views/api-management-section.php';
?>
