<template>
  <div class="dlt-lottery-page">
    <!-- 查询区域 -->
    <div class="search-section">
      <!-- 返回按钮 -->
      <div class="back-button-container">
        <button class="back-btn" @click="goBack">
          <svg class="back-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M19 12H5M12 19L5 12L12 5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
          </svg>
          返回
        </button>
      </div>
      
      <div class="search-tabs">
        <div 
          class="search-tab" 
          :class="{ active: activeTab === 'period' }"
          @click="switchTab('period')"
        >
          期号查询
        </div>
        <div 
          class="search-tab" 
          :class="{ active: activeTab === 'date' }"
          @click="switchTab('date')"
        >
          日期查询
        </div>
        <div 
          class="search-tab" 
          :class="{ active: activeTab === 'condition' }"
          @click="switchTab('condition')"
        >
          表相查询
        </div>
      </div>
      
      <div class="search-form">
        <!-- 期号查询 -->
        <div v-if="activeTab === 'period'" class="search-input-group">
          <input 
            type="text" 
            placeholder="输入期号，例如：25093" 
            v-model="searchQuery"
            class="search-input"
          />
          <button class="search-btn" @click="handleSearch" :disabled="searchLoading">
            {{ searchLoading ? '查询中...' : '查询' }}
          </button>
        </div>

        <!-- 日期查询 -->
        <div v-if="activeTab === 'date'" class="date-search-group">
          <!-- 桌面端：日期范围选择器 -->
          <div class="date-range-wrapper desktop-date-picker">
            <label class="date-label">选择日期范围</label>
            <el-date-picker
              v-model="dateRange"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="YYYY年MM月DD日"
              value-format="YYYY-MM-DD"
              size="default"
              class="date-range-picker"
              @change="onDateRangeChange"
              :clearable="true"
              :editable="false"
            />
          </div>
          
          <!-- 移动端：两个独立的日期选择器 -->
          <div class="mobile-date-pickers">
            <div class="mobile-date-wrapper">
              <label class="date-label">开始日期</label>
              <el-date-picker
                v-model="dateQuery.startDate"
                type="date"
                placeholder="开始日期"
                format="YYYY年MM月DD日"
                value-format="YYYY-MM-DD"
                size="default"
                class="mobile-date-picker"
                @change="onMobileDateChange"
                :clearable="true"
                :editable="false"
              />
            </div>
            <div class="mobile-date-wrapper">
              <label class="date-label">结束日期</label>
              <el-date-picker
                v-model="dateQuery.endDate"
                type="date"
                placeholder="结束日期"
                format="YYYY年MM月DD日"
                value-format="YYYY-MM-DD"
                size="default"
                class="mobile-date-picker"
                @change="onMobileDateChange"
                :clearable="true"
                :editable="false"
              />
            </div>
          </div>
          
          <el-button 
            type="primary" 
            @click="handleDateSearch" 
            :loading="searchLoading"
            class="search-button"
            size="default"
          >
            {{ searchLoading ? '查询中...' : '查询' }}
          </el-button>
        </div>

        <!-- 表相查询 -->
        <div v-if="activeTab === 'condition'" class="table-correlation-group">
          <div class="correlation-content">
            <div class="correlation-description">
              <p class="description-text">表相查询提供基于最新100期大乐透开奖数据的详细统计分析</p>
            </div>
            <el-button 
              type="primary" 
              @click="goToTableCorrelation"
              class="correlation-button"
              size="default"
            >
              进入表相查询
            </el-button>
          </div>
        </div>
      </div>
    </div>

    <!-- 开奖记录区域 -->
    <div class="lottery-records-section">
      <div class="section-header">
        <h3 class="section-title">
          {{ getSectionTitle() }}
        </h3>
        <!-- 搜索模式下显示清除按钮 -->
        <button v-if="isSearchMode" class="clear-search-btn" @click="clearSearch">
          <svg class="clear-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M18 6L6 18M6 6L18 18" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
          </svg>
          近期开奖记录
        </button>
      </div>
      
      <!-- 错误提示 -->
      <div v-if="error" class="error-message">
        <div class="error-icon">
          <svg class="error-svg" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M12 1C8.676 1 6 3.676 6 7V8C4.343 8 3 9.343 3 11V19C3 20.657 4.343 22 6 22H18C19.657 22 21 20.657 21 19V11C21 9.343 19.657 8 18 8V7C18 3.676 15.324 1 12 1ZM12 3C14.206 3 16 4.794 16 7V8H8V7C8 4.794 9.794 3 12 3ZM6 10H18C18.551 10 19 10.449 19 11V19C19 19.551 18.551 20 18 20H6C5.449 20 5 19.551 5 19V11C5 10.449 5.449 10 6 10ZM12 13C11.172 13 10.5 13.672 10.5 14.5C10.5 15.328 11.172 16 12 16C12.828 16 13.5 15.328 13.5 14.5C13.5 13.672 12.828 13 12 13Z" fill="currentColor"/>
          </svg>
        </div>
        <div class="error-text">{{ error }}</div>
        <button class="retry-btn" @click="loadRecentDraws">重试</button>
      </div>
      
      <!-- 加载状态 -->
      <div v-if="loading" class="loading-container">
        <div class="loading-spinner"></div>
        <div class="loading-text">正在加载开奖记录...</div>
      </div>
      
      <!-- 搜索模式：显示单个搜索结果 -->
      <div v-if="isSearchMode && searchResult && !searchLoading" class="records-list">
        <div class="record-item search-result-item">
          <div class="record-header">
            <span class="period-number">{{ searchResult.period }}</span>
            <span class="draw-date">开奖日期：{{ searchResult.date }}</span>
          </div>
          
          <div class="balls-container">
            <!-- 前区球 -->
            <div class="front-balls">
              <span 
                v-for="ball in searchResult.frontBalls" 
                :key="ball" 
                class="ball front-ball"
              >
                {{ ball }}
              </span>
            </div>
            
            <!-- 后区球 -->
            <div class="back-balls">
              <span 
                v-for="ball in searchResult.backBalls" 
                :key="ball" 
                class="ball back-ball"
              >
                {{ ball }}
              </span>
            </div>
          </div>
        </div>
      </div>

      <!-- 搜索模式：显示多条搜索结果（日期查询） -->
      <div v-if="isSearchMode && !searchResult && !loading && !error && dateSearchResults.length > 0" class="records-list">
        <!-- 开奖记录项 -->
        <div class="record-item" v-for="record in dateSearchResults" :key="record.period">
          <div class="record-header">
            <span class="period-number">{{ record.period }}</span>
            <span class="draw-date">开奖日期：{{ record.date }}</span>
          </div>
          
          <div class="balls-container">
            <!-- 前区球 -->
            <div class="front-balls">
              <span 
                v-for="ball in record.frontBalls" 
                :key="ball" 
                class="ball front-ball"
              >
                {{ ball }}
              </span>
            </div>
            
            <!-- 后区球 -->
            <div class="back-balls">
              <span 
                v-for="ball in record.backBalls" 
                :key="ball" 
                class="ball back-ball"
              >
                {{ ball }}
              </span>
            </div>
          </div>
        </div>
      </div>

      <!-- 普通模式：无数据提示 -->
      <div v-if="!isSearchMode && !loading && !error && lotteryRecords.length === 0" class="no-data">
        <div class="no-data-icon">📊</div>
        <div class="no-data-text">暂无开奖记录</div>
      </div>
      
      <!-- 普通模式：显示所有记录 -->
      <div v-if="!isSearchMode && !loading && !error && lotteryRecords.length > 0" class="records-list">
        <!-- 开奖记录项 -->
        <div class="record-item" v-for="record in lotteryRecords" :key="record.period">
          <div class="record-header">
            <span class="period-number">{{ record.period }}</span>
            <span class="draw-date">开奖日期：{{ record.date }}</span>
          </div>
          
          <div class="balls-container">
            <!-- 前区球 -->
            <div class="front-balls">
              <span 
                v-for="ball in record.frontBalls" 
                :key="ball" 
                class="ball front-ball"
              >
                {{ ball }}
              </span>
            </div>
            
            <!-- 后区球 -->
            <div class="back-balls">
              <span 
                v-for="ball in record.backBalls" 
                :key="ball" 
                class="ball back-ball"
              >
                {{ ball }}
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { dltLotteryApi } from '../../api/dlt/index.js'

export default {
  name: 'DltLottery',
  data() {
    return {
      searchQuery: '',
      lotteryRecords: [], // 近期开奖记录
      loading: false,
      searchLoading: false,
      error: null,
      isSearchMode: false, // 是否为搜索模式
      searchResult: null,  // 期号搜索结果
      dateSearchResults: [], // 日期查询结果
      activeTab: 'period',  // 当前激活的标签: 'period', 'date', 'condition'
      dateQuery: {
        startDate: '',
        endDate: ''
      },
      dateRange: null  // 日期范围选择器的值
    }
  },
  async mounted() {
    await this.loadRecentDraws()
  },
  methods: {
    // 加载近期开奖记录
    async loadRecentDraws() {
      try {
        this.loading = true
        this.error = null
        
        console.log('正在获取近期大乐透开奖记录...')
        const response = await dltLotteryApi.getRecentDraws(10) // 获取最近10期
        
        if (response && response.success && response.data) {
          // 转换数据格式
          this.lotteryRecords = response.data.map(item => ({
            period: `${item.drawId}期`,
            date: this.formatDate(item.drawDate),
            frontBalls: this.formatFrontBallsFromApi(item),
            backBalls: this.formatBackBallsFromApi(item)
          }))
          console.log('大乐透开奖记录加载成功:', this.lotteryRecords)
        } else {
          console.warn('获取大乐透开奖记录失败:', response)
          // 显示友好的错误提示
          this.error = '获取开奖记录失败'
        }
      } catch (error) {
        console.error('获取大乐透开奖记录出错:', error)
        // 尝试从错误对象中获取更具体的错误信息
        this.error = error?.response?.data?.message || error?.message || '获取开奖记录出错，请稍后重试'
      } finally {
        this.loading = false
      }
    },

    // 搜索特定期号
    async handleSearch() {
      if (!this.searchQuery.trim()) {
        return
      }
      
      try {
        this.searchLoading = true
        this.error = null
        
        console.log('搜索大乐透期号:', this.searchQuery)
        const response = await dltLotteryApi.getDrawById(this.searchQuery)
        
        if (response && response.success && response.data) {
          // 设置搜索结果
          this.searchResult = {
            period: `${response.data.drawId}期`,
            date: this.formatDate(response.data.drawDate),
            frontBalls: this.formatFrontBallsFromApi(response.data),
            backBalls: this.formatBackBallsFromApi(response.data)
          }
          
          // 进入搜索模式，只显示搜索结果
          this.isSearchMode = true
          
          console.log('大乐透期号搜索成功:', this.searchResult)
        } else {
          console.warn('未找到该期号的大乐透开奖记录:', response)
          // 显示友好的未找到记录提示
          this.error = `未找到期号 ${this.searchQuery} 的开奖记录`
        }
      } catch (error) {
        console.error('搜索大乐透期号出错:', error)
        // 尝试从错误对象中获取更具体的错误信息
        this.error = error?.response?.data?.message || error?.message || '搜索失败，请检查期号格式或稍后重试'
      } finally {
        this.searchLoading = false
      }
    },

    // 清除搜索，返回到显示所有记录
    clearSearch() {
      this.isSearchMode = false
      this.searchResult = null
      this.dateSearchResults = []
      this.searchQuery = ''
      this.error = null
    },

    // 切换查询标签
    switchTab(tabName) {
      this.activeTab = tabName
      this.error = null
      // 如果切换标签，清除搜索模式
      if (this.isSearchMode) {
        this.clearSearch()
      }
    },

    // 日期范围变化处理
    onDateRangeChange(dateRange) {
      if (dateRange && dateRange.length === 2) {
        this.dateQuery.startDate = dateRange[0]
        this.dateQuery.endDate = dateRange[1]
      } else {
        this.dateQuery.startDate = ''
        this.dateQuery.endDate = ''
      }
    },

    // 移动端日期变化处理
    onMobileDateChange() {
      // 当移动端单个日期选择器变化时，同步更新dateRange
      if (this.dateQuery.startDate && this.dateQuery.endDate) {
        this.dateRange = [this.dateQuery.startDate, this.dateQuery.endDate]
      } else {
        this.dateRange = null
      }
    },

    // 日期查询
    async handleDateSearch() {
      // 从日期范围选择器获取值
      if (this.dateRange && this.dateRange.length === 2) {
        this.dateQuery.startDate = this.dateRange[0]
        this.dateQuery.endDate = this.dateRange[1]
      }

      if (!this.dateQuery.startDate || !this.dateQuery.endDate) {
        this.error = '请选择开始日期和结束日期'
        return
      }

      try {
        this.searchLoading = true
        this.error = null

        console.log('大乐透日期查询:', this.dateQuery)
        const response = await dltLotteryApi.queryDraws(this.dateQuery.startDate, this.dateQuery.endDate)

        if (response && response.success && response.data && response.data.length > 0) {
          // 转换数据格式并设置为日期查询结果
          this.dateSearchResults = response.data.map(item => ({
            period: `${item.drawId}期`,
            date: this.formatDate(item.drawDate),
            frontBalls: this.formatFrontBallsFromApi(item),
            backBalls: this.formatBackBallsFromApi(item)
          }))

          // 进入搜索模式
          this.isSearchMode = true
          console.log('大乐透日期查询成功:', this.dateSearchResults)
        } else {
          console.warn('未找到该日期范围的大乐透开奖记录:', response)
          // 清空日期查询数据，进入搜索模式以显示正确的标题
          this.dateSearchResults = []
          this.isSearchMode = true
          // 显示友好的未找到记录提示
          this.error = `未找到 ${this.dateQuery.startDate} 到 ${this.dateQuery.endDate} 的开奖记录`
        }
      } catch (error) {
        console.error('大乐透日期查询出错:', error)
        // 如果有设置日期范围，进入搜索模式以显示正确的标题
        if (this.dateQuery.startDate && this.dateQuery.endDate) {
          this.dateSearchResults = []
          this.isSearchMode = true
        }
        // 尝试从错误对象中获取更具体的错误信息
        this.error = error?.response?.data?.message || error?.message || '日期查询失败，请稍后重试'
      } finally {
        this.searchLoading = false
      }
    },

    // 返回到开奖页面
    goBack() {
      this.$router.push('/lottery-info')
    },

    // 跳转到表相查询页面
    goToTableCorrelation() {
      // 跳转到大乐透表相查询页面
      this.$router.push('/dlt-table-analysis')
    },

    // 获取区域标题
    getSectionTitle() {
      if (!this.isSearchMode) {
        return '近期开奖记录'
      }

      if (this.activeTab === 'period' && this.searchQuery) {
        return `期号 ${this.searchQuery} 开奖记录`
      }

      if (this.activeTab === 'date' && this.dateQuery.startDate && this.dateQuery.endDate) {
        return `${this.dateQuery.startDate} 至 ${this.dateQuery.endDate} 开奖记录`
      }

      return '查询结果'
    },

    // 格式化日期
    formatDate(dateInput) {
      if (!dateInput) return ''
      
      try {
        let date
        
        // 如果是时间戳（数字）
        if (typeof dateInput === 'number') {
          date = new Date(dateInput)
        } else {
          // 如果是字符串
          date = new Date(dateInput)
        }
        
        // 检查日期是否有效
        if (isNaN(date.getTime())) {
          console.warn('无效的日期:', dateInput)
          return String(dateInput)
        }
        
        const year = date.getFullYear()
        const month = String(date.getMonth() + 1).padStart(2, '0')
        const day = String(date.getDate()).padStart(2, '0')
        
        console.log('格式化日期:', { input: dateInput, output: `${year}/${month}/${day}` })
        return `${year}/${month}/${day}`
      } catch (error) {
        console.warn('日期格式化失败:', dateInput, error)
        return String(dateInput)
      }
    },

    // 从API数据中格式化前区球数据
    formatFrontBallsFromApi(apiData) {
      if (!apiData) return []
      
      try {
        const frontBalls = []
        
        // API返回的数据结构是 frontBall1, frontBall2, ..., frontBall5
        for (let i = 1; i <= 5; i++) {
          const ballKey = `frontBall${i}`
          if (apiData[ballKey]) {
            frontBalls.push(String(apiData[ballKey]).padStart(2, '0'))
          }
        }
        
        console.log('格式化前区球数据:', { input: apiData, output: frontBalls })
        return frontBalls
      } catch (error) {
        console.warn('前区球数据格式化失败:', apiData, error)
        return []
      }
    },

    // 从API数据中格式化后区球数据
    formatBackBallsFromApi(apiData) {
      if (!apiData) return []
      
      try {
        const backBalls = []
        
        // API返回的数据结构是 backBall1, backBall2
        for (let i = 1; i <= 2; i++) {
          const ballKey = `backBall${i}`
          if (apiData[ballKey]) {
            backBalls.push(String(apiData[ballKey]).padStart(2, '0'))
          }
        }
        
        console.log('格式化后区球数据:', { input: apiData, output: backBalls })
        return backBalls
      } catch (error) {
        console.warn('后区球数据格式化失败:', apiData, error)
        return []
      }
    }
  }
}
</script>

<style scoped>
.dlt-lottery-page {
  min-height: calc(100vh - 70px);
  background: #f5f5f5;
  padding: 16px 0;
}

/* 查询区域 */
.search-section {
  background: white;
  margin: 0 16px 16px 16px;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* 返回按钮 */
.back-button-container {
  margin-bottom: 16px;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  color: #666;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.back-btn:hover {
  background: #e9ecef;
  border-color: #1890ff;
  color: #1890ff;
}

.back-icon {
  width: 16px;
  height: 16px;
}

.search-tabs {
  display: flex;
  margin-bottom: 16px;
  border-bottom: 1px solid #f0f0f0;
}

.search-tab {
  padding: 8px 16px;
  font-size: 14px;
  color: #666;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.3s ease;
}

.search-tab.active {
  color: #1890ff;
  border-bottom-color: #1890ff;
  font-weight: 600;
}

.search-tab:hover {
  color: #1890ff;
}

.search-form {
  margin-top: 16px;
}

.search-input-group {
  display: flex;
  gap: 12px;
  align-items: center;
}

.search-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
  font-size: 14px;
  transition: all 0.3s ease;
}

.search-input:focus {
  outline: none;
  border-color: #1890ff;
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

.search-input::placeholder {
  color: #bfbfbf;
}

.search-btn {
  padding: 12px 24px;
  background: linear-gradient(135deg, #1890ff, #40a9ff);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 80px;
}

.search-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(24, 144, 255, 0.4);
}

.search-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Element UI 日期查询样式 */
.date-search-group {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.date-range-wrapper {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.date-label {
  font-size: 14px;
  color: #606266;
  font-weight: 500;
  margin-bottom: 4px;
}

.date-range-picker {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* 确保日期选择器输入框不超出容器 */
.date-range-picker :deep(.el-input__wrapper) {
  max-width: 100%;
  box-sizing: border-box;
}

.date-range-picker :deep(.el-range-editor) {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

.date-range-picker :deep(.el-range-input) {
  width: auto !important;
  flex: 1 !important;
  min-width: 0 !important;
}

/* 移动端日期选择器样式 */
.mobile-date-pickers {
  display: none;
  flex-direction: column;
  gap: 16px;
}

.mobile-date-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mobile-date-picker {
  width: 100%;
}

/* 默认显示桌面端日期范围选择器 */
.desktop-date-picker {
  display: block;
}

.search-button {
  width: 100%;
  height: 40px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 8px;
}

/* 表相查询样式 */
.table-correlation-group {
  padding: 30px 20px;
}

.correlation-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}

.correlation-description {
  max-width: 400px;
}

.description-text {
  color: #606266;
  font-size: 15px;
  line-height: 1.6;
  margin: 0;
  font-weight: 500;
}

.correlation-button {
  padding: 12px 32px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 8px;
  min-width: 160px;
}

/* 开奖记录区域 */
.lottery-records-section {
  background: white;
  margin: 0 16px;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* 区域标题头部 */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.section-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin: 0;
  padding-left: 4px;
  border-left: 4px solid #1890ff;
}

/* 清除搜索按钮 */
.clear-search-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  color: #666;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.clear-search-btn:hover {
  background: #e9ecef;
  border-color: #1890ff;
  color: #1890ff;
}

.clear-icon {
  width: 14px;
  height: 14px;
}

.records-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.record-item {
  padding: 16px;
  border: 1px solid #f0f0f0;
  border-radius: 12px;
  transition: all 0.3s ease;
}

.record-item:hover {
  border-color: #1890ff;
  box-shadow: 0 4px 12px rgba(24, 144, 255, 0.1);
}

.record-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.period-number {
  font-size: 16px;
  font-weight: bold;
  color: #333;
}

.draw-date {
  font-size: 14px;
  color: #666;
}

.balls-container {
  display: flex;
  align-items: center;
  gap: 16px;
}

.front-balls {
  display: flex;
  gap: 8px;
}

.back-balls {
  display: flex;
  gap: 8px;
}

.ball {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  color: white;
  transition: all 0.3s ease;
}

.front-ball {
  background: linear-gradient(135deg, #ff4d4f, #ff7875);
  box-shadow: 0 2px 8px rgba(255, 77, 79, 0.3);
}

.back-ball {
  background: linear-gradient(135deg, #1890ff, #40a9ff);
  box-shadow: 0 2px 8px rgba(24, 144, 255, 0.3);
}

.ball:hover {
  transform: scale(1.1);
}

/* 搜索结果项特殊样式 */
.search-result-item {
  border: 2px solid #1890ff !important;
  background: linear-gradient(135deg, #e6f7ff 0%, #f0f9ff 100%) !important;
  box-shadow: 0 4px 16px rgba(24, 144, 255, 0.2) !important;
  position: relative;
}

.search-result-item::before {
  content: '搜索结果';
  position: absolute;
  top: -10px;
  right: -10px;
  background: #1890ff;
  color: white;
  font-size: 10px;
  padding: 4px 8px;
  border-radius: 10px;
  font-weight: bold;
  box-shadow: 0 2px 6px rgba(24, 144, 255, 0.4);
}

/* 错误提示 */
.error-message {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: #fff2f0;
  border: 1px solid #ffccc7;
  border-radius: 8px;
  margin-bottom: 16px;
}

.error-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.error-svg {
  width: 20px;
  height: 20px;
  color: #cf1322;
}

.error-text {
  flex: 1;
  color: #cf1322;
  font-size: 14px;
}

.retry-btn {
  padding: 4px 12px;
  background: #ff4d4f;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.retry-btn:hover {
  background: #ff7875;
}

/* 加载状态 */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  gap: 16px;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #f0f0f0;
  border-top: 3px solid #1890ff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-text {
  color: #666;
  font-size: 14px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 无数据提示 */
.no-data {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  gap: 12px;
}

.no-data-icon {
  font-size: 48px;
  opacity: 0.5;
}

.no-data-text {
  color: #999;
  font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .dlt-lottery-page {
    padding: 12px 0;
  }
  
  .search-section,
  .lottery-records-section {
    margin: 0 12px 12px 12px;
    padding: 16px;
  }
  
  .back-button-container {
    margin-bottom: 12px;
  }
  
  .back-btn {
    padding: 6px 12px;
    font-size: 13px;
  }
  
  .back-icon {
    width: 14px;
    height: 14px;
  }
  
  .search-tabs {
    margin-bottom: 12px;
  }
  
  .search-tab {
    padding: 6px 12px;
    font-size: 13px;
  }
  
  .search-input-group {
    flex-direction: column;
    gap: 8px;
  }
  
  .search-input,
  .search-btn {
    width: 100%;
  }
  
  /* Element UI 日期查询响应式 */
  .date-range-wrapper {
    gap: 8px;
  }
  
  /* 在平板和小屏幕上隐藏桌面端日期范围选择器 */
  .desktop-date-picker {
    display: none;
  }
  
  /* 显示移动端独立日期选择器 */
  .mobile-date-pickers {
    display: flex;
    gap: 12px;
  }
  
  .mobile-date-wrapper {
    gap: 6px;
  }
  
  .mobile-date-picker {
    font-size: 14px;
  }
  
  .mobile-date-picker :deep(.el-input__wrapper) {
    padding: 8px 12px !important;
  }
  
  /* 表相查询响应式 */
  .table-correlation-group {
    padding: 20px 16px;
  }
  
  .description-text {
    font-size: 14px;
  }
  
  .correlation-button {
    padding: 10px 24px;
    font-size: 15px;
    min-width: 140px;
  }
  
  .search-button {
    height: 44px;
    font-size: 16px;
  }
  
  .section-header {
    margin-bottom: 16px;
  }
  
  .section-title {
    font-size: 16px;
  }
  
  .clear-search-btn {
    padding: 4px 8px;
    font-size: 12px;
  }
  
  .clear-icon {
    width: 12px;
    height: 12px;
  }
  
  .record-item {
    padding: 12px;
  }
  
  .period-number {
    font-size: 15px;
  }
  
  .draw-date {
    font-size: 13px;
  }
  
  .balls-container {
    gap: 12px;
  }
  
  .front-balls {
    gap: 6px;
  }
  
  .ball {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .search-section,
  .lottery-records-section {
    margin: 0 8px 8px 8px;
    padding: 12px;
  }
  
  /* Element UI 日期查询小屏幕优化 */
  .mobile-date-pickers {
    gap: 10px;
  }
  
  .mobile-date-wrapper {
    gap: 4px;
  }
  
  .mobile-date-picker {
    font-size: 13px;
  }
  
  .mobile-date-picker :deep(.el-input__wrapper) {
    padding: 6px 8px !important;
    min-height: 36px !important;
  }
  
  .mobile-date-picker :deep(.el-input__inner) {
    font-size: 12px !important;
  }
  
  /* 表相查询小屏幕优化 */
  .table-correlation-group {
    padding: 16px 12px;
  }
  
  .description-text {
    font-size: 13px;
  }
  
  .correlation-button {
    padding: 8px 20px;
    font-size: 14px;
    min-width: 120px;
  }
  
  .search-button {
    height: 40px;
    font-size: 15px;
  }
  
  .back-button-container {
    margin-bottom: 8px;
  }
  
  .back-btn {
    padding: 4px 8px;
    font-size: 12px;
  }
  
  .back-icon {
    width: 12px;
    height: 12px;
  }
  
  .search-tabs {
    margin-bottom: 8px;
  }
  
  .search-tab {
    padding: 4px 8px;
    font-size: 12px;
  }
  
  .section-header {
    margin-bottom: 12px;
  }
  
  .section-title {
    font-size: 15px;
  }
  
  .record-item {
    padding: 10px;
  }
  
  .record-header {
    margin-bottom: 8px;
  }
  
  .period-number {
    font-size: 14px;
  }
  
  .draw-date {
    font-size: 12px;
  }
  
  .balls-container {
    gap: 8px;
    flex-wrap: wrap;
  }
  
  .front-balls {
    gap: 4px;
  }
  
  .ball {
    width: 26px;
    height: 26px;
    font-size: 11px;
  }
}

/* 桌面端样式 */
@media (min-width: 1024px) {
  .dlt-lottery-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
  }
  
  .search-section,
  .lottery-records-section {
    margin: 0 0 24px 0;
    padding: 24px;
  }
  
  .search-input-group {
    max-width: 400px;
  }
  
  .section-header {
    margin-bottom: 24px;
  }
  
  .section-title {
    font-size: 20px;
  }
  
  .records-list {
    gap: 20px;
  }
  
  .record-item {
    padding: 20px;
  }
  
  .period-number {
    font-size: 18px;
  }
  
  .draw-date {
    font-size: 15px;
  }
  
  .balls-container {
    gap: 20px;
  }
  
  .front-balls {
    gap: 10px;
  }
  
  .ball {
    width: 36px;
    height: 36px;
    font-size: 15px;
  }
}
</style>

