<script setup>
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
import * as echarts from 'echarts'
import { Odometer, CircleCheckFilled, VideoCameraFilled, WarnTriangleFilled } from '@element-plus/icons-vue'
import { convertPipeline, convertPoints } from '@/utils/coordTransform'
import { getGasDashboardSummary } from '@/api/pipeNetwork/basic'

const nowText = ref('2025/12/31 12:59:59')
const weekText = ref('星期三')
const mapError = ref('')
const loading = ref(false)

// ========== 仪表盘数据 ==========
const dashboardData = ref({})

const baseCards = computed(() => {
  const bs = dashboardData.value.baseStats || {}
  return [
    { label: '监测点总数', value: bs.totalPoints || 0, unit: '个', icon: Odometer, color: '#60b8ff' },
    { label: '在线监测点', value: bs.onlinePoints || 0, unit: '个', icon: CircleCheckFilled, color: '#52e0a8' },
    { label: '离线监测点', value: bs.offlinePoints || 0, unit: '个', icon: VideoCameraFilled, color: '#ff8e8e' },
    { label: '异常设备', value: bs.alarmCount || 0, unit: '个', icon: WarnTriangleFilled, color: '#ffb54d' }
  ]
})

const operationSummary = computed(() => {
  const ps = dashboardData.value.pipeStats || {}
  return [
    { label: '管网总长度', value: (ps.totalLength || 0) + 'km' },
    { label: '燃气管网', value: (ps.gasNetworks || 0) + '条' },
    { label: '管网总数', value: (ps.totalNetworks || 0) + '条' }
  ]
})

const repairRecords = computed(() => {
  const list = dashboardData.value.repairTrend || []
  if (list.length > 0) return list
  return [
    { month: '1月', value: 0 }, { month: '2月', value: 0 }, { month: '3月', value: 0 },
    { month: '4月', value: 0 }, { month: '5月', value: 0 }, { month: '6月', value: 0 }
  ]
})

const pointRows = computed(() => {
  const list = dashboardData.value.pointRows || []
  return list.length > 0 ? list : [{ id: 1, name: '暂无数据', time: '--', value: '--', status: '离线' }]
})

const equipmentRows = computed(() => {
  const list = dashboardData.value.equipmentRows || []
  return list.length > 0 ? list : [{ id: 1, name: '暂无数据', code: '--', location: '--', status: '--' }]
})

const warningRows = computed(() => {
  const list = dashboardData.value.warningRows || []
  return list.length > 0 ? list : [{ level: '中', title: '暂无告警', code: '--', time: '--:--:--', desc: '当前无告警信息', tag: '正常' }]
})

const hazardSummary = computed(() => {
  const map = dashboardData.value.hazardStats || {}
  return [
    { label: '重大隐患', value: map['重大隐患'] || 0, color: '#ff3030' },
    { label: '较大隐患', value: map['较大隐患'] || 0, color: '#ff9f1a' },
    { label: '一般隐患', value: map['一般隐患'] || 0, color: '#f3e64d' }
  ]
})

const mapKpis = computed(() => {
  const bs = dashboardData.value.baseStats || {}
  const es = dashboardData.value.equipmentStats || {}
  const total = bs.totalPoints || 0
  const online = bs.onlinePoints || 0
  return [
    { label: '在线率', value: total > 0 ? (online / total * 100).toFixed(1) + '%' : '--' },
    { label: '压力均值', value: (es.avgPressure || 0) + 'MPa' },
    { label: '今日告警', value: (es.todayAlarm || 0) + '条' }
  ]
})

const pipelineLines = [
  {
    name: '燃气1',
    color: '#ff3030',
    points: [
      [110.404947, 28.433419],
      [110.404836, 28.433429],
      [110.403275, 28.433571],
      [110.401084, 28.433876],
      [110.399601, 28.433876],
      [110.398112, 28.433979],
      [110.396717, 28.434314],
      [110.394299, 28.434538],
      [110.394352, 28.434887],
      [110.391969, 28.434985],
      [110.384374, 28.435695],
      [110.381418, 28.43559],
      [110.377993, 28.436193],
      [110.376062, 28.436385],
      [110.374231, 28.43655],
      [110.372584, 28.437107],
      [110.371292, 28.4377],
      [110.370581, 28.438198],
      [110.369831, 28.438821]
    ]
  },
  {
    name: '燃气2',
    color: '#ff3030',
points: [
      [110.361433, 28.454979],
      [110.362363, 28.453169],
      [110.362851, 28.452213],
      [110.364377, 28.452443],
      [110.365138, 28.45246],
      [110.366462, 28.452157],
      [110.369549, 28.451441],
      [110.37219, 28.450897],
      [110.372753, 28.450901],
      [110.373875, 28.451194],
      [110.373913, 28.451107],
      [110.374597, 28.451476]
    ]
  }
]

const pipePoints = [
  { name: 'A点', value: '0.22MPa', lng: 110.362363, lat: 28.453169 },
  { name: 'B点', value: '0.24MPa', lng: 110.366462, lat: 28.452157 },
  { name: 'C点', value: '0.18MPa', lng: 110.373875, lat: 28.451194},
  { name: 'D点', value: '0.23MPa', lng: 110.401084, lat: 28.433876 },
  { name: 'E点', value: '0.25MPa', lng: 110.391969, lat: 28.434985 },
  { name: 'F点', value: '0.19MPa', lng: 110.376062, lat: 28.436385 },
  { name: 'G点', value: '0.21MPa', lng: 110.370581, lat: 28.438198}
]

const mapWrapRef = ref(null)
const repairChartRef = ref(null)
const hazardChartRef = ref(null)
let mapInstance = null
let repairChart = null
let hazardChart = null
let clockTimer = null

function formatWeek(day) {
  return ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'][day]
}

function pad(value) {
  return String(value).padStart(2, '0')
}

function updateClock() {
  const now = new Date()
  nowText.value = `${now.getFullYear()}/${pad(now.getMonth() + 1)}/${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`
  weekText.value = formatWeek(now.getDay())
}

function initRepairChart() {
  if (!repairChartRef.value) return
  repairChart?.dispose()
  repairChart = echarts.init(repairChartRef.value)
  const data = repairRecords.value
  repairChart.setOption({
    grid: { left: 30, right: 12, top: 20, bottom: 24, containLabel: true },
    xAxis: {
      type: 'category',
      data: data.map(item => item.month),
      axisLine: { lineStyle: { color: 'rgba(91, 167, 219, 0.8)' } },
      axisLabel: { color: '#d2efff' }
    },
    yAxis: {
      type: 'value',
      splitLine: { lineStyle: { color: 'rgba(91, 167, 219, 0.18)' } },
      axisLine: { show: false },
      axisLabel: { color: '#d2efff' }
    },
    tooltip: { trigger: 'axis' },
    series: [{
      type: 'bar',
      barWidth: 24,
      data: data.map(item => item.value),
      itemStyle: {
        borderRadius: [6, 6, 0, 0],
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          { offset: 0, color: '#38d8ff' },
          { offset: 1, color: '#166dff' }
        ])
      }
    }]
  })
}

function initHazardChart() {
  if (!hazardChartRef.value) return
  hazardChart?.dispose()
  hazardChart = echarts.init(hazardChartRef.value)
  const data = hazardSummary.value
  hazardChart.setOption({
    grid: { left: 18, right: 18, top: 10, bottom: 10, containLabel: true },
    xAxis: {
      type: 'value',
      splitLine: { show: false },
      axisLine: { show: false },
      axisTick: { show: false },
      axisLabel: { show: false }
    },
    yAxis: {
      type: 'category',
      data: data.map(item => item.label),
      axisLine: { show: false },
      axisTick: { show: false },
      axisLabel: { color: '#d2efff', fontSize: 13 }
    },
    tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
    series: [{
      type: 'bar',
      data: data.map(item => ({ value: item.value, itemStyle: { color: item.color, borderRadius: 10 } })),
      barWidth: 14,
      label: { show: true, position: 'right', color: '#fff', fontWeight: 'bold' },
      showBackground: true,
      backgroundStyle: { color: 'rgba(255,255,255,0.08)', borderRadius: 10 }
    }]
  })
}

function waitForBMapGL() {
  return new Promise((resolve, reject) => {
    if (window.BMapGL) {
      resolve(window.BMapGL)
      return
    }
    let attempts = 0
    const timer = setInterval(() => {
      attempts += 1
      if (window.BMapGL) {
        clearInterval(timer)
        resolve(window.BMapGL)
        return
      }
      if (attempts >= 100) {
        clearInterval(timer)
        reject(new Error('百度地图加载超时'))
      }
    }, 200)
  })
}

function addPipeLine(BMapGL, pipe) {
  const bmapPoints = pipe.points.map(([lng, lat]) => new BMapGL.Point(lng, lat))
  const polyline = new BMapGL.Polyline(bmapPoints, {
    strokeColor: pipe.color,
    strokeWeight: 4,
    strokeOpacity: 0.95
  })
  mapInstance.addOverlay(polyline)

  bmapPoints.forEach((point, index) => {
    const ring = new BMapGL.Circle(point, 14, {
      strokeColor: '#ff3030',
      strokeWeight: 2,
      strokeOpacity: 0.7,
      fillColor: 'rgba(255,48,48,0.08)',
      fillOpacity: 0.18
    })
    mapInstance.addOverlay(ring)
  })
}

function addPipePoint(BMapGL, point) {
  const markerPoint = new BMapGL.Point(point.lng, point.lat)
  const marker = new BMapGL.Marker(markerPoint)
  mapInstance.addOverlay(marker)
  const label = new BMapGL.Label(`${point.name} ${point.value}`, { offset: new BMapGL.Size(-42, -40) })
  label.setPosition(markerPoint)
  label.setStyle({
    color: '#d8faff',
    background: 'rgba(18, 68, 112, 0.75)',
    border: '1px solid rgba(255, 48, 48, 0.55)',
    borderRadius: '8px',
    padding: '5px 8px',
    fontSize: '12px'
  })
  mapInstance.addOverlay(label)
}

async function initMap() {
  if (!mapWrapRef.value) return
  try {
    const BMapGL = await waitForBMapGL()
    mapInstance = new BMapGL.Map(mapWrapRef.value, { enableMapClick: true })
    const center = new BMapGL.Point(110.3965, 28.4638)
    mapInstance.centerAndZoom(center, 15)
    mapInstance.enableScrollWheelZoom(true)
    mapInstance.setMapStyleV2({ styleId: 'a0f4e6e6f9e7a6c5d8e7f7e7f7e7f7e5' })

    const bdPipelineLines = pipelineLines.map(pipe => convertPipeline(pipe))
    const bdPipePoints = convertPoints(pipePoints)
    bdPipelineLines.forEach(pipe => addPipeLine(BMapGL, pipe))
    bdPipePoints.forEach(point => addPipePoint(BMapGL, point))
  } catch (error) {
    mapError.value = '百度地图加载失败，请检查地图脚本或网络连接。'
  }
}

function handleResize() {
  repairChart?.resize()
  hazardChart?.resize()
}

async function loadDashboardData() {
  loading.value = true
  try {
    const res = await getGasDashboardSummary()
    dashboardData.value = res.data || {}
  } catch (e) { console.error(e) } finally { loading.value = false }
}

onMounted(async () => {
  updateClock()
  clockTimer = window.setInterval(updateClock, 1000)
  await loadDashboardData()
  await nextTick()
  initRepairChart()
  initHazardChart()
  initMap()
  window.addEventListener('resize', handleResize)
})

onBeforeUnmount(() => {
  if (clockTimer) window.clearInterval(clockTimer)
  window.removeEventListener('resize', handleResize)
  repairChart?.dispose()
  hazardChart?.dispose()
  mapInstance = null
})
</script>

<template>
  <div class="gas-home-screen">
    <div class="screen-header">
      <div class="header-time">{{ nowText }} {{ weekText }}</div>
      <div class="header-title-wrap">
        <div class="header-title">燃气管网安全运行监测系统</div>
        <div class="header-subtitle">Gas Pipeline Operation Dashboard</div>
      </div>
      <div class="header-tags">
        <span class="header-tag">实时监测</span>
        <span class="header-tag">管网运行</span>
        <span class="header-tag">隐患预警</span>
      </div>
    </div>

    <div class="screen-body">
      <div class="side-panel left-panel">
        <section class="panel-card base-card">
          <div class="panel-title">基础概况</div>
          <div class="base-grid">
            <div v-for="item in baseCards" :key="item.label" class="base-item">
              <div class="base-icon" :style="{ background: item.color }">
                <component :is="item.icon" class="base-icon-svg" />
              </div>
              <div class="base-text">
                <div class="base-label">{{ item.label }}</div>
                <div class="base-value">{{ item.value }}<span>{{ item.unit }}</span></div>
              </div>
            </div>
          </div>
        </section>

        <section class="panel-card">
          <div class="panel-title">维修趋势</div>
          <div ref="repairChartRef" class="chart-box repair-chart"></div>
        </section>

        <section class="panel-card table-card">
          <div class="panel-title">监测点数据</div>
          <div class="table-wrap">
            <table class="data-table">
              <thead>
                <tr>
                  <th>序号</th>
                  <th>监测点</th>
                  <th>时间</th>
                  <th>数值</th>
                  <th>状态</th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="row in pointRows" :key="row.id">
                  <td>{{ row.id }}</td>
                  <td :title="`${row.name || '-'} / ${row.deviceName || row.deviceCode || '-'}`">{{ row.name }} / {{ row.deviceName || row.deviceCode || '-' }}</td>
                  <td :title="row.time">{{ row.time }}</td>
                  <td :title="row.value">{{ row.value }}</td>
                  <td :class="['status-cell', row.status === '在线' ? 'ok' : row.status === '预警' ? 'warn' : 'off']">{{ row.status }}</td>
                </tr>
              </tbody>
            </table>
          </div>
        </section>
      </div>

      <div class="center-panel">
        <div class="map-stage">
          <div class="map-stage-top">
            <div class="summary-strip">
              <div v-for="item in operationSummary" :key="item.label" class="summary-item">
                <span class="summary-label">{{ item.label }}</span>
                <strong class="summary-value">{{ item.value }}</strong>
              </div>
            </div>
            <div class="map-kpis">
              <div v-for="item in mapKpis" :key="item.label" class="map-kpi">
                <span>{{ item.label }}</span>
                <strong>{{ item.value }}</strong>
              </div>
            </div>
          </div>

          <div ref="mapWrapRef" class="map-view"></div>
          <div v-if="mapError" class="map-error">{{ mapError }}</div>

          <div class="map-panel info-panel">
            <div class="mini-title">当前管网信息</div>
            <div class="mini-row"><span>管网总长度</span><strong>{{ (dashboardData.pipeStats && dashboardData.pipeStats.totalLength) || 0 }}km</strong></div>
            <div class="mini-row"><span>燃气管网</span><strong>{{ (dashboardData.pipeStats && dashboardData.pipeStats.gasNetworks) || 0 }}条</strong></div>
            <div class="mini-row"><span>设备总数</span><strong>{{ (dashboardData.equipmentStats && dashboardData.equipmentStats.totalEquipment) || 0 }}台</strong></div>
          </div>

          <div class="map-panel point-panel">
            <div class="mini-title">当前管点信息</div>
            <div class="mini-row"><span>监测点总数</span><strong>{{ (dashboardData.baseStats && dashboardData.baseStats.totalPoints) || 0 }}个</strong></div>
            <div class="mini-row"><span>在线监测点</span><strong>{{ (dashboardData.baseStats && dashboardData.baseStats.onlinePoints) || 0 }}个</strong></div>
            <div class="mini-row"><span>离线监测点</span><strong>{{ (dashboardData.baseStats && dashboardData.baseStats.offlinePoints) || 0 }}个</strong></div>
          </div>
        </div>
      </div>

      <div class="side-panel right-panel">
        <section class="panel-card">
          <div class="panel-title">设备运行</div>
          <div class="table-wrap equipment-wrap">
            <table class="data-table compact-table">
              <thead>
                <tr>
                  <th>序号</th>
                  <th>设备名称</th>
                  <th>设备编号</th>
                  <th>位置</th>
                  <th>状态</th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="row in equipmentRows" :key="row.id">
                  <td>{{ row.id }}</td>
                  <td>{{ row.name }}</td>
                  <td>{{ row.code }}</td>
                  <td>{{ row.location }}</td>
                  <td>{{ row.status }}</td>
                </tr>
              </tbody>
            </table>
          </div>
        </section>

        <section class="panel-card warning-card">
          <div class="panel-title">告警动态</div>
          <div class="warning-scroll">
            <div class="warning-list">
              <div v-for="(item, index) in warningRows" :key="index" class="warning-item" :class="item.level === '高' ? 'danger' : 'notice'">
                <div class="warning-side">
                  <div class="warning-badge">{{ item.level }}</div>
                  <div class="warning-tag">{{ item.tag }}</div>
                </div>
                <div class="warning-main">
                  <div class="warning-title-row">
                    <span class="warning-title">{{ item.title }}</span>
                    <span class="warning-time">{{ item.time }}</span>
                  </div>
                  <div class="warning-code">{{ item.code }}</div>
                  <div class="warning-desc">{{ item.desc }}</div>
                </div>
              </div>
            </div>
          </div>
        </section>

        <section class="panel-card hazard-card">
          <div class="panel-title">隐患统计</div>
          <div class="hazard-summary three-col">
            <div v-for="item in hazardSummary" :key="item.label" class="hazard-summary-item">
              <span class="hazard-dot" :style="{ background: item.color }"></span>
              <span>{{ item.label }}</span>
              <strong :style="{ color: item.color }">{{ item.value }}项</strong>
            </div>
          </div>
          <div ref="hazardChartRef" class="chart-box hazard-chart"></div>
        </section>
      </div>
    </div>

    <a href="https://deerflow.tech" target="_blank" class="deerflow-mark" title="Created By Deerflow">
      <span class="deerflow-diamond">◆</span>
      <span class="deerflow-text">Deerflow</span>
    </a>
  </div>
</template>

<style scoped lang="scss">
.gas-home-screen {
  min-height: 100vh;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(14, 42, 70, 0.96), rgba(8, 20, 37, 1)),
    radial-gradient(circle at center, rgba(36, 122, 184, 0.18), transparent 58%),
    #081425;
  position: relative;
}

.gas-home-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle at 28% 32%, rgba(56, 216, 255, 0.06) 0%, transparent 45%),
    radial-gradient(circle at 72% 58%, rgba(22, 109, 255, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 50% 85%, rgba(56, 216, 255, 0.04) 0%, transparent 35%);
  animation: bgPulse 8s ease-in-out infinite alternate;
}

@keyframes bgPulse {
  0% { opacity: 0.6; }
  100% { opacity: 1; }
}

.screen-header {
  height: 72px;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 320px 1fr 320px;
  align-items: center;
  position: relative;
  z-index: 1;
  background: linear-gradient(90deg, rgba(27, 98, 155, 0.95), rgba(18, 53, 98, 0.95));
  border-bottom: 1px solid rgba(93, 194, 255, 0.28);
}

.screen-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 5%;
  width: 90%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(56, 216, 255, 0.7), rgba(22, 109, 255, 0.7), transparent);
  animation: headerGlow 4s ease-in-out infinite alternate;
}

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

.header-time {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #ddf6ff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(56, 216, 255, 0.35);
}

.header-title-wrap {
  text-align: center;
}

.header-title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 3px;
  background: linear-gradient(180deg, #e8f6ff 0%, #8fd6ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-subtitle {
  margin-top: 4px;
  color: rgba(196, 234, 255, 0.65);
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.header-tags {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.header-tag {
  padding: 6px 14px;
  border: 1px solid rgba(117, 206, 255, 0.35);
  border-radius: 16px;
  color: #d8f5ff;
  background: rgba(13, 77, 128, 0.45);
  font-size: 12px;
  letter-spacing: 1px;
  transition: all 0.3s;
  cursor: default;
}

.header-tag:hover {
  border-color: rgba(117, 206, 255, 0.7);
  background: rgba(13, 77, 128, 0.65);
  box-shadow: 0 0 16px rgba(56, 216, 255, 0.15);
}

.screen-body {
  height: calc(100vh - 72px);
  padding: 12px;
  display: grid;
  grid-template-columns: 360px 1fr 360px;
  gap: 12px;
  position: relative;
  z-index: 1;
}

.side-panel,
.center-panel {
  min-height: 0;
}

.left-panel,
.right-panel {
  display: grid;
  gap: 12px;
}

.left-panel {
  grid-template-rows: 220px 220px 1fr;
}

.right-panel {
  grid-template-rows: 250px 260px 1fr;
}

.panel-card {
  min-height: 0;
  padding: 14px;
  position: relative;
  background: linear-gradient(180deg, rgba(13, 33, 56, 0.88), rgba(10, 25, 42, 0.88));
  border: 1px solid rgba(65, 158, 219, 0.22);
  border-radius: 12px;
  box-shadow: 0 2px 24px rgba(0, 0, 0, 0.25), inset 0 0 0 1px rgba(255, 255, 255, 0.025);
  transition: border-color 0.4s;
}

.panel-card::after {
  content: '';
  position: absolute;
  top: -1px;
  left: 20px;
  right: 20px;
  height: 1px;
  border-radius: 1px;
  background: linear-gradient(90deg, transparent, rgba(56, 216, 255, 0.25), transparent);
  pointer-events: none;
}

.panel-card:hover {
  border-color: rgba(65, 158, 219, 0.38);
}

.panel-title {
  position: relative;
  padding-left: 16px;
  margin-bottom: 14px;
  color: #8fe5ff;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 1px;
}

.panel-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 3px;
  width: 4px;
  height: 20px;
  border-radius: 2px;
  background: linear-gradient(180deg, #28d7ff, #1776ff);
  box-shadow: 0 0 10px rgba(40, 215, 255, 0.5);
}

.base-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.base-card {
  background: linear-gradient(180deg, rgba(10, 30, 53, 0.95), rgba(9, 24, 42, 0.95));
}

.base-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.base-item {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  padding: 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(20, 57, 89, 0.45), rgba(18, 44, 72, 0.35));
  border: 1px solid rgba(97, 190, 255, 0.12);
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: default;
  position: relative;
  overflow: hidden;
}

.base-item::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.03), transparent 70%);
  pointer-events: none;
  transition: opacity 0.35s;
  opacity: 0;
}

.base-item:hover {
  transform: translateY(-2px);
  border-color: rgba(97, 190, 255, 0.35);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(97, 190, 255, 0.1) inset;
}

.base-item:hover::before {
  opacity: 1;
}

.base-icon {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 48px;
  position: relative;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.35s;
}

.base-item:hover .base-icon {
  transform: scale(1.08);
  box-shadow: 0 0 28px rgba(56, 216, 255, 0.3);
}

.base-icon-svg {
  width: 26px;
  height: 26px;
  color: #fff;
  transition: transform 0.35s;
}

.base-item:hover .base-icon-svg {
  transform: scale(1.1);
}

.base-text {
  min-width: 0;
}

.base-label {
  color: #c0dff5;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.base-value {
  margin-top: 4px;
  color: #fff;
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

.base-value span {
  margin-left: 4px;
  color: #90d9ff;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
}

.chart-box {
  width: 100%;
  height: calc(100% - 36px);
}

.table-card,
.warning-card,
.hazard-card {
  overflow: hidden;
}

.table-wrap {
  height: calc(100% - 38px);
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.data-table thead {
  background: rgba(24, 122, 198, 0.55);
}

.data-table thead th {
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #b9e4ff;
}

.data-table th,
.data-table td {
  padding: 10px 6px;
  color: #f4fbff;
  text-align: center;
  font-size: 13px;
  border-bottom: 1px solid rgba(130, 194, 231, 0.1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table tbody tr {
  transition: background 0.25s;
}

.data-table tbody tr:nth-child(odd) {
  background: rgba(133, 196, 242, 0.10);
}

.data-table tbody tr:nth-child(even) {
  background: rgba(133, 196, 242, 0.04);
}

.data-table tbody tr:hover {
  background: rgba(56, 216, 255, 0.12);
}

.compact-table th,
.compact-table td {
  padding: 9px 4px;
}

.status-cell.ok {
  color: #6effc4;
  position: relative;
}

.status-cell.warn {
  color: #ffe16a;
}

.status-cell.off {
  color: #ff8e8e;
}

.status-cell::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.status-cell.ok::before {
  background: #6effc4;
  box-shadow: 0 0 6px rgba(110, 255, 196, 0.6);
}

.status-cell.warn::before {
  background: #ffe16a;
  box-shadow: 0 0 6px rgba(255, 225, 106, 0.6);
}

.status-cell.off::before {
  background: #ff8e8e;
  box-shadow: 0 0 6px rgba(255, 142, 142, 0.6);
}

.center-panel {
  position: relative;
}

.map-stage {
  position: relative;
  height: 100%;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid rgba(56, 159, 223, 0.2);
  background: rgba(8, 20, 37, 0.64);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.3), inset 0 0 60px rgba(8, 30, 60, 0.3);
}

.map-stage-top {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.summary-strip,
.map-kpis {
  display: flex;
  gap: 10px;
}

.summary-item,
.map-kpi {
  min-width: 110px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(8, 31, 54, 0.82);
  border: 1px solid rgba(79, 177, 238, 0.18);
  backdrop-filter: blur(8px);
  transition: all 0.3s;
}

.summary-label,
.map-kpi span {
  display: block;
  color: #91d7ff;
  font-size: 12px;
  letter-spacing: 0.5px;
}

.summary-value,
.map-kpi strong {
  display: block;
  margin-top: 4px;
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1px;
}

.map-view {
  width: 100%;
  height: 100%;
}

.map-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffd3d3;
  background: rgba(5, 10, 20, 0.72);
  z-index: 4;
}

.map-panel {
  position: absolute;
  z-index: 3;
  width: 190px;
  padding: 14px;
  border-radius: 12px;
  background: rgba(8, 31, 54, 0.82);
  border: 1px solid rgba(79, 177, 238, 0.18);
  backdrop-filter: blur(10px);
}

.info-panel {
  left: 18px;
  bottom: 20px;
}

.point-panel {
  right: 18px;
  bottom: 20px;
}

.mini-title {
  margin-bottom: 10px;
  color: #8fe5ff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.mini-row {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  padding: 4px 0;
  color: #d6efff;
  font-size: 13px;
  border-bottom: 1px solid rgba(130, 194, 231, 0.06);
}

.mini-row:last-child {
  border-bottom: none;
}

.warning-scroll {
  height: calc(100% - 38px);
  overflow-y: auto;
  padding-right: 4px;
}

.warning-scroll::-webkit-scrollbar {
  width: 5px;
}

.warning-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(96, 180, 235, 0.3);
}

.warning-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.warning-list {
  display: grid;
  gap: 10px;
}

.warning-item {
  display: flex;
  gap: 12px;
  align-items: stretch;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 108, 108, 0.1);
  background: linear-gradient(180deg, rgba(72, 24, 38, 0.42), rgba(49, 19, 31, 0.30));
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.warning-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  transition: all 0.35s;
}

.warning-item.danger::before {
  background: linear-gradient(180deg, #ff5858, #ff3030);
  box-shadow: 0 0 12px rgba(255, 58, 58, 0.5);
  animation: dangerPulse 2s ease-in-out infinite;
}

.warning-item.notice::before {
  background: linear-gradient(180deg, #ffc635, #ff9f1a);
  box-shadow: 0 0 10px rgba(255, 198, 53, 0.35);
}

@keyframes dangerPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.warning-item:hover {
  transform: translateX(3px);
}

.warning-item.danger:hover {
  border-color: rgba(255, 108, 108, 0.25);
  box-shadow: 0 4px 20px rgba(255, 58, 58, 0.1);
}

.warning-item.notice:hover {
  border-color: rgba(255, 201, 92, 0.2);
  box-shadow: 0 4px 20px rgba(255, 198, 53, 0.08);
}

.warning-item.notice {
  border-color: rgba(255, 201, 92, 0.1);
  background: linear-gradient(180deg, rgba(78, 63, 23, 0.28), rgba(48, 43, 20, 0.18));
}

.warning-side {
  width: 52px;
  flex: 0 0 52px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.warning-badge {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  transition: transform 0.3s;
}

.warning-item:hover .warning-badge {
  transform: scale(1.1);
}

.warning-tag {
  width: 100%;
  padding: 3px 0;
  border-radius: 999px;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.5px;
  color: #dcefff;
  background: rgba(255, 255, 255, 0.06);
}

.warning-item.danger .warning-badge {
  background: rgba(255, 58, 58, 0.28);
  color: #ff8787;
}

.warning-item.danger .warning-title {
  color: #ffd8d8;
}

.warning-item.notice .warning-badge {
  background: rgba(255, 198, 53, 0.2);
  color: #ffd45d;
}

.warning-item.notice .warning-title {
  color: #fff2c4;
}

.warning-main {
  min-width: 0;
  flex: 1;
}

.warning-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.warning-title {
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
}

.warning-time,
.warning-code,
.warning-desc {
  color: #dcefff;
  font-size: 12px;
}

.warning-time {
  color: #b6dfff;
  white-space: nowrap;
}

.warning-code {
  margin: 6px 0 4px;
  color: #9ad8ff;
}

.warning-desc {
  line-height: 1.5;
}

.hazard-summary {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
}

.hazard-summary.three-col {
  justify-content: space-between;
}

.hazard-summary-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.04);
  transition: all 0.3s;
}

.hazard-summary-item:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.08);
}

.hazard-dot {
  width: 8px;
  height: 24px;
  display: inline-block;
  border-radius: 4px;
  box-shadow: 0 0 10px currentColor;
}

.hazard-chart {
  height: 160px;
}

.equipment-wrap {
  height: calc(100% - 38px);
}

:deep(.BMap_cpyCtrl),
:deep(.anchorBL) {
  display: none !important;
}

.deerflow-mark {
  position: fixed;
  bottom: 14px;
  right: 18px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  opacity: 0.28;
  transition: opacity 0.4s;
}

.deerflow-mark:hover {
  opacity: 0.6;
}

.deerflow-diamond {
  font-size: 10px;
  color: #8fe5ff;
}

.deerflow-text {
  font-size: 11px;
  letter-spacing: 1px;
  color: #8fe5ff;
  font-weight: 500;
}

@media (max-width: 1500px) {
  .screen-body {
    grid-template-columns: 320px 1fr 320px;
  }

  .header-title {
    font-size: 24px;
  }

  .summary-item,
  .map-kpi {
    min-width: 96px;
  }
}
</style>
