<!--学员知识库页面-->
<template>
	<view class="main_box">
		<!-- 自定义导航栏 -->
		<view class="navbar_section">
			<view class="navbar_back" @click="goBack">
				<text class="back_icon">‹</text>
			</view>
			<view class="navbar_title">知识库</view>
			<view class="navbar_action">
				<view class="search_button" @click="showSearchPopup = true">
					<text class="search_icon">🔍</text>
				</view>
			</view>
		</view>
		
		<!-- 学员信息 -->
		<view class="student_info_section" v-if="studentInfo">
			<view class="student_name">{{ studentInfo.name }}</view>
			<view class="knowledge_stats">
				<text class="stat_item">总文章：{{ knowledgeStats.total_articles }}篇</text>
				<text class="stat_item">已收藏：{{ knowledgeStats.favorites }}篇</text>
			</view>
		</view>
		
		<!-- 知识分类 -->
		<view class="category_section">
			<view class="category_tabs">
				<view 
					v-for="category in categoryTabs" 
					:key="category.value"
					:class="['category_tab', activeCategory === category.value ? 'active' : '']"
					@click="changeCategory(category.value)"
				>
					<view class="tab_icon">{{ category.icon }}</view>
					<view class="tab_text">{{ category.text }}</view>
					<view class="tab_badge" v-if="category.count > 0">{{ category.count }}</view>
				</view>
			</view>
		</view>
		
		<!-- 推荐文章 -->
		<view class="recommend_section" v-if="activeCategory === 'all' && recommendArticles.length > 0">
			<view class="section_title">
				<text class="title_text">推荐阅读</text>
				<text class="title_icon">⭐</text>
			</view>
			<view class="recommend_list">
				<view 
					v-for="article in recommendArticles" 
					:key="article.id"
					class="recommend_item"
					@click="viewArticle(article)"
				>
					<view class="recommend_cover">
						<image :src="article.cover_image" class="cover_image" mode="aspectFill"></image>
					</view>
					<view class="recommend_info">
						<view class="recommend_title">{{ article.title }}</view>
						<view class="recommend_summary">{{ article.summary }}</view>
						<view class="recommend_meta">
							<text class="meta_item">{{ article.read_count }}次阅读</text>
							<text class="meta_item">{{ formatDate(article.publish_time) }}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 知识文章列表 -->
		<view class="articles_section">
			<view v-if="loading" class="loading_section">
				<view class="loading_text">加载中...</view>
			</view>
			
			<view v-else-if="filteredArticles.length === 0" class="empty_section">
				<view class="empty_icon">📚</view>
				<view class="empty_text">暂无相关文章</view>
				<view class="empty_hint">更多精彩内容敬请期待</view>
			</view>
			
			<view v-else class="articles_list">
				<view 
					v-for="article in filteredArticles" 
					:key="article.id"
					class="article_item"
					@click="viewArticle(article)"
				>
					<view class="article_header">
						<view class="article_category" :class="article.category">
							{{ getCategoryText(article.category) }}
						</view>
						<view class="article_meta">
							<text class="meta_time">{{ formatDate(article.publish_time) }}</text>
							<view class="favorite_button" @click.stop="toggleFavorite(article)">
								<text :class="['favorite_icon', article.is_favorite ? 'favorited' : '']">
									{{ article.is_favorite ? '❤️' : '🤍' }}
								</text>
							</view>
						</view>
					</view>
					
					<view class="article_content">
						<view class="article_info">
							<view class="article_title">{{ article.title }}</view>
							<view class="article_summary">{{ article.summary }}</view>
							<view class="article_tags" v-if="article.tags && article.tags.length > 0">
								<view 
									v-for="tag in article.tags" 
									:key="tag"
									class="tag_item"
								>
									#{{ tag }}
								</view>
							</view>
						</view>
						
						<view class="article_cover" v-if="article.cover_image">
							<image :src="article.cover_image" class="cover_image" mode="aspectFill"></image>
						</view>
					</view>
					
					<view class="article_footer">
						<view class="article_stats">
							<text class="stat_icon">👁️</text>
							<text class="stat_text">{{ article.read_count }}</text>
							<text class="stat_icon">👍</text>
							<text class="stat_text">{{ article.like_count }}</text>
						</view>
						<view class="read_status" v-if="article.is_read">
							<text class="read_text">已读</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 加载更多 -->
		<view class="load_more_section" v-if="!loading && hasMore">
			<fui-button 
				background="transparent" 
				color="#666"
				@click="loadMoreArticles"
				:loading="loadingMore"
			>
				{{ loadingMore ? '加载中...' : '加载更多' }}
			</fui-button>
		</view>
		
		<!-- 搜索弹窗 -->
		<view class="search_popup" v-if="showSearchPopup" @click="closeSearchPopup">
			<view class="popup_content" @click.stop>
				<view class="popup_header">
					<view class="popup_title">搜索文章</view>
					<view class="popup_close" @click="closeSearchPopup">×</view>
				</view>
				
				<view class="search_form">
					<view class="search_input">
						<input 
							v-model="searchKeyword" 
							placeholder="请输入关键词搜索"
							class="input_field"
							@confirm="performSearch"
						/>
						<view class="search_button" @click="performSearch">
							<text class="search_text">搜索</text>
						</view>
					</view>
					
					<view class="search_history" v-if="searchHistory.length > 0">
						<view class="history_title">搜索历史</view>
						<view class="history_tags">
							<view 
								v-for="(keyword, index) in searchHistory" 
								:key="index"
								class="history_tag"
								@click="searchKeyword = keyword; performSearch()"
							>
								{{ keyword }}
							</view>
						</view>
						<view class="clear_history" @click="clearSearchHistory">
							<text class="clear_text">清除历史</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import apiRoute from '@/api/apiRoute.js'
	
	export default {
		data() {
			return {
				studentId: 0,
				studentInfo: {},
				articlesList: [],
				filteredArticles: [],
				recommendArticles: [],
				knowledgeStats: {},
				loading: false,
				loadingMore: false,
				hasMore: true,
				currentPage: 1,
				activeCategory: 'all',
				showSearchPopup: false,
				searchKeyword: '',
				searchHistory: [],
				// 配置项
				categoryTabs: [
					{ value: 'all', text: '全部', icon: '📖', count: 0 },
					{ value: '1', text: '课程教学大纲', icon: '📖', count: 0 },
					{ value: '2', text: '跳绳教案库', icon: '🏃', count: 0 },
					{ value: '3', text: '增高教案库', icon: '📏', count: 0 },
					{ value: '4', text: '篮球教案库', icon: '🏀', count: 0 },
					{ value: '5', text: '强化教案库', icon: '💪', count: 0 },
					{ value: '6', text: '空中忍者教案库', icon: '🥷', count: 0 },
					{ value: '7', text: '少儿安防教案库', icon: '🛡️', count: 0 },
					{ value: '8', text: '体能教案库', icon: '🏋️', count: 0 }
				],
				categoryMap: {
					'1': '课程教学大纲',
					'2': '跳绳教案库',
					'3': '增高教案库',
					'4': '篮球教案库',
					'5': '强化教案库',
					'6': '空中忍者教案库',
					'7': '少儿安防教案库',
					'8': '体能教案库'
				},
				mockConfig: {
					maxSearchHistory: 10,
					pageSize: 10,
					searchDelay: 300
				}
			}
		},
		
		onLoad(options) {
			this.studentId = parseInt(options.student_id) || 0
			if (this.studentId) {
				this.initPage()
			} else {
				uni.showToast({
					title: '参数错误',
					icon: 'none'
				})
			}
		},
		
		methods: {
			goBack() {
				uni.navigateBack()
			},
			
			// Mock数据方法
			getMockArticlesData() {
				return {
					code: 1,
					data: {
						list: [
							{
								id: 1,
								title: '少儿体适能训练的核心要素',
								summary: '了解少儿体适能训练的基本原理和核心要素，帮助孩子建立正确的运动基础。',
								category: 'training',
								tags: ['体适能', '少儿训练', '基础运动'],
								cover_image: '/static/knowledge/training1.jpg',
								author: '张教练',
								publish_time: '2024-01-15 10:00:00',
								read_count: 1250,
								like_count: 88,
								is_read: false,
								is_favorite: false
							},
							{
								id: 2,
								title: '儿童运动营养指南',
								summary: '科学的营养搭配是儿童运动能力提升的重要保障。',
								category: 'nutrition',
								tags: ['运动营养', '儿童健康', '饮食搭配'],
								cover_image: '/static/knowledge/nutrition1.jpg',
								author: '李营养师',
								publish_time: '2024-01-14 15:30:00',
								read_count: 980,
								like_count: 65,
								is_read: true,
								is_favorite: true
							},
							{
								id: 3,
								title: '运动后的恢复与拉伸',
								summary: '正确的恢复和拉伸能够有效防止运动损伤。',
								category: 'recovery',
								tags: ['运动恢复', '拉伸运动', '损伤预防'],
								cover_image: '/static/knowledge/recovery1.jpg',
								author: '王康复师',
								publish_time: '2024-01-13 09:20:00',
								read_count: 756,
								like_count: 42,
								is_read: false,
								is_favorite: false
							}
						],
						total: 25,
						has_more: true,
						stats: {
							total_articles: 25,
							favorites: 8,
							read_articles: 12
						}
					}
				}
			},
			
			getMockRecommendData() {
				return [
					{
						id: 101,
						title: '新手家长必看：如何陪伴孩子开始运动',
						summary: '专为运动新手家长准备的指导文章。',
						cover_image: '/static/knowledge/recommend1.jpg',
						read_count: 2580,
						publish_time: '2024-01-10 16:00:00'
					},
					{
						id: 102,
						title: '冬季儿童运动注意事项',
						summary: '冬季天气寒冷，儿童运动需要特别注意保暖和安全。',
						cover_image: '/static/knowledge/recommend2.jpg',
						read_count: 1890,
						publish_time: '2024-01-09 10:30:00'
					}
				]
			},
			
			// 数据验证方法
			validateArticleData(article) {
				if (!article || typeof article !== 'object') {
					return false
				}
				
				const requiredFields = ['id', 'title', 'category']
				return requiredFields.every(field => article.hasOwnProperty(field) && article[field])
			},
			
			validateResponseData(response) {
				if (!response || response.code !== 1) {
					return false
				}
				
				if (!response.data || !Array.isArray(response.data.list)) {
					return false
				}
				
				return response.data.list.every(item => this.validateArticleData(item))
			},
			
			async initPage() {
				await this.loadStudentInfo()
				await this.loadKnowledgeCategories()
				await this.loadArticles()
				await this.loadRecommendArticles()
				this.updateCategoryCounts()
				this.loadSearchHistory()
			},
			
			async loadStudentInfo() {
				try {
					// 调用真实API获取学员信息
					const response = await apiRoute.xy_memberInfo({
						student_id: this.studentId
					})
					
					if (response && response.code === 1 && response.data) {
						this.studentInfo = {
							id: this.studentId,
							name: response.data.name || response.data.student_name || '学员',
							phone: response.data.phone || '',
							avatar: response.data.avatar || ''
						}
					} else {
						// API失败时使用默认信息
						this.studentInfo = {
							id: this.studentId,
							name: '学员',
							phone: '',
							avatar: ''
						}
					}
				} catch (error) {
					console.error('获取学员信息失败:', error)
					// 网络错误时使用默认信息
					this.studentInfo = {
						id: this.studentId,
						name: '学员',
						phone: '',
						avatar: ''
					}
				}
			},
			
			async loadArticles() {
				this.loading = true
				try {
					console.log('加载知识文章:', this.studentId)
					
					// 调用真实API
					const response = await apiRoute.getKnowledgeList({
						student_id: this.studentId,
						category: this.activeCategory === 'all' ? '' : this.activeCategory,
						page: this.currentPage,
						limit: this.mockConfig.pageSize
					})
					
					// 处理API响应
					if (response && response.code === 1 && response.data) {
						const apiData = response.data
						const newList = apiData.list || []
						
						if (this.currentPage === 1) {
							this.articlesList = newList
						} else {
							this.articlesList = [...this.articlesList, ...newList]
						}
						
						// 更新分页信息
						this.hasMore = apiData.current_page < apiData.last_page
						
						// 获取统计信息（如果API返回了统计数据）
						if (apiData.stats) {
							this.knowledgeStats = apiData.stats
						} else {
							// 如果没有统计数据，调用统计API
							await this.loadKnowledgeStats()
						}
						
						this.applyCategoryFilter()
						console.log('知识文章加载成功:', this.articlesList)
					} else {
						// API失败时降级到Mock数据
						console.warn('API返回失败，使用Mock数据:', response?.msg)
						await this.loadMockArticles()
					}
				} catch (error) {
					console.error('获取文章列表失败:', error)
					// 网络错误时降级到Mock数据
					await this.loadMockArticles()
				} finally {
					this.loading = false
					this.loadingMore = false
				}
			},
			
			// 加载Mock数据的方法
			async loadMockArticles() {
				const mockResponse = {
					code: 1,
					data: {
						list: [
							{
								id: 1,
								title: '少儿体适能训练的核心要素',
								summary: '了解少儿体适能训练的基本原理和核心要素，帮助孩子建立正确的运动基础，促进身心健康发展。',
								content: '少儿体适能训练是一个系统性的运动教育过程...',
								table_type: '2',
								category_name: '跳绳教案库',
								tags: ['体适能', '少儿训练', '基础运动'],
								image: '/static/knowledge/training1.jpg',
								create_time: 1642204800,
								is_read: false,
								is_favorite: false
							},
							{
								id: 2,
								title: '儿童运动营养指南',
								summary: '科学的营养搭配是儿童运动能力提升的重要保障，本文详细介绍运动前后的营养补充策略。',
								content: '儿童在进行体育运动时，合理的营养补充至关重要...',
								table_type: '7',
								category_name: '少儿安防教案库',
								tags: ['运动营养', '儿童健康', '饮食搭配'],
								image: '/static/knowledge/nutrition1.jpg',
								create_time: 1642118400,
								is_read: true,
								is_favorite: true
							}
						],
						total: 2,
						current_page: 1,
						last_page: 1
					}
				}
				
				const newList = mockResponse.data.list || []
				if (this.currentPage === 1) {
					this.articlesList = newList
				} else {
					this.articlesList = [...this.articlesList, ...newList]
				}
				
				this.hasMore = mockResponse.data.current_page < mockResponse.data.last_page
				this.knowledgeStats = {
					total_articles: 25,
					favorites: 8,
					read_articles: 12
				}
				this.applyCategoryFilter()
			},
			
			// 加载知识库分类信息
			async loadKnowledgeCategories() {
				try {
					const response = await apiRoute.getKnowledgeCategories()
					
					if (response && response.code === 1 && response.data) {
						// 构建分类标签，只包含有数据的分类
						const apiCategories = response.data.map(category => ({
							value: category.value.toString(),
							text: category.text,
							icon: category.icon,
							count: category.count
						}))
						
						// 重新构建分类标签数组，保留"全部"选项
						this.categoryTabs = [
							{ value: 'all', text: '全部', icon: '📖', count: 0 },
							...apiCategories
						]
						
						// 更新全部分类的计数
						const totalCount = apiCategories.reduce((sum, cat) => sum + cat.count, 0)
						this.categoryTabs[0].count = totalCount
					}
				} catch (error) {
					console.error('获取知识库分类失败:', error)
					// API失败时保持默认分类
				}
			},
			
			// 加载知识库统计信息
			async loadKnowledgeStats() {
				try {
					const response = await apiRoute.getKnowledgeStats({
						student_id: this.studentId
					})
					
					if (response && response.code === 1) {
						this.knowledgeStats = response.data
					}
				} catch (error) {
					console.error('获取知识库统计失败:', error)
				}
			},
			
			async loadRecommendArticles() {
				try {
					// 调用真实API获取推荐文章
					const response = await apiRoute.getRecommendArticles({
						student_id: this.studentId,
						limit: 5
					})
					
					if (response && response.code === 1) {
						this.recommendArticles = response.data || []
					} else {
						// 降级到Mock数据
						this.recommendArticles = this.getMockRecommendData()
					}
				} catch (error) {
					console.error('获取推荐文章失败:', error)
					// 降级到Mock数据
					this.recommendArticles = this.getMockRecommendData()
				}
			},
			
			async loadMoreArticles() {
				if (this.loadingMore || !this.hasMore) return
				
				this.loadingMore = true
				this.currentPage++
				await this.loadArticles()
			},
			
			async changeCategory(category) {
				this.activeCategory = category
				this.currentPage = 1
				this.hasMore = true
				// 重新加载对应分类的文章
				await this.loadArticles()
			},
			
			applyCategoryFilter() {
				if (this.activeCategory === 'all') {
					this.filteredArticles = [...this.articlesList]
				} else {
					this.filteredArticles = this.articlesList.filter(article => article.table_type === this.activeCategory)
				}
			},
			
			updateCategoryCounts() {
				const counts = {}
				this.articlesList.forEach(article => {
					counts[article.table_type] = (counts[article.table_type] || 0) + 1
				})
				
				this.categoryTabs.forEach(tab => {
					if (tab.value === 'all') {
						tab.count = this.articlesList.length
					} else {
						tab.count = counts[tab.value] || 0
					}
				})
			},
			
			getCategoryText(category) {
				// 如果传入的是table_type，直接使用categoryMap
				return this.categoryMap[category] || category
			},
			
			formatDate(dateString) {
				let date
				// 处理时间戳或日期字符串
				if (typeof dateString === 'number') {
					date = new Date(dateString * 1000) // 假设是秒级时间戳
				} else {
					date = new Date(dateString)
				}
				
				const now = new Date()
				const diffDays = Math.floor((now - date) / (1000 * 60 * 60 * 24))
				
				if (diffDays === 0) {
					return '今天'
				} else if (diffDays === 1) {
					return '昨天'
				} else if (diffDays < 7) {
					return `${diffDays}天前`
				} else {
					const month = String(date.getMonth() + 1).padStart(2, '0')
					const day = String(date.getDate()).padStart(2, '0')
					return `${month}-${day}`
				}
			},
			
			viewArticle(article) {
				console.log('查看文章:', article)
				
				// 标记为已读
				if (!article.is_read) {
					this.markAsRead(article)
				}
				
				// 跳转到文章详情页面
				uni.navigateTo({
					url: `/pages-student/knowledge/detail?article_id=${article.id}&student_id=${this.studentId}`
				})
			},
			
			async markAsRead(article) {
				try {
					console.log('标记文章已读:', article.id)
					
					// 调用真实API标记已读
					const response = await apiRoute.markArticleRead({
						article_id: article.id,
						student_id: this.studentId
					})
					
					if (response && response.code === 1) {
						// 更新本地状态
						article.is_read = true
						console.log('标记已读成功:', response.msg)
					} else {
						// 即使API失败也更新UI状态
						article.is_read = true
					}
					
					// 更新本地状态
					const index = this.articlesList.findIndex(item => item.id === article.id)
					if (index !== -1) {
						this.articlesList[index].is_read = true
						this.articlesList[index].read_count += 1
					}
				} catch (error) {
					console.error('标记已读失败:', error)
				}
			},
			
			async toggleFavorite(article) {
				try {
					console.log('切换收藏状态:', article.id, !article.is_favorite)
					
					// 调用真实API
					const response = await apiRoute.toggleArticleFavorite({
						article_id: article.id,
						student_id: this.studentId,
						action: article.is_favorite ? 'remove' : 'add'
					})
					
					if (response && response.code === 1) {
						// 更新本地状态
						const index = this.articlesList.findIndex(item => item.id === article.id)
						if (index !== -1) {
							this.articlesList[index].is_favorite = !this.articlesList[index].is_favorite
							
							// 更新收藏统计
							if (this.articlesList[index].is_favorite) {
								this.knowledgeStats.favorites += 1
							} else {
								this.knowledgeStats.favorites -= 1
							}
						}
						
						uni.showToast({
							title: response.msg || (article.is_favorite ? '已取消收藏' : '收藏成功'),
							icon: article.is_favorite ? 'none' : 'success'
						})
					}
				} catch (error) {
					console.error('收藏操作失败:', error)
					uni.showToast({
						title: '操作失败',
						icon: 'none'
					})
				}
			},
			
			closeSearchPopup() {
				this.showSearchPopup = false
				this.searchKeyword = ''
			},
			
			async performSearch() {
				if (!this.searchKeyword.trim()) {
					uni.showToast({
						title: '请输入搜索关键词',
						icon: 'none'
					})
					return
				}
				
				// 添加到搜索历史
				this.addToSearchHistory(this.searchKeyword.trim())
				
				try {
					console.log('搜索文章:', this.searchKeyword)
					
					// 调用真实搜索API
					const response = await apiRoute.searchKnowledgeArticles({
						student_id: this.studentId,
						keyword: this.searchKeyword.trim(),
						category: this.activeCategory === 'all' ? '' : this.activeCategory,
						page: 1,
						limit: 50
					})
					
					let results = []
					if (response && response.code === 1 && response.data && response.data.list) {
						results = response.data.list
					} else {
						// 降级到本地搜索
						results = this.articlesList.filter(article => 
							article.title.includes(this.searchKeyword) || 
							article.summary.includes(this.searchKeyword) ||
							(article.tags && article.tags.some(tag => tag.includes(this.searchKeyword)))
						)
					}
					
					this.filteredArticles = results
					this.closeSearchPopup()
					
					if (results.length === 0) {
						uni.showToast({
							title: '暂无相关文章',
							icon: 'none'
						})
					} else {
						uni.showToast({
							title: `找到${results.length}篇相关文章`,
							icon: 'success'
						})
					}
				} catch (error) {
					console.error('搜索失败:', error)
					uni.showToast({
						title: '搜索失败',
						icon: 'none'
					})
				}
			},
			
			addToSearchHistory(keyword) {
				// 移除重复项
				const index = this.searchHistory.indexOf(keyword)
				if (index > -1) {
					this.searchHistory.splice(index, 1)
				}
				
				// 添加到开头
				this.searchHistory.unshift(keyword)
				
				// 限制历史记录数量
				if (this.searchHistory.length > 10) {
					this.searchHistory = this.searchHistory.slice(0, 10)
				}
				
				// 保存到本地存储
				this.saveSearchHistory()
			},
			
			loadSearchHistory() {
				try {
					const history = uni.getStorageSync('knowledge_search_history')
					if (history) {
						this.searchHistory = JSON.parse(history)
					}
				} catch (error) {
					console.error('加载搜索历史失败:', error)
				}
			},
			
			saveSearchHistory() {
				try {
					uni.setStorageSync('knowledge_search_history', JSON.stringify(this.searchHistory))
				} catch (error) {
					console.error('保存搜索历史失败:', error)
				}
			},
			
			clearSearchHistory() {
				this.searchHistory = []
				this.saveSearchHistory()
				uni.showToast({
					title: '搜索历史已清除',
					icon: 'success'
				})
			}
		}
	}
</script>

<style lang="less" scoped>
// 公共样式
.image-container {
	width: 120rpx;
	height: 90rpx;
	margin-right: 20rpx;
	border-radius: 8rpx;
	overflow: hidden;
	flex-shrink: 0;
	
	.cover_image {
		width: 100%;
		height: 100%;
	}
}

.article-title {
	font-weight: 600;
	color: #333;
	margin-bottom: 8rpx;
	line-height: 1.4;
}

.text-summary {
	font-size: 22rpx;
	color: #666;
	line-height: 1.4;
	margin-bottom: 8rpx;
}

.text-meta {
	font-size: 20rpx;
	color: #999;
}

.main_box {
	background: #f8f9fa;
	min-height: 100vh;
}

// 自定义导航栏
.navbar_section {
	display: flex;
	justify-content: space-between;
	align-items: center;
	background: #29D3B4;
	padding: 40rpx 32rpx 20rpx;
	
	// 小程序端适配状态栏
	// #ifdef MP-WEIXIN
	padding-top: 80rpx;
	// #endif
	
	.navbar_back {
		width: 60rpx;
		
		.back_icon {
			color: #fff;
			font-size: 40rpx;
			font-weight: 600;
		}
	}
	
	.navbar_title {
		color: #fff;
		font-size: 32rpx;
		font-weight: 600;
	}
	
	.navbar_action {
		width: 60rpx;
		display: flex;
		justify-content: flex-end;
		
		.search_button {
			width: 40rpx;
			height: 40rpx;
			background: rgba(255, 255, 255, 0.2);
			border-radius: 50%;
			display: flex;
			align-items: center;
			justify-content: center;
			
			.search_icon {
				font-size: 20rpx;
			}
		}
	}
}

// 学员信息
.student_info_section {
	background: #fff;
	padding: 24rpx 32rpx;
	border-bottom: 1px solid #f0f0f0;
	
	.student_name {
		font-size: 32rpx;
		font-weight: 600;
		color: #333;
		margin-bottom: 12rpx;
	}
	
	.knowledge_stats {
		display: flex;
		gap: 24rpx;
		
		.stat_item {
			font-size: 24rpx;
			color: #666;
		}
	}
}

// 分类筛选
.category_section {
	background: #fff;
	margin: 20rpx;
	border-radius: 16rpx;
	padding: 24rpx 32rpx;
	
	.category_tabs {
		display: flex;
		flex-wrap: wrap;
		gap: 16rpx;
		
		.category_tab {
			position: relative;
			display: flex;
			flex-direction: column;
			align-items: center;
			padding: 16rpx 20rpx;
			background: #f8f9fa;
			border-radius: 20rpx;
			min-width: 100rpx;
			
			&.active {
				background: linear-gradient(135deg, #29D3B4, #26c6a0);
				color: #fff;
			}
			
			.tab_icon {
				font-size: 28rpx;
				margin-bottom: 6rpx;
			}
			
			.tab_text {
				font-size: 22rpx;
				color: #666;
			}
			
			&.active .tab_text {
				color: #fff;
			}
			
			.tab_badge {
				position: absolute;
				top: -6rpx;
				right: -6rpx;
				background: #ff4757;
				color: #fff;
				font-size: 18rpx;
				padding: 2rpx 6rpx;
				border-radius: 10rpx;
				min-width: 16rpx;
				text-align: center;
			}
		}
	}
}

// 推荐文章
.recommend_section {
	margin: 0 20rpx 20rpx;
	
	.section_title {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 24rpx 32rpx 16rpx;
		background: #fff;
		border-radius: 16rpx 16rpx 0 0;
		
		.title_text {
			font-size: 28rpx;
			font-weight: 600;
			color: #333;
		}
		
		.title_icon {
			font-size: 24rpx;
		}
	}
	
	.recommend_list {
		background: #fff;
		border-radius: 0 0 16rpx 16rpx;
		
		.recommend_item {
			display: flex;
			padding: 24rpx 32rpx;
			border-bottom: 1px solid #f8f9fa;
			
			&:last-child {
				border-bottom: none;
			}
			
			.recommend_cover {
				width: 120rpx;
				height: 90rpx;
				margin-right: 20rpx;
				border-radius: 8rpx;
				overflow: hidden;
				flex-shrink: 0;
				
				.cover_image {
					width: 100%;
					height: 100%;
				}
			}
			
			.recommend_info {
				flex: 1;
				
				.recommend_title {
					font-weight: 600;
					color: #333;
					margin-bottom: 8rpx;
					line-height: 1.4;
					font-size: 26rpx;
				}
				
				.recommend_summary {
					font-size: 22rpx;
					color: #666;
					line-height: 1.4;
					margin-bottom: 8rpx;
				}
				
				.recommend_meta {
					display: flex;
					gap: 16rpx;
					
					.meta_item {
						font-size: 20rpx;
						color: #999;
					}
				}
			}
		}
	}
}

// 文章列表
.articles_section {
	margin: 0 20rpx;
	
	.loading_section, .empty_section {
		background: #fff;
		border-radius: 16rpx;
		padding: 80rpx 32rpx;
		text-align: center;
		
		.loading_text, .empty_text {
			font-size: 28rpx;
			color: #666;
			margin-bottom: 12rpx;
		}
		
		.empty_icon {
			font-size: 80rpx;
			margin-bottom: 24rpx;
		}
		
		.empty_hint {
			font-size: 24rpx;
			color: #999;
		}
	}
	
	.articles_list {
		.article_item {
			background: #fff;
			border-radius: 16rpx;
			padding: 24rpx;
			margin-bottom: 16rpx;
			box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.06);
			
			.article_header {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 16rpx;
				
				.article_category {
					font-size: 22rpx;
					padding: 4rpx 12rpx;
					border-radius: 12rpx;
					
					&.training {
						color: #e74c3c;
						background: rgba(231, 76, 60, 0.1);
					}
					
					&.nutrition {
						color: #27ae60;
						background: rgba(39, 174, 96, 0.1);
					}
					
					&.recovery {
						color: #3498db;
						background: rgba(52, 152, 219, 0.1);
					}
					
					&.psychology {
						color: #9b59b6;
						background: rgba(155, 89, 182, 0.1);
					}
					
					&.equipment {
						color: #f39c12;
						background: rgba(243, 156, 18, 0.1);
					}
				}
				
				.article_meta {
					display: flex;
					align-items: center;
					gap: 16rpx;
					
					.meta_time {
						font-size: 22rpx;
						color: #999;
					}
					
					.favorite_button {
						.favorite_icon {
							font-size: 24rpx;
							
							&.favorited {
								animation: heartbeat 0.6s ease-in-out;
							}
						}
					}
				}
			}
			
			.article_content {
				display: flex;
				gap: 20rpx;
				margin-bottom: 16rpx;
				
				.article_info {
					flex: 1;
					
					.article_title {
						font-size: 28rpx;
						font-weight: 600;
						color: #333;
						line-height: 1.4;
						margin-bottom: 12rpx;
					}
					
					.article_summary {
						font-size: 24rpx;
						color: #666;
						line-height: 1.5;
						margin-bottom: 12rpx;
					}
					
					.article_tags {
						display: flex;
						flex-wrap: wrap;
						gap: 8rpx;
						
						.tag_item {
							font-size: 20rpx;
							color: #29D3B4;
							background: rgba(41, 211, 180, 0.1);
							padding: 4rpx 8rpx;
							border-radius: 8rpx;
						}
					}
				}
				
				.article_cover {
					width: 120rpx;
					height: 90rpx;
					border-radius: 8rpx;
					overflow: hidden;
					flex-shrink: 0;
					
					.cover_image {
						width: 100%;
						height: 100%;
					}
				}
			}
			
			.article_footer {
				display: flex;
				justify-content: space-between;
				align-items: center;
				
				.article_stats {
					display: flex;
					align-items: center;
					gap: 8rpx;
					
					.stat_icon {
						font-size: 20rpx;
					}
					
					.stat_text {
						font-size: 22rpx;
						color: #999;
						margin-right: 16rpx;
					}
				}
				
				.read_status {
					.read_text {
						font-size: 20rpx;
						color: #27ae60;
						background: rgba(39, 174, 96, 0.1);
						padding: 4rpx 8rpx;
						border-radius: 8rpx;
					}
				}
			}
		}
	}
}

// 加载更多
.load_more_section {
	padding: 40rpx 20rpx 80rpx;
}

// 搜索弹窗
.search_popup {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	display: flex;
	justify-content: center;
	align-items: flex-start;
	padding-top: 20vh;
	z-index: 1000;
	
	.popup_content {
		background: #fff;
		border-radius: 16rpx;
		width: 90%;
		max-height: 60vh;
		overflow: hidden;
		
		.popup_header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 32rpx;
			border-bottom: 1px solid #f0f0f0;
			
			.popup_title {
				font-size: 32rpx;
				font-weight: 600;
				color: #333;
			}
			
			.popup_close {
				font-size: 48rpx;
				color: #999;
				font-weight: 300;
			}
		}
		
		.search_form {
			padding: 32rpx;
			
			.search_input {
				display: flex;
				align-items: center;
				background: #f8f9fa;
				border-radius: 24rpx;
				padding: 12rpx 20rpx;
				margin-bottom: 32rpx;
				
				.input_field {
					flex: 1;
					font-size: 26rpx;
					border: none;
					background: transparent;
				}
				
				.search_button {
					background: #29D3B4;
					color: #fff;
					padding: 8rpx 16rpx;
					border-radius: 16rpx;
					margin-left: 16rpx;
					
					.search_text {
						font-size: 24rpx;
					}
				}
			}
			
			.search_history {
				.history_title {
					font-size: 24rpx;
					color: #666;
					margin-bottom: 16rpx;
				}
				
				.history_tags {
					display: flex;
					flex-wrap: wrap;
					gap: 12rpx;
					margin-bottom: 20rpx;
					
					.history_tag {
						background: #f8f9fa;
						color: #666;
						font-size: 24rpx;
						padding: 8rpx 16rpx;
						border-radius: 16rpx;
						border: 1px solid #e0e0e0;
					}
				}
				
				.clear_history {
					text-align: center;
					
					.clear_text {
						font-size: 24rpx;
						color: #999;
					}
				}
			}
		}
	}
}

// 动画效果
@keyframes heartbeat {
	0% { transform: scale(1); }
	50% { transform: scale(1.2); }
	100% { transform: scale(1); }
}
</style>