:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --line: #d5dee9;
  --line-soft: #e6edf5;
  --text: #22303f;
  --muted: #7b8b9d;
  --brand: #1f6fb2;
  --brand-soft: #e6f1fb;
  --accent: #d9822b;
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}

button, select, input {
  font: inherit;
  color: inherit;
}

button {
  height: 26px;
  padding: 0 10px;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--brand-soft); border-color: #b6d3ec; }
button:active { background: #d9e9f8; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: #1a5f9b; }
button.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }

select {
  height: 26px;
  padding: 0 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  max-width: 200px;
}

/* ---------------- 顶栏 ---------------- */
#topbar {
  height: 52px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: linear-gradient(#fdfefe, #f2f6fb);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(30, 60, 90, .06);
  position: relative;
  z-index: 5;
  /* 窄窗口：工具条在顶栏内部横向滚动，不撑宽 body、不把右侧栏挤出屏幕 */
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.brand { display: flex; align-items: center; gap: 8px; padding-right: 6px; border-right: 1px solid var(--line); flex: 0 0 auto; white-space: nowrap; }
.brand .logo { font-size: 20px; color: var(--brand); }
.brand-name { font-weight: 700; font-size: 14px; letter-spacing: .3px; }
.brand-sub { font-size: 11px; color: var(--muted); }

.tb-group { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }

/* 快速补偿的拖动作用选择（调补偿 / 平移）：点哪个用哪个，不用修饰键 */
#qcModes { display: inline-flex; }
#qcModes[hidden] { display: none; }
#qcModes button {
  height: 26px; padding: 0 9px; font-size: 12px;
  border: 1px solid var(--line); background: #fff; color: #4a6b7f;
}
#qcModes button:first-child { border-radius: 4px 0 0 4px; }
#qcModes button:last-child { border-radius: 0 4px 4px 0; margin-left: -1px; }
#qcModes button.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.tb-label { color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }
#fileInfo { color: var(--muted); font-size: 12px; text-align: right; max-width: 420px; flex: 0 0 auto; white-space: nowrap; }

/* ---------------- 主体 ---------------- */
main {
  height: calc(100% - 52px);
  display: flex;
  min-height: 0;
}

#stage {
  flex: 1;
  min-width: 0;
  position: relative;
  padding: 10px;
  overflow: auto;
  background: #eef2f7;
}

/* 图墙：一张图 = 一条门路径，框完自动往右加，排满自动换行 */
#plotHost {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-content: flex-start;
}

/* 面包屑：逐层圈门路径 */
.crumbs {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}
.crumb {
  border: 1px solid transparent;
  background: transparent;
  height: 22px;
  padding: 0 7px;
  border-radius: 3px;
  color: #3d556c;
  font-size: 12px;
  white-space: nowrap;
}
.crumb:hover { background: #eaf2fa; }
.crumb.cur {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}
.crumb-sep { color: #a9bacb; font-size: 11px; padding: 0 1px; }

#empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.empty-box { text-align: center; color: var(--muted); }
.empty-title { font-size: 15px; margin-bottom: 6px; color: #55687c; }
.empty-tip { font-size: 12px; }

/* ---------------- 图卡 ---------------- */
.plot {
  flex: 0 0 460px;
  width: 460px;
  /* 高度自适应视口：保证一屏至少能看到两行图 */
  height: clamp(280px, calc((100vh - 96px) / 2), 430px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(30, 60, 90, .05);
}
.plot.active { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(31, 111, 178, .14); }
.plot.flash { animation: plotFlash .7s ease; }
@keyframes plotFlash {
  0% { box-shadow: 0 0 0 3px rgba(31, 111, 178, .5); }
  100% { box-shadow: 0 0 0 2px rgba(31, 111, 178, .14); }
}
.plot-close {
  width: 20px; height: 20px; padding: 0; line-height: 1;
  font-size: 14px; color: #9aabbc;
  border-color: transparent; background: transparent;
}
.plot-close:hover { color: #d94a3d; background: #fdf1f0; }

.plot-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-bottom: 1px solid var(--line-soft);
  background: #f8fafc;
  /* 卡片被压窄时让工具换行，而不是把标题挤成一条竖线 */
  flex-wrap: wrap;
  row-gap: 2px;
  overflow: hidden;
}
.plot-titlebox {
  flex: 1 1 120px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 0 4px;
}
.plot-title {
  font-weight: 600;
  font-size: 12px;
  color: #2c4053;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* 第二行：完整门链（样本 / … / 父门），允许换行，不做省略号截断；
   最多 3 行兜底，避免极端窄卡片时把头部撑得过高 */
.plot-sub {
  font-size: 10.5px;
  color: #7b8b9d;
  line-height: 1.25;
  white-space: normal;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.toolset { display: flex; gap: 2px; flex: 0 0 auto; }
.toolset button {
  width: 24px; height: 22px; padding: 0;
  font-size: 12px; line-height: 1;
}
.toolset button.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.plot-canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  background: #fff;
  padding-top: 9px;   /* 顶部边条放横向滚动条，不与数据/刻度重叠 */
}
.plot-canvas-wrap canvas {
  display: block;
  height: 100%;
  width: 100%;
  cursor: crosshair;
}
.plot-canvas-wrap canvas.select-mode { cursor: grab; }
.plot-canvas-wrap canvas.select-mode:active { cursor: grabbing; }

/* 视图滚动条：选中图后出现，浮在绘图区内侧（不挡坐标文字） */
.viewbar {
  position: absolute;
  background: rgba(196, 213, 229, .45);
  border-radius: 5px;
  display: none;
  z-index: 4;
}
.viewbar.show { display: block; }
/* 横条在绘图区顶部边条（位置/宽度由 syncViewbars 按绘图区对齐），竖条贴右侧 */
.viewbar.h { left: 64px; right: 20px; top: 1px; height: 7px; }
.viewbar.v { top: 18px; bottom: 47px; right: 6px; width: 7px; }
.view-thumb {
  position: absolute;
  background: rgba(88, 128, 168, .55);
  border-radius: 5px;
}
.viewbar.h .view-thumb { top: 0; bottom: 0; cursor: grab; }
.viewbar.v .view-thumb { left: 0; right: 0; cursor: grab; }
.view-thumb:hover { background: rgba(60, 102, 145, .75); }

.plot-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 8px;
  border-top: 1px solid var(--line-soft);
  background: #fbfcfe;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plot-foot select { height: 22px; font-size: 12px; max-width: 150px; }
.plot-foot .grow { flex: 1; }
.plot-info { color: var(--muted); font-size: 11.5px; }
.plot-gates { color: #4a6b7f; font-size: 11.5px; }

.plot-axis {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border-bottom: 1px solid var(--line-soft);
  background: #fcfdfe;
  font-size: 12px;
  overflow: hidden;
}
.axis-item { display: flex; align-items: center; gap: 3px; min-width: 0; }
.axis-tag { color: var(--muted); font-weight: 600; }
.axis-item select { height: 22px; font-size: 11.5px; max-width: 118px; }
.mode-btn { height: 22px; padding: 0 5px; font-size: 10.5px; min-width: 30px; }

/* 散点 / 直方切换 */
.kind-btns { margin-left: auto; display: flex; gap: 3px; flex: 0 0 auto; }
.kind-btns button {
  height: 22px; padding: 0 7px; font-size: 11px;
  border: 1px solid var(--line); background: #fff; color: #4a6b7f; border-radius: 3px;
}
.kind-btns button.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

/* ---------------- 右侧栏 ---------------- */
#side {
  width: 336px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 10px 10px 0;
  min-height: 0;
}

/* 侧栏收起：完全不占位 */
body.side-hidden #side { display: none; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow: 0 1px 3px rgba(30, 60, 90, .05);
}
#panelTree { flex: 1.1; }
#panelStats { flex: 1; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line-soft);
  background: #f8fafc;
  font-weight: 600;
  font-size: 12px;
  color: #2c4053;
}
.panel-head select { max-width: 150px; height: 22px; font-size: 12px; }
.panel-foot {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-top: 1px solid var(--line-soft);
  background: #fbfcfe;
  font-size: 11px;
  line-height: 1.45;
}

.muted { color: var(--muted); font-weight: 400; font-size: 11px; }

.tree {
  overflow: auto;
  padding: 4px 2px 6px;
  font-size: 12.5px;
  flex: 1;
}
.tree-tip { padding: 10px; color: var(--muted); font-size: 12px; }

.node {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.node:hover { background: #f1f6fb; }
.node.file.sel { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.node .caret { width: 12px; display: inline-block; text-align: center; color: #93a4b6; font-size: 10px; }
.node .ico { font-size: 11px; color: #9fb0c2; }
.node .nm { overflow: hidden; text-overflow: ellipsis; }
.children.collapsed { display: none; }

/* 统计表 */
#autoBasis {
  padding: 5px 9px; border-bottom: 1px solid var(--line-soft);
  font-size: 11px; color: #5b6b7c; background: #fbfdff;
}
#autoBasis summary { cursor: pointer; color: var(--brand); user-select: none; }
#autoBasis pre {
  margin: 5px 0 0; white-space: pre-wrap; word-break: break-all;
  font: 10.5px/1.55 Consolas, "Microsoft YaHei", monospace; color: #55687c;
}
.stats { overflow: auto; flex: 1; }
.stats table { width: 100%; border-collapse: collapse; font-size: 11.5px; table-layout: auto; }
.stats th, .stats td {
  padding: 3px 4px; border-bottom: 1px solid var(--line-soft);
  text-align: right; white-space: nowrap;
}
.stats th { background: #f8fafc; color: #55687c; font-weight: 600; position: sticky; top: 0; font-size: 11px; }
.stats th:first-child, .stats td:first-child { text-align: left; }
.stats tr.sel { background: var(--brand-soft); }
.stats td.has-plot { font-weight: 600; }
.stats td.has-plot::after { content: '▣'; margin-left: 4px; color: var(--brand); font-size: 9px; }
.stats tr:hover { background: #f5f9fd; cursor: pointer; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* ---------------- 门模板菜单 ---------------- */
.tpl-menu {
  position: fixed;
  z-index: 60;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(30, 50, 70, .18);
  padding: 4px;
  display: flex;
  flex-direction: column;
  min-width: 230px;
}
.tpl-menu button {
  text-align: left;
  border: 0;
  background: none;
  padding: 7px 12px;
  font-size: 12.5px;
  border-radius: 6px;
  cursor: pointer;
  color: #2e455c;
}
.tpl-menu button:hover { background: #eef5fb; color: var(--brand); }
.tpl-menu[hidden] { display: none; }   /* 别让 display:flex 压过 hidden */
.tpl-sep { height: 1px; background: var(--line-soft); margin: 4px 8px; }
#tplSaved { display: flex; flex-direction: column; max-height: 190px; overflow: auto; padding: 0 4px 4px; }
.tpl-row { display: flex; align-items: stretch; gap: 2px; padding-bottom: 2px; }
.tpl-row .tpl-load { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-row .tpl-del { flex: none; width: 22px; padding: 7px 0; text-align: center; color: #93a4b6; }
.tpl-row .tpl-del:hover { background: #fdeeee; color: #d94a3d; }
.tpl-empty { font-size: 11.5px; color: #93a4b6; padding: 2px 12px 6px; }

/* 图卡上的显示方式 / 叠加按钮 */
.toolset .disp-btn { font-size: 13px; padding: 1px 5px; }
.toolset .ovl-btn { font-size: 11px; padding: 1px 6px; }
.toolset .ovl-btn.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* 差值模式的样本切换条（图卡下方） */
.delta-chips {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 8px 4px; flex-wrap: wrap;
}
.delta-chips .chip {
  font-size: 11px; padding: 1px 9px;
  border: 1px solid var(--line); border-radius: 999px;
  background: #fff; color: #46607a; cursor: pointer;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.delta-chips .chip:hover { border-color: var(--chip-c, var(--brand)); color: var(--chip-c, var(--brand)); }
.delta-chips .chip.on {
  border-color: var(--chip-c, var(--brand));
  color: var(--chip-c, var(--brand));
  background: #f0f7fe; font-weight: 600;
}
.delta-chips .chip-tip { font-size: 10.5px; color: #93a4b6; }

/* 右键门菜单：改名 / 换色 / 存模板 / 删除 */
.color-menu {
  position: fixed;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(30, 50, 70, .18);
  padding: 5px;
  min-width: 176px;
}
.color-menu[hidden] { display: none; }
.color-menu .gm-item {
  text-align: left;
  border: 0;
  background: none;
  padding: 6px 10px;
  font-size: 12.5px;
  border-radius: 6px;
  cursor: pointer;
  color: #2e455c;
}
.color-menu .gm-item:hover { background: #eef5fb; color: var(--brand); }
.color-menu .gm-danger:hover { background: #fdeeee; color: #d94a3d; }
.color-menu .gm-swrow { display: flex; gap: 3px; padding: 3px 6px; }
.color-menu .swatch {
  width: 19px; height: 19px;
  border-radius: 5px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.color-menu .swatch:hover { transform: scale(1.15); }
.color-menu .swatch.cur { border-color: #2e455c; }

/* 对比表差值小字 */
.cmp-wrap .diff { display: block; font-size: 10.5px; font-weight: 500; }
.cmp-wrap .diff.pos { color: #2b9e6b; }
.cmp-wrap .diff.neg { color: #d94a3d; }
.cmp-wrap td.dark .diff.pos { color: #c8f3de; }
.cmp-wrap td.dark .diff.neg { color: #ffd3cd; }
.cmp-wrap .diff-only { font-size: 12px; font-weight: 600; }
.cmp-wrap .diff.base { color: #93a4b6; font-weight: 400; font-size: 10.5px; }
.cmp-tools .chk { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; font-size: 12px; color: #46607a; }

/* 统计表：拖门前后的变化小字 */
.stat-delta { display: block; font-size: 10px; font-weight: 500; }
.stat-delta.pos { color: #2b9e6b; }
.stat-delta.neg { color: #d94a3d; }

/* 批次汇总里的疑似异常 */
.qc-outlier { color: #d94a3d; font-weight: 600; font-size: 11.5px; }

/* ---------------- 历史记录弹窗 ---------------- */
.hist-list {
  max-height: 56vh; overflow: auto;
  border: 1px solid var(--line-soft); border-radius: 6px;
}
.hist-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px; cursor: pointer;
  border-bottom: 1px solid var(--line-soft);
}
.hist-row:last-child { border-bottom: none; }
.hist-row:hover { background: #f2f7fc; }
.hist-main { flex: 1; min-width: 0; }
.hist-name { font-size: 13px; font-weight: 600; color: #24384d; }
.hist-path {
  font-size: 11px; color: #7d93a8;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hist-time { font-size: 11px; color: #7d93a8; white-space: nowrap; }

/* ---------------- 多样本对比 / 直方图叠加弹窗 ---------------- */
.cmp-box { max-width: 980px; width: 92vw; }
.cmp-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.cmp-list {
  display: flex; flex-wrap: wrap; gap: 4px 14px;
  max-height: 88px; overflow: auto;
  border: 1px solid var(--line-soft); border-radius: 6px;
  padding: 6px 8px; margin-bottom: 8px;
}
.cmp-item.cur { font-weight: 600; color: var(--brand); }
.cmp-box .modal-body { overflow: auto; }
.cmp-wrap { max-height: 44vh; overflow: auto; border: 1px solid var(--line-soft); }
.cmp-wrap table { border-collapse: collapse; font-size: 12px; width: 100%; }
.cmp-wrap th, .cmp-wrap td {
  border-bottom: 1px solid var(--line-soft);
  padding: 4px 8px; text-align: right; white-space: nowrap;
}
.cmp-wrap th {
  position: sticky; top: 0; z-index: 1;
  background: #f8fafc; color: #55687c;
}
.cmp-wrap tr.sel { background: #f2f8fd; }

/* 轴范围面板 */
.axis-box { max-width: 1080px; width: 94vw; }
.axis-tools { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.axis-tools select { height: 27px; }
.axis-hint { margin: 4px 0 8px; }
.axis-table-wrap {
  max-height: 46vh; overflow: auto;
  border: 1px solid var(--line-soft); border-radius: 6px;
}
.axis-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.axis-table th, .axis-table td {
  border-bottom: 1px solid var(--line-soft);
  padding: 5px 8px; text-align: left; white-space: nowrap;
}
.axis-table th {
  position: sticky; top: 0; z-index: 1;
  background: #f8fafc; color: #55687c;
}
.axis-table input[type="text"] {
  width: 104px; height: 24px; font: inherit; font-size: 12px;
  padding: 1px 5px; border: 1px solid var(--line); border-radius: 4px;
}
.axis-table input[type="text"].bad { border-color: #d94a3d; background: #fff4f2; }
.axis-table .axis-ch { color: #47607a; }
.axis-table .axis-title {
  max-width: 230px; overflow: hidden; text-overflow: ellipsis; color: #334c64;
}
#axisStatus { min-height: 18px; margin-top: 6px; }

/* 报告样式 */
.tb-group button.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.report-box { max-width: 760px; width: 92vw; }
.report-state { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.report-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px;
  margin: 12px 0; padding: 10px 12px;
  border: 1px solid var(--line-soft); border-radius: 6px; background: #fbfdff;
}
.report-grid label { font-size: 12px; color: #46607a; }
.report-hint { line-height: 1.6; margin-bottom: 12px; }
.report-preset-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.report-preset-head input {
  flex: 1; height: 26px; font: inherit; font-size: 12px;
  padding: 1px 7px; border: 1px solid var(--line); border-radius: 4px;
}
.report-preset-list {
  max-height: 210px; overflow: auto;
  border: 1px solid var(--line-soft); border-radius: 6px;
}
.report-preset {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-bottom: 1px solid var(--line-soft); font-size: 12px;
}
.report-preset:last-child { border-bottom: 0; }
.report-preset-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 门名改名输入框 + 导出按钮 */
.rename-input {
  width: 96px;
  font: inherit;
  padding: 1px 4px;
  border: 1px solid var(--brand);
  border-radius: 4px;
  outline: none;
}
.stats td[data-gate] { cursor: text; }
.panel-head button {
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: #46607a;
  cursor: pointer;
}
.panel-head button:hover { background: #f0f6fc; border-color: var(--brand); color: var(--brand); }

/* ---------------- 弹窗 ---------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 60, .35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal.open { display: flex; }

.modal-box {
  background: var(--panel);
  border-radius: 8px;
  box-shadow: 0 18px 40px rgba(20, 40, 60, .25);
  width: min(1600px, 97vw);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(#fdfefe, #f2f6fb);
  font-weight: 600;
}
.modal-head .x { border: none; background: transparent; font-size: 18px; line-height: 1; height: 22px; padding: 0 4px; }
.modal-body { padding: 10px 14px; overflow: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
}

.comp-tools { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.chk { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.comp-wrap { overflow: auto; max-height: 56vh; border: 1px solid var(--line); border-radius: 4px; }

/* 补偿对齐预览（右栏） */
.comp-grid { display: flex; gap: 14px; align-items: flex-start; }
.comp-left { flex: 1; min-width: 0; }
.comp-preview {
  flex: 0 0 390px;
  width: 390px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfe;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cp-head { font-weight: 600; font-size: 12.5px; }
.cp-row { display: flex; align-items: center; gap: 8px; }
.cp-row select { flex: 1; min-width: 0; height: 24px; font-size: 12px; }
.cp-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--brand); }
.cp-tag { color: #46607a; font-weight: 600; font-size: 11.5px; white-space: nowrap; }
.cp-val { min-width: 58px; text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }
/* 预览容器：顶部/右侧留边条放滚动条（与 NovoExpress 图窗一致），图内全是补偿拖动区 */
.cp-canvas-wrap {
  border: 1px solid var(--line-soft);
  background: #fff;
  position: relative;
  padding: 12px 14px 0 0;
}
.cp-canvas-wrap canvas { display: block; width: 100%; height: 300px; cursor: grab; }
.cp-canvas-wrap canvas:active { cursor: grabbing; }
/* 补偿预览的滚动条：横条在绘图区顶部、竖条在右侧，都不压数据 */
.cp-canvas-wrap .viewbar.h { left: 58px; right: 20px; top: 2px; height: 7px; z-index: 3; }
.cp-canvas-wrap .viewbar.v { top: 18px; bottom: 40px; right: 2px; width: 7px; z-index: 3; }
#cpHint { min-height: 16px; }

/* 快速补偿：浮动滑块面板（与现有控件同一套配色，不引入第三方组件） */
#qcPanel {
  position: fixed;
  left: 14px;
  bottom: 10px;
  z-index: 45;
  width: 560px;
  max-width: calc(100vw - 28px);
  max-height: 55vh;
  display: flex;
  flex-direction: column;
  padding: 0 10px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 8px 26px rgba(28, 46, 64, .18);
}
/* hidden 属性要压过上面的 display:flex，否则关闭快速补偿后面板仍浮在图上 */
#qcPanel[hidden] { display: none; }
.qc-grip {
  height: 9px;
  margin: 0 -10px 1px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(#eef3f8, #e3ebf3);
  cursor: ns-resize;
  position: relative;
}
.qc-grip::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 3px;
  width: 36px;
  height: 2px;
  margin-left: -18px;
  border-radius: 2px;
  background: #b9c8d8;
}
.qc-head { display: flex; align-items: center; gap: 7px; margin-bottom: 2px; }
.qc-title { font-weight: 600; color: var(--brand); white-space: nowrap; }
.qc-head .muted { flex: 1; min-width: 0; font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qc-head button { height: 22px; padding: 0 6px; font-size: 11.5px; white-space: nowrap; }
.qc-body { display: flex; flex-direction: column; min-height: 0; }
#qcPanel.qc-collapsed .qc-body { display: none; }
.qc-list {
  max-height: 210px;
  overflow-y: auto;
  margin: 3px -4px 0;
  padding: 0 4px;
}
.qc-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 4px;
  border-left: 3px solid transparent;
  border-radius: 4px;
}
.qc-row + .qc-row { margin-top: 2px; }
.qc-row.qc-active { background: #f1f7fd; border-left-color: #9dc3e6; }
.qc-row.sel { background: #dcebfa; border-left-color: var(--brand); }
.qc-row.sel .qc-tag { color: var(--brand); }
.qc-row:hover { background: #f7fafd; }
.qc-row.sel:hover { background: #d3e6f9; }
.qc-tag {
  flex: 0 0 185px;
  color: #46607a;
  font-weight: 600;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qc-row input[type="range"] { flex: 1; min-width: 80px; accent-color: var(--brand); height: 18px; }
.qc-row input[type="number"] {
  width: 64px;
  height: 22px;
  padding: 0 4px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}
.qc-row input[type="number"]:focus { outline: none; border-color: var(--brand); background: var(--brand-soft); }
.qc-unit { color: var(--muted); font-size: 11px; }
.qc-reset { height: 22px; padding: 0 5px; font-size: 12px; }
.qc-hint { margin-top: 5px; min-height: 15px; color: var(--muted); font-size: 11.5px; }
/* 面板开着时缩短主区域，给底部滑块留出独立空间，不遮住任何图的坐标轴 */
body.qc-on main { height: calc(100% - 52px - var(--qc-h, 340px)); }

#compTable { border-collapse: separate; border-spacing: 0; font-size: 12px; }
#compTable th, #compTable td { border-right: 1px solid #e7eef6; border-bottom: 1px solid #e7eef6; padding: 0; }
#compTable th {
  background: #f4f8fc;
  font-weight: 600;
  color: #46607a;
  padding: 4px 6px;
  position: sticky;
  top: 0;
  z-index: 2;
  white-space: nowrap;
}
#compTable th.corner {
  left: 0;
  z-index: 3;
  background: #eef4fa;
  font-weight: 400;
  color: var(--muted);
}
#compTable td.rowhead {
  position: sticky;
  left: 0;
  background: #f9fbfe;
  padding: 4px 8px;
  white-space: nowrap;
  font-weight: 600;
  color: #465a6e;
  z-index: 1;
}
#compTable td input {
  width: 74px;
  height: 24px;
  border: none;
  background: transparent;
  text-align: right;
  padding: 0 6px;
  outline: none;
}
#compTable td input:focus { background: var(--brand-soft); }
#compTable td input:disabled { color: #9fb0c2; }
#compTable td.diag { background: #f2f6fa; }
#compTable tr:hover td { background: #f7fbfe; }

/* toast */
#toast {
  position: fixed;
  right: 20px;
  bottom: 18px;
  transform: translateY(10px);
  background: rgba(30, 50, 70, .92);
  color: #fff;
  padding: 7px 14px;
  border-radius: 4px;
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 99;
}
#toast.show { opacity: 1; transform: translateY(0); }

/* ------------------------- 固定工作表 ------------------------- */
.ws-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.ws-panels {
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  margin: 8px 0;
  background: #fff;
}
.ws-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
  border-bottom: 1px dashed #e3ebf3;
  font-size: 12px;
}
.ws-panel:last-child { border-bottom: none; }
.ws-slot {
  flex: 0 0 22px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  border-radius: 4px;
  background: #e9f0f7;
  color: #47607a;
  font-size: 11px;
}
.ws-path {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
body.ws-fixed #plotHost {
  display: grid;
  grid-template-columns: repeat(var(--ws-cols, 2), minmax(0, 1fr));
  gap: 10px;
  align-content: start;
}
body.ws-fixed .plot {
  width: auto;
  flex: 0 0 auto;
  min-width: 0;
}
.plot-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------- 放大查看弹窗 ---------------- */
.zoom-box { width: auto; max-width: 96vw; }
.zoom-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 12px 12px;
}
#zoomCanvas {
  display: block;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
}
.zoom-hint { font-size: 11px; color: #7b8ca3; }

/* 放大查看：弹窗内工具条 */
.zoom-tools { display: flex; align-items: center; gap: 8px; width: 100%; }
.zoom-tools button { height: 26px; }
.zoom-tools .zoom-hint { margin-left: auto; }

.zoom-tools .zoom-sep { width: 1px; height: 18px; background: var(--line); }
.zoom-tools button.on { background: #2f7ed8; color: #fff; border-color: #2f7ed8; }

/* 矮窗口：宁可让弹窗内部纵向滚动，也不把画布缩到比图卡还小 */
@media (max-height: 450px) {
  .zoom-box { max-height: 96vh; }
  .zoom-body { padding: 6px 8px; gap: 4px; }
  .zoom-tools { flex-wrap: wrap; gap: 4px; }
  .zoom-tools .zoom-hint { display: none; }
}

/* ---------------- 通道角色映射弹窗 ---------------- */
.role-map-badge {
  margin-bottom: 10px;
  padding: 6px 10px;
  border-radius: 5px;
  background: #f1f6fc;
  border: 1px solid #d7e4f2;
  font-size: 12px;
  color: #35506b;
}
.role-map-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
  max-height: 360px;
  overflow: auto;
  padding: 4px 2px;
}
.role-map-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.role-map-row label {
  flex: 0 0 92px;
  font-weight: 600;
  color: #425a72;
  white-space: nowrap;
}
.role-map-row select {
  flex: 1;
  min-width: 0;
  height: 26px;
}
