<template>
  <div class="favorites-page">
    <div class="favorites-container">
      <!-- 标题 -->
      <div class="section-title">
        <div class="title-bar"></div>
        <h2 class="title-text">我的收藏</h2>
      </div>
      
      <!-- 收藏统计 -->
      <div v-if="!loading && stats" class="stats-section">
        <div class="stats-card">
          <div class="stats-item">
            <div class="stats-number">{{ stats.totalFavorites || 0 }}</div>
            <div class="stats-label">总收藏数</div>
          </div>
          <div class="stats-item">
            <div class="stats-number">{{ stats.workflowFavorites || 0 }}</div>
            <div class="stats-label">工作流收藏</div>
          </div>
          <div class="stats-item">
            <div class="stats-number">{{ stats.videoFavorites || 0 }}</div>
            <div class="stats-label">课程收藏</div>
          </div>
        </div>
      </div>
      
      <!-- 分类标签 -->
      <div class="category-tabs">
        <div 
          v-for="category in categories" 
          :key="category.id"
          class="category-tab"
          :class="{ active: currentCategory === category.id }"
          @click="switchCategory(category.id)"
        >
          {{ category.name }}
        </div>
      </div>
      
      <!-- 骨架屏加载状态 -->
      <div v-if="loading" class="favorites-list">
        <div 
          v-for="i in 8" 
          :key="`skeleton-${i}`"
          class="favorite-item skeleton-item"
        >
          <div class="favorite-cover skeleton-cover">
            <el-skeleton-item variant="image" style="width: 100%; height: 100%; border-radius: 0;" />
            <div class="gradient-overlay"></div>
            <el-skeleton-item variant="text" style="position: absolute; top: 12px; right: 12px; width: 54px; height: 26px; border-radius: 4px;" />
            <el-skeleton-item variant="text" style="position: absolute; bottom: 80px; right: 12px; width: 80px; height: 20px; border-radius: 4px;" />
            <div class="favorite-info">
              <el-skeleton-item variant="h3" style="width: 80%; height: 16px; margin-bottom: 12px; background: rgba(255,255,255,0.3);" />
              <div class="user-info">
                <div class="user-left">
                  <el-skeleton-item variant="circle" style="width: 28px; height: 28px; background: rgba(255,255,255,0.3);" />
                  <el-skeleton-item variant="text" style="width: 60px; height: 12px; background: rgba(255,255,255,0.3);" />
                </div>
                <el-skeleton-item variant="text" style="width: 68px; height: 28px; border-radius: 4px; background: rgba(255,255,255,0.3);" />
              </div>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 错误提示 -->
      <div v-if="error" class="error-message">
        <p>{{ error }}</p>
        <button @click="initData" class="retry-button">重试</button>
      </div>
      
      <!-- 收藏列表 -->
      <div v-else-if="!loading && filteredFavorites.length > 0" class="favorites-list">
        <div 
          v-for="favorite in filteredFavorites" 
          :key="favorite.id"
          class="favorite-item"
          @click="handleCardClick(favorite)"
        >
          <div class="favorite-cover">
            <!-- 工作流显示封面 -->
            <img v-if="favorite.category === 'workflow' && favorite.cover" :src="favorite.cover" :alt="favorite.title" />
            <!-- 课程显示封面，如果没有封面则显示默认封面 -->
            <img v-else-if="favorite.category === 'video' && favorite.cover" :src="favorite.cover" :alt="favorite.title" />
            <div v-else-if="favorite.category === 'video'" class="video-default-cover">
              <div class="video-play-icon">▶</div>
            </div>
            <div class="gradient-overlay"></div>
            <!-- VIP等级标识 -->
            <div v-if="favorite.category === 'video' && favorite.level" class="vip-badge">
              <img v-if="favorite.level === 3" src="@/assets/vip_icon/SVIP.svg" alt="SVIP" class="vip-icon" />
              <img v-else-if="favorite.level === 2" src="@/assets/vip_icon/VIP.svg" alt="VIP" class="vip-icon" />
              <img v-else src="@/assets/vip_icon/免费.svg" alt="免费" class="vip-icon" />
            </div>
            <div class="favorite-time">{{ formatTime(favorite.favoriteTime) }}</div>
            <div class="favorite-info">
              <h3 class="favorite-title">{{ favorite.title }}</h3>
              <p v-if="favorite.description" class="favorite-description">{{ favorite.description }}</p>
              <div class="action-buttons">
                <div class="tag-button" @click="handleUse(favorite, $event)">
                  <span>{{ favorite.category === 'video' ? '立即学习' : '立即使用' }}</span>
                </div>
                <div class="remove-button" @click="handleRemove(favorite, $event)">
                  <span>取消收藏</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 空状态 -->
      <div v-else-if="!loading && filteredFavorites.length === 0" class="empty-state">
    
        <p class="empty-text">暂无收藏内容</p>
        <p class="empty-subtext">去发现更多精彩内容吧</p>
      </div>
      
      <!-- 分页组件 -->
      <div v-if="showPagination && !loading && filteredFavorites.length > 0" class="pagination-container">
        <div class="pagination">
          <button 
            v-for="page in getPageNumbers()" 
            :key="page"
            class="page-button"
            :class="{ active: page === pagination.current, ellipsis: page === '...' }"
            @click="page !== '...' && handlePageChange(page)"
            :disabled="page === '...'"
          >
            {{ page }}
          </button>
          <button 
            v-if="pagination.current < pagination.pages"
            class="page-button next-button"
            @click="handlePageChange(pagination.current + 1)"
          >
            &gt;
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { getUserFavoritesStats, getUserFavoriteWorkflows, getUserFavoriteVideos, toggleWorkflowFavorite, toggleVideoFavorite, toggleCourseFavorite } from '../../api/user.js'

const router = useRouter()

// 加载状态
const loading = ref(true)

// 当前选中的分类
const currentCategory = ref('workflow')

// 分类数据
const categories = ref([
  { id: 'workflow', name: '工作流' },
  { id: 'video', name: '课程' }
])

// 收藏统计数据
const stats = ref(null)

// 收藏数据
const favorites = ref([])

// 错误状态
const error = ref(null)

// 分页数据
const pagination = ref({
  current: 1,
  size: 6,
  total: 0,
  pages: 0
})

// 是否显示分页
const showPagination = computed(() => {
  return pagination.value.total > 6
})

// 根据分类筛选收藏
const filteredFavorites = computed(() => {
  return favorites.value
})

// 获取收藏统计
const fetchFavoritesStats = async () => {
  try {
    const response = await getUserFavoritesStats()
    if (response.data && response.data.success) {
      stats.value = response.data.data || {
        totalFavorites: 0,
        workflowFavorites: 0,
        videoFavorites: 0
      }
    } else if (response.success) {
      // 兼容旧的数据结构
      stats.value = response.data || {
        totalFavorites: 0,
        workflowFavorites: 0,
        videoFavorites: 0
      }
    }
  } catch (err) {
    console.error('获取收藏统计失败:', err)
    error.value = '获取收藏统计失败'
  }
}

// 获取收藏的工作流
const fetchFavoriteWorkflows = async () => {
  try {
    loading.value = true
    const response = await getUserFavoriteWorkflows({
      page: pagination.value.current,
      size: pagination.value.size
    })
    if (response.data && response.data.success) {
      const records = response.data.records || []
      favorites.value = records.map(favorite => ({
        id: favorite.id,
        workflowId: favorite.workflowId,
        title: favorite.workflowName,
        cover: favorite.workflowCover,
        description: favorite.workflowDescription,
        favoriteTime: favorite.createTime,
        category: 'workflow'
      }))
      
      pagination.value.total = response.data.total || 0
      pagination.value.pages = Math.ceil(response.data.total / pagination.value.size)
    } else if (response.success) {
      // 兼容旧的数据结构
      const records = response.records || []
      favorites.value = records.map(favorite => ({
        id: favorite.id,
        workflowId: favorite.workflowId,
        title: favorite.workflowName,
        cover: favorite.workflowCover,
        description: favorite.workflowDescription,
        favoriteTime: favorite.createTime,
        category: 'workflow'
      }))
      
      pagination.value.total = response.total || 0
      pagination.value.pages = Math.ceil(response.total / pagination.value.size)
    }
  } catch (err) {
    console.error('获取收藏工作流失败:', err)
    error.value = '获取收藏工作流失败'
  } finally {
    loading.value = false
  }
}

// 获取收藏的课程
const fetchFavoriteVideos = async () => {
  try {
    loading.value = true
    const response = await getUserFavoriteVideos({
      page: pagination.value.current,
      size: pagination.value.size
    })
    if (response.data && response.data.success) {
      const records = response.data.records || []
      favorites.value = records.map(favorite => ({
        id: favorite.id,
        courseId: favorite.courseId,
        title: favorite.courseTitle,
        description: favorite.courseDescription,
        cover: favorite.coverUrl,
        level: favorite.level,
        levelName: favorite.levelName,
        category: 'video',
        favoriteTime: favorite.createTime
      }))
      
      pagination.value.total = response.data.total || 0
      pagination.value.pages = Math.ceil(response.data.total / pagination.value.size)
    }
  } catch (err) {
    console.error('获取收藏课程失败:', err)
    error.value = '获取收藏课程失败'
  } finally {
    loading.value = false
  }
}

// 切换分类
const switchCategory = async (categoryId) => {
  currentCategory.value = categoryId
  pagination.value.current = 1
  error.value = null
  
  if (categoryId === 'workflow') {
    await fetchFavoriteWorkflows()
  } else if (categoryId === 'video') {
    await fetchFavoriteVideos()
  }
}

// 切换页码
const handlePageChange = async (page) => {
  pagination.value.current = page
  if (currentCategory.value === 'workflow') {
    await fetchFavoriteWorkflows()
  } else if (currentCategory.value === 'video') {
    await fetchFavoriteVideos()
  }
}

// 生成页码数组
const getPageNumbers = () => {
  const pages = []
  const current = pagination.value.current
  const total = pagination.value.pages
  
  if (total <= 7) {
    for (let i = 1; i <= total; i++) {
      pages.push(i)
    }
  } else {
    if (current <= 4) {
      for (let i = 1; i <= 7; i++) {
        pages.push(i)
      }
      pages.push('...')
      pages.push(total)
    } else if (current >= total - 3) {
      pages.push(1)
      pages.push('...')
      for (let i = total - 6; i <= total; i++) {
        pages.push(i)
      }
    } else {
      pages.push(1)
      pages.push('...')
      for (let i = current - 2; i <= current + 2; i++) {
        pages.push(i)
      }
      pages.push('...')
      pages.push(total)
    }
  }
  
  return pages
}

// 格式化时间
const formatTime = (time) => {
  if (!time) return ''
  
  const date = new Date(time)
  const now = new Date()
  const diff = now - date
  
  const minutes = Math.floor(diff / (1000 * 60))
  const hours = Math.floor(diff / (1000 * 60 * 60))
  const days = Math.floor(diff / (1000 * 60 * 60 * 24))
  
  if (minutes < 60) {
    return `${minutes}分钟前`
  } else if (hours < 24) {
    return `${hours}小时前`
  } else if (days < 30) {
    return `${days}天前`
  } else {
    return date.toLocaleDateString()
  }
}

// 格式化视频时长
const formatDuration = (seconds) => {
  if (!seconds) return ''
  
  const hours = Math.floor(seconds / 3600)
  const minutes = Math.floor((seconds % 3600) / 60)
  const secs = seconds % 60
  
  if (hours > 0) {
    return `${hours}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
  } else {
    return `${minutes}:${secs.toString().padStart(2, '0')}`
  }
}

// 处理使用
const handleUse = (favorite, event) => {
  // 阻止事件冒泡，避免触发卡片的点击事件
  if (event) {
    event.stopPropagation()
  }
  
  if (favorite.category === 'video') {
    // 课程类型，跳转到课程详情页面
    const courseId = favorite.courseId || favorite.id
    ElMessage.success('正在跳转到课程详情页面...')
    router.push(`/course/${courseId}`)
  } else if (favorite.category === 'workflow') {
    // 工作流类型，跳转到工作流详情页面
    const workflowId = favorite.workflowId || favorite.id
    ElMessage.success('正在跳转到工作流详情页面...')
    router.push(`/workflow/${workflowId}`)
  }
}

// 处理卡片点击
const handleCardClick = (favorite) => {
  if (favorite.category === 'video') {
    // 课程类型，跳转到课程详情页面
    const courseId = favorite.courseId || favorite.id
    router.push(`/course/${courseId}`)
  } else if (favorite.category === 'workflow') {
    // 工作流类型，跳转到工作流详情页面
    const workflowId = favorite.workflowId || favorite.id
    router.push(`/workflow/${workflowId}`)
  }
}

// 通用收藏切换函数（供其他组件使用）
const toggleFavorite = async (type, id) => {
  try {
    let response
    if (type === 'workflow') {
      response = await toggleWorkflowFavorite(id)
    } else if (type === 'video') {
      response = await toggleVideoFavorite(id)
    } else if (type === 'course') {
      response = await toggleCourseFavorite(id)
    }
    
    if (response && response.data && response.data.success) {
      ElMessage.success(response.data.message || '收藏状态已更新')
      return true
    } else {
      ElMessage.error('操作失败')
      return false
    }
  } catch (err) {
    console.error('收藏切换失败:', err)
    ElMessage.error('操作失败')
    return false
  }
}

// 处理取消收藏
const handleRemove = async (favorite, event) => {
  // 阻止事件冒泡，避免触发卡片的点击事件
  if (event) {
    event.stopPropagation()
  }
  
  try {
    await ElMessageBox.confirm(
      '确定要取消收藏这个内容吗？',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
    )
    
    let response
    if (favorite.category === 'workflow') {
      // 使用工作流详情页面相同的接口
      response = await toggleWorkflowFavorite(favorite.workflowId || favorite.id)
    } else if (favorite.category === 'video') {
      response = await toggleCourseFavorite(favorite.courseId || favorite.id)
    }
    
    console.log('取消收藏API响应:', response)
    // 兼容两种响应结构：response.success 或 response.data.success
    const isSuccess = response?.data?.success || response?.success
    if (isSuccess) {
      ElMessage.success('已取消收藏')
      
      // 重新加载当前分类的数据，获取最新状态
      if (currentCategory.value === 'workflow') {
        await fetchFavoriteWorkflows()
      } else if (currentCategory.value === 'video') {
        await fetchFavoriteVideos()
      }
      // 重新获取统计信息
      await fetchFavoritesStats()
    } else {
      console.error('API调用失败:', response)
      ElMessage.error('操作失败')
    }
  } catch (err) {
    if (err !== 'cancel') {
      console.error('取消收藏失败:', err)
      ElMessage.error('操作失败')
    }
  }
}

// 初始化数据
const initData = async () => {
  await fetchFavoritesStats()
  await fetchFavoriteWorkflows()
}

// 组件挂载时初始化
onMounted(() => {
  initData()
})
</script>

<style scoped>
.favorites-page {
  width: 100%;
  min-height: 800px;
  padding: 0;
  margin: 0;
  overflow: hidden;
  box-sizing: border-box;
}

.favorites-container {
  width: 100%;
  box-sizing: border-box;
}

.section-title {
  width: 312px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 0;
  margin-bottom: 20px;
}

.title-bar {
  width: 4px;
  height: 24px;
  background: #333;
  border-radius: 2px;
}

.title-text {
  font-family: Arial, sans-serif;
  font-weight: 600;
  font-size: 24px;
  line-height: 28px;
  letter-spacing: 0px;
  color: #333;
  margin: 0;
  text-align: left;
}

.stats-section {
  margin-bottom: 30px;
}

.stats-card {
  display: flex;
  gap: 20px;
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border: 1px solid #f0f0f0;
}

.stats-item {
  flex: 1;
  text-align: center;
}

.stats-number {
  font-family: Arial, sans-serif;
  font-weight: 600;
  font-size: 32px;
  line-height: 36px;
  color: #333;
  margin-bottom: 8px;
}

.stats-label {
  font-family: Arial, sans-serif;
  font-weight: 400;
  font-size: 14px;
  line-height: 16px;
  color: #666;
}

.category-tabs {
  display: flex;
  gap: 20px;
  margin-bottom: 40px;
  padding-bottom: 20px;
  border-bottom: 2px solid rgba(0, 0, 0, 0.1);
  flex-wrap: wrap;
  justify-content: flex-start;
  width: 100%;
}

.category-tab {
  width: 120px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
  font-weight: 500;
  color: #666;
  flex-shrink: 0;
}

.category-tab:hover {
  background: #f5f5f5;
  border-color: #d0d0d0;
}

.category-tab.active {
  background: #333;
  color: white;
  border-color: #333;
}

.favorites-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  justify-content: start;
  overflow-y: auto;
  padding-bottom: 0px;
  min-height: 500px;
  width: 100%;
  box-sizing: border-box;
}

.favorites-list::-webkit-scrollbar {
  display: none;
}

.favorites-list {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.favorite-item {
  width: 100%;
  height: 320px;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  cursor: pointer;
  border: 1px solid #f0f0f0;
  position: relative;
}

.skeleton-item {
  width: 100%;
  height: 320px;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border: 1px solid #f0f0f0;
}

.skeleton-cover {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.skeleton-item .user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0;
}

.skeleton-item .user-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.favorite-item:hover {
  transform: translateY(-8px);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
  border-color: #ddd;
}

.favorite-cover {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.favorite-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.favorite-item:hover .favorite-cover img {
  transform: scale(1.1);
}

.gradient-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(to top, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
  pointer-events: none;
}

.vip-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
}

.vip-icon {
  width: 54px;
  height: 26px;
  object-fit: contain;
}

.favorite-time {
  position: absolute;
  bottom: 80px;
  right: 12px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  z-index: 5;
}



.video-default-cover {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.video-play-icon {
  width: 60px;
  height: 60px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #333;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.favorite-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 16px 16px;
  z-index: 5;
}

.favorite-title {
  font-family: Arial, sans-serif;
  font-weight: 500;
  font-size: 16px;
  line-height: 18px;
  letter-spacing: 0px;
  color: #ffffff;
  margin: 0 0 8px 0;
  text-align: left;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.favorite-description {
  font-family: Arial, sans-serif;
  font-weight: 400;
  font-size: 12px;
  line-height: 14px;
  letter-spacing: 0px;
  color: rgba(255, 255, 255, 0.8);
  margin: 0 0 12px 0;
  text-align: left;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0;
  height: 28px;
  min-width: 0;
  overflow: hidden;
}

.user-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-width: 0;
}

.user-avatar {
  width: 28px !important;
  height: 28px !important;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  max-width: 28px !important;
  max-height: 28px !important;
}

.default-avatar {
  width: 28px !important;
  height: 28px !important;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 500;
  color: #ffffff;
  flex-shrink: 0;
  max-width: 28px !important;
  max-height: 28px !important;
  padding: 0 2px;
  text-align: center;
  line-height: 1;
}

.user-name {
  font-family: Arial, sans-serif;
  font-weight: 400;
  font-size: 12px;
  line-height: 14px;
  letter-spacing: 0px;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 80px;
}

.action-buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  justify-content: space-between;
  margin-top: 12px;
}

.tag-button {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 32px;
  background: #ffffff;
  border: 1px solid rgba(29, 0, 255, 1);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
  margin-right: 8px;
}

.tag-button span {
  font-family: Arial, sans-serif;
  font-size: 12px;
  line-height: 14px;
  letter-spacing: 0px;
  color: rgba(29, 0, 255, 1);
  font-weight: 400;
  text-align: center;
}

.tag-button:hover {
  background: rgba(29, 0, 255, 0.1);
  border-color: rgba(29, 0, 255, 1);
  transform: translateY(-1px);
}

.remove-button {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 32px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.remove-button span {
  font-family: Arial, sans-serif;
  font-size: 12px;
  line-height: 14px;
  letter-spacing: 0px;
  color: #ffffff;
  font-weight: 400;
  text-align: center;
}

.remove-button:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.6);
  transform: translateY(-1px);
}

.error-message {
  text-align: center;
  padding: 40px 20px;
  color: #666;
}

.error-message p {
  margin: 0 0 20px 0;
  font-size: 16px;
}

.retry-button {
  background: #333;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.3s ease;
}

.retry-button:hover {
  background: #555;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #999;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-text {
  font-size: 16px;
  margin: 0 0 8px 0;
}

.empty-subtext {
  font-size: 14px;
  margin: 0;
  color: #ccc;
}

.pagination-container {
  display: flex;
  justify-content: center;
  margin-top: 40px;
  padding: 20px 0;
}

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

.page-button {
  min-width: 40px;
  height: 40px;
  border: 1px solid #e0e0e0;
  background: white;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
  font-weight: 500;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
}

.page-button:hover:not(.ellipsis):not(:disabled) {
  background: #f5f5f5;
  border-color: #d0d0d0;
}

.page-button.active {
  background: #333;
  color: white;
  border-color: #333;
}

.page-button.ellipsis {
  cursor: default;
  background: white;
  border-color: #e0e0e0;
  color: #999;
}

.page-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.next-button {
  font-weight: bold;
}

@media (max-width: 1400px) {
  .favorites-list {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }
  
  .category-tabs {
    gap: 16px;
  }
  
  .category-tab {
    width: 110px;
  }
  
  .stats-card {
    gap: 16px;
    padding: 20px;
  }
}

@media (max-width: 1100px) {
  .favorites-list {
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
  }
  
  .category-tabs {
    gap: 14px;
  }
  
  .category-tab {
    width: 100px;
    height: 44px;
    font-size: 13px;
  }
  

  
  .stats-card {
    flex-direction: column;
    gap: 12px;
  }
  
  .stats-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  
  .stats-number {
    font-size: 28px;
  }
}

@media (max-width: 768px) {
  .favorites-list {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
  
  .category-tabs {
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-start;
  }
  
  .category-tab {
    width: 90px;
    height: 40px;
    font-size: 12px;
  }
  

  
  .favorite-item {
    height: 280px;
  }
  
  .favorite-title {
    font-size: 14px;
    line-height: 16px;
  }
  
  .action-buttons {
    gap: 6px;
  }
  
  .tag-button,
  .remove-button {
    height: 28px;
  }
  
  .tag-button span,
  .remove-button span {
    font-size: 11px;
    line-height: 13px;
  }
  
  .section-title {
    margin-top: 0;
  }
  
  .title-text {
    font-size: 20px;
  }
  
  .skeleton-item {
    height: 280px;
  }
}

@media (max-width: 480px) {
  
  .category-tabs {
    gap: 10px;
  }
  
  .category-tab {
    width: 80px;
    height: 36px;
    font-size: 11px;
  }
  
  .favorites-list {
    grid-template-columns: repeat(1, 1fr);
    gap: 12px;
  }
  
  .favorite-item {
    height: 260px;
  }
  
  .favorite-title {
    font-size: 13px;
    line-height: 15px;
  }
  
  .action-buttons {
    gap: 4px;
  }
  
  .tag-button,
  .remove-button {
    height: 28px;
  }
  
  .tag-button span,
  .remove-button span {
    font-size: 10px;
    line-height: 12px;
  }
  
  .section-title {
    margin-top: 0;
  }
  
  .title-text {
    font-size: 18px;
  }
  
  .skeleton-item {
    height: 260px;
  }
}
</style> 