* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --green: #0e9f6e; --green-bg: #def7ec; --green-dark: #046c4e;
  --red: #e02424; --red-bg: #fde8e8;
  --orange: #c27803; --orange-bg: #fdf6b2;
  --blue: #3f83f8; --blue-bg: #e1effe;
  --ink: #111827; --gray: #6b7280; --gray-light: #9ca3af;
  --line: #e5e7eb; --bg: #f9fafb; --card: #ffffff;
}
body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px;
}
a { color: var(--green); text-decoration: none; }
button { font-family: inherit; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 168px; background: var(--card); border-right: 1px solid var(--line);
  padding: 16px 0; flex-shrink: 0; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { font-weight: 700; font-size: 16px; padding: 4px 20px 16px; }
.sidebar .nav-item {
  display: block; padding: 9px 20px; color: var(--ink); cursor: pointer; border-left: 3px solid transparent;
}
.sidebar .nav-item:hover { background: var(--bg); }
.sidebar .nav-item.active { border-left-color: var(--green); color: var(--green); font-weight: 600; background: #f0fdf4; }
.main { flex: 1; padding: 20px 24px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.topbar h1 { font-size: 18px; }
.topbar .user { color: var(--gray); font-size: 13px; display: flex; gap: 12px; align-items: center; }

/* ---------- 卡片 / 统计 ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat .label { color: var(--gray); font-size: 12px; margin-bottom: 6px; }
.stat .value { font-size: 22px; font-weight: 700; }
.stat .sub { font-size: 12px; color: var(--gray); margin-top: 4px; }
.stat .value.red { color: var(--red); }
.stat .value.green { color: var(--green); }

/* ---------- 表格 ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--gray); font-weight: 500; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--card); }
td { padding: 9px 10px; border-bottom: 1px solid #f3f4f6; white-space: nowrap; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.invalid td { text-decoration: line-through; color: var(--gray-light); }
tr.invalid td .badge { text-decoration: none; }
td.money { font-variant-numeric: tabular-nums; font-weight: 600; }

/* 紧凑表格：订单列表整屏自适应，不横向滚动 */
table.compact { table-layout: auto; }
table.compact th { padding: 8px 7px; font-size: 12px; }
table.compact td { padding: 6px 7px; font-size: 12.5px; }
table.compact .btn.link { padding: 1px 4px; font-size: 12px; }
.cell-sub { color: var(--gray); font-size: 11.5px; margin-top: 2px; font-weight: 400; }
.ellipsis { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.link:disabled, .btn.link:disabled:hover { color: var(--gray-light); cursor: not-allowed; }

/* 平台品牌图标 */
.plat { display: inline-flex; vertical-align: middle; }
.plat svg { width: 20px; height: 20px; display: block; border-radius: 5px; }

/* 品牌 LOGO */
.brand-logo { display: flex; align-items: center; gap: 8px; }
.brand-logo img { width: 24px; height: 24px; }
.brand-logo .brand-sub { font-size: 11px; color: var(--gray); font-weight: 400; margin-top: 1px; }
.login-logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 14px; }
.login-logo img { width: 34px; height: 34px; }
.login-logo .name { font-size: 17px; font-weight: 700; color: var(--green-dark); }

/* ---------- 徽章 ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; line-height: 18px; }
.badge.green { background: var(--green-bg); color: var(--green-dark); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }
.badge.blue { background: var(--blue-bg); color: #1a56db; }
.badge.gray { background: #f3f4f6; color: var(--gray); }
.badge.purple { background: #e5e0ff; color: #5145cd; }
.badge.cyan { background: #d5f5f6; color: #047481; }
.badge.yellow { background: #fdf2c7; color: #8a6d0b; }
.badge.pink { background: #fce8e8; color: #b43474; }

/* ---------- 按钮 / 输入 ---------- */
.btn {
  display: inline-block; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); cursor: pointer; font-size: 13px;
}
.btn:hover { border-color: var(--gray-light); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { opacity: .85; }
.btn.green { background: var(--green); color: #fff; border-color: var(--green); }
.btn.danger { color: var(--red); border-color: #fbd5d5; }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn.link { border: none; background: none; color: var(--green); padding: 2px 6px; }
.btn.link.danger-link { color: var(--red); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
  font-family: inherit; background: #fff; color: var(--ink); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); }
label.field { display: block; margin-bottom: 10px; font-size: 13px; color: var(--gray); }
label.field input, label.field select, label.field textarea { display: block; width: 100%; margin-top: 4px; }

/* ---------- 工具条 ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.batchbar {
  display: flex; gap: 10px; align-items: center; padding: 8px 12px; margin-bottom: 10px;
  background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; font-size: 13px;
}
.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding: 10px; color: var(--gray); font-size: 13px; }
.pagination button { min-width: 28px; }

/* ---------- 分销商卡片 ---------- */
.dist-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.dist-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.dist-card .head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.dist-card .avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--green-bg); color: var(--green-dark);
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex-shrink: 0;
}
.dist-card .head .info { flex: 1; min-width: 0; }
.dist-card .head .name { font-weight: 600; }
.dist-card .head .email { color: var(--gray); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.dist-card .row { display: flex; gap: 16px; margin: 6px 0; font-size: 13px; }
.dist-card .row .k { color: var(--gray); }
.dist-card .balance { font-size: 20px; font-weight: 700; }
.dist-card .balance.neg { color: var(--red); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { background: #f3f4f6; border-radius: 6px; padding: 3px 8px; font-size: 12px; color: var(--ink); }
.chip.add { cursor: pointer; color: var(--green); background: none; border: 1px dashed var(--line); }
.dist-card .actions { display: flex; gap: 6px; margin-top: 10px; border-top: 1px solid #f3f4f6; padding-top: 10px; }
.dist-card.new {
  border: 2px dashed var(--line); display: flex; align-items: center; justify-content: center;
  min-height: 200px; color: var(--gray); cursor: pointer; background: none;
}
.dist-card.new:hover { border-color: var(--green); color: var(--green); }

/* ---------- 警示条 ---------- */
.warnbar { background: #fdf6b2; border: 1px solid #fce96a; color: #723b13; border-radius: 8px; padding: 9px 14px; margin: 12px 0; font-size: 13px; }
.warnbar.red { background: var(--red-bg); border-color: #f8b4b4; color: #9b1c1c; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(17, 24, 39, .45); display: flex;
  align-items: center; justify-content: center; z-index: 100;
}
.modal { background: #fff; border-radius: 12px; padding: 20px; width: 480px; max-width: 94vw; max-height: 88vh; overflow: auto; }
.modal h3 { font-size: 16px; margin-bottom: 14px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 200;
  background: var(--ink); color: #fff; padding: 9px 18px; border-radius: 8px; font-size: 13px;
  opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 80vw;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--red); }

/* ---------- 登录页 ---------- */
html, body { height: 100%; }
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 16px; padding: 24px;
  background: linear-gradient(180deg, #f0fdf4 0%, var(--bg) 38%);
}
.login-box {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 38px 34px 30px; width: 380px; max-width: 92vw; text-align: center;
  box-shadow: 0 10px 30px rgba(14, 159, 110, .07);
}
.login-box h1 { font-size: 21px; margin: 2px 0 6px; text-align: center; }
.login-box .sub { color: var(--gray); font-size: 13px; margin-bottom: 22px; text-align: center; }
.login-box input { width: 100%; margin-bottom: 12px; padding: 11px 13px; font-size: 14px; border-radius: 9px; }
.login-box .btn { width: 100%; padding: 11px; font-size: 14.5px; border-radius: 9px; margin-top: 4px; }
.login-err { color: var(--red); font-size: 13px; margin-bottom: 10px; min-height: 18px; text-align: center; }
.login-switch { font-size: 13px; color: var(--gray); text-align: center; }
.login-logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 16px; }
.login-logo img { width: 38px; height: 38px; }
.login-logo .name { font-size: 18px; font-weight: 700; color: var(--green-dark); letter-spacing: 1px; }

/* ---------- 报表 ---------- */
.report-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; margin-bottom: 14px; }
.report-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.flow-list { font-size: 13px; }
.flow-list .item { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid #f3f4f6; gap: 10px; }
.flow-list .item:last-child { border: none; }
.flow-list .t { color: var(--gray); flex-shrink: 0; }
.flow-list .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.flow-list .amt.pos { color: var(--green); }
.flow-list .amt.neg { color: var(--ink); }
.bar-row { display: flex; align-items: center; gap: 10px; margin: 9px 0; font-size: 13px; }
.bar-row .name { width: 70px; flex-shrink: 0; }
.bar-row .bar-bg { flex: 1; height: 8px; border-radius: 4px; background: #f3f4f6; overflow: hidden; }
.bar-row .bar { height: 100%; border-radius: 4px; background: var(--green); }
.bar-row .bar.neg { background: var(--red); }
.bar-row .v { width: 88px; text-align: right; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.bar-row .rk { width: 16px; flex-shrink: 0; text-align: center; color: var(--gray); font-size: 12px; }
.bar-row.wide .name { width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 趋势图图例 */
.chart-legend { display: flex; gap: 18px; justify-content: center; font-size: 12px; color: var(--gray); margin-top: 6px; }
.chart-legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.chart-legend .dot.green { background: var(--green); }
.chart-legend .dot.red { background: var(--red); }
/* 欠款账号明细：多列网格、可滚动，容纳大量账号不破坏布局 */
.debt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 0 22px; max-height: 300px; overflow: auto; }
.debt-grid .d { display: flex; justify-content: space-between; gap: 10px; padding: 6px 2px; border-bottom: 1px solid #f3f4f6; font-size: 13px; }
.debt-grid .d .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.debt-grid .d .am { color: var(--red); font-weight: 600; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 10px; }
.section-title h2 { font-size: 15px; }
.muted { color: var(--gray); font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
img.thumb { width: 28px; height: 28px; border-radius: 4px; object-fit: cover; background: #f3f4f6; }
