<template>
  <div class="teacher-dashboard">
    <!-- 欢迎横幅 -->
    <div class="welcome-banner">
      <div class="banner-decoration">
        <div class="deco-circle c1"></div>
        <div class="deco-circle c2"></div>
        <div class="deco-circle c3"></div>
        <div class="deco-shape star">
          <StarFilled />
        </div>
        <div class="deco-shape book">
          <BookOutlined />
        </div>
      </div>
      <div class="banner-content">
        <div class="welcome-text">
          <h1 class="welcome-title">你好，老师！</h1>
          <p class="welcome-subtitle">今天也要开启美妙的阅读之旅哦～</p>
        </div>
        <div class="welcome-date">
          <CalendarOutlined class="date-icon" />
          <span class="date-text">{{ currentDate }}</span>
        </div>
      </div>
    </div>

    <!-- 统计卡片 -->
    <div class="stats-section">
      <div class="stats-grid">
        <div class="stat-card class-card">
          <div class="stat-icon-wrapper orange">
            <HomeOutlined />
          </div>
          <div class="stat-info">
            <div class="stat-value">{{ stats.classCount }}</div>
            <div class="stat-label">我的班级</div>
          </div>
        </div>
        <div class="stat-card student-card">
          <div class="stat-icon-wrapper green">
            <TeamOutlined />
          </div>
          <div class="stat-info">
            <div class="stat-value">{{ stats.studentCount }}</div>
            <div class="stat-label">我的学生</div>
          </div>
        </div>
        <div class="stat-card lesson-card">
          <div class="stat-icon-wrapper blue">
            <ReadOutlined />
          </div>
          <div class="stat-info">
            <div class="stat-value">{{ stats.lessonCount }}</div>
            <div class="stat-label">授课次数</div>
          </div>
        </div>
        <div class="stat-card course-card">
          <div class="stat-icon-wrapper purple">
            <AppstoreOutlined />
          </div>
          <div class="stat-info">
            <div class="stat-value">{{ stats.courseCount }}</div>
            <div class="stat-label">使用课程</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 统计图表 -->
    <div class="charts-section">
      <div class="content-card trend-card">
        <div class="card-header">
          <div class="card-title">
            <div class="title-icon-wrapper chart">
              <LineChartOutlined />
            </div>
            <span>授课趋势</span>
          </div>
        </div>
        <div class="card-body" :class="{ 'is-loading': trendLoading }">
          <a-spin v-if="trendLoading" />
          <div v-else ref="trendChartRef" class="chart-container"></div>
        </div>
      </div>
      <div class="content-card usage-card">
        <div class="card-header">
          <div class="card-title">
            <div class="title-icon-wrapper chart">
              <PieChartOutlined />
            </div>
            <span>课程使用</span>
          </div>
        </div>
        <div class="card-body" :class="{ 'is-loading': usageLoading }">
          <a-spin v-if="usageLoading" />
          <div v-else ref="usageChartRef" class="chart-container"></div>
        </div>
      </div>
    </div>

    <!-- 主内容区域 -->
    <div class="main-content">
      <!-- 今日课程 -->
      <div class="content-card today-lessons-card">
        <div class="card-header">
          <div class="card-title">
            <div class="title-icon-wrapper sun">
              <ClockCircleOutlined />
            </div>
            <span>今日课程</span>
          </div>
          <a-button type="link" class="view-all-btn" @click="router.push('/teacher/lessons')">
            查看全部 <RightOutlined />
          </a-button>
        </div>
        <div class="card-body" :class="{ 'is-loading': loading }">
          <a-spin :spinning="loading">
            <div v-if="todayLessons.length === 0" class="empty-state">
              <div class="empty-icon-wrapper">
                <InboxOutlined />
              </div>
              <p class="empty-text">今天没有安排课程</p>
              <p class="empty-hint">快去课程中心备课吧～</p>
            </div>
            <div v-else class="lesson-list">
              <div
                v-for="lesson in todayLessons"
                :key="lesson.id"
                class="lesson-item"
                :class="{ 'finished': lesson.status === 'FINISHED' }"
              >
                <div class="lesson-time">
                  <div class="time-value">{{ formatTime(lesson.plannedDatetime) }}</div>
                  <div class="time-duration">{{ lesson.duration }}分钟</div>
                </div>
                <div class="lesson-info">
                  <div class="lesson-name">{{ lesson.courseName }}</div>
                  <div class="lesson-class">
                    <EnvironmentOutlined />
                    <span>{{ lesson.className }}</span>
                  </div>
                </div>
                <div class="lesson-action">
                  <button
                    v-if="lesson.status === 'FINISHED'"
                    class="action-btn finished"
                    disabled
                  >
                    <CheckOutlined /> 已结束
                  </button>
                  <button
                    v-else
                    class="action-btn start"
                    @click="startLesson(lesson)"
                  >
                    <PlayCircleOutlined /> 开始上课
                  </button>
                </div>
              </div>
            </div>
          </a-spin>
        </div>
      </div>

      <!-- 推荐课程 -->
      <div class="content-card recommend-card">
        <div class="card-header">
          <div class="card-title">
            <div class="title-icon-wrapper bulb">
              <BulbOutlined />
            </div>
            <span>推荐课程</span>
          </div>
          <a-button type="link" class="view-all-btn" @click="router.push('/teacher/courses')">
            查看全部 <RightOutlined />
          </a-button>
        </div>
        <div class="card-body" :class="{ 'is-loading': loading }">
          <a-spin :spinning="loading">
            <div v-if="recommendedCourses.length === 0" class="empty-state">
              <div class="empty-icon-wrapper">
                <SearchOutlined />
              </div>
              <p class="empty-text">暂无推荐课程</p>
            </div>
            <div v-else class="recommend-list">
              <div
                v-for="course in recommendedCourses"
                :key="course.id"
                class="recommend-item"
                @click="viewCourse(course)"
              >
                <div class="recommend-cover">
                  <img
                    v-if="course.coverImagePath"
                    :src="getImageUrl(course.coverImagePath)"
                    class="cover-img"
                  />
                  <div v-else class="cover-placeholder">
                    <BookFilled />
                  </div>
                  <div class="duration-tag">{{ course.duration }}分钟</div>
                </div>
                <div class="recommend-info">
                  <div class="recommend-name">{{ course.name }}</div>
                  <div class="recommend-meta">
                    <span class="meta-item">
                      <FireOutlined /> {{ course.usageCount }}次使用
                    </span>
                    <span v-if="course.avgRating > 0" class="meta-item">
                      <StarFilled class="star-icon" /> {{ course.avgRating.toFixed(1) }}
                    </span>
                  </div>
                </div>
              </div>
            </div>
          </a-spin>
        </div>
      </div>
    </div>

    <!-- 近期活动 -->
    <div class="activity-section">
      <div class="content-card activity-card">
        <div class="card-header">
          <div class="card-title">
            <div class="title-icon-wrapper list">
              <UnorderedListOutlined />
            </div>
            <span>近期活动</span>
          </div>
        </div>
        <div class="card-body" :class="{ 'is-loading': loading }">
          <a-spin :spinning="loading">
            <div v-if="recentActivities.length === 0" class="empty-state-horizontal">
              <div class="empty-icon-wrapper small">
                <FileTextOutlined />
              </div>
              <p class="empty-text">暂无近期活动</p>
            </div>
            <div v-else class="activity-timeline">
              <div
                v-for="(item, index) in recentActivities"
                :key="item.id"
                class="activity-item"
                :class="'type-' + item.type"
              >
                <div class="activity-dot">
                  <component :is="getActivityIcon(item.type)" />
                </div>
                <div class="activity-content">
                  <div class="activity-text">{{ item.description }}</div>
                  <div class="activity-time">{{ item.time }}</div>
                </div>
              </div>
            </div>
          </a-spin>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, computed, nextTick, onUnmounted } from 'vue';
import { useRouter } from 'vue-router';
import { message } from 'ant-design-vue';
import * as echarts from 'echarts';
import {
  HomeOutlined,
  TeamOutlined,
  ReadOutlined,
  AppstoreOutlined,
  CalendarOutlined,
  BookOutlined,
  BookFilled,
  StarFilled,
  EnvironmentOutlined,
  PlayCircleOutlined,
  CheckOutlined,
  BulbOutlined,
  SearchOutlined,
  FireOutlined,
  InboxOutlined,
  RightOutlined,
  UnorderedListOutlined,
  FileTextOutlined,
  MessageOutlined,
  UserOutlined,
  FolderOutlined,
  ClockCircleOutlined,
  LineChartOutlined,
  PieChartOutlined,
} from '@ant-design/icons-vue';
import {
  getTeacherDashboard,
  getTeacherLessonTrend,
  getTeacherCourseUsage,
} from '@/api/teacher';
import type { TeacherLessonTrendItem, TeacherCourseUsageItem } from '@/api/teacher';

const router = useRouter();

const loading = ref(false);
const trendLoading = ref(false);
const usageLoading = ref(false);

// Chart refs
const trendChartRef = ref<HTMLElement>();
const usageChartRef = ref<HTMLElement>();
let trendChart: echarts.ECharts | null = null;
let usageChart: echarts.ECharts | null = null;

// Chart data
const lessonTrendData = ref<TeacherLessonTrendItem[]>([]);
const courseUsageData = ref<TeacherCourseUsageItem[]>([]);

const stats = ref({
  classCount: 0,
  studentCount: 0,
  lessonCount: 0,
  courseCount: 0,
});

const currentDate = computed(() => {
  const now = new Date();
  const weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
  const month = now.getMonth() + 1;
  const date = now.getDate();
  const day = weekDays[now.getDay()];
  return `${month}月${date}日 ${day}`;
});

interface TodayLesson {
  id: number;
  courseId: number;
  courseName: string;
  pictureBookName?: string;
  classId: number;
  className: string;
  plannedDatetime: string;
  status: string;
  duration: number;
}

interface RecommendedCourse {
  id: number;
  name: string;
  pictureBookName?: string;
  coverImagePath?: string;
  duration: number;
  usageCount: number;
  avgRating: number;
  gradeTags: string[];
}

interface RecentActivity {
  id: number;
  type: string;
  description: string;
  time: string;
}

const todayLessons = ref<TodayLesson[]>([]);
const recommendedCourses = ref<RecommendedCourse[]>([]);
const recentActivities = ref<RecentActivity[]>([]);

const getImageUrl = (path: string) => {
  if (!path) return '';
  if (path.startsWith('http')) return path;
  return `${import.meta.env.VITE_SERVER_BASE_URL || 'http://localhost:3000'}${path}`;
};

const formatTime = (datetime: string) => {
  const date = new Date(datetime);
  const hours = date.getHours().toString().padStart(2, '0');
  const minutes = date.getMinutes().toString().padStart(2, '0');
  return `${hours}:${minutes}`;
};

const formatActivityTime = (time: string) => {
  const date = new Date(time);
  const now = new Date();
  const diff = now.getTime() - date.getTime();

  const minutes = Math.floor(diff / 60000);
  const hours = Math.floor(diff / 3600000);
  const days = Math.floor(diff / 86400000);

  if (minutes < 60) {
    return `${minutes}分钟前`;
  } else if (hours < 24) {
    return `${hours}小时前`;
  } else if (days < 7) {
    return `${days}天前`;
  } else {
    return date.toLocaleDateString();
  }
};

const getActivityIcon = (type: string) => {
  const iconMap: Record<string, any> = {
    lesson: ReadOutlined,
    feedback: MessageOutlined,
    student: UserOutlined,
    course: FolderOutlined,
  };
  return iconMap[type] || FileTextOutlined;
};

// 初始化授课趋势图表
const initTrendChart = (data: TeacherLessonTrendItem[]) => {
  if (!trendChartRef.value) return;

  if (trendChart) {
    trendChart.dispose();
  }

  trendChart = echarts.init(trendChartRef.value);

  // 如果没有数据，显示空状态
  if (!data || data.length === 0) {
    trendChart.setOption({
      title: {
        text: '暂无数据',
        left: 'center',
        top: 'center',
        textStyle: {
          color: '#999',
          fontSize: 14,
        },
      },
    });
    return;
  }

  const option: echarts.EChartsOption = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
      },
    },
    legend: {
      data: ['授课次数', '平均评分'],
      top: 0,
      right: 10,
      itemWidth: 16,
      itemHeight: 10,
      textStyle: {
        fontSize: 12,
        color: '#666',
      },
    },
    grid: {
      left: '3%',
      right: '4%',
      top: '18%',
      bottom: '8%',
      containLabel: true,
    },
    xAxis: {
      type: 'category',
      data: data.map((d) => d.month),
      axisLine: {
        lineStyle: {
          color: '#E5E7EB',
        },
      },
    },
    yAxis: [
      {
        type: 'value',
        name: '授课次数',
        position: 'left',
        splitLine: {
          lineStyle: {
            color: '#F3F4F6',
          },
        },
      },
      {
        type: 'value',
        name: '平均评分',
        position: 'right',
        min: 0,
        max: 5,
        splitLine: {
          show: false,
        },
      },
    ],
    series: [
      {
        name: '授课次数',
        type: 'bar',
        data: data.map((d) => d.lessonCount),
        itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: '#FF8C42' },
            { offset: 1, color: '#FFB347' },
          ]),
          borderRadius: [4, 4, 0, 0],
        },
      },
      {
        name: '平均评分',
        type: 'line',
        yAxisIndex: 1,
        data: data.map((d) => d.avgRating),
        smooth: true,
        itemStyle: {
          color: '#52c41a',
        },
        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: 'rgba(82, 196, 26, 0.3)' },
            { offset: 1, color: 'rgba(82, 196, 26, 0)' },
          ]),
        },
      },
    ],
  };

  trendChart.setOption(option);
};

// 初始化课程使用饼图
const initUsageChart = (data: TeacherCourseUsageItem[]) => {
  if (!usageChartRef.value) return;

  if (usageChart) {
    usageChart.dispose();
  }

  usageChart = echarts.init(usageChartRef.value);

  const option: echarts.EChartsOption = {
    tooltip: {
      trigger: 'item',
      formatter: '{b}: {c}次 ({d}%)',
    },
    legend: {
      orient: 'vertical',
      right: '5%',
      top: 'center',
    },
    series: [
      {
        type: 'pie',
        radius: ['40%', '70%'],
        center: ['35%', '50%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 8,
          borderColor: '#fff',
          borderWidth: 2,
        },
        label: {
          show: false,
          position: 'center',
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 16,
            fontWeight: 'bold',
          },
        },
        labelLine: {
          show: false,
        },
        data: data.map((item, index) => ({
          ...item,
          itemStyle: {
            color: [
              '#FF8C42',
              '#52c41a',
              '#1890ff',
              '#722ed1',
              '#fa8c16',
              '#eb2f96',
            ][index % 6],
          },
        })),
      },
    ],
  };

  usageChart.setOption(option);
};

// 加载授课趋势数据
const loadTrendData = async () => {
  trendLoading.value = true;
  try {
    const data = await getTeacherLessonTrend(6);
    lessonTrendData.value = data;
  } catch (error) {
    console.error('Failed to load trend data:', error);
  } finally {
    trendLoading.value = false;
  }
  // 在 loading 结束后初始化图表
  await nextTick();
  if (lessonTrendData.value.length > 0) {
    initTrendChart(lessonTrendData.value);
  }
};

// 加载课程使用数据
const loadUsageData = async () => {
  usageLoading.value = true;
  try {
    const data = await getTeacherCourseUsage();
    courseUsageData.value = data;
  } catch (error) {
    console.error('Failed to load usage data:', error);
  } finally {
    usageLoading.value = false;
  }
  // 在 loading 结束后初始化图表
  await nextTick();
  if (courseUsageData.value.length > 0) {
    initUsageChart(courseUsageData.value);
  }
};

// 窗口大小变化时重绘图表
const handleResize = () => {
  trendChart?.resize();
  usageChart?.resize();
};

const loadDashboard = async () => {
  loading.value = true;
  try {
    const data = await getTeacherDashboard();
    stats.value = data.stats;
    todayLessons.value = data.todayLessons || [];
    recommendedCourses.value = data.recommendedCourses || [];
    recentActivities.value = (data.recentActivities || []).map((item: RecentActivity) => ({
      ...item,
      time: formatActivityTime(item.time),
    }));
  } catch (error: any) {
    console.error('Failed to load dashboard:', error);
    message.error(error?.response?.data?.message || '加载数据失败');
  } finally {
    loading.value = false;
  }
};

const startLesson = (lesson: TodayLesson) => {
  router.push(`/teacher/lessons/${lesson.id}`);
};

const viewCourse = (course: RecommendedCourse) => {
  router.push(`/teacher/courses/${course.id}`);
};

onMounted(() => {
  loadDashboard();
  loadTrendData();
  loadUsageData();

  window.addEventListener('resize', handleResize);
});

onUnmounted(() => {
  window.removeEventListener('resize', handleResize);
  trendChart?.dispose();
  usageChart?.dispose();
});
</script>

<style scoped>
/* 整体布局 */
.teacher-dashboard {
  min-height: calc(100vh - 120px);
  background: linear-gradient(180deg, #FFF8F0 0%, #FFFFFF 100%);
  padding: 24px;
  border-radius: 16px;
}

/* 欢迎横幅 */
.welcome-banner {
  position: relative;
  background: linear-gradient(135deg, #FF8C42 0%, #FFB347 100%);
  border-radius: 20px;
  padding: 28px 32px;
  margin-bottom: 24px;
  overflow: hidden;
}

.banner-decoration {
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.deco-circle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
}

.deco-circle.c1 {
  width: 140px;
  height: 140px;
  top: -40px;
  right: 60px;
}

.deco-circle.c2 {
  width: 80px;
  height: 80px;
  top: 50px;
  right: 150px;
}

.deco-circle.c3 {
  width: 50px;
  height: 50px;
  bottom: -15px;
  right: 100px;
}

.deco-shape {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.deco-shape.star {
  top: 20px;
  right: 30px;
  font-size: 16px;
}

.deco-shape.book {
  bottom: 15px;
  right: 200px;
  font-size: 18px;
}

.banner-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 1;
}

.welcome-title {
  font-size: 26px;
  font-weight: 700;
  color: #fff;
  margin: 0 0 6px;
}

.welcome-subtitle {
  font-size: 15px;
  color: rgba(255, 255, 255, 0.9);
  margin: 0;
}

.welcome-date {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.2);
  padding: 10px 20px;
  border-radius: 24px;
}

.date-icon {
  font-size: 16px;
  color: white;
}

.date-text {
  font-size: 15px;
  color: #fff;
  font-weight: 500;
}

/* 统计卡片 */
.stats-section {
  margin-bottom: 24px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.stat-card {
  position: relative;
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  transition: all 0.3s ease;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(255, 140, 66, 0.15);
}

.stat-icon-wrapper {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.stat-icon-wrapper.orange {
  background: linear-gradient(135deg, #FFE8D6 0%, #FFF0E6 100%);
  color: #FF8C42;
}

.stat-icon-wrapper.green {
  background: linear-gradient(135deg, #D9F7BE 0%, #E8FFD4 100%);
  color: #52c41a;
}

.stat-icon-wrapper.blue {
  background: linear-gradient(135deg, #D6E4FF 0%, #E8F0FF 100%);
  color: #1890ff;
}

.stat-icon-wrapper.purple {
  background: linear-gradient(135deg, #E8DAFF 0%, #F3EFFF 100%);
  color: #722ed1;
}

.stat-info {
  position: relative;
  z-index: 1;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: #333;
  line-height: 1.2;
}

.stat-label {
  font-size: 14px;
  color: #888;
  margin-top: 4px;
}

.stat-card.class-card { border-left: 4px solid #FF8C42; }
.stat-card.student-card { border-left: 4px solid #52c41a; }
.stat-card.lesson-card { border-left: 4px solid #1890ff; }
.stat-card.course-card { border-left: 4px solid #722ed1; }

/* 图表区域 */
.charts-section {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 24px;
  margin-bottom: 24px;
}

.trend-card {
  grid-column: 1;
}

.usage-card {
  grid-column: 2;
}

.chart-container {
  width: 100%;
  height: 280px;
}

.title-icon-wrapper.chart {
  background: linear-gradient(135deg, #E8F0FF 0%, #F0F5FF 100%);
  color: #1890ff;
}

/* 主内容区域 */
.main-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

/* 内容卡片 */
.content-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #F5F5F5;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 600;
  color: #333;
}

.title-icon-wrapper {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.title-icon-wrapper.sun {
  background: linear-gradient(135deg, #FFF3CD 0%, #FFFBEB 100%);
  color: #FF8C42;
}

.title-icon-wrapper.bulb {
  background: linear-gradient(135deg, #FFF3CD 0%, #FFFBEB 100%);
  color: #FFB347;
}

.title-icon-wrapper.list {
  background: linear-gradient(135deg, #E8F0FF 0%, #F0F5FF 100%);
  color: #1890ff;
}

.view-all-btn {
  font-size: 13px;
  color: #FF8C42;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.view-all-btn:hover {
  color: #E67635;
}

.card-body {
  padding: 16px;
  min-height: 200px;
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 40px 20px;
}

.empty-state-horizontal {
  text-align: center;
  padding: 30px 20px;
}

.empty-icon-wrapper {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, #F5F5F5 0%, #FAFAFA 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #BFBFBF;
}

.empty-icon-wrapper.small {
  width: 56px;
  height: 56px;
  font-size: 22px;
}

.empty-text {
  font-size: 15px;
  color: #666;
  margin: 0 0 4px;
}

.empty-hint {
  font-size: 13px;
  color: #999;
  margin: 0;
}

/* 今日课程列表 */
.lesson-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lesson-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #FFF8F0 0%, #FFFBF5 100%);
  border-radius: 12px;
  transition: all 0.3s ease;
  border: 1px solid transparent;
}

.lesson-item:hover {
  border-color: #FFD4B8;
  transform: translateX(4px);
}

.lesson-item.finished {
  opacity: 0.6;
  background: #F5F5F5;
}

.lesson-time {
  text-align: center;
  min-width: 60px;
}

.time-value {
  font-size: 18px;
  font-weight: 600;
  color: #FF8C42;
}

.time-duration {
  font-size: 12px;
  color: #999;
  margin-top: 2px;
}

.lesson-info {
  flex: 1;
  min-width: 0;
}

.lesson-name {
  font-size: 15px;
  font-weight: 500;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lesson-class {
  font-size: 13px;
  color: #888;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.lesson-action {
  flex-shrink: 0;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.action-btn.start {
  background: linear-gradient(135deg, #FF8C42 0%, #FFB347 100%);
  color: #fff;
}

.action-btn.start:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(255, 140, 66, 0.3);
}

.action-btn.finished {
  background: #E8E8E8;
  color: #999;
  cursor: not-allowed;
}

/* 推荐课程列表 */
.recommend-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.recommend-item {
  display: flex;
  gap: 14px;
  padding: 12px;
  background: #FAFAFA;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid transparent;
}

.recommend-item:hover {
  background: #FFF8F0;
  border-color: #FFD4B8;
}

.recommend-cover {
  position: relative;
  width: 80px;
  height: 60px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}

.cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #FFE4C9 0%, #FFF0E0 100%);
  font-size: 24px;
  color: #FF8C42;
}

.duration-tag {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
}

.recommend-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.recommend-name {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recommend-meta {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #888;
}

.star-icon {
  color: #FFB347;
  font-size: 11px;
}

/* 活动区域 */
.activity-section {
  margin-bottom: 24px;
}

.activity-card .card-body {
  min-height: auto;
}

.activity-timeline {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.activity-item {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.activity-dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}

.activity-item.type-lesson .activity-dot {
  background: linear-gradient(135deg, #FFE4C9 0%, #FFF0E0 100%);
  color: #FF8C42;
}

.activity-item.type-feedback .activity-dot {
  background: linear-gradient(135deg, #D6E4FF 0%, #E8F0FF 100%);
  color: #1890ff;
}

.activity-item.type-student .activity-dot {
  background: linear-gradient(135deg, #D9F7BE 0%, #E8FFD4 100%);
  color: #52c41a;
}

.activity-item.type-course .activity-dot {
  background: linear-gradient(135deg, #FFE7BA 0%, #FFF1D6 100%);
  color: #FA8C16;
}

.activity-content {
  flex: 1;
  padding-top: 6px;
}

.activity-text {
  font-size: 14px;
  color: #333;
  line-height: 1.5;
}

.activity-time {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
}

/* 响应式 */
@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .charts-section {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 992px) {
  .main-content {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .teacher-dashboard {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .charts-section {
    grid-template-columns: 1fr;
  }

  .banner-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .welcome-date {
    align-self: flex-start;
  }
}
</style>
