/* ============================================================
   SCRM 客户管理系统 · 设计系统与样式
   高端质感：深色渐变侧边栏 + 紫罗兰主色 + 柔和阴影 + 玻璃拟态
   ============================================================ */
:root {
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --primary-3: #d946ef;
  --primary-dark: #4f46e5;
  --primary-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #a855f7 100%);
  --soft: #eef2ff;
  --soft-2: #f5f3ff;

  --text: #111827;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --bg: #f6f7fb;
  --card: #ffffff;
  --border: #eceef4;

  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --blue: #0ea5e9;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 6px 22px rgba(17, 24, 39, .07);
  --shadow-lg: 0 24px 60px rgba(17, 24, 39, .16);
  --sidebar-w: 236px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #d5d8e2; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #bfc3d1; }

/* ---------------- 登录页 ---------------- */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; overflow: hidden;
  background: radial-gradient(1200px 600px at 12% 10%, #312e81 0%, transparent 55%),
              radial-gradient(1000px 700px at 88% 90%, #7c3aed 0%, transparent 55%),
              linear-gradient(135deg, #0b1020 0%, #171a35 60%, #241b45 100%);
}
.login-page::before, .login-page::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(60px); opacity: .45;
}
.login-page::before { width: 380px; height: 380px; background: #6366f1; top: -90px; left: -60px; }
.login-page::after { width: 460px; height: 460px; background: #a855f7; bottom: -140px; right: -100px; }
.login-card {
  position: relative; z-index: 2; width: 400px; max-width: 100%; border-radius: 24px; padding: 40px 34px;
  background: rgba(255, 255, 255, .09); border: 1px solid rgba(255, 255, 255, .18);
  box-shadow: var(--shadow-lg); backdrop-filter: blur(22px); -webkit-backdrop-filter: blur(22px);
  animation: rise .5s cubic-bezier(.2, .8, .2, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.login-logo {
  width: 54px; height: 54px; border-radius: 15px; display: grid; place-items: center; font-size: 26px;
  background: var(--primary-grad); box-shadow: 0 10px 26px rgba(99, 102, 241, .45); margin-bottom: 18px;
}
.login-card h1 { margin: 0; color: #fff; font-size: 23px; letter-spacing: .5px; }
.login-card .sub { color: rgba(255, 255, 255, .62); margin: 6px 0 26px; font-size: 13px; }
.login-field { margin-bottom: 15px; }
.login-field label { display: block; font-size: 12.5px; color: rgba(255, 255, 255, .7); margin-bottom: 7px; }
.login-input {
  width: 100%; height: 46px; padding: 0 15px; border-radius: 12px; color: #fff; font-size: 15px;
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .2); outline: none; transition: .2s;
}
.login-input::placeholder { color: rgba(255, 255, 255, .38); }
.login-input:focus { border-color: #a5b4fc; background: rgba(255, 255, 255, .16); box-shadow: 0 0 0 4px rgba(129, 140, 248, .22); }
.login-btn {
  width: 100%; height: 48px; margin-top: 10px; border: none; border-radius: 12px; cursor: pointer;
  color: #fff; font-size: 15px; font-weight: 600; letter-spacing: 4px; background: var(--primary-grad);
  box-shadow: 0 12px 26px rgba(99, 102, 241, .42); transition: .2s;
}
.login-btn:hover { transform: translateY(-1px); box-shadow: 0 16px 32px rgba(99, 102, 241, .5); }
.login-btn:disabled { opacity: .7; cursor: not-allowed; transform: none; }
.login-err { color: #fca5a5; font-size: 12.5px; height: 18px; margin-top: 12px; text-align: center; }
.login-tip { margin-top: 22px; font-size: 12px; color: rgba(255, 255, 255, .45); text-align: center; line-height: 1.8; }

/* ---------------- 应用骨架 ---------------- */
.shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; display: flex; flex-direction: column; color: #c7cbe0;
  background: linear-gradient(180deg, #0b1020 0%, #141a33 55%, #1b1733 100%);
  border-right: 1px solid rgba(255, 255, 255, .06);
}
.brand { padding: 22px 20px 16px; display: flex; align-items: center; gap: 11px; }
.brand .logo {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 19px;
  background: var(--primary-grad); box-shadow: 0 8px 20px rgba(99, 102, 241, .4);
}
.brand b { color: #fff; font-size: 15.5px; letter-spacing: .4px; }
.brand small { display: block; color: #7c85a8; font-size: 11px; letter-spacing: 1px; margin-top: 1px; }
.nav { flex: 1; padding: 8px 10px; overflow-y: auto; }
.nav-title { padding: 14px 12px 6px; font-size: 11px; color: #5f6885; letter-spacing: 1.2px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 11px; cursor: pointer;
  color: #b6bcd6; font-size: 14px; margin-bottom: 3px; transition: .18s; position: relative;
}
.nav-item .ni { width: 20px; text-align: center; font-size: 15px; }
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-item.active { background: var(--primary-grad); color: #fff; font-weight: 600; box-shadow: 0 8px 20px rgba(99, 102, 241, .35); }
.sidebar-foot { padding: 14px 16px; border-top: 1px solid rgba(255, 255, 255, .07); }
.me { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.me .avatar {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #fff;
  font-weight: 600; background: var(--primary-grad); flex-shrink: 0;
}
.me .nm { color: #fff; font-size: 13.5px; }
.me .rl { color: #7c85a8; font-size: 11.5px; }
.ghost-btn {
  width: 100%; height: 34px; border-radius: 9px; cursor: pointer; font-size: 13px; margin-top: 6px;
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .14); color: #d6d9e8;
}
.ghost-btn:hover { background: rgba(255, 255, 255, .12); }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar {
  height: 64px; flex-shrink: 0; display: flex; align-items: center; gap: 14px; padding: 0 24px;
  background: rgba(255, 255, 255, .82); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
}
.topbar h2 { margin: 0; font-size: 18px; font-weight: 700; }
.topbar .sp { flex: 1; }
.view { flex: 1; overflow-y: auto; padding: 24px; scroll-behavior: smooth; }
.view-inner { max-width: 1280px; margin: 0 auto; animation: fadeUp .3s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------- 通用控件 ---------------- */
.input, select.input, textarea.input {
  height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; outline: none; transition: .16s; width: 100%;
}
textarea.input { height: auto; padding: 9px 12px; resize: vertical; min-height: 74px; }
.input:focus, select.input:focus, textarea.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99, 102, 241, .14); }
select.input { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%239ca3af' stroke-width='1.6'/></svg>"); background-repeat: no-repeat; background-position: right 11px center; padding-right: 30px; }
.btn {
  height: 38px; padding: 0 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); cursor: pointer;
  background: #fff; font-size: 13.5px; white-space: nowrap; transition: .16s; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
.btn:hover { border-color: #d5d8e4; background: #fafbff; }
.btn.primary { background: var(--primary-grad); border: none; color: #fff; box-shadow: 0 8px 18px rgba(99, 102, 241, .32); }
.btn.primary:hover { transform: translateY(-1px); box-shadow: 0 12px 24px rgba(99, 102, 241, .42); }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.sm { height: 31px; padding: 0 11px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .input { width: auto; min-width: 150px; }
.grow { flex: 1; }

/* ---------------- 数据卡片 ---------------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
  background: var(--card); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm);
  border: 1px solid var(--border); position: relative; overflow: hidden; transition: .2s;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat .k { color: var(--text-2); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.stat .k .ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--soft); font-size: 15px; }
.stat .v { font-size: 28px; font-weight: 700; margin-top: 10px; letter-spacing: -.5px; }
.stat .v small { font-size: 13px; font-weight: 500; color: var(--text-3); margin-left: 4px; }
.stat .d { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.stat.accent { background: var(--primary-grad); border: none; color: #fff; }
.stat.accent .k, .stat.accent .d { color: rgba(255, 255, 255, .82); }
.stat.accent .k .ic { background: rgba(255, 255, 255, .18); }

/* ---------------- 面板 / 表格 ---------------- */
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--border); overflow: hidden; margin-bottom: 20px; }
.panel-head { padding: 15px 20px; font-weight: 600; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.panel-head .sp { flex: 1; }
.panel-body { padding: 18px 20px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid #f2f4f8; white-space: nowrap; }
th { background: #fafbff; color: var(--text-2); font-weight: 600; font-size: 12.5px; }
tbody tr { transition: background .14s; }
tbody tr:hover { background: #f8faff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; color: var(--text-3); padding: 54px 12px; }
.empty .ic { font-size: 40px; opacity: .5; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 13px 18px; color: var(--text-2); font-size: 13px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; padding: 3px 10px; border-radius: 999px; background: var(--soft); color: var(--primary-dark); }
.chip.big { font-size: 12.5px; padding: 5px 13px; }
.tag { display: inline-block; font-size: 11.5px; padding: 3px 10px; border-radius: 999px; color: #fff; margin-right: 5px; }
.badge { display: inline-block; font-size: 11.5px; padding: 3px 10px; border-radius: 999px; background: var(--soft); color: var(--primary-dark); font-weight: 500; }
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.warn { background: #fef3c7; color: #b45309; }
.badge.danger { background: #fee2e2; color: #b91c1c; }
.badge.blue { background: #e0f2fe; color: #0369a1; }
.muted { color: var(--text-3); }
.link { color: var(--primary); cursor: pointer; font-weight: 500; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--red); }
.avatar-sm { width: 30px; height: 30px; border-radius: 9px; display: inline-grid; place-items: center; color: #fff; font-size: 12px; font-weight: 600; background: var(--primary-grad); vertical-align: middle; }
.cell-flex { display: flex; align-items: center; gap: 9px; }

/* ---------------- 图表（纯 CSS） ---------------- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 200px; padding-top: 24px; }
.bars .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 0; }
.bars .bar { width: 70%; max-width: 22px; border-radius: 5px 5px 0 0; background: var(--primary-grad); min-height: 2px; position: relative; transition: .2s; }
.bars .bar.b2 { background: linear-gradient(180deg, #fbbf24, #f59e0b); }
.bars .bar:hover { filter: brightness(1.08); }
.bars .cap { font-size: 10.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; }
.bar-pair { display: flex; align-items: flex-end; justify-content: center; gap: 3px; width: 100%; height: 100%; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); padding: 10px 2px 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.progress { height: 8px; border-radius: 6px; background: #eef0f6; overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 6px; background: var(--primary-grad); }
.donut-row { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; font-size: 13px; }
.donut-row .nm { min-width: 78px; color: var(--text-2); }
.donut-row .bar-bg { flex: 1; height: 9px; border-radius: 6px; background: #eef0f6; overflow: hidden; }
.donut-row .bar-bg > i { display: block; height: 100%; border-radius: 6px; }
.donut-row .val { min-width: 42px; text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------------- 看板 ---------------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.kanban .kb-col { min-width: 262px; flex: 1; background: #f2f3f9; border-radius: 14px; padding: 12px; }
.kb-col .kb-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 13.5px; margin-bottom: 4px; }
.kb-col .kb-sum { font-size: 12px; color: var(--text-3); margin-bottom: 10px; }
.kb-card { background: #fff; border-radius: 12px; padding: 13px 14px; margin-bottom: 10px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); cursor: pointer; transition: .18s; }
.kb-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kb-card b { font-size: 13.5px; }
.kb-card .amt { color: var(--primary-dark); font-weight: 700; margin-top: 6px; }

/* ---------------- 抽屉 / 弹窗 ---------------- */
.drawer-mask { position: fixed; inset: 0; background: rgba(15, 17, 32, .45); backdrop-filter: blur(2px); z-index: 50; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 560px; max-width: 100%; background: #fff; z-index: 51;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slideIn .28s cubic-bezier(.2, .8, .2, 1);
}
@keyframes slideIn { from { transform: translateX(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.drawer-head h3 { margin: 0; font-size: 17px; flex: 1; }
.drawer-body { flex: 1; overflow-y: auto; padding: 22px 24px; }
.drawer-foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.icon-btn { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border); background: #fff; cursor: pointer; display: grid; place-items: center; font-size: 15px; }
.icon-btn:hover { background: #f6f7fb; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.field .req { color: var(--red); }
.section-title { font-size: 13px; font-weight: 600; color: var(--text); margin: 22px 0 12px; padding-left: 10px; border-left: 3px solid var(--primary); }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 10px 12px; font-size: 13.5px; }
.kv .k { color: var(--text-3); }
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 2px; background: #e9ebf3; }
.timeline .ti { position: relative; padding-bottom: 18px; }
.timeline .ti::before { content: ""; position: absolute; left: -21px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 3px var(--soft); }
.timeline .ti .th { display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--text-2); }
.timeline .ti .tc { margin-top: 5px; font-size: 13.5px; }

/* ---------------- Toast ---------------- */
#toast-root { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.toast {
  padding: 11px 18px; border-radius: 11px; background: #111827; color: #fff; font-size: 13.5px;
  box-shadow: var(--shadow-lg); animation: drop .25s; max-width: 80vw;
}
.toast.ok { background: linear-gradient(135deg, #059669, #10b981); }
.toast.err { background: linear-gradient(135deg, #dc2626, #ef4444); }
@keyframes drop { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }

/* ---------------- 移动端底部导航 ---------------- */
.mobile-nav { display: none; }
.mobile-top { display: none; }

/* ============================================================
   响应式：≤ 900px 切换为移动端布局
   ============================================================ */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .shell { flex-direction: column; height: 100vh; }
  .topbar { display: none; }
  .mobile-top {
    display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 16px; flex-shrink: 0;
    background: linear-gradient(180deg, #0b1020, #171a35); color: #fff; position: relative; z-index: 20;
  }
  .mobile-top .mt-logo { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--primary-grad); font-size: 16px; }
  .mobile-top b { font-size: 15px; flex: 1; }
  .mobile-top .mt-act { font-size: 19px; opacity: .85; cursor: pointer; }
  .view { padding: 16px 14px 84px; }
  .mobile-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: 62px;
    background: rgba(255, 255, 255, .96); backdrop-filter: blur(14px); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-nav .mn-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--text-3); font-size: 11px; cursor: pointer; }
  .mobile-nav .mn-item .mi { font-size: 19px; }
  .mobile-nav .mn-item.active { color: var(--primary); font-weight: 600; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .stat { padding: 15px 16px; }
  .stat .v { font-size: 23px; }
  .form-grid { grid-template-columns: 1fr; }
  .drawer { width: 100%; }
  .toolbar .input { min-width: 0; flex: 1; }
  .panel-body { padding: 14px; }
  th, td { padding: 11px 12px; }
  .kv { grid-template-columns: 84px 1fr; }
}
@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr; }
  .view { padding: 14px 12px 84px; }
}

/* 移动端表格转卡片列表 */
.card-list { display: flex; flex-direction: column; gap: 11px; }
.list-card { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 14px; box-shadow: var(--shadow-sm); }
.list-card .lc-top { display: flex; align-items: center; gap: 10px; }
.list-card .lc-top b { flex: 1; font-size: 15px; }
.list-card .lc-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 9px; font-size: 12.5px; color: var(--text-2); }
.list-card .lc-actions { display: flex; gap: 8px; margin-top: 12px; }
