:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --line: #e3e8ef;
  --text: #1f2733;
  --muted: #6b7787;
  --primary: #2563eb;
  --primary-dark: #1d4fc4;
  --green: #16a34a;
  --red: #dc2626;
  --yellow: #d97706;
  --gray: #64748b;
  --blue: #2563eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 28px;
  background: linear-gradient(120deg, #1e3a8a, #2563eb);
  color: #fff;
}
.topbar h1 { margin: 0 0 4px; font-size: 22px; }
.topbar .sub { margin: 0; opacity: .85; font-size: 13px; }
.stats { font-size: 14px; opacity: .95; }
.stats b { font-size: 18px; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px;
  margin-bottom: 22px;
  box-shadow: 0 1px 3px rgba(16, 24, 40, .06);
}
.card h2 { margin: 0 0 16px; font-size: 17px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, select {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--primary); }
.inline { display: flex; align-items: center; gap: 8px; }
.inline input { width: 90px; }
.checkbox { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }

.form-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--text); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn.start { background: #ecfdf3; color: var(--green); border-color: #bbeacb; }
.btn.pause { background: #fff7ed; color: var(--yellow); border-color: #fde2c4; }
.btn.danger { background: #fef2f2; color: var(--red); border-color: #fecaca; }
.btn.link { background: none; border: none; color: var(--primary); cursor: pointer; padding: 5px 8px; }

.msg { font-size: 13px; color: var(--muted); }
.msg.ok { color: var(--green); }
.msg.err { color: var(--red); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
th, td { padding: 10px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }

/* 固定列宽：除商品/链接列占剩余宽度外，其余列宽度写死，避免名称/链接长短导致后续列错位 */
th:nth-child(2), td:nth-child(2) { width: 88px; }   /* 间隔（可编辑） */
th:nth-child(3), td:nth-child(3) { width: 84px; }   /* 状态 */
th:nth-child(4), td:nth-child(4) { width: 92px; }   /* 价格（两行） */
th:nth-child(5), td:nth-child(5) { width: 118px; }  /* 刷新时间（两行） */
th:nth-child(6), td:nth-child(6) { width: 190px; }  /* 结果 */
th:nth-child(7), td:nth-child(7) { width: 110px; }  /* 验证 */
th:nth-child(8), td:nth-child(8) { width: 230px; }  /* 操作（居中） */

td .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td .url { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td:nth-child(6) { word-break: break-word; white-space: normal; } /* 结果列允许换行，不截断 */

/* 刷新时间两行：上行日期，下行时分秒 */
.dt { display: flex; flex-direction: column; line-height: 1.35; }
.dt-date { color: var(--text); white-space: nowrap; }
.dt-time { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* 价格两行：上行网站原始价，下行人民币换算价 */
.price { display: flex; flex-direction: column; line-height: 1.35; }
.price-raw { color: var(--text); white-space: nowrap; }
.price-cny { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* 间隔行内编辑 */
.interval-cell { display: flex; align-items: center; gap: 4px; }
.interval-input { width: 54px; padding: 5px 7px; font-size: 13px; }
.interval-unit { color: var(--muted); font-size: 12px; white-space: nowrap; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.st-idle { background: #eef2f7; color: var(--gray); }
.st-checking { background: #eff4ff; color: var(--blue); }
.st-in_stock { background: #ecfdf3; color: var(--green); }
.st-out_of_stock { background: #f1f5f9; color: var(--gray); }
.st-unknown { background: #fffbeb; color: var(--yellow); }
.st-error { background: #fef2f2; color: var(--red); }
.st-blocked { background: #f5f3ff; color: #7c3aed; }
.st-skipped { background: #f8fafc; color: var(--muted); }

/* 验证栏状态徽章 */
.vf-verified { background: #ecfdf3; color: var(--green); }
.vf-challenge { background: #fef2f2; color: var(--red); }
.vf-unknown { background: #eef2f7; color: var(--gray); }
.badge.dim { background: #f1f5f9; color: var(--muted); }
.verify-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }

.op-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
.hint { margin-top: 12px; font-size: 12px; color: var(--muted); }

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

.shop-group { margin-bottom: 22px; }
.shop-group:last-child { margin-bottom: 0; }
.shop-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 2px solid var(--line);
  margin-bottom: 4px;
}
.shop-name { font-size: 15px; font-weight: 700; color: var(--text); }
.shop-meta { font-size: 12px; color: var(--muted); }
.brand-tag {
  display: inline-block;
  margin-top: 3px;
  padding: 1px 9px;
  border-radius: 6px;
  background: #eef2ff;
  color: var(--primary);
  font-size: 12px;
}
td .brand-tag { margin-bottom: 3px; }

.brand-group { margin: 12px 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.brand-group > summary {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 11px 14px;
  cursor: pointer;
  background: #f8fafc;
  list-style: none;
}
.brand-group > summary::-webkit-details-marker { display: none; }
.brand-group > summary:hover { background: #eef2f7; }
.brand-group > summary::before {
  content: '▸';
  color: var(--muted);
  font-size: 12px;
  width: 14px;
  flex: none;
}
.brand-group[open] > summary::before { content: '▾'; }
.brand-name { font-weight: 600; font-size: 14px; color: var(--text); }
.brand-meta { font-size: 12px; color: var(--muted); }
.switch { margin-left: auto; flex: none; width: 40px; height: 22px; border-radius: 22px; background: #cbd5e1; border: none; cursor: pointer; position: relative; padding: 0; transition: background .2s; }
.switch .slider { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .2s; }
.switch.on { background: #16a34a; }
.switch.on .slider { transform: translateX(18px); }
.brand-group .table-wrap { border-top: 1px solid var(--line); }

/* 结果列错误短提示 */
.result-err { color: var(--red); }

/* 错误日志区 */
.err-item { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.err-item:last-child { margin-bottom: 0; }
.err-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.err-title { font-weight: 600; font-size: 14px; color: var(--text); }
.err-group { font-size: 12px; color: var(--primary); background: #eef2ff; padding: 1px 9px; border-radius: 6px; }
.err-time { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.err-body {
  margin: 0;
  max-height: 160px;
  overflow: auto;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: Consolas, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

/* 错误日志卡片：标题栏控件 / 折叠 / 隐藏 */
.topbar-right { display: flex; align-items: center; gap: 16px; }
.card-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card-bar h2 { margin: 0; }
.err-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.err-controls select { flex: 0 0 auto; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); font-size: 13px; }
.badge.dim { font-size: 12px; color: var(--muted); background: #f1f5f9; border-radius: 6px; padding: 1px 8px; margin-left: 4px; }
.err-kind { font-size: 12px; color: #b45309; background: #fef3c7; padding: 1px 9px; border-radius: 6px; }

#error-card.collapsed #error-list { display: none; }
#error-card.hidden { display: none; }

/* 顶部蓝色栏内的小按钮（卡片被隐藏后的恢复入口） */
.topbar .btn.sm.ghost { padding: 6px 12px; font-size: 13px; background: rgba(255,255,255,.16); color: #fff; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; cursor: pointer; }
.topbar .btn.sm.ghost:hover { background: rgba(255,255,255,.28); }
.topbar .btn.sm.danger { padding: 6px 12px; font-size: 13px; background: rgba(220,38,38,.25); color: #fff; border: 1px solid rgba(252,165,165,.5); border-radius: 8px; cursor: pointer; }
.topbar .btn.sm.danger:hover { background: rgba(220,38,38,.45); }
.topbar .btn.sm.danger:disabled { opacity: .6; cursor: default; }

/* 内嵌网页验证弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(15, 23, 42, .6); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-mask[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 14px; width: 100%; max-width: 960px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); overflow: hidden; display: flex; flex-direction: column; }
.modal-bar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid #eef2f7; }
.modal-title { font-weight: 600; font-size: 15px; max-width: 30%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-url { flex: 1; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-stage { background: #0f172a; padding: 10px; display: flex; align-items: center; justify-content: center; touch-action: none; outline: none; }
.modal-stage img { max-width: 100%; height: auto; border-radius: 8px; user-select: none; -webkit-user-select: none; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid #eef2f7; }
.modal-foot input { flex: 1; }
.modal-foot .hint { font-size: 12px; color: var(--muted); }
@media (max-width: 640px) {
  .modal-mask { padding: 0; }
  .modal-box { max-width: 100%; height: 100%; border-radius: 0; }
  .modal-stage { flex: 1; }
  .modal-title { max-width: 40%; }
  .modal-foot .hint { display: none; }
}

/* 登录遮罩（局域网访问校验） */
.login-box { background: #fff; border-radius: 14px; width: 100%; max-width: 340px; padding: 26px 24px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); display: flex; flex-direction: column; gap: 14px; }
.login-title { font-size: 17px; font-weight: 600; }
.login-tip { font-size: 13px; color: var(--muted); }
.login-box input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; box-sizing: border-box; }
.login-row { display: flex; justify-content: flex-end; }
.login-error { font-size: 13px; color: var(--red); }

/* 库存汇总 */
.sum-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 860px) { .sum-grid { grid-template-columns: 1fr; } }
.sum-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; border-top: 3px solid var(--gray); }
.sum-card.sum-in { border-top-color: var(--green); }
.sum-card.sum-out { border-top-color: var(--gray); }
.sum-card.sum-fail { border-top-color: var(--red); }
.sum-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.sum-title { font-size: 14px; font-weight: 600; }
.sum-count { font-size: 22px; font-weight: 700; }
.sum-in .sum-count { color: var(--green); }
.sum-out .sum-count { color: var(--gray); }
.sum-fail .sum-count { color: var(--red); }
.sum-list { display: flex; flex-direction: column; gap: 7px; max-height: 260px; overflow-y: auto; }
.sum-item { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; font-size: 13px; cursor: pointer; border-radius: 6px; padding: 2px 4px; margin: -2px -4px; }
.sum-item:hover { background: #f1f5f9; }
.row-flash td { background: #fff7ed !important; }
.row-flash td:first-child { box-shadow: inset 3px 0 0 #f97316; }
.sum-item-name { font-weight: 600; }
.sum-item-meta { color: var(--muted); font-size: 12px; }
.sum-item-reason { margin-left: auto; font-size: 11px; color: var(--red); background: #fef2f2; border-radius: 6px; padding: 1px 8px; }
.sum-empty { color: var(--muted); font-size: 13px; }
.sum-other { margin-top: 14px; font-size: 12px; color: var(--muted); }

/* ---------- 访问安全 ---------- */
.sec-tip { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.sec-bad-title { font-size: 13px; font-weight: 600; color: var(--red); margin: 12px 0 8px; }
.sec-head-row, .sec-row { display: flex; align-items: center; gap: 12px; padding: 9px 4px; border-bottom: 1px solid var(--line); font-size: 13px; }
.sec-head-row { color: var(--muted); font-size: 12px; font-weight: 600; border-bottom: 2px solid var(--line); }
.sec-head-row span, .sec-row > span { flex: 1; min-width: 0; }
.sec-ip { font-weight: 600; font-family: ui-monospace, Consolas, monospace; }
.sec-stat { color: var(--muted); }
.sec-stat b { color: var(--text); }
.sec-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.sec-path { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sec-badge { flex: 0 0 auto; padding: 2px 10px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.sec-badge.ok { background: #f0fdf4; color: #16a34a; }
.sec-badge.warn { background: #fffbeb; color: #d97706; }
.sec-badge.bad { background: #fef2f2; color: var(--red); }
.sec-row.blocked { background: #fefafa; }
.sec-row .btn { flex: 0 0 auto; }
@media (max-width: 720px) {
  .sec-head-row { display: none; }
  .sec-row { flex-wrap: wrap; }
}
