<template>
  <header class="header">
    <!-- 骨架屏加载状态 -->
    <div v-if="isLoading" class="header-skeleton">
      <div class="header-container">
        <!-- logo图片骨架屏-->
        <div class="logo-skeleton">
          <el-skeleton-item variant="image" style="width: 120px; height: 40px; border-radius: 4px;" />
        </div>

        <!-- 导航栏骨架屏 -->
        <nav class="nav-links-skeleton" aria-label="导航菜单加载中">
          <div class="nav-item-skeleton" v-for="i in 7" :key="i">
            <el-skeleton-item variant="text" style="width: 60px; height: 16px;" />
          </div>
        </nav>

        <!-- 搜索栏骨架屏 -->
        <div class="search-section-skeleton">
          <div class="search-container-skeleton">
            <el-skeleton-item variant="text" style="width: 60px; height: 20px; margin-right: 10px;" />
            <el-skeleton-item variant="text" style="flex: 1; height: 20px;" />
            <el-skeleton-item variant="circle" style="width: 20px; height: 20px;" />
          </div>
        </div>

        <!-- 用户操作骨架屏 -->
        <div class="user-actions-skeleton">
          <el-skeleton-item variant="text" style="width: 40px; height: 16px;" />
          <el-skeleton-item variant="button" style="width: 60px; height: 32px; border-radius: 4px;" />
        </div>
      </div>
    </div>

    <!-- 正常Header内容 -->
    <div v-else class="header-container">
      <!-- Logo 区域 -->
      <div class="logo-section">
        <div class="logo">
          <img src="../assets/header/logo.gif" alt="logo" class="logo-img">
        </div>

        <!-- Mobile Menu Button -->
        <button 
          class="mobile-menu-button" 
          @click="toggleMobileMenu"
          :class="{ 'active': mobileMenuVisible }"
          :aria-label="mobileMenuVisible ? '关闭菜单' : '打开菜单'"
          :aria-expanded="mobileMenuVisible"
          aria-controls="mobile-navigation"
        >
          <span class="hamburger-line"></span>
          <span class="hamburger-line"></span>
          <span class="hamburger-line"></span>
        </button>
      </div>

      <!-- 中间区域：导航 + 搜索 -->
      <div class="center-section">
        <!-- 导航栏 -->
        <nav 
          class="nav-links" 
          :class="{ 'mobile-menu-open': mobileMenuVisible }"
          id="mobile-navigation"
          role="navigation"
          aria-label="主导航菜单"
          :aria-hidden="!mobileMenuVisible"
        >
          <div class="mobile-nav-overlay" @click="closeMobileMenu"></div>
          <div class="nav-container">
            <!-- Mobile Close Button -->
            <button 
              class="mobile-close-button" 
              @click="closeMobileMenu"
              aria-label="关闭菜单"
              type="button"
            >
              <el-icon><Close /></el-icon>
            </button>
            
            <router-link 
              to="/" 
              class="nav-link" 
              :class="{ 'selected': activeNav === 'home' }"
              @click="handleNavClick('home')"
            >
              首页
              <img v-if="activeNav === 'home'" src="../assets/header/selected icon.png" alt="选中icon" class="selected-icon" />
            </router-link>
            <router-link 
              to="/ai-application" 
              class="nav-link" 
              :class="{ 'selected': activeNav === 'aiApplication' }"
              @click="handleNavClick('aiApplication')"
            >
              Sora2视频
              <img src="../assets/header/hot-13 1.svg" alt="hot" class="hot-icon" />
              <img v-if="activeNav === 'aiApplication'" src="../assets/header/selected icon.png" alt="选中icon" class="selected-icon" />
            </router-link>
            <router-link 
              to="/workflow" 
              class="nav-link" 
              :class="{ 'selected': activeNav === 'workflow' }"
              @click="handleNavClick('workflow')"
            >
              工作流复制
              <img v-if="activeNav === 'workflow'" src="../assets/header/selected icon.png" alt="选中icon" class="selected-icon" />
            </router-link>
            <router-link 
              to="/school" 
              class="nav-link nav-18xtang" 
              :class="{ 'selected': activeNav === 'school' }"
              @click="handleNavClick('school')"
            >
              18学堂
              <img v-if="activeNav === 'school'" src="../assets/header/selected icon.png" alt="选中icon" class="selected-icon" />
            </router-link>
            <router-link 
              to="/download" 
              class="nav-link" 
              :class="{ 'selected': activeNav === 'download' }"
              @click="handleNavClick('download')"
            >
              下载
              <img v-if="activeNav === 'download'" src="../assets/header/selected icon.png" alt="选中icon" class="selected-icon" />
            </router-link>
            <a 
              href="#" 
              class="nav-link" 
              :class="{ 'selected': activeNav === 'promotion' }"
              @click.prevent="handlePromotionClick"
            >
              拉新推广
              <img v-if="activeNav === 'promotion'" src="../assets/header/selected icon.png" alt="选中icon" class="selected-icon" />
            </a>
            <router-link 
              to="/membership" 
              class="nav-link hot-link" 
              :class="{ 'selected': activeNav === 'membership' }"
              @click="handleNavClick('membership')"
            >
              购买会员
              <img src="../assets/header/hot-13 1.svg" alt="hot" class="hot-icon" />
              <img v-if="activeNav === 'membership'" src="../assets/header/selected icon.png" alt="选中icon" class="selected-icon" />
            </router-link>
          </div>
        </nav>

        <!-- Search Bar with Dropdown -->
        <div class="search-section" :class="{ 'mobile-hidden': mobileMenuVisible }">
          <div class="search-container">
            <el-dropdown 
              trigger="click" 
              @command="selectSearchType"
              class="search-dropdown-wrapper"
            >
              <div class="search-dropdown">
                <span class="dropdown-text">{{ selectedSearchType }}</span>
                <el-icon class="dropdown-arrow">
                  <ArrowDown />
                </el-icon>
              </div>
              <template #dropdown>
                <el-dropdown-menu class="custom-dropdown-menu">
                  <el-dropdown-item 
                    v-for="option in searchOptions" 
                    :key="option.value"
                    :command="option"
                    class="custom-dropdown-item"
                  >
                    {{ option.label }}
                  </el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
            
            <input 
              type="text" 
              class="search-input" 
              placeholder="请输入关键词搜索"
              v-model="searchKeyword"
              @keyup.enter="handleSearch"
            >
            <button class="search-button" @click="handleSearch">
              <el-icon class="search-icon">
                <Search />
              </el-icon>
            </button>
          </div>
        </div>
      </div>

      <!-- User Actions -->
      <div class="user-actions" :class="{ 'mobile-hidden': mobileMenuVisible }">
        <!-- 未登录状态 -->
        <template v-if="!isLoggedIn">
          <a href="#" class="login-link" @click.prevent="showLoginModal('login')">登录</a>
          <button class="register-button" @click="showLoginModal('register')">注册</button>
        </template>
        
        <!-- 已登录状态 -->
        <template v-else>
          <div class="user-profile">
            <el-popover
              placement="bottom-end"
              :width="240"
              trigger="hover"
              popper-class="user-dropdown-popper"
              :show-arrow="false"
            >
              <template #reference>
                <div class="user-avatar-container">
                  <!-- 头像加载失败时显示Element Plus图标 -->
                  <div v-if="avatarLoadFailed" class="user-avatar-icon">
                    <el-icon class="avatar-icon">
                      <User />
                    </el-icon>
                  </div>
                  <!-- 头像加载成功时显示图片 -->
                  <img 
                    v-else
                    :src="getAvatarUrl()"
                    :alt="getUserDisplayName() + '的头像'"
                    class="user-avatar"
                    @error="handleAvatarError"
                    @load="handleAvatarLoad"
                  />
                  <!-- VIP钻石图标 -->
                  <div class="vip-icon-container" v-if="getVipIcon()">
                    <img :src="getVipIcon()" :alt="getVipIconAlt()" class="vip-icon" />
                  </div>
                </div>
              </template>
              <UserDropdownMenu 
                :userInfo="userInfo"
                @subscribe="handleSubscribe"
                @use-points="handleUsePoints"
                @logout="handleLogout"
              />
            </el-popover>
          </div>
        </template>
      </div>
    </div>

    <!-- 登录弹窗 -->
    <LoginModal 
      :visible="loginModalVisible" 
      :mode="loginModalMode"
      @close="hideLoginModal"
      @login="handleLogin"
      @register="handleRegister"
      @forgot-password="handleForgotPassword"
    />
  </header>
</template>

<script>
import LoginModal from './LoginModal.vue'
import UserDropdownMenu from './UserDropdownMenu.vue'
import { useUserStore } from '../store'

import { User, Close } from '@element-plus/icons-vue'

export default {
  name: 'Header',
  components: {
    LoginModal,
    UserDropdownMenu,
    User,
    Close
  },
  data() {
    return {
      // 导航选中状态
      activeNav: 'school',
      // 搜索框相关
      searchOptions: [
        { label: '视频课', value: 'course' },
        { label: '工作流', value: 'workflow' }
      ],
      selectedSearchType: '工作流',
      selectedSearchTypeValue: 'workflow',
      searchKeyword: '',
      // 加载状态
      isLoading: false,
      // 登录弹窗状态
      loginModalVisible: false,
      loginModalMode: 'login',
      // 头像加载状态
      avatarLoadFailed: false,
      // 移动端菜单状态
      mobileMenuVisible: false
    }
  },
  computed: {
    // 从状态管理获取用户信息
    userStore() {
      return useUserStore()
    },
    // 是否已登录
    isLoggedIn() {
      return this.userStore.getIsLoggedIn
    },
    // 用户信息
    userInfo() {
      return this.userStore.getUserInfo
    }
  },
  methods: {
    // 设置选中的导航项
    setActiveNav(navName) {
      this.activeNav = navName;
    },
    // 选择搜索类型
    selectSearchType(option) {
      this.selectedSearchType = option.label;
      this.selectedSearchTypeValue = option.value;
    },
    // 模拟加载状态
    toggleLoading() {
      this.isLoading = !this.isLoading;
    },
    // 根据路由设置当前选中的导航
    setActiveNavByRoute() {
      const routeMap = {
        '/': 'home',
        '/ai-application': 'aiApplication',
        '/workflow': 'workflow',
        '/school': 'school',
        '/download': 'download',
        '/promotion': 'promotion',
        '/membership': 'membership'
      };
      
      // 检查是否在个人中心的推广拉新页面
      if (this.$route.path === '/personal-center/promotion') {
        this.activeNav = 'promotion';
      } else {
        this.activeNav = routeMap[this.$route.path] || 'home';
      }
    },
    // 显示登录弹窗
    showLoginModal(mode) {
      this.loginModalMode = mode;
      this.loginModalVisible = true;
    },
    // 隐藏登录弹窗
    hideLoginModal() {
      this.loginModalVisible = false;
    },
    // 处理登录
    handleLogin(userData) {
      console.log('登录成功:', userData);
      // 使用状态管理存储用户信息和token
      this.userStore.login(userData.userInfo, userData.token);
      this.hideLoginModal();
      // 可以在这里添加登录成功后的逻辑，比如重定向或显示欢迎消息
    },
    // 处理注册
    handleRegister(userData) {
      console.log('注册成功:', userData);
      // 使用状态管理存储用户信息和token
      this.userStore.login(userData.userInfo, userData.token);
      this.hideLoginModal();
      // 可以在这里添加注册成功后的逻辑
    },
    // 处理忘记密码
    handleForgotPassword() {
      console.log('忘记密码');
      // 这里可以添加忘记密码逻辑
    },
    // 处理头像加载错误
    handleAvatarError(event) {
      // 设置头像加载失败状态，显示Element Plus图标
      this.avatarLoadFailed = true;
      console.log('头像加载失败，使用Element Plus图标替代');
    },
    // 处理头像加载成功
    handleAvatarLoad(event) {
      console.log('头像加载成功:', event.target.src);
      // 重置头像加载失败状态
      this.avatarLoadFailed = false;
    },

    // 处理退出登录
    handleLogout() {
      try {
        // 调用状态管理的logout方法清空用户数据
        this.userStore.logout();
        
        // 清空localStorage中的其他相关数据
        localStorage.removeItem('user-store');
        
        // 清空sessionStorage中的相关数据
        sessionStorage.clear();
        
        // 清空可能存在的其他用户相关数据
        const keysToRemove = [];
        for (let i = 0; i < localStorage.length; i++) {
          const key = localStorage.key(i);
          if (key && (key.includes('user') || key.includes('token') || key.includes('auth'))) {
            keysToRemove.push(key);
          }
        }
        keysToRemove.forEach(key => localStorage.removeItem(key));
        
        console.log('退出登录成功，所有用户数据已清空');
        
        // 显示退出成功消息
        this.$message && this.$message.success('退出登录成功');
        
        // 跳转到首页
        this.$router.push('/');
        
      } catch (error) {
        console.error('退出登录时发生错误:', error);
        this.$message && this.$message.error('退出登录失败，请重试');
      }
    },
    
    // 处理订阅VIP
    handleSubscribe() {
      console.log('跳转到购买会员页面');
      this.$router.push('/membership');
    },
    
    // 处理使用积分
    handleUsePoints() {
      console.log('跳转到积分使用页面');
      // 这里可以添加跳转到积分使用页面的逻辑
    },
    

    // 获取用户显示名称
    getUserDisplayName() {
      if (!this.userInfo) return '用户';
      
      // 根据接口返回的数据结构，按优先级获取用户名称：username > phone
      return this.userInfo.username || 
             this.userInfo.phone || 
             '用户';
    },
    // 获取头像URL
    getAvatarUrl() {
      if (!this.userInfo || !this.userInfo.avatarUrl) {
        // 如果没有头像URL，直接设置加载失败状态
        this.avatarLoadFailed = true;
        return '';
      }
      return this.userInfo.avatarUrl;
    },
    // 获取VIP图标
    getVipIcon() {
      if (!this.userInfo || !this.userInfo.role) return null;
      
      // 根据用户角色返回对应的VIP图标
      switch (this.userInfo.role) {
        case 1: // 普通用户
          return new URL('../assets/User_Vip/no_vip.svg', import.meta.url).href;
        case 2: // VIP
          return new URL('../assets/User_Vip/vip.svg', import.meta.url).href;
        case 3: // SVIP
          return new URL('../assets/User_Vip/svip.svg', import.meta.url).href;
        default: // 普通用户或游客不显示VIP图标
          return null;
      }
    },
    // 获取VIP图标alt文本
    getVipIconAlt() {
      if (!this.userInfo || !this.userInfo.role) return '';
      
      switch (this.userInfo.role) {
        case 2:
          return 'VIP用户';
        case 3:
          return 'SVIP用户';
        default:
          return '';
      }
    },
    // 检查用户是否是VIP
    isVipUser() {
      return this.userInfo && this.userInfo.role && (this.userInfo.role === 2 || this.userInfo.role === 3);
    },
    // 检查用户是否是SVIP
    isSvipUser() {
      return this.userInfo && this.userInfo.role && this.userInfo.role === 3;
    },
    
    // 移动端菜单切换
    toggleMobileMenu() {
      this.mobileMenuVisible = !this.mobileMenuVisible;
      // 控制body滚动
      if (this.mobileMenuVisible) {
        document.body.style.overflow = 'hidden';
      } else {
        document.body.style.overflow = '';
      }
    },
    
    // 关闭移动端菜单
    closeMobileMenu() {
      this.mobileMenuVisible = false;
      document.body.style.overflow = '';
    },
    
    // 处理导航点击（合并原有功能和移动端菜单关闭）
    handleNavClick(navName) {
      this.setActiveNav(navName);
      this.closeMobileMenu();
    },
    
    // 处理搜索
    handleSearch() {
      if (this.searchKeyword.trim()) {
        console.log('搜索关键词:', this.searchKeyword);
        console.log('搜索类型:', this.selectedSearchType);
        
        // 构建搜索参数
        const searchParams = {
          keyword: this.searchKeyword.trim(),
          type: this.selectedSearchTypeValue || 'course'  // 总是传递type参数，默认为course
        };
        
        // 跳转到搜索页面
        this.$router.push({
          path: '/search',
          query: searchParams
        });
        
        // 清空搜索框（可选）
        // this.searchKeyword = '';
      }
    },
    
    // 处理推广拉新点击
    handlePromotionClick() {
      // 先关闭移动端菜单（如果开着的话）
      this.closeMobileMenu();
      
      // 检查用户是否已登录
      if (this.isLoggedIn) {
        // 已登录，跳转到个人中心的推广拉新页面
        this.setActiveNav('promotion');
        this.$router.push('/personal-center/promotion');
      } else {
        // 未登录，显示登录弹窗并提示
        this.$message && this.$message.warning('请先登录注册才能进行推广拉新');
        this.showLoginModal('login');
      }
    }
  },
  mounted() {
    // 组件挂载后根据当前路由设置选中状态
    this.setActiveNavByRoute();
    
    // 监听窗口大小变化，在大屏幕时自动关闭移动端菜单
    this.handleResize = () => {
      if (window.innerWidth > 1500 && this.mobileMenuVisible) {
        this.closeMobileMenu();
      }
    };
    window.addEventListener('resize', this.handleResize);
    
    // 监听ESC键关闭移动端菜单
    this.handleKeyDown = (event) => {
      if (event.key === 'Escape' && this.mobileMenuVisible) {
        this.closeMobileMenu();
      }
    };
    window.addEventListener('keydown', this.handleKeyDown);
  },
  
  beforeUnmount() {
    // 清理事件监听器
    if (this.handleResize) {
      window.removeEventListener('resize', this.handleResize);
    }
    if (this.handleKeyDown) {
      window.removeEventListener('keydown', this.handleKeyDown);
    }
    // 确保组件卸载时恢复body滚动
    document.body.style.overflow = '';
  },
  watch: {
    // 监听路由变化
    '$route'(to, from) {
      this.setActiveNavByRoute();
    }
  }
}
</script>

<style scoped>
.header {
  height: 60px;
  width: 100vw;
  background-color: #ffffff;
  border-bottom: 1px solid #e8e8e8;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1001; /* 提高层级，确保在RightBar之上 */
  display: block;
  clear: both;
  min-width: 320px; /* 确保最小宽度 */
}

.header-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between; /* 三部分分布：logo, 导航+搜索, 用户操作 */
  padding: 0 2vw; /* 响应式边距，大屏幕自动增加 */
  box-sizing: border-box;
  min-width: 320px; /* 确保容器最小宽度 */
  overflow: hidden; /* 防止内容溢出 */
  gap: 20px; /* 增加元素间距 */
  /* 移除最大宽度限制，让内容占满屏幕 */
}

/* Logo Section - 左侧区域 */
.logo-section {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-shrink: 0; /* 不允许缩小 */
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  width: 150px;
  height: 50px;
  flex-shrink: 0; /* 不允许缩小 */
}

/* Center Section - 中间区域 */
.center-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(30px, 5vw, 80px); /* 响应式间距 */
  flex: 1; /* 占据剩余空间 */
  max-width: none; /* 移除最大宽度限制 */
}

.logo-img {
  height: 100%;
  object-fit: contain;
}

/* Mobile Menu Button */
.mobile-menu-button {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  gap: 4px;
  transition: all 0.3s ease;
}

.hamburger-line {
  width: 20px;
  height: 2px;
  background-color: #333333;
  transition: all 0.3s ease;
  transform-origin: center;
}

.mobile-menu-button.active .hamburger-line:nth-child(1) {
  transform: rotate(45deg) translateY(6px);
}

.mobile-menu-button.active .hamburger-line:nth-child(2) {
  opacity: 0;
}

.mobile-menu-button.active .hamburger-line:nth-child(3) {
  transform: rotate(-45deg) translateY(-6px);
}

/* Navigation Links */
.nav-links {
  display: flex;
  align-items: center;
  gap: clamp(25px, 3vw, 50px); /* 响应式间距 */
  flex-shrink: 1; /* 允许适度收缩 */
  min-width: 0; /* 允许完全收缩 */
}

.nav-container {
  display: flex;
  align-items: center;
  gap: clamp(25px, 3vw, 50px); /* 与nav-links保持一致的响应式间距 */
}

.mobile-nav-overlay {
  display: none;
}

.mobile-close-button {
  display: none;
}

.nav-link {
  text-decoration: none;
  color: #333333;
  font-size: clamp(12px, 1vw, 14px); /* 响应式字体大小 */
  font-weight: 500;
  transition: color 0.3s ease;
  position: relative;
  width: 100px;
  height: 60px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap; /* 防止文字换行 */
}

.nav-link:hover {
  color: #121213;
}

.nav-link.selected {
  color: #181818;
  font-weight: 600;
}

.hot-link {
  position: relative;
}

.hot-icon {
  position: absolute;
  top: 10px;
  left: 85px;
  width: 26px;
  height: 16.55px;
  padding: 0px;
  mix-blend-mode: multiply;
}

.selected-icon {
  width: 18px;
  height: 8px;
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  margin-bottom: 4px;
}

/* Search Section with improvements */
.search-section {
  display: flex;
  justify-content: center;
  position: relative; /* 为下拉框提供定位上下文 */
  min-width: 200px; /* 设置最小宽度，空间不足时会被隐藏 */
  max-width: clamp(300px, 25vw, 500px); /* 响应式最大宽度 */
  flex-shrink: 1; /* 允许收缩 */
}

.search-container {
  display: flex;
  align-items: center;
  background-color: #ffffff;
  border: 1px solid #d9d9d9;
  border-radius: 12px; /* 更大的圆角 */
  height: 40px;
  width: 100%;
  min-width: 200px; /* 确保最小宽度 */
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); /* 更柔和的阴影 */
  transition: all 0.3s ease;
}

.search-container:focus-within {
  border-color: #0f0f0f; /* 获得焦点时改变边框颜色 */
  box-shadow: 0 0 0 3px rgba(15, 15, 15, 0.1); /* 焦点光晕效果 */
  transform: translateY(-1px);
}

.search-dropdown-wrapper {
  height: 100%;
  width: 88px; /* 设置固定宽度，避免Element Plus默认宽度过大 */
  min-width: 60px;
  max-width: 100px;
  flex: 0 0 auto; /* 不伸缩，保持固定比例 */
}

.search-dropdown {
  display: flex;
  align-items: center;
  gap: 4px; /* 减少内部间距 */
  padding: 0 10px; /* 减少左右padding */
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-right: 1px solid #e0e0e0;
  height: 100%;
  width: 100%; /* 继承包装器宽度 */
  cursor: pointer;
  transition: all 0.3s ease;
  z-index: 10; /* 确保下拉按钮在选项上方 */
}

.search-dropdown:hover {
  background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
}

.dropdown-text {
  font-size: clamp(11px, 0.9vw, 12px); /* 响应式字体大小 */
  color: #495057;
  font-weight: 500;
  white-space: nowrap; /* 防止文字换行 */
  overflow: hidden; /* 隐藏溢出内容 */
  text-overflow: ellipsis; /* 显示省略号 */
  max-width: 60px; /* 限制最大宽度 */
}

.dropdown-arrow {
  font-size: 12px;
  color: #6c757d;
  transition: transform 0.3s ease;
}

/* Element Plus Dropdown Custom Styles */
:deep(.custom-dropdown-menu) {
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
  border: 1px solid #e0e0e0;
  padding: 0;
  margin-top: 5px;
}

:deep(.custom-dropdown-item) {
  padding: 12px 18px;
  font-size: clamp(12px, 1vw, 14px);
  color: #333333;
  transition: all 0.2s ease;
  border-bottom: 1px solid #f8f9fa;
  background-color: transparent;
}

:deep(.custom-dropdown-item:last-child) {
  border-bottom: none;
}

:deep(.custom-dropdown-item:hover) {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  color: #131313;
  padding-left: 22px;
}

:deep(.custom-dropdown-item.is-disabled) {
  background-color: transparent;
  color: #333333;
}

.search-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 0 16px;
  font-size: clamp(12px, 1vw, 14px); /* 响应式字体大小 */
  color: #333333;
  background-color: transparent;
  min-width: 120px; /* 确保输入框有最小宽度 */
}

.search-input::placeholder {
  color: #adb5bd;
  font-style: italic;
}

.search-button {
  width: 40px;
  height: 40px;
  border: none;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.search-button:hover {
  background: linear-gradient(135deg, #0f0f0f 0%, #1a1a1a 100%);
  transform: scale(1.05);
}

.search-button:hover .search-icon {
  color: #ffffff;
}

.search-icon {
  font-size: 16px;
  color: #6c757d;
  transition: all 0.3s ease;
}

/* Mobile Hidden Elements */
.mobile-hidden {
  transition: opacity 0.3s ease;
}

/* User Actions */
.user-actions {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-shrink: 0; /* 防止用户操作区域被压缩 */
  min-width: fit-content; /* 确保内容完全可见 */
  overflow: visible; /* 确保内容不被截断 */
  white-space: nowrap; /* 防止内容换行 */
}

/* 用户头像和信息样式 */
.user-profile {
  display: inline-block;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}

.user-profile:hover {
  transform: translateY(-1px);
}

.user-avatar-container {
  position: relative;
  width: 40px;
  height: 40px;
  cursor: pointer;
  margin: 0 20px 0 10px; /* 减少右边距，确保不会被截断 */
  display: inline-block;
  flex-shrink: 0; /* 防止头像被压缩 */
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #ffffff;
  transition: all 0.3s ease;
  display: block;
}

.user-avatar:hover {
  border-color: #000000;
  transform: scale(1.05);
}

.user-avatar-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #f5f5f5;
  border: 2px solid #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.user-avatar-icon:hover {
  border-color: #000000;
  transform: scale(1.05);
  background-color: #e8e8e8;
}

.avatar-icon {
  font-size: 20px;
  color: #999999;
}

.vip-icon-container {
  position: absolute;
  bottom: -8px;
  right: -8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
}

.vip-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  transition: transform 0.3s ease;
}

.vip-icon:hover {
  transform: scale(1.1);
}

.user-dropdown {
  display: flex;
  align-items: center;
}



.login-link {
  text-decoration: none;
  color: #333333;
  font-size: clamp(12px, 1vw, 14px); /* 响应式字体大小 */
  font-weight: 500;
  transition: color 0.3s ease;
}

.login-link:hover {
  color: #0a0a0a;
}

.register-button {
  background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
  color: #ffffff;
  border: none;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: clamp(12px, 1vw, 14px); /* 响应式字体大小 */
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.register-button:hover {
  background: linear-gradient(135deg, #0d0d0e 0%, #2a2a2a 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

/* 18学堂样式 */
.nav-18xtang {
  color: rgba(51,51,51,1);
  font-family: Arial, sans-serif;
  line-height: 16px;
  letter-spacing: 0px;
  text-align: center;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

/* 骨架屏样式 */
.header-skeleton {
  height: 60px;
  width: 100vw;
  background-color: #ffffff;
  border-bottom: 1px solid #e8e8e8;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1001; /* 与主Header保持一致的层级 */
}

.logo-skeleton {
  display: flex;
  align-items: center;
  width: 150px;
  height: 50px;
}

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

.nav-item-skeleton {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100px;
  height: 60px;
}

.search-section-skeleton {
  flex: 1;
  display: flex;
  justify-content: center;
  margin: 0 40px;
}

.search-container-skeleton {
  display: flex;
  align-items: center;
  background-color: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 12px;
  height: 40px;
  width: 400px;
  padding: 0 16px;
  gap: 10px;
}

.user-actions-skeleton {
  display: flex;
  align-items: center;
  gap: 20px;
}

/* PC端大屏幕优化 - 居中布局 */
@media (min-width: 1501px) {
  .header-container {
    padding: 0 clamp(20px, 3vw, 80px); /* 优化响应式边距，减少最大值 */
    gap: clamp(15px, 2vw, 40px); /* 优化响应式间距，减少最大值 */
    overflow: visible; /* 确保内容可见 */
  }
  
  .center-section {
    gap: clamp(40px, 6vw, 80px); /* 减少导航和搜索间距的最大值 */
    flex: 1; /* 确保中间区域能够伸缩 */
    min-width: 0; /* 允许收缩 */
  }
  
  .nav-links {
    gap: clamp(25px, 3vw, 50px); /* 减少导航项间距的最大值 */
    flex-shrink: 1; /* 允许适度收缩 */
  }
  
  .nav-container {
    gap: clamp(25px, 3vw, 50px); /* 与nav-links保持一致 */
  }
  
  .search-section {
    max-width: clamp(350px, 25vw, 500px); /* 减少搜索框最大宽度 */
    min-width: 300px; /* 确保搜索框最小宽度 */
    flex-shrink: 1; /* 允许适度收缩 */
  }
  
  /* 优化用户操作区域 - 关键修复 */
  .user-actions {
    gap: clamp(12px, 1.5vw, 25px); /* 减少用户操作内部元素间距 */
    flex-shrink: 1; /* 允许适度收缩 - 关键修复 */
    min-width: 120px; /* 设置最小宽度确保按钮可见 */
    max-width: none; /* 移除最大宽度限制 */
    overflow: visible; /* 确保内容可见 */
  }
  
  /* 优化登录注册按钮 */
  .login-link {
    font-size: clamp(12px, 1vw, 14px);
    white-space: nowrap; /* 防止文字换行 */
  }
  
  .register-button {
    font-size: clamp(12px, 1vw, 14px);
    padding: clamp(8px, 1vw, 12px) clamp(16px, 2vw, 24px);
    white-space: nowrap; /* 防止文字换行 */
    flex-shrink: 0; /* 注册按钮不收缩，保持可点击 */
  }
  
  /* 优化导航项尺寸 */
  .nav-link {
    width: clamp(85px, 7vw, 110px); /* 减少导航项最大宽度 */
    font-size: clamp(12px, 1.1vw, 15px); /* 减少字体最大值 */
  }
  
  /* 头像容器优化 */
  .user-avatar-container {
    margin: 0 15px 0 8px; /* 优化头像边距 */
    flex-shrink: 0; /* 头像不收缩 */
  }
}

/* Responsive adjustments - 优化桌面端布局，缩小元素边距 */

/* 大屏幕 - 开始等比缩小导航栏元素边距 */
@media (max-width: 1600px) {
  .header-container {
    padding: 0 35px 0 45px;
    gap: 14px;
  }
  
  .nav-links {
    gap: 35px;
    margin-left: 50px;
  }
  
  .nav-container {
    gap: 35px;
  }
  
  .nav-link {
    width: 98px; /* 轻微缩小导航项宽度 */
    font-size: clamp(12px, 0.98vw, 14px);
  }
  
  .search-section {
    max-width: 420px;
    min-width: 200px;
  }
}

/* 中等屏幕 - 进一步缩小边距 */
@media (max-width: 1400px) {
  .header-container {
    padding: 0 30px 0 40px;
    gap: 12px;
  }
  
  .nav-links {
    gap: 25px;
    margin-left: 40px;
  }
  
  .nav-container {
    gap: 25px;
  }
  
  .nav-link {
    width: 95px; /* 稍微缩小导航项宽度 */
    font-size: clamp(11px, 0.95vw, 13px);
  }
  
  .search-section {
    max-width: 380px;
    min-width: 180px;
  }
}

/* 小屏幕 - 继续缩小边距 */
@media (max-width: 1200px) {
  .header-container {
    padding: 0 25px 0 35px;
    gap: 10px;
  }
  
  .nav-links {
    gap: 20px;
    margin-left: 30px;
  }
  
  .nav-container {
    gap: 20px;
  }
  
  .nav-link {
    width: 90px; /* 稍微缩小导航项宽度 */
    font-size: clamp(11px, 0.9vw, 13px);
  }
  
  .search-section {
    max-width: 320px;
    min-width: 160px;
  }
  
  .search-container {
    max-width: 300px;
    min-width: 180px;
  }
  
  .search-dropdown-wrapper {
    width: 75px;
  }
  
  .search-dropdown {
    width: 100%;
    padding: 0 8px;
  }
  
  .dropdown-text {
    max-width: 40px;
    font-size: clamp(10px, 0.9vw, 11px);
  }
  
  .search-input {
    min-width: 80px;
  }
  
  .user-actions {
    gap: 10px;
  }
  
  .user-avatar-container {
    margin: 0 10px 0 5px;
  }
}

/* 1500px以下切换到移动端导航布局 */
@media (max-width: 1500px) {
  .header-container {
    padding: 0 20px 0 30px;
    gap: 15px;
    justify-content: space-between; /* 使用space-between确保元素分布 */
  }
  
  .nav-links {
    position: fixed;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); /* 更流畅的过渡动画 */
    margin-left: 0;
    gap: 0;
    display: flex; /* 显示但位置在屏幕外 */
    backdrop-filter: blur(10px); /* 添加背景模糊效果 */
  }
  
  .nav-links.mobile-menu-open {
    left: 0;
    background-color: rgba(0, 0, 0, 0.98); /* 打开时背景更不透明 */
  }
  
  .mobile-nav-overlay {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3); /* 添加半透明背景 */
    z-index: 1;
    backdrop-filter: blur(2px); /* 添加背景模糊效果 */
  }
  
  .nav-container {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    gap: 30px;
    z-index: 2;
    padding: 60px 20px;
    background: rgba(0, 0, 0, 0.95); /* 确保导航容器有背景 */
    border-radius: 0; /* 移除圆角，保持全屏 */
    width: 100%; /* 确保容器占满全宽 */
    box-sizing: border-box; /* 确保padding不会影响总宽度 */
  }
  
  .mobile-close-button {
    display: flex;
    position: absolute;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    color: #ffffff;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 22px;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px); /* 添加背景模糊 */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); /* 添加阴影 */
  }
  
  .mobile-close-button:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
    transform: scale(1.05); /* 悬停时轻微放大 */
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3); /* 悬停时增强阴影 */
  }
  
  .mobile-close-button:active {
    transform: scale(0.95); /* 点击时轻微缩小 */
  }
  
  .nav-link {
    width: 240px; /* 固定宽度，确保所有卡片大小一致 */
    height: 56px; /* 固定高度，确保所有卡片大小一致 */
    padding: 0 20px; /* 调整内边距，因为已经固定了宽高 */
    color: #ffffff;
    font-size: 18px;
    font-weight: 500;
    border-radius: 12px; /* 稍微增加圆角 */
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    text-align: center;
    position: relative; /* 确保定位正确 */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px; /* 图标和文字之间的间距 */
    box-sizing: border-box; /* 确保padding不会影响总宽度 */
  }
  
  .nav-link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.1); /* 添加悬停阴影 */
  }
  
  .nav-link.selected {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 4px 16px rgba(255, 255, 255, 0.2); /* 选中状态阴影 */
  }
  
  /* 确保所有导航链接都有统一的焦点状态 */
  .nav-link:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
  }
  
  /* 添加点击状态的视觉反馈 */
  .nav-link:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(255, 255, 255, 0.1);
  }
  
  .selected-icon {
    position: static;
    margin-left: 8px;
    transform: none;
    margin-bottom: 0;
    width: 16px; /* 统一图标尺寸 */
    height: 8px;
    opacity: 0.9; /* 稍微调整透明度 */
  }
  
  .hot-icon {
    position: static;
    margin-left: 8px;
    top: auto;
    left: auto;
    width: 20px; /* 统一图标尺寸 */
    height: 14px;
    opacity: 0.9; /* 稍微调整透明度 */
  }
  
  .mobile-menu-button {
    display: flex; /* 显示移动菜单按钮 */
  }
  
  .center-section {
    justify-content: flex-end; /* 搜索框右对齐 */
    gap: 15px;
  }
  
  /* 导航栏在移动端的显示控制已在其他规则中定义 */
  
  .search-section {
    max-width: 400px;
    min-width: 200px;
    justify-content: flex-end; /* 内容右对齐 */
  }
  
  .user-actions {
    gap: 15px;
  }
  
  .search-container {
    max-width: 350px;
    min-width: 200px;
    margin-left: auto; /* 搜索框容器右对齐 */
  }
  
  .search-dropdown-wrapper {
    width: 88px;
  }
  
  .search-dropdown {
    padding: 0 10px;
  }
  
  .dropdown-text {
    max-width: 50px;
    font-size: clamp(11px, 1vw, 12px);
  }
  
  .search-input {
    min-width: 120px;
    padding: 0 12px;
  }
  
  .user-avatar-container {
    margin: 0 15px 0 8px;
  }
  
  /* Hide search and user actions on mobile when menu is open */
  .mobile-hidden {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease; /* 添加淡出动画 */
  }
  
  /* 移动端菜单打开时的body滚动控制 */
  .mobile-menu-open {
    overflow: hidden;
  }
  
  /* 确保移动端菜单在所有设备上都有统一的样式 */
  @media (max-width: 1500px) and (max-height: 600px) {
    .nav-container {
      padding: 40px 20px; /* 小屏幕设备减少上下padding */
      gap: 20px; /* 减少导航项间距 */
    }
    
    .nav-link {
      width: 220px; /* 小屏幕设备稍微减小宽度 */
      height: 52px; /* 小屏幕设备稍微减小高度 */
      padding: 0 18px; /* 调整内边距 */
      font-size: 16px; /* 稍微减小字体 */
    }
  }
  
  /* 超小屏幕设备的额外优化 */
  @media (max-width: 1500px) and (max-width: 480px) {
    .nav-link {
      width: 200px; /* 超小屏幕设备进一步减小宽度 */
      height: 48px; /* 超小屏幕设备进一步减小高度 */
      padding: 0 16px; /* 调整内边距 */
      font-size: 15px; /* 进一步减小字体 */
    }
    
    .nav-container {
      gap: 16px; /* 减少导航项间距 */
    }
  }
}

/* 中等移动端屏幕优化 */
@media (max-width: 1200px) {
  .header-container {
    padding: 0 18px 0 25px;
    gap: 12px;
  }
  
  .search-section {
    max-width: 320px;
    min-width: 180px;
  }
  
  .search-container {
    max-width: 300px;
    min-width: 180px;
  }
  
  .search-dropdown-wrapper {
    width: 75px;
  }
  
  .search-dropdown {
    padding: 0 8px;
  }
  
  .dropdown-text {
    max-width: 45px;
    font-size: clamp(10px, 0.9vw, 11px);
  }
  
  .search-input {
    min-width: 100px;
    padding: 0 10px;
  }
  
  .user-actions {
    gap: 12px;
  }
  
  .user-avatar-container {
    margin: 0 12px 0 6px;
  }
}

/* 平板移动端优化 */
@media (max-width: 900px) {
  .header-container {
    padding: 0 15px 0 20px;
    gap: 10px;
    justify-content: space-between; /* 确保元素分布 */
  }
  
  .logo {
    width: 120px;
    height: 40px;
  }
  
  .search-section {
    max-width: 250px;
    min-width: 150px;
    margin-left: auto; /* 推送到右边 */
    justify-content: flex-end;
  }
  
  .search-container {
    max-width: 230px;
    min-width: 150px;
    margin-left: auto; /* 搜索框容器右对齐 */
  }
  
  .search-dropdown-wrapper {
    width: 65px;
  }
  
  .search-dropdown {
    padding: 0 6px;
  }
  
  .dropdown-text {
    max-width: 35px;
    font-size: clamp(9px, 0.8vw, 10px);
  }
  
  .search-input {
    min-width: 80px;
    padding: 0 8px;
  }
  
  .user-actions {
    gap: 10px;
    margin-left: auto; /* 确保右对齐 */
  }
  
  .user-avatar-container {
    width: 36px;
    height: 36px;
    margin: 0 10px 0 5px;
  }
  
  .user-avatar,
  .user-avatar-icon {
    width: 36px;
    height: 36px;
  }
}

/* 标准移动端 */
@media (max-width: 768px) {
  .header-container {
    padding: 0 12px 0 15px;
    gap: 8px;
    justify-content: space-between; /* 确保元素分布 */
  }
  
  .logo {
    width: 110px;
    height: 36px;
  }
  
  /* 768px断点只需要调整具体尺寸，移动端菜单样式已在1500px断点定义 */
  
  .search-section {
    max-width: 180px;
    min-width: 120px;
    margin-left: auto; /* 推送到右边 */
    justify-content: flex-end;
  }
  
  .search-container {
    max-width: 170px;
    min-width: 120px;
    margin-left: auto; /* 搜索框容器右对齐 */
  }
  
  .search-dropdown-wrapper {
    width: 50px;
  }
  
  .search-dropdown {
    padding: 0 4px;
  }
  
  .dropdown-text {
    max-width: 30px;
    font-size: clamp(8px, 0.7vw, 9px);
  }
  
  .search-input {
    min-width: 60px;
    padding: 0 6px;
    font-size: 12px;
  }
  
  .user-actions {
    gap: 8px;
    margin-left: auto; /* 确保右对齐 */
  }
  
  .user-avatar-container {
    width: 34px;
    height: 34px;
    margin: 0 8px 0 4px;
  }
  
  .user-avatar,
  .user-avatar-icon {
    width: 34px;
    height: 34px;
  }
}

/* 500px以下屏幕 - 搜索区域下移独占一行 */
@media (max-width: 500px) {
  .header {
    height: auto !important; /* 强制允许header高度自适应 */
    min-height: 60px !important; /* 强制保持最小高度 */
    overflow: visible !important; /* 强制允许内容溢出，避免被截断 */
    position: fixed !important; /* 强制保持固定定位 */
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 1001 !important; /* 提高层级，确保在RightBar之上 */
  }
  
  .header-container {
    padding: 0 10px 0 12px !important;
    gap: 6px !important;
    padding-top: 8px !important; /* 强制顶部留出空间 */
    padding-bottom: 8px !important; /* 强制底部留出空间 */
    height: auto !important; /* 强制容器高度自适应 */
    min-height: 60px !important; /* 强制保持最小高度 */
    position: relative !important; /* 强制为绝对定位的子元素提供定位上下文 */
    display: grid !important; /* 强制使用grid布局 */
    grid-template-areas: 
      "logo-section user-actions"
      "center-section center-section";
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    align-items: center !important;
    grid-gap: 6px 0 !important; /* 设置行间距 */
  }
  
  .logo-section {
    grid-area: logo-section !important; /* 强制使用grid布局 */
    display: flex !important;
    align-items: center !important;
    justify-self: start !important; /* 强制左对齐 */
  }
  
  .logo {
    width: 100px !important;
    height: 32px !important;
  }
  
  .mobile-menu-button {
    margin-left: 8px !important; /* 强制与logo保持适当距离 */
    display: flex !important; /* 强制确保按钮显示 */
  }
  
  .center-section {
    grid-area: center-section !important; /* 强制独占第二行 */
    width: 100% !important; /* 强制占满整行 */
    justify-content: center !important; /* 强制居中显示 */
    gap: 0 !important; /* 移除间距 */
  }
  
  .nav-links {
    display: none !important; /* 强制隐藏导航栏 */
  }
  
  /* 修复：移动端菜单打开时强制显示 */
  .nav-links.mobile-menu-open {
    display: flex !important; /* 强制显示移动端菜单 */
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100vh !important;
    background-color: rgba(0, 0, 0, 0.98) !important;
    z-index: 9999 !important;
    backdrop-filter: blur(10px) !important;
  }
  
  .search-section {
    width: 100% !important; /* 强制占满整行 */
    max-width: none !important;
    min-width: 0 !important;
    justify-content: center !important; /* 强制居中显示 */
    display: flex !important; /* 强制确保搜索区域显示 */
  }
  
  .search-container {
    width: 100% !important; /* 强制占满整行 */
    max-width: none !important;
    min-width: 0 !important;
    margin: 0 !important; /* 强制重置margin */
    height: 40px !important; /* 强制固定搜索框高度 */
    display: flex !important; /* 强制确保搜索容器显示 */
    justify-content: center !important; /* 强制居中显示 */
  }
  
  .search-dropdown-wrapper {
    width: 80px !important; /* 强制增加下拉框宽度 */
    flex-shrink: 0 !important; /* 强制防止下拉框被压缩 */
  }
  
  .search-dropdown {
    padding: 0 8px !important;
  }
  
  .dropdown-text {
    max-width: 50px !important;
    font-size: 11px !important;
  }
  
  .search-input {
    min-width: 120px !important;
    padding: 0 8px !important;
    font-size: 12px !important;
    flex: 1 !important; /* 强制输入框占据剩余空间 */
  }
  
  .search-button {
    width: 40px !important;
    height: 40px !important;
    flex-shrink: 0 !important; /* 强制防止搜索按钮被压缩 */
  }
  
  .search-icon {
    font-size: 14px !important; /* 强制调整搜索图标大小 */
  }
  
  .user-actions {
    grid-area: user-actions !important; /* 强制使用grid布局 */
    gap: 6px !important;
    display: flex !important; /* 强制确保用户操作区域显示 */
    justify-self: end !important; /* 强制右对齐 */
  }
  
  .user-avatar-container {
    width: 30px !important;
    height: 30px !important;
    margin: 0 0 0 0 !important; /* 强制重置margin */
  }
  
  .user-avatar,
  .user-avatar-icon {
    width: 30px !important;
    height: 30px !important;
  }
  
  .vip-icon-container {
    width: 16px !important;
    height: 16px !important;
    right: -3px !important;
    bottom: -3px !important;
  }
  
  .login-link,
  .register-button {
    font-size: 12px !important;
  }
  
  .register-button {
    padding: 6px 10px !important;
  }
  
  /* 移动端导航栏已在通用规则中定义 */
  
  /* 强制确保移动端遮罩层显示 */
  .mobile-nav-overlay {
    display: block !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.3) !important;
    z-index: 1 !important;
    backdrop-filter: blur(2px) !important;
  }
  
  /* 强制确保移动端导航容器显示 */
  .nav-container {
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    height: 100% !important;
    gap: 30px !important;
    z-index: 2 !important;
    padding: 60px 20px !important;
    background: rgba(0, 0, 0, 0.95) !important;
    border-radius: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }
  
  /* 强制确保移动端关闭按钮显示 */
  .mobile-close-button {
    display: flex !important;
    position: absolute !important;
    top: 20px !important;
    right: 20px !important;
    width: 44px !important;
    height: 44px !important;
    background: rgba(255, 255, 255, 0.15) !important;
    border: 1px solid rgba(255, 255, 255, 0.25) !important;
    border-radius: 50% !important;
    color: #ffffff !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    font-size: 22px !important;
    transition: all 0.3s ease !important;
    backdrop-filter: blur(10px) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
  }
  
  /* 强制确保移动端导航链接显示 */
  .nav-link {
    width: 240px !important;
    height: 56px !important;
    padding: 0 20px !important;
    color: #ffffff !important;
    font-size: 18px !important;
    font-weight: 500 !important;
    border-radius: 12px !important;
    background: rgba(255, 255, 255, 0.1) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    transition: all 0.3s ease !important;
    text-align: center !important;
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    box-sizing: border-box !important;
    text-decoration: none !important;
  }
  
  /* 强制确保移动端导航链接悬停效果 */
  .nav-link:hover {
    color: #ffffff !important;
    background: rgba(255, 255, 255, 0.2) !important;
    border-color: rgba(255, 255, 255, 0.4) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.1) !important;
  }
  
  /* 强制确保移动端导航链接选中状态 */
  .nav-link.selected {
    color: #ffffff !important;
    background: rgba(255, 255, 255, 0.3) !important;
    border-color: rgba(255, 255, 255, 0.5) !important;
    box-shadow: 0 4px 16px rgba(255, 255, 255, 0.2) !important;
  }
  
  /* 移动端菜单按钮已在通用规则中定义 */
  
  /* 强制确保汉堡菜单线条显示 */
  .hamburger-line {
    width: 20px !important;
    height: 2px !important;
    background-color: #333333 !important;
    transition: all 0.3s ease !important;
    transform-origin: center !important;
  }
  
  /* 强制确保汉堡菜单激活状态 */
  .mobile-menu-button.active .hamburger-line:nth-child(1) {
    transform: rotate(45deg) translateY(6px) !important;
  }
  
  .mobile-menu-button.active .hamburger-line:nth-child(2) {
    opacity: 0 !important;
  }
  
  .mobile-menu-button.active .hamburger-line:nth-child(3) {
    transform: rotate(-45deg) translateY(-6px) !important;
  }
  
  /* 强制调整页面内容的上边距，避免被header遮挡 */
  .page-content {
    margin-top: 100px !important; /* 强制为两行header留出空间 */
  }
  
  /* 强制确保搜索区域在移动端正确显示 */
  .search-section.mobile-hidden {
    display: flex !important; /* 强制在500px以下强制显示搜索区域 */
    opacity: 1 !important;
    pointer-events: auto !important;
  }
  
  /* 强制确保用户操作区域在移动端正确显示 */
  .user-actions.mobile-hidden {
    display: flex !important; /* 强制在500px以下强制显示用户操作区域 */
    opacity: 1 !important;
    pointer-events: auto !important;
  }
  
  /* 强制确保移动端菜单打开时的body滚动控制 */
  .mobile-menu-open {
    overflow: hidden !important;
  }
  
  /* 移动端菜单z-index已在通用规则中定义 */
}

/* 小屏移动端 - 保持原有样式 */
@media (max-width: 480px) {
  .header {
    height: auto;
    min-height: 60px;
  }
  
  .header-container {
    padding: 0 8px 0 10px;
    gap: 4px;
  }
  
  .logo {
    width: 90px;
    height: 30px;
  }
  
  .mobile-menu-button {
    margin-left: 6px;
  }
  
  .search-section {
    margin: 6px 0 0 0;
  }
  
  .search-dropdown-wrapper {
    width: 70px;
  }
  
  .search-dropdown {
    padding: 0 6px;
  }
  
  .dropdown-text {
    max-width: 45px;
    font-size: 10px;
  }
  
  .search-input {
    min-width: 100px;
    padding: 0 6px;
    font-size: 11px;
  }
  
  .user-avatar-container {
    width: 28px;
    height: 28px;
  }
  
  .user-avatar,
  .user-avatar-icon {
    width: 28px;
    height: 28px;
  }
  
  .vip-icon-container {
    width: 14px;
    height: 14px;
    right: -2px;
    bottom: -2px;
  }
  
  .login-link,
  .register-button {
    font-size: 11px;
  }
  
  .register-button {
    padding: 5px 8px;
  }
}

/* 极小屏移动端 */
@media (max-width: 360px) {
  .header-container {
    padding: 0 8px 0 10px;
    gap: 4px;
    justify-content: space-between; /* 确保元素分布 */
  }
  
  .logo {
    width: 90px;
    height: 30px;
  }
  
  .search-section {
    max-width: 110px;
    min-width: 80px;
    margin-left: auto; /* 推送到右边 */
    justify-content: flex-end;
  }
  
  .search-container {
    max-width: 100px;
    min-width: 80px;
    margin-left: auto; /* 搜索框容器右对齐 */
  }
  
  .search-dropdown-wrapper {
    width: 32px;
  }
  
  .search-dropdown {
    padding: 0 2px;
  }
  
  .dropdown-text {
    max-width: 20px;
    font-size: 6px;
  }
  
  .search-input {
    min-width: 40px;
    padding: 0 3px;
    font-size: 10px;
  }
  
  .user-actions {
    gap: 4px;
    margin-left: auto; /* 确保右对齐 */
  }
  
  .user-avatar-container {
    width: 28px;
    height: 28px;
    margin: 0 4px 0 2px;
  }
  
  .user-avatar,
  .user-avatar-icon {
    width: 28px;
    height: 28px;
  }
  
  .vip-icon-container {
    width: 14px;
    height: 14px;
    right: -2px;
    bottom: -2px;
  }
  
  .login-link,
  .register-button {
    font-size: 11px;
  }
  
  .register-button {
    padding: 5px 8px;
  }
}

/* Element Plus Popover 样式覆盖 */
:global(.user-dropdown-popper) {
  padding: 0 !important;
  border: none !important;
  box-shadow: none !important;
  background: transparent !important;
}

:global(.user-dropdown-popper .el-popover) {
  padding: 0 !important;
  border: none !important;
  box-shadow: none !important;
  background: transparent !important;
}

:global(.user-dropdown-popper .el-button) {
  background-color: #f8f9fa !important;
  border: 1px solid #e9ecef !important;
  color: #666666 !important;
}

:global(.user-dropdown-popper .el-button:hover) {
  background-color: rgba(255, 71, 87, 0.1) !important;
  border-color: #ff4757 !important;
  color: #ff4757 !important;
}

/* VIP和积分按钮样式注入 */
:global(.user-dropdown-popper .vip-btn) {
  background-color: rgba(34, 34, 34, 1) !important;
  border-color: rgba(34, 34, 34, 1) !important;
  color: rgba(255, 224, 153, 1) !important;
  width: 40px !important;
  height: 16px !important;
  padding: 0 !important;
  font-family: Arial, sans-serif !important;
  font-weight: 400 !important;
  font-size: 10px !important;
  line-height: 11px !important;
  letter-spacing: 0px !important;
}

:global(.user-dropdown-popper .vip-btn:hover) {
  background-color: rgba(34, 34, 34, 1) !important;
  border-color: rgba(34, 34, 34, 1) !important;
  color: rgba(255, 224, 153, 1) !important;
}

:global(.user-dropdown-popper .points-btn) {
  background-color: transparent !important;
  border-color: rgba(168, 98, 43, 1) !important;
  color: rgba(168, 98, 43, 1) !important;
  width: 40px !important;
  height: 16px !important;
  padding: 0 !important;
  font-family: Arial, sans-serif !important;
  font-weight: 400 !important;
  font-size: 10px !important;
  line-height: 11px !important;
  letter-spacing: 0px !important;
}

:global(.user-dropdown-popper .points-btn:hover) {
  background-color: rgba(168, 98, 43, 0.1) !important;
  border-color: rgba(168, 98, 43, 1) !important;
  color: rgba(168, 98, 43, 1) !important;
}
</style>
