:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #d8dee8;
  --blue: #2457d6;
  --green: #15803d;
  --red: #b42318;
  --amber: #b54708;
  --shadow: 0 12px 32px rgba(18, 25, 38, .08);
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 18px 28px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 22px; }
h2 { font-size: 18px; margin-bottom: 18px; }
h3 { margin: 0; font-size: 15px; letter-spacing: 0; }
p { color: var(--muted); margin: 6px 0 0; }
main { width: min(1120px, calc(100vw - 32px)); margin: 28px auto 56px; }

.user { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 14px; }
.user a { color: var(--blue); text-decoration: none; font-weight: 600; }

.hidden { display: none !important; }
.panel, .toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.panel { padding: 22px; }

.steps {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  overflow-x: auto;
}
.step, .filter, .button, .icon-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
.step { padding: 9px 14px; white-space: nowrap; color: var(--muted); }
.step.active { background: #e9eefc; color: var(--blue); border-color: #bdcaf7; }
.view { display: none; }
.view.active { display: block; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label { display: grid; gap: 7px; font-weight: 650; font-size: 13px; color: #344054; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  font: inherit;
  color: var(--text);
  background: #fff;
}
textarea { resize: vertical; min-height: 82px; line-height: 1.45; }

.status, .privacy {
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
}
.caption-examples {
  display: grid;
  gap: 10px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.caption-example-list {
  display: grid;
  gap: 8px;
}
.caption-example {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fbfcfe;
  color: #344054;
  font-size: 14px;
  line-height: 1.45;
}
.export-summary {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}
.export-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 320px);
  gap: 16px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfe;
}
.export-count {
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
}
.export-note {
  border-left: 3px solid var(--blue);
  padding-left: 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}
.export-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.export-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfe;
}
.export-grid strong {
  display: block;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}
.export-grid span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}
.export-summary p {
  max-width: 760px;
}
.export-list {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}
.export-list h3 {
  margin-top: 8px;
}
.export-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, auto);
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
}
.export-row.skipped {
  background: #fbfcfe;
}
.export-row strong,
.export-row span {
  display: block;
}
.export-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.export-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}
.export-row-meta {
  text-align: right;
}
.export-row-meta .warn {
  color: var(--amber);
}
.export-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  background: #fbfcfe;
  font-size: 14px;
}
.privacy {
  padding: 12px 14px;
  background: #ecfdf3;
  color: #05603a;
  border: 1px solid #abefc6;
  border-radius: 8px;
}
.message {
  margin-bottom: 14px;
  border: 1px solid #fedf89;
  background: #fffaeb;
  color: var(--amber);
  border-radius: 8px;
  padding: 12px 14px;
}

.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; text-decoration: none; }
.button.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.button:disabled { opacity: .5; cursor: not-allowed; }

.dropzone {
  min-height: 160px;
  border: 2px dashed var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  text-align: center;
  cursor: pointer;
  margin-top: 16px;
  background: #fbfcfe;
}
.dropzone input { display: none; }
.dropzone span { color: var(--muted); font-weight: 400; }
.dropzone.over { border-color: var(--blue); background: #eef4ff; }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 7px; border: 1px solid var(--line); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
#stats { color: var(--muted); flex: 1; min-width: 220px; }
.analysis-summary { margin-top: 14px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter { padding: 7px 10px; font-size: 13px; }
.filter.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.toggle {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}
.toggle input {
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
}
.setup-toggle {
  align-self: end;
  min-height: 42px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(18, 25, 38, .05);
}
.card.rejected { opacity: .55; }
.card.pending img { filter: grayscale(1); }
.card img { width: 100%; height: 190px; object-fit: cover; display: block; cursor: zoom-in; background: #eef2f7; }
.card-body { padding: 12px; display: grid; gap: 10px; }
.filename { color: var(--muted); font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pills { display: flex; flex-wrap: wrap; gap: 5px; }
.pill { border-radius: 999px; padding: 3px 8px; font-size: 12px; font-weight: 650; background: #f2f4f7; color: #475467; }
.pill.green { background: #dcfae6; color: var(--green); }
.pill.amber { background: #fef0c7; color: var(--amber); }
.pill.red { background: #fee4e2; color: var(--red); }
.row { display: flex; gap: 8px; align-items: center; }
.row input { min-width: 0; }
.row .button { white-space: nowrap; }
.input-clear-wrap {
  position: relative;
  min-width: 0;
  flex: 1;
}
.input-clear-wrap input {
  width: 100%;
  padding-right: 36px;
}
.input-clear {
  position: absolute;
  top: 50%;
  right: 8px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  transform: translateY(-50%);
}
.input-clear:hover { background: #eef2f6; color: var(--text); }
.input-clear:disabled { cursor: not-allowed; opacity: .4; }
.reject { color: var(--red); border-color: #fecdca; }
.reject.active { background: var(--red); color: #fff; border-color: var(--red); }
.download { margin-top: 18px; }

dialog {
  width: min(1100px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  background: #101828;
  color: #fff;
}
dialog.mapping-dialog {
  background: #fff;
  color: var(--text);
}
dialog::backdrop { background: rgba(9, 14, 25, .78); }
.lightbox-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; }
.lightbox-nav { display: flex; align-items: center; gap: 8px; min-width: 0; }
#lightboxTitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 750;
}
.lightbox-actions { display: flex; align-items: center; gap: 8px; }
.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 18px 0;
}
.icon-button { width: 34px; height: 34px; font-size: 24px; line-height: 1; }
.icon-button:disabled { opacity: .38; cursor: not-allowed; }
.lightbox-stage { position: relative; display: grid; place-items: center; background: #05070c; }
.lightbox-stage img { max-width: 100%; max-height: calc(100vh - 180px); object-fit: contain; }
#boxCanvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.box-layer { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.annotation-layer { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.lightbox-stage.drawing .annotation-layer { pointer-events: auto; cursor: crosshair; }
.lightbox-stage.hide-boxes #boxCanvas,
.lightbox-stage.hide-boxes .box-layer,
.lightbox-stage.hide-boxes .annotation-layer { display: none; }
.bib-box {
  position: absolute;
  display: grid;
  place-items: start;
  border: 3px solid;
  border-radius: 4px;
  background: rgba(0,0,0,.05);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  padding: 3px;
  cursor: pointer;
  pointer-events: auto;
  text-shadow: 0 1px 2px rgba(0,0,0,.85);
}
.bib-box.accepted { border-color: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,.25); }
.bib-box.tentative { border-color: #f59e0b; box-shadow: 0 0 0 2px rgba(245,158,11,.25); }
.bib-box.rejected { border-color: #ef4444; background: rgba(239,68,68,.18); opacity: .7; }
.bib-box-remove {
  position: absolute;
  top: -11px;
  right: -11px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 16px;
  line-height: 1;
  text-shadow: none;
}
.bib-box.manual { border-color: #38bdf8; box-shadow: 0 0 0 2px rgba(56,189,248,.28); }
.annotation-layer .bib-box { pointer-events: auto; }
.button.active { background: #e9eefc; border-color: #bdcaf7; color: var(--blue); }
.draft-box {
  position: absolute;
  border: 3px dashed #38bdf8;
  border-radius: 4px;
  background: rgba(56,189,248,.12);
  pointer-events: none;
}
.lightbox-tools {
  display: grid;
  gap: 10px;
  padding: 12px 14px 14px;
  background: #101828;
  border-top: 1px solid rgba(255,255,255,.14);
}
.lightbox-caption {
  min-height: 20px;
  color: #f2f4f7;
  font-size: 14px;
  line-height: 1.45;
}
.lightbox-bib-row {
  display: grid;
  grid-template-columns: auto minmax(160px, 360px) auto;
  gap: 10px;
  align-items: center;
}
.lightbox-bib-row label {
  color: #cbd5e1;
  margin: 0;
}
.lightbox-bib-row input {
  background: #fff;
}
.lightbox-bib-row .input-clear-wrap { flex: initial; }
.relay-leg-card-row {
  grid-template-columns: 1fr;
}
.relay-leg-card-row input {
  width: 100%;
}
.mapping-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}
.preview-wrap {
  margin: 0 18px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 280px;
}
#mappingPreview {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
#mappingPreview th,
#mappingPreview td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
}
#mappingPreview th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  font-weight: 750;
}
.mapping-dialog .actions {
  padding: 0 18px 18px;
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .grid.two { grid-template-columns: 1fr; }
  .toolbar { align-items: stretch; }
  .toolbar > * { width: 100%; }
  .export-grid { grid-template-columns: 1fr 1fr; }
  .export-hero { grid-template-columns: 1fr; }
  .export-row { grid-template-columns: 1fr; }
  .export-row-meta { text-align: left; }
  .lightbox-bar { align-items: stretch; flex-direction: column; }
  .lightbox-nav { justify-content: space-between; }
  .lightbox-actions { justify-content: flex-end; flex-wrap: wrap; }
  .mapping-grid { grid-template-columns: 1fr; }
  .lightbox-bib-row { grid-template-columns: 1fr; }
}
