:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e4e9f0;
  --border-strong: #cfd8e3;
  --text: #0e1726;
  --text-2: #334155;
  --muted: #6b7a90;
  --accent: #1d4ed8;
  --accent-2: #2563eb;
  --accent-soft: #eef3ff;
  --accent-line: #c7d6fe;
  --ok: #047857;
  --ok-soft: #ecfdf5;
  --ok-line: #a7f3d0;
  --bad: #b91c1c;
  --bad-2: #dc2626;
  --bad-soft: #fef2f2;
  --bad-line: #fecaca;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --warn-line: #fde68a;
  --die-ok: #cdd6e2;
  --die-fail: #dc2626;
  --wafer-bg: #f3f6fa;
  --wafer-edge: #b6c2d1;
  --side: #0b1324;
  --side-2: #121c31;
  --side-text: #a9b6cc;
  --shadow-sm: 0 1px 2px rgba(14, 23, 38, .05);
  --shadow: 0 1px 2px rgba(14, 23, 38, .04), 0 2px 8px rgba(14, 23, 38, .05);
  --radius: 10px;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0f1a;
    --surface: #111827;
    --surface-2: #0f1522;
    --surface-3: #172033;
    --border: #1e293b;
    --border-strong: #2b3a52;
    --text: #e6ebf2;
    --text-2: #c3cddb;
    --muted: #8a99b0;
    --accent: #6c9bff;
    --accent-2: #3b74f0;
    --accent-soft: #141f3a;
    --accent-line: #233a6e;
    --ok: #34d399;
    --ok-soft: #0b2a22;
    --ok-line: #14532d;
    --bad: #f87171;
    --bad-2: #ef4444;
    --bad-soft: #2a1215;
    --bad-line: #5b1d22;
    --warn: #fbbf24;
    --warn-soft: #2a2010;
    --warn-line: #5a4312;
    --die-ok: #2e3c52;
    --die-fail: #f43f5e;
    --wafer-bg: #0d1424;
    --wafer-edge: #3a4a63;
    --side: #070c17;
    --side-2: #0e1628;
    --shadow-sm: none;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.55 Inter, "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; letter-spacing: -.015em; }
h1 { font-size: 22px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 600; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
em { font-style: normal; color: var(--muted); font-weight: 400; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--side); color: var(--side-text);
  display: flex; flex-direction: column; padding: 18px 14px;
  border-right: 1px solid rgba(255, 255, 255, .04);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 22px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #2563eb, #1e40af); display: grid; place-items: center; color: #fff; box-shadow: 0 4px 14px rgba(37, 99, 235, .35); }
.brand-mark svg { width: 20px; height: 20px; stroke-width: 1.5; }
.brand-name { color: #fff; font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { font-size: 11px; color: #7083a3; letter-spacing: .02em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #5b6c89; font-weight: 600; padding: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; color: var(--side-text); font: inherit; font-weight: 500; text-align: left;
  padding: 8px 10px; border-radius: 7px; cursor: pointer;
}
.nav-item:hover { background: var(--side-2); color: #fff; }
.nav-item.active { background: rgba(59, 116, 240, .16); color: #fff; box-shadow: inset 2px 0 0 #3b82f6; }
.nav-item svg { width: 17px; height: 17px; opacity: .9; }
.main { padding: 26px 32px 56px; max-width: 1480px; width: 100%; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.page-h { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.crumb { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 2px; }
.page-sub { margin: 4px 0 0; color: var(--muted); max-width: 720px; }
.page-actions { display: flex; gap: 10px; align-items: center; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-h.pad { padding: 16px 20px 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.grid-2-1 { display: grid; grid-template-columns: minmax(0, 2.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-2 > .card, .grid-2 > .col { margin-bottom: 16px; }
.col > .card:last-child { margin-bottom: 0; }
.col { display: flex; flex-direction: column; gap: 16px; }
.col > .card { margin-bottom: 0; }

/* ---------- controls ---------- */
.toolbar { display: flex; align-items: flex-end; gap: 18px; flex-wrap: wrap; padding: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-2); font-weight: 500; }
.field.grow { flex: 1; min-width: 200px; }
.field-info { font-size: 12px; color: var(--muted); padding-bottom: 9px; }
.src-fields { display: flex; gap: 14px; align-items: flex-end; }
select, input[type="text"], input[type="number"] {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 7px; padding: 7px 10px; min-width: 150px; height: 36px;
}
select:hover, input[type="text"]:hover, input[type="number"]:hover { border-color: var(--muted); }
select:focus, input:focus { outline: 3px solid var(--accent-line); border-color: var(--accent-2); outline-offset: 0; }
.upload {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; cursor: pointer;
  border: 1px dashed var(--border-strong); border-radius: 7px; color: var(--text-2); font-size: 13px; max-width: 320px;
}
.upload:hover { border-color: var(--accent-2); color: var(--accent); }
.upload input { display: none; }
.upload span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toggles { display: flex; gap: 16px; padding-bottom: 8px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; user-select: none; padding-bottom: 8px; }
.toggles .switch { padding-bottom: 0; }
.switch input { display: none; }
.switch span { width: 30px; height: 17px; border-radius: 999px; background: var(--border-strong); position: relative; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + span { background: var(--accent-2); }
.switch input:checked + span::after { transform: translateX(13px); }
.seg { display: inline-flex; background: var(--surface-3); border-radius: 8px; padding: 3px; height: 36px; }
.seg button { font: inherit; font-size: 13px; font-weight: 500; border: 0; background: none; color: var(--muted); padding: 0 13px; border-radius: 6px; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px;
  font: inherit; font-weight: 500; font-size: 13px; cursor: pointer; white-space: nowrap;
  padding: 0 14px; border-radius: 7px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; margin-left: auto; box-shadow: 0 1px 2px rgba(29, 78, 216, .3); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn.primary svg { width: 13px; height: 13px; }
.btn.ok { color: var(--ok); }
.btn.ok:hover { background: var(--ok-soft); border-color: var(--ok); }
.btn.bad { color: var(--bad); }
.btn.bad:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: default; pointer-events: none; }

/* ---------- empty / loading / toast ---------- */
.empty { text-align: center; padding: 80px 24px; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); }
.empty-icon { width: 52px; height: 52px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin: 0 auto; }
.empty-icon svg { width: 26px; height: 26px; stroke-width: 1.5; }
.empty h2 { color: var(--text); font-size: 16px; font-weight: 600; margin: 14px 0 6px; }
.empty p { max-width: 520px; margin: 0 auto; }
.loading { position: fixed; inset: 0; background: rgba(8, 13, 24, .38); display: grid; place-items: center; z-index: 50; backdrop-filter: blur(3px); }
.loading-box { background: var(--surface); padding: 20px 24px; border-radius: 12px; display: flex; align-items: center; gap: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); min-width: 320px; border: 1px solid var(--border); }
.loading-title { font-weight: 600; }
.spinner { width: 24px; height: 24px; border-radius: 50%; border: 2.5px solid var(--accent-line); border-top-color: var(--accent-2); animation: spin .75s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; bottom: 22px; right: 22px; z-index: 60; max-width: min(460px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); border: 1px solid var(--bad-line); border-left: 4px solid var(--bad-2);
  padding: 12px 16px; border-radius: 8px; box-shadow: 0 12px 30px rgba(0, 0, 0, .15);
}
.toast.info { border-color: var(--border); border-left-color: var(--accent-2); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-height: 96px; }
.kpi .lbl { font-size: 12px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.bad .val { color: var(--bad); }
.kpi.ok .val { color: var(--ok); }
.kpi.warn .val { color: var(--warn); }
.skeleton { background: linear-gradient(90deg, var(--surface) 0%, var(--surface-3) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- status chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 1px solid; white-space: nowrap; }
.chip svg { width: 13px; height: 13px; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.chip.info { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.chip.neutral { background: var(--surface-3); color: var(--text-2); border-color: var(--border); }
.tag { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 5px; }
.cls { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.cls i { width: 8px; height: 8px; border-radius: 2px; flex: none; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
.data th { text-align: left; font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.data td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data tbody tr:last-child td { border-bottom: 0; }
.data tbody tr.click { cursor: pointer; }
.data tbody tr.click:hover td { background: var(--surface-2); }
.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.data .lot-id { font-weight: 600; }
td.empty-row { text-align: center; color: var(--muted); padding: 36px; }
.data td { white-space: nowrap; }
.data .seq-col { width: 34%; }
.seq { display: flex; gap: 1.5px; min-width: 220px; }
.grid-2.align-start { align-items: start; }
.alerts { display: flex; flex-direction: column; gap: 10px; }
.alert-item { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); cursor: pointer; }
.alert-item:hover { border-color: var(--bad-line); background: var(--bad-soft); }
.alert-item .drift-icon { width: 36px; height: 36px; }
.alert-item .a-t { font-weight: 600; }
.alert-item .a-s { font-size: 12px; color: var(--muted); }
.alerts-empty { display: flex; align-items: center; gap: 10px; color: var(--ok); font-weight: 500; padding: 12px; border-radius: 9px; background: var(--ok-soft); border: 1px solid var(--ok-line); }
.seq span { flex: 1; height: 16px; border-radius: 2px; position: relative; }
.seq span.alarm::after { content: ""; position: absolute; left: 0; right: 0; bottom: -5px; height: 2px; background: var(--bad-2); border-radius: 1px; }
.bar-mini { display: inline-block; width: 54px; height: 5px; border-radius: 3px; background: var(--surface-3); vertical-align: middle; margin-left: 8px; overflow: hidden; }
.bar-mini > b { display: block; height: 100%; background: var(--bad-2); }

/* ---------- distribution ---------- */
.dist { display: flex; flex-direction: column; gap: 11px; }
.dist-row { display: grid; grid-template-columns: 96px 1fr 38px; align-items: center; gap: 10px; font-size: 13px; }
.dist-bar { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.dist-bar > b { display: block; height: 100%; border-radius: 4px; }
.dist-row .n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- inspection ---------- */
.report-meta { display: flex; flex-wrap: wrap; gap: 6px 28px; padding: 12px 18px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font-size: 12px; color: var(--muted); }
.report-meta b { color: var(--text); font-weight: 600; margin-left: 6px; }
.verdict { display: flex; flex-direction: column; gap: 14px; position: relative; overflow: hidden; }
.verdict::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent-2); }
.verdict.defect::before { background: var(--bad-2); }
.verdict.clean::before { background: var(--ok); }
.verdict.unknown::before { background: var(--warn); }
.v-top { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.v-eyebrow { font-size: 12px; color: var(--muted); font-weight: 500; }
.v-class { font-size: 30px; font-weight: 700; letter-spacing: -.025em; display: flex; align-items: center; gap: 10px; line-height: 1.2; margin-top: 2px; }
.v-class i { width: 12px; height: 12px; border-radius: 3px; }
.v-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.gauge { position: relative; width: 104px; height: 104px; flex: none; }
.gauge svg { width: 104px; height: 104px; transform: rotate(-90deg); }
.gauge .g-val { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.gauge .g-val b { font-size: 18px; font-weight: 700; letter-spacing: -.02em; display: block; line-height: 1.1; }
.gauge .g-val span { font-size: 10px; color: var(--muted); }
.v-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; border-top: 1px solid var(--border); padding-top: 12px; margin-top: auto; }
.v-facts div { font-size: 12px; color: var(--muted); }
.v-facts b { display: block; color: var(--text); font-size: 14px; font-weight: 600; margin-top: 1px; }

.decision { display: flex; flex-direction: column; gap: 14px; }
.reco { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 8px; border: 1px solid; }
.reco svg { width: 26px; height: 26px; stroke-width: 1.6; }
.reco .r-t { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.reco .r-s { font-size: 12px; opacity: .85; }
.reco.stop { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }
.reco.go { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.cost-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cost-box { padding: 12px 14px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); }
.cost-box.lower { border-color: var(--accent-line); background: var(--accent-soft); }
.cost-box .lbl { font-size: 12px; color: var(--muted); font-weight: 500; }
.cost-box .val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.cost-box .formula { font-size: 11.5px; color: var(--muted); }
.cost-box .lower-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); margin-left: 6px; }
.pbar { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.pbar .track { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.pbar .track b { display: block; height: 100%; background: var(--bad-2); border-radius: 3px; }
.pbar strong { color: var(--text); font-variant-numeric: tabular-nums; }

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); align-items: center; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.lg-ok { background: var(--die-ok); }
.lg-fail { background: var(--die-fail); }
.lg-alarm { border: 2px solid var(--bad-2); background: var(--bad-soft); }
.maps { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.maps figure { margin: 0; text-align: center; }
.maps figcaption { font-size: 12px; color: var(--muted); margin-top: 8px; }
.wafer-lg { width: 100%; max-width: 300px; aspect-ratio: 1; display: block; margin: 0 auto; border-radius: 8px; image-rendering: pixelated; object-fit: contain; }
canvas.wafer-lg { background: var(--wafer-bg); }
img.wafer-lg { background: #000; }

.drift-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.drift-icon { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.drift-icon svg { width: 19px; height: 19px; }
.drift-icon.bad { background: var(--bad-soft); color: var(--bad); }
.drift-icon.ok { background: var(--ok-soft); color: var(--ok); }
.drift-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.window { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.window .w { text-align: center; padding: 8px 4px; border-radius: 7px; font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.window .w.hit { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }
.window .w.cur { box-shadow: 0 0 0 2px var(--accent-line); }
.window .w small { display: block; font-size: 10px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }

.explanation { margin: 0 0 14px; color: var(--text-2); line-height: 1.65; }
.action { background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: 8px; padding: 11px 14px; font-weight: 500; }
.action-h { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); margin-bottom: 3px; font-weight: 700; }
.refs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.ref { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 9px; border: 1px solid var(--border); border-radius: 6px; color: var(--text-2); background: var(--surface-2); }
.ref svg { width: 13px; height: 13px; color: var(--muted); }

.similar { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.sim { border: 1px solid var(--border); border-radius: 9px; padding: 8px; background: var(--surface-2); }
.sim canvas { width: 100%; aspect-ratio: 1; background: var(--wafer-bg); border-radius: 6px; display: block; }
.sim-row { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; font-size: 12px; }
.sim-p { font-weight: 700; font-variant-numeric: tabular-nums; }
.sim-id { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 1px; }

.sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 22px; }
.sliders label { font-size: 12px; color: var(--muted); font-weight: 500; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px; }
.sliders output { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.sliders input { width: 100%; accent-color: var(--accent-2); margin: 2px 0 0; }

.fb-note { margin: -6px 0 12px; }
.fb-row { display: flex; gap: 8px; flex-wrap: wrap; }
.fb-wrong { display: flex; gap: 12px; align-items: flex-end; margin-top: 14px; flex-wrap: wrap; }
.fb-wrong .btn.primary { margin-left: 0; }
.fb-done { margin-top: 12px; padding: 9px 12px; border-radius: 7px; background: var(--ok-soft); color: var(--ok); font-weight: 500; border: 1px solid var(--ok-line); }

/* ---------- lot monitor ---------- */
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; stroke: none; fill: initial; overflow: visible; }
.chart .ax { font: 11px Inter, system-ui, sans-serif; fill: var(--muted); }
.chart .grid-l { stroke: var(--border); stroke-width: 1; }
.chart .bar { cursor: pointer; transition: opacity .1s; }
.chart .bar:hover { opacity: .75; }
.chart .alarm-zone { fill: var(--bad-soft); }
.chart .alarm-line { stroke: var(--bad-2); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart .alarm-lbl { font: 600 11px Inter, system-ui, sans-serif; fill: var(--bad); }
.lot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
.tile { border: 1px solid var(--border); border-radius: 9px; padding: 7px; cursor: pointer; background: var(--surface-2); position: relative; transition: border-color .12s, box-shadow .12s; }
.tile:hover { border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-line); }
.tile canvas { width: 100%; aspect-ratio: 1; background: var(--wafer-bg); border-radius: 5px; display: block; }
.tile .t-idx { position: absolute; top: 11px; left: 11px; font-size: 10px; font-weight: 700; background: var(--surface); padding: 0 5px; border-radius: 4px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tile .t-cls { font-size: 12px; margin-top: 6px; }
.tile .t-conf { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; display: flex; justify-content: space-between; }
.tile.alarm { border-color: var(--bad-2); background: var(--bad-soft); }
.tile.first::after { content: "FIRST ALARM"; position: absolute; top: -8px; right: 6px; font-size: 9.5px; font-weight: 700; letter-spacing: .04em; background: var(--bad-2); color: #fff; padding: 1px 6px; border-radius: 4px; }
.alarm-grid { display: grid; grid-template-columns: 210px minmax(0, 1fr) minmax(0, 280px); gap: 20px; align-items: start; }
.alarm-grid img, .alarm-grid canvas { width: 100%; border-radius: 8px; background: #000; image-rendering: pixelated; display: block; }
.alarm-side { display: flex; flex-direction: column; gap: 10px; }
.alarm-side .cost-compare { grid-template-columns: 1fr; gap: 8px; }
.alarm-side .cost-box .val { font-size: 19px; }

/* ---------- upload ---------- */
.nav-count { margin-left: auto; font-size: 11px; font-weight: 600; background: rgba(59, 116, 240, .25); color: #cfe0ff; padding: 0 7px; border-radius: 999px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; cursor: pointer;
  padding: 36px 20px; border: 1.5px dashed var(--border-strong); background: var(--surface-2); transition: border-color .12s, background .12s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent-2); background: var(--accent-soft); }
.dropzone input { display: none; }
.dz-icon { width: 48px; height: 48px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 4px; }
.dropzone.over .dz-icon { background: var(--accent-2); color: #fff; }
.dz-icon svg { width: 24px; height: 24px; }
.dz-title { font-size: 15px; font-weight: 600; }
.dz-sub { font-size: 12px; color: var(--muted); }
.dz-formats { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.link { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
a { color: var(--accent); }
.formats { padding: 0; }
.formats summary { list-style: none; cursor: pointer; padding: 14px 20px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; }
.formats summary::-webkit-details-marker { display: none; }
.formats summary h3::before { content: "▸"; display: inline-block; width: 14px; color: var(--muted); transition: transform .12s; }
.formats[open] summary h3::before { transform: rotate(90deg); }
.fmt-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; padding: 4px 20px 6px; }
.fmt-grid b { font-size: 13px; }
.fmt-grid p { margin: 4px 0 0; font-size: 12.5px; color: var(--text-2); }
code { font-family: var(--mono); font-size: 11.5px; background: var(--surface-3); padding: 1px 5px; border-radius: 4px; word-break: break-word; }
.fmt-dl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 20px 16px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--border); margin-top: 10px; }
.fmt-dl .btn { text-decoration: none; }
.u-errors { border-color: var(--bad-line); background: var(--bad-soft); padding: 12px 16px; }
.u-errors h3 { color: var(--bad); display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.u-errors ul { margin: 0; padding-left: 22px; font-size: 13px; }
.u-errors li b { font-family: var(--mono); font-size: 12px; }
.u-count { padding-bottom: 8px; font-size: 13px; color: var(--text-2); display: flex; flex-direction: column; }
.u-count b { font-size: 20px; color: var(--text); margin-right: 4px; }
.up-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 12px; }
.up-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; position: relative; }
.up-card.warn { border-color: var(--warn-line); }
.up-card canvas { width: 100%; aspect-ratio: 1; background: var(--wafer-bg); border-radius: 7px; display: block; }
.up-card .u-id { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-card .u-meta { font-size: 11.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.up-card .u-warn { font-size: 11.5px; color: var(--warn); background: var(--warn-soft); border-radius: 6px; padding: 5px 7px; line-height: 1.4; }
.up-card .u-actions { display: flex; gap: 6px; margin-top: auto; }
.up-card .u-actions .btn { flex: 1; }
.up-card .u-x { position: absolute; top: 14px; right: 14px; width: 24px; height: 24px; border-radius: 6px; border: 0; background: var(--surface); color: var(--muted); cursor: pointer; display: grid; place-items: center; box-shadow: var(--shadow-sm); }
.up-card .u-x:hover { color: var(--bad); }
.up-card .u-x svg { width: 14px; height: 14px; }
.up-card .u-idx { position: absolute; top: 14px; left: 14px; font-size: 10px; font-weight: 700; background: var(--surface); padding: 0 5px; border-radius: 4px; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .grid-2-1 { grid-template-columns: 1fr; }
  .alarm-grid { grid-template-columns: 180px minmax(0, 1fr); }
  .alarm-side { grid-column: 1 / -1; }
}
@media (max-width: 1000px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: sticky; z-index: 20; height: auto; flex-direction: row; align-items: center; padding: 10px 16px; gap: 8px; overflow-x: auto; }
  .brand { padding: 0 8px 0 0; }
  .brand-sub, .nav-label { display: none; }
  .nav { flex-direction: row; }
  .nav-item { white-space: nowrap; }
  .nav-item.active { box-shadow: inset 0 -2px 0 #3b82f6; }
  .main { padding: 20px 16px 48px; }
  .grid-2 { grid-template-columns: 1fr; gap: 0; }
  .fmt-grid { grid-template-columns: 1fr 1fr; }
  .nav-count { margin-left: 6px; }
}
@media (max-width: 680px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpis-3 { grid-template-columns: 1fr; }
  .similar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sliders, .cost-compare, .maps, .alarm-grid, .fmt-grid { grid-template-columns: 1fr; }
  .up-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .src-fields { flex-wrap: wrap; }
  .btn.primary { margin-left: 0; width: 100%; }
  .v-class { font-size: 24px; }
  .v-facts { grid-template-columns: 1fr 1fr; }
  .brand-name { display: none; }
  h1 { font-size: 20px; }
}

/* ---------- print (Export report) ---------- */
@media print {
  :root { --bg: #fff; }
  body { background: #fff; }
  .sidebar, .toolbar, .page-actions, .no-print, .toast, .loading, #a-empty { display: none !important; }
  .app { display: block; }
  .main { padding: 0; max-width: none; }
  .view:not(.active) { display: none !important; }
  .card, .kpi, .report-meta { box-shadow: none; break-inside: avoid; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
}
