:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1f2329;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 18px; margin: 6px 0 0; }

/* 登录 */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--card); padding: 36px; border-radius: 12px; width: 360px;
  border: 1px solid var(--border); box-shadow: 0 8px 28px rgba(15, 23, 42, .06);
}
.login-card h1 { font-size: 18px; margin: 0 0 8px; }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  margin: 12px 0; font-size: 14px;
}
.login-card .btn { width: 100%; }

/* 布局 */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 208px; background: #0f172a; color: #cbd5e1;
  display: flex; flex-direction: column; padding: 20px 0;
}
.brand { font-size: 16px; font-weight: 600; color: #fff; padding: 0 20px 18px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  color: #cbd5e1; text-decoration: none; padding: 11px 20px; font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar nav a.active { background: rgba(37, 99, 235, .18); color: #fff; border-left-color: var(--primary); }
.sidebar-foot { margin-top: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.badge {
  font-size: 12px; padding: 5px 9px; border-radius: 999px;
  background: rgba(255, 255, 255, .1); color: #e2e8f0; display: inline-block; text-align: center;
}
.main { flex: 1; padding: 24px 28px; max-width: 1280px; }

/* 头部/筛选 */
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.view-head h2 { margin: 0; font-size: 20px; font-weight: 600; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
select, input {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
  background: var(--card); color: var(--text); outline: none;
}
select:focus, input:focus { border-color: var(--primary); }

/* 按钮 */
.btn {
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--card); cursor: pointer; font-size: 13px; color: var(--text);
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.small { padding: 5px 10px; font-size: 12px; }

/* 卡片 */
.card, .chart-card, .muted-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 20px; margin-bottom: 18px;
}
.chart-card h3, .card h3, .muted-card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.muted-card { background: #f8fafc; }
.tips { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.9; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px;
}
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kpi .value.pos { color: var(--green); }
.kpi .value.neg { color: var(--red); }

/* 表格 */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; color: var(--muted); font-weight: 500; padding: 10px 12px;
  border-bottom: 1px solid var(--border); white-space: nowrap; background: #fafbfc;
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:hover { background: #f8fafc; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--primary); }
.table th.sortable.asc::after { content: " ↑"; color: var(--primary); }
.table th.sortable.desc::after { content: " ↓"; color: var(--primary); }
.amount { font-variant-numeric: tabular-nums; }

/* 状态徽标 */
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.tag.green { background: #dcfce7; color: var(--green); }
.tag.red { background: #fee2e2; color: var(--red); }
.tag.amber { background: #fef3c7; color: var(--amber); }
.tag.gray { background: #f1f5f9; color: var(--muted); }
.tag.blue { background: #dbeafe; color: var(--primary); }

/* 分页 */
.pager { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding-top: 12px; }
.pager button { min-width: 32px; }
.pager .info { color: var(--muted); margin-right: auto; font-size: 12px; }

/* 图表 */
.chart { height: 320px; }

/* 弹窗 */
.modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .35);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-card {
  background: var(--card); border-radius: 12px; padding: 22px 24px; width: 420px;
  max-height: 86vh; overflow: auto;
}
.modal-card h3 { margin: 0 0 14px; }
.modal-card label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.modal-card label input, .modal-card label select { width: 100%; margin-top: 5px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* toast */
.toast {
  position: fixed; right: 24px; bottom: 24px; background: #0f172a; color: #fff;
  padding: 12px 18px; border-radius: 10px; font-size: 13px; z-index: 99;
}
.toast.error { background: var(--red); }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 10px 14px; }
  .sidebar nav { flex-direction: row; overflow-x: auto; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .main { padding: 16px; }
}

/* 客服聊天 */
.kf-wrap { display: grid; grid-template-columns: 300px 1fr; gap: 14px; margin-bottom: 18px; }
.kf-sessions { padding: 12px; max-height: 560px; overflow: auto; }
.kf-sessions h3 { margin: 4px 8px 10px; font-size: 14px; }
.kf-session { padding: 10px 12px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.kf-session:hover { background: #f8fafc; }
.kf-session.active { background: #eff6ff; border-color: #bfdbfe; }
.kf-session-top { display: flex; justify-content: space-between; font-size: 12px; }
.kf-session-last { font-size: 12px; color: var(--muted); margin: 4px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kf-session-meta { display: flex; gap: 8px; align-items: center; font-size: 11px; }
.kf-chat { display: flex; flex-direction: column; height: 560px; padding: 0; overflow: hidden; }
.kf-chat-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.kf-messages { flex: 1; overflow-y: auto; padding: 18px; background: #fafbfc; }
.kf-msg { margin-bottom: 14px; display: flex; flex-direction: column; }
.kf-msg.in { align-items: flex-start; }
.kf-msg.out { align-items: flex-end; }
.kf-bubble {
  max-width: 62%; padding: 9px 13px; border-radius: 10px; font-size: 13px; line-height: 1.6;
  background: #fff; border: 1px solid var(--border); word-break: break-word;
}
.kf-msg.out .kf-bubble { background: #2563eb; color: #fff; border-color: #2563eb; }
.kf-bubble.failed { background: #fee2e2; border-color: #fca5a5; color: var(--red); }
.kf-type { display: inline-block; margin-left: 6px; font-size: 11px; opacity: 0.75; }
.kf-time { font-size: 11px; margin-top: 3px; }
.kf-input { display: flex; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--border); }
.kf-input textarea { flex: 1; resize: none; font-family: inherit; }
@media (max-width: 900px) { .kf-wrap { grid-template-columns: 1fr; } }
