<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}TheNicheQuiz{% endblock %}</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet">
    <style>
        *, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
        :root {
            --bg: #0a0a1a; --bg-card: #0f1023; --bg-input: #141432;
            --bg-hover: #1a1a3e; --border: #1e1e3a;
            --text: #e8e8f0; --text-secondary: #8888a8; --text-muted: #555577;
            --amber: #F59E0B; --amber-dark: #d97706;
            --purple: #8B5CF6; --blue: #3b82f6;
            --green: #22c55e; --red: #ef4444;
        }
        body {
            font-family: 'Inter', -apple-system, sans-serif;
            background: var(--bg); color: var(--text);
            min-height: 100vh;
        }

        /* ── App Nav ──────────────────────────────────────── */
        .app-nav {
            position: sticky; top: 0; z-index: 100;
            display: flex; align-items: center; justify-content: space-between;
            padding: 0 24px; height: 60px;
            background: rgba(10,10,26,0.9);
            backdrop-filter: blur(20px);
            border-bottom: 1px solid var(--border);
        }
        .app-nav-left {
            display: flex; align-items: center; gap: 32px;
        }
        .app-nav-logo {
            display: flex; align-items: center; gap: 8px;
            text-decoration: none;
        }
        .app-nav-logo-icon {
            font-size: 18px;
        }
        .app-nav-logo-text {
            font-size: 16px; font-weight: 800; color: #fff;
        }
        .app-nav-logo-text span { color: var(--amber); }

        .app-nav-links {
            display: flex; align-items: center; gap: 2px;
        }
        .app-nav-link {
            padding: 8px 14px; border-radius: 8px;
            text-decoration: none; font-size: 13px; font-weight: 600;
            color: var(--text-muted); transition: all 0.2s;
            display: flex; align-items: center; gap: 6px;
        }
        .app-nav-link:hover { color: var(--text); background: rgba(255,255,255,0.04); }
        .app-nav-link.active { color: var(--amber); background: rgba(245,158,11,0.06); }
        .app-nav-link svg { width: 16px; height: 16px; }

        .app-nav-right {
            display: flex; align-items: center; gap: 12px;
        }
        .app-nav-user {
            display: flex; align-items: center; gap: 8px;
            font-size: 13px; font-weight: 600; color: var(--text-secondary);
        }
        .app-nav-avatar {
            width: 30px; height: 30px; border-radius: 8px;
            background: linear-gradient(135deg, var(--purple), var(--blue));
            display: flex; align-items: center; justify-content: center;
            font-size: 13px; font-weight: 700; color: #fff;
        }
        .app-nav-logout {
            padding: 6px 14px; border-radius: 6px;
            background: rgba(255,255,255,0.04);
            border: 1px solid var(--border);
            color: var(--text-muted); font-size: 12px; font-weight: 600;
            text-decoration: none; transition: all 0.2s;
        }
        .app-nav-logout:hover { color: var(--red); border-color: rgba(239,68,68,0.3); background: rgba(239,68,68,0.05); }

        /* ── Page Container ───────────────────────────────── */
        .app-page {
            max-width: 1200px; margin: 0 auto;
            padding: 32px 24px;
        }
        .page-header {
            margin-bottom: 32px;
        }
        .page-title {
            font-size: 28px; font-weight: 800; letter-spacing: -0.02em;
            margin-bottom: 6px;
        }
        .page-subtitle {
            font-size: 15px; color: var(--text-secondary);
        }

        /* ── Cards & Components ───────────────────────────── */
        .card {
            background: var(--bg-card);
            border: 1px solid var(--border);
            border-radius: 16px;
            padding: 28px;
            transition: all 0.2s;
        }
        .card:hover { border-color: rgba(255,255,255,0.06); }

        .stat-grid {
            display: grid; grid-template-columns: repeat(3, 1fr);
            gap: 16px; margin-bottom: 32px;
        }
        @media (max-width: 768px) { .stat-grid { grid-template-columns: 1fr; } }

        .stat-card {
            background: var(--bg-card);
            border: 1px solid var(--border);
            border-radius: 14px;
            padding: 24px;
            display: flex; align-items: center; gap: 16px;
        }
        .stat-icon {
            width: 48px; height: 48px; border-radius: 12px;
            display: flex; align-items: center; justify-content: center;
            font-size: 22px; flex-shrink: 0;
        }
        .stat-icon-amber { background: rgba(245,158,11,0.1); border: 1px solid rgba(245,158,11,0.15); }
        .stat-icon-purple { background: rgba(139,92,246,0.1); border: 1px solid rgba(139,92,246,0.15); }
        .stat-icon-blue { background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.15); }
        .stat-value {
            font-size: 28px; font-weight: 800; letter-spacing: -0.02em;
        }
        .stat-label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

        .btn {
            display: inline-flex; align-items: center; gap: 8px;
            padding: 10px 22px; border-radius: 10px; border: none;
            font-size: 14px; font-weight: 700; font-family: inherit;
            cursor: pointer; transition: all 0.2s;
            text-decoration: none;
        }
        .btn-amber {
            background: linear-gradient(135deg, var(--amber), var(--amber-dark));
            color: #000;
        }
        .btn-amber:hover { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(245,158,11,0.3); }
        .btn-purple {
            background: linear-gradient(135deg, var(--purple), #6d28d9);
            color: #fff;
        }
        .btn-purple:hover { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(139,92,246,0.3); }
        .btn-outline {
            background: rgba(255,255,255,0.04);
            border: 1px solid var(--border);
            color: var(--text-secondary);
        }
        .btn-outline:hover { border-color: rgba(255,255,255,0.15); color: var(--text); }
        .btn-red {
            background: rgba(239,68,68,0.08);
            border: 1px solid rgba(239,68,68,0.2);
            color: var(--red);
        }
        .btn-red:hover { background: rgba(239,68,68,0.15); }
        .btn-sm { padding: 6px 14px; font-size: 12px; border-radius: 8px; }

        .empty-state {
            text-align: center; padding: 60px 20px;
            color: var(--text-muted);
        }
        .empty-icon { font-size: 48px; margin-bottom: 16px; }
        .empty-title { font-size: 18px; font-weight: 700; color: var(--text-secondary); margin-bottom: 8px; }
        .empty-desc { font-size: 14px; margin-bottom: 24px; }

        /* ── Table ────────────────────────────────────────── */
        .data-table {
            width: 100%; border-collapse: collapse;
        }
        .data-table th {
            text-align: left; padding: 12px 16px;
            font-size: 11px; font-weight: 700; color: var(--text-muted);
            text-transform: uppercase; letter-spacing: 0.06em;
            border-bottom: 1px solid var(--border);
        }
        .data-table td {
            padding: 14px 16px; font-size: 14px;
            border-bottom: 1px solid rgba(30,30,58,0.5);
        }
        .data-table tr:hover td { background: rgba(255,255,255,0.015); }

        .badge {
            display: inline-block; padding: 3px 10px;
            border-radius: 6px; font-size: 11px; font-weight: 600;
        }
        .badge-amber { background: rgba(245,158,11,0.1); color: var(--amber); border: 1px solid rgba(245,158,11,0.15); }
        .badge-purple { background: rgba(139,92,246,0.1); color: var(--purple); border: 1px solid rgba(139,92,246,0.15); }

        /* ── Toast ────────────────────────────────────────── */
        .toast-container {
            position: fixed; bottom: 24px; right: 24px; z-index: 200;
            display: flex; flex-direction: column; gap: 8px;
        }
        .toast {
            padding: 12px 20px; border-radius: 8px; font-size: 13px; font-weight: 500;
            animation: slideIn 0.3s ease; backdrop-filter: blur(10px); max-width: 360px;
        }
        .toast.success { background: rgba(34,197,94,0.15); border: 1px solid rgba(34,197,94,0.3); color: var(--green); }
        .toast.error { background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3); color: var(--red); }
        @keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

        /* ── Mobile ───────────────────────────────────────── */
        @media (max-width: 768px) {
            .app-nav { padding: 0 16px; }
            .app-nav-links { display: none; }
            .app-nav-user span { display: none; }
            .app-page { padding: 20px 16px; }
        }

        {% block extra_styles %}{% endblock %}
    </style>
    {% block head %}{% endblock %}
</head>
<body>
    <nav class="app-nav">
        <div class="app-nav-left">
            <a href="/app" class="app-nav-logo">
                <span class="app-nav-logo-icon">🎯</span>
                <span class="app-nav-logo-text">The<span>Niche</span>Quiz</span>
            </a>
            <div class="app-nav-links">
                <a href="/app" class="app-nav-link {% if active_page == 'dashboard' %}active{% endif %}">
                    <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"/></svg>
                    Dashboard
                </a>
                <a href="/app/campaigns" class="app-nav-link {% if active_page == 'campaigns' %}active{% endif %}">
                    <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"/></svg>
                    My Campaigns
                </a>
                <a href="/app/generate" class="app-nav-link {% if active_page == 'generate' %}active{% endif %}">
                    <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/></svg>
                    Generate
                </a>
                <a href="/app/account" class="app-nav-link {% if active_page == 'account' %}active{% endif %}">
                    <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/></svg>
                    Account
                </a>
            </div>
        </div>
        <div class="app-nav-right">
            <div class="app-nav-user">
                <div class="app-nav-avatar">{{ current_user.name[0]|upper if current_user.name else 'U' }}</div>
                <span>{{ current_user.name or current_user.email }}</span>
            </div>
            <a href="/logout" class="app-nav-logout">Log Out</a>
        </div>
    </nav>

    {% block body %}{% endblock %}

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

    <script>
    function showToast(message, type = 'success') {
        const container = document.getElementById('toastContainer');
        const toast = document.createElement('div');
        toast.className = `toast ${type}`;
        toast.textContent = message;
        container.appendChild(toast);
        setTimeout(() => { toast.style.opacity = '0'; setTimeout(() => toast.remove(), 300); }, 3500);
    }
    </script>
    {% block scripts %}{% endblock %}
</body>
</html>
