<template>
  <view class="detail-page">
    <!-- 顶部状态栏 -->
    <view class="header-section">
      <view class="header-content">
        <view class="title-group">
          <text class="main-title">黑名单企业监控</text>
          <text class="sub-title">监控异常经营企业</text>
        </view>
        <view class="stat-box">
          <text class="stat-num">{{ rows?.length || 0 }}</text>
          <text class="stat-unit">家</text>
        </view>
      </view>
      <view class="header-toolbar">
        <view class="filter-tabs">
          <view
            class="tab-item"
            v-for="(tab, index) in timeFilters"
            :key="index"
            :class="{ active: currentFilter === tab.value }"
            @click="switchFilter(tab.value)"
          >
            {{ tab.label }}
          </view>
        </view>
        <view class="filter-wrap">
          <view class="selector" @click.stop="toggleProvinceDropdown">
            <text class="selector-text">{{
              selectedProvince || "全部省份"
            }}</text>
            <text
              class="selector-arrow"
              :class="{ open: dropdownProvinceOpen }"
            ></text>
          </view>
        </view>
      </view>
      <!-- 背景装饰 -->
      <view class="header-circle circle-1"></view>
      <view class="header-circle circle-2"></view>
    </view>

    <scroll-view
      class="list-scroll"
      scroll-y="true"
      refresher-enabled
      :refresher-triggered="isRefreshing"
      @refresherrefresh="onRefresh"
    >
      <view class="list-container">
        <view
          class="date-group"
          v-for="groupItem in groupedRows"
          :key="groupItem.date"
        >
          <view class="date-group-card">
            <view class="group-left">
              <view
                class="group-select-btn"
                :class="{
                  selected: isGroupFullySelected(groupItem),
                  partial: isGroupPartiallySelected(groupItem),
                }"
                @click.stop="toggleGroupSelection(groupItem)"
              >
                <text v-if="isGroupFullySelected(groupItem)">✓</text>
                <text v-else-if="isGroupPartiallySelected(groupItem)">-</text>
              </view>
              <text class="date-label">{{ groupItem.date }}</text>
            </view>
          </view>

          <view
            class="card-item"
            v-for="(item, index) in groupItem.list"
            :key="item.__selectId || index"
            @click="toDetail(item)"
          >
            <view class="card-header">
              <view class="header-left">
                <view
                  class="company-select-btn"
                  :class="{ selected: isCompanySelected(item) }"
                  @click.stop="toggleCompanySelection(item)"
                >
                  <text v-if="isCompanySelected(item)">✓</text>
                </view>
                <text class="company-name">{{ item.queryCustomer }}</text>
                <text
                  class="level-tag"
                  :class="getLevelClass(item.customerLevel)"
                >
                  {{ item.customerLevel }}
                </text>
              </view>
              <view class="header-right">
                <text class="status-tag">黑名单</text>
              </view>
            </view>

            <view class="card-body">
              <view class="code-row">
                <text class="label">信用代码：</text>
                <text class="value code-text">{{ item.socialCreditCode }}</text>
              </view>
              <view class="info-grid">
                <view class="info-item">
                  <text class="label">省份</text>
                  <text class="value">{{ item.province }}</text>
                </view>
                <view class="info-item">
                  <text class="label">责任经理</text>
                  <text class="value">{{ item.responsibleManager }}</text>
                </view>
                <view class="info-item">
                  <text class="label">客户性质</text>
                  <text class="value">{{ item.customerNature }}</text>
                </view>
              </view>
            </view>
          </view>
        </view>

        <view v-if="!loading && rows.length === 0" class="empty-data">
          <EmptyView text="无相关数据" />
        </view>
      </view>
    </scroll-view>

    <view class="footer-btn-area">
      <button class="action-btn export-btn" @click="handleExport">
        导出至邮箱
      </button>
    </view>

    <!-- 蒙层 -->
    <view
      class="report-export-create-modal-mask"
      v-if="emailModalOpen"
      @click="closeEmailModal"
      @touchmove.stop.prevent
    ></view>

    <!-- 邮箱导出弹窗 -->
    <view
      class="report-export-create-modal report-export-create-email-modal"
      :class="{ 'report-export-create-modal--open': emailModalOpen }"
      v-if="emailModalOpen"
    >
      <view class="report-export-create-modal-title">
        <text>发送至邮箱</text>
        <view
          class="report-export-create-modal-close"
          @click.stop="closeEmailModal"
          >×</view
        >
      </view>
      <view
        class="report-export-create-modal-body"
        :style="{ padding: '40rpx' }"
      >
        <up-input
          v-model="emailForm.email"
          border="none"
          :customStyle="{
            backgroundColor: '#ebf3fb',
            height: '80rpx',
            paddingLeft: '20rpx',
          }"
          placeholder="请填写邮箱"
          @input="emailError = false"
          disabled
        >
          <template #suffix>
            <view style="margin-right: 20rpx; color: #666">@999.com.cn</view>
          </template>
        </up-input>
        <text v-if="emailError" class="report-export-error-text"
          >请输入邮箱</text
        >
      </view>
      <view
        class="report-export-create-modal-footer"
        :style="{
          padding: '20rpx 40rpx 40rpx',
          display: 'flex',
          'justify-content': 'space-between',
        }"
      >
        <view
          class="report-export-create-modal-btn cancel-btn"
          @click.stop="closeEmailModal"
          >取消</view
        >
        <view
          class="report-export-create-modal-btn confirm-btn"
          @click.stop="handleSendEmail"
          >发送</view
        >
      </view>
    </view>

    <!-- 独立的下拉菜单层 -->
    <view class="dropdown-layer" v-if="dropdownProvinceOpen" @click.stop>
      <view class="dropdown">
        <view class="dropdown-search-bar">
          <input
            class="dropdown-search-input"
            v-model="provinceSearchText"
            @input="onProvinceSearch"
            placeholder="搜索省份..."
            placeholder-style="color: #999"
          />
        </view>
        <scroll-view scroll-y="true" class="dropdown-scroll-view">
          <view
            class="dropdown-item"
            v-for="(p, i) in filteredProvinceList"
            :key="p || i"
            :class="{
              active: p === selectedProvince || (!selectedProvince && i === 0),
            }"
            @click.stop="selectProvince(p)"
          >
            {{ p || "全部省份" }}
            <text
              v-if="p === selectedProvince || (!selectedProvince && i === 0)"
              class="check-mark"
              >✓</text
            >
          </view>
          <view v-if="filteredProvinceList.length === 0" class="dropdown-empty"
            >暂无数据</view
          >
        </scroll-view>
      </view>
    </view>
  </view>
  <BottomScrollTip :text="'下滑动查看更多内容'" :bottom="'140rpx'" />
</template>

<script>
import EmptyView from "../../../wigets/empty.vue";
import BottomScrollTip from "../../../wigets/BottomScrollTip.vue";
import request from "../../../request/index.js";
import { formatDate, guid } from "../../../utils/utils.js";

export default {
  components: {
    EmptyView,
    BottomScrollTip,
  },
  data() {
    return {
      isRefreshing: false,
      loading: false,
      rows: [],
      allRows: [],
      dropdownProvinceOpen: false,
      provinceSearchText: "",
      provinceList: [""],
      selectedProvince: "",
      currentFilter: "all",
      timeFilters: [
        { label: "全部", value: "all" },
        { label: "近7天", value: "7" },
        { label: "近15天", value: "15" },
        { label: "近30天", value: "30" },
      ],
      emailModalOpen: false,
      emailForm: {
        email: "",
      },
      emailError: false,
      // 仅用于展示/校验（不影响请求逻辑）
      currentFromDate: "",
      currentToDate: "",

      // 多选导出选择状态：存 socialCreditCode（或其他唯一字段）的集合
      selectedCompanyKeys: [],
    };
  },
  created() {
    this.resetFetch();
    this.getProviceList();
    const userEmail = uni.getStorageSync("traceCode_useremail");
    this.emailForm.email = userEmail;
  },
  methods: {
    formatDate,
    getLevelClass(level) {
      if (level === "VIP") return "tag-vip";
      if (level === "二级") return "tag-l2";
      if (level === "三级") return "tag-l3";
      return "tag-default";
    },
    switchFilter(value) {
      if (this.currentFilter === value) return;
      this.currentFilter = value;
      this.resetFetch();
    },

    // 用于选择的唯一 key（优先 socialCreditCode）
    getCompanyKey(item = {}) {
      return String(
        item.__selectId ||
          item.socialCreditCode ||
          item.id ||
          item.queryCustomer ||
          "",
      );
    },

    /** 将 YYYY-MM-DD 加一天，用于邮件接口 statisticsDate */
    addOneDayFromDateStr(dateStr) {
      if (!dateStr) return "";
      const parts = String(dateStr).trim().split("-");
      if (parts.length !== 3) return dateStr;
      const y = +parts[0];
      const m = +parts[1];
      const d = +parts[2];
      if (!y || !m || !d) return dateStr;
      const dt = new Date(y, m - 1, d);
      dt.setDate(dt.getDate() + 1);
      return this.formatDate(dt, "YYYY-MM-DD");
    },

    isCompanySelected(item) {
      const key = this.getCompanyKey(item);
      if (!key) return false;
      return this.selectedCompanyKeys.includes(key);
    },

    toggleCompanySelection(item) {
      const key = this.getCompanyKey(item);
      if (!key) return;
      const has = this.selectedCompanyKeys.includes(key);
      if (has) {
        this.selectedCompanyKeys = this.selectedCompanyKeys.filter(
          (k) => k !== key,
        );
      } else {
        this.selectedCompanyKeys = [...this.selectedCompanyKeys, key];
      }
    },

    isGroupFullySelected(groupItem = {}) {
      const list = Array.isArray(groupItem.list) ? groupItem.list : [];
      if (!list.length) return false;
      return list.every((it) => this.isCompanySelected(it));
    },

    isGroupPartiallySelected(groupItem = {}) {
      const list = Array.isArray(groupItem.list) ? groupItem.list : [];
      if (!list.length) return false;
      const selectedCount = list.filter((it) =>
        this.isCompanySelected(it),
      ).length;
      return selectedCount > 0 && selectedCount < list.length;
    },

    toggleGroupSelection(groupItem = {}) {
      const list = Array.isArray(groupItem.list) ? groupItem.list : [];
      if (!list.length) return;
      const groupKeys = list
        .map((it) => this.getCompanyKey(it))
        .filter(Boolean);
      if (!groupKeys.length) return;

      const allSelected = groupKeys.every((k) =>
        this.selectedCompanyKeys.includes(k),
      );
      if (allSelected) {
        this.selectedCompanyKeys = this.selectedCompanyKeys.filter(
          (k) => !groupKeys.includes(k),
        );
      } else {
        const merged = new Set([...this.selectedCompanyKeys, ...groupKeys]);
        this.selectedCompanyKeys = Array.from(merged);
      }
    },

    getProviceList() {
      request("/common/getProviceList", {
        path: "traceabilityReport/pages/blacklist/index.vue",
      }).then((res) => {
        if (res.code == 200) {
          const _data = res.data || [];
          this.provinceList = ["", ..._data.map((item) => item.regionName)];
        }
      });
    },

    fetchList() {
      if (this.loading) return;
      this.loading = true;

      const today = new Date();
      const toDateStr = this.formatDate(today, "YYYY-MM-DD");

      let fromDateStr = "";
      if (this.currentFilter === "all") {
        const twoMonthsAgo = new Date();
        twoMonthsAgo.setMonth(today.getMonth() - 2);
        fromDateStr = this.formatDate(twoMonthsAgo, "YYYY-MM-DD");
      } else {
        const days = parseInt(this.currentFilter);
        const pastDate = new Date();
        pastDate.setDate(today.getDate() - days);
        fromDateStr = this.formatDate(pastDate, "YYYY-MM-DD");
      }

      request("/blacklist-report/get-export-company-data", {
        fromDate: fromDateStr,
        toDate: toDateStr,
        path: "traceabilityReport/pages/blacklist/index.vue",
      }).then((res) => {
        if (res.code == 200) {
          this.allRows = (res.data || []).map((it) => ({
            ...it,
            __selectId: it?.__selectId || guid("blk_"),
          }));
          this.applyFilter();
        }
        this.loading = false;
        this.isRefreshing = false;
      });
    },

    async onRefresh() {
      this.isRefreshing = true;
      this.fetchList();
    },

    resetFetch() {
      this.rows = [];
      this.selectedCompanyKeys = [];
      this.fetchList();
    },

    toDetail(item) {
      uni.navigateTo({
        url: `/traceCodePackages/traceabilityReport/pages/blacklist/detail/index?id=${item.socialCreditCode}&dateStr=${item.billTime}&name=${encodeURIComponent(item.queryCustomer)}`,
      });
    },

    handleHistory() {
      uni.navigateTo({
        url: "/traceCodePackages/traceabilityReport/pages/blacklist/history/index",
      });
    },

    handleExport() {
      if (this.selectedCompanyKeys?.length === 0) {
        uni.showToast({
          title: "请选择要导出的企业",
          icon: "none",
        });
        return;
      }
      this.emailModalOpen = true;
      this.emailError = false;
    },

    closeEmailModal() {
      this.emailModalOpen = false;
    },

    handleSendEmail() {
      if (!this.emailForm.email) {
        this.emailError = true;
        return;
      }
      const selectedTaskIds = this.getSelectedTaskIds();
      if (!selectedTaskIds.length) {
        uni.showToast({ title: "未找到可导出的任务", icon: "none" });
        return;
      }
      uni.showLoading({ title: "发送中..." });

      const doSingleSend = async () => {
        const keys = new Set(this.selectedCompanyKeys || []);
        const selectedRows = (this.rows || []).filter((r) =>
          keys.has(this.getCompanyKey(r)),
        );
        const emailDTOList = selectedRows.map((item) => ({
          companyNameList: item.queryCustomer.split(","),
          statisticsDate: this.addOneDayFromDateStr(item.billTime),
          taskId: item.taskId,
        }));
        return request(
          "/api/email/send",
          {
            emailDTOList,
            type: 0,
            uid: uni.getStorageSync("userInfo").ldap,
            emailAddress: this.emailForm.email + "@999.com.cn",
            path: "traceabilityReport/pages/blacklist/index.vue",
          },
          "post",
        );
      };

      const run = async () => {
        // try {
        //   // 先尝试一次性传多个 taskId（后端若支持）
        //   const res = await request("/report/sendemail", {
        //     taskId: selectedTaskIds,
        //     emailAddress: this.emailForm.email + "@999.com.cn",
        //     path: "traceabilityReport/pages/blacklist/index.vue",
        //   });
        //   if (res?.code == 200) {
        //     uni.hideLoading();
        //     uni.showToast({ title: "发送成功", icon: "success" });
        //     this.closeEmailModal();
        //     return;
        //   }
        // } catch (e) {
        //   // ignore, fallback below
        // }

        // 不支持 combinedTask：逐个发送
        // for (let i = 0; i < selectedTaskIds.length; i++) {
        //   const taskId = selectedTaskIds[i];
        //   const r = await doSingleSend(taskId);
        //   if (r?.code != 200) {
        //     uni.hideLoading();
        //     uni.showToast({
        //       title: r?.msg || "发送失败",
        //       icon: "none",
        //     });
        //     return;
        //   }
        // }

        const r = await doSingleSend();
        if (r?.code != 200) {
          uni.hideLoading();
          uni.showToast({
            title: r?.msg || "发送失败",
            icon: "none",
          });
          return;
        }

        uni.hideLoading();
        uni.showToast({ title: "发送成功", icon: "success" });
        this.closeEmailModal();
      };

      run();
    },

    getSelectedTaskIds() {
      const keys = new Set(this.selectedCompanyKeys || []);
      const selectedRows = (this.rows || []).filter((r) =>
        keys.has(this.getCompanyKey(r)),
      );
      const ids = selectedRows.map((r) => r?.taskId).filter(Boolean);
      return Array.from(new Set(ids));
    },

    applyFilter() {
      if (!this.selectedProvince) {
        this.rows = [...this.allRows];
      } else {
        this.rows = this.allRows.filter(
          (item) => item.customerProvinceName === this.selectedProvince,
        );
      }
      this.totalCount = this.rows.length;
      // 切换省份/刷新数据后，清空已选企业，避免“跨筛选脏选中”
      this.selectedCompanyKeys = [];
    },

    toggleProvinceDropdown() {
      this.dropdownProvinceOpen = !this.dropdownProvinceOpen;
    },

    closeProvinceDropdown() {
      this.dropdownProvinceOpen = false;
    },

    selectProvince(province) {
      this.selectedProvince = province || "";
      this.dropdownProvinceOpen = false;
      this.applyFilter();
    },
  },
  computed: {
    filteredProvinceList() {
      if (!this.provinceSearchText) {
        return this.provinceList;
      }
      return this.provinceList.filter((p) =>
        p?.toLowerCase()?.includes(this.provinceSearchText.toLowerCase()),
      );
    },
    groupedRows() {
      const groups = {};
      (this.rows || []).forEach((item) => {
        const date = item?.billTime || "未知日期";
        if (!groups[date]) groups[date] = [];
        groups[date].push(item);
      });

      return Object.keys(groups)
        .sort(
          (a, b) =>
            new Date(String(b).replace(/-/g, "/")).getTime() -
            new Date(String(a).replace(/-/g, "/")).getTime(),
        )
        .map((date) => ({
          date,
          list: groups[date],
        }));
    },
  },
};
</script>

<style scoped>
.detail-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 116rpx - env(safe-area-inset-bottom));
  box-sizing: border-box;
  background: #f5f7fa;
}

/* Header Section */
.header-section {
  background: linear-gradient(135deg, #2b32b2 0%, #1488cc 100%);
  padding: 40rpx 40rpx 80rpx;
  /* Extra padding at bottom for overlap effect */
  position: relative;
  z-index: 20;
  color: #fff;
  border-bottom-left-radius: 40rpx;
  border-bottom-right-radius: 40rpx;
  overflow: hidden;
  box-shadow: 0 10rpx 30rpx rgba(20, 136, 204, 0.2);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 2;
  margin-bottom: 24rpx;
}

.title-group {
  display: flex;
  flex-direction: column;
}

.main-title {
  font-size: 40rpx;
  font-weight: bold;
  margin-bottom: 8rpx;
  letter-spacing: 2rpx;
}

.sub-title {
  font-size: 24rpx;
  opacity: 0.8;
}

.stat-box {
  display: flex;
  align-items: baseline;
}

.stat-num {
  font-size: 56rpx;
  font-weight: bold;
  margin-right: 8rpx;
  font-family: "DINAlternate-Bold", sans-serif;
}

.stat-unit {
  font-size: 24rpx;
  opacity: 0.8;
}

.header-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 3;
  gap: 20rpx;
}

.update-tip {
  display: inline-flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.15);
  padding: 8rpx 20rpx;
  border-radius: 30rpx;
  font-size: 22rpx;
  backdrop-filter: blur(10px);
}

.tip-icon {
  margin-right: 8rpx;
  font-size: 20rpx;
}

/* Filter Styles */
.filter-wrap {
  position: relative;
}

.selector {
  display: flex;
  align-items: center;
  color: #fff;
  font-size: 26rpx;
  font-weight: 500;
  padding: 8rpx 20rpx;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 30rpx;
  border: 1rpx solid rgba(255, 255, 255, 0.3);
}

.selector-text {
  max-width: 200rpx;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.selector-arrow {
  margin-left: 10rpx;
  width: 0;
  height: 0;
  border-left: 8rpx solid transparent;
  border-right: 8rpx solid transparent;
  border-top: 10rpx solid #fff;
  transition: transform 0.3s;
}

.selector-arrow.open {
  transform: rotate(180deg);
}

/* Dropdown Layer (Absolute on top of everything) */
.dropdown-layer {
  position: absolute;
  top: 300rpx;
  /* Adjust based on header layout */
  right: 40rpx;
  z-index: 999;
}

/* Header date filter tabs */
.filter-tabs {
  display: flex;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 16rpx;
  padding: 6rpx 6rpx;
  z-index: 30;
  position: relative;
  flex: 1;
  max-width: 420rpx;
}

.tab-item {
  flex: 1;
  text-align: center;
  font-size: 24rpx;
  padding: 10rpx 0;
  border-radius: 12rpx;
  color: rgba(255, 255, 255, 0.8);
  transition: all 0.3s;
}

.tab-item.active {
  background: #fff;
  color: #2b32b2;
  font-weight: 600;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
}

/* Date-group (history style) */
.date-group {
  margin-bottom: 40rpx;
}

.date-group-card {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background: #fff;
  padding: 20rpx 30rpx;
  border-radius: 16rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.03);
  border-left: 8rpx solid #1488cc;
}

.group-left {
  display: flex;
  align-items: center;
}

.date-label {
  font-size: 30rpx;
  font-weight: 600;
  color: #333;
}

.group-right {
  flex-shrink: 0;
}

.group-select-btn {
  width: 44rpx;
  height: 44rpx;
  border-radius: 50%;
  border: 2rpx solid #1488cc;
  color: #1488cc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26rpx;
  background: rgba(20, 136, 204, 0.06);
  margin-right: 18rpx;
}

.group-select-btn.selected {
  background: #1488cc;
  color: #fff;
}

.group-select-btn.partial {
  background: rgba(20, 136, 204, 0.15);
}

.company-select-btn {
  width: 44rpx;
  height: 44rpx;
  border-radius: 50%;
  border: 2rpx solid #d0d7e2;
  color: #d0d7e2;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 14rpx;
  font-size: 26rpx;
  background: #fff;
}

.company-select-btn.selected {
  border-color: #1488cc;
  color: #1488cc;
  background: rgba(20, 136, 204, 0.08);
}

.dropdown {
  width: 360rpx;
  background: #fff;
  border-radius: 12rpx;
  box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.dropdown-search-bar {
  padding: 16rpx;
  border-bottom: 1rpx solid #f0f0f0;
}

.dropdown-search-input {
  background: #f5f7fa;
  height: 64rpx;
  border-radius: 32rpx;
  padding: 0 24rpx;
  font-size: 26rpx;
}

.dropdown-scroll-view {
  max-height: 400rpx;
}

.dropdown-item {
  padding: 20rpx 30rpx;
  font-size: 28rpx;
  color: #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.2s;
}

.dropdown-item:active {
  background: #f5f7fa;
}

.dropdown-item.active {
  color: #1890ff;
  font-weight: 500;
  background: #e6f7ff;
}

.check-mark {
  font-size: 24rpx;
}

.dropdown-empty {
  padding: 40rpx;
  text-align: center;
  color: #999;
  font-size: 26rpx;
}

/* Header Decor Circles */
.header-circle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
}

.circle-1 {
  width: 300rpx;
  height: 300rpx;
  top: -100rpx;
  right: -50rpx;
}

.circle-2 {
  width: 200rpx;
  height: 200rpx;
  bottom: -50rpx;
  left: -50rpx;
}

/* List Scroll */
.list-scroll {
  flex: 1;
  height: 0;
  padding: 0 24rpx;
  /* Remove vertical padding from scroll container */
  box-sizing: border-box;
  margin-top: -50rpx;
  /* Negative margin to pull list up */
  position: relative;
  z-index: 21;
}

.list-container {
  padding-top: 10rpx;
  padding-bottom: calc(200rpx + env(safe-area-inset-bottom));
}

.card-item {
  background: #fff;
  border-radius: 20rpx;
  padding: 30rpx;
  margin-bottom: 24rpx;
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.05);
  transition: transform 0.2s;
}

.card-item:active {
  transform: scale(0.99);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24rpx;
}

.header-left {
  flex: 1;
  display: flex;
  align-items: center;
  margin-right: 20rpx;
}

.index-num {
  font-size: 24rpx;
  color: #999;
  margin-right: 12rpx;
  font-family: monospace;
}

.company-name {
  font-size: 32rpx;
  font-weight: 600;
  color: #096dd9;
  line-height: 1.4;
  text-decoration: underline;
}

.header-right {
  flex-shrink: 0;
}

.status-tag {
  font-size: 20rpx;
  padding: 6rpx 16rpx;
  border-radius: 20rpx;
  background: #fff1f0;
  color: #ff4d4f;
  font-weight: 600;
  border: 1rpx solid rgba(255, 77, 79, 0.2);
}

.card-body {
  background: #f9fbfd;
  border-radius: 12rpx;
  padding: 24rpx;
}

.code-row {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
  padding-bottom: 20rpx;
  border-bottom: 1rpx solid #edf0f5;
}

.code-row:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.code-text {
  font-family: monospace;
  color: #333 !important;
  font-weight: 600 !important;
  letter-spacing: 1rpx;
}

.info-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 24rpx;
}

.info-item {
  display: flex;
  align-items: center;
  width: 45%;
}

.info-item .label,
.code-row .label {
  font-size: 24rpx;
  color: #999;
  margin-right: 12rpx;
}

.info-item .value,
.code-row .value {
  font-size: 26rpx;
  color: #666;
  font-weight: 500;
}

/* Loading & Footer */
.loading-more {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30rpx 0;
}

.loading-text {
  font-size: 24rpx;
  color: #999;
}

.loading-icon {
  width: 32rpx;
  height: 32rpx;
  margin-right: 12rpx;
  animation: spin 1s linear infinite;
}

.empty-data {
  padding-top: 120rpx;
}

.no-more {
  text-align: center;
  color: #ccc;
  font-size: 24rpx;
  padding: 30rpx 0;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.footer-btn-area {
  padding: 24rpx 32rpx calc(24rpx + env(safe-area-inset-bottom));
  background: #fff;
  box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.08);
  position: fixed;
  z-index: 100;
  bottom: 0;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  gap: 24rpx;
}

.action-btn {
  flex: 1;
  height: 88rpx;
  line-height: 88rpx;
  border-radius: 44rpx;
  font-size: 30rpx;
  font-weight: 600;
  text-align: center;
  border: none;
  transition: all 0.3s;
}

.action-btn::after {
  border: none;
}

.action-btn:active {
  transform: scale(0.96);
}

.history-btn {
  background: #fff;
  color: #1890ff;
  border: 2rpx solid #1890ff;
  box-shadow: 0 4rpx 12rpx rgba(24, 144, 255, 0.1);
}

.export-btn {
  background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
  color: #fff;
  box-shadow: 0 6rpx 16rpx rgba(24, 144, 255, 0.35);
}

/* 弹窗样式 */
.report-export-create-modal-mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 999;
  backdrop-filter: blur(2px);
}

.report-export-create-modal {
  position: fixed;
  z-index: 1000;
  background: #fff;
  transition: all 0.3s ease;
}

.report-export-create-email-modal {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 620rpx;
  border-radius: 24rpx;
  opacity: 0;
  visibility: hidden;
  overflow: hidden;
}

.report-export-create-email-modal.report-export-create-modal--open {
  opacity: 1;
  visibility: visible;
}

.report-export-create-modal-title {
  padding: 36rpx 32rpx;
  font-size: 36rpx;
  color: #333;
  text-align: center;
  font-weight: 600;
  border-bottom: 1rpx solid #f0f0f0;
  position: relative;
}

.report-export-create-modal-close {
  position: absolute;
  right: 32rpx;
  top: 50%;
  transform: translateY(-50%);
  font-size: 44rpx;
  color: #999;
  line-height: 1;
  padding: 10rpx;
}

.report-export-create-modal-body {
  padding: 48rpx 40rpx 32rpx;
}

.report-export-error-text {
  font-size: 24rpx;
  color: #ff4d4f;
  margin-top: 12rpx;
  display: block;
}

.report-export-create-modal-footer {
  padding: 0 40rpx 48rpx;
  display: flex;
  justify-content: space-between;
  gap: 24rpx;
}

.report-export-create-modal-btn {
  height: 88rpx;
  line-height: 88rpx;
  border-radius: 44rpx;
  text-align: center;
  font-size: 30rpx;
  font-weight: 600;
  flex: 1;
  margin: 0;
}

.cancel-btn {
  background: #f5f7fa;
  color: #666;
  border: 1rpx solid #e4e7ed;
}

.confirm-btn {
  background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
  color: #fff;
  box-shadow: 0 6rpx 16rpx rgba(24, 144, 255, 0.3);
}

.level-tag {
  font-size: 20rpx;
  padding: 4rpx 12rpx;
  border-radius: 8rpx;
  white-space: nowrap;
  line-height: 1.2;
}
.tag-vip {
  background: linear-gradient(135deg, #e6f7ff, #bae7ff);
  color: #096dd9;
}

.tag-l2 {
  background: linear-gradient(135deg, #f6ffed, #d9f7be);
  color: #389e0d;
}

.tag-l3 {
  background: linear-gradient(135deg, #fff7e6, #ffe7ba);
  color: #d46b08;
}

.tag-default {
  background: #f5f5f5;
  color: #999;
}

</style>
