:root {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --text: #1f2329;
  --muted: #5c6b7a;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --primary-08: rgba(37,99,235,0.08);
  --primary-12: rgba(37,99,235,0.12);
  --border: #e1e4e8;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #f59e0b;
  --amber: #f59e0b;
  --purple: #8e44ad;
  --shadow: 0 4px 14px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.04);
  --shadow-lg: 0 18px 50px rgba(16,24,40,.14);
  --radius: 10px;
  --radius-lg: 14px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; }
body { font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* 登录 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(145deg, #eef4ff 0%, #f2f4f7 60%, #ffffff 100%); padding: 20px; }
.login-card { width: 400px; max-width: 100%; background: var(--panel); border-radius: var(--radius-lg); padding: 42px 36px; box-shadow: var(--shadow-lg); text-align: center; border: 1px solid rgba(0,0,0,.03); }
.login-logo { display: flex; align-items: center; justify-content: center; margin-bottom: 6px; }
.login-logo img { height: 64px; width: auto; }
.login-card h1 { font-size: 22px; font-weight: 700; margin: 10px 0 6px; letter-spacing: .2px; }
.login-sub { color: var(--muted); margin-bottom: 28px; font-size: 13px; }
.login-card label { display: block; text-align: left; font-size: 13px; color: var(--muted); margin: 14px 0 6px; font-weight: 500; }
.login-card input { width: 100%; padding: 11px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none; transition: .15s; background: #fafbfc; }
.login-card input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-08); }
.login-tip { margin-top: 18px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.error-text { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* 按钮 */
.btn { border: 1px solid var(--border); background: #fff; color: var(--text); padding: 8px 14px; border-radius: var(--radius-sm); font-size: 14px; transition: .15s; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.btn:hover { background: #f4f6f9; border-color: #d1d5db; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(37,99,235,.18); }
.btn.primary:hover { background: var(--primary-d); border-color: var(--primary-d); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; margin-top: 18px; padding: 12px; font-size: 15px; }
.btn.danger { background: #fff; border-color: #fecaca; color: var(--red); }
.btn.danger:hover { background: #fef2f2; }
.btn.warning { background: #fff7ed; border-color: #fdba74; color: #9a3412; }
.btn.warning:hover { background: #ffedd5; }
.btn.sm { padding: 5px 10px; font-size: 13px; }

/* 布局 */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { height: 60px; background: var(--panel); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 22px; position: sticky; top: 0; z-index: 10; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: .3px; }
.brand-logo { height: 30px; width: auto; }
.brand-text { color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-badge { background: var(--primary-08); color: var(--primary-d); padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 500; }
.layout { display: flex; flex: 1; min-height: 0; }
.sidebar { width: 220px; flex-shrink: 0; background: #f7f8fa; border-right: 1px solid var(--border); padding: 10px 0 14px; display: flex; flex-direction: column; position: sticky; top: 60px; align-self: flex-start; height: calc(100vh - 60px); overflow-y: auto; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 8px 18px 18px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.sidebar-brand img { height: 32px; width: auto; }
.sidebar-brand span { font-weight: 700; font-size: 15px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .tab { border: none; background: transparent; padding: 11px 16px; margin: 0 10px; font-size: 14px; color: var(--muted); border-radius: var(--radius-sm); cursor: pointer; display: flex; align-items: center; gap: 10px; text-align: left; white-space: nowrap; position: relative; transition: .15s; }
.tab-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .9; }
.sidebar .tab:hover { background: #ffffff; color: var(--text); }
.sidebar .tab.active { background: #ffffff; color: var(--primary); font-weight: 600; box-shadow: var(--shadow); }
.sidebar .tab.active .tab-icon { opacity: 1; }
.sidebar .tab.active::before { content: ''; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; background: var(--primary); border-radius: 0 3px 3px 0; }
.content { flex: 1; padding: 24px 28px; min-width: 0; }

/* 角色行 */
.role-row { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--panel); }
.role-row .drag-handle { cursor: grab; color: var(--muted); user-select: none; font-size: 16px; flex-shrink: 0; }
.role-row .role-info { flex: 1; min-width: 0; }
.role-row.drag-over { border-color: var(--primary); background: #f5f8ff; }

/* 统计卡片 */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { position: relative; background: var(--panel); border-radius: var(--radius); padding: 20px 18px; box-shadow: var(--shadow); overflow: hidden; }
.stat-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--primary); }
.stat-card:nth-child(2)::before { background: var(--green); }
.stat-card:nth-child(3)::before { background: var(--orange); }
.stat-card:nth-child(4)::before { background: var(--purple); }
.stat-card:nth-child(5)::before { background: #0ea5e9; }
.stat-card:nth-child(6)::before { background: #6366f1; }
.stat-card:nth-child(7)::before { background: #ec4899; }
.stat-card:nth-child(8)::before { background: #14b8a6; }
.stat-card:nth-child(9)::before { background: #f97316; }
.stat-card .num { font-size: 26px; font-weight: 700; color: var(--text); letter-spacing: -.3px; }
.stat-card .lbl { color: var(--muted); margin-top: 6px; font-size: 13px; }

.panel { background: var(--panel); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; border: 1px solid rgba(0,0,0,.02); }
.panel h3 { font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.panel-head h3 { margin-bottom: 0; }

/* 发起审批类型卡片 */
.type-card { transition: border-color .15s, box-shadow .15s, transform .1s; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; cursor: pointer; display: flex; align-items: center; gap: 12px; background: var(--panel); }
.type-card:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(37,99,235,.1); transform: translateY(-1px); }
.tf-row { background: #fafbfc; }

/* 柱状图 */
.bar-chart { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: flex; align-items: center; gap: 12px; }
.bar-row .name { width: 70px; color: var(--muted); font-size: 13px; text-align: right; }
.bar-track { flex: 1; background: #eef2f7; border-radius: 6px; height: 22px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #3b82f6); border-radius: 6px; transition: width .45s ease; display: flex; align-items: center; justify-content: flex-end; padding-right: 8px; color: #fff; font-size: 12px; font-weight: 600; }
.bar-row .val { width: 34px; font-size: 13px; color: var(--text); font-weight: 500; }

/* 分段切换（业绩排行周期） */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.seg-btn { border: none; background: #fff; color: var(--muted); padding: 7px 16px; font-size: 13px; cursor: pointer; transition: all .15s; border-right: 1px solid var(--border); }
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--primary); color: #fff; font-weight: 600; }
.section-title { font-size: 15px; font-weight: 600; margin: 18px 0 10px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.section-title .badge { font-size: 12px; font-weight: 400; color: var(--muted); background: #f1f5f9; padding: 2px 8px; border-radius: 10px; }

/* 列表 */
.simple-list .row { padding: 10px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.simple-list .row:last-child { border-bottom: none; }
.simple-list .empty { color: var(--muted); padding: 10px 0; }

/* 工具栏 */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=text] { flex: 1; min-width: 200px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none; background: #fff; }
.toolbar input:focus, .toolbar select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-08); }
.toolbar select { padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none; background: #fff; }
.hint { color: var(--muted); font-size: 13px; background: #f8fafc; padding: 6px 10px; border-radius: var(--radius-sm); border: 1px dashed var(--border); }

/* 表格 */
.table-wrap { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border: 1px solid rgba(0,0,0,.02); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 13px 14px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); }
.data-table th { background: #f8fafc; color: var(--muted); font-weight: 600; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f6f8ff; }
.data-table .ops { display: flex; gap: 6px; }
.status-tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; background: rgba(37,99,235,.07); color: var(--primary-d); border: 1px solid transparent; }
.amount { color: var(--green); font-weight: 600; }
.masked { background: #f3f4f6; padding: 2px 6px; border-radius: 4px; color: var(--muted); }

.pager { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.pager button { padding: 6px 12px; border: 1px solid var(--border); background: #fff; border-radius: var(--radius-sm); font-weight: 500; }
.pager button:disabled { opacity: .5; cursor: not-allowed; }

/* 弹窗 */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box { background: #fff; width: 600px; max-width: 94vw; max-height: 90vh; overflow: auto; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); border: 1px solid rgba(0,0,0,.04); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff; z-index: 2; }
.modal-head h3 { font-size: 16px; font-weight: 600; }
.modal-close { border: none; background: transparent; font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; width: 32px; height: 32px; border-radius: 6px; }
.modal-close:hover { background: #f3f4f6; }
.modal-body { padding: 20px; }

/* 表单 */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.form-field input, .form-field select, .form-field textarea { padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none; font-family: inherit; background: #fff; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-08); }
.form-field textarea { resize: vertical; min-height: 64px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* 跟进时间线 */
.timeline { border-left: 2px solid var(--border); margin-left: 8px; padding-left: 16px; }
.tl-item { position: relative; padding: 0 0 16px 0; }
.tl-item::before { content: ''; position: absolute; left: -23px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.tl-meta { font-size: 12px; color: var(--muted); }
.tl-content { margin-top: 4px; }
.tl-type { display: inline-block; background: #eef2f7; border-radius: 4px; padding: 1px 7px; font-size: 12px; color: var(--muted); margin-right: 6px; }
.tl-next { color: var(--primary-d); font-size: 12px; margin-top: 4px; }

/* Toast */
.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: #1f2933; color: #fff; padding: 11px 22px; border-radius: var(--radius-sm); font-size: 14px; z-index: 100; box-shadow: 0 10px 30px rgba(0,0,0,.25); }

/* 空状态 */
.empty { color: var(--muted); text-align: center; padding: 30px; font-size: 14px; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .data-table { font-size: 12px; }
  .data-table th:nth-child(2), .data-table td:nth-child(2) { display: none; }
  .sidebar { width: 64px; padding: 8px 0; }
  .sidebar-brand span { display: none; }
  .sidebar-brand { justify-content: center; padding: 10px 0 14px; }
  .sidebar-brand img { height: 28px; }
  .sidebar .tab { padding: 12px; margin: 0 6px; justify-content: center; }
  .sidebar .tab span:not(.tab-icon) { display: none; }
  .sidebar .tab.active::before { left: -6px; }
  .content { padding: 16px; }
}

/* ===== 客户档案模块补充样式 ===== */
.stat-card .stat-num { font-size: 26px; font-weight: 700; color: var(--text); letter-spacing: -.3px; }
.stat-card .stat-lbl { color: var(--muted); margin-top: 6px; font-size: 13px; }
.stat-card.ok::before { background: var(--green) !important; }
.stat-card.warn::before { background: var(--orange) !important; }
.stat-card.muted::before { background: var(--muted) !important; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 10px; background: #f1f5f9; color: var(--muted); }
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.muted { background: #f1f5f9; color: #64748b; }
.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--orange); font-weight: 600; }

/* 全局权限：非管理员隐藏导入/导出/删除类按钮（后端 isAdminOnlyOp 为权威拦截） */
body:not(.is-admin) [data-admin] { display: none !important; }
