<template>
  <div class="p-2 page-shell">
    <section class="page-hero">
      <div class="hero-copy">
        <span class="hero-eyebrow">THRESHOLD CONTROL</span>
        <h2 class="hero-title">统一点位阈值配置中心</h2>
        <p class="hero-desc">将点位阈值、回差、持续触发与启停状态集中管理，帮助现场运维更直观地完成阈值巡检和统一调整。</p>
      </div>
      <div class="hero-stats">
        <article v-for="item in overviewStats" :key="item.label" class="stat-card">
          <span class="stat-label">{{ item.label }}</span>
          <strong class="stat-value">{{ item.value }}</strong>
          <span class="stat-hint">{{ item.hint }}</span>
        </article>
      </div>
    </section>

    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover" class="query-card panel-card">
          <div class="panel-head">
            <div>
              <h3>阈值筛选</h3>
              <p>支持按点位与启用状态快速检索，适合做阈值巡检和统一治理。</p>
            </div>
            <span class="panel-badge">点位检索</span>
          </div>
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="点位名称" prop="monitorCode">
              <el-tree-select
                v-model="queryParams.monitorCode"
                :data="monitorTreeOptions"
                :props="monitorTreeProps"
                placeholder="请选择点位名称"
                clearable
                filterable
                check-strictly
                style="width: 240px"
              />
            </el-form-item>
            <el-form-item label="启用状态" prop="isEnable">
              <el-select v-model="queryParams.isEnable" placeholder="请选择启用状态" clearable style="width: 160px">
                <el-option v-for="item in sysNormalDisableOptions" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
            <el-form-item class="query-actions">
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="never" class="table-card panel-card">
      <template #header>
        <div class="panel-head panel-head-compact">
          <div>
            <h3>阈值列表</h3>
            <p>保留原有增删改导出与分页逻辑，只增强视觉识别与阅读节奏。</p>
          </div>
          <span class="panel-badge warm">统一阈值</span>
        </div>
        <el-row :gutter="10" class="mb8 toolbar-row">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['ems/base:monitorMetricThreshold:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="Edit"
              :disabled="single"
              @click="handleUpdate()"
              v-hasPermi="['ems/base:monitorMetricThreshold:edit']"
            >
              修改
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="Delete"
              :disabled="multiple"
              @click="handleDelete()"
              v-hasPermi="['ems/base:monitorMetricThreshold:remove']"
            >
              删除
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['ems/base:monitorMetricThreshold:export']"
              >导出</el-button
            >
          </el-col>
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" />
        </el-row>
      </template>

      <el-table v-loading="loading" border :data="monitorMetricThresholdList" @selection-change="handleSelectionChange" class="data-table">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" type="index" width="60" align="center" />
        <el-table-column label="点位名称" align="center" min-width="180" show-overflow-tooltip>
          <template #default="scope">
            <div class="main-cell">{{ resolveMonitorName(scope.row) }}</div>
          </template>
        </el-table-column>
        <el-table-column label="预警上限" align="center" prop="warnUpper" min-width="110" />
        <el-table-column label="预警下限" align="center" prop="warnLower" min-width="110" />
        <el-table-column label="告警上限" align="center" prop="alarmUpper" min-width="110" />
        <el-table-column label="告警下限" align="center" prop="alarmLower" min-width="110" />
        <el-table-column label="回差值" align="center" prop="hysteresis" min-width="100" />
        <el-table-column label="持续触发秒数" align="center" prop="durationSec" min-width="120" />
        <el-table-column label="告警级别" align="center" prop="alarmLevel" min-width="110" />
        <el-table-column label="启用状态" align="center" width="110">
          <template #default="scope">
            <dict-tag :options="sysNormalDisableOptions" :value="scope.row.isEnable" />
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" prop="remark" min-width="180" show-overflow-tooltip />
        <el-table-column label="操作" align="center" fixed="right" width="110" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-tooltip content="修改" placement="top">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['ems/base:monitorMetricThreshold:edit']" />
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['ems/base:monitorMetricThreshold:remove']" />
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>

    <el-dialog v-model="dialog.visible" :title="dialog.title" width="720px" append-to-body class="themed-dialog">
      <div class="dialog-tip">
        <span class="tip-dot"></span>
        阈值表单继续自动带出测量项编码，只提升录入体验与信息层次，避免人工误填技术字段。
      </div>
      <el-form ref="monitorMetricThresholdFormRef" :model="form" :rules="rules" label-width="110px" class="dialog-form">
        <el-row :gutter="16">
          <el-col :span="12">
            <el-form-item label="点位名称" prop="monitorCode">
              <el-tree-select
                v-model="form.monitorCode"
                :data="monitorTreeOptions"
                :props="monitorTreeProps"
                placeholder="请选择点位名称"
                clearable
                filterable
                check-strictly
                style="width: 100%"
                @change="handleMonitorChange"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="16">
          <el-col :span="12">
            <el-form-item label="预警上限" prop="warnUpper">
              <el-input-number v-model="form.warnUpper" :precision="4" controls-position="right" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预警下限" prop="warnLower">
              <el-input-number v-model="form.warnLower" :precision="4" controls-position="right" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="16">
          <el-col :span="12">
            <el-form-item label="告警上限" prop="alarmUpper">
              <el-input-number v-model="form.alarmUpper" :precision="4" controls-position="right" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="告警下限" prop="alarmLower">
              <el-input-number v-model="form.alarmLower" :precision="4" controls-position="right" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="16">
          <el-col :span="12">
            <el-form-item label="回差值" prop="hysteresis">
              <el-input-number v-model="form.hysteresis" :precision="4" controls-position="right" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="持续触发秒数" prop="durationSec">
              <el-input-number v-model="form.durationSec" :min="0" :step="1" controls-position="right" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="16">
          <el-col :span="12">
            <el-form-item label="告警级别" prop="alarmLevel">
              <el-input v-model="form.alarmLevel" placeholder="请输入告警级别" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="启用状态" prop="isEnable">
          <el-radio-group v-model="form.isEnable">
            <el-radio v-for="item in sysNormalDisableOptions" :key="item.value" :label="item.value">{{ item.label }}</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" type="textarea" :rows="3" maxlength="200" show-word-limit />
        </el-form-item>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { getCurrentInstance } from 'vue';
import { useDict } from '@/utils/dict';
import {
  addMonitorMetricThreshold,
  delMonitorMetricThreshold,
  getMonitorMetricThreshold,
  listMonitorMetricThreshold,
  updateMonitorMetricThreshold
} from '@/api/ems/base/monitorMetricThreshold';
import { getMonitorInfoTree } from '@/api/ems/base/baseMonitorInfo';
import type { MonitorMetricThresholdForm, MonitorMetricThresholdQuery, MonitorMetricThresholdVO } from '@/api/ems/base/monitorMetricThreshold/types';
import type { EmsTreeNode } from '@/api/ems/types';

defineOptions({
  name: 'MonitorMetricThreshold'
} as any);

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const dict = reactive({
  type: useDict('sys_normal_disable') as any
});

const sysNormalDisableOptions = computed(() => dict.type.sys_normal_disable ?? []);

interface ThresholdTreeNode extends EmsTreeNode {
  label?: string;
  value?: string | number;
  children?: ThresholdTreeNode[];
}

const monitorTreeOptions = ref<ThresholdTreeNode[]>([]);
const monitorNameMap = ref<Record<string, string>>({});
const monitorMetaMap = ref<Record<string, { label: string; metricCode?: string }>>({});

const monitorTreeProps = {
  label: 'label',
  value: 'value',
  children: 'children'
};

const monitorMetricThresholdList = ref<MonitorMetricThresholdVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);

const queryFormRef = ref<ElFormInstance>();
const monitorMetricThresholdFormRef = ref<ElFormInstance>();

const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

const normalizeMonitorTree = (nodes: ThresholdTreeNode[] = []): ThresholdTreeNode[] =>
  nodes.map((node) => {
    const children = Array.isArray(node.children) ? normalizeMonitorTree(node.children) : [];
    const label = node.monitorName || node.label || node.name || node.monitorCode || String(node.value ?? '');
    const value = node.monitorCode || node.value || node.monitorId || node.objId || node.id;

    return {
      ...node,
      label,
      value,
      children
    };
  });

const collectMonitorNames = (nodes: ThresholdTreeNode[] = []) => {
  nodes.forEach((node) => {
    const key = String(node.value ?? node.monitorCode ?? '');
    if (key) {
      monitorNameMap.value[key] = node.label || node.monitorName || key;
      monitorMetaMap.value[key] = {
        label: node.label || node.monitorName || key,
        metricCode: node.metricCode as string | undefined
      };
    }
    if (node.children?.length) {
      collectMonitorNames(node.children);
    }
  });
};

const flattenMonitorOptions = (nodes: ThresholdTreeNode[] = []): ThresholdTreeNode[] =>
  nodes.reduce<ThresholdTreeNode[]>((acc, node) => {
    acc.push(node);
    if (node.children?.length) {
      acc.push(...flattenMonitorOptions(node.children));
    }
    return acc;
  }, []);

const initFormData: MonitorMetricThresholdForm = {
  id: undefined,
  monitorCode: undefined,
  metricCode: undefined,
  warnUpper: undefined,
  warnLower: undefined,
  alarmUpper: undefined,
  alarmLower: undefined,
  hysteresis: undefined,
  durationSec: undefined,
  alarmLevel: undefined,
  // 告警通知组不再作为当前交付范围内的前端能力暴露。
  // notifyGroupId: undefined,
  isEnable: '0',
  remark: undefined
};

const data = reactive<PageData<MonitorMetricThresholdForm, MonitorMetricThresholdQuery>>({
  form: { ...initFormData },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    monitorCode: undefined,
    metricCode: undefined,
    warnUpper: undefined,
    warnLower: undefined,
    alarmUpper: undefined,
    alarmLower: undefined,
    hysteresis: undefined,
    durationSec: undefined,
    alarmLevel: undefined,
    // 告警通知组不再参与列表筛选。
    // notifyGroupId: undefined,
    isEnable: undefined,
    params: {}
  },
  rules: {
    id: [{ required: true, message: '主键ID不能为空', trigger: 'blur' }],
    monitorCode: [{ required: true, message: '点位名称不能为空', trigger: 'change' }],
    metricCode: [{ required: true, message: '测量项编码不能为空', trigger: 'blur' }]
  }
});

const { queryParams, form, rules } = toRefs(data);

// 统计卡只用于增强值班人员的整体感知，不参与查询和提交，确保功能链路保持原样。
const overviewStats = computed(() => {
  const thresholds = monitorMetricThresholdList.value;
  const relatedPoints = new Set(thresholds.filter((item) => item.monitorCode).map((item) => item.monitorCode)).size;
  const upperConfigured = thresholds.filter((item) => item.alarmUpper != null || item.warnUpper != null).length;
  const hysteresisConfigured = thresholds.filter((item) => item.hysteresis != null).length;

  return [
    {
      label: '阈值总数',
      value: total.value || thresholds.length,
      hint: '当前列表分页总量'
    },
    {
      label: '关联点位',
      value: relatedPoints,
      hint: '已挂接监测点位'
    },
    {
      label: '已设上限',
      value: upperConfigured,
      hint: '含预警或告警上限'
    },
    {
      label: '已设回差',
      value: hysteresisConfigured,
      hint: '带回差保护配置'
    }
  ];
});

const loadOptions = async () => {
  const treeRes = await getMonitorInfoTree({});

  // 点位配置是业务入口，所以这里把树节点统一归一成 label/value，避免页面继续暴露技术编码给运维人员。
  const treeData = normalizeMonitorTree(((treeRes as any).data ?? treeRes ?? []) as ThresholdTreeNode[]);
  monitorTreeOptions.value = treeData;
  monitorNameMap.value = {};
  monitorMetaMap.value = {};
  collectMonitorNames(flattenMonitorOptions(treeData));
};

const getList = async () => {
  loading.value = true;
  try {
    const res = await listMonitorMetricThreshold(queryParams.value);
    monitorMetricThresholdList.value = ((res as any).rows ?? (res as any).data ?? []) as MonitorMetricThresholdVO[];
    total.value = (res as any).total ?? monitorMetricThresholdList.value.length ?? 0;
  } finally {
    loading.value = false;
  }
};

const resolveMonitorName = (row: MonitorMetricThresholdVO) => {
  // 这里优先用后端联查字段，其次回退到前端已加载的树映射，保证列表总能展示业务名称。
  return row.monitorName || monitorNameMap.value[String(row.monitorCode ?? '')] || row.monitorCode || '-';
};

const reset = () => {
  form.value = { ...initFormData };
  monitorMetricThresholdFormRef.value?.resetFields();
};

const handleMonitorChange = (monitorCode?: string | number) => {
  // 阈值归属的测量项跟着点位档案走，页面不再让用户手填技术编码，避免阈值挂错指标。
  form.value.metricCode = monitorMetaMap.value[String(monitorCode || '')]?.metricCode;
};

const cancel = () => {
  reset();
  dialog.visible = false;
};

const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

const handleSelectionChange = (selection: MonitorMetricThresholdVO[]) => {
  ids.value = selection.map((item) => item.id as string | number);
  single.value = selection.length !== 1;
  multiple.value = !selection.length;
};

const handleAdd = () => {
  reset();
  dialog.visible = true;
  dialog.title = '添加统一点位阈值';
};

const handleUpdate = async (row?: MonitorMetricThresholdVO) => {
  reset();
  const id = row?.id || ids.value[0];
  const res = await getMonitorMetricThreshold(id as number);
  // 编辑时合并默认值，避免后端未来增加字段后旧页面把未展示字段误清空。
  form.value = {
    ...initFormData,
    ...((res as any).data ?? {})
  };
  dialog.visible = true;
  dialog.title = '修改统一点位阈值';
};

const submitForm = async () => {
  const valid = await monitorMetricThresholdFormRef.value?.validate().catch(() => false);
  if (!valid) {
    return;
  }

  buttonLoading.value = true;
  try {
    if (form.value.id) {
      await updateMonitorMetricThreshold(form.value);
      proxy?.$modal.msgSuccess('修改成功');
    } else {
      await addMonitorMetricThreshold(form.value);
      proxy?.$modal.msgSuccess('新增成功');
    }
    dialog.visible = false;
    await getList();
  } finally {
    buttonLoading.value = false;
  }
};

const handleDelete = async (row?: MonitorMetricThresholdVO) => {
  const targetIds = row?.id || ids.value;
  await proxy?.$modal.confirm(`是否确认删除统一点位阈值编号为"${targetIds}"的数据项？`);
  await delMonitorMetricThreshold(targetIds as any);
  proxy?.$modal.msgSuccess('删除成功');
  await getList();
};

const handleExport = () => {
  proxy?.download(
    'ems/base/monitorMetricThreshold/export',
    {
      ...queryParams.value
    },
    `monitorMetricThreshold_${new Date().getTime()}.xlsx`
  );
};

onMounted(async () => {
  await loadOptions();
  await getList();
});
</script>

<style scoped lang="scss">
.page-shell {
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(20, 184, 166, 0.14), transparent 28%),
    radial-gradient(circle at top right, rgba(249, 115, 22, 0.12), transparent 24%), linear-gradient(180deg, #f5faf9 0%, #edf3f4 48%, #f8fafc 100%);
}

.page-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 1fr);
  gap: 18px;
  margin-bottom: 16px;
  padding: 28px 30px;
  border-radius: 28px;
  background: linear-gradient(135deg, rgba(8, 71, 87, 0.96) 0%, rgba(13, 148, 136, 0.9) 50%, rgba(245, 158, 11, 0.82) 100%);
  box-shadow: 0 26px 54px rgba(20, 95, 88, 0.18);
  color: #fff;
  position: relative;
  overflow: hidden;
}

.page-hero::after {
  content: '';
  position: absolute;
  inset: auto -80px -110px auto;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
}

.hero-copy,
.hero-stats {
  position: relative;
  z-index: 1;
}

.hero-eyebrow {
  display: inline-flex;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 12px;
  letter-spacing: 0.16em;
}

.hero-title {
  margin: 18px 0 12px;
  font-size: 30px;
  line-height: 1.2;
}

.hero-desc {
  margin: 0;
  max-width: 700px;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.75;
}

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

.stat-card {
  padding: 18px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(10px);
}

.stat-label,
.stat-hint {
  display: block;
}

.stat-label {
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
}

.stat-value {
  display: block;
  margin: 10px 0 8px;
  font-size: 30px;
  line-height: 1;
  font-weight: 700;
}

.stat-hint {
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
}

.panel-card {
  border: 1px solid rgba(201, 214, 215, 0.72);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 18px 40px rgba(36, 71, 73, 0.08);
  backdrop-filter: blur(12px);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-head-compact {
  margin-bottom: 14px;
}

.panel-head h3 {
  margin: 0 0 6px;
  font-size: 20px;
  color: #18454a;
}

.panel-head p {
  margin: 0;
  color: #64767a;
  line-height: 1.6;
}

.panel-badge {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ccfbf1, #dbeafe);
  color: #0f6b73;
  font-size: 12px;
  font-weight: 600;
}

.panel-badge.warm {
  background: linear-gradient(135deg, #fef3c7, #fed7aa);
  color: #a16207;
}

.query-actions {
  :deep(.el-form-item__content) {
    gap: 10px;
  }
}

.toolbar-row {
  padding: 14px 16px;
  margin: 0;
  border-radius: 18px;
  background: linear-gradient(90deg, rgba(13, 148, 136, 0.08), rgba(249, 115, 22, 0.08));
}

.data-table {
  :deep(.el-table__header-wrapper th) {
    background: #f3fbfa;
    color: #17464d;
    font-weight: 700;
  }

  :deep(.el-table__body tr:hover > td) {
    background: rgba(13, 148, 136, 0.06) !important;
  }
}

.dialog-tip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 16px;
  background: linear-gradient(90deg, rgba(13, 148, 136, 0.08), rgba(249, 115, 22, 0.08));
  color: #2d5960;
  line-height: 1.65;
}

.tip-dot {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #14b8a6, #f59e0b);
  box-shadow: 0 0 0 5px rgba(20, 184, 166, 0.12);
}

.dialog-form {
  padding: 18px;
  border-radius: 18px;
  background: linear-gradient(180deg, #f8fcfc 0%, #ffffff 100%);
}

.main-cell {
  line-height: 20px;
  font-weight: 600;
  color: #17464d;
}

.sub-cell {
  color: var(--el-text-color-secondary);
  font-size: 12px;
  line-height: 18px;
}

:deep(.panel-card > .el-card__header) {
  border-bottom: none;
  padding-bottom: 0;
}

:deep(.panel-card > .el-card__body) {
  padding-top: 0;
}

:deep(.themed-dialog .el-dialog) {
  border-radius: 26px;
  overflow: hidden;
  box-shadow: 0 28px 60px rgba(15, 23, 42, 0.2);
}

:deep(.themed-dialog .el-dialog__header) {
  padding: 22px 24px 14px;
  background: linear-gradient(135deg, rgba(8, 71, 87, 0.96), rgba(13, 148, 136, 0.88));
}

:deep(.themed-dialog .el-dialog__title),
:deep(.themed-dialog .el-dialog__headerbtn .el-dialog__close) {
  color: #fff;
}

:deep(.themed-dialog .el-dialog__body) {
  padding: 22px 24px;
  background: linear-gradient(180deg, #f8fcfc 0%, #ffffff 100%);
}

:deep(.themed-dialog .el-dialog__footer) {
  padding: 0 24px 24px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fcfc 100%);
}

@media (max-width: 992px) {
  .page-hero {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .page-hero {
    padding: 18px;
    border-radius: 20px;
  }

  .hero-stats {
    grid-template-columns: 1fr;
  }

  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }
}
</style>
