/* DEMO copy drops Google Fonts so offline pages do not call the network. */
:root {
  --bg: #dbeafe;
  --bg-mesh: radial-gradient(ellipse 80% 60% at 10% -10%, rgba(255, 255, 255, 0.7), transparent 55%),
             radial-gradient(ellipse 60% 50% at 90% 100%, rgba(249, 115, 22, 0.08), transparent 50%),
             radial-gradient(ellipse 50% 40% at 50% 50%, rgba(147, 197, 253, 0.25), transparent 70%);
  --surface: rgba(255, 255, 255, 0.92);
  --surface-solid: #ffffff;
  --surface2: #edf4fc;
  --surface-hover: #e0eef9;
  --glass: rgba(255, 255, 255, 0.55);
  --border: rgba(59, 130, 246, 0.14);
  --border-strong: rgba(59, 130, 246, 0.26);
  --text: #1e3a5f;
  --text-dim: #475569;
  --text-muted: #64748b;
  --accent: #f97316;
  --accent-dim: #ea580c;
  --accent-bright: #fb923c;
  --accent-glow: rgba(249, 115, 22, 0.28);
  --accent-muted: rgba(249, 115, 22, 0.1);
  --on-accent: #fff;
  --ok: #059669;
  --ok-dim: rgba(5, 150, 105, 0.12);
  --ng: #e11d48;
  --ng-dim: rgba(225, 29, 72, 0.1);
  --warn: #d97706;
  --warn-dim: rgba(217, 119, 6, 0.1);
  --sidebar-w: 248px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(30, 64, 175, 0.08);
  --shadow-glow: 0 0 24px rgba(249, 115, 22, 0.12);
  --font: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --font-display: "Outfit", "Noto Sans TC", sans-serif;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-mesh);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(59, 130, 246, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59, 130, 246, 0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
}

.app-layout { display: flex; min-height: 100vh; position: relative; z-index: 1; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 18px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background var(--transition);
}

.sidebar-brand:hover {
  background: rgba(234, 88, 12, 0.06);
}

.sidebar-brand.active {
  background: rgba(234, 88, 12, 0.1);
}

.logo {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--accent) 0%, #f59e0b 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.05em;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.brand-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-sub { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

.sidebar-nav {
  flex: 1;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 14px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  position: relative;
}

.nav-item:hover {
  background: var(--glass);
  color: var(--text);
}

.nav-item.active {
  background: linear-gradient(135deg, var(--accent-muted), rgba(245, 158, 11, 0.1));
  color: var(--accent-dim);
  box-shadow: inset 0 0 0 1px rgba(249, 115, 22, 0.25);
}

.nav-item.active .nav-icon svg { stroke: var(--accent); }

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
  stroke: var(--text-dim);
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke var(--transition);
}

.nav-item:hover .nav-icon svg { stroke: var(--text); }

.nav-badge {
  position: absolute;
  right: 10px;
  background: var(--ng);
  color: #fff;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 700;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 18px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.6);
  animation: pulse-dot 2.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Main area ── */
.main-area {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-header {
  padding: 24px 32px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(12px);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
}

.page-header-text { flex: 1; min-width: 200px; }

.page-header h1 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.page-header p {
  font-size: 13px;
  color: var(--text-dim);
  max-width: 560px;
}

.page-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.page-header .btn { margin-left: 0; }

/* ── Workflow stepper ── */
.workflow-track {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 20px 32px;
  background: rgba(255, 255, 255, 0.6);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.wf-step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  transition: all 0.35s ease;
  white-space: nowrap;
  position: relative;
}

.wf-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  transition: all 0.35s ease;
}

.wf-step.active {
  color: var(--text);
  background: var(--accent-muted);
  border-color: rgba(249, 115, 22, 0.35);
  box-shadow: var(--shadow-glow);
}

.wf-step.active .wf-num {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  border-color: transparent;
  color: var(--on-accent);
  box-shadow: 0 0 16px var(--accent-glow);
}

.wf-step.done { color: var(--ok); }
.wf-step.done .wf-num {
  background: var(--ok-dim);
  border-color: rgba(52, 211, 153, 0.4);
  color: var(--ok);
}

.wf-arrow {
  color: var(--text-muted);
  font-size: 12px;
  padding: 0 4px;
  opacity: 0.5;
}

/* ── Layout grids ── */
.page-content { flex: 1; }
.page-grid { padding: 24px 32px 32px; display: grid; gap: 20px; }
.setup-panel { margin: 0 32px 0; border-color: rgba(249, 115, 22, 0.25); }
.setup-panel.ready { border-color: rgba(5, 150, 105, 0.35); }
.setup-panel .panel-header { gap: 12px; }
.machine-badge {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent-muted);
  color: var(--accent-dim);
  border: 1px solid rgba(249, 115, 22, 0.25);
}
.setup-form { padding-top: 4px; }
.setup-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.setup-field { display: flex; flex-direction: column; gap: 6px; }
.setup-field span { font-size: 12px; font-weight: 600; color: var(--text-dim); }
.setup-field.required em { color: var(--ng); font-style: normal; }
.setup-field input {
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
}
.setup-field input:read-only { color: var(--text-dim); background: var(--glass); cursor: default; }
.setup-field textarea {
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  resize: vertical;
  min-height: 88px;
}
.setup-field input:focus,
.setup-field textarea:focus {
  outline: none;
  border-color: rgba(249, 115, 22, 0.55);
  box-shadow: 0 0 0 3px var(--accent-muted);
}
.setup-hint { margin-top: 12px; font-size: 12px; color: var(--text-muted); }
.setup-hint.ready { color: var(--ok); font-weight: 500; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

.inspection-grid { grid-template-columns: 1.25fr 0.75fr; }
.inspection-grid .panel-wide { grid-column: span 2; }
.stats-grid { grid-template-columns: 1fr 1fr; }
.stats-grid .stat-cards-4 { grid-column: span 2; }
.stats-grid .panel-wide { grid-column: span 2; }
.analysis-grid { grid-template-columns: 1fr 1fr; }
.analysis-grid .panel-wide { grid-column: span 2; }
.retrain-grid { grid-template-columns: 1fr 1fr; }
.retrain-grid .panel-wide { grid-column: span 2; }
.judgment-grid { grid-template-columns: 1fr 1fr; }
.judgment-grid .panel-wide { grid-column: span 2; }

/* ── Panels ── */
.panel {
  background: var(--surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: border-color var(--transition);
}

.panel:hover { border-color: var(--border-strong); }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(219, 234, 254, 0.35);
}

.panel-header h2 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.panel-body { padding: 18px; }

/* ── Stat cards ── */
.stat-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 18px; }
.stat-cards-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  padding: 0;
  grid-column: span 2;
}

.stat-card {
  padding: 20px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0.6;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.stat-card.ok::before { background: var(--ok); }
.stat-card.ng::before { background: var(--ng); }
.stat-card.yield::before, .stat-card.total::before { background: var(--accent); }

.stat-value {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.stat-label { font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.stat-card.ok .stat-value { color: var(--ok); }
.stat-card.ng .stat-value { color: var(--ng); }
.stat-card.yield .stat-value, .stat-card.total .stat-value { color: var(--accent); }

.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  padding: 0 32px 20px;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color var(--transition);
}

.summary-card:hover { border-color: var(--border-strong); }
.summary-card span { font-size: 12px; color: var(--text-dim); font-weight: 500; }
.summary-card strong { font-family: var(--font-display); font-size: 24px; font-weight: 700; }

/* ── Camera / inspection view ── */
.view-toggle {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.toggle-btn {
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
}

.toggle-btn:hover { color: var(--text); }
.toggle-btn.active {
  background: linear-gradient(135deg, var(--accent-dim), var(--accent));
  color: var(--on-accent);
  font-weight: 600;
}

.camera-view {
  position: relative;
  aspect-ratio: 1;
  background: #c5dff5;
  margin: 16px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  box-shadow: inset 0 0 30px rgba(30, 64, 175, 0.06);
}

.camera-view::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(249, 115, 22, 0.1);
  border-radius: inherit;
  pointer-events: none;
}

.camera-view img { width: 100%; height: 100%; object-fit: contain; }

.image-comparison { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; padding: 16px; }
.image-comparison-side { min-width: 0; }
.image-comparison-side h3 { margin: 0 0 10px; font-size: 14px; }
.image-comparison .camera-view { margin: 0; aspect-ratio: 4 / 3; }
@media (max-width: 700px) {
  .image-comparison { grid-template-columns: minmax(0, 1fr); }
}

.placeholder { text-align: center; color: var(--text-muted); padding: 24px; }
.placeholder-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.35; }
.placeholder p { font-size: 13px; }

.processing-overlay {
  position: absolute;
  inset: 0;
  background: rgba(219, 234, 254, 0.88);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 2;
}

.processing-overlay p {
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}

.batch-progress {
  width: min(280px, 80%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.batch-progress-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 3px;
  overflow: hidden;
}

.batch-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.25s ease;
}

#batchProgressText {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.result-badge {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.06em;
  z-index: 3;
  box-shadow: var(--shadow);
}

.result-badge.ok {
  background: linear-gradient(135deg, #10b981, var(--ok));
  color: #fff;
  box-shadow: 0 4px 20px rgba(52, 211, 153, 0.4);
}

.result-badge.ng {
  background: linear-gradient(135deg, #e11d48, var(--ng));
  color: #fff;
  box-shadow: 0 4px 20px rgba(251, 113, 133, 0.4);
}

/* ── Controls & forms ── */
.controls {
  display: flex;
  gap: 10px;
  padding: 0 16px 12px;
  flex-wrap: wrap;
}

.controls select,
.controls input,
.retrain-form input,
.settings-form input[type="number"],
.settings-form input[type="text"],
#filterResult {
  flex: 1;
  min-width: 100px;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.controls select:focus,
.controls input:focus,
.settings-form input:focus,
#filterResult:focus {
  outline: none;
  border-color: rgba(249, 115, 22, 0.55);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.btn {
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-dim), var(--accent));
  color: var(--on-accent);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover { box-shadow: 0 6px 24px var(--accent-glow); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-sm { padding: 6px 12px; font-size: 11px; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-ng { background: var(--ng); color: #fff; }
.btn-lg { padding: 12px 24px; font-size: 14px; }

/* ── Sample gallery ── */
.sample-gallery {
  display: flex;
  gap: 10px;
  padding: 4px 16px 16px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.sample-thumb {
  flex-shrink: 0;
  width: 76px;
  cursor: pointer;
  text-align: center;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 5px;
  transition: border-color var(--transition), background var(--transition);
}

.sample-thumb:hover { background: var(--glass); }
.sample-thumb.selected {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.sample-thumb img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.sample-thumb span {
  font-size: 10px;
  color: var(--text-muted);
  display: block;
  margin-top: 4px;
  font-weight: 500;
}

.sample-stats {
  padding: 12px 16px 16px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.7;
}

.defect-totals {
  margin-top: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.defect-totals h3 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-dim);
  margin-bottom: 8px;
}

.defect-totals-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 12px;
  font-size: 13px;
}

.defect-totals-grid .total-all {
  grid-column: 1 / -1;
  font-weight: 600;
  color: var(--text);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}

.defect-totals-grid .total-all strong {
  color: var(--accent);
  font-size: 15px;
}

.defect-totals-sub {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.batch-summary-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 10px;
  color: var(--accent-dim);
}

.issues-table-wrap { max-height: 200px; overflow-y: auto; margin-top: 8px; }
.issues-table { font-size: 11px; }

/* ── 檢測紀錄查詢（過往批次）── */
.history-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 12px;
}

.history-filters .filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
  margin: 0;
}

.history-filters .filter-field select {
  min-width: 140px;
  max-width: 260px;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.past-batch-summary {
  margin: 0 18px 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  font-size: 12px;
}

.past-batch-summary .summary-title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--accent-dim);
}

.past-batch-summary .summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px 14px;
}

.past-batch-summary .summary-grid span {
  color: var(--text-muted);
}

.past-batch-summary .summary-grid strong {
  margin-left: 6px;
  color: var(--text);
}

/* ── Charts & metrics ── */
.yield-chart { padding: 0 18px 18px; }
.yield-bar {
  height: 10px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.yield-bar.inline { height: 8px; width: 120px; display: inline-block; vertical-align: middle; }

.yield-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--ok-dim), var(--ok));
  border-radius: 999px;
  transition: width 0.6s ease;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 18px;
  font-size: 13px;
  border-top: 1px solid var(--border);
}

.defect-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 12px; }
.defect-bar-row .label { width: 40px; font-weight: 500; }
.defect-bar-row .bar-bg { flex: 1; height: 8px; background: var(--surface2); border-radius: 999px; overflow: hidden; }
.defect-bar-row .bar-fill { height: 100%; border-radius: 999px; transition: width 0.5s ease; }
.defect-bar-row .count { width: 28px; text-align: right; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ── Detail panel ── */
.detail-content { padding: 6px 18px 14px; font-size: 13px; }

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.detail-row span:first-child { color: var(--text-dim); font-size: 12px; }
.detail-row span:last-child { font-weight: 500; text-align: right; }

.defect-tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  margin: 2px;
}

.defect-tag.crack { background: var(--ng-dim); color: var(--ng); }
.defect-center { display: block; font-size: 10px; white-space: nowrap; }
.model-path-row > span:first-child { flex-shrink: 0; white-space: nowrap; }
.model-path-row > span:last-child { min-width: 0; overflow-wrap: anywhere; }
.training-command { overflow-x: auto; padding: 14px; border: 1px solid var(--border); border-radius: 8px; }
.setup-field[hidden], #selectionSection[hidden], #exportSection[hidden] { display: none !important; }
.defect-summary-row { align-items: flex-start; }
.defect-summary-row > span:first-child { flex-shrink: 0; white-space: nowrap; }
.defect-summary-row > span:last-child { min-width: 0; }
.defect-tag.scratch { background: rgba(249, 115, 22, 0.15); color: #fb923c; }
.defect-tag.dent { background: rgba(139, 92, 246, 0.15); color: #a78bfa; }

.judgment-panel {
  padding: 16px 18px;
  border-top: 1px solid var(--border);
  background: linear-gradient(135deg, var(--accent-muted), rgba(245, 158, 11, 0.05));
}

.judgment-panel h3 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--accent-bright);
}

.judgment-reason { font-size: 12px; color: var(--text-dim); line-height: 1.7; margin-bottom: 12px; }

/* 紀錄查詢：上一個／下一個 */
.record-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.record-nav-meta {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.record-nav .btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}
.history-table tbody tr.history-row.is-active td {
  background: var(--accent-muted);
  box-shadow: inset 3px 0 0 var(--accent);
}

/* ── Judgment settings ── */
.settings-form .form-group { margin-bottom: 22px; }
.settings-form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-bottom: 10px; line-height: 1.5; }
.settings-form input[type="number"] { width: 140px; }
.settings-form .unit { margin-left: 8px; font-size: 12px; color: var(--text-dim); }

.checkbox-group { display: flex; gap: 20px; margin-top: 10px; flex-wrap: wrap; }
.checkbox-group label {
  font-weight: 400;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-dim);
}

.checkbox-group input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.rule-explainer .rule-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.rule-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-dim), var(--accent));
  color: var(--on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.rule-preview {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-dim);
}

.reason-cell { font-size: 11px; color: var(--text-muted); max-width: 320px; line-height: 1.5; }

/* ── Analysis charts ── */
.chart-row { display: flex; align-items: center; gap: 10px; font-size: 12px; margin-bottom: 10px; }
.chart-label { width: 68px; text-align: right; color: var(--text-dim); font-weight: 500; }
.chart-bar-bg { flex: 1; height: 16px; background: var(--surface2); border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.chart-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent-dim), var(--accent)); border-radius: 6px; transition: width 0.6s ease; }
.chart-val { width: 40px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.trend-chart { display: flex; align-items: flex-end; gap: 10px; height: 100px; padding-top: 8px; }
.trend-bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.trend-bar .bar {
  width: 100%;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  min-height: 4px;
  transition: height 0.5s ease;
}
.trend-bar .label { font-size: 9px; color: var(--text-muted); font-weight: 500; }

.batch-compare-row {
  display: grid;
  grid-template-columns: 100px 1fr 52px 120px;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.batch-name { font-weight: 600; }

.review-stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.review-stat {
  text-align: center;
  padding: 20px 16px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: border-color var(--transition);
}

.review-stat:hover { border-color: var(--border-strong); }
.review-stat strong { display: block; font-family: var(--font-display); font-size: 28px; font-weight: 700; color: var(--accent); }
.review-stat span { font-size: 11px; color: var(--text-dim); margin-top: 4px; display: block; }

/* ── Alerts & recommendations ── */
.alert-item {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 10px;
  border: 1px solid transparent;
}

.alert-item.high {
  background: var(--ng-dim);
  color: #be123c;
  border-color: rgba(225, 29, 72, 0.2);
  border-left: 3px solid var(--ng);
}

.alert-item.medium {
  background: var(--warn-dim);
  color: #b45309;
  border-color: rgba(217, 119, 6, 0.2);
  border-left: 3px solid var(--warn);
}

.risk-alerts-page { padding: 0 32px 16px; }

.recommendation-card {
  padding: 18px 20px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  transition: transform var(--transition);
}

.recommendation-card:hover { transform: translateX(2px); }
.recommendation-card.warning { border-left-color: var(--warn); }
.recommendation-card.success { border-left-color: var(--ok); }

.rec-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.rec-header h3 { font-size: 14px; font-weight: 600; }

.rec-priority {
  font-size: 10px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--glass);
  color: var(--text-dim);
  font-weight: 600;
  border: 1px solid var(--border);
}

.rec-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; line-height: 1.6; }
.rec-action { font-size: 12px; padding: 12px 14px; background: var(--surface); border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* ── Retrain ── */
.retrain-form { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 18px; }
.retrain-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-dim); font-weight: 500; }

.job-panel {
  margin-top: 14px;
  padding: 18px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.job-progress {
  height: 12px;
  background: var(--surface);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.job-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 999px;
  transition: width 0.5s ease;
}

.btn.is-training {
  opacity: 0.85;
  cursor: wait;
}

.label-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.label-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}

.label-chip:has(input:checked) {
  border-color: var(--accent);
  background: rgba(234, 88, 12, 0.08);
}

.dataset-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.import-label-select {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.import-label-select select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  font-size: 12px;
}

.selection-count {
  font-size: 12px;
  color: var(--text-dim);
  margin-left: auto;
}

.dataset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.dataset-card {
  display: block;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  background: var(--surface2);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.dataset-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.dataset-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.dataset-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: #c5d4e8;
}

.dataset-card-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}

.dataset-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.dataset-actions {
  display: flex;
  justify-content: flex-end;
  padding: 8px 0 24px;
}

.setup-field-wide {
  grid-column: 1 / -1;
}

.summary-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.summary-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.deploy-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.deploy-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-dim);
  margin-bottom: 12px;
}

.deploy-result {
  margin-top: 10px;
  font-size: 13px;
}

a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.home-content { padding-bottom: 32px; }

.home-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 32px;
  margin-bottom: 20px;
}

.home-hero h2 {
  font-family: var(--font-display);
  font-size: 22px;
  margin-bottom: 8px;
}

.home-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-lg {
  padding: 12px 22px;
  font-size: 14px;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.home-card {
  display: block;
  padding: 20px;
  text-decoration: none;
  color: inherit;
  transition: border-color var(--transition), transform var(--transition);
}

.home-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.home-card h3 {
  font-family: var(--font-display);
  font-size: 16px;
  margin-bottom: 8px;
  color: var(--accent-dim);
}

.home-card p {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0;
}

.home-card-admin {
  border-color: rgba(234, 88, 12, 0.35);
}

.admin-settings-grid { margin-bottom: 8px; }

.admin-table code {
  font-size: 11px;
}

.admin-actions {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.admin-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 520px;
  width: calc(100% - 32px);
  background: var(--surface);
  color: var(--text);
}

.admin-dialog h3 {
  margin-bottom: 16px;
  font-family: var(--font-display);
}

.admin-dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* ── Notifications ── */
.notif-summary {
  padding: 14px 32px;
  display: flex;
  gap: 28px;
  font-size: 13px;
  color: var(--text-dim);
}

.notif-summary strong { color: var(--text); font-family: var(--font-display); }

.notif-list {
  padding: 0 32px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.notif-card {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.notif-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.notif-card.unread { border-left: 3px solid var(--accent); }
.notif-card.high { border-left-color: var(--ng); }

.notif-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.notif-icon.alert { background: var(--ng-dim); }
.notif-icon.system { background: var(--accent-muted); }
.notif-icon.inspection { background: rgba(245, 158, 11, 0.12); }

.notif-body { flex: 1; min-width: 0; }
.notif-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.notif-msg { font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.notif-time { font-size: 11px; color: var(--text-muted); margin-top: 8px; }

.unread-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  margin-left: 6px;
  box-shadow: 0 0 6px var(--accent-glow);
}

/* ── Tables ── */
.history-table-wrap { overflow-x: auto; max-height: 340px; scrollbar-width: thin; }

.history-table { width: 100%; border-collapse: collapse; font-size: 12px; }

.history-table th {
  position: sticky;
  top: 0;
  background: var(--surface-solid);
  padding: 12px 14px;
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-strong);
  z-index: 1;
}

.history-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.history-table tbody tr { transition: background var(--transition); cursor: default; }
.history-table tbody tr:hover td { background: var(--glass); }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.04em;
}

.badge.ok { background: var(--ok-dim); color: var(--ok); border: 1px solid rgba(5, 150, 105, 0.25); }
.badge.ng { background: var(--ng-dim); color: var(--ng); border: 1px solid rgba(225, 29, 72, 0.25); }
.badge.test-badge { background: #fef3c7; color: #92400e; border: 1px solid rgba(146, 64, 14, 0.3); margin-left: 4px; }  /* 測試／部署驗證批次 */
.badge.demo-badge { background: #e0e7ff; color: #3730a3; border: 1px solid rgba(55, 48, 163, 0.3); margin-left: 4px; }  /* 示範／樣本紀錄 */

.text-ok { color: var(--ok); }
.text-ng { color: var(--ng); }
.text-warn { color: var(--warn); }
.text-dim { color: var(--text-dim); }
.empty-hint { color: var(--text-muted); font-size: 13px; padding: 16px; text-align: center; }
.hidden { display: none !important; }

#filterResult { flex: none; min-width: auto; padding: 6px 12px; font-size: 11px; }

/* ── Responsive ── */
@media (max-width: 1200px) {
  .setup-grid { grid-template-columns: repeat(2, 1fr); }
  .setup-panel { margin: 0 32px 0; }
  .summary-cards, .stat-cards-4 { grid-template-columns: repeat(2, 1fr); }
  .inspection-grid, .stats-grid, .analysis-grid, .retrain-grid, .judgment-grid { grid-template-columns: 1fr; }
  .inspection-grid .panel-wide, .stats-grid .panel-wide, .analysis-grid .panel-wide,
  .retrain-grid .panel-wide, .judgment-grid .panel-wide, .stat-cards-4 { grid-column: auto; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 68px; }
  .sidebar .brand-title, .sidebar .brand-sub, .sidebar .nav-label,
  .sidebar .nav-section-label, .sidebar-footer span:last-child { display: none; }
  .sidebar-brand { justify-content: center; padding: 16px 8px; }
  .nav-item { justify-content: center; padding: 12px; }
  .nav-badge { right: 4px; top: 4px; }
  .main-area { margin-left: 68px; }
  .page-header, .page-grid, .summary-cards, .notif-list, .risk-alerts-page { padding-left: 16px; padding-right: 16px; }
  .setup-panel { margin: 0 16px; }
  .setup-grid { grid-template-columns: 1fr; }
  .summary-cards { grid-template-columns: 1fr 1fr; }
  .workflow-track { padding: 16px; }
  .wf-step .wf-label { display: none; }
}
