/* 包材样板核对系统 - 深色主题（沿用 spray-code-check 视觉体系） */
:root {
  --bg: #0d1220;
  --panel: #151c2e;
  --panel-2: #1b2438;
  --border: #2a3550;
  --text: #e6ecff;
  --muted: #8b96b5;
  --blue: #2f6bff;
  --green: #22a45d;
  --red: #e5484d;
  --amber: #f5a524;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
/* hidden 属性优先级最高：防止组件级 display 规则（如 .thumb / .modal）覆盖掉 hidden */
[hidden] { display: none !important; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  padding: 12px 16px 40px;
  overflow-x: hidden;
}

/* 图标 */
.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon.lg { width: 20px; height: 20px; }
.icon.xl { width: 42px; height: 42px; stroke-width: 1.5; }

/* 顶栏 */
.topbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.topbar h1 { font-size: 20px; }
.topbar .sub { color: var(--muted); font-size: 12px; letter-spacing: 2px; }
.topbar nav { display: flex; gap: 8px; flex-wrap: wrap; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 16px; font-size: 14px; cursor: pointer; text-decoration: none;
  transition: filter .15s;
}
.btn:hover { filter: brightness(1.2); }
.btn-primary { background: var(--blue); border-color: var(--blue); }
.btn-green { background: var(--green); border-color: var(--green); }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.big { padding: 12px 0; font-size: 15px; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* 面板 */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; overflow-x: auto; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; flex-wrap: wrap; }
.panel-head h2 { font-size: 16px; border-left: 3px solid var(--blue); padding-left: 8px; display: flex; align-items: center; gap: 6px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

/* 筛选行 */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin: 10px 0 16px; font-size: 13px; }
.filters label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.filters select, .filters input {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 8px;
}
.checks { display: flex; gap: 12px; margin-left: auto; color: var(--muted); }
.checks label { display: flex; align-items: center; gap: 4px; }

/* 取景框 */
.camera-box {
  height: 340px; border: 1px dashed var(--border); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; overflow: hidden; background: #0a0f1c;
  position: relative;
}.camera-box img { max-width: 100%; max-height: 100%; object-fit: contain; }
.camera-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.camera-box canvas[hidden] { display: none; }

/* 分区核对条（纸箱版面大，按分区逐块拍照） */
.region-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.region-bar[hidden] { display: none; }
.region-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.region-chip {
  padding: 5px 12px; border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
  font-size: 13px; color: var(--text); background: var(--panel-2); user-select: none; transition: all .15s;
}
.region-chip:hover { border-color: var(--blue); }
.region-chip.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.region-chip.done { border-color: #22c55e; color: #22c55e; }
.region-chip.done::after { content: ' ✓'; }
.region-chip.warn-done { border-color: #f5a524; color: #f5a524; }
.region-chip.warn-done::after { content: ' △'; }
.region-chip.fail-done { border-color: #e5484d; color: #e5484d; }
.region-chip.fail-done::after { content: ' ✗'; }
.region-summary { margin-left: auto; }
.placeholder { text-align: center; color: var(--muted); font-size: 13px; line-height: 1.9; }
.placeholder .icon { display: block; margin: 0 auto 8px; opacity: .7; }

/* 蓝色裁剪框 */
#cropbox {
  position: absolute; border: 2px solid #38bdf8; border-radius: 4px;
  box-shadow: 0 0 0 9999px rgba(2, 8, 20, .45);
  cursor: move; touch-action: none; z-index: 6;
}
#cropbox[hidden] { display: none; }
#cropbox .ch {
  position: absolute; width: 26px; height: 26px; border-radius: 50%;
  background: #22d3ee; border: 2px solid #f8fafc;
  box-shadow: 0 1px 5px rgba(0,0,0,.55); touch-action: none;
}
.ch-tl { left: -14px; top: -14px; cursor: nwse-resize; }
.ch-tr { right: -14px; top: -14px; cursor: nesw-resize; }
.ch-bl { left: -14px; bottom: -14px; cursor: nesw-resize; }
.ch-br { right: -14px; bottom: -14px; cursor: nwse-resize; }

.actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 12px; }
.hint { margin-top: 8px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.hint[hidden] { display: none; }
.hint b { color: var(--text); }
.box-legend { margin-top: 10px; }

/* 结果状态卡 */
.result-status {
  padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel-2); font-size: 18px; margin-bottom: 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.result-status small { color: var(--muted); font-size: 12px; }
.result-status.pass { border-color: var(--green); color: #7ee2a8; }
.result-status.fail { border-color: var(--red); color: #ff9b9e; }
.result-status.warn { border-color: #f5a524; color: #ffd479; }
.result-status.unknown { color: var(--muted); }
.fail-reasons {
  margin: 4px 0 2px; padding: 6px 10px; border-radius: 8px;
  background: rgba(255, 80, 80, .08); border: 1px dashed rgba(255, 120, 120, .45);
  color: #ffb3b6; font-size: 13px; line-height: 1.6; word-break: break-all;
}
.fail-reasons i { font-style: normal; display: block; }

/* 对比视图 */
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
@media (max-width: 720px) { .compare-grid { grid-template-columns: 1fr; } }
.compare-col { min-width: 0; }
.compare-tag {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted); margin-bottom: 6px;
}
.compare-tag .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); }
.compare-box {
  height: 300px; border: 1px solid var(--border); border-radius: 10px;
  background: #0a0f1c; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.compare-box img { max-width: 100%; max-height: 100%; object-fit: contain; }
.compare-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.compare-box canvas[hidden] { display: none; }
.compare-empty { color: var(--muted); font-size: 12px; text-align: center; line-height: 1.8; padding: 12px; }
.legend-row { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 8px 0 2px; }
.legend-row i { font-style: normal; display: inline-flex; align-items: center; gap: 5px; }
.legend-row .lg { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* 对比明细 */
.diff-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.diff-item {
  display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px;
}
.diff-item .icon { width: 20px; height: 20px; }
.diff-item.match { border-color: rgba(34, 164, 93, .45); }
.diff-item.match .icon { color: #7ee2a8; }
.diff-item.mismatch { border-color: rgba(229, 72, 77, .5); }
.diff-item.mismatch .icon { color: #ff9b9e; }
.diff-item.missing { border-color: rgba(245, 165, 36, .5); }
.diff-item.missing .icon { color: #ffd479; }
.diff-item.extra { border-color: rgba(245, 165, 36, .5); }
.diff-item.extra .icon { color: #ffd479; }
.diff-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.diff-texts { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.diff-texts .arrow { color: var(--muted); }
.diff-texts s { text-decoration: none; }
.diff-meta { font-size: 11px; color: var(--muted); word-break: break-all; }
.diff-item img.ev {
  width: 96px; max-height: 64px; object-fit: contain; border-radius: 6px;
  border: 1px solid var(--border); background: #000; cursor: zoom-in;
}
.sim-tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.sim-tag.low { color: #ff9b9e; border-color: rgba(229, 72, 77, .45); }
.sim-tag.good { color: #7ee2a8; border-color: rgba(34, 164, 93, .45); }
.sim-tag.soft { color: #ffd479; border-color: rgba(245, 165, 36, .45); }
.diff-item.soft { opacity: .78; }
.diff-group-head {
  font-size: 12px; color: var(--muted); padding: 6px 2px;
  border-bottom: 1px dashed var(--border); margin-bottom: 6px;
}
.field-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.field-tools .hint { margin: 0; }

/* 证据图点击放大弹层 */
.ev-lightbox {
  position: fixed; inset: 0; background: rgba(2, 6, 16, .88);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 70; cursor: zoom-out;
}
.ev-lightbox-card {
  max-width: min(94vw, 1100px); max-height: 92vh;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.ev-lightbox-card img {
  max-width: 100%; max-height: 80vh; object-fit: contain;
  border-radius: 8px; border: 1px solid var(--border); background: #000;
}
.ev-lightbox-card p { color: #e6ecff; font-size: 14px; margin: 0; }

.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

/* 表格 */
.bottom { margin-top: 16px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 500; }
.table tbody tr:hover { background: rgba(47, 107, 255, .06); }
.status-pass { color: #7ee2a8; }
.status-fail { color: #ff9b9e; }
.status-warn { color: #ffd479; }
.status-unknown { color: var(--muted); }
.table.compact th, .table.compact td { padding: 5px 8px; font-size: 12px; }
.batch-tools { display: flex; gap: 8px; align-items: center; }
.batch-check, .check-all { width: 16px; height: 16px; accent-color: var(--blue); cursor: pointer; vertical-align: middle; }

/* 弹窗 */
.modal {
  position: fixed; inset: 0; background: rgba(4, 8, 18, .72);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
}
.modal-card.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; gap: 8px; }
.modal-head h2 { font-size: 16px; border-left: 3px solid var(--blue); padding-left: 8px; }
.modal-body { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.modal-body label.wide { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 13px; }
.modal-body label i { color: var(--red); font-style: normal; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.modal-actions .full { grid-column: 1 / -1; }
.modal-error {
  background: rgba(229, 72, 77, .12); border: 1px solid rgba(229, 72, 77, .5);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; color: #ff9b9e;
}
.modal-error[hidden] { display: none; }
.modal-photo { border: 1px solid var(--border); border-radius: 10px; background: #0a0f1c; position: relative; overflow: hidden; height: 320px; display: flex; align-items: center; justify-content: center; }
.modal-photo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.modal-photo canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* 设置页 */
.settings-panel { max-width: 1320px; margin: 20px auto; }
.add-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.inp {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; font-size: 13px;
}
.inp.wide { width: 100%; }
.sec-title { margin: 22px 0 4px; font-size: 14px; color: var(--muted); }
.thumb { width: 64px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); background: #000; display: block; }
.tpl-cell { display: flex; align-items: center; gap: 8px; min-width: 190px; }
.tpl-state { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.tpl-state .ok { color: #7ee2a8; }
.tpl-btns { display: flex; flex-direction: column; gap: 4px; }
.rule-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; user-select: none; }
.rule-check input { width: 16px; height: 16px; accent-color: var(--blue); }
.move-group { display: inline-flex; gap: 4px; margin-right: 6px; vertical-align: middle; }
.btn-move { padding: 3px 7px; font-size: 10px; line-height: 1.2; }

/* 车间折叠分组 */
textarea.inp { resize: vertical; min-height: 42px; line-height: 1.55; font-family: inherit; }
/* 表格列随面板宽度自适应压缩，避免右列被裁掉 */
#product-table .ws, #product-table .name, #product-table .lines { width: 100%; min-width: 88px; }
#product-table .switch-date { width: 100%; min-width: 122px; color-scheme: dark; }
#product-table .tpl-cell { min-width: 0; }
.ws-group .ws-head th {
  cursor: pointer; user-select: none; padding: 9px 10px;
  background: rgba(47, 107, 255, .12); color: var(--text);
  font-size: 13px; font-weight: 600; border-left: 3px solid var(--blue);
}
.ws-group .ws-head:hover th { background: rgba(47, 107, 255, .20); }
.ws-arrow { display: inline-block; width: 18px; color: var(--blue); transition: transform .15s; }
.ws-group.collapsed .ws-arrow { transform: rotate(-90deg); }
.ws-group.collapsed tr:not(.ws-head) { display: none; }
.ws-count { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 12px; }
.ws-move { display: inline-flex; gap: 4px; margin-left: 12px; vertical-align: middle; }
.ws-move .btn-move { background: rgba(255,255,255,.08); }
.td-actions { white-space: nowrap; }

/* 样板编辑器 */
.tpl-edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 760px) { .tpl-edit-grid { grid-template-columns: 1fr; } }
.field-rows { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow: auto; }
.field-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
}
.field-row input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--blue); }
.field-row input[type=text] { flex: 1; min-width: 0; }
.field-row.off { opacity: .5; }

/* 纸箱分区核对：分区框 + 分区列表 */
#tpl-region-layer { position: absolute; inset: 0; pointer-events: none; }
#tpl-region-layer[hidden] { display: none; }
.region-box {
  position: absolute; border: 2px solid #7c5cff; border-radius: 3px; pointer-events: auto;
  cursor: move; touch-action: none; background: rgba(124, 92, 255, .08); box-sizing: border-box;
}
.region-box.active { border-color: #a78bfa; background: rgba(124, 92, 255, .18); }
.region-box .rg-label {
  position: absolute; left: -2px; top: -22px; padding: 1px 7px; font-size: 11px; line-height: 17px;
  background: #7c5cff; color: #fff; border-radius: 4px; white-space: nowrap; pointer-events: none;
}
.region-box .rg-handle {
  position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #a78bfa;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); touch-action: none;
}
.rg-h-tl { left: -10px; top: -10px; cursor: nwse-resize; }
.rg-h-tr { right: -10px; top: -10px; cursor: nesw-resize; }
.rg-h-bl { left: -10px; bottom: -10px; cursor: nesw-resize; }
.rg-h-br { right: -10px; bottom: -10px; cursor: nwse-resize; }
.region-panel { margin-top: 10px; border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: var(--panel-2); }
.region-panel[hidden] { display: none; }
.region-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.region-list { display: flex; flex-direction: column; gap: 6px; max-height: 150px; overflow: auto; }
.region-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.region-item input { min-width: 0; }
.region-item .rg-acts { display: inline-flex; gap: 4px; }
.region-item .btn { padding: 3px 8px; font-size: 11px; }
.region-empty { color: var(--muted); font-size: 12px; }

/* 引擎自检 */
.env-rows { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.env-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); font-size: 13px;
}
.env-row span { color: var(--muted); }
.env-row b { font-variant-numeric: tabular-nums; }
.env-row b.good { color: #7ee2a8; }
.env-row b.bad { color: #ff9b9e; }
.env-row code { color: #9db4e8; font-size: 12px; }

/* 看板 / 日报 */
.board-panel, .report-panel { margin-top: 16px; }
.tabs, .report-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.date-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 12px 0; }
.kpi {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px;
}
.kpi span { color: var(--muted); font-size: 12px; }
.kpi b { font-size: 26px; line-height: 1.2; }
.kpi small { color: var(--muted); font-size: 11px; }
.kpi.pass { border-color: rgba(34, 164, 93, .55); }
.kpi.pass b { color: #7ee2a8; }
.kpi.warn { border-color: rgba(245, 165, 36, .55); }
.kpi.warn b { color: #ffd479; }
.kpi.fail { border-color: rgba(229, 72, 77, .55); }
.kpi.fail b { color: #ff9b9e; }

.bars { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 4px; }
.bar-row { display: grid; grid-template-columns: 76px 1fr 150px; gap: 10px; align-items: center; font-size: 13px; }
.bar-label { color: var(--muted); }
.bar { background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; height: 14px; overflow: hidden; }
.bar .fill { display: block; height: 100%; background: var(--blue); }
.bar .fill.pass { background: var(--green); }
.bar .fill.fail { background: var(--red); }
.bar .fill.warn { background: #f5a524; }
.bar-value { color: var(--muted); font-size: 12px; }
.board-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin-top: 10px; }
.board-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.board-card h3 { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.empty {
  padding: 22px; text-align: center; color: var(--muted); font-size: 13px;
  background: var(--panel-2); border: 1px dashed var(--border); border-radius: 10px;
}
.chip {
  display: inline-block; margin: 2px 4px 2px 0; padding: 2px 8px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  font-size: 12px; text-decoration: none;
}
.chip-active { background: var(--blue); border-color: var(--blue); color: #fff; }
.diff-summary-cell { max-width: 320px; word-break: break-all; color: #ffb3b6; font-size: 12px; }

/* 不一致摘要折叠：默认只显示「N 项不符」，点击展开完整内容（核对页/看板/日报通用） */
.diff-details { display: inline-block; max-width: 100%; }
.diff-details summary {
  cursor: pointer; list-style: none; user-select: none;
  color: var(--blue, #4d8dff); white-space: nowrap;
  padding: 1px 6px; border: 1px solid rgba(77, 141, 255, .35); border-radius: 999px;
  display: inline-block; line-height: 1.6;
}
.diff-details summary::-webkit-details-marker { display: none; }
.diff-details summary::after { content: " ▸"; font-size: 10px; }
.diff-details[open] summary::after { content: " ▾"; }
.diff-details[open] summary { color: #9ec3ff; border-color: rgba(158, 195, 255, .4); }
.diff-details .diff-full {
  margin-top: 4px; white-space: pre-wrap; word-break: break-all;
  color: #ffb3b6; line-height: 1.55;
}

/* 手机端防溢出 */
.panel { overflow-x: auto; }
.table { min-width: 620px; }
.table.compact { min-width: 0; }
.modal-card p.hint { word-break: break-all; }

@media (max-width: 720px) {
  .bar-row { grid-template-columns: 60px 1fr; }
  .bar-value { grid-column: 1 / -1; }
}

@media print {
  body { background: #fff; color: #000; padding: 0; }
  .topbar nav, .report-tools, .hint, .btn { display: none !important; }
  .panel { border: none; padding: 0; }
  .kpi, .board-card, .table th, .table td { border-color: #bbb; }
  .table th, .table td { padding: 4px 6px; font-size: 11px; }
  .kpi b { font-size: 18px; }
  .status-pass, .status-fail, .status-warn, .status-unknown { color: #000 !important; }
}
