:root {
  --surface: #ffffff;
  --surface-2: #f5f6fa;
  --border: #e7eaf3;
  --text: #181c2a;
  --text-soft: #68718a;
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --violet: #7c3aed;
  --primary-soft: #eef0fe;
  --accent: #d97706;
  --danger: #e11d48;
  --warn: #d97706;
  --ok: #059669;
  --radius: 12px;
  --grad-primary: linear-gradient(135deg, #4f46e5, #7c3aed);
  --shadow: 0 1px 2px rgba(24,28,42,.04), 0 3px 12px rgba(24,28,42,.05);
  --shadow-lg: 0 12px 36px rgba(24,28,42,.14);
  --ease: cubic-bezier(.22,.68,.32,1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--surface-2);
  font-size: 13.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
::selection { background: rgba(79,70,229,.16); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cdd2e0; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #b4bccf; }
::-webkit-scrollbar-track { background: transparent; }
:focus-visible { outline: 2px solid rgba(79,70,229,.5); outline-offset: 1px; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 222px; flex-shrink: 0;
  background: linear-gradient(180deg, #191636 0%, #211c4b 55%, #251f53 100%);
  color: #b3b9d4;
  padding: 18px 12px; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 16px; border-bottom: 1px solid rgba(255,255,255,.07); margin-bottom: 10px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--grad-primary);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 14px;
  box-shadow: 0 4px 12px rgba(99,84,229,.4);
}
.brand .name { font-size: 14px; font-weight: 700; color: #fff; letter-spacing: -.01em; }
.brand .sub { font-size: 10.5px; color: #7e86a5; }
.nav-group-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6b7392; margin: 14px 8px 5px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7.5px 11px; border-radius: 9px; color: #b3b9d4;
  cursor: pointer; margin-bottom: 2px; font-size: 13px;
  transition: background .16s var(--ease), color .16s, transform .16s var(--ease);
  position: relative;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #e8ebf7; transform: translateX(2px); }
.nav-item.active {
  background: var(--grad-primary); color: #fff; font-weight: 600;
  box-shadow: 0 4px 12px rgba(99,84,229,.35);
}
.nav-item.active::before {
  content: ''; position: absolute; left: -12px; top: 22%; bottom: 22%;
  width: 3px; border-radius: 3px; background: #8b7cf6;
  box-shadow: 0 0 8px #8b7cf6;
}
.nav-item .ic { width: 17px; text-align: center; opacity: .9; font-size: 12px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 54px; background: rgba(255,255,255,.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 22px;
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.topbar .crumb { color: var(--text-soft); font-size: 12px; }
.content { padding: 20px; overflow: auto; flex: 1; }
.content > .card { animation: cardIn .38s var(--ease) both; }
.content > .card:nth-child(2) { animation-delay: .05s; }
.content > .card:nth-child(3) { animation-delay: .1s; }
.content > .card:nth-child(4) { animation-delay: .15s; }
.content > .card:nth-child(5) { animation-delay: .2s; }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
  transition: box-shadow .2s var(--ease);
}
.card:hover { box-shadow: 0 2px 4px rgba(24,28,42,.04), 0 6px 20px rgba(24,28,42,.07); }
.card h2 { font-size: 14.5px; margin: 0 0 12px; font-weight: 700; letter-spacing: -.01em; }
.card .desc { color: var(--text-soft); font-size: 12px; margin: -6px 0 12px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-h h3 { font-size: 14.5px; margin: 0; font-weight: 700; letter-spacing: -.01em; }

/* Grid */
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } .sidebar { display: none; } }

/* Stat tiles */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
  transition: transform .18s var(--ease), box-shadow .18s var(--ease);
}
.stat:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(24,28,42,.09); }
.stat::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2.5px;
  background: var(--grad-primary);
}
.stat .label { color: var(--text-soft); font-size: 11.5px; letter-spacing: .02em; font-weight: 550; }
.stat .value { font-size: 21px; font-weight: 750; margin-top: 5px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .value.accent { background: var(--grad-primary); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat .value.ok { color: var(--ok); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 5px; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 13px; border-radius: 9px; cursor: pointer; font-size: 12.5px; font-weight: 600;
  transition: all .16s var(--ease);
  user-select: none;
}
.btn:hover { border-color: #c6cddF; background: var(--surface-2); transform: translateY(-1px); }
.btn:active { transform: scale(.96); }
.btn.primary {
  background: var(--grad-primary); border: none; color: #fff;
  box-shadow: 0 3px 10px rgba(99,84,229,.32);
}
.btn.primary:hover { box-shadow: 0 5px 16px rgba(99,84,229,.42); filter: brightness(1.06); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f6c5d1; }
.btn.danger:hover { background: #fdf0f3; }
.btn.sm { padding: 4px 9px; font-size: 11.5px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 8px 11px; border-bottom: 1px solid var(--border); }
th {
  color: var(--text-soft); font-weight: 600; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .05em;
  background: var(--surface-2); position: sticky; top: 0; z-index: 1;
}
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--primary-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow: auto; border-radius: var(--radius); border: 1px solid var(--border); }

/* Forms */
label { display: block; font-size: 12px; color: var(--text-soft); margin-bottom: 4px; font-weight: 550; }
input, select {
  width: 100%; padding: 7px 11px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 12.5px; font-family: inherit; background: #fff; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.13); }
input[type="checkbox"] { width: auto; accent-color: var(--primary); }
.field { margin-bottom: 10px; }
.field-inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.field-inline .field { margin-bottom: 0; }

/* Badges */
.badge { display: inline-block; padding: 2.5px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.gray { background: #eef0f4; color: #5b6273; }
.badge.blue { background: var(--primary-soft); color: var(--primary); }
.badge.green { background: #e2f7ee; color: var(--ok); }
.badge.amber { background: #fdf0db; color: var(--warn); }
.badge.red { background: #fdeef2; color: var(--danger); }

/* Tabs（滑动下划线） */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab {
  padding: 8px 13px; cursor: pointer; font-size: 12.5px; color: var(--text-soft);
  font-weight: 550; position: relative;
  transition: color .18s var(--ease);
}
.tab:hover { color: var(--text); }
.tab::after {
  content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px;
  background: var(--grad-primary); border-radius: 2px;
  transform: scaleX(0); transform-origin: left;
  transition: transform .22s var(--ease);
}
.tab.active { color: var(--primary); font-weight: 650; }
.tab.active::after { transform: scaleX(1); }

/* Misc */
.muted { color: var(--text-soft); }
.hidden { display: none !important; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.toast {
  position: fixed; top: 16px; right: 16px; background: #1c1740; color: #fff;
  padding: 11px 16px; border-radius: 11px; box-shadow: var(--shadow-lg);
  font-size: 12.5px; font-weight: 550; z-index: 99; opacity: 0; transform: translateY(-10px) scale(.97);
  transition: all .22s var(--ease);
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
.empty { text-align: center; color: var(--text-soft); padding: 36px 0; }
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 22px;
  text-align: center; color: var(--text-soft); cursor: pointer; transition: all .18s var(--ease);
}
.dropzone:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.map-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 760px) { .map-grid { grid-template-columns: 1fr; } }
.kpi-note { font-size: 11.5px; color: var(--text-soft); background: var(--surface-2); border-radius: 9px; padding: 9px 11px; margin-top: 8px; }

/* 弹窗 */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20,17,45,.42); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .18s var(--ease);
  padding: 20px;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 840px; max-width: 96vw; max-height: 88vh; display: flex; flex-direction: column;
  animation: modalIn .24s var(--ease);
  overflow: hidden;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 18px; border-bottom: 1px solid var(--border);
}
.modal-h h3 { margin: 0; font-size: 14px; font-weight: 700; letter-spacing: -.01em; }
.modal-b { padding: 15px 18px; overflow: auto; }

/* 进度遮罩 */
.prog-box { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 20px 22px; width: 360px; max-width: 90vw; animation: modalIn .24s var(--ease); }
.prog-title { font-size: 14px; font-weight: 650; margin-bottom: 12px; color: var(--text); }
.prog-track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.prog-fill { height: 100%; width: 0%; background: var(--grad-primary); border-radius: 999px; transition: width .25s ease; box-shadow: 0 0 8px rgba(99,84,229,.5); }
.prog-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 9px; font-size: 11.5px; color: var(--text-soft); }
.prog-pct { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }

/* 模块通用 */
.row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 6px; }
.row .inp { flex: 1; min-width: 120px; }
.inp {
  width: 100%; padding: 7px 11px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 12.5px; font-family: inherit; background: #fff; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.inp:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.13); }
.inp.sm { max-width: 220px; }
.inp.sm .lbl { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.acts { display: flex; gap: 5px; }

/* 状态标签 */
.tag { display: inline-block; padding: 2.5px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.tag.warn { background: #fdf0db; color: var(--warn); }
.tag.info { background: var(--primary-soft); color: var(--primary); }
.tag.ok { background: #e2f7ee; color: var(--ok); }
.tag.muted { background: #eef0f4; color: #5b6273; }

/* 提示消息 */
.msg { margin-top: 8px; padding: 9px 11px; border-radius: 9px; font-size: 12.5px; line-height: 1.5; }
.msg.ok { background: #e2f7ee; color: var(--ok); border: 1px solid #bdebd6; }
.msg.err { background: #fdeef2; color: var(--danger); border: 1px solid #f6c5d1; }
.msg.warn { background: #fdf0db; color: #92590a; border: 1px solid #f3d9a8; }

/* 表格汇总/强调 */
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl-wrap { overflow: auto; border-radius: var(--radius); border: 1px solid var(--border); margin-top: 8px; }
.tbl tr.sum td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border); }
.tbl td.pos { color: var(--ok); }
.tbl td.strong { font-weight: 700; }
.tbl td.muted { color: var(--text-soft); }
.map { display: flex; flex-direction: column; gap: 3px; min-width: 130px; }
.map span { font-size: 11.5px; color: var(--text-soft); font-weight: 550; }

/* 分佣比例（按分销方） */
.dist-comm-tbl { table-layout: fixed; }
.dist-comm-tbl th, .dist-comm-tbl td { vertical-align: middle; }
.dist-comm-tbl th[rowspan] { text-align: center; }
.dist-name { text-align: center; padding: 3px 0; }
.dist-name .dn-name { font-weight: 650; font-size: 13px; color: var(--text); white-space: nowrap; }
.rp-cell { text-align: center; padding: 3px 5px; }
.rp-cell .rp-unit { display: block; font-size: 10.5px; color: var(--text-soft); line-height: 1; margin-top: 2px; }
.rp-cell .rperr { font-size: 10.5px; color: var(--danger); min-height: 13px; line-height: 1.2; margin-top: 2px; }
.rpi {
  width: 54px; padding: 4px 6px; text-align: center;
  border: 1px solid var(--border); border-radius: 7px; font-size: 12.5px; background: var(--surface);
  display: inline-block;
  transition: border-color .15s, box-shadow .15s;
}
.rpi:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.13); }
.check-inline { display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px; white-space: nowrap; cursor: pointer; margin-right: 12px; }
.file-list { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }
.file-item {
  display: flex; align-items: center; gap: 9px; padding: 6px 11px;
  background: var(--surface-2); border-radius: 9px; font-size: 12.5px;
  border: 1px solid transparent; transition: border-color .15s, background .15s;
}
.file-item:hover { border-color: var(--border); background: var(--primary-soft); }
.fi-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.fi-entity { width: 120px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 7px; font-size: 11.5px; }
.block { border: 1px solid var(--border); border-radius: var(--radius); padding: 11px 13px; margin-top: 8px; background: var(--surface-2); }
.block-t { font-weight: 650; margin-bottom: 7px; color: var(--text); font-size: 13px; }
.field.inline { display: inline-flex; align-items: center; gap: 5px; margin-right: 14px; margin-bottom: 4px; }
.field.inline label { margin: 0; font-size: 11.5px; color: var(--text-soft); white-space: nowrap; }

/* 趋势图 */
.trend-wrap { max-width: 760px; margin: 0 auto; }
.trend-wrap svg { width: 100%; height: auto; display: block; }
.trend-wrap rect, .trend-wrap circle { cursor: pointer; transition: filter .15s var(--ease), opacity .15s; }
.trend-wrap rect:hover, .trend-wrap circle:hover { filter: brightness(1.18); }
.trend-val { font-size: 10.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
.trend-legend { display: flex; gap: 16px; justify-content: center; align-items: center; font-size: 11.5px; color: var(--text-soft); margin-top: 6px; flex-wrap: wrap; }
.trend-legend .sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
.trend-legend .sl { display: inline-block; width: 13px; height: 2px; margin-right: 5px; vertical-align: middle; }
.trend-hint { color: #a0a7bd; font-size: 11px; margin-left: 8px; }

/* 分页 */
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 0 0; font-size: 12.5px; color: var(--text-soft); }
.pager-info { display: flex; align-items: center; gap: 6px; }
.pager-sel { width: auto; padding: 3px 7px; border: 1px solid var(--border); border-radius: 7px; font-size: 11.5px; }
.pager-btns { display: flex; align-items: center; gap: 5px; }
.pager-cur { font-weight: 600; color: var(--text); min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; }
