:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111418;
  color: #f2f5f8;
}

html {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
}

body.labelerPage {
  height: 100vh;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 72px;
  padding: 12px 20px;
  border-bottom: 1px solid #2b323b;
  background: #161a20;
}

h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
}

p {
  margin: 4px 0 0;
  color: #9ea9b5;
  font-size: 12px;
}

.stats {
  display: flex;
  gap: 10px;
  align-items: center;
  color: #c7d0d9;
  font-size: 13px;
}

.stats span {
  border: 1px solid #303944;
  border-radius: 6px;
  padding: 6px 8px;
  background: #1d232b;
}

.stats .saveState {
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.stats .saveState.saved {
  border-color: #16835f;
  background: #0b3f31;
  color: #9af0d2;
}

.stats .saveState.unsaved {
  border-color: #9a6a16;
  background: #3d2e0b;
  color: #ffdc73;
}

.stats .saveState.saving {
  border-color: #2d7da8;
  background: #12364b;
  color: #9edcff;
}

.stats .saveState.saveError {
  border-color: #a23d45;
  background: #461c21;
  color: #ffb3ba;
}

.stats .reviewBadge,
.reviewStatusBanner {
  border-radius: 6px;
  font-weight: 800;
  letter-spacing: 0;
}

.reviewBadge.reviewed,
.reviewStatusBanner.reviewed {
  border-color: #16835f;
  background: #0b3f31;
  color: #9af0d2;
}

.reviewBadge.unreviewed,
.reviewStatusBanner.unreviewed {
  border-color: #8b5b1c;
  background: #3d2a0b;
  color: #ffd166;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  height: calc(100vh - 72px);
  overflow: hidden;
}

.viewer {
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 16px;
  background: #0d1014;
}

.stereoViewer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  overflow: hidden;
  padding: 12px;
  background: #0d1014;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#frameImage,
#leftImage,
#rightImage {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  transform: translate(var(--image-pan-x, 0px), var(--image-pan-y, 0px)) scale(var(--image-zoom, 1));
  transform-origin: center center;
  will-change: transform;
}

.stage.panning {
  cursor: grabbing;
}

.stereoStage {
  border: 1px solid #27313c;
  background: #07090c;
}

.stereoStage.activeSide {
  border-color: #00b887;
  box-shadow: inset 0 0 0 1px #00b887;
}

.sideTitle {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 4;
  border: 1px solid #303944;
  border-radius: 6px;
  padding: 4px 8px;
  background: rgba(13, 16, 20, 0.86);
  color: #f2f5f8;
  font-size: 12px;
  font-weight: 700;
}

.marker {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2px solid #00e0a4;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 0 0 2px #06110e, 0 0 14px #00e0a4;
  z-index: 3;
}

.marker::before,
.marker::after {
  content: "";
  position: absolute;
  background: #00e0a4;
}

.marker::before {
  left: 50%;
  top: -8px;
  width: 2px;
  height: 36px;
}

.marker::after {
  top: 50%;
  left: -8px;
  width: 36px;
  height: 2px;
}

.hidden {
  display: none;
}

.candidateLayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 2;
}

.labelLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.candidateBox {
  position: absolute;
  border: 1px solid #ffd166;
  background: rgba(255, 209, 102, 0.08);
  transform: translate(0, 0);
}

.candidateBox::after {
  content: attr(data-index);
  position: absolute;
  left: -1px;
  top: -20px;
  min-width: 20px;
  height: 18px;
  border-radius: 4px 4px 0 0;
  background: #ffd166;
  color: #121418;
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.candidateCenter {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffd166;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px rgba(18, 20, 24, 0.9);
}

.candidatePoint {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid #ffd166;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 0 0 2px rgba(18, 20, 24, 0.9);
}

.candidatePoint::after {
  content: attr(data-index);
  position: absolute;
  left: 12px;
  top: -16px;
  min-width: 18px;
  height: 18px;
  border-radius: 4px;
  background: #ffd166;
  color: #121418;
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.selectedBBox {
  position: absolute;
  border: 2px solid #00e0a4;
  background: rgba(0, 224, 164, 0.08);
  box-shadow: 0 0 0 2px rgba(6, 17, 14, 0.95);
  cursor: move;
  pointer-events: auto;
}

.bboxHandle {
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid #06110e;
  border-radius: 50%;
  background: #00e0a4;
  pointer-events: auto;
}

.bboxHandle.nw {
  left: -7px;
  top: -7px;
  cursor: nwse-resize;
}

.bboxHandle.ne {
  right: -7px;
  top: -7px;
  cursor: nesw-resize;
}

.bboxHandle.sw {
  left: -7px;
  bottom: -7px;
  cursor: nesw-resize;
}

.bboxHandle.se {
  right: -7px;
  bottom: -7px;
  cursor: nwse-resize;
}

.panel {
  min-width: 0;
  max-height: calc(100vh - 72px);
  overflow-x: hidden;
  overflow-y: auto;
  border-left: 1px solid #2b323b;
  background: #171c22;
  padding: 18px;
}

.fileName {
  min-height: 24px;
  margin-bottom: 18px;
  color: #f5f7fa;
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.field {
  min-width: 0;
  margin-bottom: 18px;
}

label {
  display: block;
  margin-bottom: 8px;
  color: #aeb9c4;
  font-size: 12px;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

input {
  width: 100%;
  height: 36px;
  border: 1px solid #33404c;
  border-radius: 6px;
  padding: 7px 8px;
  background: #101419;
  color: #f2f5f8;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.frameFilter {
  grid-template-columns: repeat(4, 1fr);
  margin-top: 8px;
}

.forwardGenerateControls {
  display: grid;
  grid-template-columns: minmax(76px, 92px) 1fr;
  gap: 8px;
  align-items: end;
  margin-top: 8px;
}

.forwardGenerateControls input {
  margin-top: 4px;
}

.forwardButtonStack {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.templateTrackControls {
  display: grid;
  grid-template-columns: minmax(76px, 92px) 1fr;
  gap: 8px;
  align-items: center;
}

.progressShell {
  width: 100%;
  height: 10px;
  margin-top: 8px;
  overflow: hidden;
  border: 1px solid #303944;
  border-radius: 6px;
  background: #101419;
}

.progressBar {
  width: 0%;
  height: 100%;
  background: #00b887;
  transition: width 180ms ease;
}

.compactStatus {
  min-height: 30px;
  margin-top: 8px;
  font-size: 12px;
}

.zoomControls {
  display: grid;
  grid-template-columns: 40px minmax(64px, 1fr) 40px 72px;
  gap: 8px;
  align-items: center;
}

.zoomValue {
  display: grid;
  place-items: center;
  height: 36px;
  border: 1px solid #303944;
  border-radius: 6px;
  background: #101419;
  color: #c7d0d9;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

button {
  height: 36px;
  border: 1px solid #35414c;
  border-radius: 6px;
  background: #212832;
  color: #eef3f7;
  cursor: pointer;
}

button:hover {
  background: #2a333e;
}

button.active {
  border-color: #00b887;
  background: #073f33;
}

button.primary {
  border-color: #168ad8;
  background: #126dad;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.actions .primary {
  grid-column: 1 / -1;
}

.statusText {
  min-width: 0;
  min-height: 34px;
  border: 1px solid #303944;
  border-radius: 6px;
  padding: 8px;
  background: #101419;
  color: #c7d0d9;
  font-size: 13px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.reviewStatusBanner {
  display: grid;
  place-items: center;
  min-height: 34px;
  margin-bottom: 8px;
  border: 1px solid;
  font-size: 13px;
}

.candidateList {
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
}

.candidateItem {
  height: auto;
  min-height: 44px;
  padding: 7px 8px;
  text-align: left;
  line-height: 1.25;
}

.candidateItem strong {
  display: block;
  color: #f9fafb;
  font-size: 13px;
}

.candidateItem span {
  display: block;
  color: #aeb9c4;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.managerLayout {
  min-height: calc(100vh - 72px);
  padding: 18px;
  background: #0d1014;
}

.datasetGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 14px;
}

.datasetCard {
  display: grid;
  gap: 12px;
  border: 1px solid #2b323b;
  border-radius: 8px;
  padding: 14px;
  background: #161a20;
}

.datasetHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.datasetHeader h2 {
  margin: 0;
  color: #f2f5f8;
  font-size: 17px;
  font-weight: 700;
}

.badge {
  flex: 0 0 auto;
  border: 1px solid #335548;
  border-radius: 999px;
  padding: 4px 8px;
  background: #0f3028;
  color: #9af0d2;
  font-size: 12px;
}

.badge.danger {
  border-color: #6d3035;
  background: #35181b;
  color: #ffb3ba;
}

.badge.status-reviewed {
  border-color: #16835f;
  background: #0b3f31;
  color: #9af0d2;
}

.badge.status-partial {
  border-color: #9a6a16;
  background: #3d2e0b;
  color: #ffdc73;
}

.badge.status-unreviewed {
  border-color: #a23d45;
  background: #461c21;
  color: #ffb3ba;
}

.datasetPath,
.lastLog {
  color: #9ea9b5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.progressMeta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #c7d0d9;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.datasetMetrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.datasetMetrics div {
  min-width: 0;
  border: 1px solid #303944;
  border-radius: 6px;
  padding: 8px;
  background: #101419;
}

.datasetMetrics dt {
  color: #9ea9b5;
  font-size: 12px;
}

.datasetMetrics dd {
  margin: 3px 0 0;
  color: #f2f5f8;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.datasetActions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.buttonLink {
  display: grid;
  place-items: center;
  min-height: 36px;
  border: 1px solid #35414c;
  border-radius: 6px;
  padding: 0 8px;
  background: #212832;
  color: #eef3f7;
  font-size: 13px;
  text-align: center;
  text-decoration: none;
}

.buttonLink:hover {
  background: #2a333e;
}

.buttonLink.primary {
  border-color: #168ad8;
  background: #126dad;
}

.buttonLink.disabled {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}

.headAction {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: max-content minmax(180px, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.headAction small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

@media (max-width: 620px) {
  .headAction { grid-template-columns: 1fr; }
}

.topbarLink {
  min-width: 64px;
}

.emptyState {
  border: 1px solid #303944;
  border-radius: 8px;
  padding: 18px;
  background: #161a20;
  color: #c7d0d9;
}

[hidden] { display: none !important; }
.datasetHeader h2 { min-width: 0; overflow-wrap: anywhere; }
.datasetHeader { flex-wrap: wrap; }
.keyframeStatus { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0; }
.exportDialog { width: min(760px, calc(100% - 32px)); max-height: 85vh; box-sizing: border-box; overflow: auto; border: 1px solid #555; border-radius: 8px; background: #202328; color: #eee; padding: 20px; }
.exportDialog::backdrop { background: #0008; }
.exportDialog h2 { font-size: 20px; }
.exportRow { display: grid; grid-template-columns: minmax(0, 1fr) 100px; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid #444; }
.exportRow span { overflow-wrap: anywhere; }
.exportRow small { display: block; color: #aaa; }
.exportRow select { width: 100%; padding: 8px; background: #303438; color: white; }
.exportStatus { padding: 16px 24px; white-space: pre-wrap; overflow-wrap: anywhere; }
.exportDialog input[type="checkbox"] { width: 18px; height: 18px; vertical-align: middle; margin-right: 6px; }
button:disabled { opacity: .5; cursor: default; }

@media (max-width: 800px) {
  .stats { flex-wrap: wrap; }
  .topbar > div { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
  body.keyframeOnly { height: auto; overflow: auto; }
  .keyframeOnly .layout { display: flex; flex-direction: column; height: auto; }
  .keyframeOnly .stereoViewer { flex: none; height: 440px; min-height: 440px; }
  .keyframeOnly .panel { max-height: none; overflow: visible; }
  .topbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
  }

  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    height: calc(100vh - 116px);
  }

  .panel {
    border-left: 0;
    border-top: 1px solid #2b323b;
  }

  .stereoViewer {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .datasetGrid,
  .datasetMetrics,
  .datasetActions {
    grid-template-columns: 1fr;
  }
}
