<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PiAware Dashboard</title>
    <!-- Leaflet CSS -->
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="/static/css/style.css?v=5">
</head>
<body>
    <div class="dashboard">
        <header class="glass-panel">
            <div>
                <h1>PiAware <span class="accent">Live Radar</span></h1>
                <a href="/history" style="color: var(--text-muted); text-decoration: none; font-size: 0.85rem; margin-top: 0.25rem; display: inline-block; transition: color 0.2s; margin-right: 1.5rem;" onmouseover="this.style.color='var(--accent)'" onmouseout="this.style.color='var(--text-muted)'">📖 Consulter le Registre Historique</a>
                <a href="/stats" style="color: var(--text-muted); text-decoration: none; font-size: 0.85rem; margin-top: 0.25rem; display: inline-block; transition: color 0.2s; margin-right: 1.5rem;" onmouseover="this.style.color='var(--accent)'" onmouseout="this.style.color='var(--text-muted)'">📊 Statistiques Analytiques</a>
                <a href="/atc" style="color: #10b981; text-decoration: none; font-size: 0.85rem; margin-top: 0.25rem; display: inline-block; transition: color 0.2s; text-shadow: 0 0 5px rgba(16, 185, 129, 0.5); margin-right: 1.5rem;" onmouseover="this.style.color='#34d399'" onmouseout="this.style.color='#10b981'">📡 Vue ATC</a>
                <button onclick="showSettingsModal()" style="background: transparent; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted); transition: color 0.2s; padding: 0;" onmouseover="this.style.color='var(--accent)'" onmouseout="this.style.color='var(--text-muted)'" title="Paramètres">⚙️</button>
            </div>
            <div class="stats-container">
                <div class="stat-box">
                    <span class="label">Status</span>
                    <span class="value" id="sys-status">--</span>
                </div>
                <div class="stat-box">
                    <span class="label">CPU</span>
                    <span class="value" id="sys-cpu">--</span>
                </div>
                <div class="stat-box">
                    <span class="label">Temp</span>
                    <span class="value" id="sys-temp">--</span>
                </div>
            </div>
        </header>

        <div class="controls glass-panel">
            <label class="toggle"><input type="checkbox" id="toggle-trails"> Trajectoires</label>
            <label class="toggle"><input type="checkbox" id="toggle-metric"> Système Métrique</label>
        </div>

        <div class="main-content">
            <aside class="glass-panel sidebar">
                <h2>Avions Détectés (<span id="live-count">0</span>)</h2>
                
                <!-- Spotter Card -->
                <div id="spotter-card" style="display: none; flex-direction: column; gap: 0.5rem; padding: 1rem; margin-bottom: 1rem; background: rgba(0,0,0,0.2); border-radius: 12px; border: 1px solid var(--glass-border);">
                    <div style="display: flex; justify-content: space-between; align-items: flex-start;">
                        <h3 id="spotter-callsign" class="accent" style="margin: 0; font-size: 1.25rem;">-</h3>
                        <img id="spotter-airline-logo" src="" style="max-height: 25px; display: none; border-radius: 4px;" />
                    </div>
                    <div style="font-family: monospace; font-size: 0.8rem; color: var(--text-muted);" id="spotter-hex"></div>
                    <div id="spotter-type" style="font-weight: 600; font-size: 0.9rem; margin-top: 0.25rem;"></div>
                    
                    <div id="spotter-flight-data" style="display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; font-size: 0.8rem; margin-top: 0.5rem; background: rgba(255,255,255,0.05); padding: 0.5rem; border-radius: 6px;">
                        <div><span style="color:var(--text-muted)">Alt:</span> <span id="spotter-alt">-</span></div>
                        <div><span style="color:var(--text-muted)">Vit:</span> <span id="spotter-spd">-</span></div>
                        <div><span style="color:var(--text-muted)">Cap:</span> <span id="spotter-hdg">-</span></div>
                        <div><span style="color:var(--text-muted)">Dist:</span> <span id="spotter-dist">-</span></div>
                    </div>
                    
                    <img id="spotter-photo" src="" style="width: 100%; border-radius: 8px; margin-top: 0.5rem; display: none;" />
                    <div id="spotter-loading" style="font-size: 0.8rem; color: var(--text-muted); font-style: italic; margin-top: 0.5rem;">Recherche en base de données...</div>
                    
                    <!-- Contrôles Photo Spotter -->
                    <div id="spotter-photo-controls" style="display: none; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem;">
                        <div style="display: flex; gap: 0.4rem;">
                            <button id="btn-spotter-approve" class="spotter-btn" style="flex: 1; background: #10b981; color: white; border: none; padding: 6px; border-radius: 6px; cursor: pointer; font-size: 0.8rem; font-weight: 600; transition: background 0.2s; display: flex; align-items: center; justify-content: center; gap: 4px;" onmouseover="this.style.background='#059669'" onmouseout="this.style.background='#10b981'">✅ Valider</button>
                            <button id="btn-spotter-reject" class="spotter-btn" style="flex: 1; background: #f59e0b; color: white; border: none; padding: 6px; border-radius: 6px; cursor: pointer; font-size: 0.8rem; font-weight: 600; transition: background 0.2s; display: flex; align-items: center; justify-content: center; gap: 4px;" onmouseover="this.style.background='#d97706'" onmouseout="this.style.background='#f59e0b'">⏭️ Suivant</button>
                            <button id="btn-spotter-cancel" class="spotter-btn" style="flex: 1; background: #ef4444; color: white; border: none; padding: 6px; border-radius: 6px; cursor: pointer; font-size: 0.8rem; font-weight: 600; transition: background 0.2s; display: flex; align-items: center; justify-content: center; gap: 4px;" onmouseover="this.style.background='#dc2626'" onmouseout="this.style.background='#ef4444'">❌ Annuler</button>
                        </div>
                    </div>
                    <div id="spotter-photo-search" style="display: none; margin-top: 0.5rem;">
                        <div style="display: flex; gap: 0.25rem;">
                            <input type="text" id="spotter-search-query" placeholder="Rechercher manuellement..." style="flex: 1; padding: 6px 8px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.1); background: rgba(0,0,0,0.3); color: white; font-size: 0.8rem; outline: none; transition: border-color 0.2s;" onfocus="this.style.borderColor='var(--accent)'" onblur="this.style.borderColor='rgba(255,255,255,0.1)'" />
                            <button id="btn-spotter-search" style="background: var(--accent); color: white; border: none; padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 0.8rem; transition: background 0.2s;" onmouseover="this.style.background='#0284c7'" onmouseout="this.style.background='var(--accent)'">🔍</button>
                        </div>
                    </div>
                    <div id="spotter-status-badge" style="display: none; margin-top: 0.5rem; font-size: 0.75rem; font-weight: 600; padding: 4px 8px; border-radius: 6px; text-align: center;"></div>
                    
                    <button id="btn-spotter-close" onclick="closeSpotterCard()" style="margin-top: 0.5rem; background: rgba(255,255,255,0.1); color: white; border: none; padding: 8px; border-radius: 6px; cursor: pointer; font-size: 0.8rem; font-weight: 600; transition: background 0.2s;" onmouseover="this.style.background='rgba(255,255,255,0.2)'" onmouseout="this.style.background='rgba(255,255,255,0.1)'">⬅️ Retour à la liste</button>
                </div>

                <div id="aircraft-list" class="aircraft-list">
                    <!-- Javascript populates this -->
                </div>
            </aside>
            <main class="glass-panel map-container">
                <div id="map"></div>
            </main>
        </div>
    </div>

    <!-- Fenêtre Modale de Paramètres -->
    <div id="settings-modal" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 9999; justify-content: center; align-items: center; backdrop-filter: blur(5px);">
        <div class="glass-panel" style="background: rgba(15, 23, 42, 0.95); width: 400px; padding: 2rem; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.5);">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h2 style="margin: 0; font-size: 1.25rem; color: #f8fafc;">⚙️ Paramètres</h2>
                <button onclick="hideSettingsModal()" style="background: transparent; border: none; color: var(--text-muted); font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            
            <div style="margin-bottom: 1.5rem;">
                <label for="retention-days" style="display: block; color: var(--text-muted); font-size: 0.9rem; margin-bottom: 8px;">Jours de conservation de l'historique :</label>
                <div style="display: flex; gap: 10px;">
                    <input type="number" id="retention-days" value="{{ retention }}" min="1" max="3650" style="flex: 1; padding: 10px; border-radius: 8px; border: 1px solid var(--accent); background: rgba(0,0,0,0.5); color: var(--text); outline: none;">
                    <button onclick="saveSettings()" style="background: var(--accent); color: white; border: none; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-weight: bold; transition: background 0.2s;">Sauvegarder</button>
                </div>
                <div id="settings-msg" style="margin-top: 8px; font-size: 0.85rem; color: #10b981; display: none;">Enregistré avec succès !</div>
            </div>
            
            <div style="margin-bottom: 1.5rem; border-top: 1px solid var(--glass-border); padding-top: 1.5rem;">
                <h3 style="margin: 0 0 1rem 0; font-size: 1rem; color: #f8fafc;">Sensibilité du Zoom</h3>
                
                <div style="margin-bottom: 1rem;">
                    <div style="display: flex; justify-content: space-between; color: var(--text-muted); font-size: 0.85rem; margin-bottom: 6px;">
                        <label for="zoom-delta">Pas du zoom (boutons & clavier) :</label>
                        <span id="zoom-delta-val">0.5</span>
                    </div>
                    <input type="range" id="zoom-delta" min="0.1" max="1.0" step="0.05" value="0.5" style="width: 100%; accent-color: var(--accent); cursor: pointer;">
                </div>
                
                <div style="margin-bottom: 1rem;">
                    <div style="display: flex; justify-content: space-between; color: var(--text-muted); font-size: 0.85rem; margin-bottom: 6px;">
                        <label for="zoom-wheel-speed">Vitesse molette :</label>
                        <span id="zoom-wheel-speed-val">120px (plus grand = plus doux)</span>
                    </div>
                    <input type="range" id="zoom-wheel-speed" min="60" max="300" step="10" value="120" style="width: 100%; accent-color: var(--accent); cursor: pointer;">
                </div>
            </div>
            
            <div style="font-size: 0.8rem; color: var(--text-muted); line-height: 1.4;">
                <span style="color: #f59e0b;">ⓘ</span> Les vols plus anciens que cette durée seront supprimés (sauf s'ils détiennent un Trophée).
            </div>
        </div>
    </div>

    <!-- Leaflet JS -->
    <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
    <script src="/static/js/app.js?v=8"></script>
</body>
</html>
