:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #dfe4ea;
  --text: #18202a;
  --muted: #6a7583;
  --ok: #15805f;
  --warn: #b86b00;
  --alert: #c93636;
  --blue: #246b9f;
  --teal: #168174;
  --shadow: 0 1px 2px rgba(18, 25, 38, 0.08), 0 8px 24px rgba(18, 25, 38, 0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.topbar {
  min-height: 72px;
  padding: 14px 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

h1, h2, p { margin: 0; }
h1 { font-size: 21px; font-weight: 700; }
h2 { font-size: 15px; font-weight: 700; }
#subtitle { margin-top: 4px; color: var(--muted); font-size: 13px; }

.status-strip { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f4f7f6;
  color: var(--ok);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
.pill.warn { background: #fff6e8; border-color: #f0c982; color: var(--warn); }
.pill.alert { background: #fff0f0; border-color: #eda7a7; color: var(--alert); }
.pill.offline { background: #eef1f4; color: #596574; }
.pill.unscored { background: #eef1f4; color: #596574; }
.explorer-controls { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; margin-bottom: 12px; }
.explorer-controls label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; min-width: 150px; flex: 1; }
.explorer-controls select, .explorer-controls button { padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); font: inherit; }
.explorer-controls button { background: #eaf3fb; color: #174c72; cursor: pointer; flex: 0 0 auto; }
.explorer-controls button:disabled { opacity: .5; cursor: wait; }
.range-summary { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.range-summary .kv { min-height: 62px; }
.range-track { height: 24px; position: relative; background: #edf1f5; border-radius: 5px; margin: 20px 4px 8px; }
.range-band { position: absolute; top: 0; bottom: 0; background: #a9d5f0; border-radius: 4px; }
.range-marker { position: absolute; top: -5px; width: 3px; height: 34px; background: #b82323; }
.source-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; margin-top: 10px; }
.source-card { border: 1px solid var(--line); border-radius: 6px; padding: 9px; overflow-wrap: anywhere; font-size: 12px; }
.source-card b { display: block; margin-bottom: 5px; }
.source-card button { margin-top: 7px; border: 1px solid var(--line); background: #f3f7fa; border-radius: 5px; padding: 5px 8px; cursor: pointer; }
.training-preview { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.training-preview img { max-width: 480px; max-height: 300px; display: none; border-radius: 6px; }
.training-preview img[src] { display: block; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--muted); font-size: 12px; }
.micro { color: var(--muted); font-size: 12px; }

.layout { padding: 18px 24px 32px; display: grid; gap: 18px; }
.hero-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.main-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; align-items: stretch; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }

.camera-panel img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #111820;
  border-radius: 6px;
  border: 1px solid #101820;
}
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.metric-grid.small { grid-template-columns: repeat(4, minmax(82px, 1fr)); }
.kv { border: 1px solid var(--line); border-radius: 6px; padding: 8px; min-height: 54px; }
.kv b { display: block; font-size: 16px; line-height: 1.2; }
.kv span { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }


.feature-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.feature-card { border: 1px solid var(--line); border-radius: 6px; padding: 9px; background: #fff; min-width: 0; }
.feature-card.missing { background: #fffaf1; }
.feature-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; font-size: 12px; }
.feature-title span { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--muted); }
.feature-card img, .empty-preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  object-fit: contain;
  background: #111820;
  color: #a8b3bf;
  border: 1px solid #101820;
  border-radius: 6px;
  font-size: 12px;
}
.feature-card .micro { margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vision-panel { padding-bottom: 16px; }
.vision-grid { display: grid; grid-template-columns: repeat(5, minmax(180px, 1fr)); gap: 10px; }
.vision-card { border: 1px solid var(--line); border-left: 4px solid var(--ok); border-radius: 6px; padding: 8px; background: #fff; min-width: 0; }
.vision-card.warn { border-left-color: var(--warn); background: #fffaf1; }
.vision-card.alert { border-left-color: var(--alert); background: #fff6f6; }
.vision-card.offline { border-left-color: #b8c0ca; }
.vision-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 7px; font-size: 12px; }
.vision-head span { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: nowrap; }
.vision-card canvas { width: 100%; height: auto; display: block; border: 1px solid var(--line); border-radius: 6px; background: #fbfcfd; }

.metric-list { display: grid; gap: 8px; }
.metric-row {
  border: 1px solid var(--line);
  border-left: 4px solid var(--ok);
  border-radius: 6px;
  padding: 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.metric-row.warn { border-left-color: var(--warn); background: #fffaf1; }
.metric-row.alert { border-left-color: var(--alert); background: #fff6f6; }
.metric-title { font-weight: 700; font-size: 13px; }
.metric-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.metric-value { text-align: right; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--muted); }

.chart-panel canvas, .position-panel canvas { width: 100%; height: auto; display: block; border: 1px solid var(--line); border-radius: 6px; background: #fbfcfd; }
.joints-panel { grid-column: 1 / -1; }
.joint-bars { display: grid; gap: 10px; }
.joint-row { display: grid; grid-template-columns: 174px minmax(0, 1fr) 76px; gap: 10px; align-items: center; font-size: 12px; }
.joint-name { color: var(--muted); min-width: 0; }
.joint-name b {
  display: block;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.1;
}
.joint-name span {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
}
.joint-range {
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: linear-gradient(90deg, #eef2f5 0%, #f8fafb 50%, #eef2f5 100%);
  position: relative;
  overflow: visible;
}
.joint-common {
  position: absolute;
  top: 6px;
  bottom: 6px;
  border-radius: 999px;
  background: rgba(22, 129, 116, 0.22);
}
.joint-median {
  position: absolute;
  top: 5px;
  bottom: 5px;
  width: 2px;
  background: rgba(24, 32, 42, 0.32);
}
.joint-dot {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: var(--alert);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(18, 25, 38, 0.24), 0 2px 8px rgba(18, 25, 38, 0.22);
}
.joint-dot.ok { background: var(--alert); }
.joint-dot.warn { background: var(--alert); }
.joint-dot.alert { background: var(--alert); width: 14px; height: 14px; }
.joint-row.warn .joint-name { color: #94620d; }
.joint-row.alert .joint-name { color: var(--alert); font-weight: 700; }
.joint-row.warn .joint-name b { color: #94620d; }
.joint-row.alert .joint-name b { color: var(--alert); }
.joint-axis-labels {
  position: absolute;
  left: 9px;
  right: 9px;
  bottom: 1px;
  display: flex;
  justify-content: space-between;
  color: #8993a0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 9px;
  pointer-events: none;
}
.joint-reading { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; text-align: right; color: var(--muted); line-height: 1.25; }
.joint-reading b { display: block; color: var(--text); font-size: 12px; }
.joint-reading span { display: block; font-size: 10px; }

.baseline-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.baseline-item { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; }
.baseline-item img { width: 100%; display: block; aspect-ratio: 4 / 3; object-fit: cover; background: #f0f2f4; }
.baseline-item div { padding: 8px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 1200px) {
  .vision-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .feature-panel { grid-column: span 2; }
}

@media (max-width: 980px) {
  .hero-grid, .main-grid, .baseline-grid, .vision-grid { grid-template-columns: 1fr; }
  .feature-panel { grid-column: auto; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .status-strip { justify-content: flex-start; }
  .metric-grid.small, .feature-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .layout { padding: 12px; }
  .feature-grid { grid-template-columns: 1fr; }
  .joint-row { grid-template-columns: 92px minmax(0, 1fr); }
  .joint-reading { grid-column: 2; text-align: left; }
}
