<template>
  <div class="report-view">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-content">
        <div class="header-title">
          <div class="title-icon-wrapper">
            <BarChartOutlined class="title-icon" />
          </div>
          <div class="title-text">
            <h2>数据报告</h2>
            <p>查看学校教学数据和统计分析</p>
          </div>
        </div>
        <div class="header-actions">
          <a-range-picker
            v-model:value="dateRange"
            :placeholder="['开始日期', '结束日期']"
            style="width: 240px;"
            @change="handleDateRangeChange"
          />
          <a-button class="export-btn" @click="handleExport">
            <DownloadOutlined class="btn-icon" />
            导出报告
          </a-button>
        </div>
      </div>
    </div>

    <!-- 概览卡片 -->
    <a-spin :spinning="loading">
      <div class="overview-cards">
        <div class="overview-card">
          <div class="card-icon" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">
            <SolutionOutlined />
          </div>
          <div class="card-content">
            <div class="card-value">{{ overviewData.totalTeachers }}</div>
            <div class="card-label">教师总数</div>
          </div>
        </div>
        <div class="overview-card">
          <div class="card-icon" style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);">
            <UserOutlined />
          </div>
          <div class="card-content">
            <div class="card-value">{{ overviewData.totalStudents }}</div>
            <div class="card-label">学生总数</div>
          </div>
        </div>
        <div class="overview-card">
          <div class="card-icon" style="background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);">
            <HomeOutlined />
          </div>
          <div class="card-content">
            <div class="card-value">{{ overviewData.totalClasses }}</div>
            <div class="card-label">班级总数</div>
          </div>
        </div>
        <div class="overview-card">
          <div class="card-icon" style="background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);">
            <BookOutlined />
          </div>
          <div class="card-content">
            <div class="card-value">{{ overviewData.monthlyLessons }}</div>
            <div class="card-label">本月授课</div>
          </div>
        </div>
      </div>
    </a-spin>

    <!-- 标签页 -->
    <div class="report-tabs">
      <div class="tab-header">
        <div v-for="tab in tabs" :key="tab.key" class="tab-item" :class="{ 'active': activeTab === tab.key }"
          @click="activeTab = tab.key">
          <BarChartOutlined v-if="tab.icon === 'bar-chart'" class="tab-icon" />
          <SolutionOutlined v-else-if="tab.icon === 'solution'" class="tab-icon" />
          <ReadOutlined v-else-if="tab.icon === 'read'" class="tab-icon" />
          <TeamOutlined v-else-if="tab.icon === 'team'" class="tab-icon" />
          <span class="tab-label">{{ tab.label }}</span>
        </div>
      </div>

      <div class="tab-content">
        <!-- 整体概览 -->
        <div v-if="activeTab === 'overview'" class="overview-content">
          <a-spin :spinning="chartLoading">
            <div class="chart-grid">
              <div class="chart-card">
                <div class="chart-header">
                  <LineChartOutlined class="chart-icon" />
                  <h4>课程使用趋势</h4>
                </div>
                <div class="lesson-trend-chart">
                  <div class="trend-bars">
                    <div
                      v-for="(item, index) in lessonTrendData"
                      :key="index"
                      class="trend-bar-wrapper"
                    >
                      <div class="trend-value">{{ item.lessonCount }}</div>
                      <div
                        class="trend-bar"
                        :style="{
                          height: maxLessonCount > 0 ? (item.lessonCount / maxLessonCount * 100) + '%' : '8px',
                          background: item.lessonCount > 0 ? 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)' : '#e0e0e0'
                        }"
                      ></div>
                      <div class="trend-label">{{ item.date }}</div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="chart-card">
                <div class="chart-header">
                  <AimOutlined class="chart-icon" />
                  <h4>教师活跃度</h4>
                </div>
                <div class="teacher-activity-chart">
                  <div class="circle-chart">
                    <svg viewBox="0 0 100 100">
                      <circle cx="50" cy="50" r="40" fill="none" stroke="#F0F0F0" stroke-width="12" />
                      <circle
                        cx="50" cy="50" r="40" fill="none"
                        stroke="url(#gradient1)"
                        stroke-width="12"
                        :stroke-dasharray="activeRateProgress"
                        stroke-linecap="round"
                        transform="rotate(-90 50 50)"
                      />
                      <defs>
                        <linearGradient id="gradient1" x1="0%" y1="0%" x2="100%" y2="0%">
                          <stop offset="0%" style="stop-color:#667eea" />
                          <stop offset="100%" style="stop-color:#764ba2" />
                        </linearGradient>
                      </defs>
                    </svg>
                    <div class="circle-text">
                      <span class="percent">{{ teacherActiveRate }}%</span>
                      <span class="label">活跃率</span>
                    </div>
                  </div>
                  <div class="activity-stats">
                    <div class="stat-item">
                      <span class="stat-label">活跃教师</span>
                      <span class="stat-value">{{ teacherStats.filter(t => t.lessonCount > 0).length }}人</span>
                    </div>
                    <div class="stat-item">
                      <span class="stat-label">教师总数</span>
                      <span class="stat-value">{{ overviewData.totalTeachers }}人</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </a-spin>
        </div>

        <!-- 教师报告 -->
        <div v-if="activeTab === 'teacher'" class="table-content">
          <div class="teacher-cards" v-if="teacherData.length > 0">
            <div v-for="teacher in teacherData" :key="teacher.teacherId" class="teacher-report-card">
              <div class="teacher-header">
                <div class="teacher-avatar">
                  <SolutionOutlined />
                </div>
                <div class="teacher-info">
                  <div class="teacher-name">{{ teacher.teacherName }}</div>
                  <div class="teacher-rating">
                    <StarFilled v-for="i in 5" :key="i" class="star"
                      :class="{ 'filled': i <= Math.round(teacher.averageRating) }" />
                    <span class="rating-value">{{ teacher.averageRating.toFixed(1) }}</span>
                  </div>
                </div>
              </div>
              <div class="teacher-stats">
                <div class="stat-item">
                  <BookOutlined class="stat-icon" />
                  <span class="stat-value">{{ teacher.lessonCount }}</span>
                  <span class="stat-label">授课次数</span>
                </div>
                <div class="stat-item">
                  <ReadOutlined class="stat-icon" />
                  <span class="stat-value">{{ teacher.taskCount }}</span>
                  <span class="stat-label">任务数</span>
                </div>
                <div class="stat-item">
                  <AimOutlined class="stat-icon" />
                  <span class="stat-value">{{ teacher.lastLessonTime ? '活跃' : '未活跃' }}</span>
                  <span class="stat-label">最后活跃</span>
                </div>
              </div>
              <div class="teacher-action">
                <a-button type="link" @click="viewTeacherDetail(teacher)">
                  <FileTextOutlined style="margin-right: 4px;" />
                  查看详情
                </a-button>
              </div>
            </div>
          </div>
          <a-empty v-else description="暂无教师数据" />
        </div>

        <!-- 课程报告 -->
        <div v-if="activeTab === 'course'" class="table-content">
          <div class="course-report-list" v-if="courseData.length > 0">
            <div v-for="(course, index) in courseData" :key="course.courseId" class="course-report-item">
              <div class="course-rank" :class="'rank-' + (index + 1)">
                <TrophyOutlined v-if="index < 3" class="rank-icon" :class="'rank-' + (index + 1)" />
                <span v-else>{{ index + 1 }}</span>
              </div>
              <div class="course-info">
                <div class="course-name">{{ course.courseName }}</div>
                <div class="course-stats-inline">
                  <span>
                    <BookOutlined style="margin-right: 4px;" />授课{{ course.lessonCount }}次
                  </span>
                  <span>
                    <TeamOutlined style="margin-right: 4px;" />{{ course.studentCount }}名学生
                  </span>
                  <span>
                    <AimOutlined style="margin-right: 4px;" />完成率{{ course.completionRate?.toFixed(0) || 0 }}%
                  </span>
                </div>
              </div>
              <div class="course-rating">
                <StarFilled class="rating-stars" />
                <span class="rating-value">{{ course.averageRating.toFixed(1) }}</span>
              </div>
              <div class="course-action">
                <a-button type="link" size="small" @click="viewCourseDetail(course)">
                  详情
                </a-button>
              </div>
            </div>
          </div>
          <a-empty v-else description="暂无课程数据" />
        </div>

        <!-- 学生报告 -->
        <div v-if="activeTab === 'student'" class="table-content">
          <div class="student-report-grid" v-if="studentData.length > 0">
            <div v-for="student in studentData" :key="student.studentId" class="student-report-card">
              <div class="student-header">
                <div class="student-avatar">
                  <UserOutlined />
                </div>
                <div class="student-info">
                  <div class="student-name">{{ student.studentName }}</div>
                  <div class="student-class">{{ student.className }}</div>
                </div>
              </div>
              <div class="student-stats">
                <div class="stat-row">
                  <span class="stat-label">
                    <BookOutlined style="margin-right: 4px;" />完成任务
                  </span>
                  <span class="stat-value">{{ student.taskCount }} 次</span>
                </div>
                <div class="stat-row">
                  <span class="stat-label">
                    <FileTextOutlined style="margin-right: 4px;" />成长记录
                  </span>
                  <span class="stat-value">{{ student.growthRecordCount }} 条</span>
                </div>
                <div class="stat-row">
                  <span class="stat-label">
                    <AimOutlined style="margin-right: 4px;" />出勤率
                  </span>
                  <div class="progress-mini">
                    <div class="progress-fill" :style="{ width: student.attendanceRate + '%' }"></div>
                  </div>
                  <span class="stat-value">{{ student.attendanceRate?.toFixed(0) || 0 }}%</span>
                </div>
              </div>
            </div>
          </div>
          <a-empty v-else description="暂无学生数据" />
        </div>
      </div>
    </div>

    <!-- 教师详情弹窗 -->
    <a-modal v-model:open="teacherDetailVisible" :title="`${selectedTeacher?.teacherName} - 教师报告详情`" width="600px"
      :footer="null">
      <div v-if="selectedTeacher" class="detail-content">
        <div class="detail-header">
          <div class="detail-avatar">
            <SolutionOutlined />
          </div>
          <div class="detail-info">
            <h3>{{ selectedTeacher.teacherName }}</h3>
            <div class="detail-rating">
              <StarFilled v-for="i in 5" :key="i" :class="{ 'filled': i <= Math.round(selectedTeacher.averageRating) }" />
              <span class="rating-text">{{ selectedTeacher.averageRating.toFixed(1) }} 分</span>
            </div>
          </div>
        </div>
        <a-divider />
        <div class="detail-stats">
          <div class="detail-stat-item">
            <div class="stat-number">{{ selectedTeacher.lessonCount }}</div>
            <div class="stat-label">授课次数</div>
          </div>
          <div class="detail-stat-item">
            <div class="stat-number">{{ selectedTeacher.taskCount }}</div>
            <div class="stat-label">任务完成数</div>
          </div>
          <div class="detail-stat-item">
            <div class="stat-number">{{ selectedTeacher.lastLessonTime ? '活跃' : '未活跃' }}</div>
            <div class="stat-label">最后活跃</div>
          </div>
        </div>
        <a-divider />
        <div class="detail-section">
          <h4>
            <BookOutlined style="margin-right: 8px;" />教学概况
          </h4>
          <p class="detail-desc">
            {{ selectedTeacher.teacherName }} 老师共完成 {{ selectedTeacher.lessonCount }} 次授课，
            参与 {{ selectedTeacher.taskCount }} 次任务评价。
            <template v-if="selectedTeacher.averageRating > 0">
              平均评分为 {{ selectedTeacher.averageRating.toFixed(1) }} 分，
              {{ selectedTeacher.averageRating >= 4.5 ? '教学效果优秀！' : selectedTeacher.averageRating >= 3.5 ? '教学效果良好。' : '继续努力！'
              }}
            </template>
            <template v-else>
              暂无评分数据。
            </template>
          </p>
        </div>
      </div>
    </a-modal>

    <!-- 课程详情弹窗 -->
    <a-modal v-model:open="courseDetailVisible" :title="`${selectedCourse?.courseName} - 课程报告详情`" width="600px"
      :footer="null">
      <div v-if="selectedCourse" class="detail-content">
        <div class="detail-header">
          <div class="detail-avatar course-avatar">
            <ReadOutlined />
          </div>
          <div class="detail-info">
            <h3>{{ selectedCourse.courseName }}</h3>
            <div class="detail-rating">
              <StarFilled v-for="i in 5" :key="i" :class="{ 'filled': i <= Math.round(selectedCourse.averageRating) }" />
              <span class="rating-text">{{ selectedCourse.averageRating.toFixed(1) }} 分</span>
            </div>
          </div>
        </div>
        <a-divider />
        <div class="detail-stats">
          <div class="detail-stat-item">
            <div class="stat-number">{{ selectedCourse.lessonCount }}</div>
            <div class="stat-label">授课次数</div>
          </div>
          <div class="detail-stat-item">
            <div class="stat-number">{{ selectedCourse.studentCount }}</div>
            <div class="stat-label">参与学生</div>
          </div>
          <div class="detail-stat-item">
            <div class="stat-number">{{ selectedCourse.completionRate?.toFixed(0) || 0 }}%</div>
            <div class="stat-label">完成率</div>
          </div>
        </div>
        <a-divider />
        <div class="detail-section">
          <h4>
            <ReadOutlined style="margin-right: 8px;" />课程概况
          </h4>
          <p class="detail-desc">
            《{{ selectedCourse.courseName }}》共被授课 {{ selectedCourse.lessonCount }} 次，
            累计覆盖 {{ selectedCourse.studentCount }} 名学生，
            课程完成率 {{ selectedCourse.completionRate?.toFixed(0) || 0 }}%。
            <template v-if="selectedCourse.averageRating > 0">
              课程平均评分为 {{ selectedCourse.averageRating.toFixed(1) }} 分，
              {{ selectedCourse.averageRating >= 4.5 ? '深受师生好评！' : selectedCourse.averageRating >= 3.5 ? '反馈良好。' : '有待改进。' }}
            </template>
            <template v-else>
              暂无评分数据。
            </template>
          </p>
        </div>
      </div>
    </a-modal>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue';
import { message } from 'ant-design-vue';
import dayjs, { Dayjs } from 'dayjs';
import {
  BarChartOutlined,
  DownloadOutlined,
  BookOutlined,
  SolutionOutlined,
  ReadOutlined,
  StarFilled,
  LineChartOutlined,
  AimOutlined,
  FileTextOutlined,
  TeamOutlined,
  UserOutlined,
  TrophyOutlined,
  HomeOutlined,
} from '@ant-design/icons-vue';
import {
  getReportOverview,
  getTeacherReports,
  getCourseReports,
  getStudentReports,
  getLessonTrend,
  getTeacherStats,
  type ReportOverview,
  type TeacherReport,
  type CourseReport,
  type StudentReport,
  type LessonTrendItem,
  type TeacherActivityItem,
} from '@/api/school';

const activeTab = ref('overview');
const dateRange = ref<[Dayjs, Dayjs] | undefined>(undefined);
const loading = ref(false);

const tabs = [
  { key: 'overview', label: '整体概览', icon: 'bar-chart' },
  { key: 'teacher', label: '教师报告', icon: 'solution' },
  { key: 'course', label: '课程报告', icon: 'read' },
  { key: 'student', label: '学生报告', icon: 'team' },
];

// 概览数据
const overviewData = ref<ReportOverview>({
  reportDate: '',
  totalTeachers: 0,
  totalStudents: 0,
  totalClasses: 0,
  monthlyLessons: 0,
  monthlyTasksCompleted: 0,
});

const teacherData = ref<TeacherReport[]>([]);
const courseData = ref<CourseReport[]>([]);
const studentData = ref<StudentReport[]>([]);

// 图表数据
const lessonTrendData = ref<LessonTrendItem[]>([]);
const teacherStats = ref<TeacherActivityItem[]>([]);
const chartLoading = ref(false);

// 计算课程趋势最高值用于柱状图比例
const maxLessonCount = computed(() => {
  if (lessonTrendData.value.length === 0) return 0;
  return Math.max(...lessonTrendData.value.map(item => item.lessonCount), 1);
});

// 计算教师活跃率
const teacherActiveRate = computed(() => {
  if (teacherStats.value.length === 0) return 0;
  // 需要获取教师总数来计算活跃率
  const activeTeachers = teacherStats.value.filter(t => t.lessonCount > 0).length;
  const totalTeachers = overviewData.value.totalTeachers || teacherStats.value.length;
  return Math.round((activeTeachers / totalTeachers) * 100);
});

// 计算环形进度条的 stroke-dasharray 值
const activeRateProgress = computed(() => {
  const circumference = 2 * Math.PI * 40; // r=40
  const progress = (teacherActiveRate.value / 100) * circumference;
  return `${progress} ${circumference - progress}`;
});

// 加载数据
const loadData = async () => {
  loading.value = true;
  chartLoading.value = true;
  try {
    const startDate = dateRange.value?.[0]?.format('YYYY-MM-DD');
    const endDate = dateRange.value?.[1]?.format('YYYY-MM-DD');

    console.log('加载数据，日期范围:', startDate, 'to', endDate);

    const [overview, teachers, courses, students, lessonTrend, teacherStatsData] = await Promise.all([
      getReportOverview(startDate, endDate),
      getTeacherReports(startDate, endDate),
      getCourseReports(startDate, endDate),
      getStudentReports(startDate, endDate),
      getLessonTrend(startDate, endDate),
      getTeacherStats(startDate, endDate, 10),
    ]);

    console.log('课程趋势数据:', lessonTrend);
    console.log('教师活跃度数据:', teacherStatsData);

    overviewData.value = overview;
    teacherData.value = teachers;
    courseData.value = courses;
    studentData.value = students;
    lessonTrendData.value = lessonTrend;
    teacherStats.value = teacherStatsData;
  } catch (error: any) {
    console.error('加载数据失败:', error);
    message.error(error.response?.data?.message || '加载数据失败');
  } finally {
    loading.value = false;
    chartLoading.value = false;
  }
};

// 教师详情弹窗
const teacherDetailVisible = ref(false);
const selectedTeacher = ref<TeacherReport | null>(null);

// 课程详情弹窗
const courseDetailVisible = ref(false);
const selectedCourse = ref<CourseReport | null>(null);

const viewTeacherDetail = (teacher: TeacherReport) => {
  selectedTeacher.value = teacher;
  teacherDetailVisible.value = true;
};

const viewCourseDetail = (course: CourseReport) => {
  selectedCourse.value = course;
  courseDetailVisible.value = true;
};

// 导出报告功能
const handleExport = () => {
  message.info('导出功能开发中，敬请期待...');
  // TODO: 实现导出功能，调用后端导出接口
};

// 设置默认日期范围为当月
const setDefaultDateRange = () => {
  const now = dayjs();
  const monthStart = now.startOf('month');
  const monthEnd = now.endOf('month');
  dateRange.value = [monthStart, monthEnd];
};

// 处理日期范围变化
const handleDateRangeChange = (dates: any) => {
  console.log('日期范围变化:', dates);
  if (dates && dates.length === 2) {
    dateRange.value = [dates[0], dates[1]];
    loadData();
  }
};

onMounted(() => {
  setDefaultDateRange();
  loadData();
});
</script>

<style scoped>
.report-view {
  min-height: 100vh;
  background: linear-gradient(180deg, #FFF8F0 0%, #FFFFFF 100%);
  padding: 24px;
}

/* 页面头部 */
.page-header {
  background: linear-gradient(135deg, #FF8C42 0%, #FFB347 100%);
  border-radius: 20px;
  padding: 24px 32px;
  margin-bottom: 24px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 16px;
}

.title-icon-wrapper {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.title-icon {
  font-size: 32px;
  color: white;
}

.title-text h2 {
  color: white;
  font-size: 24px;
  font-weight: 700;
  margin: 0;
}

.title-text p {
  color: rgba(255, 255, 255, 0.8);
  font-size: 14px;
  margin: 4px 0 0 0;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.export-btn {
  background: white;
  border: none;
  border-radius: 12px;
  color: #FF8C42;
  font-weight: 600;
}

.export-btn:hover {
  background: #FFF8F0;
  color: #FF7A2A;
}

.btn-icon {
  margin-right: 8px;
  font-size: 16px;
}

/* 概览卡片 */
.overview-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.overview-card {
  background: white;
  border-radius: 16px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.overview-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.card-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: white;
}

.card-value {
  font-size: 28px;
  font-weight: 700;
  color: #2D3436;
}

.card-label {
  font-size: 13px;
  color: #636E72;
  margin-top: 4px;
}

/* 标签页 */
.report-tabs {
  background: white;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.tab-header {
  display: flex;
  border-bottom: 1px solid #F0F0F0;
  padding: 0 24px;
}

.tab-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 24px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease;
  color: #636E72;
}

.tab-item:hover {
  color: #FF8C42;
}

.tab-item.active {
  color: #FF8C42;
  border-bottom-color: #FF8C42;
}

.tab-icon {
  font-size: 18px;
}

.tab-label {
  font-weight: 500;
}

.tab-content {
  padding: 24px;
}

/* 图表区域 */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.chart-card {
  background: #F8F9FA;
  border-radius: 16px;
  padding: 20px;
}

.chart-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.chart-icon {
  font-size: 20px;
  color: #FF8C42;
}

.chart-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #2D3436;
}

.chart-placeholder {
  height: 250px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

/* 课程使用趋势图表 */
.lesson-trend-chart {
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.trend-bars {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  width: 100%;
  height: 220px;
  padding: 0 10px;
  gap: 8px;
}

.trend-bar-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  position: relative;
  min-width: 30px;
}

.trend-bar {
  width: 24px;
  min-height: 4px;
  border-radius: 4px 4px 0 0;
  transition: all 0.3s ease;
  margin-bottom: 24px;
}

.trend-label {
  margin-top: 8px;
  font-size: 11px;
  color: #636E72;
  white-space: nowrap;
}

.trend-value {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 600;
  color: #2D3436;
  margin-bottom: 4px;
}

/* 教师活跃度图表 */
.teacher-activity-chart {
  height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.activity-stats {
  display: flex;
  gap: 32px;
  padding: 16px 24px;
  background: #F8F9FA;
  border-radius: 12px;
}

.activity-stats .stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.activity-stats .stat-label {
  font-size: 12px;
  color: #636E72;
}

.activity-stats .stat-value {
  font-size: 18px;
  font-weight: 600;
  color: #2D3436;
}

.circle-chart {
  position: relative;
  width: 180px;
  height: 180px;
}

.circle-chart svg {
  width: 100%;
  height: 100%;
}

.circle-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.circle-text .percent {
  display: block;
  font-size: 32px;
  font-weight: 700;
  color: #2D3436;
}

.circle-text .label {
  font-size: 12px;
  color: #636E72;
}

/* 教师报告卡片 */
.teacher-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.teacher-report-card {
  background: #F8F9FA;
  border-radius: 16px;
  padding: 20px;
}

.teacher-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.teacher-avatar {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: white;
}

.teacher-name {
  font-size: 16px;
  font-weight: 600;
  color: #2D3436;
}

.teacher-rating {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 4px;
}

.star {
  font-size: 12px;
  color: #D0D0D0;
}

.star.filled {
  color: #FFB800;
}

.rating-value {
  margin-left: 4px;
  font-size: 12px;
  color: #FF8C42;
  font-weight: 600;
}

.teacher-stats {
  display: flex;
  justify-content: space-around;
  padding: 16px 0;
  border-top: 1px solid #E0E0E0;
  border-bottom: 1px solid #E0E0E0;
}

.stat-item {
  text-align: center;
}

.stat-item .stat-icon {
  display: block;
  font-size: 20px;
  margin-bottom: 4px;
  color: #FF8C42;
}

.stat-item .stat-value {
  font-size: 20px;
  font-weight: 700;
  color: #2D3436;
}

.stat-item .stat-label {
  font-size: 11px;
  color: #636E72;
}

.teacher-action {
  padding-top: 12px;
  text-align: right;
}

/* 课程报告列表 */
.course-report-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.course-report-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: #F8F9FA;
  border-radius: 12px;
  transition: all 0.2s ease;
}

.course-report-item:hover {
  background: #FFF8F0;
}

.course-rank {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #E0E0E0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: #636E72;
}

.course-rank .rank-icon.rank-1 {
  color: #FFD700;
}

.course-rank .rank-icon.rank-2 {
  color: #C0C0C0;
}

.course-rank .rank-icon.rank-3 {
  color: #CD7F32;
}

.course-info {
  flex: 1;
}

.course-name {
  font-size: 15px;
  font-weight: 600;
  color: #2D3436;
}

.course-stats-inline {
  font-size: 12px;
  color: #636E72;
  margin-top: 4px;
  display: flex;
  gap: 16px;
}

.course-rating {
  display: flex;
  align-items: center;
  gap: 4px;
}

.rating-stars {
  font-size: 18px;
  color: #FFB800;
}

.course-rating .rating-value {
  font-size: 16px;
  font-weight: 600;
  color: #FF8C42;
}

/* 学生报告网格 */
.student-report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.student-report-card {
  background: #F8F9FA;
  border-radius: 16px;
  padding: 16px;
}

.student-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.student-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: white;
}

.student-report-card .student-name {
  font-size: 15px;
  font-weight: 600;
  color: #2D3436;
}

.student-report-card .student-class {
  font-size: 12px;
  color: #636E72;
}

.student-stats {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.stat-row .stat-label {
  font-size: 12px;
  color: #636E72;
  min-width: 70px;
}

.stat-row .stat-value {
  font-size: 12px;
  font-weight: 600;
  color: #2D3436;
  margin-left: auto;
}

.progress-mini {
  flex: 1;
  height: 6px;
  background: #E0E0E0;
  border-radius: 3px;
  overflow: hidden;
}

.progress-mini .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #43e97b 0%, #38f9d7 100%);
  border-radius: 3px;
}

.progress-mini.pink .progress-fill {
  background: linear-gradient(90deg, #f093fb 0%, #f5576c 100%);
}

/* 详情弹窗样式 */
.detail-content {
  padding: 8px 0;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 16px;
}

.detail-avatar {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: white;
}

.detail-avatar.course-avatar {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.detail-info h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #2D3436;
}

.detail-rating {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
}

.detail-rating .anticon {
  font-size: 16px;
  color: #D0D0D0;
}

.detail-rating .anticon.filled {
  color: #FFB800;
}

.rating-text {
  margin-left: 8px;
  font-size: 14px;
  color: #FF8C42;
  font-weight: 600;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  text-align: center;
}

.detail-stat-item {
  padding: 16px;
  background: #F8F9FA;
  border-radius: 12px;
}

.detail-stat-item .stat-number {
  font-size: 32px;
  font-weight: 700;
  color: #FF8C42;
}

.detail-stat-item .stat-label {
  font-size: 13px;
  color: #636E72;
  margin-top: 4px;
}

.detail-section h4 {
  margin: 0 0 12px 0;
  font-size: 15px;
  font-weight: 600;
  color: #2D3436;
  display: flex;
  align-items: center;
}

.detail-desc {
  margin: 0;
  font-size: 14px;
  color: #636E72;
  line-height: 1.8;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .overview-cards {
    grid-template-columns: repeat(2, 1fr);
  }

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

@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: 16px;
    text-align: center;
  }

  .header-actions {
    width: 100%;
    flex-direction: column;
  }

  .overview-cards {
    grid-template-columns: 1fr;
  }

  .tab-header {
    overflow-x: auto;
    padding: 0;
  }

  .tab-item {
    padding: 12px 16px;
    white-space: nowrap;
  }
}
</style>
