:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e3e7ee;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}
button, input, select { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: #0f172a; color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 600; }
.logo { width: 24px; height: 24px; color: #60a5fa; }
.badge { font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: rgba(96,165,250,.18); color: #93c5fd; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(560px, 660px) 1fr;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 56px);
}
.panel, .stage { overflow: auto; min-width: 0; }
.panel { display: flex; flex-direction: column; gap: 16px; }
.stage { display: flex; flex-direction: column; gap: 16px; }
.panel > *, .stage > * { flex-shrink: 0; }

.card, .viewer-card, .result-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card { padding: 16px; }
h2 { margin: 0 0 12px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.step {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
}

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-grid input, .form-grid select {
  height: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); font-size: 14px;
}
input:focus, select:focus { outline: 2px solid rgba(37,99,235,.35); outline-offset: -1px; border-color: var(--primary); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
  cursor: pointer; white-space: nowrap; font-size: 13px;
}
.btn:hover { border-color: #c3cad6; background: #f8fafc; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; height: 36px; padding: 0 20px; }
.btn.primary:hover { background: var(--primary-d); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }

.msg { padding: 8px 12px; border-radius: 6px; margin-bottom: 10px; font-size: 13px; background: #eff6ff; color: #1e40af; }
.msg.error { background: #fef2f2; color: #991b1b; }
.msg.warn { background: #fffbeb; color: #92400e; }
.msg.ok { background: #f0fdf4; color: #166534; }

/* ---------- item table ---------- */
.table-wrap { overflow: auto; max-height: calc(100vh - 470px); min-height: 160px; border: 1px solid var(--line); border-radius: 8px; }
table.items { width: 100%; border-collapse: collapse; font-size: 13px; }
table.items th {
  position: sticky; top: 0; z-index: 1;
  background: #f8fafc; color: var(--muted); font-weight: 500; text-align: left;
  padding: 6px 4px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.items td { padding: 3px 4px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
table.items tr:last-child td { border-bottom: 0; }
table.items input[type=text], table.items input[type=number] {
  width: 100%; height: 28px; padding: 0 6px;
  border: 1px solid transparent; border-radius: 4px; background: transparent;
}
table.items input:hover { border-color: var(--line); }
table.items input:focus { background: #fff; }
table.items .in-id { min-width: 78px; }
table.items .in-num { width: 62px; text-align: right; }
table.items input.missing { background: #fef2f2; border-color: #fecaca; }
table.items input.est { background: #fffbeb; border-color: #fde68a; }
.th-check { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
td.c { text-align: center; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.check { font-size: 12px; white-space: nowrap; }
.check .ok { color: var(--ok); }
.check .warn { color: var(--warn); }
.check .err { color: var(--err); }
.icon { border: 0; background: transparent; cursor: pointer; color: #9ca3af; font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 4px; }
.icon:hover { color: var(--err); background: #fef2f2; }
.empty-list { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.8; }

.totals { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.totals b { color: var(--text); }

/* ---------- viewer ---------- */
.viewer-card { display: flex; flex-direction: column; overflow: hidden; }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs, .views { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 28px; padding: 0 10px; border: 1px solid var(--line); border-radius: 999px; background: #fff; cursor: pointer; font-size: 12px; }
.chip:hover { background: #f1f5f9; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.viewer { position: relative; height: 56vh; min-height: 340px; background: #f2f4f7; }
.viewer canvas { display: block; }
.viewer-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); text-align: center; padding: 20px; z-index: 1; pointer-events: none; }
.tooltip { position: absolute; display: none; pointer-events: none; z-index: 2; background: rgba(15,23,42,.92); color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 12px; line-height: 1.6; max-width: 240px; }
.stepper { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-top: 1px solid var(--line); }
.stepper input[type=range] { flex: 1; accent-color: var(--primary); }
.step-label { font-size: 12px; color: var(--muted); min-width: 210px; text-align: right; }

/* ---------- results ---------- */
.results { display: flex; flex-direction: column; gap: 12px; }
.result-card { padding: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 600; margin-top: 2px; }
.stat .s { font-size: 12px; color: var(--muted); }
.bar { height: 6px; border-radius: 3px; background: #e5e7eb; margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); }
.bar.warn > i { background: var(--warn); }
.bar.err > i { background: var(--err); }

.result-card h3 { margin: 0 0 10px; font-size: 15px; }
table.simple { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 12px; }
table.simple th, table.simple td { padding: 6px 8px; border-bottom: 1px solid #f0f2f5; text-align: left; }
table.simple th { color: var(--muted); font-weight: 500; background: #f8fafc; }
table.simple td.n, table.simple th.n { text-align: right; }
details { margin-top: 12px; }
summary { cursor: pointer; font-weight: 500; color: var(--primary); }
ol.steps { margin: 8px 0 0; padding-left: 22px; font-size: 13px; }
ol.steps li { padding: 3px 0; }
ol.steps li .meta { color: var(--muted); }

.form-grid input, .form-grid select { width: 100%; min-width: 0; }
table.items { min-width: 600px; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 1fr); height: auto; }
  .panel, .stage { overflow: visible; }
  .table-wrap { max-height: 420px; }
  .viewer { height: 440px; }
}
@media (max-width: 640px) {
  .layout { padding: 10px; gap: 10px; }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: 0 12px; }
  .badge { display: none; }
  .step-label { min-width: 0; }
}
