/* Photo Index — pit-lane review bench.
   Family palette shared with Race Index brand tokens. */
:root {
  --bg: #0F0F13;
  --panel: #17171C;
  --panel-2: #1F1F26;
  --line: #2A2A32;
  --text: #E8E8EC;
  --muted: #A8A8AD;
  --dim: #6B6B72;
  --accent: #FFD60A;
  --red: #E63946;
  --amber: #FFB800;
  --ok: #57D98A;
  --mx1: #E63946;
  --mx2: #4EA8DE;
  --mx3: #9B5DE5;
  --mx85: #F77F00;
  --mx65: #2EC4B6;
  --mxw: #FF5D8F;
  --cls-other: #8D99AE;
  --display: "Avenir Next Condensed", "Arial Narrow", sans-serif-condensed, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
html, body { background: var(--bg); color: var(--text); }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  padding-bottom: 48px;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg); z-index: 20;
}
.logo { display: flex; align-items: center; }
.logo svg { display: block; }
.logo svg rect:first-of-type { stroke: var(--line); stroke-width: 1; }
.spacer { flex: 1; }
select, input[type="search"], input[type="text"] {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px;
  font: inherit;
}
button.primary {
  background: var(--accent); color: #17130A; font-weight: 600;
  border-radius: 6px; padding: 8px 16px;
}
button.primary:disabled { background: var(--panel-2); color: var(--dim); cursor: default; }
button.primary.small { padding: 6px 12px; }
button.ghost {
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 14px; color: var(--muted);
}
button.ghost:hover { color: var(--text); border-color: var(--dim); }

/* ---------- toolbar / stats ---------- */
.toolbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 20px;
}
.stats { display: flex; gap: 10px; }
.stat {
  display: flex; align-items: baseline; gap: 7px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 12px;
}
.stat b { font-family: var(--display); font-size: 21px; font-weight: 700; }
.stat span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.stat.ok b { color: var(--ok); }
.stat.review b { color: var(--amber); }
.stat.no-rider b { color: var(--dim); }
.seg { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { padding: 7px 13px; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); }

/* ---------- grid ---------- */
.grid {
  display: grid; gap: 14px; padding: 6px 20px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; cursor: pointer; transition: border-color .12s;
}
.card:hover { border-color: var(--dim); }
.card.excluded { opacity: .38; }
.thumbwrap { position: relative; aspect-ratio: 3 / 2; background: #000; }
.thumbwrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dot {
  position: absolute; top: 8px; right: 8px; width: 9px; height: 9px; border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(0,0,0,.45);
}
.sel {
  position: absolute; top: 6px; left: 6px; width: 24px; height: 24px;
  border-radius: 50%; border: 2px solid rgba(255,255,255,.75);
  background: rgba(10,10,12,.55); color: transparent; font-size: 14px;
  line-height: 1; display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .1s;
}
.card:hover .sel, body.selecting .sel { opacity: 1; }
.sel.on {
  opacity: 1; background: var(--accent); border-color: var(--accent);
  color: #17130A; font-weight: 700;
}
.card.selected { border-color: var(--accent); }
.selbar {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; z-index: 30;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; box-shadow: 0 8px 28px rgba(0,0,0,.55);
}
.selbar b { font-family: var(--display); font-size: 18px; }
.dot.ok { background: var(--ok); }
.dot.review { background: var(--amber); }
.dot.no-rider { background: var(--dim); }
.chips { position: absolute; left: 8px; bottom: 8px; display: flex; gap: 6px; flex-wrap: wrap; }

/* race number plate chips — the house style */
.plate {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(10,10,12,.82); border: 1.5px solid var(--cls-c, var(--cls-other));
  border-radius: 5px; padding: 2px 7px 2px 5px; backdrop-filter: blur(2px);
}
.plate b {
  font-family: var(--display); font-weight: 700; font-size: 17px; line-height: 1;
  color: var(--cls-c, var(--cls-other));
}
.plate i {
  font-style: normal; font-size: 10px; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text);
}
.plate.ungated { border-style: dashed; opacity: .75; }
.cls-MX1 { --cls-c: var(--mx1); } .cls-MX2 { --cls-c: var(--mx2); }
.cls-MX3 { --cls-c: var(--mx3); } .cls-MX85 { --cls-c: var(--mx85); }
.cls-MX65 { --cls-c: var(--mx65); } .cls-MXW { --cls-c: var(--mxw); }

/* rename rail — segmented proposed filename */
.rail {
  font-family: var(--mono); font-size: 11.5px; padding: 9px 11px;
  border-top: 1px solid var(--line); word-break: break-all; line-height: 1.6;
}
.rail .sep { color: var(--dim); }
.t-date { color: #7FB4D9; }
.t-round { color: var(--accent); }
.t-plate, .t-rider { color: var(--cls-c, var(--cls-other)); font-weight: 600; }
.t-sponsor { color: var(--ok); }
.t-tag { color: var(--mxw); }
.tagbtn.on { border-color: var(--mxw); color: var(--mxw); }
.tagbadge {
  display: inline-flex; align-items: center;
  background: rgba(10,10,12,.82); border: 1.5px solid var(--mxw); border-radius: 5px;
  padding: 3px 7px; font-size: 10px; letter-spacing: .07em; color: var(--mxw);
  text-transform: uppercase;
}
.t-orig { color: var(--dim); }
.t-warn { color: var(--red); font-family: inherit; font-size: 11px; margin-left: 6px; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 40; display: flex;
  background: rgba(8,8,10,.94);
}
.lb-stage { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; }
.lb-imgwrap { position: relative; max-width: calc(100% - 110px); }
.lb-imgwrap img { max-width: 100%; max-height: 92vh; display: block; }
.bbox {
  position: absolute; border: 2px solid var(--cls-c, var(--cls-other));
  border-radius: 3px; pointer-events: none;
}
.bbox.human { border-width: 2.5px; border-color: var(--ok); }
.bbox.human.plate { border-color: var(--accent); }
.bbox.temp { border-style: dashed; border-color: var(--accent); }
.lb-imgwrap.drawing { cursor: crosshair; }
.lb-imgwrap.drawing img { -webkit-user-drag: none; user-select: none; }
.boxtools { display: flex; gap: 8px; margin-bottom: 8px; }
.boxtools button.on { border-color: var(--accent); color: var(--accent); }
.bbox label {
  position: absolute; top: -22px; left: -2px;
  font-family: var(--display); font-weight: 700; font-size: 15px;
  background: var(--cls-c, var(--cls-other)); color: #0F0F13;
  padding: 0 6px; border-radius: 3px; white-space: nowrap;
}
.lb-nav {
  font-size: 44px; color: var(--muted); padding: 0 18px; align-self: stretch;
}
.lb-nav:hover { color: var(--text); }
.lb-side {
  width: 320px; background: var(--panel); border-left: 1px solid var(--line);
  padding: 18px; overflow-y: auto; position: relative;
}
.lb-close { position: absolute; top: 10px; right: 12px; font-size: 26px; color: var(--muted); }
.lb-file { font-family: var(--mono); font-size: 12px; color: var(--muted); margin: 4px 0 10px; word-break: break-all; }
.lb-rail { font-family: var(--mono); font-size: 12px; word-break: break-all; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; margin-bottom: 16px; line-height: 1.6; }
.lb-side h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 0 8px; }
a.ghost.dl {
  display: inline-block; text-decoration: none; font-size: 13px;
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 14px;
  color: var(--muted); margin-bottom: 4px;
}
a.ghost.dl:hover { color: var(--text); border-color: var(--dim); }
.riderrow {
  display: flex; align-items: center; gap: 9px; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 6px; margin-bottom: 7px;
  width: 100%; text-align: left;
}
.riderrow:hover { border-color: var(--dim); }
.riderrow.is-primary { border-color: var(--accent); }
.riderrow .conf { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.riderrow .tag { font-size: 10px; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.fixrow { display: flex; gap: 8px; }
.fixrow select { width: 90px; }
.fixrow input { flex: 1; min-width: 0; }
.fixname { color: var(--muted); font-size: 12px; margin-top: 7px; min-height: 16px; }
.excl { display: flex; gap: 8px; align-items: center; margin-top: 18px; color: var(--muted); cursor: pointer; }
.lb-flags { margin-top: 14px; color: var(--red); font-size: 12px; }

/* ---------- lightbox: label chips, class row, rider picker, sponsors ---------- */
.labelrow { display: flex; flex-wrap: wrap; gap: 7px; }
.lchip {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1.5px solid var(--cls-c, var(--cls-other)); border-radius: 5px;
  background: var(--bg); padding: 4px 6px 4px 8px; font-size: 12px;
}
.lchip em {
  font-style: normal; font-size: 9px; letter-spacing: .05em; color: var(--accent);
  text-transform: uppercase;
}
.lchip b { font-family: var(--display); font-size: 16px; line-height: 1; color: var(--cls-c, var(--cls-other)); }
.lchip .x { color: var(--muted); font-size: 15px; line-height: 1; padding: 0 2px; }
.lchip .x:hover { color: var(--red); }
.hint { color: var(--dim); font-size: 12px; }
.ridersearch { width: 100%; margin-bottom: 8px; }
.classrow { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.classrow.dimmed { opacity: .35; pointer-events: none; }
.riderbtn i {
  position: absolute; top: 3px; right: 4px; font-style: normal;
  font-size: 9px; letter-spacing: .04em; color: var(--muted);
}
.clsbtn {
  font-family: var(--display); font-weight: 700; font-size: 14px; letter-spacing: .03em;
  border: 1.5px solid var(--line); border-radius: 5px; padding: 4px 10px; color: var(--muted);
}
.clsbtn.on { border-color: var(--cls-c, var(--cls-other)); color: var(--cls-c, var(--cls-other)); background: var(--bg); }
.riderpick {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 6px; max-height: 240px; overflow-y: auto; padding-right: 2px;
}
.riderbtn {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 4px 5px;
  background: var(--bg); position: relative;
}
.riderbtn:hover { border-color: var(--cls-c, var(--cls-other)); }
.riderbtn.on { border-color: var(--cls-c, var(--cls-other)); box-shadow: inset 0 0 0 1px var(--cls-c, var(--cls-other)); }
.riderbtn em {
  position: absolute; top: 3px; left: 4px; font-style: normal; font-size: 9px;
  color: var(--accent); letter-spacing: .03em;
}
.riderbtn b { font-family: var(--display); font-weight: 700; font-size: 19px; line-height: 1.05; color: var(--cls-c, var(--cls-other)); }
.riderbtn span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chipcloud { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.schip {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); border-radius: 20px; padding: 4px 11px;
  font-size: 12px; color: var(--muted); background: var(--bg);
}
.schip.on { border-color: var(--ok); color: var(--ok); }
.schip .x { font-size: 14px; line-height: 1; color: var(--muted); padding: 0; }
.schip .x:hover { color: var(--red); }

/* ---------- settings drawer ---------- */
.drawerwrap { position: fixed; inset: 0; z-index: 45; background: rgba(8,8,10,.6); }
.drawer {
  position: absolute; top: 0; right: 0; height: 100%; width: min(420px, 94vw);
  background: var(--panel); border-left: 1px solid var(--line);
  padding: 20px; overflow-y: auto;
}
.drawer h2 { font-family: var(--display); font-weight: 700; margin-bottom: 6px; }
.drawer h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 8px; }
.preview {
  font-family: var(--mono); font-size: 12px; color: var(--accent);
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 10px; margin-bottom: 12px; word-break: break-all;
}
.field { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.field input, .field select { display: block; width: 100%; margin-top: 5px; font-family: var(--mono); font-size: 13px; }
.field small { display: block; margin-top: 4px; color: var(--dim); font-family: var(--mono); font-size: 10.5px; }
.field.small { width: 31%; }
.fieldrow { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; cursor: pointer; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.presets button {
  font-family: var(--mono); font-size: 11px; border: 1px solid var(--line);
  border-radius: 5px; padding: 4px 8px; color: var(--muted);
}
.presets button:hover { color: var(--text); border-color: var(--dim); }
.acctrow { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.acctrow .acct-em { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.acctrow .acct-em i { font-style: normal; color: var(--dim); }
.acctrow .x { color: var(--muted); font-size: 15px; }
.acctrow .x:hover { color: var(--red); }
button.small2 { font-size: 11px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); }
button.small2:hover { color: var(--ok); border-color: var(--ok); }
.acrtable { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.acrtable label { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.acrtable input { width: 64px; font-family: var(--mono); text-transform: uppercase; }

/* ---------- modal / toast ---------- */
/* roles: viewers browse + download only; labelers can't run admin ops */
.force-hidden { display: none !important; }
body[data-role="viewer"] .admin-only,
body[data-role="viewer"] .labeler-only,
body[data-role="labeler"] .admin-only { display: none !important; }
.login-card { text-align: left; width: min(400px, 92vw); }
.login-card svg { margin-bottom: 6px; }
.login-sub { color: var(--muted); margin: 4px 0 16px; }
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(8,8,10,.7); display: flex; align-items: center; justify-content: center; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  width: min(560px, 92vw); max-height: 84vh; padding: 22px; overflow-y: auto;
}
.modal-card h2 { font-family: var(--display); font-weight: 700; letter-spacing: .02em; margin-bottom: 12px; }
.modal-card .counts { display: flex; gap: 14px; margin-bottom: 12px; }
.modal-card .sample { font-family: var(--mono); font-size: 11.5px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px; margin: 10px 0; max-height: 260px; overflow-y: auto; line-height: 1.7; word-break: break-all; }
.modal-card .skip { color: var(--muted); font-size: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal label.opt { display: flex; gap: 8px; align-items: center; color: var(--muted); margin: 10px 0; cursor: pointer; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 11px 18px; z-index: 60; box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
@media (prefers-reduced-motion: no-preference) {
  .card { transition: border-color .12s, transform .12s; }
  .card:hover { transform: translateY(-1px); }
  .lightbox, .modal, .toast { animation: fade .14s ease-out; }
  @keyframes fade { from { opacity: 0; } }
}
@media (max-width: 760px) {
  .lightbox { flex-direction: column; }
  .lb-side { width: 100%; border-left: none; border-top: 1px solid var(--line); }
  .lb-imgwrap { max-width: 100%; }
  .lb-nav { display: none; }
}
