* { box-sizing: border-box; }

/* 顶部有吸顶栏（topbar 56px + tabs 46px ≈ 102px）。设置 scroll-padding-top 后，
   scrollIntoView / 锚点跳转 / 键盘 Tab 切到输入框时，不会把目标滚到吸顶栏底下看不见。
   注意：页面里改了吸顶高度就要同步改这个数。 */
html { scroll-padding-top: 110px; }

:root {
  --brand: #185fa5;
  --brand-dark: #10406f;
  --brand-light: #e6f1fb;
  --line: #dfe3e9;
  --bg: #f4f6f9;
  --text: #1f2733;
  --muted: #67717f;
  --ok: #1d9e75;
  --warn: #ba7517;
  --danger: #c0392b;
  --radius: 10px;
}

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

a { color: var(--brand); }

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 7px 14px;
  transition: background .15s, border-color .15s;
}
button:hover { background: #f2f5f9; }
button:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }

.btn-danger { color: var(--danger); border-color: #f0c8c2; background: #fdf6f5; }
.btn-danger:hover { background: #fbeae7; }

.btn-sm { padding: 4px 10px; font-size: 13px; }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(24, 95, 165, .12);
}
textarea { resize: vertical; min-height: 64px; }

/* ---------- 登录 / 初始化 ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px 30px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 20px; font-weight: 600; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.auth-card button { width: 100%; margin-top: 6px; }

/* ---------- 布局 ---------- */
.topbar {
  height: 56px;
  background: var(--brand-dark);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  /* 吸顶：滚到下面填表单时，退出按钮和页签条要一直可见 */
  position: sticky;
  top: 0;
  z-index: 60;
}
.topbar .brand { font-weight: 600; font-size: 15px; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; opacity: .92; }
.role-chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 20px;
  background: rgba(255, 255, 255, .18);
  font-size: 12px;
  margin-left: 6px;
}
.topbar button {
  background: rgba(255, 255, 255, .12);
  border-color: rgba(255, 255, 255, .25);
  color: #fff;
  padding: 5px 12px;
  font-size: 13px;
}
.topbar button:hover { background: rgba(255, 255, 255, .22); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  /* 吸顶并贴在 .topbar(56px) 下面。没有这一条时，页面往下滚一点页签就看不见了，
     必须滚回顶部才能切页面 —— 实测反馈过的问题。 */
  position: sticky;
  top: 56px;
  z-index: 55;
}
.tabs button {
  border: none;
  background: none;
  border-radius: 0;
  padding: 12px 14px;
  color: var(--muted);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tabs button:hover { background: none; color: var(--brand); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 500; }

.page { padding: 20px; max-width: 1500px; margin: 0 auto; }

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.card > h2 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.card > h2 .tag { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 8px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar .spacer { flex: 1; }

/* ---------- 表格 ---------- */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
th {
  background: var(--brand-light);
  color: var(--brand-dark);
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
tbody tr:nth-child(even) { background: #fafbfc; }
tbody tr:hover { background: #f2f7fd; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.mono { font-family: ui-monospace, Consolas, monospace; }
/* 日期 / 选品编码 / SKU 编码不许折行 —— 加了 SKU 编码列之后表格更挤，
   这几列一旦被压窄就会「001-HMP-」换行成「01」，很难认 */
td.nowrap { white-space: nowrap; }
/* 列表里的盈亏着色（此前只在测算面板里生效，表格里漏了） */
tbody td.pos { color: var(--ok); }
tbody td.neg { color: var(--danger); }
/* 模拟值列：系统按 2 倍马币定价算出来的，不是实际值 —— 浅橙底以示区别。
   放在 tbody tr:nth-child(even) 之后，靠顺序取胜（同特异性）。 */
tbody td.sim { background: #fff7ed; }
tbody tr:hover td.sim { background: #ffedd5; }
.ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 20px;
  font-size: 12px;
  background: #eef1f5;
  color: var(--muted);
}
.badge.ok { background: #e6f7f0; color: var(--ok); }
.badge.off { background: #fdeded; color: var(--danger); }
.pill { display:inline-block; padding:1px 7px; border-radius:20px; font-size:12px; background:var(--brand-light); color:var(--brand-dark); }

.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 12px; color: var(--muted); font-size: 13px; }

/* ---------- 表单栅格 ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.grid .full { grid-column: 1 / -1; }
.req::after { content: " *"; color: var(--danger); }

.calc-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  background: #f7f9fc;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
}
.calc-panel .item { font-size: 13px; }
.calc-panel .item .k { color: var(--muted); font-size: 12px; }
.calc-panel .item .v { font-size: 16px; font-variant-numeric: tabular-nums; font-weight: 500; }
.calc-panel .item .v.pos { color: var(--ok); }
.calc-panel .item .v.neg { color: var(--danger); }

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--brand-dark);
  margin: 18px 0 10px;
  padding-left: 9px;
  border-left: 3px solid var(--brand);
}
.section-title.todo { color: var(--warn); border-left-color: var(--warn); }

.actions { display: flex; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }

.img-box { display: flex; gap: 10px; align-items: flex-start; }
.img-box .preview {
  width: 88px; height: 88px; border: 1px dashed var(--line); border-radius: 8px;
  background: #fafbfc; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; overflow: hidden; flex: none;
}
.img-box .preview img { width: 100%; height: 100%; object-fit: contain; }

.notice {
  background: #fff8e8;
  border: 1px solid #f0dcb0;
  color: #7a5300;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
}
.notice.info { background: var(--brand-light); border-color: #bcd8f2; color: var(--brand-dark); }
.notice.danger { background: #fdf2f1; border-color: #f0c8c2; color: #96271b; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(20px);
  background: #1f2733;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 999;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #b3271b; }

/* ==================== 多行链接（1688 / 虾皮对标） ==================== */

.link-rows { display: flex; flex-direction: column; gap: 8px; }
.link-row { display: flex; gap: 8px; align-items: flex-start; }
.link-row .lk-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.link-row .lk-url { width: 100%; min-width: 0; }
.link-row .lk-sku { width: 100%; }
.link-row .lk-img { display: none; }
.link-row .lk-del {
  flex: 0 0 auto;
  padding: 6px 10px;
  color: var(--muted);
  line-height: 1;
}
.link-row .lk-del:hover { color: var(--danger); border-color: var(--danger); }
.lk-add { margin-top: 8px; }
.field > .link-rows + .lk-add { display: inline-block; }

/* 链接左边那个「参考主图」小方块：点一下再 Ctrl+V 就能粘图。
   1688 的图有 Referer 防盗链，直接引用会 403，所以走「转存到自己 COS」这条路。 */
.lk-thumb {
  position: relative;
  flex: 0 0 72px;
  width: 72px; height: 72px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fafbfc;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  outline: none;
}
.lk-thumb:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(24, 95, 165, .12); }
.lk-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.lk-thumb-ph { color: var(--muted); font-size: 11px; text-align: center; line-height: 1.4; }
.lk-thumb.busy::after {
  content: '取图中…';
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--brand);
  background: rgba(255, 255, 255, .78);
}
.lk-thumb .lk-imgclr {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; padding: 0; line-height: 1;
  font-size: 11px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .92);
  color: var(--muted); cursor: pointer; display: none;
}
.lk-thumb.has-img:hover .lk-imgclr { display: block; }
.lk-thumb .lk-imgclr:hover { color: var(--danger); border-color: var(--danger); }

/* ==================== 变体规格（勾维度 + 填取值） ==================== */

.dims-box { position: relative; }
.dims-rows { display: flex; flex-direction: column; gap: 8px; }
.dims-rows:empty { display: none; }
.dim-row { display: flex; gap: 8px; align-items: center; }
.dim-row .dim-name {
  flex: 0 0 auto;
  min-width: 84px;
  max-width: 170px;
  align-self: stretch;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--brand-light);
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dim-row .dim-vals { flex: 1 1 auto; min-width: 0; }
.dim-row .dim-del {
  flex: 0 0 auto;
  padding: 6px 10px;
  color: var(--muted);
  line-height: 1;
}
.dim-row .dim-del:hover { color: var(--danger); border-color: var(--danger); }
.dims-rows:not(:empty) + .dims-add { margin-top: 8px; }

/* 多选下拉面板。刻意不做「点外部自动收起」—— 那会和取值输入框抢焦点，老是误关。
   再点一次按钮收起。 */
.dims-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: 8px;
  z-index: 45;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(20, 32, 48, .14);
  padding: 12px;
}
.dims-panel-title { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.dims-opts { display: flex; flex-wrap: wrap; gap: 6px 8px; }
.dims-opt {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fafbfc;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.dims-opt:hover { border-color: var(--brand); background: var(--brand-light); }
.dims-opt input { width: auto; margin: 0; padding: 0; }
/* 选中态由 JS 切 .on（不依赖 CSS :has()，老 Chromium 表现一致） */
.dims-opt.on {
  border-color: var(--brand);
  background: var(--brand-light);
  color: var(--brand-dark);
  font-weight: 500;
}
.dims-custom { display: flex; gap: 8px; margin-top: 10px; }
.dims-custom input { flex: 1; min-width: 0; }
.dims-custom button { flex: 0 0 auto; }

/* ==================== SKU 编码（一个品多条） ==================== */

.code-rows { display: flex; flex-direction: column; gap: 8px; }
.code-row { display: flex; gap: 8px; align-items: center; }
.code-row .sk-code { flex: 1 1 auto; min-width: 0; max-width: 420px; }
.code-row .lk-del {
  flex: 0 0 auto;
  padding: 6px 10px;
  color: var(--muted);
  line-height: 1;
}
.code-row .lk-del:hover { color: var(--danger); border-color: var(--danger); }
.code-rows:not(:empty) + .lk-add { margin-top: 8px; }

/* 列表里「等 N 条」这类补充说明 */
td .more { color: var(--muted); font-size: 12px; }

/* 系统自动算出来的值：灰底只读，一眼能看出「不用你填」 */
.derived-input[readonly] {
  background: #f1f4f8;
  color: var(--brand-dark);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: default;
}

/* 测算面板里「扣减项」用减号色，和盈利/亏损区分开 */
.calc-panel .item .v.minus { color: var(--warn); }

/* ==================== 弹窗 ==================== */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 35, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}
.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 460px;
  padding: 20px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .25);
}
.modal h3 { margin: 0 0 6px; font-size: 16px; }
.modal-desc { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.modal-body .field { margin-bottom: 12px; }
.modal-body .field:last-child { margin-bottom: 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn-primary { flex: 1; }

.row-inline { display: flex; gap: 8px; }
.row-inline input { flex: 1; min-width: 0; }
.row-inline button { flex: 0 0 auto; }

.rate-eq { color: var(--brand-dark); }
code {
  background: #f1f4f8;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

@media (max-width: 720px) {
  .page { padding: 12px; }
  .topbar { padding: 0 12px; gap: 10px; }
  .topbar .brand { font-size: 14px; }
  .grid { grid-template-columns: 1fr; }
  .link-row { flex-wrap: wrap; }
  .link-row .lk-main { flex: 1 1 calc(100% - 80px); }
}
