<template>
   <div class="app-container">
      <div class="user-container">
        <!-- 搜索区域 -->
        <el-form :model="queryParams" ref="queryRef" class="search-area" inline>
          <el-form-item label="姓名" prop="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入驾驶员姓名"
              clearable
              prefix-icon="Search"
              class="search-input"
              @keyup.enter="handleQuery"
              @clear="resetQuery"
            />
          </el-form-item>
          
          <!-- 账号状态筛选 -->
          <el-form-item label="账号状态" prop="status">
            <el-select v-model="queryParams.status" placeholder="账号状态" clearable class="search-select" @change="handleQuery">
              <el-option label="全部" value="" />
              <el-option
                v-for="dict in sys_normal_disable"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          
          <div class="search-buttons">
            <el-button type="primary" class="search-btn" @click="handleQuery">搜索</el-button>
            <el-button class="reset-btn" @click="resetQuery">重置</el-button>
          </div>
          
          <div class="action-buttons">
            <el-button type="primary" class="search-btn" @click="handleAdd">新增</el-button>
            <!-- <el-button class="reset-btn" plain @click="handleImport">导入</el-button> -->
            <el-button class="reset-btn" plain @click="handleExport">导出</el-button>
            <el-button class="export-btn" type="info" :disabled="multiple" @click="handleDelete">删除</el-button>
          </div>
        </el-form>

        <!-- 驾驶员表格 -->
        <el-table
          v-loading="loading"
          :data="driverList"
          @selection-change="handleSelectionChange"
          style="width: 100%"
          class="custom-table"
          :header-cell-style="{ backgroundColor: '#343744', color: '#fff' }"
          :bg-color="'#292C38'"
        >
          <el-table-column type="selection" width="50" align="left" />
          <el-table-column label="序号" width="60" align="left">
            <template #default="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120" align="left">
            <template #default="scope">
              <el-button link text @click="handleUpdate(scope.row)">编辑</el-button>
              <el-button link text type="primary" @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
          <el-table-column label="人像" prop="avatar" align="left" >
            <template #default="scope"> 
              <div class="avatar-box">
                <img :src="scope.row.avatar" alt="" />
              </div>
            </template>

          </el-table-column>
          <el-table-column label="姓名" prop="userName" align="left" />
         
          <el-table-column label="驾照类型" prop="licenseType" align="left" />
          <el-table-column label="账号状态" align="left">
            <template #default="scope">
                {{ scope.row.status === '0' ? '正常' : '停用' }}
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="left" prop="createTime" width="160">
            <template #default="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </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"
        />
      </div>

      <!-- 添加或修改驾驶员对话框 -->
      <el-dialog :title="title" v-model="open" width="600px" append-to-body>
        <el-form :model="form" :rules="rules" ref="driverRef" label-width="100px">
          <el-row>
            <el-col :span="24">
              <el-form-item label="姓名" prop="userName">
                <el-select 
                  v-model="form.userId" 
                  placeholder="请选择驾驶员姓名"
                  :disabled="isEdit"
                  class="full-width-select"
                  @change="handleUserChange"
                >
                  <el-option 
                    v-for="user in userOptions" 
                    :key="user.userId" 
                    :label="user.userName" 
                    :value="user.userId" 
                  />
                </el-select>
              </el-form-item>
            </el-col>
           
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="驾驶证类型" prop="licenseType">
                 <el-input 
                  v-model="form.licenseType" 
                  placeholder="请输入驾驶证类型" 
                />
              </el-form-item>
            </el-col>
          </el-row>
          
          <!-- <el-row>
            <el-col :span="24">
              <el-form-item label="人像">
                <div class="avatar-uploader-box">
                  <div v-if="form.avatar" class="avatar-preview">
                    <img :src="form.avatar" class="avatar" />
                    <div class="avatar-count">1/1</div>
                    <div class="avatar-replace" @click.stop="handleRemoveAvatar" v-if="!isEdit">
                      <el-icon><Close /></el-icon>
                    </div>
                  </div>
                  <el-upload
                    v-else
                    class="avatar-uploader"
                    :show-file-list="false"
                    :action="upload.avatarUrl"
                    :headers="upload.headers"
                    :before-upload="beforeAvatarUpload"
                    :on-success="handleAvatarSuccess"
                    :disabled="isEdit"
                  >
                    <div class="avatar-upload-placeholder">
                      <el-icon class="avatar-uploader-icon"><Plus /></el-icon>
                      <div class="avatar-count">0/1</div>
                    </div>
                  </el-upload>
                </div>
              </el-form-item>
            </el-col>
          </el-row> -->
         
        </el-form>
        <template #footer>
          <div class="dialog-footer">
            <el-button class="export-btn" @click="cancel">取 消</el-button>
            <el-button class="search-btn" type="primary" @click="submitForm">确 定</el-button>
          </div>
        </template>
      </el-dialog>

      <!-- 驾驶员导入对话框 -->
      <el-dialog :title="upload.title" v-model="upload.open" width="500px" append-to-body class="import-dialog">
        <div class="import-title">选择需要导入的项目文件</div>
        <el-upload
          ref="uploadRef"
          :limit="1"
          accept=".xlsx, .xls"
          :headers="upload.headers"
          :action="upload.url + '?updateSupport=' + upload.updateSupport"
          :disabled="upload.isUploading"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :auto-upload="false"
          drag
          class="import-upload"
        >
          <div class="upload-content">
            <el-icon class="upload-icon"><upload-filled /></el-icon>
            <div class="upload-text">拖拽文件到这里，或</div>
            <div class="upload-link">
              <el-icon class="upload-icon-small" style="color: #347AE2"><upload-filled /></el-icon>
              <span class="click-upload">点此添加</span>
            </div>
          </div>
        </el-upload>
        <div class="import-footer">
          <div class="footer-left">
            <el-checkbox v-model="upload.updateSupport">是否更新已经存在的驾驶员数据</el-checkbox>
          </div>
          <div class="footer-right">
            <span class="file-format">仅允许导入xls、xlsx格式文件。</span>
            <el-link type="primary" :underline="false" class="download-link" @click="importTemplate">下载模板</el-link>
          </div>
        </div>
        <template #footer>
          <div class="dialog-footer">
            <el-button class="export-btn" @click="upload.open = false">取 消</el-button>
            <el-button class="search-btn" type="primary" @click="submitFileForm">确 定</el-button>
          </div>
        </template>
      </el-dialog>
   </div>
</template>

<script setup name="Driver">
import { getToken } from "@/utils/auth";
import { parseTime } from "@/utils/ruoyi";
import { listRole } from "@/api/system/role";
// import { getInitPassword } from "@/utils/auth";
import { listUser } from "@/api/system/user";
import { getRoleUsers } from "@/api/system/role";
import { 
  listDriver_info, 
  getDriver_info, 
  addDriver_info, 
  updateDriver_info, 
  delDriver_info, 

} from "@/api/system/driver_info.js"; //  uploadAvatar 
import { Plus, Delete, UploadFilled, Close } from '@element-plus/icons-vue';

const { proxy } = getCurrentInstance();
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");

const driverList = ref([]);
const open = ref(false);
const loading = ref(false);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const roleOptions = ref([]);
const userOptions = ref([]);
const isEdit = ref(false);
const selectedUser = ref(null);
const allUserOptions = ref([]);
const registeredUserIds = ref([]);

// 驾驶员导入参数
const upload = reactive({
  open: false,
  title: "",
  isUploading: false,
  updateSupport: 0,
  headers: { Authorization: "Bearer " + getToken() },
  url: window.APP_CONFIG?.VITE_BASE_URL + "/system/driver_info/importData",
  avatarUrl: window.APP_CONFIG?.VITE_BASE_URL + "/system/driver_info/avatar"
});

const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  userName: undefined,
  status: undefined,
  userId: undefined
});

const form = ref({});

const rules = ref({
  // 仅对 licenseType 做内置校验，其余在提交时兜底检查
  licenseType: [
    { required: true, message: "驾照类型不能为空", trigger: "blur" }
  ]
});

/** 处理用户选择变更 */
function handleUserChange(value) {
  const source = isEdit.value ? allUserOptions.value : userOptions.value;
  const user = source.find(u => u.userId === value);
  if (user) {
    form.value.userId = user.userId;
    form.value.userName = user.userName;
    form.value.avatar = user.avatar;
  } else {
    form.value.userId = undefined;
    form.value.userName = undefined;
    form.value.avatar = undefined;
  }
}

/** 查询驾驶员列表 */
function getList() {
  loading.value = true;
  listDriver_info(queryParams.value).then(res => {
    const rows = res.rows || [];
    // 兼容后端未按姓名过滤的情况，前端兜底过滤
    const name = typeof queryParams.value.userName === 'string' ? queryParams.value.userName.trim() : undefined;
    if (name) {
      driverList.value = rows.filter(item => (item.userName || '').includes(name));
      total.value = driverList.value.length;
    } else {
      driverList.value = rows;
      total.value = res.total || rows.length;
    }
    loading.value = false;
  }).catch(() => {
    loading.value = false;
    driverList.value = [];
    total.value = 0;
  });
}
// getUserOptions();
/** 获取用户列表 */
function getUserOptions() {
  return Promise.all([
    getRoleUsers(3),
    listDriver_info({ pageNum: 1, pageSize: 9999 })
  ]).then(([userRes, driverRes]) => {
    allUserOptions.value = (userRes.rows || []);
    const rows = driverRes.rows || [];
    registeredUserIds.value = rows.map(item => item.userId).filter(v => v !== undefined);
    if (isEdit.value) {
      userOptions.value = allUserOptions.value;
    } else {
      userOptions.value = allUserOptions.value.filter(u => !registeredUserIds.value.includes(u.userId));
    }
  }).catch(() => {
    userOptions.value = [];
    allUserOptions.value = [];
    registeredUserIds.value = [];
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  // 规范姓名与状态参数，避免空格或空字符串导致查询失效
  if (typeof queryParams.value.userName === 'string') {
    const name = queryParams.value.userName.trim();
    queryParams.value.userName = name || undefined;
  }
  if (queryParams.value.status === '') {
    queryParams.value.status = undefined;
  }
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  // 手动清理关键查询字段，确保彻底重置
  queryParams.value.userName = undefined;
  queryParams.value.status = undefined;
  queryParams.value.pageNum = 1;
  getList();
}

/** 选择条数 */
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.userId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 删除按钮操作 */
function handleDelete(row) {
  const userId = row.userId || ids.value;
  proxy.$modal.confirm('确定删除此驾驶员吗?', '删除').then(function() {
    return delDriver_info(userId);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
    getUserOptions();
  }).catch(() => {});
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  isEdit.value = false;
  selectedUser.value = null;
  title.value = "添加驾驶员信息";
  getUserOptions().then(() => {
    open.value = true;
  });
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  isEdit.value = true;
  const userId = row.userId || ids.value[0];
  getUserOptions().then(() => {
    getDriver_info(userId).then(response => {
      form.value = response.data || {};
      form.value.driverId = form.value.driverId || form.value.userId;
      if (form.value.userId) {
        selectedUser.value = userOptions.value.find(user => user.userId === form.value.userId) || null;
        if (!selectedUser.value) {
          userOptions.value = [
            ...userOptions.value,
            {
              userId: form.value.userId,
              userName: form.value.userName,
              avatar: form.value.avatar
            }
          ];
        }
      }
      open.value = true;
      title.value = "修改驾驶员";
    });
  });
}

/** 重置表单 */
function reset() {
  form.value = {
    userId: undefined,
    userName: undefined,
    licenseType: undefined,
    avatar: undefined,
    driverId: undefined // 确保重置driverId
  };
  selectedUser.value = null;
  proxy.resetForm("driverRef");
}

/** 提交表单 */
function submitForm() {
  proxy.$refs["driverRef"].validate(valid => {
    if (valid) {
      // 前置必填拦截
      if (!form.value.userId) {
        proxy.$modal.msgError("请选择驾驶员姓名");
        return;
      }
      const licenseTypeVal = typeof form.value.licenseType === 'string'
        ? form.value.licenseType.trim()
        : form.value.licenseType;
      if (!licenseTypeVal) {
        proxy.$modal.msgError("驾照类型不能为空");
        return;
      }

      // 白名单化载荷，仅提交后端所需字段，避免未知字段解析错误
      const payload = {
        userId: form.value.userId,
        licenseType: licenseTypeVal
      };
      if (form.value.avatar) payload.avatar = form.value.avatar;

      if (form.value.driverId) {
        // 修改操作
        updateDriver_info(payload).then(() => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        }).catch(error => {
          console.error("更新失败:", error);
          proxy.$modal.msgError("修改失败: " + (error.message || "未知错误"));
        });
      } else {
        // 新增操作
        addDriver_info(payload).then(() => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
          getUserOptions();
        }).catch(error => {
          console.error("新增失败:", error);
          proxy.$modal.msgError("新增失败: " + (error.message || "未知错误"));
        });
      }
    }
  });
}

/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download("system/driver_info/export", {
    ...queryParams.value,
    pageNum: undefined,
    pageSize: undefined
  }, `驾驶员数据_${new Date().getTime()}.xlsx`);
}

/** 导入按钮操作 */
function handleImport() {
  upload.title = "驾驶员导入";
  upload.open = true;
}

/** 导入对话框关闭时清除数据 */
function handleFileUploadProgress(event, file, fileList) {
  upload.isUploading = true;
}

/** 导入成功处理 */
function handleFileSuccess(response, file, fileList) {
  upload.open = false;
  upload.isUploading = false;
  proxy.$refs["uploadRef"].clearFiles();
  proxy.$modal.msgSuccess(response.msg);
  getList();
}

/** 下载导入模板 */
function importTemplate() {
  proxy.download("system/driver_info/importTemplate", {}, `driver_template_${new Date().getTime()}.xlsx`);
}

/** 提交上传文件 */
function submitFileForm() {
  proxy.$refs["uploadRef"].submit();
}

/** 头像上传前处理 */
function beforeAvatarUpload(file) {
  const isJPG = file.type === 'image/jpeg' || file.type === 'image/png';
  const isLt2M = file.size / 1024 / 1024 < 2;

  if (!isJPG) {
    proxy.$modal.msgError('上传头像图片只能是JPG或PNG格式!');
    return false;
  }
  if (!isLt2M) {
    proxy.$modal.msgError('上传头像图片大小不能超过2MB!');
    return false;
  }
  return true;
}

/** 头像上传成功处理 */
function handleAvatarSuccess(res, file) {
  if (res.code === 200) {
    form.value.avatar = res.data.url;
    proxy.$modal.msgSuccess("上传成功");
  } else {
    proxy.$modal.msgError(res.msg || "上传失败");
  }
}

/** 移除头像 */
function handleRemoveAvatar() {
  form.value.avatar = undefined;
}

// 获取角色下拉列表
function getRoleOptions() {
  listRole().then(res => {
    roleOptions.value = res.rows || [];
  });
}

onMounted(() => {
  getList();
  getRoleOptions();
  getUserOptions();
});
</script>

<style lang="scss" scoped>
.app-container {
  padding: 20px;
  background-color: #292C38;
  color: #ffffff;
  min-height: 100%;
  border-radius: 10px;
}

.user-container {
  background-color: #292c38;
  border-radius: 4px;
  height: calc(100vh - 180px);
  // overflow-y: auto;
}

.search-area {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  
  .search-input {
    width: 250px;
    margin-right: 10px;
  }
  
  .search-select {
    width: 150px;
    margin-right: 10px;
  }
  
  .search-buttons {
    margin-right: 20px;
    display: flex;
    gap: 10px;
  }
  
  .action-buttons {
    margin-left: auto;
    display: flex;
  }
}

// 输入框 下拉框 搜索栏
:deep(.el-input__wrapper:hover) {
  box-shadow: none !important;
}

:deep(.el-select) {
  border:none !important;
  width:140px !important;
  // 修改el-select的输入框的border 
  --el-border-color-hover: #343744!important;
  --el-border-color: #343744!important;
}

:deep(.el-select__wrapper.is-focused) {
  box-shadow: none !important;
}

:deep(.el-select__wrapper) {
  background: #343744 !important;
  color: #96A0B5 !important;
  border-radius: 8px !important;
  height: 36px !important;
  width: 140px;
  font-size: 15px;
  border: none !important;
  border:none !important;
}

:deep(.el-input__wrapper) {
  background: #343744 !important;
  color: #96A0B5 !important;
  border-radius: 8px !important;
  height: 36px !important;
  border: none !important;
  box-shadow: none !important;
}

:deep(.el-select__placeholder) {
  color: #96A0B5 !important;
}
.custom-table {
  background-color: #292c38 !important;
  color: #ffffff;
  margin-bottom: 20px;
  border-radius: 4px;
  overflow: hidden;
  
  // 防止表格闪白
  :deep(.el-loading-mask) {
    background-color: rgba(41, 44, 56, 0.7) !important;
  }
  
  :deep(.el-table__empty-block) {
    background-color: #292c38 !important;
  }
  
  :deep(.el-table__empty-text) {
    color: #96A0B5 !important;
  }
  
  // 确保整个表格区域背景色
  :deep(.el-table) {
    background-color: #292c38 !important;
  }
  
  :deep(.el-table__body) {
    background-color: #292c38 !important;
  }
  
  .avatar-box{
    width: 50px;
    height: 50px;
    border-radius: 6px;

   
  }
  .avatar-box  img{
      width: 100%;
      height: 100%;
      object-fit: cover;
      border-radius: 6px;

    }
  :deep(.el-table__inner-wrapper::before) {
    display: none; /* 隐藏表格顶部的边框线 */
  }
  
  :deep(.el-table__header) {
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    overflow: hidden;
  }
  
  :deep(.el-table__header-wrapper) {
    th {
      background-color: #343744 !important;
      color: #96A0B5!important;
      font-weight: normal;
      border-bottom: none; /* 移除th底部边线 */
    }
    
    tr th.el-table__cell:first-child {
      border-top-left-radius: 6px;
      
      .cell {
        border-top-left-radius: 6px;
      }
    }
    
    tr th.el-table__cell:last-child {
      border-top-right-radius: 4px;
      
      .cell {
        border-top-right-radius: 4px;
      }
    }
    
    .el-table__header th.el-table__cell {
      background-color: #343744 !important;
      color: #96A0B5;
    }
    
    tr {
      background-color: #343744 !important;
    }
  }
  
  :deep(.el-table__body-wrapper) {
   
    td {
      height: 68px!important;
      background-color: #292c38;
      color: #ffffff;
      border-bottom: 1px solid #4C4F5F;
    }
  }
  
  :deep(.el-table__body tr:hover > td) {
    background: #2B3B5A!important; 
    
  }
  
  :deep(.el-button--link) {
    border: none;
    background: transparent;
    color: #347AE2;
    padding: 0;
    margin: 0 5px;
  }
  
  :deep(.el-button.is-text) {
    background-color: transparent !important;
    border-color: transparent;
    color: #347AE2;
    
    &:hover, &:focus, &:active {
      background-color: transparent !important;
      color: #347AE2;
    }
  }
  
  :deep(.el-button.el-button--primary.is-text) {
    background-color: transparent !important;
    color: #347AE2;
    
    &:hover {
      background-color: transparent !important;
      color: #347AE2;
    }
  }
  
  :deep(.el-table__body tr:hover .el-button--link.is-text) {
    background-color: transparent !important;
    color: #347AE2;
  }
}

.status-normal {
  color: #67c23a;
}

.status-disabled {
  color: #e6a23c;
}

:deep(.el-input__wrapper) {
  background-color: #292c38;
  box-shadow: 0 0 0 1px #565C70 inset !important;
  
  .el-input__inner {
    color: #ffffff;
  }
}

:deep(.el-input__count) {
  background: transparent !important;
  color: #C0C4CC !important;
  
  .el-input__count-inner {
    background: transparent !important;
    color: #C0C4CC !important;
  }
}

:deep(.el-radio__label) {
  color: #C8C9CC;
}

:deep(.el-radio.is-checked .el-radio__label) {
  color: #409EFF;
}

:deep(.el-button) {
  background-color: #292c38;
  border-color: #4c4f5f;
  color: #ffffff;
  
  &.el-button--primary {
    background-color: #409eff;
    border-color: #409eff;
  }
}

:deep(.el-select) {
  .el-input__wrapper {
    background-color: #292c38;
    box-shadow: 0 0 0 1px #565C70 inset !important;
  }
}

// 弹窗样式优化
:deep(.el-dialog) {
  .el-form-item__label {
    color: #96A0B5 !important;
  }
  .el-radio__label {
    color: #C8C9CC !important;
  }
  
  .el-radio.is-checked .el-radio__label {
    color: #409EFF !important;
  }
}

// 保留搜索区域的样式
.search-area {
  :deep(.el-input__wrapper) {
    background: #343744 !important;
    color: #96A0B5 !important;
    border-radius: 8px !important;
    height: 36px !important;
    border: none !important;
    box-shadow: none !important;
  }
}


/* 头像上传样式 */
.avatar-uploader-box {
  display: flex;
  justify-content: flex-start;
  margin-top: 8px;
}

.avatar-uploader {
  text-align: center;
}

.avatar-preview {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 0;
  overflow: visible; /* 修改为visible，使计数器可以溢出边界 */
  
  .avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0;
    border: 1px solid #343744;
  }
  
  .avatar-count {
    position: absolute;
    top: -5px;
    right: -30px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.85);
    z-index: 1;
  }
  
  .avatar-replace {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    opacity: 1;
    z-index: 2;
    
    .el-icon {
      font-size: 14px;
      color: #ffffff;
    }
  }
}

.avatar-upload-placeholder {
  width: 120px;
  height: 120px;
  border: 1px dashed #4C4F5F;
  border-radius: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
  background-color: transparent;
  overflow: visible; /* 修改为visible，使计数器可以溢出边界 */
  
  &:hover {
    border-color: #409EFF;
  }
  
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
  }
  
  .avatar-count {
    position: absolute;
    top: -5px;
    right: -30px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.85);
    z-index: 1;
  }
}

// 弹窗样式优化
:deep(.el-dialog) {
  .el-form-item__label {
    color: #96A0B5 !important;
  }
  
  .el-input__wrapper {
    background-color: #292c38 !important;
    box-shadow: 0 0 0 1px #565C70 inset !important;
    
    .el-input__inner {
      color: #ffffff !important;
    }
  }
  
  .el-input__count {
    background: transparent !important;
    color: #C0C4CC !important;
    
    .el-input__count-inner {
      background: transparent !important;
      color: #C0C4CC !important;
    }
  }
  
  .el-radio__label {
    color: #C8C9CC !important;
  }
  
  .el-radio.is-checked .el-radio__label {
    color: #409EFF !important;
  }
  
  .el-select .el-input__wrapper {
    background-color: #292c38 !important;
    box-shadow: 0 0 0 1px #565C70 inset !important;
  }
}

// 保留搜索区域的样式
.search-area {
  :deep(.el-input__wrapper) {
    background: #343744 !important;
    color: #96A0B5 !important;
    border-radius: 8px !important;
    height: 36px !important;
    border: none !important;
    box-shadow: none !important;
  }
}

// 全局表格样式覆盖，防止闪白
:deep(.el-table) {
  --el-table-bg-color: #292c38 !important;
  --el-table-tr-bg-color: #292c38 !important;
  --el-table-border-color: #4C4F5F !important;
  --el-table-header-bg-color: #343744 !important;
  --el-table-row-hover-bg-color: #2B3B5A !important;
  
  &::before {
    display: none;
  }
}

// 导入弹窗样式
.import-dialog {
  :deep(.el-dialog__header) {
    margin-right: 0;
    padding: 20px;
    border-bottom: 1px solid #4C4F5F;
  }

  :deep(.el-dialog__body) {
    padding: 20px;
  }

  :deep(.el-dialog__footer) {
    padding: 20px;
    border-top: 1px solid #4C4F5F;
  }

  .import-title {
    font-size: 14px;
    color: #96A0B5;
    margin-bottom: 20px;
  }

  .import-upload {
    :deep(.el-upload-dragger) {
      width: 100%;
      height: 200px;
      background-color: #292C38;
      border: 1px dashed #4C4F5F;
      border-radius: 8px;
      display: flex;
      justify-content: center;
      align-items: center;

      &:hover {
        border-color: #347AE2;
      }
    }

    .upload-content {
      display: flex;
      flex-direction: column;
      align-items: center;
      color: #96A0B5;

      .upload-icon {
        font-size: 40px;
        color: #96A0B5;
        margin-bottom: 10px;
      }

      .upload-text {
        font-size: 14px;
        margin-bottom: 10px;
      }

      .upload-link {
        display: flex;
        align-items: center;
        color: #347AE2;
        cursor: pointer;

        .upload-icon-small {
          font-size: 16px;
          margin-right: 4px;
        }

        .click-upload {
          font-size: 14px;
        }
      }
    }
  }

  .import-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;

    .footer-left {
      :deep(.el-checkbox__label) {
        color: #96A0B5;
      }
    }

    .footer-right {
      display: flex;
      align-items: center;
      gap: 10px;

      .file-format {
        color: #96A0B5;
        font-size: 12px;
      }

      .download-link {
        font-size: 12px;
      }
    }
  }

  .dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
  }
}

// 下拉框充满整行的样式
.full-width-select {
  width: 100% !important;
}

:deep(.full-width-select) {
  width: 100% !important;
  
  .el-input {
    width: 100% !important;
  }
  
  .el-input__wrapper {
    width: 100% !important;
  }
}
</style>
