<template>
  <view class="container">
    <!-- 设备头部信息区域 -->
    <view class="device-header">
      <view class="device-info-row">
        <view class="device-name-container">
          <text class="device-name">{{ deviceInfo.name }}</text>
          <view 
            class="status-tag" 
            :class="deviceInfo.status === 1 ? 'status-online' : 'status-offline'"
          >
            <view class="status-dot" :class="{'offline-dot': deviceInfo.status === 1}"></view>
            {{ deviceInfo.status === 1 ? '在线' : '离线' }}
          </view>
        </view>
        
        <view class="refresh-btn" :class="{'refreshing': isRefreshing}" @tap="refreshData">
          <image src="/static/icons/refresh_icon.png" mode="aspectFit" style="width: 22px; height: 22px;"></image>
        </view>
      </view>
      
      <view class="device-meta-row">
        <view class="device-meta-item">
          <view class="meta-icon">
            <image src="/static/icons/device_icon.png" mode="aspectFit" style="width: 36rpx; height: 36rpx;"></image>
          </view>
          <text class="meta-label">设备编号：</text>
          <text class="meta-value">{{ deviceInfo.deviceId }}</text>
        </view>
        
        <view class="device-meta-item">
          <view class="meta-icon">
            <image src="/static/icons/location_icon.png" mode="aspectFit" style="width: 36rpx; height: 36rpx;"></image>
          </view>
          <text class="meta-label">安装位置：</text>
          <text class="meta-value">{{ deviceInfo.location }}</text>
        </view>
        
        <view class="device-meta-item">
          <view class="meta-icon">
            <image src="/static/icons/clock_icon.png" mode="aspectFit" style="width: 36rpx; height: 36rpx;"></image>
          </view>
          <text class="meta-label">最近更新：</text>
          <text class="meta-value">{{ formatDate(deviceInfo.lastUpdate) }}</text>
        </view>
      </view>
    </view>
    
    <!-- 采集数据展示区域 - 气象站 -->
    <view class="data-section" v-if="deviceInfo.deviceTypeId === '4'">
      <view class="section-title data-title">
        <text>气象数据</text>
      </view>
      
      <view class="data-grid">
        <!-- 气温 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">气温</text>
          <view class="data-value-container">
            <template v-if="weatherData.temperature">
              <text class="data-value" :class="{
                'updated': updatedFields.weather && updatedFields.weather.temperature,
                'value-warning': parseFloat(weatherData.temperature) > 35 || parseFloat(weatherData.temperature) < 5
              }">{{ weatherData.temperature }}</text>
              <text class="data-unit">℃</text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view> 
          <text class="data-time" v-if="weatherData.temperature">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
        </view>
        
        <!-- 湿度 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">湿度</text>
          <view class="data-value-container">
            <template v-if="weatherData.humidity">
              <text class="data-value" :class="{
                'updated': updatedFields.weather && updatedFields.weather.humidity,
                'value-warning': parseFloat(weatherData.humidity) > 85
              }">{{ weatherData.humidity }}</text>
              <text class="data-unit">%</text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view>
          <text class="data-time" v-if="weatherData.humidity">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
        </view>
        
        <!-- 降雨量 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">降雨量</text>
          <view class="data-value-container">
            <template v-if="weatherData.rainfall">
              <text class="data-value" :class="{
                'updated': updatedFields.weather && updatedFields.weather.rainfall,
                'value-alert': parseFloat(weatherData.rainfall) > 10
              }">{{ weatherData.rainfall }}</text>
              <text class="data-unit">mm</text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view>
          <text class="data-time" v-if="weatherData.rainfall">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
        </view>
        
        <!-- 风向 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">风向</text>
          <view class="data-value-container">
            <template v-if="weatherData.windDirection">
              <text class="data-value" :class="{'updated': updatedFields.weather && updatedFields.weather.windDirection}">{{ weatherData.windDirection }}</text>
              <text class="data-unit"></text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view>
          <text class="data-time" v-if="weatherData.windDirection">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
        </view>
        
        <!-- 风速 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">风速</text>
          <view class="data-value-container">
            <template v-if="weatherData.windSpeed">
              <text class="data-value" :class="{
                'updated': updatedFields.weather && updatedFields.weather.windSpeed,
                'value-alert': parseFloat(weatherData.windSpeed) > 8,
                'value-warning': parseFloat(weatherData.windSpeed) > 5 && parseFloat(weatherData.windSpeed) <= 8
              }">{{ weatherData.windSpeed }}</text>
              <text class="data-unit">m/s</text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view>
          <text class="data-time" v-if="weatherData.windSpeed">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
        </view>
        
        <!-- 气压 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">气压</text>
          <view class="data-value-container">
            <template v-if="weatherData.pressure">
              <text class="data-value" :class="{'updated': updatedFields.weather && updatedFields.weather.pressure}">{{ weatherData.pressure }}</text>
              <text class="data-unit">hPa</text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view>
          <text class="data-time" v-if="weatherData.pressure">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
        </view>
        
        <!-- 光照 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">光照</text>
          <view class="data-value-container">
            <template v-if="weatherData.illumination">
              <text class="data-value" :class="{'updated': updatedFields.weather && updatedFields.weather.illumination}">{{ weatherData.illumination }}</text>
              <text class="data-unit">lux</text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view>
          <text class="data-time" v-if="weatherData.illumination">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
        </view>
      </view>
    </view>
    
    <!-- 采集数据展示区域 - 土壤墒情 -->
    <view class="data-section" v-if="deviceInfo.deviceTypeId === '1'">
      <view class="section-title soil-title">
        <text>土壤数据</text>
      </view>
      
      <view class="data-grid">
        <!-- 土壤温度 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">土壤温度</text>
          <view class="data-value-container">
            <template v-if="soilData.temperature">
              <text class="data-value" :class="{
                'updated': updatedFields.soil && updatedFields.soil.temperature,
                'value-warning': parseFloat(soilData.temperature) > 30 || parseFloat(soilData.temperature) < 5
              }">{{ soilData.temperature }}</text>
              <text class="data-unit">℃</text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view>
          <text class="data-time" v-if="soilData.temperature">{{ formatDate(soilData.updateTime) || '未知' }}</text>
        </view>
        
        <!-- 土壤湿度 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">土壤湿度</text>
          <view class="data-value-container">
            <template v-if="soilData.moisture">
              <text class="data-value" :class="{
                'updated': updatedFields.soil && updatedFields.soil.moisture,
                'value-warning': parseFloat(soilData.moisture) < 20,
                'value-alert': parseFloat(soilData.moisture) < 10
              }">{{ soilData.moisture }}</text>
              <text class="data-unit">%</text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view>
          <text class="data-time" v-if="soilData.moisture">{{ formatDate(soilData.updateTime) || '未知' }}</text>
        </view>
        
        <!-- 氮含量 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">氮含量</text>
          <view class="data-value-container">
            <template v-if="soilData.nitrogen">
              <text class="data-value" :class="{
                'updated': updatedFields.soil && updatedFields.soil.nitrogen,
                'value-warning': parseFloat(soilData.nitrogen) < 120
              }">{{ soilData.nitrogen }}</text>
              <text class="data-unit">mg/kg</text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view>
          <text class="data-time" v-if="soilData.nitrogen">{{ formatDate(soilData.updateTime) || '未知' }}</text>
        </view>
        
        <!-- 磷含量 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">磷含量</text>
          <view class="data-value-container">
            <template v-if="soilData.phosphorus">
              <text class="data-value" :class="{
                'updated': updatedFields.soil && updatedFields.soil.phosphorus,
                'value-warning': parseFloat(soilData.phosphorus) < 30
              }">{{ soilData.phosphorus }}</text>
              <text class="data-unit">mg/kg</text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view>
          <text class="data-time" v-if="soilData.phosphorus">{{ formatDate(soilData.updateTime) || '未知' }}</text>
        </view>
        
        <!-- 钾含量 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">钾含量</text>
          <view class="data-value-container">
            <template v-if="soilData.potassium">
              <text class="data-value" :class="{
                'updated': updatedFields.soil && updatedFields.soil.potassium,
                'value-warning': parseFloat(soilData.potassium) < 150
              }">{{ soilData.potassium }}</text>
              <text class="data-unit">mg/kg</text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view>
          <text class="data-time" v-if="soilData.potassium">{{ formatDate(soilData.updateTime) || '未知' }}</text>
        </view>
        
        <!-- 土壤电导率 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">电导率</text>
          <view class="data-value-container">
            <template v-if="soilData.conductivity">
              <text class="data-value" :class="{
                'updated': updatedFields.soil && updatedFields.soil.conductivity,
                'value-alert': parseFloat(soilData.conductivity) > 0.8
              }">{{ soilData.conductivity }}</text>
              <text class="data-unit">μS/cm</text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view>
          <text class="data-time" v-if="soilData.conductivity">{{ formatDate(soilData.updateTime) || '未知' }}</text>
        </view>
        
        <!-- PH值 -->
        <view class="data-item" hover-class="data-item-hover">
          <text class="data-label">PH值</text>
          <view class="data-value-container">
            <template v-if="soilData.ph">
              <text class="data-value" :class="{
                'updated': updatedFields.soil && updatedFields.soil.ph,
                'value-warning': parseFloat(soilData.ph) < 5.5 || parseFloat(soilData.ph) > 8.5,
                'value-alert': parseFloat(soilData.ph) < 4.5 || parseFloat(soilData.ph) > 9
              }">{{ soilData.ph }}</text>
              <text class="data-unit"></text>
            </template>
            <text v-else class="data-value no-data">暂无数据</text>
          </view>
          <text class="data-time" v-if="soilData.ph">{{ formatDate(soilData.updateTime) || '未知' }}</text>
        </view>
      </view>
    </view>
    
    <!-- 告警信息列表 -->
    <view class="alerts-section">
      <view class="section-title">
        <text>告警信息</text>
        <view class="alert-badge" v-if="getUnhandledAlerts.length > 0">{{ getUnhandledAlerts.length }}</view>
      </view>
      
      <view class="alerts-list" v-if="getUnhandledAlerts.length > 0">
        <view 
          v-for="(item, index) in getUnhandledAlerts.slice(0, 3)" 
          :key="index"
          class="alert-item"
          :class="{
            'alert-urgent': item.level === 3, 
            'alert-warning': item.level === 2, 
            'alert-info': item.level === 1
          }"
        >
          <view class="alert-item-icon">
            <image v-if="item.level === 3" src="/static/icons/warning_icon.png" mode="aspectFit" style="width: 24px; height: 24px;"></image>
            <image v-else-if="item.level === 2" src="/static/icons/info_icon.png" mode="aspectFit" style="width: 24px; height: 24px;"></image>
            <image v-else src="/static/icons/success_icon.png" mode="aspectFit" style="width: 24px; height: 24px;"></image>
          </view>
          
          <view class="alert-item-info">
            <text class="alert-item-type">{{ item.type }}</text>
            <text class="alert-item-level">
              {{ item.level === 3 ? '紧急' : item.level === 2 ? '警告' : '提示' }}
            </text>
          </view>
          
          <view class="alert-item-time">{{ formatSmartTime(item.time) }}</view>
        </view>
      </view>
      
      <view v-else class="empty-alert">
        <text class="empty-text">暂无告警信息</text>
      </view>
    </view>
  </view>
</template>

<script>
import { getDeviceCollectorDetail } from "@/api/services/device.js";
import { formatSmartTime, formatDate } from '@/utils/dateUtils'
export default {
  data() {
    return {
      deviceInfo: {
        deviceId: '',
        name: '设备加载中...',
        status: '',
        location: '正在获取位置...',
        lastUpdate: '',
        deviceType: 'weather' ,// 默认类型，会根据API返回更新
		deviceTypeId:null
      },
      
      // 气象站数据
      weatherData: {
        temperature: '',
        humidity: '',
        rainfall: '',
        windDirection: '',
        windSpeed: '',
        pressure: '',
        illumination: '',
        updateTime: ''
      },
      
      // 土壤墒情数据
      soilData: {
        temperature: '',
        moisture: '',
        nitrogen: '',
        phosphorus: '',
        potassium: '',
        conductivity: '',
        ph: '',
        updateTime: ''
      },
      
      // 告警数据
      alertHistory: [],
      
      // 刷新状态
      isRefreshing: false,
      
      // 数值更新动画
      updatedFields: {
        weather: {},
        soil: {}
      },
    }
  },
  
  computed: {
    // 获取所有未处理的告警
    getUnhandledAlerts() {
      return this.alertHistory.filter(alert => alert.status === 0);//未处理
    }
  },
  
  onReady() {
    // 设置页面标题
    uni.setNavigationBarTitle({
      title: this.deviceInfo.name
    })
  },
  
  onLoad(options) {
	  uni.$once('passDeviceData', (data) => {
	      console.log('接收到数据', data);
		  // 如果有传入设备ID，则获取设备信息
		  if (data && data.deviceId) {
		    this.deviceInfo.deviceId = data.deviceId;
		    this.deviceInfo.location = data.fieldName;
		    this.deviceInfo.name = data.deviceName;
		    this.deviceInfo.status = data.status;
		    this.deviceInfo.deviceTypeId = data.deviceTypeId || '';
		    
		    // 加载设备详情
		    this.fetchDeviceCollectorDetail();
		  }
	    });
    
  },
  
  methods: {
	formatDate,
    formatSmartTime,
    // 获取设备采集器详情
    fetchDeviceCollectorDetail() {
      if (!this.deviceInfo.deviceId) return;
      
      uni.showLoading({
        title: '加载数据中...'
      });
      
      getDeviceCollectorDetail(this.deviceInfo.deviceId)
        .then(res => {
          console.log('设备详情数据:', res);
          if (res.data.data && res.data.code === 200) {
            const detail = res.data.data;
            this.deviceInfo.lastUpdate = detail.collectTime
            // 保存旧数据用于比较
            let oldData = null;
            
            // 根据设备类型更新数据
            if (this.deviceInfo.deviceTypeId === '4') { //气象设备
				if(this.weatherData){
					oldData = JSON.parse(JSON.stringify(this.weatherData));
				}
              // 更新气象数据
              this.weatherData = {
                temperature: detail.temperature || '',
                humidity: detail.humidity || '',
                rainfall: detail.rainfall || '',
                windDirection: detail.windDirection || '',
                windSpeed: detail.windSpeed || '',
                pressure: detail.pressure || '',
                illumination: detail.illumination || '',
                updateTime: detail.collectTime|| '暂无数据'
              };
              
              // 检查哪些字段发生了变化
              this.updatedFields.weather = {};
              Object.keys(this.weatherData).forEach(key => {
                if (key !== 'updateTime' && this.weatherData[key] !== oldData[key]) {
                  this.updatedFields.weather[key] = true;
                  
                  // 1秒后清除动画标记
                  setTimeout(() => {
                    this.$set(this.updatedFields.weather, key, false);
                  }, 1000);
                }
              });
              
            } else if (this.deviceInfo.deviceTypeId === '1') { // 土壤设备
			if(this.soilData){
				oldData = JSON.parse(JSON.stringify(this.soilData));
			}
              
              // 更新土壤数据
              this.soilData = {
                temperature: detail.temperature || '',
                moisture: detail.soilTemperature || '',
                nitrogen: detail.soilN || '',
                phosphorus: detail.soilP || '',
                potassium: detail.soilK || '',
                conductivity: detail.conductivity || '',
                ph: detail.ph || '',
                updateTime: detail.collectTime || '暂无数据'
              };
              
              // 检查哪些字段发生了变化
              this.updatedFields.soil = {};
              Object.keys(this.soilData).forEach(key => {
                if (key !== 'updateTime' && this.soilData[key] !== oldData[key]) {
                  this.updatedFields.soil[key] = true;
                  
                  // 1秒后清除动画标记
                  setTimeout(() => {
                    this.$set(this.updatedFields.soil, key, false);
                  }, 1000);
                }
              });
            }
            
            // 更新告警信息
            if (detail.alertRecordList && detail.alertRecordList.length > 0) {
              this.alertHistory = detail.alertRecordList.map(alert => ({
                id: alert.alertId,
                time: alert.alertTime,
                type: alert.alertContent,
                status: alert.processStatus,
                level: alert.alertLevel
              }));
            }
            
            // 更新页面标题
            uni.setNavigationBarTitle({
              title: this.deviceInfo.name
            });
          } else {
            uni.showToast({
              title: '暂无设备信息',
              icon: 'none'
            });
          }
        })
        .catch(error => {
          console.error('获取设备详情失败', error);
          uni.showToast({
            title: '获取设备数据失败',
            icon: 'none'
          });
        })
        .finally(() => {
          uni.hideLoading();
          this.isRefreshing = false;
        });
    },
	// 格式还日期格式；返回 今天：18:00
    // formatSmartTime(timeStr) {
    //   if (!timeStr) return '未知';
    
    //   // iOS兼容：将 "2025-06-19 09:15:00" 转换为 "2025-06-19T09:15:00"
    //   const safeStr = timeStr.replace(' ', 'T');
    
    //   const inputDate = new Date(safeStr);
    //   if (isNaN(inputDate.getTime())) return '时间格式错误';
    
    //   const now = new Date();
    
    //   // 取日期差值（单位：天）
    //   const inputDayStart = new Date(inputDate.getFullYear(), inputDate.getMonth(), inputDate.getDate());
    //   const nowDayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
    
    //   const diffTime = nowDayStart - inputDayStart;
    //   const oneDay = 1000 * 60 * 60 * 24;
    
    //   const timePart = inputDate.toTimeString().slice(0, 5); // HH:mm
    
    //   if (diffTime === 0) {
    //     return `今天 ${timePart}`;
    //   } else if (diffTime === oneDay) {
    //     return `昨天 ${timePart}`;
    //   } else if (diffTime === oneDay * 2) {
    //     return `前天 ${timePart}`;
    //   } else {
    //     return `${inputDate.getMonth() + 1}月${inputDate.getDate()}日 ${timePart}`;
    //   }
    // },

    // 刷新数据
    refreshData() {
      if (this.isRefreshing) return;
      
      this.isRefreshing = true;
      this.fetchDeviceCollectorDetail();
    },
	// 格式化日期
	// formatDate(dateStr) {
	//   if (!dateStr) return '未知';
	  
	//   // 解析为 Date
	//   const parsedStr = dateStr.replace(' ', 'T'); 
	//   const date = new Date(parsedStr);
	//   if (isNaN(date)) return '无效时间';
	  
	//   const now = new Date();
	
	//   // 计算差时长（分钟）
	//   const diff = Math.floor((now - date) / 1000 / 60);
	  
	//   if (diff < 1) return '刚刚更新';
	//   if (diff < 5) return '1分钟前更新';
	//   if (diff < 10) return '5分钟前更新';
	//   if (diff < 60) return `${diff}分钟前更新`;
	  
	//   if (diff < 120) return '1小时前更新';
	//   if (diff < 24 * 60) return `${Math.floor(diff / 60)}小时前更新`;
	//   if (diff < 7 * 24 * 60) return `${Math.floor(diff / (60 * 24))}天前更新`;
	  
	//   return parsedStr.split('T')[0] + ' 更新';
	// },
  }
}
</script>

<style>
/* 基础样式 */
.container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #F8FCF9;
  padding-bottom: 30rpx;
}

/* 设备头部样式 */
.device-header {
  background-color: #FFFFFF;
  border-radius: 20rpx;
  padding: 30rpx;
  margin: 30rpx 30rpx 30rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
  border: 1rpx solid rgba(210, 237, 217, 0.5);
}

.device-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28rpx;
}

.device-name-container {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.refresh-btn {
  width: 48rpx;
  height: 48rpx;
  background-color: rgba(76, 175, 80, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12rpx;
  transition: transform 0.3s ease;
}

.refresh-btn:active {
  transform: rotate(180deg);
}

.device-name {
  font-size: 36rpx;
  color: #333333;
  font-weight: 600;
  margin-bottom: 12rpx;
}

.status-tag {
  padding: 6rpx 16rpx 6rpx 28rpx;
  border-radius: 30rpx;
  font-size: 24rpx;
  font-weight: 500;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.status-online {
  background-color: rgba(76, 175, 80, 0.1);
  color: #3BB44A;
}

.status-offline {
  background-color: rgba(245, 108, 108, 0.1);
  color: #F56C6C;
  padding-left: 28rpx;
}

.status-dot {
  position: absolute;
  width: 6rpx;
  height: 6rpx;
  background-color: #3BB44A;
  border-radius: 50%;
  top: 50%;
  left: 12rpx;
  transform: translateY(-50%);
  box-shadow: 0 0 4rpx rgba(76, 175, 80, 0.8);
  animation: blink 1.5s infinite;
  display: inline-block;
}

.status-dot.offline-dot {
  background-color: #F56C6C;
  box-shadow: 0 0 4rpx rgba(245, 108, 108, 0.8);
}

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

.device-meta-row {
  display: flex;
  flex-direction: column;
  background-color: #F9FCFA;
  padding: 20rpx 24rpx;
  border-radius: 16rpx;
  border: 1rpx solid rgba(210, 237, 217, 0.8);
}

.device-meta-item {
  display: flex;
  align-items: center;
  font-size: 28rpx;
  margin-top: 18rpx;
}

.device-meta-item:first-child {
  margin-top: 0;
}

.meta-icon {
  width: 36rpx;
  height: 36rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12rpx;
}

.meta-label {
  color: #777777;
  min-width: 140rpx;
  font-size: 28rpx;
}

.meta-value {
  color: #333333;
  flex: 1;
  font-size: 28rpx;
  font-weight: 500;
}

/* 数据展示区域 */
.data-section {
  margin: 0 30rpx 30rpx;
  background-color: #FFFFFF;
  border-radius: 24rpx;
  padding: 30rpx 24rpx;
  box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.05);
  border: 1rpx solid rgba(210, 237, 217, 0.5);
}

.section-title {
  font-size: 32rpx;
  font-weight: 600;
  color: #333333;
  margin-bottom: 20rpx;
  padding: 0 10rpx 16rpx;
  display: flex;
  align-items: center;
  position: relative;
  border-bottom: 2rpx solid rgba(59, 180, 74, 0.1);
}

.section-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 8rpx;
  height: 32rpx;
  background: linear-gradient(to bottom, #4CAF50, #81C784);
  border-radius: 4rpx;
  margin-right: 10rpx;
}

.section-title text {
  margin-left: 20rpx;
}

.alert-badge {
  background-color: #F56C6C;
  color: #FFFFFF;
  font-size: 22rpx;
  border-radius: 30rpx;
  padding: 2rpx 12rpx;
  margin-left: 12rpx;
  font-weight: normal;
  min-width: 32rpx;
  text-align: center;
}

.data-grid {
  display: flex;
  flex-wrap: wrap;
  padding: 16rpx 0;
  width: 100%;
  margin: 0 -12rpx;
}

.data-item {
  width: calc(50% - 24rpx);
  margin: 0 12rpx 24rpx;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  background: linear-gradient(to bottom right, #F9FFFB, #FFFFFF);
  border-radius: 24rpx;
  padding: 28rpx 24rpx;
  box-sizing: border-box;
  box-shadow: 0 6rpx 18rpx rgba(0, 0, 0, 0.06), inset 0 1rpx 3rpx rgba(255, 255, 255, 0.8);
  position: relative;
  border: 1rpx solid rgba(210, 237, 217, 0.6);
  transition: all 0.25s ease;
  overflow: hidden;
  min-height: 180rpx;
}

.data-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 8rpx;
  height: 100%;
  background: linear-gradient(to bottom, #4CAF50, #81C784);
  opacity: 0.9;
  border-radius: 4rpx 0 0 4rpx;
}

.data-item-hover {
  transform: scale(1.02);
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08), inset 0 1rpx 3rpx rgba(255, 255, 255, 0.8);
  background: linear-gradient(to bottom right, #F7FFF9, #FFFFFF);
}

.data-label {
  font-size: 26rpx;
  color: #666666;
  margin-bottom: 22rpx;
  font-weight: 500;
  align-self: flex-start;
}

.data-value-container {
  display: flex;
  align-items: flex-end;
  width: 100%;
  margin-bottom: 18rpx;
}

.data-value {
  font-size: 40rpx;
  color: #222222;
  font-weight: 700;
  line-height: 1;
}

.data-value.no-data {
  font-size: 28rpx;
  color: #999999;
  font-weight: normal;
}

.data-unit {
  font-size: 24rpx;
  color: #999999;
  margin-left: 6rpx;
  padding-bottom: 6rpx;
  align-self: flex-end;
}

.data-time {
  font-size: 20rpx;
  color: #AAAAAA;
  width: 100%;
  text-align: right;
}

/* 数据更新动画 */
@keyframes fadeNumberChange {
  0% {
    opacity: 0.6;
    transform: scale(0.95);
  }
  50% {
    opacity: 1;
    transform: scale(1.05);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.data-value.updated {
  animation: fadeNumberChange 0.8s ease;
}

/* 异常值样式 */
.value-warning {
  color: #E6A23C !important;
}

.value-alert {
  color: #F56C6C !important;
}

/* 点击波纹效果（可选）*/
@keyframes ripple {
  0% {
    transform: scale(0);
    opacity: 0.6;
  }
  100% {
    transform: scale(2);
    opacity: 0;
  }
}

.data-item::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(76, 175, 80, 0.1);
  border-radius: 24rpx;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: -1;
}

.data-item-hover::after {
  opacity: 1;
}

/* 告警信息列表 */
.alerts-section {
  margin: 0 30rpx 30rpx;
  background-color: #FFFFFF;
  border-radius: 20rpx;
  padding: 30rpx 24rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  border: 1rpx solid rgba(210, 237, 217, 0.5);
}

.alerts-list {
  display: flex;
  flex-direction: column;
}

.alert-item {
  display: flex;
  align-items: center;
  padding: 24rpx 20rpx;
  border-radius: 12rpx;
  margin-bottom: 16rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  position: relative;
  border: 1rpx solid transparent;
  transition: transform 0.2s ease;
}

.alert-item:active {
  transform: scale(0.98);
}

.alert-urgent {
  background-color: #FEF3F3;
  border-left: 4rpx solid #F56C6C;
  border-color: rgba(245, 108, 108, 0.2);
}

.alert-warning {
  background-color: #FFF8E6;
  border-left: 4rpx solid #E6A23C;
  border-color: rgba(230, 162, 60, 0.2);
}

.alert-info {
  background-color: #F2FAF5;
  border-left: 4rpx solid #67C23A;
  border-color: rgba(103, 194, 58, 0.2);
}

.alert-item-icon {
  width: 50rpx;
  height: 50rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16rpx;
}

.alert-item-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.alert-item-type {
  font-size: 28rpx;
  color: #333333;
  font-weight: 500;
  margin-bottom: 8rpx;
}

.alert-item-level {
  font-size: 24rpx;
  color: #999999;
}

.alert-item-time {
  font-size: 24rpx;
  color: #999999;
  margin-left: 16rpx;
  min-width: 100rpx;
  text-align: right;
}

.empty-alert {
  padding: 60rpx 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.empty-text {
  font-size: 28rpx;
  color: #999999;
}

/* 刷新按钮旋转动画 */
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.refresh-btn.refreshing {
  animation: spin 1.2s linear infinite;
}

/* 土壤数据标题样式调整 */
.soil-title, .data-title {
  display: flex;
  align-items: center;
  position: relative;
  padding-left: 24rpx;
}

.soil-title::before, .data-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 8rpx;
  height: 36rpx;
  background: linear-gradient(to bottom, #4CAF50, #81C784);
  border-radius: 4rpx;
}

.soil-title text, .data-title text {
  margin-left: 16rpx;
  font-weight: 600;
}
</style> 