<template>
  <div class="screen-page er-page" :class="{ 'is-loading': loading }">
    <div v-if="loadError" class="er-error" @click="fetchDashboard">{{ loadError }}（点击重试）</div>

    <!-- <div class="er-year-bar">
      <label class="er-year-bar__label">统计年份</label>
      <select
        v-model="statYear"
        class="er-year-bar__select"
        :disabled="loading"
        @change="onYearChange"
      >
        <option v-for="y in availableYears" :key="y" :value="String(y)">{{ y }}年</option>
      </select>
    </div> -->

    <div class="screen-page--home-column">
      <div class="screen-page--home-column-top er-weather">
        <div class="er-weather__head">
          <div class="top_title">气象数据 གནམ་གསལ་གྱི་གྲངས་གཞི།</div>
          <div
            v-if="weather && !weatherLoading && !weatherError"
            class="er-weather__summary"
          >
            <span class="er-weather__city">{{ weather.city || '巴青' }}</span>
            <span class="er-weather__wea">{{ weather.wea || '—' }}</span>
            <span class="er-weather__tem">{{ weatherDisplay.tem }}</span>
            <span v-if="weatherDisplay.range" class="er-weather__range">{{
              weatherDisplay.range
            }}</span>
            <span class="er-weather__update">更新 {{ weather.update_time || '—' }}</span>
          </div>
        </div>
        <div v-if="weatherLoading" class="er-weather__hint">气象数据加载中…</div>
        <div v-else-if="weatherError" class="er-weather__hint er-weather__hint--error">
          {{ weatherError }}
        </div>
        <div v-else-if="weather" class="er-weather__body">
          <div class="er-weather__grid">
            <div
              v-for="item in weatherMetrics"
              :key="item.key"
              class="er-weather__cell"
              :class="'er-weather__cell--' + item.key"
            >
              <ScreenScrollNumber
                v-if="item.numeric"
                class="er-weather__val"
                :value="item.rawValue"
                :format="item.format"
              />
              <span v-else class="er-weather__val">{{ item.value }}</span>
            </div>
          </div>
        </div>
      </div>

      <div class="screen-page--home-column-flex">
        <div class="screen-page--home-column-flex-item">
          <div class="flex_title">样本来源检测 དཔྱད་གཞིའི་འབྱུང་གནས་བར་རྟག་བྱ་སྤྱོད།</div>
          <div class="flex_content">
            <ScreenChart :option="sampleSourceChartOption" />
          </div>
        </div>
        <div class="screen-page--home-column-flex-item">
          <div class="flex_title">实验室检测 ཚོགས་སྒྲིག་ཁང་གི་བར་རྟག</div>
          <div class="flex_content flex_content--lab">
            <div class="lab-summary">
              <div class="lab-summary__item">
                <div class="lab-summary__label">检测量</div>
                <div class="lab-summary__val">
                  <strong>{{ display(labDetection?.testQuantityTotal) }}</strong> 份
                </div>
              </div>
              <div class="lab-summary__item">
                <div class="lab-summary__label">阳性检出数</div>
                <div class="lab-summary__val">
                  <strong>{{ display(labDetection?.positiveCountTotal) }}</strong> 份
                </div>
              </div>
              <div class="lab-summary__item lab-summary__item--rate">
                <div class="lab-summary__label">阳性检出率</div>
                <div class="lab-summary__val">
                  <strong>{{ formatRate(labDetection?.positiveRate) }}</strong>
                </div>
              </div>
            </div>
            <div class="lab-chart">
              <ScreenChart :option="labChartOption" />
            </div>
          </div>
        </div>
      </div>

      <div class="screen-page--home-column-flex">
        <div class="screen-page--home-column-flex-item screen-jibing-risk">
          <div class="flex_title">疫病风险 ན་རྟག་གི་ཉེན་ཁ།</div>
          <div class="flex_content">
            <ScreenChart :option="riskLevelChartOption" />
          </div>
        </div>
        <div class="screen-page--home-column-flex-item">
          <div class="flex_title">疫病态势 ན་རྟག་གི་གནས་ཚད།</div>
          <div class="flex_content flex_content--situation">
            <div class="situation-grid">
              <div class="situation-cell">
                <div class="situation-cell__num">
                  <strong>{{ display(epidemicSituation?.availableQuarantinePointCount) }}</strong> 个
                </div>
                <div class="situation-cell__label">可用检疫点</div>
              </div>
              <div class="situation-cell">
                <div class="situation-cell__num">
                  <strong>{{ display(epidemicSituation?.disabledQuarantinePointCount) }}</strong> 个
                </div>
                <div class="situation-cell__label">停用检疫点</div>
              </div>
              <div class="situation-cell">
                <div class="situation-cell__num">
                  <strong>{{ display(epidemicSituation?.activeControlAreaCount) }}</strong> 处
                </div>
                <div class="situation-cell__label">防控中地区</div>
              </div>
              <div class="situation-cell">
                <div class="situation-cell__num">
                  <strong>{{ display(epidemicSituation?.releasedAreaCount) }}</strong> 处
                </div>
                <div class="situation-cell__label">已解除地区</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="screen-page--home-column">
      <div class="screen-page--home-column-right er-reports-panel">
        <div class="top_title">疫情上报情况 ན་རྟག་གི་གསན་བསྐུལ་གནས་ཚད།</div>
        <div class="er-table-wrap">
          <div ref="reportScrollRef" class="er-table-scroll" @scroll="onReportScroll">
            <table class="er-table">
              <thead>
                <tr>
                  <th>上报日期</th>
                  <th>传播途径</th>
                  <th>涉疫点位及轨迹</th>
                  <th>疾病类型</th>
                  <th>风险等级</th>
                  <th>疫情状态</th>
                </tr>
              </thead>
              <tbody>
                <tr v-if="reportLoading && !reportRows.length">
                  <td colspan="6" class="er-table__empty">加载中…</td>
                </tr>
                <tr v-else-if="!reportRows.length">
                  <td colspan="6" class="er-table__empty">暂无上报数据</td>
                </tr>
                <tr v-for="row in reportRows" :key="row.id">
                  <td>{{ row.reportDate || '—' }}</td>
                  <td>{{ row.transmissionRouteName || '—' }}</td>
                  <td class="er-table__track" :title="row.affectedLocationTrack">
                    {{ row.affectedLocationTrack || '—' }}
                  </td>
                  <td>{{ row.epidemicTypeName || row.epidemicName || '—' }}</td>
                  <td>
                    <span class="er-risk" :class="'er-risk--' + row.riskLevel">
                      {{ row.riskLevelName || '—' }}
                    </span>
                  </td>
                  <td>{{ relieveStatusText(row) }}</td>
                </tr>
                <tr v-if="reportLoadingMore">
                  <td colspan="6" class="er-table__more">加载下一页…</td>
                </tr>
              </tbody>
            </table>
          </div>
          <div class="er-table-footer">
            <span v-if="reportLoadingMore">加载中…</span>
            <span v-else-if="reportHasMore">上滑加载更多（{{ reportPageNum }}/{{ reportMaxPage }}）</span>
            <span v-else-if="reportRows.length">已加载全部 {{ reportRows.length }} 条</span>
          </div>
        </div>
      </div>

      <div class="screen-page--home-column-flex">
        <div class="screen-page--home-column-flex-item">
          <div class="flex_title">疫病类型分布 ན་རྟག་རིགས་ཀྱི་ཁྱབ་སྤེལ།</div>
          <div class="flex_content">
            <ScreenChart :option="epidemicTypeChartOption" />
          </div>
        </div>
        <div class="screen-page--home-column-flex-item">
          <div class="flex_title">疫病解除时效 ན་རྟག་འགྲོ་བའི་དུས་ཚད།</div>
          <div class="flex_content">
            <ScreenChart :option="relieveChartOption" />
          </div>
        </div>
      </div>

      <div class="screen-page--home-column-flex">
        <div class="screen-page--home-column-flex-item">
          <div class="flex_title">传播途径 ཁྱབ་སྤེལ་གྱི་ལམ་ཐག</div>
          <div class="flex_content">
            <ScreenChart :option="routeChartOption" />
          </div>
        </div>
        <div class="screen-page--home-column-flex-item">
          <div class="flex_title">风险因子指数 ཉེན་ཁའི་རྒྱ་གཞི་གྲངས་ཚད།</div>
          <div class="flex_content">
            <ScreenChart :option="riskFactorChartOption" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
import ScreenChart from '@/components/ScreenChart.vue'
import ScreenScrollNumber from '@/components/ScreenScrollNumber.vue'
import { getEpidemicRiskDashboard, getEpidemicRiskReports } from '@/api/epidemicRisk'
import { getBaqingWeather, parseWinMeterToMs } from '@/api/weather'
import { useStatYear } from '@/stores/statYear'
import {
  buildEpidemicTypePieOption,
  buildLabDetectionOption,
  buildRelieveDurationBarOption,
  buildRiskFactorRadarOption,
  buildRiskLevelPieOption,
  buildSampleSourceBarOption,
  buildTransmissionRoutePieOption
} from './chartOptions'

const REPORT_PAGE_SIZE = 8
const WEATHER_REFRESH_MS = 5 * 60 * 1000

const loading = ref(false)
const weatherLoading = ref(false)
const weatherError = ref('')
const weather = ref(null)
let weatherTimer = null
const reportLoading = ref(false)
const loadError = ref('')
const { statYear, mergeAvailableYears } = useStatYear()

const hasLabData = ref(false)
const hasEpidemicData = ref(false)
const hasRelievedData = ref(false)
const labDetection = ref(null)
const sampleSourceStats = ref(null)
const riskLevelStats = ref([])
const epidemicSituation = ref(null)
const epidemicTypeStats = ref([])
const transmissionRouteStats = ref([])
const relieveDurationByType = ref([])
const riskFactorWeights = ref(null)

const reportScrollRef = ref(null)
const reportPageNum = ref(1)
const reportPageSize = REPORT_PAGE_SIZE
const reportRows = ref([])
const reportTotal = ref(0)
const reportLoadingMore = ref(false)
const reportScrollLoading = ref(false)

const sampleSourceChartOption = computed(() => buildSampleSourceBarOption(sampleSourceStats.value))
const labChartOption = computed(() => buildLabDetectionOption(labDetection.value))
const riskLevelChartOption = computed(() =>
  buildRiskLevelPieOption(riskLevelStats.value, hasEpidemicData.value)
)
const epidemicTypeChartOption = computed(() =>
  buildEpidemicTypePieOption(epidemicTypeStats.value, hasEpidemicData.value)
)
const relieveChartOption = computed(() =>
  buildRelieveDurationBarOption(relieveDurationByType.value, hasRelievedData.value)
)
const routeChartOption = computed(() =>
  buildTransmissionRoutePieOption(transmissionRouteStats.value, hasEpidemicData.value)
)
const riskFactorChartOption = computed(() => buildRiskFactorRadarOption(riskFactorWeights.value))

const reportMaxPage = computed(() =>
  Math.max(1, Math.ceil(reportTotal.value / reportPageSize))
)

const reportHasMore = computed(() => reportRows.value.length < reportTotal.value)

const weatherDisplay = computed(() => {
  const w = weather.value
  if (!w) {
    return { tem: '—', range: '' }
  }
  const tem = w.tem != null && w.tem !== '' ? `${w.tem}` : '—'
  const low = w.tem2 != null && w.tem2 !== '' ? w.tem2 : null
  const high = w.tem1 != null && w.tem1 !== '' ? w.tem1 : null
  const range = low != null && high != null ? `${low}~${high}°C` : ''
  return { tem: tem === '—' ? tem : `${tem}°C`, range }
})

function isNumericWeatherValue(val) {
  if (val === null || val === undefined || val === '') {
    return false
  }
  const text = String(val).trim()
  if (text === '—' || text === '--' || text === '-') {
    return false
  }
  return !Number.isNaN(Number(text))
}

function weatherNumberFormat(val) {
  const n = Number(val)
  if (Number.isNaN(n)) {
    return 'int'
  }
  return Number.isInteger(n) ? 'int' : 'area'
}

const weatherMetrics = computed(() => {
  const w = weather.value
  if (!w) {
    return []
  }
  const humidity =
    w.humidity != null && w.humidity !== '' ? String(w.humidity).replace(/%$/, '') : '—'
  const rain = w.rain_pcpn != null && w.rain_pcpn !== '' ? String(w.rain_pcpn) : '0'
  const uv = w.uvIndex != null && w.uvIndex !== '' ? String(w.uvIndex) : '—'
  const speed = parseWinMeterToMs(w.win_meter)
  const tem = w.tem != null && w.tem !== '' ? String(w.tem) : '—'
  const win = w.win || '—'

  return [
    { key: 'win', value: win },
    { key: 'speed', value: speed },
    { key: 'uv', value: uv },
    { key: 'humidity', value: humidity || '—' },
    { key: 'rain', value: rain },
    { key: 'tem', value: tem }
  ].map((item) => {
    const numeric = item.key !== 'win' && isNumericWeatherValue(item.value)
    return {
      ...item,
      numeric,
      rawValue: numeric ? Number(item.value) : null,
      format: numeric ? weatherNumberFormat(item.value) : 'int'
    }
  })
})

function formatNum(val) {
  if (val === null || val === undefined || val === '') {
    return '0'
  }
  const n = Number(val)
  if (Number.isNaN(n)) {
    return '0'
  }
  return n.toLocaleString('zh-CN')
}

function display(val) {
  return formatNum(val)
}

function formatRate(rate) {
  if (rate === null || rate === undefined || rate === '') {
    return '0%'
  }
  const n = Number(rate)
  if (Number.isNaN(n)) {
    return '0%'
  }
  const pct = n <= 1 ? n * 100 : n
  return `${pct.toFixed(1)}%`
}

function relieveStatusText(row) {
  if (row.relieveStatus === 1) {
    return row.releaseDate ? `已解除(${row.releaseDate})` : '已解除'
  }
  return '未解除'
}

function applyDashboard(data) {
  if (!data) {
    return
  }
  mergeAvailableYears(data.availableYears)
  hasLabData.value = !!data.hasLabData
  hasEpidemicData.value = !!data.hasEpidemicData
  hasRelievedData.value =
    !!data.hasRelievedData ||
    (data.relieveDurationByType || []).some(
      (item) =>
        item?.avgRelieveDays != null ||
        item?.avg_relieve_days != null ||
        (item?.recordCount ?? item?.record_count ?? 0) > 0
    )
  labDetection.value = data.labDetection || null
  sampleSourceStats.value = data.sampleSourceStats || null
  riskLevelStats.value = data.riskLevelStats || []
  epidemicSituation.value = data.epidemicSituation || null
  epidemicTypeStats.value = data.epidemicTypeStats || []
  transmissionRouteStats.value = data.transmissionRouteStats || []
  relieveDurationByType.value = data.relieveDurationByType || []
  riskFactorWeights.value = data.riskFactorWeights || null
}

async function fetchDashboard() {
  loading.value = true
  loadError.value = ''
  try {
    const res = await getEpidemicRiskDashboard(statYear.value)
    applyDashboard(res.data)
    reportPageNum.value = 1
    await fetchReports()
  } catch (e) {
    loadError.value = e?.message || '看板数据加载失败'
  } finally {
    loading.value = false
  }
}

async function fetchReports(reset = true) {
  if (reset) {
    reportPageNum.value = 1
    reportRows.value = []
    reportLoading.value = true
  } else {
    if (!reportHasMore.value || reportLoadingMore.value || reportScrollLoading.value) {
      return
    }
    reportLoadingMore.value = true
  }

  try {
    const res = await getEpidemicRiskReports({
      statYear: statYear.value,
      pageNum: reportPageNum.value,
      pageSize: reportPageSize
    })
    const rows = res.rows || []
    reportTotal.value = res.total ?? 0
    if (reset) {
      reportRows.value = rows
    } else {
      reportRows.value = [...reportRows.value, ...rows]
    }
  } catch (e) {
    if (reset) {
      reportRows.value = []
      reportTotal.value = 0
    }
    if (!loadError.value) {
      loadError.value = e?.message || '疫情列表加载失败'
    }
  } finally {
    reportLoading.value = false
    reportLoadingMore.value = false
  }
}

async function loadMoreReports() {
  if (!reportHasMore.value || reportLoading.value || reportLoadingMore.value || reportScrollLoading.value) {
    return
  }
  reportScrollLoading.value = true
  reportPageNum.value += 1
  try {
    await fetchReports(false)
  } finally {
    reportScrollLoading.value = false
  }
}

function onReportScroll(event) {
  const el = event.target
  if (!el || el.scrollHeight <= el.clientHeight) {
    return
  }
  const distance = el.scrollHeight - el.scrollTop - el.clientHeight
  if (distance > 28) {
    return
  }
  loadMoreReports()
}

function onYearChange() {
  fetchDashboard()
}

async function fetchWeather() {
  weatherLoading.value = true
  weatherError.value = ''
  try {
    weather.value = await getBaqingWeather()
  } catch (e) {
    weather.value = null
    weatherError.value = e?.message || '气象数据加载失败'
  } finally {
    weatherLoading.value = false
  }
}

onMounted(() => {
  fetchDashboard()
  fetchWeather()
  weatherTimer = setInterval(fetchWeather, WEATHER_REFRESH_MS)
})

watch(statYear, () => {
  fetchDashboard()
})

onUnmounted(() => {
  if (weatherTimer) {
    clearInterval(weatherTimer)
    weatherTimer = null
  }
})
</script>

<style scoped>
.er-page {
  position: relative;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 20px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.er-page.is-loading {
  opacity: 0.92;
}

.er-error {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  padding: 4px 12px;
  font-size: 12px;
  color: #ffb4b4;
  background: rgba(80, 20, 20, 0.75);
  border-radius: 4px;
  cursor: pointer;
}

.er-year-bar {
  position: absolute;
  top: 8px;
  right: 24px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
}

.er-year-bar__label {
  font-size: 12px;
  color: var(--screen-text-secondary, #a8d4c8);
}

.er-year-bar__select {
  min-width: 88px;
  height: 28px;
  padding: 0 8px;
  font-size: 13px;
  color: #e8eef5;
  background: rgba(4, 48, 40, 0.85);
  border: 1px solid var(--screen-line-dim, rgba(61, 217, 176, 0.42));
  border-radius: 4px;
  outline: none;
}

.screen-page--home-column {
  width: 617px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.screen-page--home-column-top {
  width: 617px;
  height: 201px;
  background: url('../../assets/risk/qx.png') no-repeat center center;
  background-size: 100% 100%;
}

.er-weather__head {
  display: flex;
  align-items: center;
  height: 35px;
  flex-shrink: 0;
}

.er-weather__head .top_title {
  width: auto;
  min-width: 240px;
  margin-bottom: 0;
  flex-shrink: 0;
}

.er-weather__hint {
  padding: 48px 24px 0;
  text-align: center;
  font-size: 14px;
  color: rgba(168, 212, 200, 0.75);
}

.er-weather__hint--error {
  color: rgba(255, 180, 180, 0.9);
}

.er-weather__body {
  height: calc(100% - 35px);
  box-sizing: border-box;
  min-height: 0;
}

.er-weather__summary {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 0 14px 0 8px;
  font-size: 11px;
  color: #a8d4c8;
}

.er-weather__city {
  color: #e8eef5;
  font-weight: 600;
}

.er-weather__wea {
  color: #45f0b8;
}

.er-weather__tem {
  font-size: 18px;
  font-weight: 600;
  color: #ecd27b;
}

.er-weather__range {
  color: #ffffff;
  font-weight: 500;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.75);
}

.er-weather__update {
  font-size: 10px;
  color: #d4f5e8;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.75);
}

/* 背景 qx.png 已含图标、名称、单位，数值叠在图标与右侧文案之间 */
.er-weather__grid {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  box-sizing: border-box;
  padding: 16px 20px 16px 32px;
  grid-gap: 16px 32px;
}

.er-weather__cell {
  position: relative;
  box-sizing: border-box;
}

.er-weather__val {
  position: absolute;
  top: 45%;
  right: 20%;
  transform: translateY(-50%);
  max-width: 46%;
  font-size: 17px;
  font-weight: 600;
  color: #e8eef5;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 0 10px rgba(69, 240, 184, 0.35);
}

.er-weather__val :deep(.screen-scroll-number) {
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  text-shadow: inherit;
}

.er-weather__val :deep(.screen-scroll-number__strip),
.er-weather__val :deep(.screen-scroll-number__sep) {
  color: inherit;
  text-shadow: inherit;
}
.er-weather__cell--speed .er-weather__val {
  right: 25%;
}
.er-weather__cell--humidity .er-weather__val {
  top: 40%;
}
.er-weather__cell--rain .er-weather__val {
  right: 30%;
}

.er-weather__cell--win .er-weather__val {
  right: 20%;
  font-size: 14px;
}


.screen-page--home-column-right {
  width: 617px;
  background: url('../../assets/pro/pro.png') no-repeat center center;
  background-size: 100% 100%;
}

/* 右侧栏略宽，疫情上报表格空间更大 */
.er-page > .screen-page--home-column:last-child {
  width: 660px;
  flex-shrink: 0;
}

.er-page > .screen-page--home-column:last-child .screen-page--home-column-right,
.er-page > .screen-page--home-column:last-child .screen-page--home-column-flex {
  width: 660px;
}

.er-page > .screen-page--home-column:last-child .screen-page--home-column-flex-item {
  width: 325px;
}

.er-reports-panel {
  height: 201px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.er-table-wrap {
  flex: 1;
  min-height: 0;
  padding: 0 12px 6px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.er-table-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(69, 240, 184, 0.45) rgba(4, 30, 26, 0.35);
}

.er-table-scroll::-webkit-scrollbar {
  width: 4px;
}

.er-table-scroll::-webkit-scrollbar-track {
  background: rgba(4, 30, 26, 0.35);
  border-radius: 2px;
}

.er-table-scroll::-webkit-scrollbar-thumb {
  background: rgba(69, 240, 184, 0.42);
  border-radius: 2px;
}

.er-table-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(69, 240, 184, 0.65);
}

.er-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  color: #e8eef5;
  table-layout: fixed;
}

.er-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 6px 4px;
  font-weight: 500;
  color: #a8d4c8;
  text-align: left;
  background: rgba(5, 36, 30, 0.98);
  border-bottom: 1px solid rgba(61, 217, 176, 0.35);
  box-shadow: 0 1px 0 rgba(61, 217, 176, 0.2);
}

.er-table td {
  padding: 5px 4px;
  border-bottom: 1px solid rgba(61, 217, 176, 0.12);
  vertical-align: middle;
}

.er-table th:nth-child(1),
.er-table td:nth-child(1) {
  width: 72px;
}

.er-table th:nth-child(3),
.er-table td:nth-child(3) {
  width: 24%;
}

.er-table th:nth-child(6),
.er-table td:nth-child(6) {
  width: 102px;
  min-width: 102px;
  white-space: nowrap;
}

.er-table__track {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.er-table__empty {
  text-align: center;
  color: #6a9f90;
  padding: 24px 0;
}

.er-table__more {
  text-align: center;
  color: #6a9f90;
  padding: 8px 0;
  font-size: 10px;
}

.er-table-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding-top: 4px;
  font-size: 10px;
  color: #6a9f90;
}

.er-risk--1 {
  color: #ecd27b;
}

.er-risk--2 {
  color: #6eb5ff;
}

.er-risk--3 {
  color: #45f0b8;
}

.er-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding-top: 4px;
  font-size: 11px;
  color: #a8d4c8;
}

.er-pager button {
  padding: 2px 10px;
  font-size: 11px;
  color: #e8eef5;
  background: rgba(4, 48, 40, 0.85);
  border: 1px solid rgba(61, 217, 176, 0.42);
  border-radius: 3px;
  cursor: pointer;
}

.er-pager button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.screen-page--home-column-flex {
  width: 617px;
  height: 223px;
  display: flex;
  justify-content: space-between;
}

.screen-page--home-column-flex-item {
  width: 304px;
  height: 223px;
  background: url('../../assets/home/mini_box.png') no-repeat center center;
  background-size: 100% 100%;
}
.top_title {
  width: 100%;
  height: 35px;
  box-sizing: border-box;
  font-size: 18px;
  color: #fff;
  line-height: 35px;
  padding-left: 100px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.flex_title {
  width: 100%;
  box-sizing: border-box;
  height: 35px;
  font-size: 16px;
  color: #fff;
  line-height: 35px;
  padding-left: 45px;
  margin-bottom: 5px;
}

.flex_content {
  width: 100%;
  height: 180px;
  box-sizing: border-box;
  padding: 5px;
}

.flex_content--lab {
  display: flex;
  flex-direction: column;
  padding: 4px 6px;
}

.lab-summary {
  display: flex;
  flex-direction: row;
  gap: 4px;
  height: 32px;
  flex-shrink: 0;
}

.lab-summary__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(4, 48, 40, 0.45);
  border-radius: 4px;
  border: 1px solid rgba(61, 217, 176, 0.2);
}

.lab-summary__label {
  font-size: 9px;
  color: #a8d4c8;
  line-height: 13px;
}

.lab-summary__val {
  font-size: 10px;
  color: #fff;
  line-height: 14px;
}

.lab-summary__val strong {
  font-size: 13px;
  background: linear-gradient(to bottom, #98e9aa, #ecd27b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lab-summary__item--rate .lab-summary__label {
  color: #ecd27b;
}

.lab-chart {
  flex: 1;
  min-height: 0;
}

.lab-chart :deep(.screen-chart) {
  min-height: 0;
  height: 100%;
}

.flex_content--situation {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
}

.situation-grid {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

.situation-cell {
  text-align: center;
  box-sizing: border-box;
  min-height: 56px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: url('../../assets/risk/box_1.png') no-repeat center center;
  background-size: 100% 100%;
}

.situation-cell__num {
  font-size: 12px;
  color: #fff;
  line-height: 1.4;
}

.situation-cell__num strong {
  font-size: 20px;
  background: linear-gradient(to bottom, #98e9aa, #ecd27b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.situation-cell__label {
  margin-top: 4px;
  font-size: 12px;
  color: #a8d4c8;
}
</style>
