:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #1f2330;
  --ink-2: #5a6172;
  --ink-3: #8b93a6;
  --line: #e3e7ef;
  --brand: #2f6fed;
  --brand-dark: #1f55c4;
  --ok: #12a150;
  --warn: #d98410;
  --danger: #d93f3f;
  --radius: 12px;
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

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

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  background: #eef1f7;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

/* ==================== 整体骨架：左sidebar + 右内容 ==================== */

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 17px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-weight: 600;
  font-size: 16px;
  flex: 0 0 auto;
}
.brand:hover { text-decoration: none; }
.brand-icon { font-size: 20px; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.side-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px;
}
.side-group {
  font-size: 12px;
  color: var(--ink-3);
  padding: 14px 9px 5px;
  letter-spacing: .5px;
}
.side-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 14px;
  margin-bottom: 2px;
  transition: background .13s, color .13s;
}
.side-item:hover {
  background: #f2f5fb;
  color: var(--ink);
  text-decoration: none;
}
.side-item.active {
  background: #eef3ff;
  color: var(--brand);
  font-weight: 600;
}
.side-icon { font-size: 16px; flex: 0 0 auto; width: 20px; text-align: center; }
.side-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.side-foot {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding: 11px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-3);
}
.side-logout { color: var(--ink-3); }
.side-logout:hover { color: var(--danger); text-decoration: none; }

.content {
  flex: 1 1 auto;
  min-width: 0;
  padding: 24px 30px 64px;
}

/* 登录页这种没有侧边栏的页面 */
body.bare {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.content-bare {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.footer-bare { text-align: center; color: var(--ink-3); font-size: 13px; padding: 20px; }

/* ==================== 首页 ==================== */

.hero { margin-bottom: 22px; }
.hero h1 { margin: 0 0 6px; font-size: 25px; }
.lead { color: var(--ink-2); margin: 0; }

.tool-grid { display: grid; gap: 13px; }
.tool-card {
  display: flex;
  align-items: center;
  gap: 15px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 17px 19px;
  color: var(--ink);
  transition: border-color .15s, transform .1s;
}
.tool-card:hover {
  text-decoration: none;
  border-color: var(--brand);
  transform: translateY(-1px);
}
.tool-icon {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: #eef3ff;
  border-radius: 10px;
  font-size: 23px;
  flex: 0 0 auto;
}
.tool-body { flex: 1; min-width: 0; }
.tool-body h2 { margin: 0 0 2px; font-size: 16px; }
.tool-body p { margin: 0 0 6px; color: var(--ink-2); font-size: 14px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: 12px;
  color: var(--ink-2);
  background: #f1f3f8;
  border-radius: 999px;
  padding: 1px 9px;
}
.tool-arrow { color: var(--ink-3); font-size: 18px; }

.notes {
  margin-top: 26px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.notes h2 { margin: 0 0 8px; font-size: 15px; }
.notes ul { margin: 0; padding-left: 20px; color: var(--ink-2); font-size: 14px; }
.notes li.warn { color: var(--danger); }

/* ==================== 工具页 ==================== */

.tool-head { margin-bottom: 18px; }
.tool-head h1 { margin: 0 0 6px; font-size: 23px; display: flex; align-items: center; gap: 10px; }
.tool-head .lead { max-width: 780px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 19px;
  margin-bottom: 16px;
}
.card > h2 { margin: 0 0 13px; font-size: 16px; }
.card > h2 .hint { font-weight: 400; color: var(--ink-3); font-size: 13px; margin-left: 8px; }

/* 上传 */
.upload {
  border: 2px dashed #c9d2e4;
  border-radius: var(--radius);
  padding: 26px 20px;
  text-align: center;
  transition: border-color .15s, background .15s;
  cursor: pointer;
  display: block;
}
.upload.dragover { border-color: var(--brand); background: #f2f6ff; }
.upload .big { font-size: 30px; }
.upload .hint { color: var(--ink-3); font-size: 13px; margin-top: 4px; }
.upload .picked { color: var(--ok); font-weight: 600; margin-top: 8px; word-break: break-all; }
.upload input[type=file] { display: none; }

.fieldrow {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); }
.field input {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
  color: var(--ink);
}
.field input:focus { outline: none; border-color: var(--brand); }
.field select,
.field textarea {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
  color: var(--ink);
  resize: vertical;
}
.field select:focus,
.field textarea:focus { outline: none; border-color: var(--brand); }
.field .req { color: var(--danger); }

.actions { margin-top: 15px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}
.btn:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
  padding: 10px 22px;
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-sm { padding: 4px 11px; font-size: 13px; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); background: #fdf3f3; }
.inline-form { display: inline; margin: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 结果 */
/* 统计块（数字概览） */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  background: #f7f9fd;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}
.stat .n { font-size: 24px; font-weight: 700; line-height: 1.3; }
.stat .l { color: var(--ink-2); font-size: 13px; }

.meta-row { display: flex; flex-wrap: wrap; gap: 8px 22px; color: var(--ink-2); font-size: 14px; }
.meta-row b { color: var(--ink); }

.result-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.result-block:last-child { margin-bottom: 0; }
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.result-head h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.count-pill {
  font-size: 13px;
  background: #eef3ff;
  color: var(--brand);
  border-radius: 999px;
  padding: 2px 10px;
  font-weight: 600;
}
.result-block.empty .count-pill { background: #f1f3f8; color: var(--ink-3); }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.result-sub { color: var(--ink-3); font-size: 13px; margin-top: 4px; }

textarea.ids {
  width: 100%;
  min-height: 88px;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
  word-break: break-all;
}

details.more { margin-top: 10px; }
details.more summary { cursor: pointer; color: var(--ink-2); font-size: 13px; }
table.mini { border-collapse: collapse; width: 100%; margin-top: 8px; font-size: 13px; }
table.mini th, table.mini td { border-bottom: 1px solid var(--line); padding: 5px 8px; text-align: left; }
table.mini th { color: var(--ink-2); font-weight: 500; }
table.mini td.num { text-align: right; width: 70px; }
table.mini tr:last-child td { border-bottom: none; }

.funnel { margin: 8px 0 0; padding: 0; list-style: none; font-size: 13px; }
.funnel li { color: var(--ink-2); }
.funnel li b { color: var(--ink); }

.alert {
  border-radius: 8px;
  padding: 10px 14px;
  margin: 0 0 12px;
  font-size: 14px;
}
.alert-warn { background: #fff7e8; border: 1px solid #f2dcb3; color: #7a5310; }
.alert-error { background: #fdeeee; border: 1px solid #f3c9c9; color: #8f2725; }
.alert-info { background: #eef4ff; border: 1px solid #cfdef8; color: #23457f; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }

/* 列映射 */
table.cols { border-collapse: collapse; font-size: 13px; width: 100%; }
table.cols th, table.cols td { border-bottom: 1px solid var(--line); padding: 6px 10px; text-align: left; }
table.cols th { color: var(--ink-2); font-weight: 500; }
.ok-mark { color: var(--ok); }
.miss-mark { color: var(--danger); }

/* 金额列选择器 */
.colpick {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 6px 14px;
  margin: 12px 0 4px;
  padding: 12px;
  background: #f7f9fd;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 260px;
  overflow-y: auto;
}
.colchk { display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.colchk input { margin: 0; flex: 0 0 auto; }
.colchk span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

table.mini tfoot td { border-top: 2px solid var(--line); border-bottom: none; padding-top: 8px; }

/* 历史 */
table.history { border-collapse: collapse; width: 100%; font-size: 14px; }
table.history th, table.history td { border-bottom: 1px solid var(--line); padding: 9px 10px; text-align: left; }
table.history th { color: var(--ink-2); font-weight: 500; font-size: 13px; }
table.history tr:last-child td { border-bottom: none; }
.muted { color: var(--ink-3); }

/* 登录 */
.login-box {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  margin: 0;
}
.login-box h1 { margin: 0 0 4px; font-size: 22px; }
.login-form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.login-form input {
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}
.login-form input:focus { outline: none; border-color: var(--brand); }

.error-box { max-width: 520px; text-align: center; }
.error-box h1 { font-size: 46px; margin: 0; color: var(--ink-3); }

/* 处理中的遮罩 */
#busy {
  display: none;
  position: fixed; inset: 0;
  background: rgba(255,255,255,.75);
  z-index: 100;
  align-items: center; justify-content: center;
  flex-direction: column;
  gap: 14px;
}
#busy.on { display: flex; }
.spinner {
  width: 34px; height: 34px;
  border: 3px solid #d7deeb;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== 窄屏：侧边栏变成顶部横向导航 ==================== */

@media (max-width: 760px) {
  .app { flex-direction: column; }

  .sidebar {
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding: 12px 14px; font-size: 15px; }
  .side-nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 8px 10px;
    flex: 0 0 auto;
  }
  .side-group { display: none; }
  .side-item { margin-bottom: 0; white-space: nowrap; flex: 0 0 auto; }
  .side-foot { display: none; }

  .content { padding: 18px 14px 44px; }
  .tool-head h1 { font-size: 20px; }
}

/* 首页的分节标题（工具 / 数据区）*/
.group-head { margin: 26px 0 -4px; }
.group-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: .04em;
}
.group-head h2::before {
  content: "";
  display: inline-block;
  width: 4px; height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
  border-radius: 2px;
  background: var(--brand, #2f6fed);
}

/* 覆盖确认框（客户尺码管理）*/
.confirm-card { border-color: #f0c36d; box-shadow: 0 0 0 3px #fdf6e3; }
table.cols td.changed { color: var(--brand); font-weight: 600; }
table.cols td.changed::after { content: " ← 新"; font-size: 12px; color: var(--ink-2); font-weight: 400; }
