:root {
  --bg: #070b14;
  --bg-elevated: #0b1220;
  --surface: #0e1624;
  --surface-2: #121c2e;
  --card: #152033;
  --border: rgba(125, 160, 200, 0.12);
  --border-strong: rgba(125, 160, 200, 0.22);
  --accent: #0096ef;
  --accent-bright: #00c2ff;
  --accent-deep: #0066c8;
  --accent-soft: rgba(0, 150, 239, 0.12);
  --accent-glow: rgba(0, 194, 255, 0.18);
  --green: #2dd4a0;
  --green-soft: rgba(45, 212, 160, 0.14);
  --red: #ff6b7a;
  --red-soft: rgba(255, 107, 122, 0.12);
  --yellow: #f5c542;
  --text: #eef3f9;
  --text-secondary: #b4c0d0;
  --muted: #7e8fa6;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.28);
  --header-h: 60px;
  --font: "Plus Jakarta Sans", system-ui, sans-serif;
  --ease: 160ms ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { color-scheme: dark; }

.icon-sprite {
  position: absolute !important;
  width: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  flex-shrink: 0;
  color: inherit;
  vertical-align: -0.125em;
  overflow: visible;
}
.icon use { pointer-events: none; }
.icon-sm { width: 14px; height: 14px; }
.icon-md { width: 18px; height: 18px; }
.icon-lg { width: 28px; height: 28px; }

body {
  background:
    radial-gradient(900px 420px at 8% -8%, rgba(0, 150, 239, 0.14) 0%, transparent 55%),
    radial-gradient(700px 360px at 92% 0%, rgba(0, 102, 200, 0.1) 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* —— Header —— */
header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 11, 20, 0.92);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  text-decoration: none;
  color: inherit;
  line-height: 1;
  flex-shrink: 0;
}
.logo-mark {
  width: 30px;
  height: 28px;
  object-fit: contain;
  display: block;
}
.logo-text {
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: -0.035em;
  color: var(--text);
}
.logo-text em {
  font-style: normal;
  font-weight: 600;
  color: var(--accent-bright);
  margin-left: .2rem;
}

nav {
  display: flex;
  gap: .3rem;
  margin-left: .25rem;
  padding: .2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
nav button {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: .4rem .9rem;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: .8rem;
  font-family: inherit;
  transition: color var(--ease), background var(--ease);
}
nav button.active {
  color: var(--text);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}
nav button:hover:not(.active) { color: var(--text-secondary); }

.header-right {
  margin-left: auto;
  display: flex;
  gap: .55rem;
  align-items: center;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .35rem .7rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
}
.status-pill.on {
  color: var(--green);
  border-color: rgba(45, 212, 160, 0.28);
  background: var(--green-soft);
}
.status-pill.warn {
  color: var(--yellow);
  border-color: rgba(245, 197, 66, 0.35);
  background: rgba(245, 197, 66, 0.12);
}
.status-pill.warn .status-dot,
.status-dot.warn {
  background: var(--yellow);
  box-shadow: 0 0 0 3px rgba(245, 197, 66, 0.2);
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}
.status-dot.on {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(45, 212, 160, 0.2);
}

/* —— Forms —— */
input, textarea, select {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: .55rem .75rem;
  font: inherit;
  transition: border-color var(--ease), box-shadow var(--ease);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: rgba(0, 150, 239, 0.55);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
textarea { resize: vertical; min-height: 88px; }
label {
  font-size: .72rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  display: block;
  margin-bottom: .35rem;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .52rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: .82rem;
  font-family: inherit;
  white-space: nowrap;
  transition: background var(--ease), border-color var(--ease), filter var(--ease), color var(--ease);
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent-deep), var(--accent));
  color: #fff;
  border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary {
  background: var(--surface-2);
  color: var(--text-secondary);
  border-color: var(--border-strong);
}
.btn-secondary:hover {
  color: var(--text);
  border-color: rgba(0, 150, 239, 0.35);
  background: var(--card);
}
.btn-success {
  background: var(--green-soft);
  color: var(--green);
  border-color: rgba(45, 212, 160, 0.28);
}
.btn-success:hover { filter: brightness(1.1); }
.btn-danger {
  background: var(--red-soft);
  color: var(--red);
  border-color: rgba(255, 107, 122, 0.28);
}
.btn-danger:hover { filter: brightness(1.08); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
  padding: .4rem;
}
.btn-ghost:hover {
  color: var(--red);
  background: var(--red-soft);
}
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-xs);
}
.btn-sm {
  padding: .35rem .65rem;
  font-size: .75rem;
}
.btn-run {
  width: 100%;
  padding: .95rem 1rem;
  font-size: .95rem;
  background: linear-gradient(135deg, var(--accent-deep) 0%, var(--accent) 48%, var(--accent-bright) 100%);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 102, 200, 0.28);
}
.btn-run:hover:not(:disabled) { filter: brightness(1.06); }
.btn:disabled { opacity: .38; cursor: not-allowed; filter: none !important; }

/* —— Layout —— */
.view {
  display: none;
  padding: 1.5rem 1.5rem 2.5rem;
  max-width: 1240px;
  margin: 0 auto;
}
.view.active { display: block; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 1.35rem;
}
.page-head h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: .25rem;
}
.page-head .muted { font-size: .85rem; color: var(--text-secondary); }

.project-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: end;
}
.project-bar > * { min-width: 0; }
.project-bar select,
.project-bar input { width: auto; min-width: 10rem; }

/* —— Cards —— */
.panel {
  background: linear-gradient(180deg, rgba(18, 28, 46, 0.92) 0%, rgba(14, 22, 36, 0.96) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.panel-h {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .85rem 1.1rem;
  border-bottom: 1px solid var(--border);
  font-size: .84rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  background: rgba(255, 255, 255, 0.015);
}
.panel-h .panel-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent-bright);
  border: 1px solid rgba(0, 150, 239, 0.18);
}
.panel-h .panel-icon .icon { width: 15px; height: 15px; }
.panel-h .muted {
  margin-left: .15rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  font-size: .75rem;
}
.panel-b {
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .85rem;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem;
  align-items: start;
}
.stack { display: flex; flex-direction: column; }
.grid-3 {
  display: grid;
  grid-template-columns: 220px 1fr 250px;
  gap: 1.1rem;
  min-height: 70vh;
}
@media (max-width: 960px) {
  .setup-grid, .grid-3 { grid-template-columns: 1fr; }
}

/* —— Classes —— */
.class-row {
  display: flex;
  align-items: center;
  gap: .55rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .4rem .45rem .4rem .5rem;
  margin-bottom: .45rem;
  transition: border-color var(--ease);
}
.class-row:hover { border-color: var(--border-strong); }
.class-row input[type="text"],
.class-row > input:not([type="color"]) {
  border: none;
  background: transparent;
  padding: .35rem .4rem;
  box-shadow: none;
}
.class-row input:focus { box-shadow: none; }
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 0;
  cursor: pointer;
  background: transparent;
  flex-shrink: 0;
}
.swatch::-webkit-color-swatch-wrapper { padding: 0; }
.swatch::-webkit-color-swatch { border: none; border-radius: 5px; }

/* —— Upload —— */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: 1.85rem 1rem;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, var(--accent-soft) 0%, transparent 70%),
    var(--bg-elevated);
  cursor: pointer;
  text-align: center;
  transition: border-color var(--ease), background var(--ease), box-shadow var(--ease);
}
.dropzone .drop-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent-bright);
  border: 1px solid rgba(0, 150, 239, 0.2);
  margin-bottom: .15rem;
}
.dropzone .drop-icon .icon { width: 22px; height: 22px; }
.dropzone strong { font-size: .92rem; font-weight: 600; letter-spacing: -0.01em; }
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.upload-actions {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: .5rem;
  align-items: center;
}
@media (max-width: 720px) {
  .upload-actions { grid-template-columns: 1fr 1fr; }
  .upload-actions input { grid-column: 1 / -1; }
}

.image-list {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  max-height: 148px;
  overflow: auto;
  padding-right: .15rem;
}
.image-chip {
  font-size: .7rem;
  font-weight: 500;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .22rem .55rem;
  color: var(--text-secondary);
}
.img-count {
  font-size: .82rem;
  color: var(--text-secondary);
}
.img-count strong { color: var(--text); font-weight: 700; }

.run-panel .panel-b { gap: .9rem; }
.run-status { min-height: 1.2rem; font-size: .85rem; white-space: pre-line; }
.progress-track {
  height: 7px;
  background: var(--bg-elevated);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent-bright), var(--green));
  transition: width .35s ease;
  border-radius: inherit;
}
.run-actions { margin-top: .15rem; flex-wrap: wrap; }
.run-actions > * { flex: 0 0 auto; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: .45rem;
}
.metric-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem .6rem;
  min-width: 0;
}
.metric-card .k {
  font-size: .62rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}
.metric-card .v {
  font-size: .92rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: .12rem;
  color: var(--text);
  word-break: break-word;
}
.metric-card .v.na {
  color: var(--muted);
  font-weight: 600;
  font-size: .8rem;
}

/* —— Review —— */
.filmstrip { display: flex; flex-direction: column; gap: .4rem; max-height: 70vh; overflow: auto; }
.film-item {
  display: flex;
  align-items: center;
  gap: .55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .45rem .55rem;
  cursor: pointer;
  background: var(--bg-elevated);
  font-size: .75rem;
  color: var(--text-secondary);
  transition: border-color var(--ease), background var(--ease), color var(--ease);
}
.film-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: #05070d;
  border: 1px solid var(--border);
}
.film-meta { min-width: 0; line-height: 1.35; }
.film-item:hover { border-color: var(--border-strong); color: var(--text); }
.film-item.active {
  border-color: rgba(0, 150, 239, 0.5);
  background: var(--accent-soft);
  color: var(--text);
}
.review-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem .55rem;
}
.review-toolbar .conf-filter {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: .72rem;
  color: var(--muted);
}
.review-toolbar .conf-filter input[type="range"] {
  width: 88px;
  padding: 0;
  accent-color: var(--accent);
}
.review-viewport {
  position: relative;
  overflow: hidden;
  background: #05070d;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  min-height: 240px;
  max-height: 72vh;
}
.review-viewport.panning { cursor: grab; }
.review-viewport.panning.dragging,
.review-viewport.dragging { cursor: grabbing; }
.review-stage {
  position: relative;
  width: 100%;
  background: #05070d;
  line-height: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.review-stage img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  user-select: none;
  -webkit-user-drag: none;
}
#reviewCanvas {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  cursor: crosshair;
  pointer-events: auto;
}
.review-viewport.panning #reviewCanvas { cursor: grab; }

.review-filter {
  display: inline-flex;
  gap: .25rem;
  padding: .2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  margin-bottom: .35rem;
}
.review-filter button {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .75rem;
  font-weight: 600;
  padding: .35rem .75rem;
  border-radius: 999px;
  cursor: pointer;
}
.review-filter button.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.film-item .status-tag {
  display: inline-block;
  margin-left: .35rem;
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent-bright);
}
.film-item .status-tag.approved,
.film-item .status-tag.edited { color: var(--green); }
.film-item .status-tag.rejected { color: var(--red); }
.box-list { display: flex; flex-direction: column; gap: .45rem; max-height: 50vh; overflow: auto; }
.box-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: .45rem;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem;
  cursor: pointer;
}
.box-item:hover { border-color: var(--border-strong); }
.box-item.active {
  border-color: rgba(0, 150, 239, 0.45);
  background: var(--accent-soft);
}

.settings-impact {
  margin-top: .7rem;
  font-size: .75rem;
  line-height: 1.45;
}
.settings-impact strong { color: var(--text-secondary); font-weight: 600; }
.settings-impact code {
  font-size: .7rem;
  background: var(--bg-elevated);
  padding: .05rem .3rem;
  border-radius: 4px;
}

.schema-hint {
  font-size: .7rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .65rem .75rem;
  white-space: pre-wrap;
  color: var(--muted);
  line-height: 1.5;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  padding: .75rem 1.05rem;
  border-radius: var(--radius-sm);
  opacity: 0;
  transform: translateY(12px);
  transition: .22s ease;
  z-index: 100;
  max-width: 360px;
  box-shadow: var(--shadow-md);
  font-size: .85rem;
  font-weight: 500;
}
.toast.show { opacity: 1; transform: none; }

.login-screen {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
body.auth-locked .login-screen { display: flex; }
body.auth-locked header,
body.auth-locked .view { display: none; }

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem 1.75rem 1.6rem;
  display: flex;
  flex-direction: column;
  gap: .9rem;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: .7rem;
}
.login-card .logo-text { font-size: 1.25rem; }
.login-field { display: flex; flex-direction: column; }
.login-submit {
  width: 100%;
  margin-top: .15rem;
  padding: .7rem 1rem;
}
.login-error {
  color: var(--red);
  font-size: .8rem;
  font-weight: 600;
}

.muted { color: var(--muted); font-size: .8rem; }
.row { display: flex; gap: .5rem; align-items: center; }
.row > * { flex: 1; }
.row.triple > * { flex: 1; min-width: 0; }
.row.tight > *:last-child { flex: 0 0 auto; }

.empty-hint {
  padding: .75rem;
  text-align: center;
  color: var(--muted);
  font-size: .8rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

/* Source type toggle (Images | Video) — reuses the review-filter look. */
.source-toggle {
  display: inline-flex;
  gap: .25rem;
  padding: .2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  margin-bottom: .6rem;
}
.source-toggle button {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .8rem;
  font-weight: 600;
  padding: .4rem .9rem;
  border-radius: 999px;
  cursor: pointer;
}
.source-toggle button.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Download Dataset dialog. */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 20, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(440px, 92vw);
  overflow: hidden;
}
.modal-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-b { padding: 1rem; display: flex; flex-direction: column; gap: .6rem; }
.modal-option {
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  padding: .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.modal-option input { margin-top: .2rem; }
.modal-option strong { display: block; font-size: .85rem; }
.modal-option .muted { font-size: .72rem; }
.modal-f {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
}
