:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #e3e7ee;
  --line-2: #eef1f6;
  --text: #1c2333;
  --text-2: #5b6577;
  --text-3: #8b94a7;
  --brand: #2563eb;
  --brand-soft: #eaf1ff;
  --danger: #d93b3b;
  --warn: #e8833a;
  --ok: #16a34a;
  --purple: #8b5cf6;
  --cyan: #0891b2;
  --blue: #2563eb;
  --amber: #f0b429;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 14px rgba(20, 30, 60, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
button { font-family: inherit; }

/* ===================== 顶栏 ===================== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 38px; height: 38px; border-radius: 9px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff; display: grid; place-items: center;
  font-size: 19px; font-weight: 600; letter-spacing: 1px;
}
.brand-text h1 { font-size: 16px; letter-spacing: .2px; }
.brand-text span { font-size: 12px; color: var(--text-3); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--text);
  font-size: 13px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { background: #f7f9fc; border-color: #cfd7e5; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; border-color: #1d4ed8; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; justify-content: center; margin-top: 4px; }

.icon-btn {
  width: 30px; height: 30px; border-radius: 7px;
  border: 1px solid var(--line); background: #fff;
  color: var(--text-2); cursor: pointer; font-size: 15px; line-height: 1;
}
.icon-btn:hover { background: #f2f5fa; }

/* ===================== 布局 ===================== */
.layout {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  gap: 14px; padding: 14px 20px;
  align-items: start;
}
.sidebar { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 76px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
}
.card-title {
  font-size: 13px; color: var(--text-2); margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between;
}

/* ===================== 概览 ===================== */
.verdict-empty { color: var(--text-3); font-size: 13px; padding: 6px 0 2px; }
.verdict-box {
  border-radius: 9px; padding: 12px 14px; margin-bottom: 12px;
  border: 1px solid transparent;
}
.verdict-box .v-title { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.verdict-box .v-desc { font-size: 12px; margin-top: 4px; opacity: .9; }
.verdict-box.ok   { background: #ecfdf3; border-color: #b7e8c8; color: #146c3a; }
.verdict-box.warn { background: #fff7ed; border-color: #fbd9a8; color: #9a4a10; }
.verdict-box.bad  { background: #fef2f2; border-color: #f8c4c4; color: #9b1c1c; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  border: 1px solid var(--line-2); border-radius: 8px;
  padding: 8px 6px; text-align: center; background: #fcfdff;
}
.stat .n { font-size: 19px; font-weight: 600; line-height: 1.15; }
.stat .t { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.stat.zero .n { color: var(--text-3); }

.meta-list { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.meta-list div { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); padding: 2px 0; }
.meta-list b { font-weight: 500; color: var(--text); }

/* ===================== 参数 ===================== */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.hint { font-size: 11px; color: var(--text-3); margin: 5px 0 0; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  flex: 1; height: 30px; border: 0; background: #fff;
  font-size: 12px; color: var(--text-2); cursor: pointer;
  border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: #f5f8fd; }
.seg button.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.seg.small button { height: 26px; font-size: 12px; }

.switches { display: flex; flex-direction: column; gap: 7px; }
.sw { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.sw input { accent-color: var(--brand); width: 15px; height: 15px; }
.sw.small { font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px; border-radius: 20px; font-size: 12px;
  border: 1px solid var(--line); background: #fff;
  color: var(--text-3); cursor: pointer; user-select: none;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .35; }
.chip.on { color: var(--text); border-color: #c6d3ea; background: #f8fafd; }
.chip.on .dot { opacity: 1; }

.advanced { margin-top: 4px; border-top: 1px dashed var(--line); padding-top: 10px; }
.advanced summary { font-size: 12px; color: var(--text-2); cursor: pointer; }
.advanced summary::marker { color: var(--text-3); }
.slider-row { margin-top: 10px; }
.slider-row label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.slider-row label b { color: var(--brand); font-weight: 600; }
.slider-row input[type=range] { width: 100%; accent-color: var(--brand); }

/* ===================== 图像区 ===================== */
.stage {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 540px;
}
.stage-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line-2);
  flex-wrap: wrap;
}
.legend { display: flex; gap: 12px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2); }
.legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.view-tools { display: flex; align-items: center; gap: 6px; }
.view-tools #zoomLabel { font-size: 12px; color: var(--text-3); min-width: 40px; text-align: center; }

.canvas-box {
  flex: 1; position: relative; overflow: hidden;
  background:
    linear-gradient(45deg, #f0f2f6 25%, transparent 25%, transparent 75%, #f0f2f6 75%) 0 0/20px 20px,
    linear-gradient(45deg, #f0f2f6 25%, transparent 25%, transparent 75%, #f0f2f6 75%) 10px 10px/20px 20px,
    #f8f9fc;
  min-height: 420px; cursor: grab;
  display: block;
}
.canvas-box.grabbing { cursor: grabbing; }
/* 绝对定位到左上角：居中与缩放全部交给 transform，保证坐标换算只有一套基准 */
#view {
  position: absolute; left: 0; top: 0; display: block;
  transform-origin: 0 0; will-change: transform;
}

.dropzone {
  position: absolute; inset: 0; display: grid; place-items: center;
  text-align: center; color: var(--text-3); padding: 20px;
}
.dz-inner svg { color: #c3cbdb; margin-bottom: 10px; }
.dz-inner p { margin: 0 0 6px; font-size: 14px; color: var(--text-2); }
.dz-inner span { font-size: 12px; }
.dropzone.hide { display: none; }
.dropzone.over { background: rgba(37, 99, 235, .06); outline: 2px dashed var(--brand); outline-offset: -12px; }

.analyzing {
  position: absolute; inset: 0; display: none; place-items: center;
  background: rgba(255, 255, 255, .82); font-size: 13px; color: var(--text-2); gap: 8px;
}
.analyzing.on { display: grid; grid-auto-flow: column; }
.spinner {
  width: 18px; height: 18px; border: 2px solid #d5dced; border-top-color: var(--brand);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stage-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-top: 1px solid var(--line-2);
  font-size: 12px; color: var(--text-3);
}
.stage-foot .spacer { flex: 1; }
.hover-info { color: var(--brand); }
.sep { opacity: .5; }

/* ===================== 清单 ===================== */
.defects {
  margin: 0 20px 22px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.defects-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap;
}
.defects-head h2 { font-size: 14px; }
.count { font-size: 12px; color: var(--text-3); font-weight: 400; margin-left: 6px; }
.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#searchBox {
  height: 28px; padding: 0 10px; border: 1px solid var(--line);
  border-radius: 7px; font-size: 12px; width: 150px; font-family: inherit;
}
.table-wrap { max-height: 380px; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky; top: 0; background: #fafbfd; z-index: 2;
  text-align: left; font-size: 12px; font-weight: 500; color: var(--text-3);
  padding: 9px 12px; border-bottom: 1px solid var(--line);
}
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); font-size: 13px; vertical-align: top; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f6f9fe; }
tbody tr.sel { background: var(--brand-soft); }
tbody tr.dim td { opacity: .45; }
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 5px;
  font-size: 12px; color: #fff; white-space: nowrap;
}
.sev { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; }
.sev i { width: 7px; height: 7px; border-radius: 50%; }
.pos { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 12px; }
.desc { color: var(--text-2); font-size: 12.5px; }
.suspect-badge {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  border-radius: 4px; background: #fff4e0; color: #9a5b10; font-size: 11px;
}
.table-empty { padding: 34px; text-align: center; color: var(--text-3); font-size: 13px; }
.loc-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  padding: 3px 9px; font-size: 12px; color: var(--brand); cursor: pointer;
}
.loc-btn:hover { background: var(--brand-soft); }

/* ===================== 打印报告 ===================== */
.report { display: none; }
@media print {
  body { background: #fff; }
  .topbar, .layout, .defects { display: none !important; }
  .report { display: block; padding: 0 4mm; color: #000; }
  .report h1 { font-size: 18pt; margin-bottom: 4mm; }
  .report h2 { font-size: 12pt; margin: 6mm 0 2mm; border-bottom: .5pt solid #999; padding-bottom: 1mm; }
  .report table { width: 100%; border-collapse: collapse; font-size: 9pt; margin-bottom: 3mm; }
  .report th, .report td { border: .5pt solid #bbb; padding: 1.2mm 2mm; text-align: left; }
  .report th { background: #f0f0f0; }
  .report img { width: 100%; border: .5pt solid #bbb; }
  .report-meta { font-size: 9pt; color: #555; margin-bottom: 4mm; }
  .report-foot { margin-top: 6mm; font-size: 8pt; color: #777; }
  @page { margin: 14mm; }
}

/* ===================== 响应式 ===================== */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .stage { min-height: 420px; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 10px 12px; }
  .layout { padding: 12px; }
  .defects { margin: 0 12px 16px; }
  .actions { width: 100%; }
  .btn { flex: 1; justify-content: center; padding: 0 8px; }
  .brand-text span { display: none; }
  .filters { width: 100%; }
  #searchBox { flex: 1; }
  .table-wrap { max-height: 300px; }
}
