/* ============================================================
   admin.css - PC端后台管理样式
   ============================================================ */
:root {
  --brand: #2563eb;
  --brand-light: #e3f2fd;
  --brand-dark: #1d4ed8;
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #1a1a2e;
  --text-2: #8e8e93;
  --border: #e8e8ed;
  --green: #34c759;
  --green-bg: #e8f9ed;
  --orange: #ff9500;
  --red: #ff3b30;
  --red-bg: #ffeael;
  --shadow: 0 1px 4px rgba(0,0,0,0.06);
  --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* Layout */
.admin-layout { display: flex; height: 100vh; }
.admin-sidebar { width: 220px; background: #1a1a2e; color: #fff; flex-shrink: 0; padding: 0; display: flex; flex-direction: column; }
.admin-sidebar-footer { margin-top: auto; padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.08); }
.admin-sidebar-footer .asf-user { font-size: 12px; color: rgba(255,255,255,0.55); margin-bottom: 10px; word-break: break-all; line-height: 1.5; }
.admin-sidebar-footer .asf-logout { width: 100%; padding: 8px; border: 1px solid rgba(255,255,255,0.2); background: transparent; color: rgba(255,255,255,0.75); border-radius: 6px; font-size: 13px; cursor: pointer; transition: all .2s; }
.admin-sidebar-footer .asf-logout:hover { background: rgba(255,255,255,0.08); color: #fff; }
.admin-sidebar .logo { padding: 20px 24px; font-size: 18px; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,0.1); display: flex; align-items: center; gap: 8px; }
.admin-sidebar .nav-item { padding: 14px 24px; cursor: pointer; display: flex; align-items: center; gap: 10px; font-size: 14px; color: rgba(255,255,255,0.65); transition: all 0.2s; border-left: 3px solid transparent; text-decoration: none; }
.admin-sidebar a.nav-item:visited { color: rgba(255,255,255,0.65); }
.admin-sidebar .nav-item:hover { color: #fff; background: rgba(255,255,255,0.05); }
.admin-sidebar .nav-item.active { color: #fff; background: rgba(37,99,235,0.2); border-left-color: var(--brand); }
.admin-sidebar .nav-item .ni-icon { font-size: 18px; }
.admin-sidebar .nav-group { margin: 4px 0; }
.admin-sidebar .nav-group-label { padding: 12px 24px 4px; font-size: 12px; letter-spacing: .5px; color: rgba(255,255,255,0.4); display: flex; align-items: center; gap: 10px; }
.admin-sidebar .nav-group.active .nav-group-label { color: rgba(255,255,255,0.85); }
.admin-sidebar .nav-group-label .ni-icon { font-size: 15px; }
.admin-sidebar .nav-item.nav-sub { padding-left: 46px; font-size: 13px; color: rgba(255,255,255,0.55); }
.admin-sidebar .nav-item.nav-sub .ni-icon { font-size: 16px; }
.admin-main { flex: 1; padding: 24px; overflow-y: auto; overflow-x: hidden; }

/* Page header */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header .ph-title { font-size: 20px; font-weight: 700; }
.page-header .ph-actions { display: flex; gap: 8px; }

/* Table：自身作为横向滚动容器，sticky 列以 table 右边缘为基准 */
.data-table { width: 100%; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; overflow-y: hidden; position: relative; }
.data-table table { width: 100%; min-width: max-content; border-collapse: collapse; background: #fff; }
.data-table th { background: #f8f9fa; padding: 12px 16px; text-align: left; font-size: 13px; color: var(--text-2); font-weight: 600; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 12px 16px; font-size: 14px; border-bottom: 1px solid var(--border); white-space: nowrap; background: transparent; }
.data-table tbody tr { background: #fff; }
.data-table tbody tr:nth-child(even) { background: #f8f9fa; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #eef4ff; }
/* 操作列固定在最右侧（横向滚动时常驻可见） */
.data-table th.col-action,
.data-table td.col-action {
  position: sticky;
  right: 0;
  z-index: 10;
  box-shadow: -4px 0 6px -3px rgba(0,0,0,0.08);
  width: 140px;
  min-width: 140px;
  max-width: 140px;
  text-align: center;
  overflow: hidden;
  background-clip: padding-box;
  border-left: 1px solid var(--border);
}
/* header 需要压在所有 body 单元格之上 */
.data-table th.col-action { z-index: 20; background: #f8f9fa; }
/*  body 固定列必须带实色背景，盖住底层横向滚动的文字 */
.data-table tbody tr td.col-action { background: #fff; }
.data-table tbody tr:nth-child(even) td.col-action { background: #f8f9fa; }
.data-table tbody tr:hover td.col-action { background: #eef4ff; }
/* 加固：用伪元素在 sticky 列右侧再补一条同色遮罩，封死 1px 缝隙 */
.data-table th.col-action::after,
.data-table td.col-action::after {
  content: '';
  position: absolute;
  top: 0;
  right: -1px;
  width: 1px;
  height: 100%;
  background: inherit;
  pointer-events: none;
}

/* Status badge */
.status-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; }
.status-bound { background: var(--green-bg); color: var(--green); }
.status-unbound { background: var(--red-bg); color: var(--red); }

/* Buttons */
.btn { padding: 8px 16px; border-radius: var(--radius); font-size: 14px; cursor: pointer; border: none; transition: opacity 0.2s; }
.btn:active { opacity: 0.85; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-outline { border: 1px solid var(--border); background: #fff; color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { background: var(--red); color: #fff; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1000; display: none; align-items: center; justify-content: center; }
.modal-overlay.active { display: flex; }
.modal { background: #fff; border-radius: 12px; padding: 24px; width: 440px; max-width: 90vw; }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.modal-body { margin-bottom: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; }

/* Form */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.form-select, .form-input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; background: #fff; }
.form-select:focus, .form-input:focus { border-color: var(--brand); }

/* Rule editor */
.rule-editor { background: #1e1e2e; color: #e0e0e0; border-radius: var(--radius); padding: 20px; font-family: 'Fira Code', 'Consolas', 'Monaco', monospace; font-size: 13px; line-height: 1.6; width: 100%; min-height: 400px; resize: vertical; border: none; outline: none; tab-size: 2; }
.rule-section { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.rule-section h3 { font-size: 15px; font-weight: 700; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.rule-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.rule-field label { font-size: 12px; color: var(--text-2); display: block; margin-bottom: 4px; }
.rule-field input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }

/* Toggle switch（启用开关） */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; cursor: pointer; inset: 0; background: #cbd5e1; border-radius: 24px; transition: background 0.2s; }
.switch .slider::before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.2s; }
.switch input:checked + .slider { background: var(--brand, #185FA5); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* Stats */
.stats-row { display: flex; gap: 16px; margin-bottom: 20px; }
.stat-card { flex: 1; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.stat-card .sc-num { font-size: 28px; font-weight: 800; color: var(--brand); }
.stat-card .sc-label { font-size: 13px; color: var(--text-2); margin-top: 4px; }

/* 客户列表页：筛选条 + 徽章 */
.filter-bar { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 20px; margin-bottom: 16px; }
.filter-bar .fb-item { display: flex; flex-direction: column; gap: 6px; }
.filter-bar label { font-size: 12px; color: var(--text-2); }
.filter-bar .form-input, .filter-bar .form-select { width: auto; min-width: 150px; }
.filter-bar .fb-spacer { flex: 1; }
.cust-badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.c-gray { background: #f1f3f5; color: #495057; }
.c-blue { background: #e7f1ff; color: #185FA5; }
.c-green { background: #e6f7f1; color: #0F6E56; }
.c-orange { background: #fff3e0; color: #b26a00; }
.c-red { background: #fdecea; color: #A32D2D; }
.src-jdy { background: #eef4ff; color: #185FA5; }
.src-manual { background: #f1ecff; color: #5b3aa6; }
.list-count { font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.link-btn { color: var(--brand); cursor: pointer; text-decoration: none; }
.link-btn:hover { text-decoration: underline; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
.detail-grid .dg-item { font-size: 14px; }
.detail-grid .dg-item .dg-k { color: var(--text-2); font-size: 12px; display: block; margin-bottom: 2px; }
.detail-grid .dg-item.full { grid-column: 1 / -1; }
/* 文件/附件字段：可点击下载链接 */
.detail-grid .dg-v a.file-link {
  display: inline-block;
  max-width: 100%;
  padding: 3px 10px;
  margin: 2px 0;
  background: #eef4ff;
  border: 1px solid #c9dbff;
  border-radius: 6px;
  color: #185FA5;
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.detail-grid .dg-v a.file-link:hover { background: #dce9ff; text-decoration: underline; }
/* 本地图片缩略图预览 */
.detail-grid .dg-v .img-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.detail-grid .dg-v a.img-preview-wrap { display: inline-block; line-height: 0; }
.detail-grid .dg-v img.img-preview {
  width: 110px; height: 110px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--border); cursor: pointer; background: #f5f5f5; transition: transform .12s ease;
}
.detail-grid .dg-v img.img-preview:hover { transform: scale(1.04); border-color: var(--brand); }
/* 单个图片单元格：缩略图 + "查看原图" 链接竖向排列 */
.detail-grid .dg-v .img-cell { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; margin: 2px 4px 2px 0; vertical-align: top; }
.detail-grid .dg-v .img-orig-link { font-size: 11px; color: var(--brand); text-decoration: none; }
.detail-grid .dg-v .img-orig-link:hover { text-decoration: underline; }
.detail-remark { white-space: pre-wrap; word-break: break-all; background: #f8f9fa; border-radius: 6px; padding: 8px 10px; font-size: 13px; }
.detail-hint { background: #fff7e6; border: 1px solid #ffd591; color: #ad6800; border-radius: 6px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; grid-column: 1 / -1; }

/* ===== 客户详情页：顶部 tab 切换不同表 ===== */
.back-link { color: var(--brand); text-decoration: none; font-weight: 500; }
.back-link:hover { text-decoration: underline; }
.ph-sub { color: var(--text-2); font-size: 13px; font-weight: 400; margin-left: 4px; }
.detail-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 6px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.dtab { padding: 7px 14px; border-radius: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; white-space: nowrap; user-select: none; }
.dtab:hover { background: var(--brand-light); color: var(--brand); }
.dtab.active { background: var(--brand); color: #fff; }
.detail-content { padding: 14px 2px; }

/* ===== 新增客户：动态表单字段 ===== */
.create-hint { font-size: 13px; color: var(--text-2); margin-bottom: 14px; }
.form-field { margin-bottom: 12px; }
.form-field > label { display: block; margin-bottom: 5px; font-weight: 600; font-size: 13px; color: var(--text-1); }
.form-field .req { color: #c0392b; margin-left: 3px; }
.form-field input, .form-field textarea, .form-field select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; background: var(--bg-1); color: var(--text-1); box-sizing: border-box;
}
.form-field textarea { min-height: 64px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
.form-field.full { grid-column: 1 / -1; }
.rel-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; background: #fff; }
.rel-card-title { font-size: 13px; font-weight: 600; color: var(--text-1); margin-bottom: 10px; }
.empty { text-align: center; color: var(--text-2); padding: 40px 0; font-size: 14px; }

/* ===== 组织架构树 ===== */
.org-tree { display: flex; flex-direction: column; gap: 16px; }
.org-dept { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.org-dept-title { font-weight: 700; font-size: 15px; margin-bottom: 10px; }
.org-count { color: var(--text-2); font-weight: 400; font-size: 13px; margin-left: 6px; }
.org-node { padding: 6px 0; border-bottom: 1px dashed #eee; display: flex; align-items: center; gap: 8px; }
.org-node:last-child { border-bottom: none; }
.org-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); display: inline-block; flex: 0 0 auto; }
.org-tag { background: var(--brand-light); color: var(--brand); border-radius: 10px; padding: 1px 8px; font-size: 12px; }
.org-sub { color: var(--text-2); font-size: 12px; }

/* ===== 员工视角横幅 / 客户列表归属标签 ===== */
.owner-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--brand-light); border: 1px solid var(--brand); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 14px; font-size: 14px; color: var(--text-1);
}
.owner-banner .ob-text b { color: var(--brand); }
.owner-tag {
  display: inline-block; background: var(--brand-light); color: var(--brand);
  border-radius: 10px; padding: 1px 8px; font-size: 12px; white-space: nowrap;
}
.owner-tag.owner-none { background: #f0f0f0; color: var(--text-2); }
