<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    {include file="seo.tpl"}
    <meta name="theme-color" content="#4ab1f1">

    <!-- 预加载关键CSS -->
    <link rel="preload" href="{resource_url path='templates/default/css/style.css'}" as="style">

    <!-- 主CSS -->
    <link rel="stylesheet" href="{resource_url path='templates/default/css/style.css'}">

    <!-- 内联关键CSS（用于首屏优化） -->
    <style>
        .header, .main-content, .footer { opacity: 0; }
        .loaded .header, .loaded .main-content, .loaded .footer {
            opacity: 1;
            transition: opacity 0.3s ease;
        }
        
        /* 导航栏优化 */
        .navbar {
            position: relative;
            z-index: 1000;
        }
        
        .nav-menu {
            display: flex;
            align-items: center;
            gap: 1.5rem;
            margin: 0;
            padding: 0;
            list-style: none;
        }
        
        .nav-link {
            color: white;
            text-decoration: none;
            font-weight: 500;
            padding: 0.5rem 1rem;
            border-radius: 4px;
            transition: all 0.3s ease;
            position: relative;
        }
        
        .nav-link:hover,
        .nav-link.active {
            background: rgba(255, 255, 255, 0.1);
            color: white;
        }
        
        .nav-link.active::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 1rem;
            right: 1rem;
            height: 2px;
            background: white;
        }
        
        /* 搜索框优化 */
        .search-form {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        
        .search-input {
            padding: 0.5rem 1rem;
            border: none;
            border-radius: 25px;
            outline: none;
            min-width: 250px;
            font-size: 0.9rem;
            background: rgba(255, 255, 255, 0.9);
            transition: all 0.3s ease;
        }
        
        .search-input:focus {
            background: white;
            box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
            min-width: 300px;
        }
        
        .search-button {
            background: white;
            color: var(--primary-color);
            border: none;
            padding: 0.5rem;
            border-radius: 50%;
            cursor: pointer;
            transition: all 0.3s ease;
            width: 36px;
            height: 36px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .search-button:hover {
            background: var(--bg-lighter);
            transform: scale(1.05);
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .navbar {
                flex-direction: column;
                gap: 1rem;
                text-align: center;
            }
            
            .nav-menu {
                order: 2;
                width: 100%;
                justify-content: center;
                flex-wrap: wrap;
                gap: 0.5rem;
            }
            
            .search-form {
                order: 3;
                width: 100%;
                justify-content: center;
            }
            
            .search-input {
                min-width: auto;
                flex: 1;
                max-width: 300px;
            }
            
            .search-input:focus {
                min-width: 250px;
            }
        }
        
        @media (max-width: 480px) {
            .nav-menu {
                flex-direction: column;
                gap: 0.5rem;
            }
            
            .nav-link {
                padding: 0.5rem;
                font-size: 0.9rem;
            }
        }
    </style>
</head>
<body>
<!-- 头部自定义数据钩子 -->
{display_custom_data position='header' page_type=$mod}

<!-- 头部导航 -->
<header class="header">
    <div class="container">
        <nav class="navbar">
            <a href="{resource_url}" class="logo">
                <span style="font-size: 1.2em;">📝</span>
                {$config.site.name}
            </a>

            <ul class="nav-menu">
                <li><a href="{resource_url}" class="nav-link {if $mod == 'index'}active{/if}">首页</a></li>
                {* 使用自定义导航数据替换自动分类导航 *}
                {if $config.custom_nav}
                    {foreach $config.custom_nav as $nav}
                        {if $nav.type == 'category'}
                            {* 分类链接 *}
                            <li>
                                <a href="{build_url mod='category' cate=$nav.category_id}"
                                   class="nav-link {if $mod == 'category' && isset($current_category) && $current_category.id == $nav.category_id}active{/if}"
                                   target="{$nav.target}">
                                    {$nav.name}
                                </a>
                            </li>
                        {else}
                            {* 自定义链接 *}
                            <li>
                                <a href="{$nav.url}" class="nav-link" target="{$nav.target}">
                                    {$nav.name}
                                </a>
                            </li>
                        {/if}
                    {/foreach}
                {/if}
            </ul>

            <!-- 修复搜索表单：使用正确的动态URL -->
            <form class="search-form" action="{build_url mod='search'}" method="get">
                <input type="hidden" name="mod" value="search">
                <input type="text" name="keyword" class="search-input" placeholder="输入关键词..." value="{$keyword|default:''}">
                <button type="submit" class="search-button" aria-label="搜索">
                    <span style="font-size: 0.9em;">🔍</span>
                </button>
            </form>
        </nav>
    </div>
</header>

    {* 头部广告 *}
    {if $config.ads.header.enabled}
    <div class="header-ad">
        {$config.ads.header.content}
    </div>
    {/if}

<!-- 主要内容容器 -->
<main class="container">
    <div class="main-content fade-in">
        <div class="content-area">

            <!-- 内容前自定义数据钩子 -->
            {display_custom_data position='before_content' page_type=$mod}