            <div style="display:flex; gap: 20px; margin-bottom: 20px; flex-wrap: wrap;">
                <div class="glass" style="padding: 20px; flex: 1; min-width: 350px; display: flex; align-items: center; justify-content: space-between; border-left: 5px solid var(--accent);">
                    <div>
                        <h3 style="margin-top:0; color:var(--text-muted); font-size:1rem; margin-bottom:5px;">Licence systému</h3>
                        <div id="licenseStatus" style="font-size:1.2rem; font-weight:bold;">Načítám...</div>
                    </div>
                    <div id="licenseBtnContainer" style="display:none;"></div>
                </div>
                <div id="updateStatusContainer" style="display:none; flex: 1; min-width: 350px;"></div>
            </div>
            
            <div style="display:flex; gap:20px; margin-bottom: 20px; flex-wrap:wrap;">
                <div class="glass" style="flex:1; padding: 20px; text-align: center; min-width: 120px;">
                    <div style="font-size:1.2rem; color:var(--text-muted);">Posluchačů</div>
                    <div id="dashListeners" style="font-size:2.5rem; color:var(--accent); font-weight:bold;">...</div>
                </div>
                <div class="glass" style="flex:1; padding: 20px; text-align: center; min-width: 120px;">
                    <div style="font-size:1.2rem; color:var(--text-muted);">Zobrazení</div>
                    <div id="dashViews" style="font-size:1.8rem; color:var(--accent); font-weight:bold;">...</div>
                </div>
                <div class="glass" style="flex:1; padding: 20px; text-align: center; min-width: 120px;">
                    <div style="font-size:1.2rem; color:var(--text-muted);">Unikátní</div>
                    <div id="dashUnique" style="font-size:1.8rem; color:var(--accent); font-weight:bold;">...</div>
                </div>
                <div class="glass" style="flex:2; padding: 20px; text-align: center; min-width: 250px;">
                    <div style="font-size:1.2rem; color:var(--text-muted);">Právě hraje</div>
                    <div id="dashNowPlaying" style="color:var(--accent); font-weight:bold; margin-top:10px; display:flex; align-items:center; justify-content:center; gap:15px;">...</div>
                </div>
            </div>
            
            <h1>Dashboard - Aktuálně ve vysílání</h1>
            <div style="display:flex; gap:20px; flex-wrap:wrap;">
                <div class="glass" style="flex:2; padding: 40px 20px; text-align: center; min-width: 300px;">
                    <div style="font-size: 1.2rem; color: var(--text-muted); margin-bottom: 10px;">🔴 ON-AIR</div>
                    <h2 id="onAirStatus" style="font-size: 2.5rem; color: var(--accent); margin: 0 0 10px 0;">Načítám...</h2>
                    <p id="onAirType" style="color: var(--text-muted); margin: 0;">...</p>
                </div>
                <div class="glass" style="flex:1; padding: 20px; min-width: 300px; display:flex; flex-direction:column; justify-content:center;">
                    <h3 style="margin-top:0;">Nečekaná změna? (Ruční přepnutí)</h3>
                    <p style="font-size:0.9rem; color:var(--text-muted);">Pokud do studia dorazil náhradník mimo kalendář, můžete jej přepnout zde.</p>
                    <div class="form-group" style="flex-direction:column; align-items:stretch; gap:10px; margin-bottom:0;">
                        <select id="overrideModSelect"><option value="">-- Vyberte moderátora --</option></select>
                        <div style="display:flex; gap:10px;">
                            <button onclick="setOverride()" style="flex:2;">Nastavit ručně</button>
                            <button onclick="clearOverride()" style="flex:1; background: rgba(255,255,255,0.2);">Zrušit</button>
                        </div>
                    </div>
                </div>
            </div>
            <script>
                async function loadOnAir() {
                    const res = await fetch('/admin/api/onair'); const json = await res.json();
                    const statusEl = document.getElementById('onAirStatus'); const typeEl = document.getElementById('onAirType');
                    if (json.data.is_autopilot) { statusEl.innerText = json.data.mods[0].name; statusEl.style.color = '#b026ff'; typeEl.innerText = '⚙️ Vysílá automat (žádný moderátor v kalendáři)'; } 
                    else { statusEl.innerText = json.data.mods.map(m => m.name).join(', '); statusEl.style.color = 'var(--accent)'; typeEl.innerText = json.data.is_override ? '⚠️ Vysílá v ručním režimu (mimo kalendář)' : '📅 Vysílá podle kalendáře'; }
                    if (json.data.web_views !== undefined) {
                        document.getElementById('dashViews').innerText = json.data.web_views.toLocaleString('cs-CZ');
                        document.getElementById('dashUnique').innerText = json.data.web_unique.toLocaleString('cs-CZ');
                    }
                    if (json.data.current_listeners !== undefined) {
                        document.getElementById('dashListeners').innerText = json.data.current_listeners.toLocaleString('cs-CZ');
                    }
                    if (json.data.now_playing !== undefined) {
                        let artworkHtml = '';
                        if (json.data.now_playing_artwork) {
                            artworkHtml = `<img src="${json.data.now_playing_artwork}" style="width:40px; height:40px; border-radius:5px; object-fit:cover; box-shadow:var(--glass-shadow);">`;
                        } else {
                            artworkHtml = `<div style="width:40px; height:40px; background:rgba(0,0,0,0.2); border-radius:5px; display:flex; align-items:center; justify-content:center; font-size:1.5rem;">🎵</div>`;
                        }
                        document.getElementById('dashNowPlaying').innerHTML = `${artworkHtml} <span style="font-size:1.1rem;">${json.data.now_playing || 'Nic nehraje'}</span>`;
                    }
                }
                async function loadActiveModeratorsForSelect() {
                    const res = await fetch('/admin/api/moderators'); const json = await res.json();
                    const select = document.getElementById('overrideModSelect');
                    json.data.forEach(m => { if (m.active) select.innerHTML += `<option value="${m.id}">${m.name}</option>`; });
                }
                async function setOverride() {
                    const modId = document.getElementById('overrideModSelect').value; if (!modId) return alert('Nejprve vyberte moderátora.');
                    await fetch('/admin/api/onair', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ moderator_ids: [modId] }) }); loadOnAir();
                }
                async function clearOverride() { await fetch('/admin/api/onair', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ clear: true }) }); loadOnAir(); document.getElementById('overrideModSelect').value = ''; }
                
                async function loadLicense() {
                    try {
                        const res = await fetch('/admin/api/license-check');
                        const json = await res.json();
                        const statEl = document.getElementById('licenseStatus');
                        const btnContainer = document.getElementById('licenseBtnContainer');
                        if (json.status === 'success' && json.data.configured) {
                            const l = json.data;
                            const isOk = l.license.toUpperCase() === 'OK';
                            let alertHtml = '';
                            if (isOk && l.valid_until && l.valid_until !== '-') {
                                const parts = l.valid_until.split('.');
                                if (parts.length === 3) {
                                    const expDate = new Date(`${parts[2]}-${parts[1]}-${parts[0]}T23:59:59`);
                                    const diffDays = Math.floor((expDate - new Date()) / (1000 * 60 * 60 * 24));
                                    if (diffDays <= 30 && diffDays >= 0) { alertHtml = `<div style="margin-top:10px; padding:10px; background:rgba(242, 201, 76, 0.2); border:1px solid #f2c94c; border-radius:8px; color:#f2c94c;">⚠️ Vaše licence vyprší za ${diffDays} dní! Nezapomeňte ji včas prodloužit.</div>`; }
                                    else if (diffDays < 0 && diffDays >= -30) { alertHtml = `<div style="margin-top:10px; padding:10px; background:rgba(255, 75, 43, 0.2); border:1px solid #ff4b2b; border-radius:8px; color:#ff4b2b;">🚨 Platnost licence vypršela před ${Math.abs(diffDays)} dny. Běží ochranná lhůta 30 dní, poté bude systém uzamčen!</div>`; }
                                    else if (diffDays < -30) { alertHtml = `<div style="margin-top:10px; padding:10px; background:rgba(255, 75, 43, 0.5); border:1px solid #ff4b2b; border-radius:8px; color:#fff; font-weight:bold;">⛔ Licence expirovala před více než 30 dny. Administrace je omezena.</div>`; }
                                }
                            } else if (!isOk) {
                                alertHtml = `<div style="margin-top:10px; padding:10px; background:rgba(255, 75, 43, 0.5); border:1px solid #ff4b2b; border-radius:8px; color:#fff; font-weight:bold;">⛔ Neplatná licence! Zkontrolujte nastavení. Administrace omezena.</div>`;
                            }
                            
                            if (l.update_available) {
                                document.getElementById('updateStatusContainer').innerHTML = `<div class="glass" style="padding:15px 20px; background:rgba(0, 210, 255, 0.1); border:1px solid var(--accent); border-radius:15px; color:#fff; display:flex; align-items:center; justify-content:space-between; height: 100%; box-sizing: border-box;">
                                    <div><strong style="color:var(--accent); font-size:1.1rem;">Nová verze k dispozici!</strong><br>
                                    Nainstalováno: ${l.local_version} &rarr; <strong>Nová: ${l.remote_version}</strong></div>
                                    <button onclick="window.location.href='/update.php'" style="background:linear-gradient(135deg, #00d2ff 0%, #3a7bd5 100%); color:#000; border-radius: 8px;">🚀 Aktualizovat</button>
                                </div>`;
                                document.getElementById('updateStatusContainer').style.display = 'block';
                            }

                            statEl.innerHTML = `Stav: <span style="color:${isOk ? '#38ef7d' : '#ff4b2b'}">${l.license}</span> &nbsp;|&nbsp; Verze: <span style="color:var(--accent)">${l.local_version}</span><div style="font-size: 0.9rem; font-weight: normal; margin-top: 5px;">Platnost do: <span style="color:var(--text-color)">${l.valid_until}</span></div>${alertHtml}`;
                            btnContainer.innerHTML = `<a href="https://api.mysoft.cz/redir.php?from=radiowebsystem&kam=prodlouzit&API=${encodeURIComponent(l.api_key)}" target="_blank" style="display:inline-block; padding:10px 15px; background:linear-gradient(135deg, #f2c94c 0%, #f2994a 100%); color:#000; text-decoration:none; border-radius:8px; font-weight:bold; transition:transform 0.2s;" onmouseover="this.style.transform='scale(1.05)'" onmouseout="this.style.transform='scale(1)'">Prodloužit licenci</a>`;
                            btnContainer.style.display = 'block';
                        } else if (json.status === 'success' && !json.data.configured) {
                            statEl.innerHTML = '<span style="color:var(--text-muted); font-size:1rem;">Licenční API klíč není zadán. Přejděte do Nastavení -> Integrace.</span>';
                        } else {
                            statEl.innerHTML = `<span style="color:#ff4b2b;">${json.message || 'Chyba komunikace s licenčním serverem'}</span>`;
                        }
                    } catch (e) { document.getElementById('licenseStatus').innerHTML = '<span style="color:#ff4b2b;">Chyba sítě.</span>'; }
                }
                
                loadLicense(); loadActiveModeratorsForSelect(); loadOnAir(); setInterval(loadOnAir, 5000);
            </script>