:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --line: #e4e7ec;
  --line-strong: #d5d9e0;
  --ink: #10151f;
  --ink-2: #4a5361;
  --ink-3: #79828f;
  --accent: #1d4ed8;
  --accent-soft: #eef3ff;

  --tier-a: #6d28d9;
  --tier-b: #1d4ed8;
  --tier-c: #0e7490;
  --tier-d: #64748b;
  --act-active: #15803d;
  --act-warning: #c2410c;
  --act-dormant: #b91c1c;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 21, 31, .04), 0 1px 3px rgba(16, 21, 31, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
b, strong { font-weight: 600; }

.num { font-variant-numeric: tabular-nums; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 10px; align-items: center; padding: 20px 18px 18px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #1e3a8a);
  color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 16px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { color: #f8fafc; font-size: 14.5px; }
.brand-text span { font-size: 11.5px; color: #8592a6; }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; }
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px; border-radius: 8px;
  color: #b9c3d1; font-size: 13.5px;
  transition: background .12s, color .12s;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #eef2f7; }
.nav a.active { background: #1e293b; color: #fff; font-weight: 500; }
.nav-ico { font-size: 12px; opacity: .8; width: 14px; text-align: center; }

.sidebar-foot { margin-top: auto; padding: 14px; }
.rule-card { background: rgba(255,255,255,.05); border-radius: 8px; padding: 11px 12px; font-size: 11.5px; color: #94a3b8; }
.rule-title { color: #e2e8f0; font-weight: 600; margin-bottom: 6px; font-size: 12px; }
.rule-line { margin: 3px 0; }
.rule-line b { color: #cbd5e1; font-weight: 500; }
.rule-note { margin-top: 7px; padding-top: 7px; border-top: 1px solid rgba(255,255,255,.08); color: #7f8c9f; }

.main { flex: 1; min-width: 0; padding: 22px 26px 48px; }
.loading { color: var(--ink-3); padding: 40px 0; }

/* ---------- 通用 ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { font-size: 19px; font-weight: 600; letter-spacing: -.2px; margin: 0; }
.page-sub { color: var(--ink-3); font-size: 12.5px; margin-top: 3px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-title { font-size: 13.5px; font-weight: 600; }
.card-hint { font-size: 11.5px; color: var(--ink-3); }
.card-body { padding: 16px; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 15px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; color: var(--ink-3); }
.kpi-value { font-size: 22px; font-weight: 600; letter-spacing: -.5px; margin-top: 3px; }
.kpi-foot { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.kpi.alert .kpi-value { color: var(--act-warning); }

/* 徽章 */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; line-height: 1.6;
  border: 1px solid transparent; white-space: nowrap;
}
.badge-A { color: var(--tier-a); background: #f5f0ff; border-color: #e6dbff; }
.badge-B { color: var(--tier-b); background: #eef3ff; border-color: #dbe5ff; }
.badge-C { color: var(--tier-c); background: #e8f7fa; border-color: #cceef3; }
.badge-D { color: var(--tier-d); background: #f1f3f6; border-color: #e2e6ec; }
.badge-active { color: var(--act-active); background: #eaf7ee; border-color: #cfeddb; }
.badge-warning { color: var(--act-warning); background: #fdf2e9; border-color: #fadfc7; }
.badge-dormant { color: var(--act-dormant); background: #fdeceb; border-color: #f8d4d1; }
.badge-plain { color: var(--ink-2); background: var(--surface-2); border-color: var(--line); font-weight: 500; }

.pri { font-weight: 700; font-size: 11px; padding: 1px 5px; border-radius: 4px; margin-right: 5px; }
.pri-P0 { background: #b91c1c; color: #fff; }
.pri-P1 { background: #c2410c; color: #fff; }
.pri-P2 { background: #b45309; color: #fff; }
.pri-P3 { background: #64748b; color: #fff; }

/* ---------- 12 格矩阵 ---------- */
.matrix-wrap { overflow-x: auto; }
.matrix { width: 100%; border-collapse: separate; border-spacing: 8px; min-width: 720px; }
.matrix th { font-size: 12px; color: var(--ink-3); font-weight: 600; text-align: left; padding: 0 4px 2px; }
.matrix th.act-h { text-align: center; }
.matrix th.act-h small { display: block; font-weight: 400; color: var(--ink-3); font-size: 11px; }
.matrix td.row-h {
  width: 128px; vertical-align: middle; padding: 0 6px;
}
.row-h-inner { display: flex; flex-direction: column; gap: 2px; }
.row-h-inner .desc { font-size: 11px; color: var(--ink-3); }

.cell {
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
  padding: 11px 12px; cursor: pointer; transition: transform .1s, box-shadow .12s, border-color .12s;
  display: block; min-height: 88px;
}
.cell:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(16,21,31,.09); border-color: var(--line-strong); }
.cell-count { font-size: 21px; font-weight: 600; letter-spacing: -.4px; }
.cell-count small { font-size: 12px; font-weight: 400; color: var(--ink-3); margin-left: 3px; }
.cell-amount { font-size: 12px; color: var(--ink-2); margin-top: 1px; }
.cell-action { margin-top: 8px; font-size: 12px; font-weight: 500; display: flex; align-items: center; }
.cell-w4 { background: #fff5f5; border-color: #f6cfcb; }
.cell-w3 { background: #fff8f1; border-color: #f7ddc2; }
.cell-w2 { background: #fbfaff; border-color: #e6e3f5; }
.cell-w1 { background: var(--surface); }
.cell-w0 { background: var(--surface-2); }
.cell-w0 .cell-count { color: var(--ink-2); }
.cell-empty { opacity: .55; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  text-align: left; font-size: 11.5px; font-weight: 600; color: var(--ink-3);
  padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
  background: var(--surface-2); position: sticky; top: 0; z-index: 1;
}
table.grid th.sortable { cursor: pointer; user-select: none; }
table.grid th.sortable:hover { color: var(--accent); }
table.grid th .arrow { opacity: .55; font-size: 9px; margin-left: 2px; }
table.grid td { padding: 10px 12px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover { background: #f8fafc; }
table.grid .right { text-align: right; }
.company-cell { display: flex; flex-direction: column; gap: 1px; }
.company-cell .cname { font-weight: 500; }
.company-cell .cmeta { font-size: 11.5px; color: var(--ink-3); }

/* 筛选栏 */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.chipset { display: flex; gap: 5px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 3px; box-shadow: var(--shadow); }
.chip {
  padding: 5px 11px; border-radius: 6px; font-size: 12.5px; color: var(--ink-2);
  cursor: pointer; border: none; background: transparent; font-family: inherit;
}
.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--ink); color: #fff; font-weight: 500; }
.search {
  flex: 1; min-width: 200px; max-width: 320px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); font-family: inherit; font-size: 13px; box-shadow: var(--shadow);
}
.search:focus { outline: 2px solid var(--accent-soft); border-color: #b9cbff; }
select.sel {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); font-family: inherit; font-size: 13px; box-shadow: var(--shadow);
}

.pager { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--ink-3); }
.pager button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 7px;
  padding: 5px 11px; cursor: pointer; font-family: inherit; font-size: 12.5px; margin-left: 6px;
}
.pager button:disabled { opacity: .45; cursor: not-allowed; }
.pager button:not(:disabled):hover { border-color: var(--line-strong); background: var(--surface-2); }

/* ---------- 客户360 ---------- */
.back-link { font-size: 12.5px; color: var(--ink-3); display: inline-block; margin-bottom: 10px; }
.back-link:hover { color: var(--accent); }

.profile-head {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 12px;
  display: flex; gap: 18px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap;
}
.ph-left h1 { font-size: 20px; margin: 0 0 5px; letter-spacing: -.3px; }
.ph-meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.ph-meta span b { color: var(--ink-3); font-weight: 400; margin-right: 4px; }
.ph-right { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; }
.ph-badges { display: flex; gap: 6px; }
.action-bar {
  display: inline-flex; align-items: center; gap: 7px;
  background: #0f172a; color: #fff; border-radius: 8px; padding: 7px 13px; font-size: 13px; font-weight: 500;
}
.action-bar .cross { color: #94a3b8; font-weight: 400; font-size: 12px; }

.metric-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden;
}
.metric {
  padding: 11px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.metric-label { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.metric-value { font-size: 16px; font-weight: 600; margin-top: 1px; letter-spacing: -.2px; }
.metric-value.warn { color: var(--act-warning); }
.metric-value.danger { color: var(--act-dormant); }
.metric-value small { font-size: 11.5px; font-weight: 400; color: var(--ink-3); margin-left: 2px; }

.detail-cols { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .95fr); gap: 12px; align-items: start; }
@media (max-width: 1080px) { .detail-cols { grid-template-columns: 1fr; } }

/* 时间轴 */
.tl-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.timeline { padding: 4px 16px 8px; }
.tl-item { display: flex; gap: 12px; padding: 12px 0; position: relative; }
.tl-item::before {
  content: ''; position: absolute; left: 13px; top: 34px; bottom: -12px; width: 1px; background: var(--line);
}
.tl-item:last-child::before { display: none; }
.tl-ico {
  width: 27px; height: 27px; border-radius: 8px; flex: 0 0 27px;
  display: grid; place-items: center; font-size: 11px; font-weight: 600; color: #fff; z-index: 1;
}
.ico-wangwang { background: #ea8a1f; }
.ico-email { background: #3b6fd4; }
.ico-order { background: #0f766e; }
.tl-body { flex: 1; min-width: 0; }
.tl-line1 { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; font-size: 12px; color: var(--ink-3); }
.tl-who { color: var(--ink); font-weight: 500; font-size: 12.5px; }
.tl-dir { font-size: 11px; padding: 0 5px; border-radius: 4px; border: 1px solid var(--line); }
.tl-dir.in { color: #0f766e; background: #edfaf7; border-color: #cbeae3; }
.tl-dir.out { color: #4b5563; background: var(--surface-2); }
.tl-subject { font-weight: 500; margin-top: 3px; font-size: 13px; }
.tl-content { margin-top: 2px; color: var(--ink-2); font-size: 12.8px; word-break: break-word; }
.tl-content.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tl-more { font-size: 11.5px; color: var(--accent); cursor: pointer; margin-top: 2px; display: inline-block; }
.tl-tags { display: flex; gap: 5px; margin-top: 5px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-3); }
.tag.unresolved { background: #fdeceb; border-color: #f8d4d1; color: var(--act-dormant); font-weight: 600; }

.tl-order {
  background: #f0fdfa; border: 1px solid #ccebe6; border-radius: 9px; padding: 10px 13px;
}
.tl-order .o-top { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.tl-order .o-amount { font-size: 16px; font-weight: 700; color: #0f766e; letter-spacing: -.3px; }
.tl-order .o-no { font-size: 12.5px; font-weight: 600; }
.tl-order .o-meta { font-size: 12px; color: var(--ink-2); margin-top: 3px; }

/* 右栏 */
.side-card + .side-card { margin-top: 12px; }
.summary-block + .summary-block { margin-top: 13px; padding-top: 13px; border-top: 1px solid var(--line); }
.summary-h { font-size: 12px; font-weight: 600; color: var(--ink-3); margin-bottom: 5px; letter-spacing: .3px; }
.summary-p { font-size: 13px; color: var(--ink-2); line-height: 1.65; }
ul.clean { margin: 0; padding-left: 17px; font-size: 12.8px; color: var(--ink-2); line-height: 1.7; }
ul.clean li + li { margin-top: 3px; }
.issue { background: #fffbf5; border: 1px solid #f6e3c8; border-radius: 8px; padding: 8px 10px; font-size: 12.5px; }
.issue + .issue { margin-top: 7px; }
.issue-meta { font-size: 11px; color: var(--ink-3); margin-bottom: 2px; }

.task { display: flex; gap: 9px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid #f0f2f5; font-size: 12.8px; }
.task:last-child { border-bottom: none; }
.task-dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 6px; flex: 0 0 7px; background: var(--act-warning); }
.task-dot.done { background: #cbd5e1; }
.task-done { color: var(--ink-3); text-decoration: line-through; }
.task-meta { font-size: 11.5px; color: var(--ink-3); }
.task-meta .overdue { color: var(--act-dormant); font-weight: 600; }

.contact-row { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid #f0f2f5; }
.contact-row:last-child { border-bottom: none; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 30px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12px;
}
.contact-info { min-width: 0; flex: 1; }
.contact-name { font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.contact-line { font-size: 11.8px; color: var(--ink-3); overflow-wrap: anywhere; }
.chan { display: inline-block; width: 15px; color: var(--ink-3); }

.side-card table.grid th { position: static; }
.side-card table.grid td:first-child, .side-card table.grid th:first-child { white-space: nowrap; }

.empty { color: var(--ink-3); font-size: 12.5px; padding: 12px 0; text-align: center; }
