:root {
  --primary: #1a56db;
  --primary-dark: #1e40af;
  --bg: #f3f5f9;
  --border: #e3e7ee;
  --text: #1f2937;
  --muted: #6b7280;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --info: #0891b2;
  --sidebar-w: 220px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-size: 15px;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* 左侧任务栏布局 */
.layout { min-height: 100vh; }
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
  background: #102a56; color: #fff; z-index: 200;
  display: flex; flex-direction: column;
}
.sidebar .brand { font-size: 21px; font-weight: 700; padding: 22px 20px 18px; white-space: nowrap; }
.sidebar .brand span { color: #8fb4ff; }
.sidenav { flex: 1; display: flex; flex-direction: column; gap: 5px; padding: 12px; }
.sidenav a {
  color: #c9d6f2; padding: 12px 16px; border-radius: 8px; white-space: nowrap;
  font-size: 15px;
}
.sidenav a:hover { background: rgba(255,255,255,.1); text-decoration: none; color: #fff; }
.sidenav a.active { background: var(--primary); color: #fff; }
.sidebar-mask { display: none; }

.mainwrap { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topline {
  height: 58px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 20px;
  position: sticky; top: 0; z-index: 100;
}
.topline-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topline .top-title { font-size: 17px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.userbox { display: flex; align-items: center; gap: 12px; font-size: 14px; white-space: nowrap; }
/* 右上角账户名 + 点击弹出的下拉菜单 */
.umenu { position: relative; }
.um-btn {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--border); background: #fff; border-radius: 6px;
  padding: 6px 14px; font-size: 14px; color: var(--text); cursor: pointer;
}
.um-btn:hover { background: #f1f5f9; }
.um-caret { font-size: 10px; color: var(--muted); }
.um-panel {
  display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 300;
  min-width: 190px; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(15,23,42,.12); overflow: hidden;
}
.um-panel.show { display: block; }
.um-panel a { display: block; padding: 10px 15px; color: var(--text); font-size: 14px; }
.um-panel a:hover { background: #f1f5f9; color: var(--primary); }
.um-info { padding: 11px 15px; border-bottom: 1px solid var(--border); }
.um-info-name { font-weight: 600; color: var(--text); font-size: 14px; }
.menu-btn {
  display: none; border: 1px solid var(--border); background: #fff; border-radius: 6px;
  width: 36px; height: 34px; font-size: 17px; line-height: 1; cursor: pointer; color: var(--text);
}

/* 内容区 */
.container { width: 100%; max-width: 1760px; margin: 0 auto; padding: 22px 22px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* 卡片 */
.card { background: #fff; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 18px; }
.card-hd { padding: 14px 20px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 15.5px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card-bd { padding: 20px; }
.card-bd.tight { padding: 8px 0; }

/* 工作台统计卡 */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 20px; display: flex; gap: 16px; align-items: center; }
.stat .ico { width: 52px; height: 52px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 25px; color: #fff; flex: none; }
.stat .num { font-size: 28px; font-weight: 700; line-height: 1.2; }
.stat .lbl { color: var(--muted); font-size: 14px; }
.bg-blue { background: var(--primary); } .bg-orange { background: var(--warning); }
.bg-red { background: var(--danger); } .bg-green { background: var(--success); }

/* 表格 */
table.grid { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.grid th, table.grid td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid th { background: #f8fafc; color: #475569; font-weight: 600; font-size: 14px; white-space: nowrap; }
table.grid tr:hover td { background: #f8faff; }
table.grid .empty { text-align: center; color: var(--muted); padding: 34px; }

/* 表单 */
.form-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.form-item { flex: 1; min-width: 190px; }
.form-item label { display: block; font-size: 14px; color: #374151; margin-bottom: 6px; }
.form-item label .req { color: var(--danger); }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=datetime-local], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid #cbd2dd; border-radius: 7px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.12); }
textarea { resize: vertical; min-height: 80px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

/* 按钮 */
.btn { display: inline-block; padding: 9px 18px; border-radius: 7px; border: 1px solid var(--primary);
  background: var(--primary); color: #fff; cursor: pointer; font-size: 15px; text-decoration: none; }
.btn:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn.secondary { background: #fff; color: #374151; border-color: #cbd2dd; }
.btn.secondary:hover { background: #f1f5f9; color: #374151; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.success { background: var(--success); border-color: var(--success); }
.btn.sm { padding: 5px 12px; font-size: 14px; }
.btn.ghost { background: transparent; color: var(--primary); border-color: transparent; }
.btn.ghost.danger { color: var(--danger); }

/* 列表行内操作（分配/转交/认领） */
.row-act { display: flex; gap: 6px; align-items: center; margin: 0; }
.sel-sm { width: auto; min-width: 96px; padding: 4px 8px; font-size: 13px; }

/* 复选框列 + 批量操作条 */
.col-check { width: 36px; text-align: center; }
.col-check input, td .row-ck { width: auto; margin: 0; cursor: pointer; }
.batchbar {
  display: none; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #eef4ff; border: 1px solid #c7d9fb; border-radius: 8px;
  padding: 10px 16px; margin-bottom: 14px; font-size: 14px;
}
.batchbar.show { display: flex; }
.batchbar .bc-count { font-weight: 600; color: #1e40af; }
.batchbar .btn { padding: 5px 14px; font-size: 14px; }
.row-op { color: #334155; }

/* 徽章 */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; background: #eef2f7; color: #475569; white-space: nowrap; }
.badge.blue { background: #e0ecff; color: #1e40af; }
.badge.green { background: #dcfce7; color: #166534; }
.badge.orange { background: #ffedd5; color: #9a3412; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.gray { background: #f1f5f9; color: #64748b; }
.badge.purple { background: #ede9fe; color: #5b21b6; }

/* 客户详情标签页 */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a { padding: 11px 18px; color: #475569; border-bottom: 2px solid transparent; margin-bottom: -2px; font-size: 15px; }
.tabs a:hover { color: var(--primary); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* 通用工具类 */
.gap { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.mono { font-family: Consolas, "Courier New", monospace; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.page-foot { color: var(--muted); }

/* 提示条（flash / 表单错误） */
.alert { padding: 11px 16px; border-radius: 8px; font-size: 14.5px; margin-bottom: 14px; border: 1px solid transparent; }
.alert.err { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.alert.ok { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.alert.warn { background: #ffedd5; color: #9a3412; border-color: #fed7aa; }
.alert.info { background: #e0f2fe; color: #075985; border-color: #bae6fd; }

/* 筛选栏 */
.filterbar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.filterbar .hint { flex-basis: 100%; }

/* 分页 */
.pager { display: flex; justify-content: center; align-items: center; gap: 6px; flex-wrap: wrap; margin: 18px 0 4px; font-size: 14px; }
.pager a, .pager span, .pager strong {
  min-width: 34px; height: 34px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 7px; background: #fff; color: #374151;
}
.pager a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.pager .on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.pager .muted, .pager .disabled { color: #9ca3af; background: #f8fafc; }

/* 登录页 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(135deg, #102a56 0%, #1a56db 100%); }
.login-box { width: 100%; max-width: 400px; background: #fff; border-radius: 12px; box-shadow: 0 20px 50px rgba(15,23,42,.25); padding: 36px 32px; }
.login-box h1 { margin: 0 0 6px; font-size: 22px; text-align: center; }
.login-box .sub { text-align: center; color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.login-box .btn { width: 100%; }

/* 弹窗（openModal/closeModal 配合 .show 与 display:flex） */
.modal-mask {
  display: none; position: fixed; inset: 0; z-index: 500;
  background: rgba(15,23,42,.45); align-items: center; justify-content: center; padding: 20px;
}
.modal-mask.show { display: flex; }
.modal {
  width: 100%; max-width: 520px; max-height: 90vh; display: flex; flex-direction: column;
  background: #fff; border-radius: 10px; box-shadow: 0 20px 50px rgba(15,23,42,.3); overflow: hidden;
}
.modal-hd { padding: 14px 20px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 15.5px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.modal-bd { padding: 20px; overflow-y: auto; }
.modal-ft { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

/* 标签徽章 + 勾选列表 */
.tag-badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; color: #fff; line-height: 1.6; }
.ck-list { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; }
.ck-line { display: flex; align-items: center; gap: 8px; padding: 6px 4px; font-size: 14px; cursor: pointer; border-radius: 6px; }
.ck-line:hover { background: #f8fafc; }
.ck-line input, .chk-line input { width: auto; margin: 0; cursor: pointer; }
.chk-line { display: flex; align-items: center; gap: 7px; font-size: 14.5px; color: #374151; cursor: pointer; }

/* 详情键值对（dl.kv 两列） */
dl.kv { display: grid; grid-template-columns: 120px 1fr; gap: 10px 16px; margin: 0; font-size: 14.5px; }
.kv dt { color: var(--muted); white-space: nowrap; }
.kv dd { margin: 0; word-break: break-all; }

/* 工作台两栏 + 跟进动态时间线 */
.dash-cols { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; }
.lead-cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.timeline { display: flex; flex-direction: column; gap: 14px; }
.tl-item { position: relative; padding-left: 16px; border-left: 2px solid var(--border); }
.tl-item.mail { border-left-color: var(--info); }
.tl-time { font-size: 12.5px; color: var(--muted); margin-bottom: 3px; }
.tl-title { font-size: 14.5px; line-height: 1.5; }

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

/* 邮件中心：三栏布局（左账号/文件夹，中列表，右读信） */
.mail-pane { display: flex; gap: 14px; align-items: flex-start; }
.mail-pane > * { min-width: 0; }
.mail-side { width: 220px; flex: none; display: flex; flex-direction: column; gap: 12px; }
.mail-compose-btn { text-align: center; }
.mail-acct, .mail-folders { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.mail-acct { max-height: 220px; overflow-y: auto; }
.mail-acct-item { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 7px; color: var(--text); font-size: 13px; }
.mail-acct-item:hover { background: #f1f5f9; text-decoration: none; }
.mail-acct-item.on { background: #eef4ff; color: var(--primary-dark); font-weight: 600; }
.mail-acct-item .badge { flex: none; }
.mail-acct-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-folder { display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 7px; color: var(--text); font-size: 14px; }
.mail-folder:hover { background: #f1f5f9; text-decoration: none; }
.mail-folder.on { background: var(--primary); color: #fff; }
.mail-folder.on .mf-count { color: rgba(255,255,255,.85); }
.mf-icon { width: 20px; text-align: center; flex: none; }
.mf-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mf-badge { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11.5px; padding: 1px 7px; flex: none; }
.mf-count { color: var(--muted); font-size: 12.5px; flex: none; }

.mail-list { flex: none; width: 400px; min-width: 0; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; }
.mail-search { display: flex; gap: 8px; margin-bottom: 10px; }
.mail-search input { flex: 1; min-width: 0; }
.mail-list-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.mail-list-tools form { margin: 0; }
.mail-items { min-height: 120px; }
.mail-item { display: flex; align-items: flex-start; gap: 10px; padding: 11px 10px; border-bottom: 1px solid var(--border); border-radius: 7px; cursor: pointer; }
.mail-item:hover { background: #f8faff; }
.mail-item.unread .mail-from, .mail-item.unread .mail-subject { font-weight: 600; }
.mail-item.mail-sel, .mail-item.mail-sel:hover { background: #eef4ff; }
.mail-from { width: 150px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.mail-subject { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.mail-meta { color: var(--muted); font-weight: 400; font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-time { margin-left: auto; flex: none; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.mail-badge { background: var(--primary); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; flex: none; }
.mail-att { color: var(--muted); font-size: 12.5px; flex: none; }

.mail-syncbar { display: flex; gap: 6px; justify-content: flex-end; margin-bottom: 8px; }

/* 客户列表关注星标（无边框小星星） */
.star-form { display: inline-block; line-height: 1; }
.star-btn { border: none; background: none; padding: 0 2px; cursor: pointer; font-size: 15px; line-height: 1; color: #cbd5e1; vertical-align: -1px; }
.star-btn:hover { color: #f59e0b; }
.star-btn.on { color: #f59e0b; }

.mail-detail { flex: 1.35; min-width: 0; background: #fff; border: 1px solid var(--border); border-radius: 10px; overflow-y: auto; }
.mail-readpane { padding: 20px; }
.mail-body { font-size: 14.5px; line-height: 1.7; word-break: break-word; overflow-wrap: anywhere; }
.mail-body img { max-width: 100%; height: auto; }
.mail-body table { max-width: 100%; }
.mail-body a { word-break: break-all; }

/* 邮件设置中心（模板/签名/账户/黑名单等） */
.ms-wrap { max-width: 1080px; }
.ms-nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 7px 9px; margin-bottom: 18px; }
.ms-nav a { padding: 8px 14px; border-radius: 7px; color: #475569; font-size: 14px; }
.ms-nav a:hover { background: #f1f5f9; color: var(--primary); text-decoration: none; }
.ms-nav a.on { background: var(--primary); color: #fff; }
.ms-back { margin-left: auto; font-size: 13.5px; }
.acct-title { font-size: 15px; font-weight: 600; }
.acct-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.test-tip { color: var(--muted); }

/* 邮件模板 / 签名列表行 */
.tpl-list, .sig-list { display: flex; flex-direction: column; }
.tpl-row, .sig-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 13px 4px; border-bottom: 1px solid var(--border); }
.tpl-row:last-child, .sig-row:last-child { border-bottom: none; }
.tpl-row-main, .sig-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.tpl-row-name, .sig-row-name { font-weight: 600; font-size: 14.5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tpl-preview, .sig-preview { color: var(--muted); font-size: 13px; line-height: 1.6; word-break: break-word; }
.tpl-row-act, .sig-row-act { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; flex: none; }
.sig-edit { margin-top: 14px; padding-top: 16px; border-top: 1px dashed var(--border); }

/* 签名富文本编辑器 */
.rte-toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px 8px; background: #f8fafc; border: 1px solid #cbd2dd; border-bottom: none; border-radius: 7px 7px 0 0; }
.rte-btn { border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 6px; min-width: 30px; height: 28px; padding: 0 8px; font-size: 13px; cursor: pointer; }
.rte-btn:hover { background: #eef4ff; border-color: #c7d9fb; }
.rte-editor { border: 1px solid #cbd2dd; border-radius: 0 0 7px 7px; background: #fff; padding: 10px 12px; min-height: 110px; max-height: 320px; overflow-y: auto; font-size: 14.5px; }
.rte-editor:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.12); }

/* 响应式 */
@media (max-width: 1100px) {
  .mail-side { width: 180px; }
  .mail-list { width: 320px; }
  .mail-from { width: 110px; }
}
@media (max-width: 900px) {
  .menu-btn { display: inline-block; }
  .sidebar { transform: translateX(-100%); transition: transform .18s ease; }
  .sidebar.show { transform: none; box-shadow: 0 0 40px rgba(15,23,42,.35); }
  .sidebar-mask.show { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 150; }
  .mainwrap { margin-left: 0; }
  .hide-sm { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-cols, .lead-cols { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; gap: 12px; }
  .form-item { min-width: 0; }
  .mail-pane { flex-direction: column; }
  .mail-side { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: flex-start; }
  .mail-acct, .mail-folders { flex: 1; min-width: 200px; max-height: none; }
}
@media (max-width: 640px) {
  .stat-grid { grid-template-columns: 1fr; }
  .container { padding: 14px 14px 50px; }
  .mail-from { width: 84px; }
  .modal-ft { justify-content: stretch; }
  .modal-ft .btn { flex: 1; }
}
