:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --blue: #2563eb;
  --red: #dc2626;
  --green: #059669;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}
.hidden { display: none !important; }

/* 数据源标注与子页签 */
.src-badge {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid transparent; white-space: nowrap;
}
.src-badge.ok { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.src-badge.aux { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.subtabs { display: flex; gap: 6px; margin-top: 10px; }
.subtabs button {
  background: #f1f5f9; color: var(--muted); border: 1px solid var(--line);
  border-radius: 7px; padding: 5px 12px; cursor: pointer; font-size: 13px;
}
.subtabs button.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.diff-body { overflow: auto; }
.diff-table th, .diff-table td { text-align: right; }
.diff-table th:first-child, .diff-table td:first-child { text-align: left; }
.prod-stat-table th:nth-child(2), .prod-stat-table td:nth-child(2) { text-align: left; }
.prod-stat-table tbody tr:hover { background: #f8fafc; }

/* 登录 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  width: 360px; background: var(--card); padding: 28px; border-radius: 12px;
  box-shadow: 0 8px 30px rgba(17, 24, 39, .08);
}
.login-card h1 { margin: 0 0 18px; font-size: 20px; }
.login-card label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.login-card input {
  width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px;
}
.login-card button {
  width: 100%; margin-top: 6px; padding: 9px; border: 0; border-radius: 8px;
  background: var(--blue); color: #fff; font-size: 15px; cursor: pointer;
}
.login-card button:hover { background: #1d4ed8; }
.msg { min-height: 20px; margin-top: 8px; color: var(--red); font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  padding: 10px 18px; background: #0f172a; color: #fff;
}
.brand { font-weight: 700; font-size: 16px; margin-right: auto; }
.tag { font-size: 11px; background: #1e293b; padding: 2px 6px; border-radius: 6px; color: #93c5fd; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.controls select {
  padding: 6px 8px; border-radius: 8px; border: 1px solid #334155;
  background: #1e293b; color: #fff; max-width: 220px;
}
.seg { display: inline-flex; border: 1px solid #334155; border-radius: 8px; overflow: hidden; }
.seg button {
  background: transparent; color: #cbd5e1; border: 0; padding: 6px 10px;
  cursor: pointer; font-size: 13px;
}
.seg button.active { background: var(--blue); color: #fff; }
.user { color: #cbd5e1; font-size: 13px; }
.link { background: none; border: 0; color: #93c5fd; cursor: pointer; font-size: 13px; }

/* 标签页 */
.tabs {
  display: flex; gap: 4px; padding: 0 18px; background: #fff;
  border-bottom: 1px solid var(--line); position: sticky; top: 52px; z-index: 9;
  overflow-x: auto;
}
.tabs button {
  background: none; border: 0; padding: 12px 14px; cursor: pointer;
  color: var(--muted); font-size: 14px; border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs button.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }

main { padding: 16px 18px 40px; max-width: 1280px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

/* 卡片 */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.card h2 small { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.note { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.takt-note { color: var(--text); opacity: .82; font-variant-numeric: tabular-nums; }
.takt-chart { margin-top: 4px; }
.takt-chart svg.chart { max-height: 210px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  margin-top: 2px; font-size: 11px; color: var(--muted); }
.chart-legend .lg-click { cursor: pointer; }
.chart-legend .lg-note { color: #9ca3af; }
.chart-legend .lg .dash { width: 12px; height: 0; border-top: 2px dashed #dc2626;
  border-radius: 0; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpis.small { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px;
}
.kpi .k { color: var(--muted); font-size: 12px; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 2px; }
.kpi .v.good { color: var(--green); }
.kpi .v.bad { color: var(--red); }
.kpis.small .v { font-size: 20px; }

/* 图表 */
.chart-box { width: 100%; overflow: hidden; }
svg.chart { display: block; width: 100%; height: auto; }
.chart .gl { stroke: #eef2f7; stroke-width: 1; }
.chart .tick { fill: #6b7280; font-size: 10px; }
.chart .hoverable:hover { opacity: .82; }
.chart .clickable { cursor: pointer; }
.chart .stat-val { fill: #111827; font-size: 11px; font-weight: 600; }
.chart .stat-sub { fill: #6b7280; font-size: 9.5px; }
/* 直方图下方图例：与卡片说明同为灰色小字，窄屏只截断不换行、不溢出 */
.hist-legend {
  margin: 4px 0 0; font-size: 10px; line-height: 1.5; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.empty {
  padding: 40px 10px; text-align: center; color: var(--muted);
  background: #fafbfd; border: 1px dashed var(--line); border-radius: 8px;
}
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 5px; }
.lg i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* 表格 */
.table-wrap { overflow: auto; max-height: 360px; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid #f1f5f9; text-align: left; white-space: nowrap; }
th { background: #f8fafc; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
tr:hover td { background: #f8fafc; }
.badge { padding: 1px 6px; border-radius: 10px; font-size: 12px; }
.badge.ok { background: #ecfdf5; color: var(--green); }
.badge.bad { background: #fef2f2; color: var(--red); }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 10px; font-size: 13px; }
.pager button {
  padding: 5px 12px; border: 1px solid var(--line); background: #fff;
  border-radius: 8px; cursor: pointer;
}
.pager button:disabled { opacity: .45; cursor: default; }

/* CPK */
select.wide { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; }
.dimstats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin-top: 10px; font-size: 13px; }
.dimstats div { color: var(--muted); }
.dimstats b { color: var(--text); }

.load-veil {
  position: fixed; inset: 0; z-index: 8; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .22s ease, visibility 0s linear .22s;
}
.load-veil.show {
  opacity: 1; visibility: visible; pointer-events: auto;
  transition: opacity .16s ease;
}
.veil-box { text-align: center; }
.veil-spin {
  width: 28px; height: 28px; margin: 0 auto 10px; border-radius: 50%;
  border: 3px solid #dbeafe; border-top-color: var(--blue);
  animation: veilSpin .8s linear infinite;
}
.veil-text { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.veil-bars { width: min(320px, 70vw); margin: 0 auto; display: grid; gap: 8px; }
.veil-bars i {
  display: block; height: 10px; border-radius: 6px;
  background: linear-gradient(90deg, #e8eef7 25%, #f4f8fd 37%, #e8eef7 63%);
  background-size: 400% 100%; animation: veilShimmer 1.3s ease infinite;
}
.veil-bars i:nth-child(2) { width: 86%; }
.veil-bars i:nth-child(3) { width: 68%; }
@keyframes veilSpin { to { transform: rotate(360deg); } }
@keyframes veilShimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.tab.fade-in { animation: tabIn .3s ease; }
@keyframes tabIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .load-veil, .veil-spin, .veil-bars i, .tab.fade-in { animation: none; transition: none; }
}
.load-error {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
  margin: 0 0 14px; padding: 10px 14px; border: 1px solid #fecaca;
  border-left: 4px solid var(--red); border-radius: 8px;
  background: #fef2f2; color: #991b1b; font-size: 13px;
}
.load-error span { flex: 1 1 260px; }
.load-error button {
  padding: 5px 14px; border: 1px solid #fca5a5; border-radius: 6px;
  background: #fff; color: var(--red); cursor: pointer; font-size: 13px;
}
.load-error button:hover { background: #fee2e2; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30;
  background: #111827; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px;
}
.subhead { font-size: 12px; color: var(--muted); margin: 6px 0 2px; }

/* 管理后台 */
.admin-subnav { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.admin-subnav button {
  padding: 6px 12px; border: 1px solid var(--line); background: #fff;
  border-radius: 16px; cursor: pointer; font-size: 13px; color: var(--muted);
}
.admin-subnav button.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.admin-card h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.admin-card h3 small { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 14px; }
.form-grid label { display: block; font-size: 12px; color: var(--muted); }
.form-grid input, .form-grid select, .modal input {
  width: 100%; margin-top: 3px; padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 13px; background: #fff; color: var(--text);
}
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.form-msg { min-height: 18px; margin-top: 6px; font-size: 12px; }
.form-msg.ok { color: var(--green); }
.form-msg.err { color: var(--red); }
.btn {
  padding: 6px 12px; border: 1px solid var(--line); background: #fff;
  border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--text);
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { background: #fef2f2; border-color: #fecaca; color: var(--red); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .45; cursor: default; }
td.ops { white-space: nowrap; }
td.ops .btn { margin-right: 4px; }
select.mini, input.mini {
  padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 12px; background: #fff;
}
input.mini.num { width: 92px; }
.danger-text { color: var(--red); font-size: 13px; margin: 0 0 10px; }
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  width: 100%; max-width: 460px; background: #fff; border-radius: 12px;
  padding: 18px; box-shadow: 0 20px 50px rgba(17, 24, 39, .25); max-height: 90vh; overflow: auto;
}
.modal h3 { margin: 0 0 12px; font-size: 15px; }
.modal-body label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modal pre { background: #f8fafc; padding: 8px; border-radius: 6px; font-size: 11px; overflow: auto; }

/* 二维码查询 */
.qr-card h2 { margin: 0 0 8px; }
.qr-form { display: flex; gap: 8px; }
.qr-form input {
  flex: 1; min-width: 0; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; font-family: ui-monospace, Consolas, monospace;
}
.btn.mini { padding: 3px 10px; font-size: 12px; border-radius: 6px; }
.qr-scan-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 6px; }
.qr-scan-hint { margin: 0 0 12px; font-size: 12.5px; line-height: 1.6; }
.qr-cam { margin: 0 0 12px; }
.qr-cam video { display: block; width: 100%; max-width: 520px; border-radius: 10px; background: #0f172a; }
.qr-cam-actions { margin-top: 8px; }
.qr-code-line {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin: 6px 0 0; font-size: 13px; color: var(--muted);
}
.qr-code-line code {
  color: #0f172a; word-break: break-all; background: #f1f5f9;
  border: 1px solid var(--line); padding: 3px 8px; border-radius: 6px; font-size: 12.5px;
}
.qr-summary .qr-sum-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.qr-count { font-size: 30px; font-weight: 700; color: var(--blue); white-space: nowrap; }
.qr-count small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); text-align: right; }
.qr-timeline { display: flex; gap: 12px; overflow-x: auto; padding: 4px 2px 10px; }
.qr-node {
  flex: 0 0 auto; min-width: 190px; max-width: 240px; text-align: left; cursor: pointer;
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--muted);
  border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px;
}
.qr-node.ok { border-left-color: var(--green); }
.qr-node.bad { border-left-color: var(--red); }
.qr-node-time { font-size: 13px; font-weight: 600; }
.qr-node-prod { font-size: 12px; color: var(--muted); }
.qr-node-dims { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.qr-kv { background: #f1f5f9; border-radius: 4px; padding: 1px 5px; font-size: 11px; }
.qr-kv.oos { background: #fef2f2; color: var(--red); font-weight: 600; }
.qr-muted { color: var(--muted); }
.qr-rec { margin-bottom: 12px; }
.qr-rec-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.qr-rec-head h3 { margin: 0; font-size: 14px; }
.qr-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 4px 16px; margin: 10px 0; font-size: 13px;
}
.qr-note { color: var(--muted); font-size: 12px; margin: 4px 0 8px; }
.qr-rec h4 { margin: 8px 0 6px; font-size: 13px; }
.qr-dimwrap table { font-size: 12px; }
.qr-dimwrap tr.oos td { background: #fef2f2; color: #b91c1c; font-weight: 600; }
.qr-tag {
  display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 8px;
  background: #eff6ff; color: var(--blue); font-size: 11px;
}
.qr-notfound h2 { color: var(--red); }

@media (max-width: 900px) {
  .kpis, .kpis.small { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
  .brand { font-size: 14px; width: 100%; }
  .topbar { position: static; }
  .tabs { position: static; }
  .controls select { max-width: 100%; }
}
@media (max-width: 560px) {
  main { padding: 10px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi .v { font-size: 18px; }
  .chart .tick { font-size: 9px; }
  .qr-form { flex-direction: column; }
  .qr-summary .qr-sum-head { flex-direction: column; align-items: flex-start; }
  .qr-count small { text-align: left; }
  .qr-grid { grid-template-columns: 1fr; }
}


/* Pareto 累计占比开关 */
.cum-toggle {
  float: right; display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 400; color: #6b7280;
  cursor: pointer; user-select: none; line-height: 1.6;
}
.cum-toggle input { width: 13px; height: 13px; margin: 0; accent-color: #2563eb; cursor: pointer; }


/* 扫码引擎状态与全屏取景 */
.qr-engine { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.qr-engine b { color: #374151; }
.qr-big { min-height: 42px; }
.qr-cam {
  position: fixed; inset: 0; z-index: 80; background: #000; overflow: hidden; margin: 0;
  display: flex; align-items: center; justify-content: center;
}
.qr-cam.hidden { display: none; }
.qr-cam video {
  position: absolute; inset: 0; width: 100%; height: 100%; max-width: none;
  object-fit: cover; background: #000; border-radius: 0;
}
.qr-frame {
  position: relative; width: min(78vw, 60vh); height: min(78vw, 60vh);
  border: 2px solid rgba(255, 255, 255, .92); border-radius: 16px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .48); pointer-events: none;
}
.qr-cam-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center;
  justify-content: space-between; color: #fff; font-size: 13px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(rgba(0, 0, 0, .6), rgba(0, 0, 0, 0));
}
.qr-cam-close {
  width: 38px; height: 38px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(255, 255, 255, .18); color: #fff; font-size: 22px; line-height: 1;
}
.qr-cam-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; color: #fff;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .75));
}
.qr-cam-msg { margin: 0 0 8px; text-align: center; font-size: 14px; min-height: 20px; }
.qr-caps { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 8px; }
.qr-chip {
  font-size: 11px; line-height: 18px; padding: 1px 8px; border-radius: 999px;
  background: rgba(255, 255, 255, .16); color: #e5e7eb;
}
.qr-zoom { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-size: 12px; color: #e5e7eb; }
.qr-zoom input[type=range] { flex: 1; accent-color: #fff; }
.qr-cam-btns { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
.qr-cam-btns .btn {
  min-width: 120px; min-height: 44px; color: #fff;
  background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .3);
}
.qr-cam-btns .btn.on { background: #f59e0b; border-color: #f59e0b; color: #111; }

/* 不良统计忽略标签说明 */
.ignore-note { font-size: 12px; color: #9ca3af; margin: -2px 0 10px; }
