:root {
  color-scheme: light;
  --bg: #f7f8f8;
  --panel: #ffffff;
  --text: #1f2528;
  --muted: #647074;
  --border: #d8dedf;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --amber: #a16207;
  --red: #b42318;
  --green: #047857;
  --shadow: 0 10px 30px rgba(31, 37, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: clamp(300px, 20vw, 340px) minmax(0, 1fr);
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
}

.rail {
  border-right: 1px solid var(--border);
  background: #fbfcfc;
  padding: 18px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: sticky;
  top: 0;
  min-width: 0;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  min-width: 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
  background: var(--accent);
}

.portal-user-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  background: #ffffff;
  margin-bottom: 10px;
}

.portal-user-panel div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.portal-user-panel strong,
.portal-user-panel span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portal-user-panel strong {
  font-size: 12px;
}

.portal-user-panel span {
  color: var(--muted);
  font-size: 11px;
}

.portal-user-panel button {
  min-height: 30px;
  padding: 0 9px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
}

h2 {
  font-size: 22px;
  line-height: 1.2;
}

h3 {
  font-size: 14px;
  margin-bottom: 10px;
}

p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.workspace {
  min-width: 0;
  padding: 14px;
  display: grid;
  gap: 12px;
  align-content: start;
  overflow-x: hidden;
}

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

.queue-stat {
  min-height: 58px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 9px 10px;
  display: grid;
  align-content: center;
  gap: 5px;
}

.queue-stat span {
  color: var(--muted);
  font-size: 12px;
}

.queue-stat strong {
  font-size: 21px;
  line-height: 1;
}

.capture-panel,
.result-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
  padding: 14px;
}

.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.active-statuses {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: end;
}

.status {
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.video-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(190px, 220px);
  gap: 12px;
  min-width: 0;
}

.preview-column {
  display: grid;
  gap: 8px;
}

.preview-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
}

.preview-title {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.preview-title strong {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-title span {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: end;
}

.preview-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  min-height: 240px;
  background: #111819;
  border-radius: 8px;
  overflow: hidden;
}

video,
canvas,
#imagePreview {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#captureCanvas {
  display: none;
}

#recordedPreview {
  display: none;
  background: #111819;
}

#imagePreview {
  display: none;
  background: #111819;
}

.controls {
  display: grid;
  gap: 8px;
  align-content: start;
  min-width: 0;
}

button,
.icon-button {
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  border-radius: 8px;
  min-height: 40px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #aab5b7;
}

button:disabled {
  cursor: not-allowed;
  color: #9aa4a7;
  background: #f2f4f4;
}

button.primary {
  color: white;
  border-color: var(--accent);
  background: var(--accent);
}

button.primary:hover {
  background: var(--accent-strong);
}

.rail button,
.rail input,
.rail select {
  width: 100%;
  min-width: 0;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.capture-hint {
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

select {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  padding: 0 10px;
}

input[type="search"] {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  padding: 0 10px;
  color: var(--text);
}

input:not([type]),
input[type="password"],
input[type="text"],
input[type="search"] {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  padding: 0 10px;
  color: var(--text);
}

.rail-section {
  margin-top: 14px;
}

.rail-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.rail-title h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--muted);
}

.task-search-panel {
  width: 100%;
  min-width: 0;
  margin-bottom: 10px;
}

.clip-row,
.task-row {
  width: 100%;
  min-width: 0;
  text-align: left;
  border: 1px solid var(--border);
  background: white;
  border-radius: 8px;
  padding: 10px;
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px;
  min-height: 96px;
}

.task-thumb {
  width: 74px;
  aspect-ratio: 4 / 3;
  align-self: center;
  border-radius: 6px;
  overflow: hidden;
  background: #111819;
  display: grid;
  place-items: center;
}

.task-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.task-thumb-fallback {
  color: #dbe7e5;
  font-size: 11px;
}

.task-row-body {
  min-width: 0;
  overflow: hidden;
  display: grid;
  gap: 4px;
  align-content: center;
}

.clip-row-top {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.clip-row-top strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clip-row.active,
.task-row.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.12);
}

.clip-row strong,
.task-row strong {
  font-size: 12px;
}

.clip-row span,
.task-row span {
  color: var(--muted);
  font-size: 12px;
}

.task-list {
  width: 100%;
  display: grid;
  gap: 8px;
  margin-top: 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 4px 8px 0;
  overscroll-behavior: contain;
}

.task-group {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.task-group-history,
.task-history,
.corrected-list {
  display: grid;
  gap: 6px;
}

.history-row {
  min-height: 34px;
  border-radius: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto auto;
  gap: 6px;
  align-items: center;
  padding: 6px 8px;
  text-align: left;
}

.history-row span,
.history-row em {
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-row strong {
  font-size: 11px;
}

.history-row strong.live {
  color: var(--green);
}

.history-row strong.spoof,
.history-row strong.failed {
  color: var(--red);
}

.history-row strong.review {
  color: var(--amber);
}

.history-row.active {
  border-color: var(--accent);
  background: rgba(15, 118, 110, 0.06);
}

.task-row-badges {
  min-width: 0;
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: end;
}

.task-row-badges .status-chip {
  max-width: 86px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clip-model {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.metric {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 6px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  font-size: 21px;
  line-height: 1.1;
}

.verdict.live strong {
  color: var(--green);
}

.verdict.spoof strong {
  color: var(--red);
}

.verdict.review strong {
  color: var(--amber);
}

.verdict.failed strong {
  color: var(--red);
}

.verdict.queued strong {
  color: #1d4ed8;
}

.verdict.running strong {
  color: #7c3aed;
}

.evidence-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 9px;
  color: #314044;
  background: #f7faf9;
  font-size: 12px;
}

.status-chip {
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.chip.pending,
.status-chip.pending {
  color: var(--muted);
  background: #f4f6f6;
}

.status-chip.live {
  color: var(--green);
  border-color: rgba(4, 120, 87, 0.28);
  background: rgba(4, 120, 87, 0.08);
}

.status-chip.spoof {
  color: var(--red);
  border-color: rgba(180, 35, 24, 0.28);
  background: rgba(180, 35, 24, 0.08);
}

.status-chip.review {
  color: var(--amber);
  border-color: rgba(161, 98, 7, 0.28);
  background: rgba(161, 98, 7, 0.08);
}

.status-chip.queued {
  color: #1d4ed8;
  border-color: rgba(29, 78, 216, 0.25);
  background: rgba(29, 78, 216, 0.08);
}

.status-chip.running {
  color: #7c3aed;
  border-color: rgba(124, 58, 237, 0.25);
  background: rgba(124, 58, 237, 0.08);
}

.status-chip.failed {
  color: var(--red);
  border-color: rgba(180, 35, 24, 0.28);
  background: rgba(180, 35, 24, 0.08);
}

.status-chip.uploaded,
.chip.uploaded {
  color: #155e75;
  border-color: rgba(21, 94, 117, 0.24);
  background: rgba(21, 94, 117, 0.08);
}

.status-chip.corrected,
.chip.corrected {
  color: #6d3d00;
  border-color: rgba(109, 61, 0, 0.24);
  background: rgba(245, 158, 11, 0.12);
}

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

.engine-row {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 11px;
  display: grid;
  align-content: start;
  gap: 4px;
  font-size: 11px;
  line-height: 1.35;
}

.engine-row strong {
  min-width: 0;
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.engine-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.meta-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
  min-width: 0;
}

.meta-grid {
  display: grid;
  gap: 8px;
}

.meta-row {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.meta-row span {
  color: var(--muted);
  font-size: 12px;
}

.meta-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.label-panel {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr) minmax(210px, 1.2fr);
  gap: 8px;
  align-items: end;
  min-width: 0;
}

.label-intro,
.label-choice,
.label-notes {
  min-width: 0;
}

.label-current {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  display: grid;
  gap: 2px;
}

.label-current span {
  color: var(--muted);
  font-size: 11px;
}

.label-current strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.compact-field {
  min-width: 0;
}

.label-choice {
  display: grid;
  gap: 6px;
}

.label-choice > span {
  color: var(--muted);
  font-size: 12px;
}

.label-notes input {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
}

.label-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.label-actions button {
  min-height: 34px;
  white-space: nowrap;
}

.label-actions button.active {
  color: white;
  border-color: var(--accent);
  background: var(--accent);
}

.label-panel > #confirmTrainingLabel,
.label-panel > #labelStatus {
  align-self: end;
}

.label-panel > #labelStatus {
  justify-self: start;
}

.corrected-panel {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.compact-header {
  margin-bottom: 10px;
}

.corrected-row-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 6px;
  align-items: stretch;
}

.corrected-row {
  min-height: 54px;
  text-align: left;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.corrected-row div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.corrected-row strong,
.corrected-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.corrected-row span {
  color: var(--muted);
  font-size: 12px;
}

.corrected-row-labels {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
}

.corrected-delete {
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  align-self: stretch;
  color: #b42318;
  border-color: #f2b8b5;
  background: #fff5f4;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

.corrected-delete:hover {
  color: white;
  border-color: #b42318;
  background: #b42318;
}

.training-panel {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.training-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}

.training-counts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
}

.training-counts div {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 8px;
  display: grid;
  gap: 2px;
}

.training-counts span {
  color: var(--muted);
  font-size: 11px;
}

.training-counts strong {
  font-size: 18px;
  line-height: 1;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  padding: 10px;
  font-size: 12px;
}

details {
  margin-top: 12px;
}

summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

pre {
  overflow: auto;
  max-height: 360px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #101718;
  color: #dbe7e5;
  padding: 14px;
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 1180px) {
  .video-grid,
  .engine-status,
  .meta-layout,
  .label-panel,
  .training-actions {
    grid-template-columns: 1fr;
  }

  .training-counts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .rail {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    min-height: auto;
    height: 58vh;
    position: static;
  }

  .video-grid,
  .evidence-layout,
  .result-grid,
  .queue-panel,
  .meta-layout,
  .label-panel,
  .training-actions,
  .training-counts {
    grid-template-columns: 1fr;
  }

  .active-statuses {
    justify-content: start;
  }
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #eef3f2;
}

.auth-shell {
  width: min(100%, 420px);
}

.auth-shell.wide {
  width: min(100%, 680px);
}

.auth-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 20px;
  display: grid;
  gap: 16px;
}

.auth-brand {
  margin-bottom: 0;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.inline-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.auth-status {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--muted);
  background: #f7faf9;
  font-size: 13px;
}

.account-panel {
  align-content: start;
}

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

.setup-section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: grid;
  gap: 12px;
}

.setup-section[hidden] {
  display: none;
}

.setup-section h2 {
  font-size: 16px;
}

.setup-key {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 6px;
  background: #f7faf9;
}

.qr-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  place-items: center;
  padding: 14px;
  background: white;
}

.qr-panel img {
  width: min(100%, 220px);
  aspect-ratio: 1 / 1;
  display: block;
}

.setup-key span {
  color: var(--muted);
  font-size: 12px;
}

.setup-key strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 16px;
  overflow-wrap: anywhere;
}

@media (max-width: 620px) {
  .inline-form,
  .account-summary {
    grid-template-columns: 1fr;
  }
}
