:root {
  --bg: #f4f5f7;
  --card: #fff;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e3e5e9;
  --primary: #d43a2f;
  --primary-dark: #b32d24;
  --ok: #15803d;
  --ok-bg: #ecfdf3;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --fail: #b91c1c;
  --fail-bg: #fef2f2;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

/* ── 顶栏 ── */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; flex: none;
  background: var(--card); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; white-space: nowrap; }
.mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-size: 11px; letter-spacing: .5px;
}
.spacer { flex: 1; }
.model-info { font-size: 12px; color: var(--muted); white-space: nowrap; }
.pager { display: flex; align-items: center; gap: 2px; }
.pg {
  width: 26px; height: 26px; border: 1px solid var(--border); background: var(--card);
  border-radius: 6px; cursor: pointer; color: var(--text); font-size: 15px; line-height: 1;
}
.pg:hover { border-color: #c9ccd2; }
.page-label { font-size: 12px; color: var(--muted); min-width: 42px; text-align: center; }

/* ── 按钮 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 1px solid transparent;
  font-family: inherit; font-weight: 600; cursor: pointer;
  transition: .15s ease; white-space: nowrap;
}
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-primary { background: var(--primary); color: #fff; padding: 10px 16px; font-size: 14px; width: 100%; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #e2e4e8; color: #9aa0a6; cursor: not-allowed; }
.btn-ghost { background: var(--card); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: #c9ccd2; }

/* ── 主布局 ── */
.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  padding: 10px;
}
.viewer {
  position: relative; min-height: 0;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  display: flex; flex-direction: column; overflow: hidden;
}
.drop {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  margin: 14px; border: 1.5px dashed #d4d7dd; border-radius: 10px;
  cursor: pointer; transition: .15s ease; background: #fbfcfd;
}
.drop:hover, .drop.dragover { border-color: var(--primary); background: #fff8f7; }
.drop-title { margin: 0 0 4px; font-weight: 600; }
.drop-sub { margin: 0; font-size: 12.5px; color: var(--muted); }
.canvas-wrap {
  flex: 1; min-height: 0; overflow: auto;
  display: flex; justify-content: center; align-items: flex-start;
  padding: 10px;
}
.preview { display: block; width: 100%; height: auto; cursor: pointer; }
.viewer-bar {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-top: 1px solid var(--border);
  background: #fafbfc; font-size: 12px; overflow: hidden;
}
.vdivider { width: 1px; height: 16px; background: var(--border); flex: none; }
.btn-mini {
  padding: 3px 8px; font-size: 11.5px; border: 1px solid var(--border);
  background: #fff; border-radius: 5px; cursor: pointer; color: var(--muted);
}
.btn-mini:hover { border-color: #c9ccd2; color: var(--text); }
.file-bar {
  margin-left: auto; color: var(--muted); font-size: 11.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding-left: 8px;
}

/* ── 右侧面板 ── */
.side {
  min-height: 0; display: flex; flex-direction: column; gap: 10px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px;
}
.side-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; font-weight: 600; flex: none;
}
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }
.tmpl-list {
  flex: none; display: flex; flex-wrap: wrap; gap: 6px;
  max-height: 132px; overflow-y: auto; align-content: flex-start;
}
.field-list {
  flex: none; max-height: 220px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px;
  font-size: 12px; color: var(--text);
}
.field-block { padding: 4px 0; }
.field-block + .field-block { border-top: 1px solid var(--border); margin-top: 2px; }
.field-block-title {
  font-size: 12px; font-weight: 700; color: var(--primary);
  padding: 3px 0 2px;
}
.field-headers {
  font-size: 10.5px; color: var(--muted); line-height: 1.5;
  padding: 2px 0 4px; word-break: break-all;
}
.field-item {
  display: flex; gap: 8px; justify-content: space-between;
  padding: 3px 0; border-bottom: 1px dashed var(--border);
}
.field-item:last-child { border-bottom: none; }
.field-name { font-weight: 600; white-space: nowrap; }
.field-desc { color: var(--muted); text-align: right; }
.field-tag {
  margin-left: 4px; padding: 0 5px; border-radius: 4px;
  background: var(--warn-bg); color: var(--warn);
  font-size: 10px; font-weight: 600;
}
/* 横向测试项目标签（与桌面版 Tab 一致） */
.tmpl-item {
  display: inline-flex; align-items: center;
  padding: 5px 13px; border: 1px solid var(--border); border-radius: 999px;
  cursor: pointer; transition: .12s ease; background: #fff;
  font-size: 12.5px; font-weight: 600; color: #4b5563; white-space: nowrap;
}
.tmpl-item:hover { border-color: var(--primary); color: var(--primary); background: #fff8f7; }
.tmpl-item.selected { border-color: var(--primary); background: var(--primary); color: #fff; }
.tmpl-name { font-size: 12.5px; font-weight: 600; }

/* ── 进度 ── */
.progress { flex: none; }
.track { height: 5px; background: #eef0f3; border-radius: 999px; overflow: hidden; }
#progressBar { height: 100%; width: 0; background: var(--primary); transition: width .3s ease; }
.progress-text { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

/* ── 结果 ── */
.results { flex: 1.2; min-height: 80px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.result-card {
  border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; background: #fff;
}
.result-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.result-head h3 { margin: 0; font-size: 13.5px; }
.badge {
  padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  border: 1px solid transparent;
}
.badge.pass { background: var(--ok-bg); color: var(--ok); border-color: #bbf7d0; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: #fde68a; }
.badge.fail { background: var(--fail-bg); color: var(--fail); border-color: #fecaca; }
.stats { margin-left: auto; display: flex; gap: 9px; font-size: 11.5px; color: var(--muted); }
.stats b { font-size: 13px; }
.check-item {
  display: flex; gap: 8px; padding: 7px 0;
  border-bottom: 1px dashed var(--border); font-size: 12.5px; line-height: 1.5;
}
.check-item:last-child { border-bottom: none; }
.dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 6px; flex: none; }
.dot.pass { background: var(--ok); }
.dot.warn { background: #f59e0b; }
.dot.fail { background: var(--fail); }
.check-item .msg { flex: 1; }
.toggle { margin-top: 6px; font-size: 12px; color: var(--primary); cursor: pointer; user-select: none; }
.raw {
  margin-top: 6px; padding: 8px; background: #f8f9fa; border-radius: 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px; white-space: pre-wrap; word-break: break-all;
  max-height: 200px; overflow: auto; color: #374151;
}
.result-error { color: var(--fail); font-size: 12.5px; margin: 6px 0 0; }

/* ── 状态栏 ── */
.statusbar {
  flex: none; padding: 6px 12px; font-size: 12px; color: var(--muted);
  background: var(--card); border-top: 1px solid var(--border);
}

/* ── 弹窗 ── */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(17, 24, 39, .42);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  background: var(--card); border-radius: 12px; padding: 18px;
  width: 100%; max-width: 470px; max-height: 86vh; overflow-y: auto;
}
.modal-title { font-weight: 700; font-size: 15px; margin-bottom: 12px; }
.status-line {
  padding: 9px 11px; border-radius: 8px; margin-bottom: 12px;
  background: #f8f9fa; border: 1px solid var(--border);
  font-size: 12.5px; color: var(--muted); line-height: 1.6;
}
.form-label { display: block; font-size: 12.5px; color: var(--muted); margin: 8px 0 5px; }
.form-input {
  width: 100%; padding: 8px 10px; font-size: 13.5px;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--card); color: var(--text); outline: none;
}
.form-input:focus { border-color: var(--primary); }
.form-hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.section-title {
  margin: 16px 0 2px; padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12.5px; font-weight: 700; color: var(--text);
}
.section-title:first-of-type { border-top: none; padding-top: 0; margin-top: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-actions .btn { padding: 8px 14px; font-size: 13px; width: auto; }
.test-line {
  margin-top: 10px; padding: 8px 10px; border-radius: 7px;
  font-size: 12.5px; line-height: 1.5; word-break: break-all;
  background: #f8f9fa; border: 1px solid var(--border); color: var(--muted);
}
.test-line.ok { background: var(--ok-bg); border-color: #bbf7d0; color: var(--ok); }
.test-line.fail { background: var(--fail-bg); border-color: #fecaca; color: var(--fail); }

.hidden { display: none !important; }

/* ── 手机端 ── */
@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(200px, 42vh) 1fr;
    padding: 8px; gap: 8px;
  }
  .topbar { flex-wrap: wrap; gap: 6px; padding: 6px 10px; }
  .brand span:last-child { font-size: 13px; }
  .model-info { display: none; }
  .btn-sm { padding: 5px 10px; font-size: 12px; }
  .side { padding: 10px; }
  .results { flex: 1; }
  .canvas-wrap { padding: 6px; }
  .viewer-bar { flex-wrap: wrap; }
  .field-list { max-height: 110px; }
}
