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

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

    <div class="screen-page--home-column">
      <div class="screen-page--home-column-top">
        <div class="top_title">产业总览 ལས་རྩོམ་ཐོག་མའི་དོ་དམ།</div>
        <div class="top_content">
          <div
            class="content_1 overview-metric--clickable"
            role="button"
            tabindex="0"
            @click="yakInventoryOutboundDialogVisible = true"
            @keyup.enter="yakInventoryOutboundDialogVisible = true"
          >
            <div class="content_num">
              <ScreenScrollNumber :value="overview?.inventoryTotal" /> 头
            </div>
            <div class="content_title"><div>牦牛存栏总量</div></div>
          </div>
          <div
            class="content_2 overview-metric--clickable"
            role="button"
            tabindex="0"
            @click="yakInventoryOutboundDialogVisible = true"
            @keyup.enter="yakInventoryOutboundDialogVisible = true"
          >
            <div class="content_num">
              <ScreenScrollNumber :value="overview?.annualOutbound" /> 头
            </div>
            <div class="content_title"><div>牦牛年出栏量</div></div>
          </div>
          <div
            class="content_3 overview-metric--clickable"
            role="button"
            tabindex="0"
            @click="breedingEntityDialogVisible = true"
            @keyup.enter="breedingEntityDialogVisible = true"
          >
            <div class="content_num">
              <ScreenScrollNumber :value="overview?.cooperativeCount" /> 个
            </div>
            <div class="content_title"><div>合作社</div></div>
          </div>
          <div
            class="content_4 overview-metric--clickable"
            role="button"
            tabindex="0"
            @click="breedingEntityDialogVisible = true"
            @keyup.enter="breedingEntityDialogVisible = true"
          >
            <div class="content_num">
              <ScreenScrollNumber :value="overview?.familyRanchCount" /> 个
            </div>
            <div class="content_title"><div>家庭牧场</div></div>
          </div>
        </div>
        <div class="top_content">
          <div
            class="content_1 overview-metric--clickable"
            role="button"
            tabindex="0"
            @click="breedingEntityDialogVisible = true"
            @keyup.enter="breedingEntityDialogVisible = true"
          >
            <div class="content_num">
              <ScreenScrollNumber :value="overview?.largeLivestockFarmerCount" /> 个
            </div>
            <div class="content_title"><div>养殖大户</div></div>
          </div>
          <div
            class="content_2 overview-metric--clickable"
            role="button"
            tabindex="0"
            @click="breedingEntityDialogVisible = true"
            @keyup.enter="breedingEntityDialogVisible = true"
          >
            <div class="content_num">
              <ScreenScrollNumber :value="overview?.pastureCount" /> 户
            </div>
            <div class="content_title"><div>农牧户数</div></div>
          </div>
          <div
            class="content_3 overview-metric--clickable"
            role="button"
            tabindex="0"
            @click="livestockOwnershipDialogVisible = true"
            @keyup.enter="livestockOwnershipDialogVisible = true"
          >
            <div class="content_num">
              <ScreenScrollNumber :value="overview?.withLivestockHouseholdCount" /> 户
            </div>
            <div class="content_title"><div>有畜户数</div></div>
          </div>
          <div
            class="content_4 overview-metric--clickable"
            role="button"
            tabindex="0"
            @click="grasslandAreaDialogVisible = true"
            @keyup.enter="grasslandAreaDialogVisible = true"
          >
            <div class="content_num">
              <ScreenScrollNumber :value="overview?.grasslandAreaMu" format="area" /> 亩
            </div>
            <div class="content_title"><div>草场面积</div></div>
          </div>
        </div>
      </div>

      <div class="screen-page--home-column-flex">
        <div class="screen-page--home-column-flex-item">
          <div
            class="flex_title flex_title--clickable"
            role="button"
            tabindex="0"
            @click="herdInventoryDialogVisible = true"
            @keyup.enter="herdInventoryDialogVisible = true"
          >
            畜群存栏结构 ཕྱུགས་ཁྱུ་གནས་ཚད་གྲུབ་ཆ།
          </div>
          <div
            class="flex_content flex_content--clickable"
            role="button"
            tabindex="0"
            @click="herdInventoryDialogVisible = true"
            @keyup.enter="herdInventoryDialogVisible = true"
          >
            <ScreenChart :option="herdInventoryStructureOption" />
          </div>
        </div>
        <div class="screen-page--home-column-flex-item">
          <div
            class="flex_title flex_title--clickable"
            role="button"
            tabindex="0"
            @click="yakHerdInventoryDialogVisible = true"
            @keyup.enter="yakHerdInventoryDialogVisible = true"
          >
            牦牛存栏结构 གཡག་གནས་ཚད་གྲུབ་ཆ།
          </div>
          <div
            class="flex_content flex_content--clickable"
            role="button"
            tabindex="0"
            @click="yakHerdInventoryDialogVisible = true"
            @keyup.enter="yakHerdInventoryDialogVisible = true"
          >
            <ScreenChart :option="yakInventoryStructureOption" />
          </div>
        </div>
      </div>

      <div class="screen-page--home-column-flex">
        <div class="screen-page--home-column-flex-item">
          <div
            class="flex_title flex_title--clickable"
            role="button"
            tabindex="0"
            @click="livestockOutboundDialogVisible = true"
            @keyup.enter="livestockOutboundDialogVisible = true"
          >
            牲畜出栏统计 ཕྱུགས་ཟོག་ཕྱིར་འཐེན་གྱི་གྲངས་རྩིས།
          </div>
          <div
            class="flex_content flex_content--clickable"
            role="button"
            tabindex="0"
            @click="livestockOutboundDialogVisible = true"
            @keyup.enter="livestockOutboundDialogVisible = true"
          >
            <ScreenChart :option="livestockOutboundStructureOption" />
          </div>
        </div>
        <div class="screen-page--home-column-flex-item">
          <div
            class="flex_title flex_title--clickable"
            role="button"
            tabindex="0"
            @click="selfConsumptionDialogVisible = true"
            @keyup.enter="selfConsumptionDialogVisible = true"
          >
            自食情况统计 རང་ཟས་གནས་ཚུལ་གྱི་གྲངས་རྩིས།
          </div>
          <div
            class="flex_content flex_content--clickable"
            role="button"
            tabindex="0"
            @click="selfConsumptionDialogVisible = true"
            @keyup.enter="selfConsumptionDialogVisible = true"
          >
            <ScreenChart :option="selfConsumptionOption" />
          </div>
        </div>
      </div>
    </div>

    <div class="screen-page--home-column">
      <div class="screen-page--home-column-right">
        <div class="top_title">企业年度收入与补助 ཁེ་ལས་ལོ་རེའི་ཡོང་འབབ་དང་རོགས་དངུལ།</div>
        <div class="top_flex top_flex--finance">
          <div
            class="top_flex_chart top_flex_chart--clickable"
            role="button"
            tabindex="0"
            @click="familyRanchDialogVisible = true"
            @keyup.enter="familyRanchDialogVisible = true"
          >
            <ScreenChart :option="familyRanchFinanceOption" />
          </div>
          <div
            class="top_flex_chart top_flex_chart--clickable"
            role="button"
            tabindex="0"
            @click="largeFarmerDialogVisible = true"
            @keyup.enter="largeFarmerDialogVisible = true"
          >
            <ScreenChart :option="largeLivestockFarmerFinanceOption" />
          </div>
        </div>
      </div>

      <div class="screen-page--home-column-flex">
        <div class="screen-page--home-column-flex-item">
          <div
            class="flex_title flex_title--clickable"
            role="button"
            tabindex="0"
            @click="cooperativeDialogVisible = true"
            @keyup.enter="cooperativeDialogVisible = true"
          >
            合作社经营分类 མཉམ་ལས་ཁང་གི་ཐབས་ལམ་དབྱེ་བ།
          </div>
          <div
            class="flex_content flex_content--clickable"
            role="button"
            tabindex="0"
            @click="cooperativeDialogVisible = true"
            @keyup.enter="cooperativeDialogVisible = true"
          >
            <ScreenChart :option="cooperativeBusinessModelOption" />
          </div>
        </div>
        <div class="screen-page--home-column-flex-item">
          <div
            class="flex_title flex_title--clickable"
            role="button"
            tabindex="0"
            @click="farmerHouseholdDialogVisible = true"
            @keyup.enter="farmerHouseholdDialogVisible = true"
          >
            补助奖励资金 རོགས་དངུལ་བྱ་དགའི་མ་དངུལ།
          </div>
          <div
            class="flex_content flex_content--subsidy"
            role="button"
            tabindex="0"
            @click="farmerHouseholdDialogVisible = true"
            @keyup.enter="farmerHouseholdDialogVisible = true"
          >
            <div v-if="!townSubsidyTotals.length" class="imbalance-empty">暂无补助数据</div>
            <div v-else class="subsidy-list">
              <div
                v-for="(row, idx) in townSubsidyTotals"
                :key="`${row.townName || ''}-${idx}`"
                class="subsidy-item"
              >
                <span class="subsidy-item__town" :title="row.townName">{{ row.townName || '—' }}</span>
                <span class="subsidy-item__amount">{{ formatSubsidy(row.subsidyTotal) }}元</span>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="screen-page--home-column-flex">
        <div class="screen-page--home-column-flex-item">
          <div
            class="flex_title flex_title--clickable"
            role="button"
            tabindex="0"
            @click="perCapitaDialogVisible = true"
            @keyup.enter="perCapitaDialogVisible = true"
          >
            人均收入 མི་རེའི་ཡོང་འབབ།
          </div>
          <div
            class="flex_content flex_content--clickable"
            role="button"
            tabindex="0"
            @click="perCapitaDialogVisible = true"
            @keyup.enter="perCapitaDialogVisible = true"
          >
            <ScreenChart :option="perCapitaIncomeTrendOption" />
          </div>
        </div>
        <div class="screen-page--home-column-flex-item">
          <div
            class="flex_title flex_title--clickable"
            role="button"
            tabindex="0"
            @click="imbalanceDialogVisible = true"
            @keyup.enter="imbalanceDialogVisible = true"
          >
            草畜失衡预警 རྩྭ་ཕྱུགས་མི་མཐུན་པའི་ཉེན་བརྡ།
          </div>
          <div
            class="flex_content flex_content--imbalance"
            role="button"
            tabindex="0"
            @click="imbalanceDialogVisible = true"
            @keyup.enter="imbalanceDialogVisible = true"
          >
            <div v-if="imbalanceWarningLoading && !imbalanceWarnings.length" class="imbalance-empty">
              加载中…
            </div>
            <div v-else-if="!imbalanceWarnings.length" class="imbalance-empty">暂无预警</div>
            <div v-else class="imbalance-list">
              <div
                v-for="(row, idx) in imbalanceWarnings"
                :key="`${row.statYear}-${row.statMonth}-${row.subjectName}-${idx}`"
                class="imbalance-item"
              >
                <span class="imbalance-item__icon" aria-hidden="true">
                  <svg viewBox="0 0 24 24" width="16" height="16" fill="none">
                    <path
                      d="M12 3.2L2.8 19.2h18.4L12 3.2z"
                      stroke="#e0b84a"
                      stroke-width="1.6"
                      stroke-linejoin="round"
                      fill="rgba(224,184,74,0.18)"
                    />
                    <path
                      d="M12 9.2v5.2"
                      stroke="#e0b84a"
                      stroke-width="1.8"
                      stroke-linecap="round"
                    />
                    <circle cx="12" cy="17.2" r="1.05" fill="#e0b84a" />
                  </svg>
                </span>
                <span class="imbalance-item__date">{{ formatWarningDate(row) }}</span>
                <span class="imbalance-item__content" :title="warningContent(row)">
                  {{ warningContent(row) }}
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <ImbalanceWarningDialog v-model="imbalanceDialogVisible" />
  <PerCapitaIncomeDialog v-model="perCapitaDialogVisible" />
  <FarmerHouseholdDialog v-model="farmerHouseholdDialogVisible" />
  <CooperativeDevelopmentDialog v-model="cooperativeDialogVisible" />
  <FamilyRanchDialog v-model="familyRanchDialogVisible" />
  <FamilyRanchDialog
    v-model="largeFarmerDialogVisible"
    title="养殖大户数据明细"
    :api="getLargeLivestockFarmers"
  />
  <SelfConsumptionDialog v-model="selfConsumptionDialogVisible" />
  <LivestockOutboundDialog v-model="livestockOutboundDialogVisible" />
  <YakHerdInventoryDialog v-model="yakHerdInventoryDialogVisible" />
  <HerdInventoryDialog v-model="herdInventoryDialogVisible" />
  <YakInventoryOutboundDialog v-model="yakInventoryOutboundDialogVisible" />
  <LivestockOwnershipDialog v-model="livestockOwnershipDialogVisible" />
  <GrasslandAreaDialog v-model="grasslandAreaDialogVisible" />
  <BreedingEntityQuantityDialog v-model="breedingEntityDialogVisible" />
</template>
<script setup>
import { computed, onMounted, ref, watch } from 'vue'
import ScreenChart from '@/components/ScreenChart.vue'
import ScreenScrollNumber from '@/components/ScreenScrollNumber.vue'
import BreedingEntityQuantityDialog from './BreedingEntityQuantityDialog.vue'
import CooperativeDevelopmentDialog from './CooperativeDevelopmentDialog.vue'
import FamilyRanchDialog from './FamilyRanchDialog.vue'
import FarmerHouseholdDialog from './FarmerHouseholdDialog.vue'
import GrasslandAreaDialog from './GrasslandAreaDialog.vue'
import HerdInventoryDialog from './HerdInventoryDialog.vue'
import ImbalanceWarningDialog from './ImbalanceWarningDialog.vue'
import LivestockOutboundDialog from './LivestockOutboundDialog.vue'
import LivestockOwnershipDialog from './LivestockOwnershipDialog.vue'
import PerCapitaIncomeDialog from './PerCapitaIncomeDialog.vue'
import SelfConsumptionDialog from './SelfConsumptionDialog.vue'
import YakHerdInventoryDialog from './YakHerdInventoryDialog.vue'
import YakInventoryOutboundDialog from './YakInventoryOutboundDialog.vue'
import {
  getGrassLivestockImbalanceWarnings,
  getHomeDashboard,
  getLargeLivestockFarmers
} from '@/api/home'
import { useStatYear } from '@/stores/statYear'
import {
  buildCooperativeBusinessModelOption,
  buildEnterpriseFinanceOption,
  buildHerdInventoryStructureOption,
  buildLivestockOutboundStructureOption,
  buildPerCapitaIncomeTrendOption,
  buildSelfConsumptionOption,
  buildYakInventoryStructureOption
} from './chartOptions'

const IMBALANCE_PAGE_SIZE = 50

const { statYear, availableYears, mergeAvailableYears } = useStatYear()
const loading = ref(false)
const loadError = ref('')
const statDate = ref('')
const overview = ref(null)
const herdInventoryStructure = ref([])
const familyRanchFinance = ref(null)
const largeLivestockFarmerFinance = ref(null)
const cooperativeBusinessModel = ref([])
const townSubsidyTotals = ref([])
const perCapitaIncomeTrend = ref([])
const imbalanceWarnings = ref([])
const imbalanceWarningLoading = ref(false)
const imbalanceDialogVisible = ref(false)
const perCapitaDialogVisible = ref(false)
const farmerHouseholdDialogVisible = ref(false)
const cooperativeDialogVisible = ref(false)
const familyRanchDialogVisible = ref(false)
const largeFarmerDialogVisible = ref(false)
const selfConsumptionDialogVisible = ref(false)
const livestockOutboundDialogVisible = ref(false)
const yakHerdInventoryDialogVisible = ref(false)
const herdInventoryDialogVisible = ref(false)
const yakInventoryOutboundDialogVisible = ref(false)
const livestockOwnershipDialogVisible = ref(false)
const grasslandAreaDialogVisible = ref(false)
const breedingEntityDialogVisible = ref(false)

const herdInventoryStructureOption = computed(() =>
  buildHerdInventoryStructureOption(herdInventoryStructure.value)
)
const yakInventoryStructureOption = computed(() =>
  buildYakInventoryStructureOption(yakInventoryStructure.value)
)
const livestockOutboundStructureOption = computed(() =>
  buildLivestockOutboundStructureOption(livestockOutboundStructure.value)
)
const selfConsumptionOption = computed(() =>
  buildSelfConsumptionOption(selfConsumption.value)
)
const familyRanchFinanceOption = computed(() =>
  buildEnterpriseFinanceOption(familyRanchFinance.value, '家庭牧场')
)
const largeLivestockFarmerFinanceOption = computed(() =>
  buildEnterpriseFinanceOption(largeLivestockFarmerFinance.value, '养殖大户')
)
const cooperativeBusinessModelOption = computed(() =>
  buildCooperativeBusinessModelOption(cooperativeBusinessModel.value)
)
const perCapitaIncomeTrendOption = computed(() =>
  buildPerCapitaIncomeTrendOption(perCapitaIncomeTrend.value)
)

const yakInventoryStructure = ref([])
const livestockOutboundStructure = ref([])
const selfConsumption = ref(null)

function formatNum(val, fractionDigits) {
  if (val === null || val === undefined || val === '') {
    return '0'
  }
  const n = Number(val)
  if (Number.isNaN(n)) {
    return '0'
  }
  if (typeof fractionDigits === 'number') {
    return n.toLocaleString('zh-CN', {
      minimumFractionDigits: fractionDigits,
      maximumFractionDigits: fractionDigits
    })
  }
  return n.toLocaleString('zh-CN')
}

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

/** 补助金额：空为 —，数字带千分位 */
function formatSubsidy(val) {
  if (val === null || val === undefined || val === '') {
    return '—'
  }
  const n = Number(val)
  if (Number.isNaN(n)) {
    return '—'
  }
  return n.toLocaleString('zh-CN', { maximumFractionDigits: 2 })
}

/** 预警日期：所属年-月 */
function formatWarningDate(row) {
  if (!row) {
    return '—'
  }
  if (row.statYear != null && row.statMonth != null) {
    return `${row.statYear}-${String(row.statMonth).padStart(2, '0')}`
  }
  if (row.statYear != null) {
    return String(row.statYear)
  }
  return '—'
}

/** 预警内容：乡镇/村 + 主体 + 载畜量对比 */
function warningContent(row) {
  if (!row) {
    return '—'
  }
  const place = [row.townName, row.villageName].filter(Boolean).join('')
  const subject = [row.subjectName, row.subjectType ? `（${row.subjectType}）` : '']
    .filter(Boolean)
    .join('')
  const approved = row.approvedCarryingCapacity != null ? row.approvedCarryingCapacity : '—'
  const stock = row.yearEndStockSheepUnit != null ? row.yearEndStockSheepUnit : '—'
  const balanced = row.isGrassBalanced || '—'
  return `${place} ${subject}：核定载畜量${approved}，年底存栏${stock}，草畜平衡：${balanced}`.trim()
}

/** 应用看板主数据 */
function applyDashboard(data) {
  if (!data) {
    return
  }
  mergeAvailableYears(data.availableYears)
  statDate.value = data.statDate || ''
  overview.value = data.industryOverview || null
  herdInventoryStructure.value = data.herdInventoryStructure || []
  yakInventoryStructure.value = data.yakInventoryStructure || []
  livestockOutboundStructure.value = data.livestockOutboundStructure || []
  selfConsumption.value = data.selfConsumption || null
  familyRanchFinance.value = data.familyRanchFinance || null
  largeLivestockFarmerFinance.value = data.largeLivestockFarmerFinance || null
  cooperativeBusinessModel.value = data.cooperativeBusinessModel || []
  townSubsidyTotals.value = data.townSubsidyTotals || []
  perCapitaIncomeTrend.value = data.perCapitaIncomeTrend || []
}

/** 拉取草畜失衡预警列表 */
async function fetchImbalanceWarnings() {
  imbalanceWarningLoading.value = true
  try {
    const res = await getGrassLivestockImbalanceWarnings({
      statYear: statYear.value,
      pageNum: 1,
      pageSize: IMBALANCE_PAGE_SIZE
    })
    imbalanceWarnings.value = res.rows || []
  } catch (e) {
    imbalanceWarnings.value = []
    if (!loadError.value) {
      loadError.value = e?.message || '预警列表加载失败'
    }
  } finally {
    imbalanceWarningLoading.value = false
  }
}

/** 拉取看板 + 预警列表（切换年份时） */
async function fetchDashboard() {
  loading.value = true
  loadError.value = ''
  try {
    const res = await getHomeDashboard(statYear.value)
    applyDashboard(res.data)
    await fetchImbalanceWarnings()
  } catch (e) {
    loadError.value = e?.message || '看板数据加载失败'
  } finally {
    loading.value = false
  }
}

function onYearChange() {
  fetchDashboard()
}

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

onMounted(() => {
  fetchDashboard()
})
</script>

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

.screen-page--home.is-loading {
  opacity: 0.92;
}

.home-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;
}

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

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

.home-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;
}

.home-year-bar__date {
  font-size: 11px;
  color: var(--screen-text-secondary, #a8d4c8);
}

.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/home/big_box.png') no-repeat center center;
  background-size: 100% 100%;
}

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

.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;
}

.top_content {
  width: 100%;
  height: 75px;
  display: flex;
  flex-direction: row;
}

.content_1 {
  width: 180px;
  height: 100%;
}

.content_2 {
  width: 116px;
  height: 100%;
}

.content_3 {
  width: 190px;
  height: 100%;
}

.content_4 {
  width: 116px;
  height: 100%;
}

.content_num {
  text-align: center;
  font-size: 16px;
  color: #fff;
  line-height: 30px;
  margin: 10px 0;
}

.content_num :deep(.screen-scroll-number) {
  font-size: 20px;
}

.content_num :deep(.screen-scroll-number__strip),
.content_num :deep(.screen-scroll-number__sep) {
  background: linear-gradient(to bottom, #98e9aa, #ecd27b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

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

.content_title {
  text-align: center;
  font-size: 12px;
  color: #fff;
}

.overview-metric--clickable {
  cursor: pointer;
}

.overview-metric--clickable:hover .content_title {
  color: #ecd27b;
}

.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_title--clickable {
  cursor: pointer;
}

.flex_title--clickable:hover {
  color: #ecd27b;
}

.flex_title--with-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 8px;
}

.flex_title__meta {
  flex-shrink: 0;
  font-size: 10px;
  color: #a8d4c8;
  line-height: 1.2;
  text-align: right;
  max-width: 48%;
}

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

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

.top_flex {
  width: 100%;
  height: 155px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  gap: 8px;
}

.top_flex--finance .top_flex_chart {
  flex: 1;
  min-width: 0;
  height: 100%;
  box-sizing: border-box;
}

.top_flex_chart--clickable {
  cursor: pointer;
}

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

.flex_content--imbalance,
.flex_content--subsidy {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 4px 6px;
  cursor: pointer;
}

.flex_content--clickable {
  cursor: pointer;
}

.imbalance-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6a9f90;
  font-size: 13px;
}

.imbalance-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}

.imbalance-list::-webkit-scrollbar {
  width: 4px;
}

.imbalance-list::-webkit-scrollbar-thumb {
  background: rgba(61, 217, 176, 0.35);
  border-radius: 2px;
}

.imbalance-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: linear-gradient(
    90deg,
    rgba(12, 48, 40, 0.75) 0%,
    rgba(6, 28, 24, 0.4) 100%
  );
  border: 1px solid rgba(232, 176, 74, 0.22);
  border-radius: 2px;
}

.imbalance-item__icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 0 4px rgba(224, 184, 74, 0.55));
}

.imbalance-item__icon svg {
  display: block;
}

.imbalance-item__date {
  flex-shrink: 0;
  width: 58px;
  font-size: 12px;
  color: #e0b84a;
  line-height: 18px;
  font-variant-numeric: tabular-nums;
}

.imbalance-item__content {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: #e8eef5;
  line-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subsidy-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}

.subsidy-list::-webkit-scrollbar {
  width: 4px;
}

.subsidy-list::-webkit-scrollbar-thumb {
  background: rgba(61, 217, 176, 0.35);
  border-radius: 2px;
}

.subsidy-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 8px;
  background: linear-gradient(
    90deg,
    rgba(12, 48, 40, 0.75) 0%,
    rgba(6, 28, 24, 0.4) 100%
  );
  border: 1px solid rgba(61, 217, 176, 0.22);
  border-radius: 2px;
}

.subsidy-item__town {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: #e8eef5;
  line-height: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subsidy-item__amount {
  flex-shrink: 0;
  font-size: 12px;
  color: #5ef0c8;
  line-height: 18px;
  font-variant-numeric: tabular-nums;
}
</style>
