:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e2e6ec;
  --ink: #1f2733;
  --muted: #6b7684;
  --accent: #2f6fd0;
  --accent-soft: rgba(47, 111, 208, .13);
  --warn: #c2410c;
  --ok: #15803d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

body { display: flex; flex-direction: column; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px;
  background: var(--accent); color: #fff; font-weight: 700; letter-spacing: .5px;
}
.topbar h1 { margin: 0; font-size: 16px; font-weight: 650; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.status {
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: #eef1f5; color: var(--muted); max-width: 46%;
}
.status.busy { background: #fff3e0; color: var(--warn); }
.status.err { background: #fdecec; color: #b91c1c; }
.status.ok { background: #e7f6ec; color: var(--ok); }

/* ---------- 三栏 ---------- */
.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 300px minmax(420px, 1fr) 340px;
  gap: 12px; padding: 12px;
  transition: grid-template-columns .25s ease;
}
.panel { min-height: 0; display: flex; flex-direction: column; }
.left, .right { overflow: hidden; }
.leftInner { overflow: auto; min-height: 0; }

/* 左栏收起 / 展开：点击左栏头部的 ‹ / › 按钮 */
.leftHead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2px 6px; flex: none;
}
.leftTitle { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.leftToggle {
  width: 24px; height: 24px; padding: 0; line-height: 1; flex: none;
  border-radius: 7px; font-size: 14px; color: var(--muted);
}
.leftVertical {
  display: none;                       /* 仅收起时可见 */
  writing-mode: vertical-rl; letter-spacing: 4px;
  font-size: 12px; color: var(--muted); font-weight: 600;
  margin: 2px auto 0; user-select: none;
}
body.leftCollapsed .layout { grid-template-columns: 34px minmax(420px, 1fr) 340px; }
body.leftCollapsed .leftInner,
body.leftCollapsed .leftTitle { display: none; }
body.leftCollapsed .leftHead { justify-content: center; padding-bottom: 2px; }
body.leftCollapsed .leftToggle { transform: rotate(180deg); }
body.leftCollapsed .leftVertical { display: block; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; margin-bottom: 12px;
}
.card h2 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; }

/* ---------- 上传 ---------- */
.drop {
  border: 1.5px dashed #c3ccd8; border-radius: 9px; padding: 18px 12px;
  text-align: center; cursor: pointer; background: #fbfcfe;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-main { margin: 0; font-weight: 600; }
.drop-sub { margin: 4px 0 0; font-size: 12px; color: var(--muted); word-break: break-all; }

/* ---------- 表单 ---------- */
.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .listHead input {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px;
  background: #fff; font-size: 13px; color: var(--ink);
}
button {
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 7px;
  background: #fff; cursor: pointer; font-size: 13px; color: var(--ink);
}
button:hover { border-color: #c3ccd8; background: #f7f9fc; }
button:disabled { opacity: .5; cursor: not-allowed; }
button:disabled:hover { border-color: var(--line); background: #fff; }
button.primary {
  width: 100%; background: var(--accent); border-color: var(--accent);
  color: #fff; font-weight: 600; padding: 9px;
}
button.primary:disabled { opacity: .55; cursor: progress; }
.hint { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.6; }

/* ---------- 概览 ---------- */
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.summary div {
  background: #f7f9fc; border-radius: 8px; padding: 8px; text-align: center;
}
.summary b { display: block; font-size: 17px; }
.summary span { font-size: 11px; color: var(--muted); }

/* ---------- 图纸区 ---------- */
.center {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden;
}
.tabs { display: flex; gap: 4px; padding: 8px 8px 0; flex-wrap: wrap; }
.tabs button { border-radius: 7px 7px 0 0; font-size: 12.5px; }
.tabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.toolbar {
  display: flex; align-items: center; gap: 8px; padding: 8px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: #fafbfd; flex-wrap: wrap;
}
.toolbar .spacer { flex: 1; }
.check { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); }
#zoomLabel { font-variant-numeric: tabular-nums; min-width: 46px; text-align: center; font-size: 12.5px; }
.exportBtn { flex: none; font-weight: 600; color: var(--accent); }
.exportBtn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }

.viewport {
  flex: 1; min-height: 0; overflow: auto; background: #eef1f5;
  position: relative; padding: 12px;
}
.stage { position: relative; margin: 0 auto; transform-origin: 0 0; box-shadow: 0 2px 14px rgba(0,0,0,.14); }
.stage img { display: block; width: 100%; }
.stage svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.stage svg .hit { pointer-events: auto; cursor: pointer; }

.hl { fill: none; stroke: var(--accent); stroke-width: 2.2; vector-effect: non-scaling-stroke; }
.hl.faint { stroke: #7f8b99; stroke-width: 1; opacity: .5; }
.hl.sel { stroke: #ff5722; stroke-width: 3; filter: drop-shadow(0 0 4px rgba(255,87,34,.55)); }
.hl.box { fill: rgba(47,111,208,.06); }
.hl.box.sel { fill: rgba(255,87,34,.13); }
.hl.wire.sel { stroke-width: 3.4; }
.hl.pulse { animation: pulse 1.1s ease-out 3; }
@keyframes pulse {
  0% { stroke-width: 6; opacity: .95; }
  100% { stroke-width: 3; opacity: 1; }
}
.label-chip { fill: #ff5722; font-size: 11px; font-weight: 700; }

.empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); font-size: 13px; text-align: center; padding: 20px;
}
.empty.small { position: static; padding: 22px 12px; font-size: 12.5px; }

/* ---------- 列表 ---------- */
.right {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.listHead { padding: 10px; border-bottom: 1px solid var(--line); }
.lists { flex: 1; overflow: auto; padding: 8px 10px 12px; }
.group { margin-bottom: 10px; }
.group h3 {
  margin: 8px 0 6px; font-size: 12px; color: var(--muted); font-weight: 650;
  display: flex; align-items: center; gap: 6px; cursor: pointer;
}
.group h3 .count { background: #eef1f5; border-radius: 999px; padding: 0 6px; font-size: 11px; }
.group h3 .swatch { width: 9px; height: 9px; border-radius: 2px; background: var(--accent); }
.item {
  display: flex; align-items: baseline; gap: 6px; padding: 5px 7px; border-radius: 7px;
  cursor: pointer; border: 1px solid transparent;
}
.item:hover { background: #f4f7fb; }
.item.on { background: #fff1ea; border-color: #ffb59a; }
.item .id { font-weight: 650; font-variant-numeric: tabular-nums; }
.item .desc { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .tag {
  margin-left: auto; font-size: 10.5px; padding: 1px 5px; border-radius: 4px;
  background: #eef1f5; color: var(--muted); white-space: nowrap;
}
.item .tag.neg { background: #fdecec; color: #b91c1c; }
.item .tag.lab { background: #fff3e0; color: var(--warn); }

.detail {
  border-top: 1px solid var(--line); padding: 10px; background: #fbfcfe;
  max-height: 34%; overflow: auto;
}
.detail h4 { margin: 0 0 6px; font-size: 12.5px; }
.detail table { width: 100%; border-collapse: collapse; font-size: 12px; }
.detail td { padding: 2px 4px; vertical-align: top; border-bottom: 1px dotted #e8ecf1; }
.detail td.k { color: var(--muted); white-space: nowrap; width: 84px; }
.detail .pos { margin-top: 6px; font-size: 11.5px; color: var(--muted); }
