/* VIPOSeg Unified Review — cool-paper workbench, action indigo + group hues.
   Three theme states: bare :root = light; media query (guarded) = system dark;
   [data-theme] stamps win in both directions. */

:root {
  --ground:#f3f4f2; --surface:#ffffff; --raised:#e9ebe7; --inset:#eef0ec;
  --ink:#16181d; --muted:#626a75; --hair:#dcdfda;
  --act:#4338ca; --act-bg:#e3e5ff; --act-line:#a5b0fc; --act-dim:#eceefe;
  --ok:#15803d; --ok-bg:#dcf2e3;
  --amber:#a16207; --amber-bg:#f8ecd1;
  --bad:#be123c; --bad-bg:#fbe0e6;
  --sel:#1d4ed8; --sel-bg:#dbeafe;
  --g0:#2563eb; --g1:#c2410c; --g2:#0f766e; --g3:#9333ea;
  --g4:#be123c; --g5:#4d7c0f; --g6:#0369a1; --g7:#a16207;
  --shadow:0 1px 2px rgba(22,24,29,.06), 0 6px 20px rgba(22,24,29,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground:#101318; --surface:#171b22; --raised:#1f242d; --inset:#131720;
    --ink:#e6e9ee; --muted:#8d96a4; --hair:#272d38;
    --act:#a5b0fc; --act-bg:#2a2d5c; --act-line:#4f46e5; --act-dim:#20233f;
    --ok:#4ade80; --ok-bg:#12351f;
    --amber:#fbbf24; --amber-bg:#3d2f0e;
    --bad:#fb7185; --bad-bg:#45151f;
    --sel:#93c5fd; --sel-bg:#1e3a5f;
    --g0:#60a5fa; --g1:#fb923c; --g2:#2dd4bf; --g3:#c084fc;
    --g4:#fb7185; --g5:#a3e635; --g6:#38bdf8; --g7:#facc15;
    --shadow:0 1px 2px rgba(0,0,0,.5), 0 6px 20px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --ground:#101318; --surface:#171b22; --raised:#1f242d; --inset:#131720;
  --ink:#e6e9ee; --muted:#8d96a4; --hair:#272d38;
  --act:#a5b0fc; --act-bg:#2a2d5c; --act-line:#4f46e5; --act-dim:#20233f;
  --ok:#4ade80; --ok-bg:#12351f;
  --amber:#fbbf24; --amber-bg:#3d2f0e;
  --bad:#fb7185; --bad-bg:#45151f;
  --sel:#93c5fd; --sel-bg:#1e3a5f;
  --g0:#60a5fa; --g1:#fb923c; --g2:#2dd4bf; --g3:#c084fc;
  --g4:#fb7185; --g5:#a3e635; --g6:#38bdf8; --g7:#facc15;
  --shadow:0 1px 2px rgba(0,0,0,.5), 0 6px 20px rgba(0,0,0,.35);
}

* { box-sizing:border-box; }
/* #assignbar and #video-head set display:flex, which outranks the UA's
   [hidden] rule — without this they never actually hide. */
[hidden] { display:none !important; }
html, body { height:100%; }
body {
  margin:0; background:var(--ground); color:var(--ink);
  font-family:"Archivo", ui-sans-serif, system-ui, sans-serif;
  font-size:13.5px; line-height:1.45;
  display:flex; flex-direction:column; overflow:hidden;
}
.mono { font-family:"IBM Plex Mono", ui-monospace, "SF Mono", monospace; }
button {
  font:inherit; color:var(--ink); background:var(--surface);
  border:1px solid var(--hair); border-radius:7px; padding:5px 11px;
  cursor:pointer;
}
button:hover { border-color:var(--act-line); }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline:2px solid var(--act-line); outline-offset:1px;
}
button.primary { background:var(--act); border-color:var(--act); color:var(--surface); font-weight:600; }
button.primary:hover { filter:brightness(1.08); }
button.danger { color:var(--bad); border-color:var(--bad); }
button.danger:hover { background:var(--bad-bg); }
button.quiet { border-color:transparent; background:transparent; color:var(--muted); }
select, input[type=search] {
  font:inherit; color:var(--ink); background:var(--surface);
  border:1px solid var(--hair); border-radius:7px; padding:4px 8px;
}
kbd {
  font-family:"IBM Plex Mono",monospace; font-size:10.5px;
  background:var(--raised); border:1px solid var(--hair); border-bottom-width:2px;
  border-radius:4px; padding:0 4px;
}
.spacer { flex:1; }

/* ---------------------------------------------------------------- header */
#topbar {
  display:flex; align-items:center; gap:22px; padding:10px 18px;
  background:var(--surface); border-bottom:1px solid var(--hair);
}
#brand { font-weight:700; font-size:16px; letter-spacing:-.01em; white-space:nowrap; }
#brand .mark {
  color:var(--act); font-family:"IBM Plex Mono",monospace; font-weight:700;
  border:2px solid var(--act); border-radius:6px; padding:1px 6px; margin-right:6px;
}
#meters { display:flex; gap:26px; flex:1; min-width:0; }
.meter { display:flex; align-items:center; gap:9px; flex:1; max-width:340px; }
.mlabel {
  font-size:10.5px; font-weight:600; text-transform:uppercase; letter-spacing:.08em;
  color:var(--muted); width:38px;
}
.mtrack {
  position:relative; flex:1; height:10px; background:var(--raised);
  border-radius:99px; overflow:hidden;
}
.mconf, .mprog { position:absolute; inset:0 auto 0 0; border-radius:99px; }
.mprog { background:var(--amber); opacity:.45; }
.mconf { background:var(--ok); z-index:1; }
.mnum {
  font-family:"IBM Plex Mono",monospace; font-size:11px; color:var(--muted);
  font-variant-numeric:tabular-nums; white-space:nowrap;
}

/* -------------------------------------------------------------- filterbar */
#filterbar {
  display:flex; align-items:center; gap:10px; padding:8px 18px; flex-wrap:wrap;
  background:var(--surface); border-bottom:1px solid var(--hair);
}
.seg { display:inline-flex; border:1px solid var(--hair); border-radius:7px; overflow:hidden; }
.seg button { border:0; border-radius:0; background:transparent; padding:4px 14px; }
.seg button.on { background:var(--act); color:var(--surface); font-weight:600; }
.chk { display:inline-flex; align-items:center; gap:5px; color:var(--muted); font-size:12.5px; }
.chk input { accent-color:var(--act); }
#f-q { min-width:200px; flex:1; max-width:340px; }

/* ---------------------------------------------------------------- layout */
#layout { display:flex; flex:1; min-height:0; }
#queue {
  width:292px; min-width:292px; display:flex; flex-direction:column;
  border-right:1px solid var(--hair); background:var(--surface);
}
#queue-meta {
  padding:7px 14px; font-size:11px; color:var(--muted); border-bottom:1px solid var(--hair);
  font-family:"IBM Plex Mono",monospace;
}
#queue-scroll { overflow-y:auto; flex:1; }
.qitem {
  display:block; width:100%; text-align:left; border:0; border-radius:0;
  border-bottom:1px solid var(--hair); background:transparent;
  padding:7px 12px 7px 10px; height:56px; overflow:hidden; position:relative;
}
.qitem:hover { background:var(--inset); }
.qitem.cur { background:var(--act-dim); box-shadow:inset 3px 0 0 var(--act); }
.qtop { display:flex; gap:7px; align-items:center; }
.qid { font-family:"IBM Plex Mono",monospace; font-size:11.5px; font-weight:600; }
.qmeta { font-size:10px; color:var(--muted); margin-left:auto; white-space:nowrap; }
.qcap { color:var(--sel); font-weight:700; }
.qitem.hidden { opacity:.72; }
.qprev {
  font-size:11px; color:var(--muted); white-space:nowrap; overflow:hidden;
  text-overflow:ellipsis; display:block; margin-top:2px;
}
.dot { width:8px; height:8px; border-radius:99px; background:var(--hair); flex:none; }
.dot.in_progress { background:var(--amber); }
.dot.confirmed { background:var(--ok); }
.dot.differ { background:var(--bad); }

#work { flex:1; overflow-y:auto; padding:16px 22px 60px; min-width:0; }
#placeholder { color:var(--muted); padding:60px 0; text-align:center; }

/* ---------------------------------------------------------- unified evidence */
#media-card {
  background:var(--surface); border:1px solid var(--hair); border-radius:12px;
  box-shadow:var(--shadow); padding:12px 14px; margin-bottom:16px;
}
#media-tools, #entities-head {
  display:flex; align-items:center; gap:9px; flex-wrap:wrap; margin-bottom:9px;
}
#media-tools .ctitle {
  font-size:11px; text-transform:uppercase; letter-spacing:.1em;
  color:var(--muted); font-weight:600;
}
#media-meta { color:var(--muted); font-size:11px; }
#media-panels {
  display:flex; gap:7px; overflow-x:auto; padding:2px 0 8px;
}
#media-panelbar { display:flex; align-items:center; gap:5px; margin:0 0 5px; font-size:11px; }
#media-panelbar button { font-size:11px; padding:2px 7px; }
#media-panelbar button.on { background:var(--act); color:var(--surface); border-color:var(--act); }
.media-thumb {
  flex:0 0 150px; height:104px; padding:2px; overflow:hidden; background:var(--inset);
  display:flex; flex-direction:column; align-items:stretch;
}
.media-thumb img { width:100%; height:80px; object-fit:cover; display:block; flex:0 0 80px; }
.media-thumb-label {
  display:block; height:19px; line-height:19px; padding:0 3px;
  color:var(--muted); font:10px/19px ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; text-align:center;
}
#media-big {
  width:100%; max-height:410px; object-fit:contain; display:block;
  background:var(--inset); border-radius:8px; min-height:120px;
}
#media-tabs button { font-size:11px; padding:3px 8px; }
.media-thumb.selected { border-color:var(--act); box-shadow:inset 0 0 0 1px var(--act); }
#media-frame-controls {
  display:flex; align-items:center; justify-content:center; gap:10px;
  flex-wrap:wrap; margin:0 0 8px;
}
#media-frame-controls button { touch-action:none; user-select:none; }
#media-frame-controls button:disabled { opacity:.45; cursor:default; }
#media-frame-position { font:11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.media-hold-hint { font-size:11px; }

/* ------------------------------------------------------------ entity review */
#entities-wrap {
  margin-top:16px; background:var(--surface); border:1px solid var(--hair);
  border-radius:12px; box-shadow:var(--shadow); padding:12px 14px;
}
#entities-head { display:flex; align-items:center; gap:12px; flex-wrap:wrap; margin-bottom:8px; }
#entities-head h2 { font-size:11px; text-transform:uppercase; letter-spacing:.1em;
  color:var(--muted); margin:0; font-weight:600; }
#btn-new-entity { margin-left:auto; }
#entity-list { display:flex; flex-direction:column; gap:5px; }
.erow {
  display:flex; align-items:center; gap:8px; padding:6px 8px; border:1px solid var(--hair);
  border-radius:7px; cursor:pointer; background:var(--surface);
}
.erow:hover, .erow.sel { border-color:var(--act-line); background:var(--act-dim); }
.enum { width:18px; color:var(--muted); font-family:"IBM Plex Mono",monospace; }
.etext { font-weight:600; min-width:140px; }
.erow select { margin-left:auto; font-size:11px; padding:2px 5px; }
#mark-list { display:flex; gap:6px; flex-wrap:wrap; margin-top:10px; }
.mark-card { display:inline-flex; align-items:center; gap:5px; padding:4px 7px; }
.mark-card.linked { border-color:var(--act); background:var(--act-dim); }
.mark-cat { font-size:11px; }
.temporal-row { display:flex; align-items:center; gap:8px; margin-top:6px; color:var(--muted); }
.time-chip { font-family:"IBM Plex Mono",monospace; color:var(--act); font-size:11px; }
.time-edit { font-size:11px; padding:2px 7px; }
.temporal-editor {
  margin:7px 0 0 58px; padding:8px 10px; border:1px solid var(--hair);
  border-radius:7px; background:var(--inset);
}
.temporal-segment { display:flex; align-items:center; gap:6px; flex-wrap:wrap; margin:3px 0; }
.temporal-seg-label { color:var(--muted); font-size:11px; min-width:58px; }
.temporal-field { color:var(--muted); font-size:11px; }
.temporal-input { width:72px; font-family:"IBM Plex Mono",monospace; font-size:12px; padding:2px 5px; }
.temporal-seg-hint { color:var(--muted); font-size:10.5px; }
.temporal-editor-note { color:var(--muted); font-size:10.5px; margin-top:6px; }
.temporal-editor-buttons { display:flex; gap:6px; margin-top:7px; }
.temporal-editor-buttons button { font-size:11px; padding:3px 8px; }
.human-time-row { border-top:1px dashed var(--hair); padding-top:5px; }
.human-temporal-editor { border-color:var(--act-line); }
.frame-pick { font-size:10px; padding:2px 5px; }
.frame-pick.active { background:var(--act); color:var(--surface); border-color:var(--act); }
.human-frame-strip {
  display:flex; gap:5px; overflow-x:auto; padding:7px 0 4px; margin-top:5px;
}
.human-frame {
  flex:0 0 94px; padding:2px; background:var(--surface); border:1px solid var(--hair);
  border-radius:5px; color:var(--muted); cursor:pointer;
}
.human-frame:hover, .human-frame.selected { border-color:var(--act); background:var(--act-dim); }
.human-frame img { width:88px; height:58px; object-fit:cover; display:block; }
.human-frame-label { display:block; font:10px "IBM Plex Mono",monospace; padding:3px 1px 1px; }

/* ------------------------------------------------------------ video head */
#video-head { display:flex; align-items:center; gap:9px; margin-bottom:10px; flex-wrap:wrap; }
#vh-id { font-weight:700; font-size:15px; }
.badge {
  font-size:10.5px; font-weight:600; text-transform:uppercase; letter-spacing:.06em;
  border:1px solid var(--hair); color:var(--muted); border-radius:5px; padding:1px 7px;
}
.badge.edited { color:var(--amber); border-color:var(--amber); }
.badge.vrepaired { color:var(--amber); border-color:var(--amber); }
.badge.vfailed { color:var(--bad); border-color:var(--bad); }
.pill { font-size:11px; font-weight:700; border-radius:99px; padding:2px 10px; }
.pill.unreviewed { background:var(--raised); color:var(--muted); }
.pill.in_progress { background:var(--amber-bg); color:var(--amber); }
.pill.confirmed { background:var(--ok-bg); color:var(--ok); }
.pill.differ { background:var(--bad-bg); color:var(--bad); }
.badge.autov { color:var(--ok); border-color:var(--ok); }
.badge.capedit { color:var(--sel); border-color:var(--sel); }
.badge.vnote { color:var(--bad); border-color:var(--bad); max-width:340px;
               overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* ---------------------------------------------------------------- canvas */
#canvas-card {
  background:var(--surface); border:1px solid var(--hair); border-radius:12px;
  box-shadow:var(--shadow); padding:18px 20px 12px; margin-bottom:16px;
}
#canvas {
  margin:0 0 12px; font-size:17.5px; line-height:2.35; cursor:crosshair;
  user-select:none; -webkit-user-select:none;
}
/* ---- caption text editing: locked object mentions, free slots between them */
#canvas-tools { display:flex; align-items:center; gap:8px; margin:0 0 10px; }
#canvas-tools .ctitle {
  font-size:11px; text-transform:uppercase; letter-spacing:.1em; color:var(--muted);
  font-weight:600;
}
#canvas-tools .spacer { flex:1; }
#canvas-tools button { font-size:12px; padding:3px 9px; }
#canvas-tools button.primary { background:var(--act); color:#fff; border-color:var(--act); }
#cap-hint { font-size:11px; color:var(--muted); }
#cap-hint.warn { color:var(--amber); font-weight:600; }
#canvas.editing {
  cursor:text; user-select:text; -webkit-user-select:text; white-space:pre-wrap;
  background:var(--inset); border-radius:9px; padding:10px 12px;
  box-shadow:inset 0 0 0 1px var(--act-line);
}
#canvas.editing .lockpiece {
  padding:3px 2px; border-radius:3px; background:var(--surface);
  box-shadow:inset 0 0 0 1px var(--hair); cursor:not-allowed;
  user-select:none; -webkit-user-select:none;
}
#canvas.editing .slot { outline:none; border-radius:3px; padding:3px 0; }
#canvas.editing .slot:focus { background:var(--sel-bg); }
#canvas.editing .slot:empty { padding:3px 7px; background:var(--act-dim); }
#canvas .tok { border-radius:3px; padding:3px 0; }
#canvas .tok.word:hover { box-shadow:inset 0 0 0 1.5px var(--act-line); }
#canvas .act { background:var(--act-bg); color:var(--act); font-weight:600;
               box-shadow:inset 0 -2px 0 var(--act-line); }
#canvas .part { background:var(--act-bg); color:var(--act); font-weight:600;
                box-shadow:inset 0 -2px 0 var(--act-line);
                text-decoration:underline dotted; text-underline-offset:4px; }
#canvas .hot { filter:brightness(.92); box-shadow:inset 0 -3px 0 var(--act),
               inset 0 0 0 1.5px var(--act); }
#canvas .subj-hot { box-shadow:inset 0 0 0 1.5px var(--ok); background:var(--ok-bg); }
#canvas .obj-hot { box-shadow:inset 0 0 0 1.5px var(--amber); background:var(--amber-bg); }
#canvas .selrange { background:var(--sel-bg); box-shadow:inset 0 0 0 1.5px var(--sel); }
#canvas .entity-selected { outline:none; }
#canvas .entity-expand-preview { background:var(--sel-bg); box-shadow:inset 0 0 0 1.5px var(--sel); }
#canvas .gu0 { border-bottom:3px solid var(--g0); }
#canvas .gu1 { border-bottom:3px solid var(--g1); }
#canvas .gu2 { border-bottom:3px solid var(--g2); }
#canvas .gu3 { border-bottom:3px solid var(--g3); }
#canvas .gu4 { border-bottom:3px solid var(--g4); }
#canvas .gu5 { border-bottom:3px solid var(--g5); }
#canvas .gu6 { border-bottom:3px solid var(--g6); }
#canvas .gu7 { border-bottom:3px solid var(--g7); }
.achip {
  display:inline-block; font-family:"IBM Plex Mono",monospace; font-size:10px;
  font-weight:700; background:var(--act); color:var(--surface); border-radius:4px;
  padding:0 4px; margin:0 3px 0 1px; vertical-align:super; cursor:pointer;
  user-select:none;
}
.achip.hot { outline:2px solid var(--ink); }

#legend { display:flex; gap:12px; flex-wrap:wrap; font-size:11px; color:var(--muted); }
.gkey { display:inline-flex; align-items:center; gap:5px; font-family:"IBM Plex Mono",monospace; }
.gbadge {
  font-family:"IBM Plex Mono",monospace; font-size:10px; font-weight:700;
  padding:0 4px; border-radius:4px; color:var(--surface);
}
.gb0 { background:var(--g0); } .gb1 { background:var(--g1); }
.gb2 { background:var(--g2); } .gb3 { background:var(--g3); }
.gb4 { background:var(--g4); } .gb5 { background:var(--g5); }
.gb6 { background:var(--g6); } .gb7 { background:var(--g7); }
#issues { margin-top:8px; font-size:11.5px; color:var(--amber); }
#issues li { margin:2px 0; }

/* ---------------------------------------------------------------- actions */
#actions-head { display:flex; align-items:center; gap:12px; margin:0 0 8px; }
#actions-head h2 {
  font-size:11px; text-transform:uppercase; letter-spacing:.1em; color:var(--muted);
  margin:0; font-weight:600;
}
#btn-add.armed { background:var(--sel-bg); border-color:var(--sel); color:var(--sel); }
.acard {
  background:var(--surface); border:1px solid var(--hair); border-radius:10px;
  padding:10px 13px; margin-bottom:8px; box-shadow:var(--shadow);
}
.acard.sel { border-color:var(--act); box-shadow:0 0 0 2px var(--act-bg), var(--shadow); }
.acard:hover { border-color:var(--act-line); }
.arow1 { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.anum {
  font-family:"IBM Plex Mono",monospace; font-size:11px; font-weight:700;
  background:var(--act); color:var(--surface); border-radius:5px; padding:1px 6px;
  cursor:pointer;
}
.acard select { font-size:12px; padding:2px 5px; }
.asent { font-size:10.5px; color:var(--muted); font-family:"IBM Plex Mono",monospace; }
.adel { margin-left:auto; color:var(--bad); border-color:transparent; background:transparent; }
.adel:hover { border-color:var(--bad); }
.arow2 { display:flex; align-items:baseline; gap:7px; flex-wrap:wrap; margin-top:7px; }
.rlab {
  font-size:10px; text-transform:uppercase; letter-spacing:.07em; color:var(--muted);
  width:58px; flex:none;
}
.chip {
  display:inline-flex; align-items:center; gap:5px;
  font-family:"IBM Plex Mono",monospace; font-size:12px;
  border-radius:6px; padding:2px 7px; border:1px solid transparent;
}
.chip .x { cursor:pointer; opacity:.55; font-weight:700; }
.chip .x:hover { opacity:1; }
.chip.mention { background:var(--act-bg); color:var(--act); font-weight:600; }
.chip.subject { background:var(--ok-bg); color:var(--ok); }
.chip.object { background:var(--amber-bg); color:var(--amber); }
.chip.empty { border:1px dashed var(--hair); color:var(--muted); font-size:11px; }
.add-inline { font-size:11px; padding:2px 7px; color:var(--act); border-color:var(--act-line); }
.add-inline:hover { background:var(--act-dim); }
.chip .pmark { opacity:.75; font-weight:500; }
.chip .gbadge { margin-left:2px; }
.group-picker {
  max-width:230px; font-family:"IBM Plex Mono",monospace; font-size:10px;
  padding:2px 4px; color:var(--muted); background:var(--surface);
}
.unlinked-tag { font-size:9.5px; color:var(--amber); border:1px solid var(--amber);
                border-radius:4px; padding:0 4px; text-transform:uppercase; }
#no-actions { color:var(--muted); font-size:12.5px; padding:14px 4px; }

/* --------------------------------------------------------------- assign bar */
#assignbar {
  position:fixed; z-index:40; display:flex; gap:6px; align-items:center;
  background:var(--surface); border:1px solid var(--act-line); border-radius:10px;
  padding:7px 9px; box-shadow:var(--shadow);
}
#assignbar button { font-size:12px; padding:3px 9px; }
#ab-sel {
  max-width:180px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
  font-size:11.5px; color:var(--sel); font-weight:600;
}

/* --------------------------------------------------------------- status bar */
#statusbar {
  display:flex; align-items:center; gap:14px; padding:6px 18px;
  background:var(--surface); border-top:1px solid var(--hair);
  font-size:11.5px; color:var(--muted);
}
#save-state.saving { color:var(--amber); }
#save-state.saved { color:var(--ok); }
#save-state.error { color:var(--bad); font-weight:600; }
.keys { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

#toast {
  position:fixed; bottom:52px; left:50%; transform:translateX(-50%); z-index:60;
  background:var(--ink); color:var(--ground); border-radius:9px; padding:9px 16px;
  font-size:12.5px; box-shadow:var(--shadow); max-width:70vw;
}
#toast.err { background:var(--bad); color:#fff; }

@media (prefers-reduced-motion: no-preference) {
  .acard, .qitem, button { transition:border-color .12s, background .12s, box-shadow .12s; }
  #assignbar { animation:pop .12s ease-out; }
  @keyframes pop { from { transform:scale(.96); opacity:0; } }
}
@media (max-width: 980px) {
  #queue { width:210px; min-width:210px; }
  #canvas { font-size:15.5px; }
  .keys { display:none; }
}
