:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --brand: #2f6bff;
  --brand-dark: #1e50d0;
  --good: #0f9d58;
  --bad: #d93025;
  --warn: #b45309;
  --warn-bg: #fff8e6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 "微软雅黑", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
}

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; background: #fff; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px; background: var(--brand);
  color: #fff; font-size: 20px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.top h1 { font-size: 17px; margin: 0; }
.top .sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; gap: 8px; }

button {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 7px 14px;
  border: 1px solid var(--line); background: #fff; color: var(--text);
}
button:hover { border-color: #c7d2e5; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
button.primary[disabled] { background: #a9bce6; border-color: #a9bce6; cursor: not-allowed; }
button.big { padding: 10px 22px; font-size: 15px; }
button.ghost { background: transparent; }
button.link { border: none; background: none; color: var(--brand); padding: 2px 6px; }

.tabs { display: flex; gap: 4px; padding: 10px 22px 0; }
.tab { border: none; background: transparent; color: var(--muted); padding: 9px 14px; border-radius: 8px 8px 0 0; }
.tab.active { background: #fff; color: var(--brand); font-weight: 600; box-shadow: 0 -1px 0 var(--line), 1px 0 0 var(--line), -1px 0 0 var(--line); }

main { padding: 16px 22px 60px; }
.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 10px; flex-wrap: wrap; }
.card h3 { margin: 0; font-size: 15px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .grid2 { grid-template-columns: 1fr; } }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi .k { color: var(--muted); font-size: 12px; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -0.5px; }
.kpi .n { color: var(--muted); font-size: 11px; margin-top: 2px; }
.kpi.good .v { color: var(--good); }
.kpi.bad .v { color: var(--bad); }
.kpi.warn { background: var(--warn-bg); border-color: #f2d99a; }
.kpi.warn .v { color: var(--warn); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
table.tbl th { background: #f8fafc; color: var(--muted); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
table.tbl.small { font-size: 12.5px; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl tbody tr:hover { background: #f9fbff; }
table.tbl td.note { color: var(--muted); }
table.tbl th.strong, table.tbl td.strong { font-weight: 700; color: #111827; }
table.tbl tr.total-row td { border-top: 2px solid #cbd5e1; font-weight: 700; background: #f8fafc; }
.scroll { max-height: 460px; overflow: auto; }
.neg { color: var(--bad); }
.pos { color: var(--good); }

.toolbar { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar label { display: flex; align-items: center; gap: 8px; color: var(--muted); }
select, input[type=text], input[placeholder] {
  font: inherit; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text);
}
.meta { color: var(--muted); font-size: 12.5px; }
.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline { color: var(--muted); display: flex; align-items: center; gap: 4px; font-size: 12.5px; }

.pill {
  background: #eef2ff; color: #3346b3; border-radius: 999px;
  padding: 2px 10px; font-size: 12px; white-space: nowrap;
}
.pill.bad { background: #fdeceb; color: var(--bad); }
.pill.good { background: #e8f7ee; color: var(--good); }

.banner {
  background: var(--warn-bg); border: 1px solid #f2d99a; color: var(--warn);
  padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 13px;
}
.banner.err { background: #fdeceb; border-color: #f5b5b0; color: var(--bad); }
.warn-card { border-color: #f2d99a; background: var(--warn-bg); }
.empty { background: #fff; border: 1px dashed var(--line); border-radius: 12px; padding: 40px; text-align: center; color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
.hidden { display: none !important; }

.steps { display: grid; gap: 16px; }
.step { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.step-head h3 { margin: 0; font-size: 15px; }
.idx {
  width: 24px; height: 24px; border-radius: 50%; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
}
.step.done .idx { background: var(--good); }
.drop {
  border: 2px dashed #cfd8e6; border-radius: 10px; padding: 22px; text-align: center;
  cursor: pointer; transition: .15s; margin-top: 8px; background: #fbfcfe;
}
.drop:hover, .drop.over { border-color: var(--brand); background: #f2f6ff; }
.drop p { margin: 4px 0; }
.two { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.two label { display: flex; align-items: center; gap: 8px; color: var(--muted); }

.result { margin-top: 10px; background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.result .kv { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 6px; }
.result .kv b { font-weight: 600; }
.result .warnline { color: var(--warn); }

.prose h3 { margin: 16px 0 6px; }
.prose ol, .prose ul { margin: 6px 0; padding-left: 22px; }
.prose li { margin: 4px 0; }

.toast {
  position: fixed; right: 22px; bottom: 22px; background: #1f2937; color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 50; max-width: 460px;
}
.toast.err { background: var(--bad); }
.toast.ok { background: var(--good); }

.busy { opacity: .6; pointer-events: none; }

/* 危险操作（清空数据） */
button.danger {
  background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5;
}
button.danger:hover { background: #fecaca; }
.modal {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal.hidden { display: none; }
.modal-box {
  background: #fff; border-radius: 14px; padding: 22px 24px;
  width: min(560px, 100%); box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
}
.modal-box h3 { margin: 0 0 12px; font-size: 17px; }
.modal-box.wide { width: min(880px, 100%); }
.modal-body { font-size: 13.5px; line-height: 1.75; color: var(--text); }
.modal-body ul { margin: 8px 0; padding-left: 20px; }
.modal-body li { margin: 2px 0; }
.modal-body code {
  background: #f1f5f9; padding: 1px 6px; border-radius: 4px; font-size: 12.5px;
}
.modal-actions.left { justify-content: flex-start; margin: 4px 0 10px; }
.modal-body b.warn { color: #b91c1c; }
.modal-input { display: block; margin: 14px 0 6px; font-size: 13.5px; }
.modal-input code {
  display: inline-block; margin: 0 6px; padding: 2px 10px;
  background: #f1f5f9; border-radius: 6px; font-size: 15px; letter-spacing: 1px;
}
.modal-input input {
  display: block; margin-top: 8px; width: 180px; padding: 7px 10px; font-size: 14px;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* 店铺选择 */
.shop-pick { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.shop-pick > span { color: var(--muted); }
.shop-pick select { max-width: 240px; padding: 6px 8px; font-size: 13px; }

/* 退货去向 */
.disp-select { min-width: 168px; font-size: 12.5px; padding: 4px 6px; }
.disp-inputs { display: inline-flex; gap: 6px; align-items: center; }
.disp-inputs input { width: 86px; padding: 4px 6px; font-size: 12.5px; }
.disp-inputs.muted input { background: #f1f5f9; color: #94a3b8; }
.disp-note { width: 140px; padding: 4px 6px; font-size: 12.5px; }
.bulk-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: #f8fafc; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; margin: 8px 0;
}
.bulk-label { color: var(--muted); font-size: 12.5px; }
button.bulk { padding: 5px 12px; font-size: 12.5px; }
#bulk-discount { width: 110px; padding: 5px 8px; font-size: 12.5px; }

/* 窄屏适配：表单保持可操作，宽表格在卡片内横向滚动 */
@media (max-width: 700px) {
  body { font-size: 13px; overflow-x: hidden; }
  .top { display: block; padding: 10px 10px 8px; }
  .brand { gap: 9px; align-items: flex-start; }
  .logo { width: 34px; height: 34px; border-radius: 9px; font-size: 18px; }
  .top h1 { font-size: 16px; }
  .top .sub { font-size: 11px; line-height: 1.35; }
  .top-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
  .top-actions button { min-height: 40px; padding: 7px 6px; white-space: nowrap; }
  .shop-pick { grid-column: 1 / -1; width: 100%; min-height: 40px; }
  .shop-pick > span { flex: 0 0 auto; }
  .shop-pick select { max-width: none; min-width: 0; width: 100%; flex: 1; min-height: 40px; }
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 2px; padding: 8px 8px 0; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; padding: 10px 12px; }
  main { padding: 10px 8px 46px; }
  .card, .step { padding: 12px 10px; border-radius: 10px; margin-bottom: 10px; }
  .card-head { align-items: flex-start; gap: 8px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
  .kpi { padding: 10px 9px; }
  .kpi .v { font-size: 18px; overflow-wrap: anywhere; }
  .toolbar { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 10px; }
  .toolbar label { justify-content: space-between; }
  .toolbar select { min-width: 0; width: 68%; }
  .filters { width: 100%; gap: 6px; }
  .filters input { min-width: 0; flex: 1; width: 100%; }
  .two { align-items: stretch; flex-direction: column; gap: 8px; }
  .two label, .two select, .two input, .two button { width: 100%; min-height: 40px; }
  .two label { justify-content: space-between; }
  .drop { padding: 18px 10px; }
  .bulk-row { align-items: stretch; padding: 8px 9px; }
  .bulk-label { width: 100%; }
  button.bulk, #bulk-discount { min-height: 38px; }
  .scroll, .result { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.tbl { min-width: 680px; }
  table.tbl.small { min-width: 560px; }
  #product-tbl { min-width: 1180px; }
  #unmatched-tbl, #order-tbl, #returns-tbl, #stock-tbl, #history-tbl { min-width: 980px; }
  #flow-tbl, #recon-tbl, #fees-tbl, #purchase-periods-tbl, #manual-tbl, #backup-tbl { min-width: 560px; }
  .hint { line-height: 1.6; }
  .toast { left: 10px; right: 10px; bottom: 10px; max-width: none; }
  .modal { padding: 10px; align-items: flex-end; }
  .modal-box, .modal-box.wide { width: 100%; max-height: 92vh; overflow: auto; padding: 16px 14px; border-radius: 14px 14px 10px 10px; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions button { flex: 1; min-height: 40px; }
  .modal-input input { width: 100%; min-height: 40px; }
}

@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
  .top-actions { grid-template-columns: 1fr; }
  .shop-pick { grid-column: auto; }
}
