<template>
  <div class="app-container ai-sip-call-user">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="80px"
      class="search-form"
    >
      <el-form-item label="登录账号" prop="loginName">
        <el-input
          v-model="queryParams.loginName"
          placeholder="请输入登录账号"
          clearable
          size="small"
          class="filter-control"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户昵称" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户昵称"
          clearable
          size="small"
          class="filter-control"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户来源" prop="userSource">
        <el-select
          v-model="queryParams.userSource"
          placeholder="请选择用户来源"
          clearable
          size="small"
          class="filter-control"
        >
          <el-option label="销售" :value="0" />
          <el-option label="总后台" :value="1" />
          <el-option label="医生" :value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="用户状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择用户状态"
          clearable
          size="small"
          class="filter-control"
        >
          <el-option label="正常" value="0" />
          <el-option label="停用" value="1" />
        </el-select>
      </el-form-item>
      <el-form-item class="search-actions">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8 toolbar-row">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['his:aiSipCallUser:aiSipCallUser:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['his:aiSipCallUser:aiSipCallUser:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      border
      stripe
      v-loading="loading"
      :data="aiSipCallUserList"
      class="user-table"
      :header-cell-style="headerCellStyle"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="用户ID" align="center" prop="userId" width="90" />
      <el-table-column label="用户来源" align="center" prop="userSource" min-width="100">
        <template slot-scope="scope">
          <el-tag
            size="mini"
            effect="plain"
            :type="userSourceTagType(scope.row.userSource)"
          >{{ formatUserSource(scope.row.userSource) }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="登录账号" align="center" prop="loginName" min-width="120" show-overflow-tooltip />
      <el-table-column label="分机号" align="center" prop="extNum" min-width="100" />
      <el-table-column label="分机密码" align="center" prop="extPass" min-width="150">
        <template slot-scope="scope">
          <div class="pwd-cell">
            <span class="pwd-text">{{ scope.row.showPassword ? scope.row.extPass : '******' }}</span>
            <button
              type="button"
              class="op-chip op-chip--ghost"
              @click="togglePasswordVisibility(scope.row)"
            >
              <i :class="scope.row.showPassword ? 'el-icon-hide' : 'el-icon-view'"></i>
              <span>{{ scope.row.showPassword ? '隐藏' : '查看' }}</span>
            </button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="绑定网关" align="center" prop="gatewayIds" min-width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ getGatewayNames(scope.row.gatewayIds) || '—' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户状态" align="center" prop="status" width="100">
        <template slot-scope="scope">
          <el-tag
            size="mini"
            effect="plain"
            :type="scope.row.status == '0' || scope.row.status === 0 ? 'success' : 'info'"
          >{{ formatStatus(scope.row.status) }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" min-width="120" show-overflow-tooltip />
      <el-table-column label="创建时间" align="center" prop="createTime" width="170" />
      <el-table-column label="操作" align="center" width="168" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <div class="op-actions">
            <button
              type="button"
              class="op-chip op-chip--edit"
              v-hasPermi="['his:aiSipCall:aiSipCallUser:edit']"
              @click="handleUpdate(scope.row)"
            >
              <i class="el-icon-edit"></i>
              <span>修改</span>
            </button>
            <button
              type="button"
              class="op-chip op-chip--danger"
              v-hasPermi="['his:aiSipCall:aiSipCallUser:remove']"
              @click="handleDelete(scope.row)"
            >
              <i class="el-icon-delete"></i>
              <span>删除</span>
            </button>
          </div>
        </template>
      </el-table-column>
    </el-table>

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

    <!-- 添加或修改 sip用户信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="760px"
      append-to-body
      custom-class="ai-sip-user-dialog"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="96px" class="user-dialog-form">
        <div class="dialog-section">
          <div class="dialog-section__title">基础信息</div>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="登录账号" prop="loginName">
                <el-input v-model="form.loginName" disabled placeholder="登录账号" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="用户姓名" prop="userName">
                <el-input v-model="form.userName" disabled placeholder="用户姓名" />
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="!form.userId">
              <el-form-item label="登录密码" prop="password">
                <el-input
                  v-model="form.password"
                  disabled
                  :type="passwordVisible ? 'text' : 'password'"
                  placeholder="登录密码"
                >
                  <i
                    slot="suffix"
                    class="el-icon-view pwd-eye"
                    @click="togglePasswordVisible"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="用户状态" prop="status">
                <div class="readonly-status">
                  <el-tag
                    size="small"
                    effect="plain"
                    :type="form.status === 0 || form.status === '0' ? 'success' : 'info'"
                  >{{ formatStatus(form.status) }}</el-tag>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
        </div>

        <div class="dialog-section">
          <div class="dialog-section__title">外呼配置</div>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="绑定分机号" prop="extNum">
                <el-select
                  v-model="form.extNum"
                  placeholder="请选择绑定的分机号"
                  clearable
                  filterable
                  class="full-width"
                >
                  <el-option
                    v-for="item in extNumOptions"
                    :key="item.extId"
                    :label="item.extNum"
                    :value="item.extNum"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="用户性别" prop="sex">
                <el-radio-group v-model="form.sex" class="sex-group">
                  <el-radio-button :label="0">男</el-radio-button>
                  <el-radio-button :label="1">女</el-radio-button>
                  <el-radio-button :label="2">未知</el-radio-button>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item label="网关" prop="gatewayIds" class="gateway-form-item">
            <div
              class="gateway-select-wrap"
              :class="{ 'has-extra-count': extraGatewayCount > 0 }"
            >
              <el-select
                ref="gatewaySelect"
                v-model="selectedGateways"
                placeholder="请选择网关"
                multiple
                filterable
                class="full-width gateway-select gateway-select--max4"
                @change="syncGatewayTagCollapse"
                @visible-change="syncGatewayTagCollapse"
              >
                <el-option
                  v-for="item in gateways"
                  :key="item.id"
                  :label="item.gwDesc"
                  :value="item.id"
                />
              </el-select>
              <span v-if="extraGatewayCount > 0" class="gateway-extra-count">+{{ extraGatewayCount }}</span>
            </div>
            <div class="selected-gateway-names">
              <template v-if="selectedGatewayItems.length">
                <div class="selected-gateway-names__label">已选网关（{{ selectedGatewayItems.length }}）：</div>
                <div class="selected-gateway-names__list">
                  <span
                    v-for="item in selectedGatewayItems"
                    :key="item.id"
                    class="selected-gateway-name"
                    title="点击删除"
                    @click="removeSelectedGateway(item.id)"
                  >{{ item.gwDesc }}</span>
                </div>
              </template>
              <span v-else class="selected-gateway-names__empty">暂未选择网关</span>
            </div>
          </el-form-item>

          <el-form-item label="备注" prop="remark">
            <el-input
              v-model="form.remark"
              type="textarea"
              :rows="3"
              maxlength="200"
              show-word-limit
              placeholder="请输入备注内容"
            />
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listAiSipCallUser,
  getAiSipCallUser,
  delAiSipCallUser,
  addAiSipCallUser,
  updateAiSipCallUser,
  exportAiSipCallUser,
  getUnBindExtnum,
  getCompanyUnBindExtnum
} from "@/api/aiSipCall/aiSipCallUser";
import {remoteGatewayList} from "../../api/aiSipCall/aiSipCallGateway";

export default {
  name: "AiSipCallUser",
  props: {
    /** 嵌入用户管理等页面时仅作弹窗组件，禁止 created 自动拉 SIP 列表（远程 401 会触发全局登出） */
    autoLoad: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      loading: true,
      exportLoading: false,
      ids: [],
      single: true,
      multiple: true,
      showSearch: true,
      total: 0,
      aiSipCallUserList: [],
      extNumOptions: [],
      gateways: [],
      selectedGateways: [],
      open: false,
      headerCellStyle: {
        background: '#f7f9fc',
        color: '#303133',
        fontWeight: 600
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: null,
        loginName: null,
        userName: null,
        userType: null,
        email: null,
        phonenumber: null,
        sex: null,
        avatar: null,
        password: null,
        salt: null,
        status: null,
        userSource: null,
        loginIp: null,
        loginDate: null,
        pwdUpdateDate: null,
        logo: null,
        companyUserId: null,
        extNum: null
      },
      form: {
        password: '123456'
      },
      passwordVisible: false,
      title: "",
      rules: {
        loginName: [
          {required: true, message: "登录账号不能为空", trigger: "blur"}
        ],
        password: [
          {required: true, message: "登录密码不能为空", trigger: "blur"}
        ],
        userName: [
          {required: true, message: "用户姓名不能为空", trigger: "blur"}
        ],
        extNum: [
          {required: true, message: "绑定的分机号不能为空", trigger: "change"}
        ]
      }
    };
  },
  created() {
    if (this.autoLoad) {
      this.getList();
    } else {
      this.loading = false;
    }
  },
  computed: {
    selectedGatewayItems() {
      if (!this.selectedGateways || !this.selectedGateways.length) {
        return [];
      }
      return this.selectedGateways
        .map(id => {
          const gateway = this.gateways.find(gw => gw.id === id || String(gw.id) === String(id));
          return gateway
            ? { id: gateway.id, gwDesc: gateway.gwDesc }
            : { id, gwDesc: `网关#${id}` };
        });
    },
    extraGatewayCount() {
      const total = this.selectedGateways ? this.selectedGateways.length : 0;
      return total > 4 ? total - 4 : 0;
    }
  },
  watch: {
    selectedGateways() {
      this.syncGatewayTagCollapse();
    },
    open(val) {
      if (val) {
        this.syncGatewayTagCollapse();
      }
    }
  },
  methods: {
    /** 用户来源：0销售 1总后台 2医生 */
    formatUserSource(source) {
      const map = { '0': '销售', '1': '总后台', '2': '医生' };
      const key = source == null || source === '' ? '' : String(source);
      return map[key] || (source == null || source === '' ? '-' : source);
    },
    userSourceTagType(source) {
      const map = { '0': 'warning', '1': 'info', '2': 'success' };
      const key = source == null || source === '' ? '' : String(source);
      return map[key] || 'info';
    },
    formatStatus(status) {
      if (status == '0' || status === 0) return '正常';
      if (status == '1' || status === 1) return '停用';
      return status == null || status === '' ? '-' : status;
    },
    handleUpdateById(id) {
      this.reset();
      getAiSipCallUser(id).then(response => {
        if (response && response.data) {
          this.form = {...response.data};
          this.form.status = Number(this.form.status);
          this.form.sex = Number(this.form.sex);
          this.form.password = null;
          if (this.form.gatewayIds) {
            this.selectedGateways = this.form.gatewayIds
              .split(',')
              .map(id => Number(id))
              .filter(id => !Number.isNaN(id));
          }
          getUnBindExtnum().then(res => {
            this.extNumOptions = res.data || [];
          });
          remoteGatewayList({ pageNum:1, pageSize: 50,isAICall:false,params:{purposes: [1, 3]} }).then(response => {
            this.gateways = response.rows || [];
          });
          this.open = true;
          const employeeName = this.form.userName || '未知角色';
          this.title = `修改 sip 外呼角色角色 - ${employeeName}`;
        } else {
          this.$message.error("获取 sip 外呼角色信息失败");
        }
      }).catch(error => {
        console.error("获取 sip 外呼角色信息失败:", error);
        this.$message.error("获取 sip 外呼角色信息失败");
      });
    },
    /** 添加公司用户 */
    handleAddCompanyUserOnSip(userName, nickName, userId) {
      this.reset();
      this.form.userName = nickName;
      this.form.loginName = userName;
      this.form.sysUserId = userId;
      this.form.sysUserName = userName;
      this.form.status = 0;
      this.form.sex = 0;

      getUnBindExtnum().then(response => {
        this.extNumOptions = response.data || [];
      });

      remoteGatewayList({ pageNum:1, pageSize: 50,isAICall:false,params:{purposes: [1, 3]} }).then(response => {
        this.gateways = response.rows || [];
      });

      this.open = true;
      const employeeName = nickName || '未知员工';
      this.title = `添加 sip 外呼角色 - ${employeeName}`;
    },
    /** 查询 sip 用户信息列表 */
    getList() {
      this.loading = true;
      remoteGatewayList({ pageNum:1, pageSize: 50,isAICall:false,params:{purposes: [1, 3]} }).then(response => {
        this.gateways = response.rows || [];
        listAiSipCallUser(this.queryParams).then(response => {
          this.aiSipCallUserList = response.rows.map(item => ({
            ...item,
            showPassword: false
          }));
          this.total = response.total;
          this.loading = false;
        });
      }).catch(() => {
        this.loading = false;
      });
    },
    cancel() {
      this.open = false;
      this.reset();
    },
    reset() {
      this.form = {
        password: '123456'
      };
      this.selectedGateways = [];
      this.passwordVisible = false;
      this.resetForm("form");
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.userSource = null;
      this.handleQuery();
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加 sip用户信息";
    },
    handleUpdate(row) {
      this.reset();
      const userId = row.userId || this.ids
      getAiSipCallUser(userId).then(response => {
        this.form = response.data;
        this.form.status = Number(this.form.status);
        this.form.sex = Number(this.form.sex);
        this.form.password = null;
        if (this.form.gatewayIds) {
          this.selectedGateways = this.form.gatewayIds
            .split(',')
            .map(id => Number(id))
            .filter(id => !Number.isNaN(id));
        }

        const extNumPromise = this.form.userSource === '0' || this.form.userSource === 0
          ? getCompanyUnBindExtnum(this.form.companyId)
          : getUnBindExtnum();

        extNumPromise.then(res => {
          this.extNumOptions = res.data || [];
        });
        remoteGatewayList({ pageNum:1, pageSize: 50,isAICall:false,params:{purposes: [1, 3]} }).then(response => {
          this.gateways = response.rows || [];
          this.open = true;
          this.title = "修改 sip 用户信息";
        });
      });
    },
    togglePasswordVisible() {
      this.passwordVisible = !this.passwordVisible;
    },
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.gatewayIds = this.selectedGateways.join(',');

          if (this.form.userId != null) {
            updateAiSipCallUser(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              this.$emit('refreshParentData');
            });
          } else {
            addAiSipCallUser(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              this.$emit('refreshParentData');
            });
          }
        }
      });
    },
    handleDelete(row) {
      const userIds = row.userId || this.ids;
      this.$confirm('是否确认删除sip用户信息编号为"' + userIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delAiSipCallUser(userIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有 sip 用户信息数据项？', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportAiSipCallUser(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      })
    },
    getGatewayNames(gatewayIds) {
      if (!gatewayIds) {
        return '';
      }
      const ids = gatewayIds.split(',').map(id => Number(id));
      const names = ids
        .map(id => {
          const gateway = this.gateways.find(gw => gw.id === id);
          return gateway ? gateway.gwDesc : '';
        })
        .filter(name => name);
      return names.join(', ');
    },
    removeSelectedGateway(id) {
      this.selectedGateways = this.selectedGateways.filter(
        item => item !== id && String(item) !== String(id)
      );
    },
    syncGatewayTagCollapse() {
      this.$nextTick(() => {
        const select = this.$refs.gatewaySelect;
        if (!select || !select.$el) return;
        const tags = select.$el.querySelectorAll('.el-select__tags > span > .el-tag');
        tags.forEach((tag, index) => {
          tag.style.display = index < 4 ? '' : 'none';
        });
      });
    },
    togglePasswordVisibility(row) {
      row.showPassword = !row.showPassword;
    }
  }
};
</script>

<style scoped>
.ai-sip-call-user .search-form {
  margin-bottom: 12px;
  padding: 14px 16px 4px;
  background: #fafbfc;
  border: 1px solid #eef0f3;
  border-radius: 8px;
}

.ai-sip-call-user .filter-control {
  width: 160px;
}

.ai-sip-call-user .search-actions {
  margin-left: 4px;
}

.ai-sip-call-user .toolbar-row {
  margin-top: 4px;
}

.ai-sip-call-user .user-table {
  border-radius: 6px;
  overflow: hidden;
}

.ai-sip-call-user .pwd-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.ai-sip-call-user .pwd-text {
  font-family: Consolas, Monaco, monospace;
  letter-spacing: 0.5px;
  color: #606266;
}

.ai-sip-call-user .op-actions {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.ai-sip-call-user .op-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 14px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
  background: transparent;
}

.ai-sip-call-user .op-chip i {
  font-size: 13px;
}

.ai-sip-call-user .op-chip--ghost {
  color: #606266;
  background: #f4f5f7;
  border-color: #e8eaed;
  height: 24px;
  padding: 0 8px;
}

.ai-sip-call-user .op-chip--ghost:hover {
  color: #409eff;
  background: #edf4ff;
  border-color: #d6e6ff;
}

.ai-sip-call-user .op-chip--edit {
  color: #2f6fed;
  background: #edf4ff;
  border-color: #d6e6ff;
}

.ai-sip-call-user .op-chip--edit:hover {
  color: #fff;
  background: #409eff;
  border-color: #409eff;
  box-shadow: 0 4px 10px rgba(64, 158, 255, 0.28);
}

.ai-sip-call-user .op-chip--danger {
  color: #d94848;
  background: #fff1f0;
  border-color: #fad2d0;
}

.ai-sip-call-user .op-chip--danger:hover {
  color: #fff;
  background: #f56c6c;
  border-color: #f56c6c;
  box-shadow: 0 4px 10px rgba(245, 108, 108, 0.28);
}
</style>

<style>
.ai-sip-user-dialog {
  border-radius: 12px;
  overflow: hidden;
}

.ai-sip-user-dialog .el-dialog__header {
  padding: 18px 24px 14px;
  border-bottom: 1px solid #eef0f3;
  background: linear-gradient(180deg, #ffffff 0%, #f9fbff 100%);
}

.ai-sip-user-dialog .el-dialog__title {
  font-size: 17px;
  font-weight: 600;
  color: #303133;
}

.ai-sip-user-dialog .el-dialog__body {
  padding: 18px 24px 10px;
  background: #f5f7fb;
  max-height: 72vh;
  overflow-y: auto;
}

.ai-sip-user-dialog .el-dialog__footer {
  padding: 14px 24px 18px;
  border-top: 1px solid #eef0f3;
  background: #fff;
}

.ai-sip-user-dialog .user-dialog-form .dialog-section {
  margin-bottom: 16px;
  padding: 16px 18px 8px;
  background: #fff;
  border: 1px solid #e8edf5;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(31, 45, 61, 0.03);
}

.ai-sip-user-dialog .user-dialog-form .dialog-section__title {
  margin-bottom: 14px;
  padding-left: 10px;
  border-left: 3px solid #409eff;
  font-size: 14px;
  font-weight: 600;
  color: #303133;
  line-height: 1.2;
}

.ai-sip-user-dialog .readonly-status {
  display: flex;
  align-items: center;
  min-height: 36px;
}

.ai-sip-user-dialog .pwd-eye {
  cursor: pointer;
  color: #909399;
}

.ai-sip-user-dialog .pwd-eye:hover {
  color: #409eff;
}

.ai-sip-user-dialog .gateway-form-item {
  margin-bottom: 18px;
}

.ai-sip-user-dialog .gateway-select-wrap {
  position: relative;
  width: 100%;
}

.ai-sip-user-dialog .gateway-select {
  width: 100%;
}

.ai-sip-user-dialog .gateway-select--max4 .el-select__tags > span > .el-tag:nth-child(n + 5) {
  display: none !important;
}

.ai-sip-user-dialog .gateway-select-wrap.has-extra-count .el-select__tags {
  padding-right: 46px;
}

.ai-sip-user-dialog .gateway-extra-count {
  position: absolute;
  right: 30px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 24px;
  padding: 0 8px;
  border-radius: 4px;
  background: #ecf5ff;
  border: 1px solid #d9ecff;
  color: #409eff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
}

.ai-sip-user-dialog .selected-gateway-names {
  margin-top: 10px;
  padding: 10px 12px;
  background: #f5f9ff;
  border: 1px solid #d6e6ff;
  border-radius: 6px;
}

.ai-sip-user-dialog .selected-gateway-names__label {
  margin-bottom: 8px;
  font-size: 12px;
  color: #909399;
}

.ai-sip-user-dialog .selected-gateway-names__list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
}

.ai-sip-user-dialog .selected-gateway-name {
  color: #409eff;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
  user-select: none;
  transition: color 0.2s ease, opacity 0.2s ease;
}

.ai-sip-user-dialog .selected-gateway-name:hover {
  color: #f56c6c;
  text-decoration: line-through;
  opacity: 0.85;
}

.ai-sip-user-dialog .selected-gateway-names__empty {
  font-size: 12px;
  color: #c0c4cc;
}

.ai-sip-user-dialog .sex-group .el-radio-button__inner {
  padding: 8px 18px;
}

.ai-sip-user-dialog .full-width {
  width: 100%;
}

.ai-sip-user-dialog .dialog-footer {
  text-align: right;
}
</style>
