File size: 15,353 Bytes
1404692
b2b72aa
1404692
273ab56
 
 
b2b72aa
273ab56
 
f697c3b
273ab56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f697c3b
273ab56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f697c3b
273ab56
 
 
1404692
f697c3b
273ab56
15fea8d
273ab56
15fea8d
273ab56
 
 
 
 
 
 
 
 
 
15fea8d
273ab56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f946b58
273ab56
 
 
 
 
 
 
 
 
 
 
b8fe50f
273ab56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1404692
 
273ab56
 
 
 
 
15fea8d
 
273ab56
 
 
 
 
 
 
15fea8d
 
 
 
273ab56
15fea8d
 
 
273ab56
 
 
 
 
1404692
15fea8d
 
273ab56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15fea8d
273ab56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b8fe50f
273ab56
15fea8d
273ab56
 
 
 
 
 
15fea8d
 
273ab56
 
 
 
 
 
 
 
15fea8d
273ab56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15fea8d
273ab56
15fea8d
273ab56
 
 
15fea8d
273ab56
 
 
 
15fea8d
273ab56
15fea8d
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}Telegram Stremio{% endblock %}</title>

<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"/>

<style>
:root {
    --primary: {{ theme.colors.primary }};
    --secondary: {{ theme.colors.secondary }};
    --accent: {{ theme.colors.accent }};
    --bg: {{ theme.colors.background }};
    --card: {{ theme.colors.card }};
    --border: {{ theme.colors.border }}; /* Added theme border */
    --text: {{ theme.colors.text }};
    --text-sec: {{ theme.colors.text_secondary }};
}

body {
    background-color: var(--bg);
    color: var(--text);
    background-image: 
        radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--primary) 12%, transparent), transparent 40%),
        radial-gradient(circle at 85% 80%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 40%),
        radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--card) 40%, transparent), transparent 60%);
    background-attachment: fixed;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* GLASS PANELS */
.glass-panel {
    background: color-mix(in srgb, var(--card) 45%, transparent);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.glass-pill { border-radius: 9999px; }

/* NAV LINKS */
.nav-link {
    color: var(--text-sec);
    border-radius: 9999px;
    padding: 0.5rem 1.25rem;
    transition: color 0.3s ease;
    position: relative;
    z-index: 1;
    white-space: nowrap;
    font-weight: 600;
}

/* FIX: Text becomes dark background color when pill is behind it for readability */
.nav-link:hover, .nav-link.active-page {
    color: var(--bg) !important; 
}

/* ACTIVE PILL */
#active-pill {
    position: absolute;
    background: var(--primary);
    border-radius: 9999px;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 0;
    box-shadow: 0 0 15px color-mix(in srgb, var(--primary) 40%, transparent);
}

    .toast {
        pointer-events: auto;
        min-width: 260px;
        max-width: 360px;
        border: 1px solid var(--border);
        background: color-mix(in srgb, var(--card) 88%, transparent);
        color: var(--text);
        box-shadow: 0 18px 40px rgba(0,0,0,0.2);
        border-radius: 1rem;
        padding: 0.9rem 1rem;
        display: flex;
        align-items: flex-start;
        gap: 0.75rem;
        backdrop-filter: blur(14px);
        animation: toast-in 220ms ease-out;
    }

    .toast.success { border-color: color-mix(in srgb, #22c55e 35%, var(--border)); }
    .toast.error { border-color: color-mix(in srgb, #ef4444 35%, var(--border)); }
    .toast.info { border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); }

    .toast-title {
        font-weight: 800;
        font-size: 0.9rem;
        line-height: 1.2;
    }

    .toast-message {
        margin-top: 0.15rem;
        font-size: 0.82rem;
        color: var(--text-secondary);
        line-height: 1.35;
    }

    @keyframes toast-in {
        from { opacity: 0; transform: translateY(-10px) scale(0.98); }
        to { opacity: 1; transform: translateY(0) scale(1); }
    }

    @keyframes toast-out {
        from { opacity: 1; transform: translateY(0) scale(1); }
        to { opacity: 0; transform: translateY(-8px) scale(0.98); }
    }

/* Mobile improvement */
@media (max-width: 640px) {
    #toast-container {
        top: 5rem;
        left: 0.75rem;
        right: 0.75rem;
    }

    .toast {
        max-width: none;
        width: 100%;
    }
}
    
/* THEME SELECT */
.theme-select {
    appearance: none;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.5rem 2rem 0.5rem 1rem;
    font-size: 0.875rem;
    cursor: pointer;
}

/* OVERLAY */
#overlay {
    backdrop-filter: blur(8px);
    background: rgba(0,0,0,0.4);
    transition: opacity 0.3s ease;
}

/* SCROLL ANIMATION - Fixed "Jumping" issue */
.nav-scrolled { 
    transform: translate(-50%, -5px) scale(0.97); 
    background: color-mix(in srgb, var(--card) 80%, transparent);
}

#mobile-menu { will-change: max-height, opacity; }
</style>

<script>
tailwind.config = {
    darkMode: 'class',
    theme: {
        extend: {
            colors: {
                primary: 'var(--primary)',
                secondary: 'var(--secondary)',
                accent: 'var(--accent)',
                background: 'var(--bg)',
                card: 'var(--card)',
                border: 'var(--border)',
                text: 'var(--text)',
                'text-secondary': 'var(--text-sec)'
            }
        }
    }
}
</script>
</head>

<body class="pt-24 pb-12 antialiased">

<div id="overlay" class="fixed inset-0 z-40 opacity-0 pointer-events-none"></div>

<nav id="navbar" class="fixed top-6 left-1/2 -translate-x-1/2 w-[95%] max-w-6xl z-50 glass-panel glass-pill px-5 py-3 flex justify-between items-center transition-all duration-300">
    
    <a href="/" class="flex items-center gap-3 shrink-0">
        <div class="w-8 h-8 rounded-full bg-primary flex items-center justify-center shadow-[0_0_15px_var(--primary)]">
            <i class="fa-solid fa-play text-white text-xs"></i>
        </div>
        <span class="text-lg md:text-xl font-extrabold tracking-wide text-transparent bg-clip-text bg-gradient-to-r from-primary to-accent">
            TG Stremio
        </span>
    </a>

    {% if current_user %}
    <div id="nav-container" class="hidden md:flex absolute left-1/2 -translate-x-1/2 items-center gap-1 p-1 bg-black/10 rounded-full border border-white/5">
        <div id="active-pill" class="pointer-events-none"></div>
        <a href="/" class="nav-link">Home</a>
        <a href="/media/manage" class="nav-link">Media</a>
        <a href="/admin/dashboard" class="nav-link">Admin</a>
        <a href="/admin/subscriptions" class="nav-link">Subs</a>
        <a href="/admin/access" class="nav-link">Access</a>
    </div>
    {% endif %}

    <div class="flex items-center gap-3">
        {% if current_user %}
            <button id="menu-btn" class="md:hidden w-10 h-10 flex items-center justify-center text-xl hover:bg-white/10 rounded-full transition">
                <i id="menu-icon" class="fa-solid fa-bars"></i>
            </button>

            <div class="relative">
                <button id="user-btn" class="w-10 h-10 rounded-full bg-primary/20 hover:bg-primary/30 flex items-center justify-center text-primary text-lg transition border border-primary/30">
                    <i class="fa-solid fa-user"></i>
                </button>

                <div id="user-dropdown" class="absolute right-0 top-14 w-64 glass-panel rounded-2xl p-4 opacity-0 scale-95 pointer-events-none transition-all duration-200 origin-top-right z-50">
                    <div class="mb-3 border-b border-white/10 pb-3">
                        <p class="text-sm font-bold text-text">{{ current_user }}</p>
                        <p class="text-[10px] text-green-400 font-bold uppercase tracking-wider flex items-center gap-1">
                            <span class="w-1.5 h-1.5 rounded-full bg-green-400 animate-pulse"></span> Online
                        </p>
                    </div>

                    <form method="post" action="/set-theme" class="mb-4">
                        <label class="text-[10px] uppercase text-text-secondary font-bold mb-1 block ml-2">App Theme</label>
                        <select name="theme" onchange="this.form.submit()" class="theme-select w-full">
                            {% for theme_key, theme_data in themes.items() %}
                            <option value="{{ theme_key }}" {% if current_theme==theme_key %}selected{% endif %}>
                                {{ theme_data.name }}
                            </option>
                            {% endfor %}
                        </select>
                    </form>

                    <a href="/logout" class="block text-center bg-red-500/10 hover:bg-red-500 text-red-500 hover:text-white px-4 py-2.5 rounded-xl text-sm font-bold transition-all">
                        Logout
                    </a>
                </div>
            </div>
        {% else %}
            <a href="/login" class="bg-primary hover:bg-primary/80 text-white px-6 py-2 rounded-full text-sm font-bold transition shadow-lg shadow-primary/20">
                Login
            </a>
        {% endif %}
    </div>

    <div id="mobile-menu" class="absolute top-[calc(100%+12px)] left-0 w-full overflow-hidden max-h-0 opacity-0 transition-all duration-300 ease-in-out md:hidden z-40">
        <div class="glass-panel mx-2 rounded-3xl p-4 flex flex-col gap-2">
            <a href="/" class="px-4 py-3 rounded-xl hover:bg-primary hover:text-background transition flex items-center gap-3 font-semibold"><i class="fa-solid fa-house"></i> Home</a>
            <a href="/media/manage" class="px-4 py-3 rounded-xl hover:bg-primary hover:text-background transition flex items-center gap-3 font-semibold"><i class="fa-solid fa-clapperboard"></i> Media</a>
            <a href="/admin/dashboard" class="px-4 py-3 rounded-xl hover:bg-primary hover:text-background transition flex items-center gap-3 font-semibold"><i class="fa-solid fa-chart-line"></i> Admin</a>
            <a href="/admin/subscriptions" class="px-4 py-3 rounded-xl hover:bg-primary hover:text-background transition flex items-center gap-3 font-semibold"><i class="fa-solid fa-credit-card"></i> Subs</a>
            <a href="/admin/access" class="px-4 py-3 rounded-xl hover:bg-primary hover:text-background transition flex items-center gap-3 font-semibold"><i class="fa-solid fa-shield"></i> Access</a>
        </div>
    </div>
</nav>

<main class="flex-1 w-full max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 mt-8">
    {% block content %}{% endblock %}
</main>

<footer class="mt-auto w-full max-w-5xl mx-auto px-6 py-8">
    <div class="glass-panel rounded-3xl p-6 flex flex-col md:flex-row justify-between items-center gap-4">
        <div class="flex items-center gap-2">
            <i class="fa-brands fa-telegram text-primary text-xl"></i>
            <p class="text-text-secondary text-sm">© 2026 Telegram Stremio</p>
        </div>
    </div>
</footer>
    
<div id="toast-container"
     class="fixed top-4 right-4 z-[9999] space-y-3 pointer-events-none"></div>
    
<script>
const btn = document.getElementById('menu-btn');
const mobileMenu = document.getElementById('mobile-menu');
const overlay = document.getElementById('overlay');
const icon = document.getElementById('menu-icon');
const navbar = document.getElementById('navbar');
const userBtn = document.getElementById('user-btn');
const userDropdown = document.getElementById('user-dropdown');
const navContainer = document.getElementById('nav-container');

let isMenuOpen = false;
let isUserOpen = false;

// --- MENU & DROPDOWN TOGGLE ---
function toggleMenu() {
    isMenuOpen = !isMenuOpen;
    if(isUserOpen) closeUser();
    if (isMenuOpen) {
        mobileMenu.style.maxHeight = mobileMenu.scrollHeight + "px";
        mobileMenu.style.opacity = "1";
        overlay.style.opacity = "1";
        overlay.classList.remove("pointer-events-none");
        icon.classList.replace("fa-bars","fa-xmark");
    } else closeMenu();
}

function closeMenu() {
    mobileMenu.style.maxHeight = "0px";
    mobileMenu.style.opacity = "0";
    icon.classList.replace("fa-xmark","fa-bars");
    isMenuOpen = false;
    checkOverlay();
}

function toggleUser(e) {
    if(e) e.stopPropagation();
    isUserOpen = !isUserOpen;
    if(isMenuOpen) closeMenu();
    if (isUserOpen) {
        userDropdown.classList.remove("opacity-0", "scale-95", "pointer-events-none");
        overlay.style.opacity = "1";
        overlay.classList.remove("pointer-events-none");
    } else closeUser();
}

function closeUser() {
    if(userDropdown) userDropdown.classList.add("opacity-0", "scale-95", "pointer-events-none");
    isUserOpen = false;
    checkOverlay();
}

function checkOverlay() {
    if (!isMenuOpen && !isUserOpen) {
        overlay.style.opacity = "0";
        overlay.classList.add("pointer-events-none");
    }
}
    function showToast(message, type = 'info', title = '') {
        const container = document.getElementById('toast-container');
        if (!container) return;

        const toast = document.createElement('div');
        toast.className = `toast ${type}`;

        const icon = type === 'success'
            ? 'fa-circle-check'
            : type === 'error'
                ? 'fa-triangle-exclamation'
                : 'fa-circle-info';

        toast.innerHTML = `
            <i class="fa-solid ${icon} mt-0.5"></i>
            <div class="min-w-0">
                ${title ? `<div class="toast-title">${escapeHtml(title)}</div>` : ''}
                <div class="toast-message">${escapeHtml(message)}</div>
            </div>
        `;

        container.appendChild(toast);

        setTimeout(() => {
            toast.style.animation = 'toast-out 180ms ease-in forwards';
            setTimeout(() => {
                if (toast.parentNode) toast.parentNode.removeChild(toast);
            }, 200);
        }, 2600);
    }

    // GLOBAL SAFE ESCAPE (important!)
    function escapeHtml(str) {
        return String(str || '')
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#039;');
    }
    
// Events
if(btn) btn.onclick = toggleMenu;
if(userBtn) userBtn.onclick = toggleUser;
overlay.onclick = () => { closeMenu(); closeUser(); };

window.addEventListener("scroll", () => {
    if (isMenuOpen) closeMenu();
    if (isUserOpen) closeUser();
    navbar.classList.toggle("nav-scrolled", window.scrollY > 20);
});

document.addEventListener("keydown", e => {
    if (e.key === "Escape") { closeMenu(); closeUser(); }
});

if (userDropdown) {
    userDropdown.addEventListener("click", e => e.stopPropagation());
}

// --- SMART ACTIVE PILL LOGIC ---
const links = document.querySelectorAll(".nav-link");
const pill = document.getElementById("active-pill");
let activeLink = null;

function movePill(el) {
    if(!pill || !el) return;
    const r = el.getBoundingClientRect();
    const pr = el.parentElement.getBoundingClientRect();
    pill.style.width = r.width + "px";
    pill.style.height = r.height + "px";
    pill.style.left = (r.left - pr.left) + "px";
    pill.style.top = (r.top - pr.top) + "px";
}

window.addEventListener('load', () => {
    const current = window.location.pathname;
    activeLink = [...links].find(l => l.getAttribute("href") === current) || links[0];
    if(activeLink) {
        activeLink.classList.add('active-page');
        movePill(activeLink);
    }
});

links.forEach(l => {
    l.addEventListener("mouseenter", () => movePill(l));
});

// Returns pill to active page when mouse leaves the navbar
if(navContainer) {
    navContainer.addEventListener("mouseleave", () => {
        if(activeLink) movePill(activeLink);
    });
}
</script>

</body>
</html>