/* ========== 基础 ========== */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1e293b;
  --text-2: #64748b;
  --border: #e2e8f0;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --green: #16a34a;
  --green-light: #dcfce7;
  --orange: #ea580c;
  --orange-light: #ffedd5;
  --red: #dc2626;
  --red-light: #fee2e2;
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
#app { display: flex; height: 100vh; overflow: hidden; }

/* ========== 侧边栏 ========== */
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.logo-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff; font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: .5px;
}
.logo-mark.logo-img { background: #fff; padding: 3px; }
.logo-mark.logo-img img { width: 100%; height: 100%; object-fit: contain; }
.logo-title { color: #fff; font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.logo-sub { font-size: 10px; opacity: .55; margin-top: 2px; }
.nav { flex: 1; padding: 14px 10px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 2px;
  border-radius: 8px; cursor: pointer;
  color: var(--sidebar-text); font-size: 13.5px;
  transition: all .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .ico { font-size: 15px; width: 20px; text-align: center; }
.sidebar-footer {
  padding: 14px 18px; font-size: 11px;
  border-top: 1px solid rgba(255,255,255,.07);
  display: flex; align-items: center; gap: 7px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; }

/* ========== 主区域 ========== */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: 60px; flex-shrink: 0;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
}
.page-title { font-size: 17px; font-weight: 600; }
.topbar-actions { display: flex; gap: 10px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 5px; border-radius: 999px;
  background: #f1f5f9; cursor: pointer; font-size: 13px;
  transition: background .15s;
}
.user-chip:hover { background: var(--primary-light); }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}
.user-role { font-size: 11px; color: var(--text-2); background: #fff; padding: 1px 8px; border-radius: 999px; }
.content { flex: 1; overflow-y: auto; padding: 22px 24px; }

/* ========== 通用组件 ========== */
.btn {
  border: none; cursor: pointer;
  padding: 8px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 13px; padding: 2px 6px; }
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--red); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 18px 20px;
}
.card-title { font-size: 14.5px; font-weight: 600; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }

.badge {
  display: inline-block; padding: 2px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 500;
}
.badge-blue { background: var(--primary-light); color: var(--primary-dark); }
.badge-green { background: var(--green-light); color: var(--green); }
.badge-orange { background: var(--orange-light); color: var(--orange); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-purple { background: var(--purple-light); color: var(--purple); }
.badge-gray { background: #f1f5f9; color: var(--text-2); }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; padding: 10px 12px;
  font-size: 12px; color: var(--text-2); font-weight: 500;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl td { padding: 11px 12px; border-bottom: 1px solid #f1f5f9; font-size: 13px; }
.tbl tr:hover td { background: #f8fafc; }
.tbl tr.clickable { cursor: pointer; }

/* ========== 仪表盘 ========== */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.kpi {
  background: var(--card); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  padding: 18px 20px;
  display: flex; align-items: center; gap: 14px;
}
.kpi-ico {
  width: 46px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.kpi-val { font-size: 24px; font-weight: 700; line-height: 1.2; }
.kpi-label { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 18px; }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 300px; }

.funnel-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.funnel-name { width: 70px; font-size: 12.5px; color: var(--text-2); flex-shrink: 0; }
.funnel-bar { flex: 1; height: 22px; background: #f1f5f9; border-radius: 6px; overflow: hidden; }
.funnel-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, #60a5fa, #2563eb); transition: width .4s; }
.funnel-val { width: 110px; font-size: 12px; color: var(--text-2); text-align: right; flex-shrink: 0; }

/* ========== 工具栏 / 筛选 ========== */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar .spacer { flex: 1; }
.input, .select, .textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); }
.textarea { resize: vertical; min-height: 80px; }
.input-sm { padding: 6px 10px; font-size: 12.5px; }

/* ========== 模态框 / 抽屉 ========== */
.modal-mask, .drawer-mask {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .45);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
}
.modal-mask.show, .drawer-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: 14px;
  width: 560px; max-width: 92vw; max-height: 88vh;
  display: flex; flex-direction: column;
  animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-header, .drawer-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 22px; border-bottom: 1px solid var(--border);
}
.modal-header h3, .drawer-header h3 { font-size: 15.5px; }
.modal-close {
  border: none; background: none; font-size: 20px;
  color: var(--text-2); cursor: pointer; line-height: 1;
}
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-footer {
  padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 520px; max-width: 94vw;
  background: #fff; display: flex; flex-direction: column;
  animation: slide .2s ease;
}
@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px 22px; }
.drawer-mask { align-items: stretch; justify-content: flex-end; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.form-item { display: flex; flex-direction: column; gap: 5px; }
.form-item.full { grid-column: 1 / -1; }
.form-item label { font-size: 12.5px; color: var(--text-2); }
.form-item label .req { color: var(--red); }

/* ========== 客户详情 ========== */
.detail-section { margin-bottom: 22px; }
.detail-section h4 {
  font-size: 13px; color: var(--text-2);
  margin-bottom: 10px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; font-size: 13px; }
.info-grid .k { color: var(--text-2); }
.timeline-item {
  padding: 10px 12px; background: #f8fafc;
  border-radius: 8px; margin-bottom: 8px; font-size: 12.5px;
  border-left: 3px solid var(--primary);
}
.timeline-item .t { color: var(--text-2); font-size: 11.5px; margin-bottom: 3px; }

/* ========== 产品清单 ========== */
.cat-layout { display: grid; grid-template-columns: 200px 1fr; gap: 16px; }
.cat-list .cat-item {
  padding: 10px 14px; border-radius: 8px; cursor: pointer;
  font-size: 13.5px; margin-bottom: 4px;
  display: flex; justify-content: space-between; align-items: center;
  color: var(--text-2);
}
.cat-list .cat-item:hover { background: #f1f5f9; }
.cat-list .cat-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 500; }
.cat-list .cat-item .cnt { font-size: 11px; opacity: .7; }
.prod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.prod-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  transition: all .15s;
}
.prod-card:hover { border-color: var(--primary); box-shadow: 0 4px 12px rgba(37, 99, 235, .08); }
.prod-card .pn { font-weight: 600; font-size: 14px; margin-bottom: 4px; display: flex; justify-content: space-between; align-items: center; }
.prod-card .ps { font-size: 12px; color: var(--text-2); min-height: 32px; line-height: 1.5; }
.prod-card .pf { margin-top: 10px; display: flex; justify-content: space-between; align-items: center; }
.prod-card .price { color: var(--red); font-weight: 700; font-size: 15px; }
.prod-card .price small { font-weight: 400; font-size: 11px; color: var(--text-2); }
.prod-card .acts { display: flex; gap: 2px; }
.tag-custom { font-size: 10px; background: var(--green-light); color: var(--green); border-radius: 4px; padding: 1px 6px; font-weight: 400; }

/* ========== 企业微信 / 设置 ========== */
.set-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.tip-box {
  background: #eff6ff; border: 1px solid #bfdbfe;
  border-radius: 10px; padding: 14px 16px;
  font-size: 12.5px; line-height: 1.8; color: #1e40af;
}
.tip-box code { background: #dbeafe; padding: 1px 6px; border-radius: 4px; font-size: 11.5px; }
.switch-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.switch-row:last-child { border-bottom: none; }
.switch-row .lbl { font-size: 13px; }
.switch-row .desc { font-size: 11.5px; color: var(--text-2); margin-top: 2px; }
.switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; border-radius: 22px;
  background: #cbd5e1; cursor: pointer; transition: .2s;
}
.slider::before {
  content: ""; position: absolute;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; top: 2px; left: 2px; transition: .2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* ========== Toast ========== */
.toast-wrap { position: fixed; top: 20px; right: 20px; z-index: 300; }
.toast {
  background: #fff; border: 1px solid var(--border);
  border-left: 4px solid var(--green);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(15,23,42,.12);
  padding: 11px 18px; margin-bottom: 10px;
  font-size: 13px; animation: pop .18s ease;
}
.toast.error { border-left-color: var(--red); }

.empty { text-align: center; color: var(--text-2); padding: 40px 0; font-size: 13px; }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3, .set-grid { grid-template-columns: 1fr; }
}
