<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>The Macro Hub - Professional Automation Suite by Make A Macro</title>
    <meta name="description" content="Advanced macro recording and playback with AI-powered human emulation">
    <link rel="stylesheet" href="/static/css/style.css">
    <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cdefs%3E%3ClinearGradient id='grad' x1='0%25' y1='0%25' x2='100%25' y2='100%25'%3E%3Cstop offset='0%25' style='stop-color:%238a2be2;stop-opacity:1' /%3E%3Cstop offset='100%25' style='stop-color:%23da70d6;stop-opacity:1' /%3E%3C/linearGradient%3E%3C/defs%3E%3Ccircle cx='50' cy='50' r='45' fill='url(%23grad)' /%3E%3Cpath d='M 30 50 L 40 50 L 40 35 L 60 50 L 40 65 L 40 50 L 30 50 M 70 35 L 70 65' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E">
</head>
<body>
    <div class="background-gradient"></div>
    
    <div class="container">
        <!-- Header -->
        <header class="header">
            <div class="brand-container">
                <h1 class="logo">
                    <svg class="logo-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
                        <path d="M4 7 L9 7 L9 2 L15 12 L9 12 L9 17 L4 7" stroke-linecap="round" stroke-linejoin="round"/>
                        <circle cx="18" cy="6" r="2.5" fill="currentColor"/>
                        <circle cx="20" cy="18" r="2.5" fill="currentColor"/>
                    </svg>
                    <div class="brand-text">
                        <span class="brand-name">The Macro Hub</span>
                        <span class="brand-tagline">by Make A Macro</span>
                    </div>
                </h1>
                <div class="version-badge">v1.1.0</div>
                <div class="license-badge" id="licenseBadge" onclick="openLicenseModal()">
                    <span class="license-icon">🔑</span>
                    <span class="license-text">Checking...</span>
                </div>
            </div>
            <div class="status-badge" id="statusBadge">
                <span class="status-dot"></span>
                <span class="status-text">Idle</span>
            </div>
        </header>
        
        <!-- License Management Modal -->
        <div class="modal" id="licenseModal" onclick="if(event.target === this) closeLicenseModal()">
            <div class="modal-content" onclick="event.stopPropagation()">
                <div class="modal-header">
                    <h2>License Management</h2>
                    <button class="modal-close" onclick="closeLicenseModal()">&times;</button>
                </div>
                <div class="modal-body" id="licenseModalBody">
                    <!-- Content populated by JavaScript -->
                </div>
            </div>
        </div>

        <!-- Update Available Banner -->
        {% if update_available %}
        <div class="update-banner" style="background: linear-gradient(135deg, #10b981, #059669); color: white; padding: 1rem; border-radius: 12px; margin-bottom: 1rem; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 4px 20px rgba(16, 185, 129, 0.3);">
            <div style="display: flex; align-items: center; gap: 1rem;">
                <div style="font-size: 2rem;">🎉</div>
                <div>
                    <div style="font-weight: 700; font-size: 1.1rem; margin-bottom: 0.25rem;">
                        New Version Available: v{{ latest_version }}
                    </div>
                    <div style="opacity: 0.9; font-size: 0.9rem;">
                        You're running v{{ app_version }}. Update now for the latest features and improvements!
                    </div>
                </div>
            </div>
            <a href="{{ download_url }}" target="_blank" style="background: white; color: #059669; padding: 0.75rem 1.5rem; border-radius: 8px; text-decoration: none; font-weight: 700; transition: transform 0.2s;" onmouseover="this.style.transform='scale(1.05)'" onmouseout="this.style.transform='scale(1)'">
                Download Update
            </a>
        </div>
        {% endif %}

        <!-- System Message Banner (admin broadcasts) -->
        <div class="system-message-banner" id="systemMessageBanner" style="display: none;">
            <div class="system-message-content">
                <div class="system-message-icon" id="systemMessageIcon">ℹ️</div>
                <div class="system-message-text" id="systemMessageText"></div>
                <button class="system-message-close" onclick="dismissSystemMessage()" title="Dismiss">×</button>
            </div>
        </div>

        <!-- Main Control Panel -->
        <div class="main-panel glass-card">
            <div class="control-section">
                <!-- Record Button -->
                <div class="record-section">
                    <button class="btn-record" id="recordBtn">
                        <div class="record-icon">
                            <svg class="icon-circle" viewBox="0 0 24 24" fill="currentColor">
                                <circle cx="12" cy="12" r="8"/>
                            </svg>
                        </div>
                        <div class="record-text">
                            <div class="record-timer" id="recordTimer">00:00.00</div>
                        </div>
                    </button>
                    <div class="keyboard-hint">
                        <kbd id="recordKeyDisplay" class="keybind-clickable" title="Click to rebind">F2</kbd> to start/stop recording
                    </div>
                    <div class="keyboard-hint" style="margin-top: 0.5rem;">
                        <kbd id="playbackKeyDisplay" class="keybind-clickable" title="Click to rebind">F3</kbd> to start/stop playback
                    </div>
                    <div class="keyboard-hint" style="margin-top: 0.25rem; font-size: 0.75rem; opacity: 0.7;">
                        💡 Click hotkeys above to customize
                    </div>
                </div>

                <!-- Action Buttons -->
                <div class="action-buttons">
                    <button class="btn-action btn-play" id="playBtn" disabled>
                        <svg class="btn-icon" viewBox="0 0 24 24" fill="currentColor">
                            <path d="M8 5v14l11-7z"/>
                        </svg>
                        <span>Play</span>
                    </button>
                    
                    <button class="btn-action btn-stop" id="stopBtn" disabled>
                        <svg class="btn-icon" viewBox="0 0 24 24" fill="currentColor">
                            <rect x="6" y="6" width="12" height="12"/>
                        </svg>
                        <span>Stop</span>
                    </button>
                    
                    <button class="btn-action btn-clear" id="clearBtn" disabled>
                        <svg class="btn-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                            <path d="M3 6h18M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"/>
                        </svg>
                        <span>Clear</span>
                    </button>
                </div>

                <!-- Loop Toggle -->
                <div class="loop-control">
                    <label class="toggle-label">
                        <input type="checkbox" id="loopToggle" class="toggle-input">
                        <div class="toggle-switch">
                            <div class="toggle-slider"></div>
                        </div>
                        <span class="toggle-text">
                            <svg class="loop-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                <path d="M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0118.8-4.3M22 12.5a10 10 0 01-18.8 4.2"/>
                            </svg>
                            Keep Looping
                        </span>
                    </label>
                    <div class="loop-counter" id="loopCounter" style="display: none;">
                        Loop <span id="loopCount">0</span> of ∞
                    </div>
                </div>
            </div>
        </div>

        <!-- AI-Powered Humanization Panel -->
        <div class="humanize-panel glass-card">
            <div class="panel-header-premium">
                <h2 class="panel-title">
                    <svg class="title-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                        <path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/>
                    </svg>
                    AI-Powered Humanization Engine
                    <span class="premium-badge">PRO</span>
                </h2>
                <div class="humanize-description">
                    Advanced neural algorithms simulate authentic human behavior patterns. Evade detection with industry-leading anti-bot technology powered by behavioral biometrics.
                </div>
            </div>
            
            <div class="offset-controls">
                <div class="offset-control">
                    <div class="offset-header">
                        <label for="movementOffset" class="offset-label">
                            <svg class="offset-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                <path d="M5 12h14M12 5l7 7-7 7"/>
                            </svg>
                            Movement Path Offset
                        </label>
                        <div class="offset-input-group">
                            <input type="number" id="movementOffsetInput" class="offset-input" min="0" max="100" step="0.01" value="0">
                            <span class="offset-unit">%</span>
                        </div>
                    </div>
                    <input type="range" id="movementOffset" class="offset-slider" min="0" max="100" value="0" step="1">
                    <div class="offset-hint">Natural variance in mouse trajectory (Beta distribution)</div>
                </div>
                
                <div class="offset-control">
                    <div class="offset-header">
                        <label for="clickOffset" class="offset-label">
                            <svg class="offset-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                <circle cx="12" cy="12" r="3"/>
                                <path d="M12 1v6M12 17v6M23 12h-6M7 12H1"/>
                            </svg>
                            Click Location Offset
                        </label>
                        <div class="offset-input-group">
                            <input type="number" id="clickOffsetInput" class="offset-input" min="0" max="100" step="0.01" value="0">
                            <span class="offset-unit">%</span>
                        </div>
                    </div>
                    <input type="range" id="clickOffset" class="offset-slider" min="0" max="100" value="0" step="1">
                    <div class="offset-hint">Randomizes exact click coordinates within radius</div>
                </div>
                
                <div class="offset-control">
                    <div class="offset-header">
                        <label for="speedVariance" class="offset-label">
                            <svg class="offset-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                <polyline points="23 6 13.5 15.5 8.5 10.5 1 18"/>
                                <polyline points="17 6 23 6 23 12"/>
                            </svg>
                            Speed Variance
                        </label>
                        <div class="offset-input-group">
                            <input type="number" id="speedVarianceInput" class="offset-input" min="0" max="100" step="0.01" value="0">
                            <span class="offset-unit">%</span>
                        </div>
                    </div>
                    <input type="range" id="speedVariance" class="offset-slider" min="0" max="100" value="0" step="1">
                    <div class="offset-hint">Randomizes movement speed (acceleration/deceleration)</div>
                </div>
                
                <div class="offset-control">
                    <div class="offset-header">
                        <label for="pauseFrequency" class="offset-label">
                            <svg class="offset-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                <rect x="6" y="4" width="4" height="16"/>
                                <rect x="14" y="4" width="4" height="16"/>
                            </svg>
                            Micro-Pause Frequency
                        </label>
                        <div class="offset-input-group">
                            <input type="number" id="pauseFrequencyInput" class="offset-input" min="0" max="100" step="0.01" value="0">
                            <span class="offset-unit">%</span>
                        </div>
                    </div>
                    <input type="range" id="pauseFrequency" class="offset-slider" min="0" max="100" value="0" step="1">
                    <div class="offset-hint">Chance of brief hesitation (human thinking moments)</div>
                </div>
                
                <div class="offset-control">
                    <div class="offset-header">
                        <label for="jitterIntensity" class="offset-label">
                            <svg class="offset-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                <path d="M3 12h4l3-9 4 18 3-9h4"/>
                            </svg>
                            Micro-Jitter Intensity
                        </label>
                        <div class="offset-input-group">
                            <input type="number" id="jitterIntensityInput" class="offset-input" min="0" max="100" step="0.01" value="0">
                            <span class="offset-unit">%</span>
                        </div>
                    </div>
                    <input type="range" id="jitterIntensity" class="offset-slider" min="0" max="100" value="0" step="1">
                    <div class="offset-hint">Subtle hand tremor simulation (0=none, 100=max)</div>
                </div>
                
                <div class="offset-control">
                    <div class="offset-header">
                        <label for="overshootIntensity" class="offset-label">
                            <svg class="offset-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                <path d="M12 2L2 12l10 10 10-10L12 2z"/>
                                <path d="M12 6v12"/>
                            </svg>
                            Mouse Overshoot Intensity
                        </label>
                        <div class="offset-input-group">
                            <input type="number" id="overshootIntensityInput" class="offset-input" min="0" max="100" step="0.01" value="0">
                            <span class="offset-unit">%</span>
                        </div>
                    </div>
                    <input type="range" id="overshootIntensity" class="offset-slider" min="0" max="100" value="0" step="1">
                    <div class="offset-hint">How far the mouse overshoots the target (magnitude)</div>
                </div>
                
                <div class="offset-control">
                    <div class="offset-header">
                        <label for="overshootFrequency" class="offset-label">
                            <svg class="offset-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                <path d="M12 2L2 12l10 10 10-10L12 2z"/>
                                <circle cx="12" cy="12" r="3"/>
                            </svg>
                            Mouse Overshoot Frequency
                        </label>
                        <div class="offset-input-group">
                            <input type="number" id="overshootFrequencyInput" class="offset-input" min="0" max="100" step="0.01" value="0">
                            <span class="offset-unit">%</span>
                        </div>
                    </div>
                    <input type="range" id="overshootFrequency" class="offset-slider" min="0" max="100" value="0" step="1">
                    <div class="offset-hint">How often overshoots occur (randomized to avoid patterns)</div>
                </div>
                
                <div class="offset-control">
                    <div class="offset-header">
                        <label for="randomMovement" class="offset-label">
                            <svg class="offset-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                <circle cx="12" cy="12" r="10"/>
                                <path d="M8 12h8M12 8v8"/>
                            </svg>
                            Random Fidgeting
                        </label>
                        <div class="offset-input-group">
                            <input type="number" id="randomMovementInput" class="offset-input" min="0" max="100" step="0.01" value="0">
                            <span class="offset-unit">%</span>
                        </div>
                    </div>
                    <input type="range" id="randomMovement" class="offset-slider" min="0" max="100" value="0" step="1">
                    <div class="offset-hint">Small circles/wiggles between actions (totally unique each time)</div>
                </div>
                
                <div class="offset-control">
                    <div class="offset-header">
                        <label for="playbackSpeed" class="offset-label">
                            <svg class="offset-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                <polygon points="5 3 19 12 5 21 5 3"/>
                            </svg>
                            Playback Speed
                        </label>
                        <div class="offset-input-group">
                            <input type="number" id="playbackSpeedInput" class="offset-input" min="10" max="300" step="0.1" value="100">
                            <span class="offset-unit">%</span>
                        </div>
                    </div>
                    <input type="range" id="playbackSpeed" class="offset-slider" min="10" max="300" value="100" step="1">
                    <div class="offset-hint">Playback speed multiplier (50%=slower, 100%=normal, 200%=faster)</div>
                </div>
            </div>
            
            <div class="humanize-features">
                <div class="feature-badge">
                    <svg class="feature-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                        <polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/>
                    </svg>
                    Bezier Curves
                </div>
                <div class="feature-badge">
                    <svg class="feature-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                        <path d="M12 2L2 12l10 10 10-10L12 2z"/>
                    </svg>
                    Overshoot
                </div>
                <div class="feature-badge">
                    <svg class="feature-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                        <circle cx="12" cy="12" r="10"/>
                        <path d="M12 8v8M8 12h8"/>
                    </svg>
                    Random Fidgeting
                </div>
                <div class="feature-badge">
                    <svg class="feature-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                        <circle cx="12" cy="12" r="10"/>
                        <path d="M12 6v6l4 2"/>
                    </svg>
                    Easing
                </div>
                <div class="feature-badge">
                    <svg class="feature-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                        <path d="M21 16V8a2 2 0 00-1-1.73l-7-4a2 2 0 00-2 0l-7 4A2 2 0 003 8v8a2 2 0 001 1.73l7 4a2 2 0 002 0l7-4A2 2 0 0021 16z"/>
                    </svg>
                    Beta Distribution
                </div>
            </div>
        </div>

        <!-- Statistics Panel -->
        <div class="stats-panel glass-card">
            <h2 class="panel-title">
                <svg class="title-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                    <line x1="18" y1="20" x2="18" y2="10"/>
                    <line x1="12" y1="20" x2="12" y2="4"/>
                    <line x1="6" y1="20" x2="6" y2="14"/>
                </svg>
                Recording Statistics
            </h2>
            <div class="stats-grid">
                <div class="stat-card">
                    <div class="stat-value" id="statDuration">00:00.00</div>
                    <div class="stat-label">Duration</div>
                </div>
                <div class="stat-card">
                    <div class="stat-value" id="statClicks">0</div>
                    <div class="stat-label">Clicks</div>
                </div>
                <div class="stat-card">
                    <div class="stat-value" id="statMovements">0</div>
                    <div class="stat-label">Movements</div>
                </div>
                <div class="stat-card">
                    <div class="stat-value" id="statEvents">0</div>
                    <div class="stat-label">Total Events</div>
                </div>
            </div>
        </div>

        <!-- Macro Management Panel -->
        <div class="macro-panel glass-card">
            <h2 class="panel-title">
                <svg class="title-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                    <path d="M19 21H5a2 2 0 01-2-2V5a2 2 0 012-2h11l5 5v11a2 2 0 01-2 2z"/>
                    <polyline points="17 21 17 13 7 13 7 21"/>
                    <polyline points="7 3 7 8 15 8"/>
                </svg>
                Saved Macros
            </h2>
            
            <div class="macro-controls">
                <div class="save-section">
                    <input type="text" id="macroName" class="input-field" placeholder="Enter macro name..." maxlength="50">
                    <button class="btn-save" id="saveBtn" disabled>
                        <svg class="btn-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                            <path d="M19 21H5a2 2 0 01-2-2V5a2 2 0 012-2h11l5 5v11a2 2 0 01-2 2z"/>
                            <polyline points="17 21 17 13 7 13 7 21"/>
                            <polyline points="7 3 7 8 15 8"/>
                        </svg>
                        Save Macro
                    </button>
                </div>
                
                <div class="macro-list" id="macroList">
                    <div class="empty-state">
                        <svg class="empty-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                            <path d="M9 11l3 3L22 4"/>
                            <path d="M21 12v7a2 2 0 01-2 2H5a2 2 0 01-2-2V5a2 2 0 012-2h11"/>
                        </svg>
                        <p>No saved macros yet</p>
                        <p class="empty-hint">Record and save a macro to get started</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Toast Notifications -->
        <div class="toast-container" id="toastContainer"></div>
    </div>

    <!-- Keybind Rebinding Modal -->
    <div class="keybind-modal" id="keybindModal">
        <div class="keybind-modal-content">
            <div class="keybind-modal-header">
                <h3 id="keybindModalTitle">Rebind Hotkey</h3>
            </div>
            <div class="keybind-modal-body">
                <div class="keybind-instruction">
                    <svg class="keybind-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                        <rect x="2" y="4" width="20" height="16" rx="2"/>
                        <path d="M6 8h.01M10 8h.01M14 8h.01M6 12h.01M10 12h.01M14 12h.01M6 16h.01M10 16h.01M14 16h.01"/>
                    </svg>
                    <p id="keybindMessage">Press any key to set as the new hotkey...</p>
                    <div class="keybind-preview" id="keybindPreview">Waiting for input...</div>
                </div>
                <div class="keybind-buttons">
                    <button class="keybind-btn keybind-btn-cancel" id="keybindCancel">Cancel (ESC)</button>
                </div>
            </div>
        </div>
    </div>

    <script src="/static/js/app.js"></script>
</body>
</html>

