<template>
  <div class="app-container">
    <!-- 搜索区域 -->
    <el-card shadow="never" class="search-card">
      <el-form :model="queryParams" ref="queryRef" inline label-width="80px">
        <el-form-item label="客户名称" prop="customerName" class="custom-form-item">
          <el-input v-model="queryParams.customerName" placeholder="请输入客户名称" clearable style="width: 180px" />
        </el-form-item>
        <el-form-item label="编号" prop="receiptId" class="custom-form-item">
          <el-input v-model="queryParams.receiptId" placeholder="请输入编号" clearable style="width: 180px" />
        </el-form-item>
        <el-form-item label="联系人" prop="contactPerson" class="custom-form-item">
          <el-select v-model="queryParams.contactPerson" placeholder="请选择" clearable filterable remote :remote-method="remoteLoadAllContacts" :loading="contactSearchLoading" @focus="remoteLoadAllContacts('')" style="width: 180px">
            <el-option v-for="item in filterContactOptions" :key="item.value" :label="item.label" :value="item.label" />
          </el-select>
        </el-form-item>
        <el-form-item label-width="0" class="btns-item">
          <div class="search-btns-group">
            <el-button icon="Search" @click="handleQuery" class="btn-search">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery" class="btn-reset">重置</el-button>
            <el-button type="primary" icon="Plus" @click="handleAdd" class="btn-plus">新增</el-button>
          </div>
        </el-form-item>
      </el-form>
    </el-card>

    <!-- 列表标题 + Tabs -->
    <div class="title-container">
      <div class="header-left">
        <span class="page-title">客户关怀信息列表</span>
      </div>
      <div class="tabs-group">
        <span :class="['tab-btn', activeTab === 'mine' ? 'active' : '']" @click="switchTab('mine')">我负责的关怀</span>
        <span :class="['tab-btn', activeTab === 'all' ? 'active' : '']" @click="switchTab('all')">全部客户关怀</span>
      </div>
    </div>

    <!-- 表格区域 -->
    <el-card shadow="never" class="table-card">
      <el-table ref="tableRef" v-loading="loading" :data="dataList" border class="custom-table" :header-cell-style="{ background: '#f8fafc', color: '#333', fontWeight: 'bold' }">
        <el-table-column label="单据编号" align="center" prop="receiptId" width="150">
          <template #default="scope">
            <span class="link-text" @click="handleDetail(scope.row)">{{ scope.row.receiptId }}</span>
          </template>
        </el-table-column>
        <el-table-column label="登记日期" align="center" prop="createTime" width="160">
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户联系人" align="center" prop="contactPerson" width="120" />
        <el-table-column label="客户名称" align="center" prop="customerName" min-width="250" show-overflow-tooltip />
        <el-table-column label="关怀类型" align="center" prop="concernType" width="120">
          <template #default="scope">
            <el-tag :type="careTypeTag(scope.row.concernType)" size="small">{{ careTypeText(scope.row.concernType) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="金额" align="center" prop="amount" width="100" />
        <el-table-column label="状态" align="center" prop="auditStatus" width="100">
          <template #default="scope">
            <el-tag :type="statusTag(scope.row.auditStatus)" size="small">{{ statusText(scope.row.auditStatus) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="120" fixed="right">
          <template #default="scope">
            <el-button link type="primary" @click="handleDetail(scope.row)">详情</el-button>
            <el-button link type="danger" @click="handleDelete(scope.row)">删除</el-button>
          </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-drawer :title="drawerTitle" v-model="open" direction="rtl" size="80%" destroy-on-close>
      <div class="drawer-body">
        <el-form ref="formRef" :model="form" :rules="rules" label-width="90px" label-position="right">
          <div class="dialog-section no-border">
            <div class="section-title">个人资料</div>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="客户名称" prop="customerName">
                  <el-select v-model="form.customerName" placeholder="请输入关键词搜索客户" style="width: 100%" filterable remote :remote-method="remoteLoadCustomers" :loading="selectLoading" @focus="remoteLoadCustomers('')" @change="handleCustomerChange">
                    <el-option v-for="item in customerOptions" :key="item.value" :label="item.label" :value="item.label" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="行业" prop="profession">
                  <el-input v-model="form.profession" placeholder="" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="30">
              <el-col :span="12">
                <el-form-item label="部门" prop="department">
                  <el-input v-model="form.department" placeholder="" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="业务员" prop="salesman">
                  <el-input v-model="form.salesman" placeholder="" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="30">
              <el-col :span="12">
                <el-form-item label="联系人" prop="contactPerson">
                  <el-select v-model="form.contactPerson" placeholder="请输入关键词搜索联系人" style="width: 100%" filterable clearable remote :remote-method="remoteSearchContacts" :loading="contactSearchLoading" @focus="onContactFocus" @change="handleContactChange">
                    <el-option v-for="item in contactOptions" :key="item.id" :label="item.label" :value="item.label" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="手机" prop="phone">
                  <el-input v-model="form.phone" placeholder="请输入手机" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="30">
              <el-col :span="12">
                <el-form-item label="固定电话" prop="telephone">
                  <el-input v-model="form.telephone" placeholder="请输入固定电话" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="关怀类型" prop="concernType">
                  <el-select v-model="form.concernType" placeholder="请选择" style="width: 100%">
                    <el-option v-for="item in careTypeOptions" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="30">
              <el-col :span="12">
                <el-form-item label="金额" prop="amount">
                  <el-input v-model="form.amount" placeholder="1" type="number" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="需求时间" prop="requirementDate">
                  <el-date-picker v-model="form.requirementDate" type="datetime" placeholder="请选择" style="width: 100%" value-format="YYYY-MM-DD HH:mm:ss" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="30">
              <el-col :span="12">
                <el-form-item label="附件" prop="fileNo">
                  <fileUpload v-model="form.fileNo" :limit="5" :fileSize="10" :isShowTip="false" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <div class="dialog-section no-border no-margin">
            <el-form-item label="礼品描述" prop="giftDesc">
              <el-input v-model="form.giftDesc" type="textarea" :rows="4" placeholder="请输入内容" />
            </el-form-item>
            <el-form-item label="关怀理由" prop="concernArgument">
              <el-input v-model="form.concernArgument" type="textarea" :rows="4" placeholder="请输入内容" />
            </el-form-item>
          </div>
        </el-form>
      </div>
      <template #footer>
        <div style="flex: auto; text-align: right; padding-right: 20px; padding-bottom: 20px;">
          <el-button type="primary" @click="submitForm">确认</el-button>
          <el-button @click="open = false">取消</el-button>
        </div>
      </template>
    </el-drawer>

    <!-- 详情抽屉 -->
    <el-drawer v-model="detailOpen" direction="rtl" size="80%" destroy-on-close :with-header="false" class="detail-drawer">
      <div class="detail-container">
        <div class="detail-header">
          <span class="detail-header-title">客户关怀详情</span>
          <el-icon class="detail-close-btn" @click="detailOpen = false"><Close /></el-icon>
        </div>
        <div class="detail-body">
          <div class="detail-main">
            <div class="detail-info-content">
              <div class="detail-edit-bar">
                <el-button type="primary" size="small" icon="Edit" @click="handleEditFromDetail">编辑</el-button>
              </div>

              <div class="detail-section">
                <div class="detail-section-title">基本信息</div>
                <div class="detail-grid">
                  <div class="detail-field">
                    <span class="field-label">单据编号</span>
                    <span class="field-value id-text">{{ detailData.receiptId }}</span>
                  </div>
                  <div class="detail-field">
                    <span class="field-label">客户名称</span>
                    <span class="field-value">{{ detailData.customerName }}</span>
                  </div>
                  <div class="detail-field">
                    <span class="field-label">行业</span>
                    <span class="field-value">{{ detailData.profession }}</span>
                  </div>
                  <div class="detail-field">
                    <span class="field-label">部门</span>
                    <span class="field-value">{{ detailData.department }}</span>
                  </div>
                  <div class="detail-field">
                    <span class="field-label">销售员</span>
                    <span class="field-value">{{ detailData.salesman }}</span>
                  </div>
                  <div class="detail-field">
                    <span class="field-label">人员编号</span>
                    <span class="field-value">{{ detailData.personnelNumber }}</span>
                  </div>
                  <div class="detail-field">
                    <span class="field-label">联系人</span>
                    <span class="field-value">{{ detailData.contactPerson }}</span>
                  </div>
                  <div class="detail-field">
                    <span class="field-label">电话</span>
                    <span class="field-value">{{ detailData.phone }}</span>
                  </div>
                  <div class="detail-field">
                    <span class="field-label">固定电话</span>
                    <span class="field-value">{{ detailData.telephone }}</span>
                  </div>
                  <div class="detail-field">
                    <span class="field-label">关怀类型</span>
                    <span class="field-value">{{ careTypeText(detailData.concernType) }}</span>
                  </div>
                  <div class="detail-field">
                    <span class="field-label">金额</span>
                    <span class="field-value">{{ detailData.amount }}</span>
                  </div>
                  <div class="detail-field">
                    <span class="field-label">需求日期</span>
                    <span class="field-value">{{ parseTime(detailData.requirementDate) }}</span>
                  </div>
                  <div class="detail-field full-width">
                    <span class="field-label">附件</span>
                    <span class="field-value">
                      <fileUpload v-model="detailData.fileNo" :disabled="true" />
                    </span>
                  </div>
                  <div class="detail-field">
                    <span class="field-label">审核状态</span>
                    <span class="field-value">{{ statusText(detailData.auditStatus) }}</span>
                  </div>
                  <div class="detail-field">
                    <span class="field-label">审核日期</span>
                    <span class="field-value">{{ parseTime(detailData.auditDate) }}</span>
                  </div>
                </div>
              </div>

              <div class="detail-section">
                <div class="detail-section-title">礼品描述</div>
                <div class="detail-text-block">{{ detailData.giftDesc || '' }}</div>
              </div>

              <div class="detail-section">
                <div class="detail-section-title">关注论据</div>
                <div class="detail-text-block">{{ detailData.concernArgument || '' }}</div>
              </div>
            </div>
          </div>

          <div class="detail-sidebar">
            <div class="sidebar-title">管理信息</div>
            <div class="sidebar-item">
              <span class="sidebar-label">创建时间</span>
              <span class="sidebar-value">{{ detailData.createTime }}</span>
            </div>
            <div class="sidebar-item">
              <span class="sidebar-label">创建人</span>
              <span class="sidebar-value">{{ detailData.createUserId }}</span>
            </div>
            <div class="sidebar-item">
              <span class="sidebar-label">修改时间</span>
              <span class="sidebar-value">{{ detailData.updateTime }}</span>
            </div>
            <div class="sidebar-item">
              <span class="sidebar-label">最后修改人</span>
              <span class="sidebar-value">{{ detailData.updateUserId }}</span>
            </div>
          </div>
        </div>
      </div>
    </el-drawer>
  </div>
</template>

<script setup name="CustomerCare">
import { ref, reactive, onMounted, getCurrentInstance } from 'vue';
import { Close } from '@element-plus/icons-vue';
import { listCare, getCare, delCare, addCare, updateCare } from "@/api/customer/crmCare";
import { listDictByType } from "@/api/customer/customerDict";
import { listCustomerInfo, getCustomerInfo } from "@/api/customer/customerInfo/";
import { listContact } from "@/api/customer/crmContact";

const { proxy } = getCurrentInstance();

const loading = ref(false);
const selectLoading = ref(false);
const contactSearchLoading = ref(false);
const total = ref(0);
const dataList = ref([]);
const open = ref(false);
const drawerTitle = ref("新建客户关怀");
const careTypeOptions = ref([]);
const contactOptions = ref([]);
const filterContactOptions = ref([]);
const customerOptions = ref([]);
const activeTab = ref('mine');

const detailOpen = ref(false);
const detailData = ref({});
const auditStatusOptions = [
  { label: '待审核', value: 0 },
  { label: '已通过', value: 1 },
  { label: '已驳回', value: 2 }
];

const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  customerName: undefined,
  receiptId: undefined,
  contactPerson: undefined,
  concernType: undefined,
  auditStatus: undefined,
  scope: 'mine'
});

const initFormData = () => ({
  id: undefined,
  receiptId: '',
  customerId: undefined,
  customerName: '',
  profession: '',
  department: '',
  salesman: '',
  personnelNumber: '',
  contactPerson: '',
  phone: '',
  telephone: '',
  concernType: '',
  amount: 1,
  requirementDate: undefined,
  fileNo: '',
  giftDesc: '',
  concernArgument: '',
  auditStatus: 0,
  platformCode: ''
});

const form = reactive(initFormData());

const rules = reactive({
  customerName: [{ required: true, message: "客户名称不能为空", trigger: "change" }],
  contactPerson: [{ required: true, message: "联系人不能为空", trigger: "change" }],
  phone: [{ required: true, message: "手机不能为空", trigger: "blur" }],
  telephone: [{ required: true, message: "固定电话不能为空", trigger: "blur" }],
  concernType: [{ required: true, message: "关怀类型不能为空", trigger: "change" }],
  amount: [{ required: true, message: "金额不能为空", trigger: "blur" }],
  giftDesc: [{ required: true, message: "礼品描述不能为空", trigger: "blur" }],
  concernArgument: [{ required: true, message: "关怀理由不能为空", trigger: "blur" }]
});

const careTypeText = (val) => {
  const obj = careTypeOptions.value.find(item => item.dictValue === val);
  return obj ? obj.dictLabel : val;
};

const statusText = (status) => {
  const map = { 0: '待审核', 1: '已通过', 2: '已驳回' };
  return map[status] || '未知';
};
const statusTag = (status) => {
  const map = { 0: 'warning', 1: 'success', 2: 'danger' };
  return map[status] || '';
};
const careTypeTag = (val) => {
  const map = { '1': 'success', '2': '', '3': 'info', '4': 'warning', '5': 'danger' };
  return map[val] || 'info';
};

const switchTab = (tab) => {
  activeTab.value = tab;
  queryParams.scope = tab;
  handleQuery();
};

const getList = () => {
  loading.value = true;
  listCare(queryParams).then(response => {
    dataList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
};

/** 远程搜索所有联系人（查询栏使用） */
const remoteLoadAllContacts = (query) => {
  contactSearchLoading.value = true;
  listContact({ contactName: query || undefined, pageSize: 20 }).then(res => {
    filterContactOptions.value = (res.rows || []).map(item => ({
      label: item.contactName,
      value: item.id
    }));
    contactSearchLoading.value = false;
  }).catch(() => {
    contactSearchLoading.value = false;
  });
};

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

const resetQuery = () => {
  proxy.resetForm("queryRef");
  queryParams.scope = activeTab.value;
  handleQuery();
};

/** 远程加载客户列表 */
const remoteLoadCustomers = (query) => {
  selectLoading.value = true;
  listCustomerInfo({ customerName: query || undefined, pageSize: 20 }).then(res => {
    customerOptions.value = (res.rows || []).map(item => ({
      label: item.customerName,
      value: item.customerName,
      id: item.id,
      ...item
    }));
    selectLoading.value = false;
  }).catch(() => {
    selectLoading.value = false;
  });
};

/** 客户选中处理 */
const handleCustomerChange = async (val) => {
  const customer = customerOptions.value.find(item => item.label === val);
  if (customer) {
    form.customerId = customer.id;
    // 重置联系人相关字段
    form.contactPerson = '';
    form.phone = '';
    form.telephone = '';
    
    try {
      // 获取客户详细信息，填充行业、业务员、部门等信息
      const res = await getCustomerInfo(customer.id);
      const detail = res.data;
      if (detail) {
        form.profession = detail.industryCategory || '';
        if (detail.customerSalesInfoVo) {
          form.salesman = detail.customerSalesInfoVo.salesPerson || '';
          form.department = detail.customerSalesInfoVo.belongingDepartment || '';
        }
      }
    } catch (error) {
      console.error("加载客户详情失败", error);
    }
    // 直接查询 customer_contact 表获取联系人列表
    remoteSearchContacts('');
  } else {
    form.customerId = undefined;
    form.profession = '';
    form.salesman = '';
    form.department = '';
    form.contactPerson = '';
    form.phone = '';
    form.telephone = '';
    contactOptions.value = [];
  }
};

/** 远程搜索联系人（表单下拉使用，直接查询 customer_contact 表） */
const remoteSearchContacts = (query) => {
  contactSearchLoading.value = true;
  const params = { pageSize: 50 };
  if (form.customerId) {
    // 已选客户：只搜索该客户下的联系人
    params.customerId = form.customerId;
  }
  if (query) {
    params.contactName = query;
  }
  listContact(params).then(res => {
    contactOptions.value = (res.rows || []).map(item => ({
      label: item.contactName,
      value: item.contactName,
      id: item.id,
      ...item
    }));
  }).finally(() => {
    contactSearchLoading.value = false;
  });
};

/** 联系人下拉聚焦时加载数据 */
const onContactFocus = () => {
  if (contactOptions.value.length === 0) {
    remoteSearchContacts('');
  }
};

/** 联系人选中处理 */
const handleContactChange = (val) => {
  if (!val) {
    form.phone = '';
    form.telephone = '';
    return;
  }
  const contact = contactOptions.value.find(item => item.label === val);
  if (contact) {
    form.phone = contact.phone || '';
    form.telephone = contact.officePhone || '';
  } else {
    form.phone = '';
    form.telephone = '';
  }
};

const handleAdd = () => {
  resetForm();
  drawerTitle.value = "新建客户关怀";
  customerOptions.value = [];
  // 预加载前20个客户
  listCustomerInfo({ pageSize: 20 }).then(res => {
    customerOptions.value = (res.rows || []).map(item => ({
      label: item.customerName,
      value: item.customerName,
      id: item.id,
      ...item
    }));
  });
  open.value = true;
};

const handleDetail = (row) => {
  getCare(row.id).then(response => {
    detailData.value = response.data;
    detailOpen.value = true;
  });
};

const handleEditFromDetail = () => {
  detailOpen.value = false;
  const oldData = { ...detailData.value };
  resetForm();
  Object.assign(form, oldData);
  drawerTitle.value = "修改客户关怀";
  
  // 确保下拉框有当前客户
  customerOptions.value = [{
    label: form.customerName,
    value: form.customerName,
    id: form.customerId,
    industryName: form.profession,
    salesmanName: form.salesman,
    deptName: form.department
  }];
  
  open.value = true;
  if (form.customerId) {
    remoteSearchContacts('');
  }
};

const handleDelete = (row) => {
  proxy.$modal.confirm(`确认删除单据编号为"${row.receiptId}"的关怀记录吗？`).then(() => {
    return delCare(row.id);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
};

const resetForm = () => {
  Object.assign(form, initFormData());
  contactOptions.value = [];
  customerOptions.value = [];
  if (proxy.$refs.formRef) {
    proxy.resetForm("formRef");
  }
};

const submitForm = () => {
  proxy.$refs["formRef"].validate(valid => {
    if (valid) {
      if (form.id != null) {
        updateCare(form).then(() => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addCare(form).then(() => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
};

/** 加载关怀类型字典 */
const loadCareTypes = () => {
  listDictByType('care_type').then(res => {
    careTypeOptions.value = res.data || [];
  });
};

onMounted(() => {
  getList();
  loadCareTypes();
  remoteLoadAllContacts('');
});
</script>

<style scoped lang="scss">
.app-container {
  padding: 20px;
  background-color: #fff;
  min-height: 100vh;
}

.search-card {
  border: none;
  background-color: #fff;
  margin-bottom: 5px;
  :deep(.el-card__body) { padding: 10px 0 20px 0; }
  :deep(.el-form) {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
  }
}

.custom-form-item, .btns-item {
  margin-bottom: 12px !important;
  margin-right: 12px;
  display: flex !important;
  align-items: center;
  :deep(.el-form-item__label) {
    color: #333; font-weight: 400; white-space: nowrap;
    line-height: 36px; height: 36px; padding-right: 8px;
  }
}

.custom-form-item {
  :deep(.el-input__wrapper), :deep(.el-select__wrapper) {
    background-color: #fff;
    box-shadow: 0 0 0 1px #cbd5e1 inset !important;
    border-radius: 4px; height: 36px !important; line-height: 36px;
  }
}

.btns-item {
  margin-left: 5px;
  :deep(.el-form-item__content) { height: 36px; display: flex; align-items: center; }
}

.search-btns-group {
  display: flex; gap: 10px; align-items: center;
  .el-button { height: 36px !important; padding: 0 15px; vertical-align: middle; }
  .btn-search, .btn-reset {
    background-color: #fff; border: 1px solid #dcdfe6; color: #606266;
    &:hover { color: #409eff; border-color: #c6e2ff; background-color: #ecf5ff; }
  }
  .btn-plus { width: 90px; background-color: #409eff; border-color: #409eff; color: #fff; font-weight: bold; }
}

.title-container {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 15px 0 10px 0;
  margin-bottom: 5px;
  gap: 20px;
}

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

.page-title {
  font-size: 14px;
  font-weight: bold;
  color: #333;
}

.tabs-group {
  display: flex;
  gap: 0;
  .tab-btn {
    padding: 7px 16px; font-size: 13px; color: #606266; cursor: pointer;
    border: 1px solid #dcdfe6; background: #fff;
    &:first-child { border-radius: 4px 0 0 4px; }
    &:last-child { border-radius: 0 4px 4px 0; }
    &:not(:first-child) { margin-left: -1px; }
    &.active { border: 1px solid #409eff; color: #409eff; background-color: #ecf5ff; z-index: 1; position: relative; }
    &:hover { color: #409eff; }
  }
}

.table-card { border: none; :deep(.el-card__body) { padding: 0; } }
.custom-table { :deep(th.el-table__cell) { background-color: #f8fafc !important; } }
.link-text { color: #ff8c42; font-weight: 500; cursor: pointer; }

.dialog-section {
  padding-bottom: 20px; margin-bottom: 20px; border-bottom: 1px solid #f1f5f9;
  &.no-border { border-bottom: none; }
  &.no-margin { margin-bottom: 0; padding-bottom: 0; }
  .section-title {
    font-size: 14px; font-weight: bold; color: #334155;
    margin-bottom: 20px; padding-left: 10px; border-left: 4px solid #3b82f6;
  }
}

.drawer-body { padding: 0 40px; }

/* ====== 详情抽屉样式 ====== */
.detail-container { display: flex; flex-direction: column; height: 100%; }
.detail-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid #e2e8f0;
  .detail-header-title { font-size: 16px; font-weight: 600; color: #1e293b; }
  .detail-close-btn { font-size: 20px; color: #94a3b8; cursor: pointer; &:hover { color: #475569; } }
}

.detail-body { display: flex; flex: 1; overflow: hidden; }
.detail-main { flex: 1; overflow-y: auto; }
.detail-info-content { padding: 20px 24px; }
.detail-edit-bar { display: flex; justify-content: flex-end; margin-bottom: 16px; }

.detail-section {
  margin-bottom: 24px;
  .detail-section-title {
    font-size: 14px; font-weight: bold; color: #334155;
    margin-bottom: 16px; padding-left: 10px; border-left: 4px solid #3b82f6;
  }
}

.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.detail-field {
  display: flex; align-items: flex-start; padding: 10px 0;
  .field-label { min-width: 80px; color: #94a3b8; font-size: 13px; flex-shrink: 0; }
  .field-value { color: #1e293b; font-size: 13px; word-break: break-all; &.id-text { color: #3b82f6; } }
}

.detail-text-block { color: #64748b; font-size: 13px; line-height: 1.8; min-height: 20px; }

.detail-sidebar {
  width: 300px; flex-shrink: 0; border-left: 1px solid #e2e8f0;
  padding: 20px; background-color: #fafbfc; overflow-y: auto;
  .sidebar-title { font-size: 14px; font-weight: 600; color: #ef4444; margin-bottom: 20px; }
  .sidebar-item {
    display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px;
    .sidebar-label { color: #94a3b8; font-size: 13px; min-width: 70px; }
    .sidebar-value { color: #1e293b; font-size: 13px; text-align: right; white-space: nowrap; }
  }
}

:deep(.detail-drawer .el-drawer__header) { display: none; }
</style>
