:root {
  --bg: #0f1115;
  --bg-elev: #181b22;
  --bg-elev-2: #20242d;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --text-dim: #9aa3b2;
  --accent: #7c9cff;
  --accent-2: #5a7be0;
  --green: #4ade80;
  --green-bg: #14532d;
  --red: #f87171;
  --red-bg: #5a1a1a;
  --yellow: #fbbf24;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
header h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: 0.2px; }
.stats { color: var(--text-dim); font-size: 13px; font-variant-numeric: tabular-nums; }

main { padding: 24px; max-width: 1400px; margin: 0 auto; }
.screen[hidden] { display: none; }

/* ====== Upload ====== */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 80px 24px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-elev);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag {
  border-color: var(--accent);
  background: var(--bg-elev-2);
}
.dz-title { margin: 0 0 6px; font-size: 18px; font-weight: 500; }
.dz-sub { margin: 0; color: var(--text-dim); }
.hint { color: var(--text-dim); text-align: center; margin-top: 14px; font-size: 13px; }

/* ====== Review ====== */
#screen-review {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 20px;
  align-items: start;
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  min-height: 60vh;
}
.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.position {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-size: 13px;
  background: var(--bg-elev-2);
  padding: 4px 10px;
  border-radius: 999px;
}
.filename {
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 500;
}
.status-pill.accepted { background: var(--green-bg); color: var(--green); }
.status-pill.rejected { background: var(--red-bg); color: var(--red); }
.status-pill.pending  { background: var(--bg-elev-2); color: var(--text-dim); }
.status-pill.processed{ background: #1e3a5f; color: var(--accent); }
.status-pill.error    { background: var(--red-bg); color: var(--red); }
.status-pill:empty { display: none; }

.preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.preview-cell figcaption {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
}
.preview-cell { margin: 0; }
.img-frame {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.img-frame img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.img-frame.checkered {
  background-color: #2a2f3a;
  background-image:
    linear-gradient(45deg, #20242d 25%, transparent 25%),
    linear-gradient(-45deg, #20242d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #20242d 75%),
    linear-gradient(-45deg, transparent 75%, #20242d 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.controls {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--bg-elev-2);
  border-radius: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.cm-input {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.cm-input input {
  width: 90px;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-variant-numeric: tabular-nums;
}
.cm-input input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.output-info {
  color: var(--text-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

button {
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  transition: filter .12s, transform .04s, background .12s, border-color .12s;
}
button:hover { filter: brightness(1.1); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #0c1226; }
button.primary:hover { background: var(--accent-2); }
button.accept { background: var(--green-bg); border-color: #14532d; color: var(--green); }
button.reject { background: var(--red-bg); border-color: #5a1a1a; color: var(--red); }

.actions { display: flex; gap: 10px; margin-bottom: 14px; }
.actions button { flex: 1; font-size: 15px; padding: 12px; }

.nav {
  display: flex;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ====== Queue ====== */
.queue {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  position: sticky;
  top: 80px;
}
.queue-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}
.queue-item:hover { background: var(--bg-elev-2); }
.queue-item.active { background: var(--bg-elev-2); outline: 1px solid var(--accent); }
.queue-thumb {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg-elev-2);
  flex-shrink: 0;
}
.queue-meta {
  flex: 1;
  overflow: hidden;
}
.queue-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.queue-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-dim);
}
.queue-dot.accepted { background: var(--green); }
.queue-dot.rejected { background: var(--red); }
.queue-dot.processed { background: var(--accent); }
.queue-dot.error { background: var(--red); }

/* ====== Done ====== */
.done-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px;
  text-align: center;
  max-width: 480px;
  margin: 80px auto;
}
.done-card h2 { margin-top: 0; }
.done-stats { color: var(--text-dim); margin-bottom: 22px; }
.done-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ====== Toast ====== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 100;
}
.toast.error { border-color: var(--red); color: var(--red); }

/* ====== Spinner ====== */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--text-dim);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  #screen-review { grid-template-columns: 1fr; }
  .queue { position: static; max-height: 220px; }
  .preview-grid { grid-template-columns: 1fr; }
}
