:root {
  --ink: #1a2230;
  --muted: #5b6676;
  --line: #e3e8ef;
  --bg: #f5f7fa;
  --card: #ffffff;
  --blue: #185fa5;
  --blue-dark: #134a80;
  --blue-bg: #eaf2fb;
  --teal: #0f6e56;
  --teal-bg: #e7f4ef;
  --amber: #ba7517;
  --amber-bg: #fbf2e2;
  --red: #b3261e;
  --red-bg: #fbeceb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(26, 34, 48, 0.04), 0 8px 24px rgba(26, 34, 48, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }

/* ---------------- 登录 ---------------- */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 15% -10%, #e8f1fb 0%, rgba(245, 247, 250, 0) 60%),
    radial-gradient(900px 500px at 95% 110%, #e6f4ef 0%, rgba(245, 247, 250, 0) 55%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 30px;
  box-shadow: var(--shadow);
}

.login-card .brand {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 18px;
}

.login-card h1 { font-size: 21px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfcfe;
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(24, 95, 165, 0.12);
}
.field textarea { resize: vertical; min-height: 64px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.form-error {
  color: var(--red);
  background: var(--red-bg);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin: 4px 0 12px;
}
.form-error:empty { display: none; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14px;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #f7f9fc; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(24, 95, 165, 0.07); }
.btn.danger { color: var(--red); border-color: #f0cdca; background: #fff; }
.btn.danger:hover { background: var(--red-bg); }
.btn.block { width: 100%; padding: 11px 16px; font-weight: 600; }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 22px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 32px; height: 32px; flex: none;
  border-radius: 9px;
  background: var(--blue);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.shop { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.shop strong { font-size: 15px; }
.shop span { font-size: 12px; }
.top-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.page { max-width: 1180px; margin: 0 auto; padding: 20px 22px 60px; }

/* ---------------- 统计 ---------------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 650; letter-spacing: -0.5px; margin-top: 2px; }
.stat .v small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.stat.warn .v { color: var(--amber); }
.stat.alert .v { color: var(--red); }

/* ---------------- 工具栏 ---------------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.search { flex: 1 1 240px; position: relative; }
.search input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 14px 10px 36px;
  outline: none;
}
.search input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(24, 95, 165, 0.1); }
.search::before {
  content: "";
  position: absolute;
  left: 13px; top: 50%;
  width: 12px; height: 12px;
  margin-top: -7px;
  border: 2px solid #9aa5b4;
  border-radius: 50%;
}
.search::after {
  content: "";
  position: absolute;
  left: 24px; top: 50%;
  width: 6px; height: 2px;
  background: #9aa5b4;
  transform: rotate(45deg);
  margin-top: 4px;
}
.filters { display: flex; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--muted);
}
.chip.active { background: var(--blue-bg); border-color: #c9dcf1; color: var(--blue); font-weight: 600; }

/* ---------------- 客户卡片列表 ---------------- */
.list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
}
.cust {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: box-shadow .18s, border-color .18s, transform .18s;
}
.cust:hover { box-shadow: var(--shadow); border-color: #cfdbe8; }
.cust-head { display: flex; align-items: flex-start; gap: 10px; }
.cust-name { font-weight: 650; font-size: 16px; line-height: 1.3; }
.cust-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.cust-balance {
  margin-left: auto;
  text-align: right;
  line-height: 1.1;
  flex: none;
}
.cust-balance b { font-size: 26px; letter-spacing: -1px; font-weight: 650; }
.cust-balance span { font-size: 11px; color: var(--muted); display: block; }
.cust-balance.low b { color: var(--amber); }
.cust-balance.zero b { color: var(--red); }
.cust-balance.paused b { color: #9aa5b4; }

.cust-note {
  font-size: 12.5px;
  color: var(--muted);
  background: #f7f9fc;
  border-radius: 8px;
  padding: 6px 10px;
  margin-top: 10px;
}
.cust-foot {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  align-items: center;
}
.cust-foot .spacer { flex: 1; }
.cust-foot .btn { padding: 7px 14px; font-size: 13px; }
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--blue-bg);
  color: var(--blue);
  font-weight: 600;
  vertical-align: middle;
}
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.gray { background: #eef1f5; color: var(--muted); }
.badge.teal { background: var(--teal-bg); color: var(--teal); }

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.list-foot { text-align: center; font-size: 12.5px; margin-top: 16px; }

/* ---------------- 弹窗 ---------------- */
.modal-root { position: fixed; inset: 0; z-index: 60; }
.layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-mask { position: absolute; inset: 0; background: rgba(20, 28, 40, 0.42); }
.head-text { min-width: 0; flex: 1; }
.foot-actions { display: inline-flex; gap: 6px; }

.modal {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(16, 24, 40, 0.28);
  overflow: hidden;
  animation: pop .16s ease-out;
}
.modal.wide { max-width: 620px; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 12px;
}
.modal-head h2 { font-size: 17px; margin: 0; font-weight: 650; }
.modal-head .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.icon-btn {
  margin-left: auto;
  border: none;
  background: transparent;
  width: 30px; height: 30px;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
}
.icon-btn:hover { background: #f1f4f8; }
.modal-body { padding: 4px 20px 8px; overflow-y: auto; }
.modal-foot {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
  background: #fcfdfe;
}
.modal-foot .left {
  margin-right: auto;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
  padding-right: 6px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.quick-counts { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.quick-counts button {
  min-width: 46px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 9px;
  padding: 8px 0;
  font-weight: 600;
}
.quick-counts button.on { background: var(--blue-bg); border-color: #c9dcf1; color: var(--blue); }

.balance-hint {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  background: #f7f9fc;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}
.balance-hint b { font-size: 20px; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------------- 详情 ---------------- */
.detail-top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0 16px;
  border-bottom: 1px solid var(--line);
}
.detail-big { text-align: center; flex: none; padding: 8px 16px; background: var(--blue-bg); border-radius: 12px; }
.detail-big b { display: block; font-size: 28px; line-height: 1.1; color: var(--blue); font-variant-numeric: tabular-nums; }
.detail-big span { font-size: 11px; color: var(--blue); }
.detail-info { min-width: 0; }
.detail-info .n { font-size: 17px; font-weight: 650; }

.tx-list { list-style: none; margin: 0; padding: 6px 0 0; }
.tx {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid #f0f3f7;
}
.tx:last-child { border-bottom: none; }
.tx-icon {
  width: 30px; height: 30px; flex: none;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.tx-icon.minus { background: var(--amber-bg); color: var(--amber); }
.tx-icon.plus { background: var(--teal-bg); color: var(--teal); }
.tx-main { min-width: 0; flex: 1; }
.tx-title { font-size: 14px; }
.tx-sub { font-size: 12px; color: var(--muted); }
.tx-val { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15px; }
.tx-val.minus { color: var(--amber); }
.tx-val.plus { color: var(--teal); }
.tx-val small { display: block; font-size: 11px; color: var(--muted); font-weight: 500; text-align: right; }

.section-label {
  font-size: 12px;
  color: var(--muted);
  margin: 18px 0 6px;
  font-weight: 600;
  letter-spacing: .3px;
}

.issue {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--red-bg);
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 13.5px;
}
.ok-box {
  background: var(--teal-bg);
  color: var(--teal);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  font-weight: 600;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
}
.switch-row .label { flex: 1; font-size: 14px; }
.switch {
  position: relative;
  width: 42px; height: 24px;
  flex: none;
}
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch i {
  position: absolute; inset: 0;
  background: #d5dce6;
  border-radius: 999px;
  transition: background .15s;
  pointer-events: none;
}
.switch i::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform .15s;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.switch input:checked + i { background: var(--blue); }
.switch input:checked + i::after { transform: translateX(18px); }

.divider { height: 1px; background: var(--line); margin: 16px 0; }

/* ---------------- Toast ---------------- */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: #1f2937;
  color: #fff;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .24);
  animation: rise .2s ease-out;
  max-width: 88vw;
}
.toast.ok { background: #0f6e56; }
.toast.err { background: #a1231c; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; } }

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .page { padding: 14px 14px 48px; }
  .topbar { padding: 10px 14px; }
  .top-actions .btn { padding: 7px 10px; font-size: 13px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .list { grid-template-columns: 1fr; }
  .modal-root { padding: 0; }
  .layer { padding: 0; align-items: flex-end; }
  .modal, .modal.wide { max-width: none; width: 100%; border-radius: 16px 16px 0 0; max-height: 92vh; }
  .toolbar .btn.primary { width: 100%; }
}
