/* =========================
   Header 基础
========================= */
.site-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--color-border);
    transition: box-shadow 0.3s ease;
}

.site-header.scrolled {
    box-shadow: var(--shadow-sm);
}

/* Header 容器 */
.header-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between; /* Default: spread items */
    gap: 20px;
}

/* =========================
   左侧：Logo
========================= */
.header-left .logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--color-text-main);
    font-weight: 600;
    flex-shrink: 0; /* Prevent logo shrinking */
}

.header-left img {
    height: 36px;
    width: 36px;
    margin-right: 10px;
}

.header-left .slogan {
    font-size: 16px;
    color: var(--color-text-main);
    letter-spacing: 0.5px;
    font-family: var(--font-serif);
    white-space: nowrap;
}

/* =========================
   中间：导航
========================= */
.header-nav {
    display: flex;
    align-items: center;
    gap: 30px;
    flex-shrink: 0;
}

.header-nav .nav-item {
    font-size: 15px;
    color: var(--color-text-secondary);
    text-decoration: none;
    padding: 20px 0;
    position: relative;
    font-weight: 500;
    transition: color 0.3s;
}

.header-nav .nav-item:hover,
.header-nav .nav-item.active {
    color: var(--color-primary);
}

.header-nav .nav-item.active::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 2px;
    background-color: var(--color-primary);
    border-radius: 2px 2px 0 0;
}

/* =========================
   搜索框 (Desktop & Mobile)
========================= */
.header-search {
    position: relative;
    display: flex;
    align-items: center;
    margin-left: auto; /* Push to right on desktop by default if space permits, or managed by flex */
}

.header-search input {
    width: 200px;
    padding: 8px 16px 8px 36px;
    border: 1px solid var(--color-border);
    border-radius: 20px;
    font-size: 14px;
    background-color: var(--color-bg-light);
    color: var(--color-text-main);
    transition: all 0.3s;
    text-align: center; /* Center placeholder text */
}

.header-search input::placeholder {
    color: var(--color-text-light);
    text-align: center; /* Ensure placeholder is centered */
}

.header-search input:focus {
    outline: none;
    border-color: var(--color-primary);
    background-color: #fff;
    width: 240px;
    box-shadow: 0 0 0 3px rgba(16, 172, 132, 0.1);
    text-align: left; /* Optional: align left when typing */
}

/* When focused, move placeholder to left if desired, or keep centered. 
   Usually better UX to align left on focus. */
.header-search input:focus::placeholder {
    text-align: left;
}

.header-search-icon {
    position: absolute;
    left: 12px;
    color: var(--color-text-light);
    pointer-events: none;
    width: 16px;
    height: 16px;
}

/* ==============================================
    header 搜索后进入loading 转圈样式
============================================== */
.loading-spinner {
    border: 4px solid #f3f3f3; /* 浅灰背景 */
    border-top: 4px solid #007bff; /* 蓝色高亮 */
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 10px auto;
}

/* 动画关键帧 */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}


/* =========================
   右侧：功能区
========================= */
.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}


/* 听读按钮 */
.listen-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: var(--color-primary);
    color: #fff;
    font-size: 14px;
    padding: 8px 18px;
    border-radius: 20px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s;
    box-shadow: 0 2px 5px rgba(16, 172, 132, 0.2);
    white-space: nowrap;
}

.listen-btn:hover {
    background-color: var(--color-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(16, 172, 132, 0.3);
}

.listen-btn:active {
    transform: translateY(0);
}

/* 登录按钮 */
.login-btn {
    font-size: 14px;
    color: var(--color-text-secondary);
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.2s;
    white-space: nowrap;
}

.login-btn:hover {
    color: var(--color-primary);
    background-color: rgba(16, 172, 132, 0.05);
}

/* 用户头像 */
.user-avatar {
    display: flex;
    align-items: center;
}

.user-avatar img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s;
}

.user-avatar:hover img {
    transform: scale(1.05);
    border-color: var(--color-primary);
}

/* =========================
   移动端适配
========================= */
@media (max-width: 768px) {
    .header-container {
        padding: 0 12px;
        height: 56px;
        gap: 10px; /* Smaller gap */
    }

    /* 1. Logo (Left) */
    .header-left .slogan {
        display: none; /* Hide slogan */
    }
    .header-left img {
        margin-right: 0;
        width: 32px;
        height: 32px;
    }

    /* 2. Nav (Hidden) */
    .header-nav {
        display: none;
    }

    /* 3. Search (Middle - Flex Grow) */
    .header-search {
        display: flex;
        flex: 1; /* Take up remaining space */
        margin-left: 0;
        margin-right: 0;
        max-width: 100%;
    }

    .header-search input {
        width: 100%; /* Full width of container */
        padding: 6px 12px 6px 32px;
        font-size: 13px;
        height: 36px;
    }
    
    .header-search input:focus {
        width: 100%; /* Maintain width */
    }

    /* 4. Right Section (Login/User) */
    .header-right {
        gap: 8px;
    }

    /* Hide Listen Button on Mobile (Space is tight, use bottom nav) */
    .listen-btn {
        display: none;
    }

    /* Adjust Login Button */
    .login-btn {
        padding: 4px 8px;
        font-size: 13px;
    }
    
    .user-avatar img {
        width: 32px;
        height: 32px;
    }
}
