:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e3e6ea;
  --border-strong: #ccd2d9;
  --text: #1b2430;
  --text-2: #5a6673;
  --text-3: #8b95a1;
  --primary: #17518c;
  --primary-soft: #e8f0f9;
  --red: #c62828;
  --red-soft: #fdecec;
  --amber: #b26b00;
  --amber-soft: #fdf3e2;
  --blue: #1565c0;
  --blue-soft: #e8f1fc;
  --green: #1b7a43;
  --green-soft: #e7f5ec;
  --gray-soft: #eef0f2;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(20, 30, 45, .07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 54px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
  margin-right: 20px;
  white-space: nowrap;
}
.brand small { font-weight: 400; color: var(--text-3); font-size: 12px; margin-left: 6px; }
.nav {
  display: flex;
  align-items: center;          /* 所有导航项在同一水平线上 */
  gap: 2px;
  flex: 1;
}
.nav > a,
.nav > .drop,
.drop-toggle {
  display: inline-flex;
  align-items: center;          /* 文字垂直居中 */
  justify-content: center;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 14px;
  line-height: 1;               /* 防止 ▾ 等特殊字符撑开行高 */
  white-space: nowrap;
}
.nav > a:hover,
.drop-toggle:hover { background: var(--gray-soft); text-decoration: none; }
.nav > a.active,
.drop-toggle.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 13px; }

.wrap { max-width: 1440px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-tight { padding: 0; overflow: hidden; }
.card-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-2);
}
.card-head h2, .card-head h3 { margin: 0; }

.grid { display: grid; gap: 14px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat .n { font-size: 30px; font-weight: 600; line-height: 1.2; }
.stat .t { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.stat.red .n { color: var(--red); }
.stat.amber .n { color: var(--amber); }
.stat.blue .n { color: var(--blue); }
.stat.green .n { color: var(--green); }
.stat.clickable { cursor: pointer; transition: border-color .15s; }
.stat.clickable:hover { border-color: var(--primary); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { min-height: 48px; }
.table-scroll { overflow-x: auto; width: 100%; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 13px; }
.nowrap { white-space: nowrap; }

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 13px; /* 与按钮字号一致（梁总 2026-08-20 定：表格内 tag 与 查看 按钮同字号） */
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.7;
}
.tag.red { background: var(--red-soft); color: var(--red); }
.tag.amber { background: var(--amber-soft); color: var(--amber); }
.tag.blue { background: var(--blue-soft); color: var(--blue); }
.tag.green { background: var(--green-soft); color: var(--green); }
.tag.gray, .tag.done, .tag.none { background: var(--gray-soft); color: var(--text-2); }

.bar { height: 7px; background: var(--gray-soft); border-radius: 4px; overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 4px; transition: width .3s; }
.bar.full > i { background: var(--green); }
.progress-cell { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.progress-cell span { font-size: 12px; color: var(--text-2); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }

button, .btn {
  font-family: inherit;
  font-size: 14px;
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
button:hover, .btn:hover { background: var(--gray-soft); text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 500; }
.btn-primary:hover { background: #123f6e; }
.btn-danger { color: var(--red); border-color: #e8b4b4; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[type="number"] { text-align: right; }
label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 14px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-width: 130px; }
.toolbar .grow { flex: 1; min-width: 200px; }

.muted { color: var(--text-3); }
.small { font-size: 12px; }
.empty { text-align: center; padding: 40px 20px; color: var(--text-3); }
.err { background: var(--red-soft); color: var(--red); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 30, 45, .45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 10px; padding: 20px;
  width: 100%; max-width: 620px; max-height: 88vh; overflow: auto;
  box-shadow: 0 12px 40px rgba(20, 30, 45, .22);
}
.modal h2 { margin-bottom: 14px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.modal-xl { max-width: min(1200px, 92vw); width: 100%; }
.modal-xl .modal-body { max-height: calc(88vh - 120px); overflow-y: auto; padding-right: 6px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1b2430; color: #fff; padding: 11px 22px; border-radius: 24px;
  font-size: 14px; z-index: 200; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast.err { background: var(--red); color: #fff; }

.steps { display: flex; flex-wrap: wrap; gap: 6px; }
.step-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 16px; font-size: 12px;
  border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer;
  transition: border-color .12s;
}
.step-chip:hover { border-color: var(--primary); }
.step-chip.done { background: var(--green-soft); border-color: #a8d5b9; color: var(--green); }
.step-chip.doing { background: var(--blue-soft); border-color: #a9cbf0; color: var(--blue); }
.step-chip.skip { background: var(--gray-soft); color: var(--text-3); text-decoration: line-through; }
.step-chip b { font-weight: 600; }

/* 商品页标准路线流程条 */
td.route-cell { min-width: 420px; max-width: 520px; }
th.route-head { min-width: 420px; }
.route-flow {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px;
  font-size: 12px; line-height: 1.4;
}
.route-step {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px 3px 4px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  white-space: nowrap;
}
.route-no {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 11px; font-weight: 700;
}
.route-name { font-weight: 600; color: var(--text); }
.route-machine {
  padding: 1px 5px; border-radius: 4px;
  background: var(--blue-soft); color: var(--blue);
  font-size: 11px;
}
.route-arrow { color: var(--text-3); font-size: 11px; padding: 0 1px; }

.item-row > td { background: var(--surface); }
.sub-row > td { background: var(--surface-2); padding: 10px 16px 14px 34px; }

/* ===== 表单 / 步骤编辑 ===== */
.full { width: 100%; grid-column: 1 / -1; }
.btn-cell { white-space: nowrap; }
.steps-edit { display: flex; flex-direction: column; gap: 8px; }
.step-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.step-row input { width: auto; }
ol.steps { list-style: decimal; padding-left: 22px; display: block; gap: 4px; }
ol.steps > li { display: block; margin-bottom: 4px; }
ol.steps .muted { display: inline; }

@media (max-width: 780px) {
  .wrap { padding: 12px; }
  .topbar { padding: 0 12px; height: auto; flex-wrap: wrap; gap: 6px; padding-bottom: 8px; }
  .nav { overflow-x: auto; }
  th { position: static; }
  .table-scroll { overflow-x: auto; }
}

/* ===== 商品列表分页（向进销存学习：每页30条，最新在前，2026-08-20） ===== */
.pager { display: flex; align-items: center; justify-content: flex-start; gap: 10px; padding: 10px 2px; flex-wrap: wrap; } /* 梁总 2026-08-20 定：分页器左对齐 */
.pager-info { color: var(--text-3); font-size: 12.5px; }
.pager .btn-sm { padding: 4px 12px; }

/* ===== 多标签工作台（梁总 2026-08-20 定：跟进销存一样多窗口任务） ===== */
.workspace { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.tabbar {
  display: flex; align-items: flex-end; gap: 4px;
  padding: 8px 12px 0; background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; flex-shrink: 0;
}
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border: 1px solid var(--border); border-bottom: none;
  border-radius: 8px 8px 0 0; background: var(--gray-soft);
  cursor: pointer; font-size: 13px; color: var(--text-2);
  white-space: nowrap; user-select: none;
}
.tab:hover { color: var(--primary); }
.tab.active { background: #fff; color: var(--primary); font-weight: 600; }
.tab-x {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 4px;
  font-size: 14px; line-height: 1; color: var(--text-3);
}
.tab-x:hover { background: var(--gray-soft); color: var(--danger, #c0392b); }
.ws-frame { flex: 1; position: relative; background: #fff; }
.ws-frame iframe { width: 100%; height: 100%; border: 0; display: none; }
.ws-frame iframe.active { display: block; }
/* iframe 内页面：隐藏顶部导航后留出合理内边距 */
body.in-iframe .wrap { padding: 16px 20px; }
body.in-iframe .topbar { display: none; }

/* ===== 二级下拉菜单（梁总 2026-08-20 定：全部菜单二级化，跟进销存一样） ===== */
.drop { position: relative; }
.drop-toggle { cursor: pointer; user-select: none; }
.drop-menu {
  display: none; position: absolute; top: 100%; left: 0; z-index: 60;
  min-width: 140px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 4px;
}
.drop-menu a { display: block; padding: 7px 12px; border-radius: 6px; color: var(--text-2); font-size: 13.5px; }
.drop-menu a:hover { background: var(--gray-soft); color: var(--primary); text-decoration: none; }
.drop-menu a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.drop:hover .drop-menu { display: block; }
.drop-toggle.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
/* 复选框整体放大 50%（梁总 2026-08-20 定） */
input[type="checkbox"] { width: 20px; height: 20px; cursor: pointer; vertical-align: middle; }

/* ===== 系统基本参数：标签编辑（商品种类/单位/材料/表面处理） ===== */
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 12px; border-radius: 20px;
  background: var(--primary-soft); color: var(--primary);
  font-size: 13px; font-weight: 500; line-height: 1.6;
}
.chip-edit {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  border: none; background: rgba(23, 81, 140, .18); color: var(--primary);
  cursor: pointer; font-size: 12px; line-height: 1; padding: 0;
}
.chip-edit:hover { background: var(--primary); color: #fff; }
.chip-editing {
  padding: 2px 4px 2px 8px;
  background: #fff;
  border: 1px solid var(--primary);
  border-radius: 20px;
  gap: 4px;
}
.chip-input {
  width: 90px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 13px;
}
.chip-save, .chip-cancel {
  padding: 2px 8px;
  border-radius: 12px;
  border: none;
  font-size: 12px;
  cursor: pointer;
}
.chip-save { background: var(--primary); color: #fff; }
.chip-cancel { background: var(--bg); color: var(--text); }
.add-row { display: flex; gap: 8px; }
.add-row input { width: auto; flex: 1; min-width: 160px; }
