<template>
  <div class="eval-manage">
    <!-- Header -->
    <div class="page-header">
      <div class="header-left">
        <h2 class="page-title">评估管理</h2>
        <p class="page-subtitle">评估数据集质量和模型性能</p>
      </div>
      <div class="header-actions">
        <el-button type="primary" @click="showEvalDialog = true" class="create-btn">
          <el-icon><Plus /></el-icon>
          <span>新建评估</span>
        </el-button>
      </div>
    </div>

    <!-- Stats Cards -->
    <div class="stats-grid">
      <div
        class="stat-card stat-total"
        :class="{ active: filterStatus === '' }"
        @click="filterStatus = ''"
      >
        <div class="stat-glow"></div>
        <div class="stat-inner">
          <div class="stat-icon-wrap">
            <el-icon size="24"><DataAnalysis /></el-icon>
          </div>
          <div class="stat-info">
            <span class="stat-value">{{ evalDatasets.length }}</span>
            <span class="stat-label">评估数据集</span>
          </div>
        </div>
      </div>
      <div
        class="stat-card stat-completed"
        :class="{ active: filterStatus === 'completed' }"
        @click="filterStatus = filterStatus === 'completed' ? '' : 'completed'"
      >
        <div class="stat-glow"></div>
        <div class="stat-inner">
          <div class="stat-icon-wrap">
            <el-icon size="24"><CircleCheckFilled /></el-icon>
          </div>
          <div class="stat-info">
            <span class="stat-value">{{ completedCount }}</span>
            <span class="stat-label">已完成</span>
          </div>
        </div>
      </div>
      <div
        class="stat-card stat-processing"
        :class="{ active: filterStatus === 'running' }"
        @click="filterStatus = filterStatus === 'running' ? '' : 'running'"
      >
        <div class="stat-glow"></div>
        <div class="stat-inner">
          <div class="stat-icon-wrap">
            <el-icon size="24"><Loading /></el-icon>
          </div>
          <div class="stat-info">
            <span class="stat-value">{{ runningCount }}</span>
            <span class="stat-label">运行中</span>
          </div>
        </div>
      </div>
      <div
        class="stat-card stat-failed"
        :class="{ active: filterStatus === 'failed' }"
        @click="filterStatus = filterStatus === 'failed' ? '' : 'failed'"
      >
        <div class="stat-glow"></div>
        <div class="stat-inner">
          <div class="stat-icon-wrap">
            <el-icon size="24"><CircleCloseFilled /></el-icon>
          </div>
          <div class="stat-info">
            <span class="stat-value">{{ failedCount }}</span>
            <span class="stat-label">失败</span>
          </div>
        </div>
      </div>
    </div>

    <!-- Tabs -->
    <el-tabs v-model="activeTab" class="eval-tabs">
      <el-tab-pane label="评估数据集" name="eval">
        <div class="eval-container" v-loading="loading && isInitialLoad">
          <!-- Empty State -->
          <div v-if="!loading && !isInitialLoad && filteredDatasets.length === 0" class="empty-state">
            <div class="empty-illustration">
              <div class="orbit orbit-1"></div>
              <div class="orbit orbit-2"></div>
              <div class="orbit orbit-3"></div>
              <div class="empty-core">
                <el-icon size="40"><DataAnalysis /></el-icon>
              </div>
            </div>
            <h3 class="empty-title">暂无评估数据集</h3>
            <p class="empty-desc">创建您的第一个评估数据集</p>
            <el-button type="primary" @click="showEvalDialog = true" class="empty-btn">新建评估</el-button>
          </div>

          <!-- Eval Table -->
          <div v-else class="eval-table-wrapper">
            <!-- Table Header -->
            <div class="table-header">
              <div class="table-select">
                <el-checkbox
                  :model-value="isAllSelected"
                  @change="toggleSelectAll"
                  class="select-all"
                >
                  <span v-if="selectedCount > 0" class="selected-text">已选择 {{ selectedCount }} 项</span>
                  <span v-else>全选</span>
                </el-checkbox>
              </div>
              <div class="table-actions" v-if="selectedCount > 0">
                <el-button type="danger" size="small" plain @click="clearSelection" class="batch-clear-btn">
                  <el-icon><Close /></el-icon>
                  <span>清除选择</span>
                </el-button>
                <el-button type="danger" size="small" plain @click="batchDelete" class="batch-delete-btn">
                  <el-icon><Delete /></el-icon>
                  <span>批量删除</span>
                </el-button>
              </div>
            </div>

            <!-- Table Body -->
            <div class="eval-table">
              <div
                v-for="(evalSet, index) in filteredDatasets"
                :key="evalSet.id"
                class="eval-row"
                :class="{
                  'is-selected': isSelected(evalSet.id),
                  'row-animated': isInitialLoad
                }"
                :style="{ '--delay': index * 0.04 + 's' }"
                @click="toggleSelect(evalSet.id)"
              >
                <!-- Select Checkbox -->
                <div class="col-select" @click.stop>
                  <el-checkbox
                    :model-value="isSelected(evalSet.id)"
                    @change="toggleSelect(evalSet.id)"
                  />
                </div>

                <!-- Eval Icon -->
                <div class="col-icon">
                  <div class="eval-type-icon" :style="{ '--type-color': getTypeColor(evalSet.question_type) }">
                    <el-icon size="18"><DataLine /></el-icon>
                  </div>
                </div>

                <!-- Eval Name -->
                <div class="col-name">
                  <span class="eval-name-text">{{ evalSet.name }}</span>
                  <el-tag size="small" effect="dark">{{ getTypeName(evalSet.question_type) }}</el-tag>
                </div>

                <!-- Question Count -->
                <div class="col-count">
                  {{ evalSet.question_count || 0 }} 题
                </div>

                <!-- Status -->
                <div class="col-status">
                  <div class="status-pill" :class="'status-' + (evalSet.status || 'pending')">
                    <span class="status-dot"></span>
                    <span class="status-text">{{ getStatusText(evalSet.status) }}</span>
                  </div>
                </div>

                <!-- Date -->
                <div class="col-date">
                  {{ formatDate(evalSet.created_at) }}
                </div>

                <!-- Actions -->
                <div class="col-actions" @click.stop>
                  <el-tooltip content="运行" placement="top">
                    <el-button text size="small" class="action-btn run" @click="runEval(evalSet)">
                      <el-icon><VideoPlay /></el-icon>
                    </el-button>
                  </el-tooltip>
                  <el-tooltip content="结果" placement="top">
                    <el-button text size="small" class="action-btn" @click="viewResults(evalSet)">
                      <el-icon><View /></el-icon>
                    </el-button>
                  </el-tooltip>
                  <el-popconfirm title="确定删除此评估？" @confirm="handleDelete(evalSet)">
                    <template #reference>
                      <el-button text size="small" class="action-btn delete">
                        <el-icon><Delete /></el-icon>
                      </el-button>
                    </template>
                  </el-popconfirm>
                </div>
              </div>
            </div>
          </div>
        </div>
      </el-tab-pane>

      <el-tab-pane label="盲测系统" name="blind-test">
        <div class="blind-test-container" v-loading="loading && isInitialLoad">
          <div v-if="!loading && !isInitialLoad && blindTasks.length === 0" class="empty-state">
            <div class="empty-illustration">
              <div class="orbit orbit-1"></div>
              <div class="orbit orbit-2"></div>
              <div class="orbit orbit-3"></div>
              <div class="empty-core">
                <el-icon size="40"><Aim /></el-icon>
              </div>
            </div>
            <h3 class="empty-title">暂无盲测任务</h3>
            <p class="empty-desc">创建盲测来对比模型表现</p>
            <el-button type="primary" @click="showBlindTestDialog = true" class="empty-btn">创建测试</el-button>
          </div>

          <div v-else class="tasks-grid">
            <div v-for="(task, index) in blindTasks" :key="task.id" class="task-card" :style="{ '--delay': index * 0.08 + 's' }">
              <div class="task-header">
                <div class="task-icon" :class="task.status">
                  <el-icon size="20"><component :is="getTaskIcon(task.status)" /></el-icon>
                </div>
                <el-tag :type="getStatusType(task.status)" size="small" effect="dark">{{ getStatusText(task.status) }}</el-tag>
              </div>
              <h3 class="task-name">{{ task.name }}</h3>
              <el-progress :percentage="task.progress || 0" :stroke-width="6" />
              <div class="task-meta">已完成: {{ task.completed || 0 }}/{{ task.total || 0 }}</div>
              <div class="task-actions">
                <el-button v-if="task.status === 'running'" type="danger" size="small" @click="stopTask(task)">停止</el-button>
                <el-button type="primary" size="small" @click="continueTask(task)">{{ task.status === 'running' ? '查看' : '继续' }}</el-button>
              </div>
            </div>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>

    <!-- Eval Dialog -->
    <el-dialog v-model="showEvalDialog" title="新建评估数据集" width="520px" class="eval-dialog">
      <el-form :model="evalForm" label-position="top">
        <el-form-item label="数据集名称">
          <el-input v-model="evalForm.name" placeholder="输入名称" size="large" />
        </el-form-item>
        <div class="form-row">
          <el-form-item label="问题类型">
            <el-select v-model="evalForm.question_type" placeholder="选择类型" size="large" style="width: 100%">
              <el-option label="混合" value="mixed" />
              <el-option label="事实性" value="fact" />
              <el-option label="推理" value="reasoning" />
            </el-select>
          </el-form-item>
          <el-form-item label="问题数量">
            <el-input-number v-model="evalForm.count" :min="10" :max="500" size="large" style="width: 100%" />
          </el-form-item>
        </div>
      </el-form>
      <template #footer>
        <el-button @click="showEvalDialog = false">取消</el-button>
        <el-button type="primary" @click="createEval">创建</el-button>
      </template>
    </el-dialog>

    <!-- Blind Test Dialog -->
    <el-dialog v-model="showBlindTestDialog" title="创建盲测任务" width="520px" class="blind-dialog">
      <el-form :model="blindForm" label-position="top">
        <el-form-item label="任务名称">
          <el-input v-model="blindForm.name" placeholder="输入任务名称" size="large" />
        </el-form-item>
        <el-form-item label="选择模型">
          <el-checkbox-group v-model="blindForm.model_ids" class="model-check-group">
            <el-checkbox-button label="gpt-4">GPT-4</el-checkbox-button>
            <el-checkbox-button label="claude-3">Claude-3</el-checkbox-button>
            <el-checkbox-button label="gemini-pro">Gemini Pro</el-checkbox-button>
            <el-checkbox-button label="llama-3">Llama 3</el-checkbox-button>
          </el-checkbox-group>
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="showBlindTestDialog = false">取消</el-button>
        <el-button type="primary" @click="createBlindTest">创建</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, computed, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
import { evalApi } from '@/core/api'

const route = useRoute()
const projectId = computed(() => route.params.id)

const loading = ref(false)
const isInitialLoad = ref(true)
const activeTab = ref('eval')
const evalDatasets = ref([])
const blindTasks = ref([])
const showEvalDialog = ref(false)
const showBlindTestDialog = ref(false)
const filterStatus = ref('')

const evalForm = reactive({
  name: '',
  question_type: 'mixed',
  count: 50
})

const blindForm = reactive({
  name: '',
  model_ids: []
})

// Multi-select
const selectedDatasets = ref([])

const filteredDatasets = computed(() => {
  if (!filterStatus.value) return evalDatasets.value
  return evalDatasets.value.filter(e => e.status === filterStatus.value)
})

const completedCount = computed(() => evalDatasets.value.filter(e => e.status === 'completed').length)
const runningCount = computed(() => evalDatasets.value.filter(e => e.status === 'running').length)
const failedCount = computed(() => evalDatasets.value.filter(e => e.status === 'failed').length)

const isAllSelected = computed(() => filteredDatasets.value.length > 0 && selectedDatasets.value.length === filteredDatasets.value.length)
const selectedCount = computed(() => selectedDatasets.value.length)

const toggleSelectAll = () => {
  if (isAllSelected.value) {
    selectedDatasets.value = []
  } else {
    selectedDatasets.value = filteredDatasets.value.map(e => e.id)
  }
}

const toggleSelect = (id) => {
  const index = selectedDatasets.value.indexOf(id)
  if (index === -1) {
    selectedDatasets.value.push(id)
  } else {
    selectedDatasets.value.splice(index, 1)
  }
}

const isSelected = (id) => selectedDatasets.value.includes(id)

const clearSelection = () => {
  selectedDatasets.value = []
}

const batchDelete = async () => {
  if (selectedDatasets.value.length === 0) return
  try {
    for (const id of selectedDatasets.value) {
      await evalApi.delete(projectId.value, id)
    }
    ElMessage.success(`已删除 ${selectedDatasets.value.length} 个评估`)
    selectedDatasets.value = []
    fetchEvalDatasets()
  } catch (error) {
    ElMessage.error('删除失败')
  }
}

const fetchEvalDatasets = async () => {
  const wasInitial = isInitialLoad.value
  loading.value = true
  try {
    const res = await evalApi.list(projectId.value)
    evalDatasets.value = res.data?.datasets || res || []
  } catch (error) {
    evalDatasets.value = []
  } finally {
    loading.value = false
    if (wasInitial) {
      isInitialLoad.value = false
    }
  }
}

const createEval = async () => {
  try {
    await evalApi.create(projectId.value, evalForm)
    ElMessage.success('创建成功')
    showEvalDialog.value = false
    fetchEvalDatasets()
  } catch (error) {
    ElMessage.error('创建失败')
  }
}

const runEval = async (evalSet) => {
  try {
    await evalApi.run(projectId.value, evalSet.id)
    ElMessage.success('评估已启动')
    fetchEvalDatasets()
  } catch (error) {
    ElMessage.error('启动失败')
  }
}

const viewResults = (evalSet) => {
  ElMessage.info('结果查看功能开发中')
}

const handleDelete = async (evalSet) => {
  try {
    await evalApi.delete(projectId.value, evalSet.id)
    ElMessage.success('删除成功')
    fetchEvalDatasets()
  } catch (error) {
    ElMessage.error('删除失败')
  }
}

const createBlindTest = () => {
  ElMessage.info('盲测功能开发中')
  showBlindTestDialog.value = false
}

const stopTask = (task) => ElMessage.info('停止功能开发中')
const continueTask = (task) => ElMessage.info('继续功能开发中')

const getTypeName = (type) => {
  const map = { mixed: '混合', fact: '事实性', reasoning: '推理' }
  return map[type] || type
}

const getTypeColor = (type) => {
  const map = { mixed: '#818cf8', fact: '#3b82f6', reasoning: '#f59e0b' }
  return map[type] || '#818cf8'
}

const getStatusType = (status) => {
  const map = { pending: 'info', running: 'warning', completed: 'success', failed: 'danger' }
  return map[status] || 'info'
}

const getStatusText = (status) => {
  const map = { pending: '等待中', running: '运行中', completed: '已完成', failed: '失败' }
  return map[status] || '未知'
}

const getTaskIcon = (status) => {
  const map = { pending: 'Clock', running: 'Loading', completed: 'CircleCheck', failed: 'CircleClose' }
  return map[status] || 'Clock'
}

const formatDate = (date) => {
  if (!date) return ''
  return new Date(date).toLocaleDateString('zh-CN', { month: 'short', day: 'numeric' })
}

onMounted(() => fetchEvalDatasets())
</script>

<style scoped>
/* ========================
   CSS Variables
   ======================== */
.eval-manage {
  --accent-cyan: #00d4ff;
  --accent-cyan-dim: rgba(0, 212, 255, 0.15);
  --accent-cyan-glow: rgba(0, 212, 255, 0.4);
  --bg-elevated: #0f1117;
  --bg-card: #161920;
  --bg-hover: #1c2029;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-active: rgba(0, 212, 255, 0.3);
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius-lg: 12px;
  --radius-md: 8px;
  --radius-sm: 6px;
  padding: 28px 32px;
}

/* ========================
   Header
   ======================== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
}

.header-left {
  position: relative;
}

.page-title {
  font-size: 28px;
  font-weight: 700;
  margin: 0;
  background: linear-gradient(135deg, #ffffff 0%, var(--accent-cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin: 6px 0 0;
}

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

.create-btn {
  background: var(--accent-cyan) !important;
  border: none !important;
  color: #030407 !important;
  font-weight: 600;
  padding: 10px 22px;
  border-radius: var(--radius-md);
  box-shadow: 0 0 20px var(--accent-cyan-dim);
  transition: all 0.2s ease;
}

.create-btn:hover {
  box-shadow: 0 0 35px var(--accent-cyan-glow);
  transform: translateY(-1px);
}

/* ========================
   Stats Grid
   ======================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all 0.25s ease;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-active);
  cursor: pointer;
}

.stat-card:hover::before {
  opacity: 1;
}

.stat-card.active {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 20px var(--accent-cyan-dim);
}

.stat-card.active::before {
  opacity: 1;
}

.stat-card.active .stat-glow {
  opacity: 0.5;
}

.stat-glow {
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.stat-card:hover .stat-glow {
  opacity: 0.5;
}

/* Stat variations */
.stat-total {
  --stat-color: #818cf8;
}

.stat-total::before {
  background: linear-gradient(90deg, #6366f1, #818cf8);
}

.stat-total .stat-glow {
  background: radial-gradient(circle at 30% 30%, rgba(99, 102, 241, 0.3), transparent 50%);
}

.stat-completed {
  --stat-color: var(--success);
}

.stat-completed::before {
  background: linear-gradient(90deg, #16a34a, var(--success));
}

.stat-completed .stat-glow {
  background: radial-gradient(circle at 30% 30%, rgba(34, 197, 94, 0.3), transparent 50%);
}

.stat-processing {
  --stat-color: var(--warning);
}

.stat-processing::before {
  background: linear-gradient(90deg, #d97706, var(--warning));
}

.stat-processing .stat-glow {
  background: radial-gradient(circle at 30% 30%, rgba(245, 158, 11, 0.3), transparent 50%);
}

.stat-failed {
  --stat-color: var(--danger);
}

.stat-failed::before {
  background: linear-gradient(90deg, #dc2626, var(--danger));
}

.stat-failed .stat-glow {
  background: radial-gradient(circle at 30% 30%, rgba(239, 68, 68, 0.3), transparent 50%);
}

.stat-inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 22px;
  z-index: 1;
}

.stat-icon-wrap {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  color: var(--stat-color);
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: #ffffff;
  font-family: 'SF Mono', 'JetBrains Mono', monospace;
  line-height: 1.1;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ========================
   Tabs
   ======================== */
.eval-tabs {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.eval-container,
.blind-test-container {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  overflow-x: auto;
}

/* ========================
   Empty State
   ======================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 40px;
  min-height: 450px;
}

.empty-illustration {
  position: relative;
  width: 140px;
  height: 140px;
  margin-bottom: 28px;
}

.orbit {
  position: absolute;
  border-radius: 50%;
  border: 1px dashed rgba(0, 212, 255, 0.2);
}

.orbit-1 {
  inset: 10px;
  animation: orbit-rotate 20s linear infinite;
}

.orbit-2 {
  inset: 30px;
  border-color: rgba(0, 212, 255, 0.15);
  animation: orbit-rotate 15s linear infinite reverse;
}

.orbit-3 {
  inset: 50px;
  border-color: rgba(0, 212, 255, 0.1);
  animation: orbit-rotate 10s linear infinite;
}

@keyframes orbit-rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.empty-core {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 70px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg-hover) 0%, var(--bg-card) 100%);
  border: 1px solid var(--border-subtle);
  border-radius: 50%;
  color: var(--accent-cyan);
  box-shadow: 0 0 40px var(--accent-cyan-dim);
}

.empty-title {
  font-size: 22px;
  font-weight: 600;
  color: #ffffff;
  margin: 0 0 8px;
}

.empty-desc {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0 0 20px;
  text-align: center;
}

.empty-btn {
  background: var(--accent-cyan) !important;
  border: none !important;
  color: #030407 !important;
  font-weight: 600;
}

/* ========================
   Eval Table
   ======================== */
.eval-table-wrapper {
  display: flex;
  flex-direction: column;
  min-width: 800px;
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}

.table-select .select-all {
  --el-checkbox-text-color: var(--text-secondary);
}

.selected-text {
  color: var(--accent-cyan);
  font-weight: 500;
}

.batch-delete-btn {
  background: transparent !important;
  border-color: var(--danger) !important;
  color: var(--danger) !important;
}

.batch-delete-btn:hover {
  background: var(--danger) !important;
  color: white !important;
}

.batch-clear-btn {
  background: transparent !important;
  border-color: var(--text-muted) !important;
  color: var(--text-secondary) !important;
}

.batch-clear-btn:hover {
  background: var(--bg-hover) !important;
  border-color: var(--text-secondary) !important;
  color: #ffffff !important;
}

.eval-table {
  display: flex;
  flex-direction: column;
}

.eval-row {
  display: grid;
  grid-template-columns: 40px 50px 1fr 80px 80px 100px 90px;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-subtle);
  transition: background 0.15s ease;
  cursor: pointer;
}

.eval-row.row-animated {
  animation: row-in 0.3s ease backwards;
  animation-delay: var(--delay);
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
}

.eval-row:hover {
  background: var(--bg-hover);
}

.eval-row.is-selected {
  background: rgba(0, 212, 255, 0.05);
}

/* Column styles */
.col-select {
  display: flex;
  justify-content: center;
}

.col-icon {
  display: flex;
  justify-content: center;
}

.eval-type-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--type-color) 15%, transparent);
  border-radius: var(--radius-sm);
  color: var(--type-color);
}

.col-name {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

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

.col-count {
  font-size: 13px;
  color: var(--text-muted);
  font-family: 'SF Mono', monospace;
}

.col-date {
  font-size: 13px;
  color: var(--text-muted);
  font-family: 'SF Mono', monospace;
}

/* Status Pill */
.col-status {
  min-width: 80px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-running {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning);
}

.status-running .status-dot {
  background: var(--warning);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-completed {
  background: rgba(34, 197, 94, 0.1);
  color: var(--success);
}

.status-completed .status-dot {
  background: var(--success);
}

.status-failed {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.status-failed .status-dot {
  background: var(--danger);
}

.status-pending {
  background: rgba(107, 114, 128, 0.1);
  color: var(--text-muted);
}

.status-pending .status-dot {
  background: var(--text-muted);
}

/* Actions */
.col-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  min-width: 90px;
}

.action-btn {
  color: var(--text-muted) !important;
  transition: all 0.15s ease;
}

.action-btn:hover {
  color: var(--accent-cyan) !important;
  background: var(--accent-cyan-dim) !important;
}

.action-btn.run:hover {
  color: var(--success) !important;
  background: rgba(34, 197, 94, 0.1) !important;
}

.action-btn.delete:hover {
  color: var(--danger) !important;
  background: rgba(239, 68, 68, 0.1) !important;
}

/* ========================
   Blind Test Tasks Grid
   ======================== */
.tasks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.task-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all var(--transition-base);
  animation: cardIn 0.4s ease backwards;
  animation-delay: var(--delay);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(15px); }
}

.task-card:hover {
  border-color: var(--accent-cyan);
  transform: translateY(-3px);
}

.task-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.task-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
}

.task-icon.running {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warning);
  animation: pulse 2s infinite;
}

.task-icon.completed {
  background: var(--success-muted);
  color: var(--success);
}

.task-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.task-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 12px 0;
}

.task-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ========================
   Dialog
   ======================== */
.eval-dialog,
.blind-dialog {
  --el-dialog-bg-color: var(--bg-elevated);
  --el-dialog-border-radius: var(--radius-xl);
  border: 1px solid var(--border-subtle);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.model-check-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ========================
   Responsive
   ======================== */
@media (max-width: 900px) {
  .eval-manage {
    padding: 20px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .page-header {
    flex-direction: column;
    gap: 16px;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .el-button {
    flex: 1;
  }

  .eval-row {
    grid-template-columns: 40px 40px 1fr 60px;
    gap: 8px;
  }

  .col-date,
  .col-status {
    display: none;
  }

  .col-actions {
    min-width: 50px;
  }
}
</style>
