:root {
  --bg: #eef3f7;
  --panel: #ffffff;
  --ink: #102033;
  --muted: #65748a;
  --line: #dbe4ec;
  --nav: #142235;
  --nav-2: #1e3148;
  --blue: #1769e0;
  --green: #17a673;
  --yellow: #d59b13;
  --red: #cf3e43;
  --shadow: 0 18px 45px rgba(31, 50, 72, 0.12);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button, input { font: inherit; }
button { cursor: pointer; border: 0; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  background: linear-gradient(180deg, var(--nav), #0f1b2b);
  color: white;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 8px;
  display: grid; place-items: center;
  background: #ffffff;
  overflow: hidden;
  padding: 4px;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand strong { display: block; font-size: 16px; }
.brand span { display: block; color: #9eb0c7; font-size: 12px; margin-top: 4px; }

.nav-list { display: grid; gap: 6px; }
.nav-item {
  height: 42px;
  color: #c7d3e3;
  background: transparent;
  border-radius: 8px;
  text-align: left;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: 0.18s ease;
}
.nav-item:hover, .nav-item.active { background: var(--nav-2); color: #fff; }
.icon { width: 22px; text-align: center; color: #8fb4e8; }

.sidebar-card {
  margin-top: auto;
  padding: 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
}
.sidebar-card p { color: #b7c5d7; font-size: 12px; line-height: 1.7; margin: 12px 0 0; }
.switch { float: right; position: relative; width: 40px; height: 22px; }
.switch input { display: none; }
.switch span { position: absolute; inset: 0; background: #526176; border-radius: 999px; }
.switch span::after {
  content: ""; position: absolute; width: 16px; height: 16px; top: 3px; left: 3px;
  background: white; border-radius: 50%; transition: 0.2s ease;
}
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(18px); }

.main { padding: 22px; overflow: hidden; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 18px;
}
h1, h2, p { margin: 0; }
h1 { font-size: 24px; letter-spacing: 0; }
h2 { font-size: 18px; letter-spacing: 0; }
.topbar p, .panel-head p { color: var(--muted); margin-top: 6px; font-size: 13px; }
.top-status { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.top-status span {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: #334258;
  font-size: 13px;
}
.dot {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  margin-right: 7px;
  vertical-align: 1px;
}
.ok { background: var(--green); }
.warn { background: var(--yellow); }
.bad { background: var(--red); }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 8px 20px rgba(31, 50, 72, 0.04);
}
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { display: block; font-size: 30px; margin: 8px 0 5px; letter-spacing: 0; }
.metric em { color: var(--muted); font-size: 12px; font-style: normal; }
.metric.success strong { color: var(--green); }
.metric.warning strong { color: var(--yellow); }
.metric.danger strong { color: var(--red); }

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
}
.inspection-panel, .evidence-panel, .chart-panel, .rank-panel, .records-panel, .trace-section, .module-section, .review-workbench {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.inspection-panel { padding: 18px; }
.evidence-panel { padding: 18px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 15px;
}
.panel-head.compact { margin-bottom: 12px; }

.segmented {
  display: flex;
  padding: 4px;
  background: #edf3f8;
  border-radius: 8px;
}
.segmented button {
  padding: 9px 12px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}
.segmented button.active { background: #fff; color: var(--ink); box-shadow: 0 3px 8px rgba(20,34,53,0.1); }

.product-cases {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 14px;
}
.product-case {
  min-height: 78px;
  text-align: left;
  border: 1px solid var(--line);
  background: #f7fafc;
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  transition: 0.18s ease;
}
.product-case:hover,
.product-case.active {
  border-color: rgba(23, 105, 224, 0.55);
  background: #eef6ff;
  box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.08);
}
.product-case span,
.product-case em {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.35;
}
.product-case strong {
  display: block;
  margin: 5px 0 4px;
  font-size: 14px;
}

.workflow-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  gap: 8px;
  align-items: center;
  margin: 0 0 14px;
}
.workflow-step {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafc;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  color: var(--muted);
  transition: 0.2s ease;
}
.workflow-step b {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e4edf6;
  color: #35506d;
  font-size: 12px;
}
.workflow-step span { font-size: 13px; white-space: nowrap; }
.workflow-step.active {
  color: var(--ink);
  border-color: rgba(23, 105, 224, 0.55);
  background: #eef6ff;
}
.workflow-step.active b { background: var(--blue); color: #fff; }
.workflow-step.done {
  color: var(--green);
  border-color: rgba(23, 166, 115, 0.35);
  background: #effbf6;
}
.workflow-step.done b { background: var(--green); color: #fff; }

.inspection-stage {
  position: relative;
  min-height: 385px;
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(22,44,71,0.12), transparent),
    linear-gradient(180deg, #d7e0e9, #b8c6d4);
  display: grid;
  place-items: center;
}
.part-visual {
  position: relative;
  width: min(82%, 700px);
  aspect-ratio: 16 / 8.2;
  border-radius: 6px;
  background: #d4dbe2;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.6), 0 28px 70px rgba(38, 54, 73, 0.28);
  overflow: hidden;
  transform: perspective(900px) rotateX(3deg) rotateZ(-0.5deg);
}
.part-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.part-label {
  position: absolute; left: 18px; top: 16px;
  padding: 7px 10px;
  background: rgba(16, 32, 51, 0.72);
  color: #fff;
  border-radius: 6px;
  font-size: 12px;
}
.surface-line {
  position: absolute; left: 8%; right: 8%; height: 1px;
  background: rgba(255,255,255,0.26);
}
.l1 { top: 34%; } .l2 { top: 51%; } .l3 { top: 68%; }
.defect-box {
  position: absolute;
  width: 132px; height: 62px;
  left: var(--defect-x, 58%);
  top: var(--defect-y, 39%);
  border: 2px solid var(--yellow);
  border-radius: 6px;
  box-shadow: 0 0 0 4px rgba(213,155,19,0.18);
  opacity: 1;
}
.defect-box span {
  position: absolute;
  left: -2px; top: -30px;
  background: var(--yellow);
  color: #fff;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 12px;
}
.heatmap {
  position: absolute;
  left: calc(var(--defect-x, 58%) + 36px);
  top: calc(var(--defect-y, 39%) + 18px);
  width: 86px; height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(207,62,67,0.78), rgba(213,155,19,0.28) 60%, transparent 72%);
  filter: blur(2px);
  opacity: 1;
}
.scan-rail {
  position: absolute;
  top: 0; bottom: 0; left: 28%;
  width: 2px;
  background: linear-gradient(180deg, transparent, rgba(23,105,224,0.78), transparent);
  opacity: 0;
}
.inspection-stage.scanning .scan-rail { opacity: 1; animation: scan 1.4s ease-in-out infinite; }
@keyframes scan { 50% { left: 72%; } }

.capture-flash {
  position: absolute;
  left: 16px;
  bottom: 16px;
  background: rgba(23, 105, 224, 0.9);
  color: #fff;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  opacity: 0;
  transform: translateY(6px);
}
.inspection-stage.capturing .capture-flash {
  animation: flashLabel 1s ease both;
}
@keyframes flashLabel {
  0% { opacity: 0; transform: translateY(6px); }
  20%, 80% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-4px); }
}

.analysis-grid {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(23,105,224,0.13) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23,105,224,0.13) 1px, transparent 1px);
  background-size: 42px 42px;
  opacity: 0;
  pointer-events: none;
}
.inspection-stage.analyzing .analysis-grid {
  animation: gridPulse 1.1s ease-in-out infinite;
}
@keyframes gridPulse {
  0%, 100% { opacity: 0.12; }
  50% { opacity: 0.42; }
}
.inspection-stage.hide-defect .defect-box,
.inspection-stage.hide-defect .heatmap {
  opacity: 0;
}
.inspection-stage.marking .defect-box {
  animation: markBox 0.8s ease both;
}
.inspection-stage.marking .heatmap {
  animation: heatAppear 0.8s ease both;
}
@keyframes markBox {
  0% { opacity: 0; transform: scale(0.72); }
  65% { opacity: 1; transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes heatAppear {
  0% { opacity: 0; transform: scale(0.4); }
  100% { opacity: 1; transform: scale(1); }
}

.result-row {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.result-status {
  border-left: 4px solid var(--yellow);
  padding-left: 12px;
}
.result-status span, .result-status em { display: block; color: var(--muted); font-size: 12px; font-style: normal; }
.result-status strong { display: block; font-size: 24px; margin: 4px 0; }
.result-status.success { border-color: var(--green); }
.result-status.success strong { color: var(--green); }
.result-status.danger { border-color: var(--red); }
.result-status.danger strong { color: var(--red); }
.result-status.warning strong { color: var(--yellow); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.primary, .secondary, .success-btn, .danger-btn, .ghost {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 14px;
  font-size: 14px;
}
.primary { background: var(--blue); color: white; }
.secondary { background: #e9f0f7; color: #22344b; }
.success-btn { background: var(--green); color: white; }
.danger-btn { background: var(--red); color: white; }
.ghost { background: transparent; color: var(--blue); }
.small { min-height: 34px; font-size: 13px; }

.evidence-images { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.evidence-images span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.thumb {
  height: 104px;
  border-radius: 8px;
  background: var(--thumb-image, url("./assets/inspection-part.png")) center / cover;
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}
.thumb.result i {
  position: absolute; width: 36px; height: 28px; right: 24px; top: 42px;
  border: 2px solid var(--yellow); border-radius: 4px;
}
.evidence-list { margin: 14px 0 0; display: grid; gap: 9px; }
.evidence-list div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid #edf2f6; padding-bottom: 9px; }
dt { color: var(--muted); font-size: 12px; }
dd { margin: 0; font-size: 13px; text-align: right; }
.trace-callout {
  margin-top: 16px;
  background: #f2f8ff;
  border: 1px solid #d6e9ff;
  border-radius: 8px;
  padding: 13px;
}
.trace-callout strong, .trace-callout span { display: block; }
.trace-callout strong { font-size: 14px; }
.trace-callout span { color: var(--muted); font-size: 12px; margin-top: 6px; line-height: 1.6; }

.lower-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.8fr 1.4fr;
  gap: 14px;
  margin-top: 14px;
}
.chart-panel, .rank-panel, .records-panel, .trace-section, .module-section, .review-workbench { padding: 16px; }
.review-workbench { margin-top: 14px; }
.review-summary { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.review-summary span {
  min-height: 34px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  font-size: 13px;
  background: #f7fafc;
}
.review-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 310px;
  gap: 14px;
}
.review-queue { display: grid; gap: 9px; align-content: start; }
.review-case {
  text-align: left;
  border: 1px solid var(--line);
  background: #f7fafc;
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
}
.review-case.active {
  background: #eef6ff;
  border-color: rgba(23, 105, 224, 0.55);
  box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.08);
}
.review-case.high { border-color: rgba(207, 62, 67, 0.35); }
.review-case b, .review-case span, .review-case em { display: block; }
.review-case b { font-size: 14px; }
.review-case span { color: var(--muted); font-size: 12px; margin: 6px 0; line-height: 1.45; }
.review-case em { color: var(--yellow); font-size: 12px; font-style: normal; }
.review-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.review-image-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 7px;
}
.review-image {
  min-height: 250px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--review-image, url("./assets/sample-white-plastic.png")) center / cover;
  position: relative;
  overflow: hidden;
}
.review-image.ai i {
  position: absolute;
  left: 58%;
  top: 42%;
  width: 100px;
  height: 58px;
  border: 2px solid var(--yellow);
  border-radius: 6px;
  box-shadow: 0 0 0 4px rgba(213,155,19,0.16);
}
.review-image.ai i::after {
  content: "";
  position: absolute;
  left: 28px;
  top: 18px;
  width: 54px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(207,62,67,0.8), rgba(213,155,19,0.25) 60%, transparent 72%);
  filter: blur(2px);
}
.review-decision {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f7fafc;
}
.review-decision strong {
  display: block;
  font-size: 20px;
  margin: 8px 0 12px;
}
.review-decision dl { margin: 0; display: grid; gap: 9px; }
.review-decision dl div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #e7eef5;
  padding-bottom: 9px;
}
.review-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}
.review-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}
.bars { height: 168px; display: flex; align-items: end; gap: 12px; padding-top: 12px; }
.bars span {
  flex: 1;
  min-width: 18px;
  background: linear-gradient(180deg, var(--blue), #9fc3f2);
  border-radius: 6px 6px 2px 2px;
}
.rank-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.rank-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; background: #f4f7fa; border-radius: 8px;
}
.rank-list b { color: var(--red); }
.record-list { display: grid; gap: 8px; }
.record-item {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid #edf2f6;
  border-radius: 8px;
}
.record-thumb {
  width: 44px; height: 34px;
  border-radius: 6px;
  background: linear-gradient(135deg, #d5dde4, #aebbc6);
}
.record-item strong { display: block; font-size: 13px; }
.record-item span { color: var(--muted); font-size: 12px; }
.tag {
  padding: 5px 8px; border-radius: 999px; color: white; font-size: 12px;
}
.tag.ok { background: var(--green); }
.tag.warn { background: var(--yellow); }
.tag.bad { background: var(--red); }

.trace-section { margin-top: 14px; }
.module-section { margin-top: 14px; }
.module-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.module-card {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 15px;
  background: #f7fafc;
}
.module-card span, .module-card em {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}
.module-card strong {
  display: block;
  margin: 9px 0 6px;
  font-size: 24px;
}
.module-card.good strong { color: var(--green); }
.module-card.warn-card strong { color: var(--yellow); }
.search-box { display: flex; gap: 8px; }
.search-box input {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  min-width: 230px;
}
.trace-grid { display: grid; grid-template-columns: 1fr 1.2fr; gap: 14px; }
.trace-summary {
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.trace-summary strong { display: block; font-size: 26px; margin: 8px 0; }
.trace-summary p { color: var(--muted); line-height: 1.7; margin-bottom: 14px; }
.trace-timeline {
  border-left: 2px solid #dbe7f1;
  padding-left: 18px;
  display: grid;
  gap: 13px;
}
.trace-timeline div { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.muted { color: var(--muted); font-size: 12px; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #102033;
  color: #fff;
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 82px minmax(0, 1fr); }
  .brand div:not(.brand-mark), .nav-item:not(.active) { font-size: 0; }
  .nav-item { justify-content: center; padding: 0; }
  .nav-item.active { font-size: 0; }
  .icon { font-size: 16px; }
  .sidebar-card { display: none; }
  .metrics-grid { grid-template-columns: repeat(3, 1fr); }
  .workspace-grid, .lower-grid, .trace-grid, .module-grid, .review-layout, .review-compare { grid-template-columns: 1fr; }
  .product-cases { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workflow-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; padding: 14px; }
  .nav-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-item, .nav-item.active, .nav-item:not(.active) { font-size: 12px; justify-content: flex-start; padding: 0 10px; }
  .main { padding: 14px; overflow: visible; }
  .topbar, .panel-head, .result-row { align-items: stretch; flex-direction: column; }
  .top-status { display: grid; grid-template-columns: 1fr; justify-content: stretch; }
  .top-status span, .top-status button { width: 100%; max-width: 100%; min-width: 0; overflow-wrap: anywhere; }
  .metrics-grid { grid-template-columns: 1fr; }
  .product-cases { grid-template-columns: 1fr; }
  .workflow-strip { grid-template-columns: 1fr; }
  .inspection-stage { min-height: 280px; }
  .part-visual { width: 90%; }
  .actions, .search-box { display: grid; grid-template-columns: 1fr 1fr; }
  .search-box input { min-width: 0; }
}
