:root {
  --bg: #0e1117;
  --bg-elev: #161b22;
  --bg-card: #1c2330;
  --bg-card-hover: #232b3a;
  --border: #2a3344;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --accent-dim: #1f3a5f;
  --pass: #3fb950;
  --pass-bg: #132d1b;
  --partial: #d29922;
  --partial-bg: #2d2410;
  --fail: #f85149;
  --fail-bg: #2d1517;
  --deprecated: #6e7681;
  --i2v: #a371f7;
  --omni: #39c5cf;
  --radius: 10px;
  --font: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 8px 24px rgba(0,0,0,0.35);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* Top bar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
}

.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.topbar-brand .muted { margin: 2px 0 0; }

.topbar-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover { background: var(--bg-card-hover); border-color: #3d4a63; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b1220;
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 8px; font-size: 12px; }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px 18px 0;
}

.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-n { font-size: 20px; font-weight: 600; font-family: var(--mono); }
.stat-l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat.pass .stat-n { color: var(--pass); }
.stat.partial .stat-n { color: var(--partial); }
.stat.fail .stat-n { color: var(--fail); }

/* Filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filters select {
  min-width: 120px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
}

/* Layout */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr 320px;
  gap: 0;
  min-height: 0;
}

.panel {
  padding: 14px 16px;
  overflow: auto;
  border-right: 1px solid var(--border);
  min-height: 420px;
}

.detail-panel { border-right: none; }

.panel h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.panel h3 {
  margin: 14px 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Batch list */
.batch-list, .previz-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.batch-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  padding: 10px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.batch-item:hover { background: var(--bg-card-hover); }
.batch-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.batch-item.deprecated {
  opacity: 0.45;
  filter: grayscale(0.6);
  cursor: default;
}

.batch-item.deprecated.active {
  opacity: 0.7;
  filter: grayscale(0.3);
}

.batch-id {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  word-break: break-all;
}

.batch-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--mono);
  line-height: 1.5;
}

.badge.route-i2v { background: #2a1f3d; color: var(--i2v); }
.badge.route-omni { background: #0f2d30; color: var(--omni); }
.badge.qc-pass { background: var(--pass-bg); color: var(--pass); }
.badge.qc-partial { background: var(--partial-bg); color: var(--partial); }
.badge.qc-fail { background: var(--fail-bg); color: var(--fail); }
.badge.status-qc_done { background: var(--pass-bg); color: var(--pass); }
.badge.status-deprecated { background: #22262e; color: var(--deprecated); }
.badge.status-running { background: var(--accent-dim); color: var(--accent); }
.badge.cond { background: #22262e; color: var(--text); }

.previz-block { margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--border); }

.previz-list li {
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.previz-list .bug {
  display: block;
  margin-top: 3px;
  color: var(--fail);
  font-size: 11px;
}

/* Jobs */
.jobs-header { margin-bottom: 10px; }
.jobs-header h2 { margin-bottom: 2px; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 15px; }
.jobs-subtitle, #jobs-subtitle { margin: 0; font-size: 12px; }

.job-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.job-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.12s, background 0.12s;
}

.job-card:hover { background: var(--bg-card-hover); border-color: #3d4a63; }
.job-card.active { border-color: var(--accent); }

.job-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 72px;
  margin: -4px -4px 10px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(88,166,255,0.12), rgba(163,113,247,0.10)),
    repeating-linear-gradient(
      -45deg,
      transparent,
      transparent 6px,
      rgba(255,255,255,0.02) 6px,
      rgba(255,255,255,0.02) 12px
    );
  border: 1px dashed var(--border);
  color: var(--accent);
}

.job-thumb.empty {
  color: var(--muted);
  background: var(--bg);
}

.job-thumb-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  font-size: 11px;
  line-height: 1;
  padding-left: 2px;
}

.job-thumb-label {
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.02em;
}

.job-card.active .job-thumb {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(88,166,255,0.25) inset;
}

.detail-video {
  margin: 10px 0 4px;
}

.detail-video video {
  display: block;
  width: 100%;
  max-height: 360px;
  background: #000;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.detail-video-src {
  margin: 6px 0 0;
  font-size: 11px;
  word-break: break-all;
}

.job-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.job-id {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 13px;
}

.job-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }

.job-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin: 3px 0;
}

.job-row .val {
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  text-align: right;
  word-break: break-all;
}

.job-actions {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.qc-notes {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px dashed var(--border);
  padding-top: 6px;
}

.empty-hint {
  color: var(--muted);
  font-size: 13px;
  padding: 24px 8px;
  text-align: center;
}

/* Detail */
.hypo {
  margin: 0;
  padding: 10px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
}

.finding-md {
  margin: 0;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 48vh;
  overflow: auto;
  line-height: 1.55;
  color: #c9d1d9;
}

.next-todo {
  margin: 12px 0 0;
  padding: 8px 10px;
  background: var(--accent-dim);
  border-radius: 8px;
  font-size: 12px;
  color: var(--accent);
}

#job-detail {
  margin-bottom: 16px;
  padding: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
}

#job-detail dl {
  margin: 0;
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 4px 8px;
}

#job-detail dt { color: var(--muted); }
#job-detail dd { margin: 0; font-family: var(--mono); font-size: 11px; word-break: break-all; }

.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 11px;
  color: var(--muted);
}

/* Mobile */
@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .panel {
    min-height: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .batch-panel { max-height: 280px; }
  .detail-panel { max-height: none; }
}

@media (max-width: 520px) {
  .topbar { padding: 10px 12px; }
  .filters, .stats { padding-left: 12px; padding-right: 12px; }
  .filters select { min-width: 100%; }
  .filters label { flex: 1 1 45%; }
}
