<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}ZJPB - 自己品吧 | AI工具导航{% endblock %}</title>

    {% block extra_head %}{% endblock %}

    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        :root {
            --primary-blue: #0ea5e9;
            --primary-dark: #0284c7;
            --text-primary: #1e293b;
            --text-secondary: #64748b;
            --text-muted: #94a3b8;
            --bg-page: #f8fafc;
            --bg-white: #ffffff;
            --border-color: #e2e8f0;
            --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
            --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
            --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
            --radius-sm: 6px;
            --radius-md: 8px;
            --radius-lg: 12px;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
            background: var(--bg-page);
            color: var(--text-primary);
            line-height: 1.6;
        }

        /* 导航栏 */
        .navbar {
            background: var(--bg-white);
            border-bottom: 1px solid var(--border-color);
            padding: 0;
            position: sticky;
            top: 0;
            z-index: 1000;
            box-shadow: var(--shadow-sm);
        }

        .nav-container {
            max-width: 1280px;
            margin: 0 auto;
            padding: 0 24px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            height: 64px;
        }

        .nav-left {
            display: flex;
            align-items: center;
            gap: 40px;
        }

        .nav-logo {
            display: flex;
            align-items: center;
            gap: 8px;
            text-decoration: none;
            color: var(--text-primary);
            font-weight: 700;
            font-size: 18px;
        }

        .nav-logo-icon {
            width: 32px;
            height: 32px;
            background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
        }

        .nav-links {
            display: flex;
            align-items: center;
            gap: 32px;
            list-style: none;
        }

        .nav-links a {
            color: var(--text-secondary);
            text-decoration: none;
            font-size: 14px;
            font-weight: 500;
            transition: color 0.2s;
        }

        .nav-links a:hover {
            color: var(--text-primary);
        }

        .nav-right {
            display: flex;
            align-items: center;
            gap: 16px;
        }

        .search-box {
            position: relative;
            display: flex;
            align-items: center;
        }

        .search-box input {
            width: 280px;
            padding: 8px 12px 8px 36px;
            border: 1px solid var(--border-color);
            border-radius: var(--radius-sm);
            font-size: 14px;
            background: var(--bg-page);
            transition: all 0.2s;
        }

        .search-box input:focus {
            outline: none;
            border-color: var(--primary-blue);
            background: var(--bg-white);
        }

        .search-box .search-icon {
            position: absolute;
            left: 10px;
            top: 50%;
            transform: translateY(-50%);
            font-size: 16px;
            color: var(--text-muted);
        }

        .btn {
            padding: 8px 16px;
            border-radius: var(--radius-sm);
            font-size: 14px;
            font-weight: 500;
            text-decoration: none;
            cursor: pointer;
            transition: all 0.2s;
            border: none;
            display: inline-flex;
            align-items: center;
            gap: 6px;
        }

        .btn-secondary {
            background: transparent;
            color: var(--text-secondary);
        }

        .btn-secondary:hover {
            color: var(--text-primary);
        }

        .btn-primary {
            background: var(--primary-blue);
            color: white;
        }

        .btn-primary:hover {
            background: var(--primary-dark);
        }

        /* 用户菜单 */
        .user-menu {
            position: relative;
        }

        .user-btn {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .avatar-sm {
            width: 28px;
            height: 28px;
            border-radius: 50%;
            object-fit: cover;
        }

        .avatar-placeholder {
            background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 12px;
            font-weight: 600;
        }

        .dropdown-arrow {
            font-size: 10px;
            transition: transform 0.2s;
        }

        .user-btn:hover .dropdown-arrow {
            transform: translateY(1px);
        }

        .dropdown-menu {
            position: absolute;
            top: calc(100% + 8px);
            right: 0;
            background: var(--bg-white);
            border: 1px solid var(--border-color);
            border-radius: var(--radius-md);
            box-shadow: var(--shadow-lg);
            min-width: 180px;
            padding: 8px;
            z-index: 1000;
        }

        .dropdown-menu a {
            display: block;
            padding: 10px 12px;
            color: var(--text-primary);
            text-decoration: none;
            border-radius: var(--radius-sm);
            font-size: 14px;
            transition: background 0.2s;
        }

        .dropdown-menu a:hover {
            background: var(--bg-page);
        }

        .dropdown-menu hr {
            margin: 4px 0;
            border: none;
            border-top: 1px solid var(--border-color);
        }

        /* 主内容区 */
        .main-content {
            max-width: 1280px;
            margin: 0 auto;
            padding: 0 24px;
        }

        /* 页脚 */
        .footer {
            background: var(--bg-white);
            border-top: 1px solid var(--border-color);
            margin-top: 80px;
            padding: 32px 0;
        }

        .footer-container {
            max-width: 1280px;
            margin: 0 auto;
            padding: 0 24px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .footer-text {
            color: var(--text-secondary);
            font-size: 14px;
        }

        .footer-links {
            display: flex;
            gap: 24px;
        }

        .footer-links a {
            color: var(--text-secondary);
            text-decoration: none;
            font-size: 14px;
            transition: color 0.2s;
        }

        .footer-links a:hover {
            color: var(--text-primary);
        }

        {% block extra_css %}{% endblock %}
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar">
        <div class="nav-container">
            <div class="nav-left">
                <a href="/" class="nav-logo">
                    <div class="nav-logo-icon">
                        <span style="font-size: 20px;">✦</span>
                    </div>
                    <span>ZJPB</span>
                </a>
                <ul class="nav-links">
                    <li><a href="/">Home</a></li>
                    <li><a href="/#categories">Categories</a></li>
                    <li><a href="/admin/login">Admin</a></li>
                </ul>
            </div>
            <div class="nav-right">
                <form action="/" method="get" class="search-box">
                    <span class="search-icon">🔍</span>
                    <input type="text" name="q" placeholder="搜索 AI 工具..." value="{{ search_query or '' }}">
                </form>
                {% if current_user.is_authenticated and current_user.__class__.__name__ == 'User' %}
                <!-- 已登录用户 -->
                <div class="user-menu">
                    <button class="btn btn-secondary user-btn" onclick="toggleUserDropdown(event)">
                        {% if current_user.avatar %}
                        <img src="{{ current_user.avatar }}" alt="{{ current_user.username }}" class="avatar-sm">
                        {% else %}
                        <div class="avatar-sm avatar-placeholder">{{ current_user.username[0].upper() }}</div>
                        {% endif %}
                        <span>{{ current_user.username }}</span>
                        <span class="dropdown-arrow">▼</span>
                    </button>
                    <div id="userDropdown" class="dropdown-menu" style="display: none;">
                        <a href="/user/profile">👤 个人中心</a>
                        <a href="/user/collections">⭐ 我的收藏</a>
                        <a href="/user/change-password">🔒 修改密码</a>
                        <hr>
                        <a href="#" onclick="logout(event)">🚪 退出登录</a>
                    </div>
                </div>
                {% else %}
                <!-- 未登录 -->
                <a href="/login" class="btn btn-secondary">登录</a>
                <a href="/register" class="btn btn-primary">注册</a>
                {% endif %}
            </div>
        </div>
    </nav>

    <!-- 主内容 -->
    {% block content %}{% endblock %}

    <!-- 页脚 -->
    <footer class="footer">
        <div class="footer-container">
            <div class="footer-text">
                <div>© 2025 ZJPB - 自己品吧 | AI工具导航. All rights reserved.</div>
                <div style="margin-top: 8px;">
                    <a href="https://beian.miit.gov.cn/" target="_blank" rel="noopener noreferrer" style="color: var(--text-secondary); text-decoration: none;">
                        浙ICP备2025154782号-1
                    </a>
                </div>
            </div>
            <div class="footer-links">
                <a href="#">关于我们</a>
                <a href="#">隐私政策</a>
                <a href="#">用户协议</a>
            </div>
        </div>
    </footer>

    <!-- Google tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-LZ4FGX5LRB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-LZ4FGX5LRB');
    </script>

    <!-- Microsoft Clarity 统计代码 -->
    <script type="text/javascript">
        (function(c,l,a,r,i,t,y){
            c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
            t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
            y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
        })(window, document, "clarity", "script", "uoa2j40sf0");
    </script>

    <!-- User Dropdown Script -->
    <script>
        function toggleUserDropdown(event) {
            event.stopPropagation();
            const dropdown = document.getElementById('userDropdown');
            dropdown.style.display = dropdown.style.display === 'none' ? 'block' : 'none';
        }

        function logout(event) {
            event.preventDefault();
            if (confirm('确定要退出登录吗？')) {
                window.location.href = '/logout';
            }
        }

        // 点击外部关闭下拉菜单
        document.addEventListener('click', function(event) {
            const dropdown = document.getElementById('userDropdown');
            if (dropdown && !event.target.closest('.user-menu')) {
                dropdown.style.display = 'none';
            }
        });
    </script>

    {% block extra_js %}{% endblock %}
</body>
</html>
