/* ============================================================
   智能客服系统 · 后台统一样式
   ============================================================ */
:root {
  --primary: #3370ff;
  --primary-dark: #2860e0;
  --primary-light: #eaf1ff;
  --success: #00b42a;
  --success-light: #e8ffea;
  --warning: #ff7d00;
  --warning-light: #fff7e8;
  --danger: #f53f3f;
  --danger-light: #ffece8;
  --text-1: #1d2129;
  --text-2: #4e5969;
  --text-3: #86909c;
  --border: #e5e6eb;
  --border-light: #f2f3f5;
  --bg: #f5f7fa;
  --white: #ffffff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0, 0, 0, .06);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, .12);
  --sidebar-w: 216px;
  --header-h: 58px;
}

* { box-sizing: border-box; }
html { height: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
ul { margin: 0; padding: 0; list-style: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---------------------- 布局 ---------------------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: #1d2939; color: #c9d0da;
  position: fixed; top: 0; left: 0; bottom: 0; display: flex; flex-direction: column; z-index: 100;
}
.sidebar .brand {
  height: var(--header-h); display: flex; align-items: center; gap: 10px;
  padding: 0 20px; font-size: 16px; font-weight: 600; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand .logo {
  width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, #3370ff, #00b8d9);
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.sidebar nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.sidebar nav .group-title { font-size: 12px; color: #6b7688; padding: 14px 12px 6px; letter-spacing: .5px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: #c9d0da; font-size: 14px; margin-bottom: 2px; transition: all .15s;
}
.sidebar nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar nav a .icon { width: 18px; text-align: center; font-size: 15px; }
.sidebar nav a .badge-dot {
  margin-left: auto; background: var(--danger); color: #fff; border-radius: 10px;
  font-size: 11px; padding: 1px 6px; min-width: 18px; text-align: center;
}
.sidebar .footer { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #6b7688; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--header-h); background: var(--white); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 50;
}
.topbar h2 { font-size: 17px; }
.topbar .spacer { flex: 1; }
.user-menu { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px 10px; border-radius: 8px; }
.user-menu:hover { background: var(--border-light); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; flex: none;
}
.content { padding: 20px 24px 40px; flex: 1; }

/* ---------------------- 卡片 ---------------------- */
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; }
.card-head {
  padding: 16px 20px; border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; gap: 12px;
}
.card-head h3 { font-size: 15px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 20px; }
.card-body.np { padding: 0; }

/* ---------------------- 统计卡片 ---------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 18px; }
.stat {
  background: var(--white); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.stat .label { color: var(--text-3); font-size: 13px; margin-bottom: 8px; }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.stat .sub { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.stat .sub .up { color: var(--success); }
.stat .sub .down { color: var(--danger); }
.stat .ico {
  position: absolute; right: 16px; top: 16px; width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.ico.blue { background: var(--primary-light); color: var(--primary); }
.ico.green { background: var(--success-light); color: var(--success); }
.ico.orange { background: var(--warning-light); color: var(--warning); }
.ico.red { background: var(--danger-light); color: var(--danger); }

/* ---------------------- 按钮 ---------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--white); color: var(--text-1); cursor: pointer; font-size: 14px;
  transition: all .15s; white-space: nowrap; line-height: 1.4;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { opacity: .9; color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--border-light); color: var(--text-1); }
.btn.sm { padding: 5px 11px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------------- 表单 ---------------------- */
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.form-row .tip { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.input, .select, .textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--white); color: var(--text-1); transition: border-color .15s; outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(51,112,255,.1); }
.textarea { resize: vertical; min-height: 90px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------------------- 表格 ---------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; padding: 12px 16px; background: #fafbfc; color: var(--text-2);
  font-weight: 500; font-size: 13px; border-bottom: 1px solid var(--border-light); white-space: nowrap;
}
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
table.data tr:hover td { background: #fafbfc; }
table.data .actions { display: flex; gap: 6px; }
.empty { text-align: center; padding: 50px 20px; color: var(--text-3); }
.empty .big { font-size: 40px; margin-bottom: 10px; opacity: .4; }

/* ---------------------- 标签 ---------------------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; line-height: 18px;
  background: var(--border-light); color: var(--text-2);
}
.badge.primary { background: var(--primary-light); color: var(--primary); }
.badge.success { background: var(--success-light); color: var(--success); }
.badge.warning { background: var(--warning-light); color: var(--warning); }
.badge.danger { background: var(--danger-light); color: var(--danger); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.online { background: var(--success); }
.dot.busy { background: var(--warning); }
.dot.offline { background: var(--text-3); }

/* ---------------------- 分页 ---------------------- */
.pagination { display: flex; gap: 6px; justify-content: flex-end; padding: 16px 20px; align-items: center; }
.pagination a, .pagination span {
  min-width: 34px; height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-2); background: #fff;
}
.pagination a:hover { border-color: var(--primary); color: var(--primary); }
.pagination .current { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination .info { margin-right: auto; color: var(--text-3); font-size: 13px; border: none; }

/* ---------------------- 模态框 ---------------------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; visibility: hidden; transition: opacity .2s;
}
.modal-mask.open { opacity: 1; visibility: visible; }
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 560px; max-height: 88vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg); transform: translateY(12px); transition: transform .2s;
}
.modal-mask.open .modal { transform: translateY(0); }
.modal.wide { max-width: 820px; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border-light); display: flex; align-items: center; }
.modal-head h3 { font-size: 16px; }
.modal-head .close { margin-left: auto; cursor: pointer; color: var(--text-3); font-size: 20px; line-height: 1; background: none; border: none; }
.modal-body { padding: 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border-light); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------------------- 提示 ---------------------- */
#toast-box { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 3000; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.toast {
  background: #fff; border-radius: 8px; padding: 10px 20px; box-shadow: var(--shadow-lg);
  font-size: 14px; display: flex; align-items: center; gap: 8px; animation: toastIn .25s; border-left: 3px solid var(--primary);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert.info { background: var(--primary-light); color: var(--primary-dark); }
.alert.success { background: var(--success-light); color: #00771d; }
.alert.warning { background: var(--warning-light); color: #b25c00; }
.alert.danger { background: var(--danger-light); color: #c0291f; }

/* ---------------------- 工具类 ---------------------- */
.flex { display: flex; align-items: center; }
.gap8 { gap: 8px; } .gap12 { gap: 12px; } .gap16 { gap: 16px; }
.spacer { flex: 1; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; } .mb12 { margin-bottom: 12px; } .mb16 { margin-bottom: 16px; } .mb20 { margin-bottom: 20px; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid2, .grid3, .form-grid { grid-template-columns: 1fr; } }

/* ---------------------- 图表 ---------------------- */
.chart-box { width: 100%; height: 260px; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.bar-row .name { width: 80px; color: var(--text-2); flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track { flex: 1; background: var(--border-light); border-radius: 4px; height: 18px; overflow: hidden; }
.bar-row .fill { height: 100%; background: linear-gradient(90deg, #3370ff, #5b8cff); border-radius: 4px; transition: width .4s; }
.bar-row .val { width: 50px; text-align: right; color: var(--text-2); flex: none; }

/* ---------------------- 登录页 ---------------------- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(135deg, #1d2939 0%, #2b4a8b 55%, #3370ff 100%);
}
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 40px 34px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card h1 { font-size: 22px; text-align: center; margin-bottom: 6px; }
.login-card .sub { text-align: center; color: var(--text-3); font-size: 13px; margin-bottom: 28px; }
.login-card .logo-big {
  width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 18px;
  background: linear-gradient(135deg, #3370ff, #00b8d9); display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: #fff;
}

/* ---------------------- 视觉细节 ---------------------- */
.btn { border-radius: 8px; font-weight: 500; }
.btn.primary { box-shadow: 0 2px 8px rgba(51, 112, 255, .22); }
.btn:active { transform: translateY(1px); }
.card { border: 1px solid rgba(229, 230, 235, .7); box-shadow: 0 1px 3px rgba(15, 23, 42, .04); }
.stat { border: 1px solid rgba(229, 230, 235, .7); box-shadow: 0 1px 3px rgba(15, 23, 42, .04); }
table.data th { background: #f7f9fc; font-weight: 600; }
table.data tbody tr:last-child td { border-bottom: none; }
.badge { font-weight: 500; }

/* ---------------------- 移动端适配 ---------------------- */
.nav-toggle {
  display: none; width: 40px; height: 40px; flex: none; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: #fff; border-radius: 8px;
  font-size: 16px; line-height: 1; color: var(--text-2); cursor: pointer;
}
.nav-toggle:active { background: var(--border-light); }
.nav-mask { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 99; }

/* 断点需与 desk.css 的 900px 保持一致：否则 769~900px 之间侧边栏会常驻显示并挤压内容区 */
@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; }
  /* 侧边栏改为抽屉，避免在小屏上挤占内容区 */
  .sidebar {
    width: 236px; transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 8px 0 28px rgba(0, 0, 0, .25);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .nav-mask { display: block; }

  .main { margin-left: 0; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar h2 { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .user-menu { padding: 6px; }
  .topbar .user-menu > span:not(.avatar) { display: none; }
  .content { padding: 14px 14px 36px; }

  .card-head { padding: 13px 14px; flex-wrap: wrap; }
  .card-body { padding: 14px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .stat { padding: 14px 16px; }
  .stat .value { font-size: 22px; }
  .stat .ico { display: none; }

  .modal { max-height: 92vh; }
  .modal-head, .modal-body, .modal-foot { padding-left: 16px; padding-right: 16px; }
  /* 触屏点击目标不小于 40px */
  .modal-head .close { min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; margin-right: -8px; }
  .modal-foot .btn { min-height: 40px; padding-left: 16px; padding-right: 16px; }
  .card-head .btn, .card-head .input, .card-head .select { min-height: 40px; }
  .pagination { flex-wrap: wrap; padding: 12px 14px; }
  table.data th, table.data td { padding: 10px 12px; white-space: nowrap; }
  .login-page { padding: 14px; }
  .login-card { padding: 28px 22px; }

  /* 表单控件不小于 16px，避免 iOS 聚焦时自动放大整页 */
  .input, .select, .textarea { font-size: 16px; }
}

@media (max-width: 400px) {
  .stat-grid { grid-template-columns: 1fr; }
}