/* 立柱出厂检测 H5 —— 移动端优先 · 米白浅色主题 */
:root {
  --bg: #f3f0e9;        /* 米白背景 */
  --card: #ffffff;      /* 卡片纯白 */
  --card-2: #f6f3ec;    /* 输入框/次级面 暖白 */
  --line: #e4ddcf;      /* 暖灰描边 */
  --text: #2f3138;      /* 主文字 深石板 */
  --muted: #8f897b;     /* 次要文字 暖灰 */
  --blue: #2563eb;
  --blue-soft: #e8eefc;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40, 35, 25, .05), 0 6px 16px rgba(40, 35, 25, .04);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 14px calc(env(safe-area-inset-bottom) + 24px);
}

/* 顶部状态条 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 14px 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar h1 { font-size: 17px; margin: 0; flex: 1; font-weight: 700; }
.conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn[data-on="1"] { color: #15803d; background: #eaf6ee; border-color: #c6e9d2; }
.conn[data-on="1"] .dot { background: var(--green); box-shadow: 0 0 6px rgba(22,163,74,.5); }
.conn[data-on="0"] { color: #b91c1c; background: #fceceb; border-color: #f3cfcd; }
.conn[data-on="0"] .dot { background: var(--red); }

/* 设备切换 Tab */
.tabs { display: flex; gap: 8px; margin: 4px 0 14px; }
.tab {
  flex: 1;
  padding: 12px 0;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.tab.active { color: #fff; background: var(--blue); border-color: var(--blue); }

/* 一键自检按钮 */
.btn-selfcheck {
  width: 100%;
  margin: 0 0 14px;
  padding: 13px 0;
  border: 1px solid #cdbf9a;
  border-radius: var(--radius);
  background: #fbf2da;
  color: #8a6d1f;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow);
}
.btn-selfcheck .ico { width: 18px; height: 18px; }
.btn-selfcheck:active { filter: brightness(0.97); }
.btn-selfcheck:disabled { opacity: 0.6; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 14px; margin: 0 0 12px; color: var(--muted); font-weight: 600; }

label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }

/* 仅作用于文本类输入与下拉，排除复选框/单选——否则 appearance:none 会抹掉对勾 */
input:not([type="checkbox"]):not([type="radio"]), select {
  width: 100%;
  padding: 12px 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  appearance: none;
}
input::placeholder { color: #b3ab9b; }
input:focus, select:focus { border-color: var(--blue); background: #fff; box-shadow: 0 0 0 3px var(--blue-soft); }

/* SN 行：输入 + 扫码按钮 */
.sn-row { display: flex; gap: 8px; align-items: flex-end; }
/* 扫码按钮与输入框底边对齐：清掉输入框继承的 margin-bottom，否则按钮显得偏上 */
.sn-row .field { flex: 1; margin-bottom: 0; }
.btn-scan { height: 46px; }
.btn-scan {
  flex: 0 0 auto;
  padding: 12px 16px;
  background: var(--green);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 6px rgba(22,163,74,.25);
}
.btn-scan:active { filter: brightness(0.95); }
.btn-scan .ico { width: 18px; height: 18px; }

/* 内联图标基线对齐 */
.ico { display: inline-block; vertical-align: -3px; }

.field { margin-bottom: 12px; }
.fields-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fields-grid .field.full { grid-column: 1 / -1; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0; }

.actions { display: flex; gap: 8px; margin-top: 4px; }
.btn {
  flex: 1;
  padding: 14px 0;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
}
.btn-primary { background: var(--blue); color: #fff; box-shadow: 0 2px 6px rgba(37,99,235,.25); }
.btn-ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn-cancel { background: #fceceb; color: var(--red); border: 1px solid #f3cfcd; }
.btn:disabled { opacity: 0.5; }
.btn:active { filter: brightness(0.95); }

.error { color: var(--red); font-size: 13px; min-height: 18px; margin: 8px 0 0; }

/* 回包结果区 */
.result { margin-top: 0; }
.result-flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--muted);
  margin-bottom: 10px;
}
.result-flag[data-state="ok"] { background: #eaf6ee; border-color: #c6e9d2; color: #15803d; }
.result-flag[data-state="wait"] { background: #fdf3e3; border-color: #f3e0bf; color: var(--amber); }
.result-flag[data-state="fail"] { background: #fceceb; border-color: #f3cfcd; color: var(--red); }
.result-flag .flag-icon .ico { width: 16px; height: 16px; vertical-align: -3px; }
/* 等待回包时图标旋转 */
.result-flag[data-state="wait"] .flag-icon .ico { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

pre {
  margin: 0;
  padding: 12px;
  background: #faf8f2;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: #3f4654;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 240px;
  overflow: auto;
}
.io-label { font-size: 12px; color: var(--muted); margin: 10px 0 4px; }

.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--blue); color: #fff; }
/* 协议 CMD 号对测试员是噪音：弱化成灰色小标，仅供工程师对照协议 */
.cmd-badge { background: var(--card-2); color: var(--muted); border: 1px solid var(--line); font-weight: 500; }
.topic-line { font-size: 11px; color: var(--muted); word-break: break-all; margin-top: 8px; }

/* 自检报告弹层 */
.report {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(30, 26, 18, .45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.report.open { display: flex; }
.report-card {
  width: 100%;
  max-width: 460px;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(30,26,18,.28);
}
.report-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.report-head .t { font-size: 16px; font-weight: 700; }
.report-close { background: var(--card-2); border: 1px solid var(--line); color: var(--muted); font-size: 22px; width: 34px; height: 34px; border-radius: 50%; line-height: 1; }
.report-summary {
  margin: 14px 16px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  background: var(--card-2);
  color: var(--muted);
}
.report-summary[data-state="running"] { background: #fdf3e3; color: var(--amber); }
.report-summary[data-state="ok"] { background: #eaf6ee; color: #15803d; }
.report-summary[data-state="fail"] { background: #fceceb; color: var(--red); }
.report-summary[data-state="warn"] { background: #fdf3e3; color: var(--amber); }
/* 勾选模式 */
.report-select { padding: 14px 16px 16px; overflow: auto; }
.report-hint { margin: 0 0 12px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.report-items { margin-bottom: 14px; }
.report-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card-2);
  font-size: 15px;
}
.report-item input { width: 22px; height: 22px; flex: 0 0 auto; accent-color: var(--blue); }
/* 选中行整行高亮，让“测/不测”一眼可辨 */
.report-item:has(input:checked) { background: var(--blue-soft); border-color: var(--blue); color: #1d4ed8; font-weight: 600; }
.report-select .btn, .report-run .btn { width: 100%; }

.report-steps { padding: 0 16px 12px; overflow: auto; }
.report-run { display: flex; flex-direction: column; min-height: 0; }
/* 类选择器的 display:flex 会盖过 [hidden]，需显式恢复隐藏 */
.report-run[hidden], .report-select[hidden] { display: none; }
.report-run .btn { margin: 0 16px 16px; width: auto; }
.report-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
  font-size: 15px;
}
.report-step:first-child { border-top: none; }
.report-step .rs-icon .ico { width: 20px; height: 20px; display: block; }
.report-step[data-state="pending"] .rs-icon { color: #c9c1ad; }
.report-step[data-state="running"] .rs-icon { color: var(--amber); }
.report-step[data-state="running"] .rs-icon .ico { animation: spin 1s linear infinite; }
.report-step[data-state="pass"] .rs-icon { color: var(--green); }
.report-step[data-state="fail"] .rs-icon { color: var(--red); }
.report-step .rs-label { flex: 1; }
.report-step[data-state="fail"] .rs-label { color: var(--red); font-weight: 600; }
.report-step .rs-note { font-size: 12px; color: var(--red); }

/* 扫码全屏弹层（相机画面用深色背景更聚焦） */
.scanner {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: none;
  flex-direction: column;
}
.scanner.open { display: flex; }
.scanner-head {
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  background: rgba(0,0,0,.6);
}
.scanner-head .t { font-size: 15px; font-weight: 600; }
.scanner-close { background: rgba(255,255,255,.15); border: none; color: #fff; font-size: 22px; width: 38px; height: 38px; border-radius: 50%; }
#reader { flex: 1; width: 100%; }
.scanner-tip { padding: 14px 16px calc(env(safe-area-inset-bottom) + 14px); color: #d8dde6; font-size: 13px; text-align: center; background: rgba(0,0,0,.6); }
