/* picviewer. Design seed is in DESIGN.md at the repo root; the short version:
   evidence register, dark light-table, mono for every label, stamp-ink red as the
   only hue, radius 0/2/999, compact. Keep the contact sheet butted and unrounded. */
:root {
  --ink: #0f1113;
  --surface: #16191c;
  --surface-2: #1d2125;
  --surface-3: #23282d;
  --line: #2a2f34;
  --line-soft: #202428;
  --text: #dfe3e6;
  --text-dim: #8d959c;
  --text-faint: #636c74;
  --stamp: #a8382c;
  --stamp-lit: #c9483a;
  --mono: ui-monospace, "SFMono-Regular", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --rail: 196px;
  --rec: 348px;
  --bar: 38px;
}

* { box-sizing: border-box; }
/* several overlays below set display:flex, which otherwise beats the UA's
   [hidden] rule and leaves the lightbox, modal and drop veil on screen. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font: 13px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--text); text-decoration: none; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  height: var(--bar);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.brand-name {
  font: 600 12px/1 var(--mono);
  letter-spacing: .18em;
}
.brand-sub {
  font: 11px/1 var(--mono);
  color: var(--text-faint);
  letter-spacing: .06em;
  white-space: nowrap;
}
.tally {
  font: 11px/1 var(--mono);
  color: var(--text-dim);
  letter-spacing: .04em;
  display: flex;
  gap: 14px;
  overflow: hidden;
}
.tally b { color: var(--text); font-weight: 600; }
.topbar-acts { margin-left: auto; display: flex; gap: 6px; }

.btn {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 4px 9px;
  font: 11px/1.4 var(--mono);
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: #39414a; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-key { border-color: #3c454e; }
.btn-danger { color: #e8a39a; border-color: #4a2a26; }
.btn-danger:hover { background: #2a1a18; border-color: var(--stamp); }
.btn.on { background: var(--surface-3); border-color: #49535d; color: #fff; }
.rail-head .mini { margin-left: auto; }
.mini {
  background: none;
  border: 0;
  color: var(--text-faint);
  font: 10px/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 2px 0 2px 6px;
}
.mini:hover { color: var(--text); }

/* ------------------------------------------------------------------ shell */
.shell {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  min-height: calc(100vh - var(--bar));
}
.shell.with-record { grid-template-columns: var(--rail) minmax(0, 1fr) var(--rec); }

.rail {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 10px 0 40px;
  position: sticky;
  top: var(--bar);
  align-self: start;
  max-height: calc(100vh - var(--bar));
  overflow-y: auto;
}
.rail-group { margin-bottom: 18px; }
.rail-head {
  display: flex;
  align-items: center;
  margin: 0 10px 5px;
  font: 10px/1 var(--mono);
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.rail-list { list-style: none; margin: 0; padding: 0; }
.rail-list li {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 26px;
  padding: 0 10px;
  font: 12px/1 var(--mono);
  color: var(--text-dim);
  cursor: pointer;
  border-left: 2px solid transparent;
}
.rail-list li:hover { background: var(--surface-2); color: var(--text); }
.rail-list li.on {
  background: var(--surface-2);
  color: #fff;
  border-left-color: var(--stamp);
}
.rail-list li .n { margin-left: auto; color: var(--text-faint); font-size: 11px; }
.rail-list li.on .n { color: var(--text-dim); }
.rail-list li .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 6px category chip: encodes a user-chosen category, not decoration */
.chip { width: 6px; height: 6px; flex: 0 0 6px; background: var(--c, #4b5560); }
.rail-list li .edit { opacity: 0; color: var(--text-faint); font-size: 10px; }
.rail-list li:hover .edit { opacity: 1; }

.tagcloud { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 10px; }
.tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  font: 11px/1.3 var(--mono);
  color: var(--text-dim);
  cursor: pointer;
  background: none;
}
.tag:hover { color: var(--text); border-color: #3b434c; }
.tag.on { background: var(--stamp); border-color: var(--stamp); color: #fff; }
.tag .n { color: var(--text-faint); margin-left: 5px; }
.tag.on .n { color: #f0cdc8; }

/* ---------------------------------------------------------------- filters */
.main { min-width: 0; display: flex; flex-direction: column; }
.filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--ink);
  position: sticky;
  top: var(--bar);
  z-index: 20;
}
.in {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 4px 7px;
  font: 12px/1.4 var(--mono);
  color: var(--text);
}
.in:focus { outline: 1px solid #49535d; outline-offset: -1px; border-color: #49535d; }
#q { flex: 1 1 240px; min-width: 150px; }
.dates {
  display: flex;
  align-items: center;
  gap: 5px;
  font: 10px/1 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.in-date { width: 130px; color-scheme: dark; }
.to { color: var(--text-faint); }
.resultline {
  margin-left: auto;
  font: 11px/1 var(--mono);
  color: var(--text-faint);
  letter-spacing: .04em;
}

/* ----------------------------------------------- the contact sheet (signature) */
.sheet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 2px;
  padding: 2px;
  align-content: start;
}
.frame {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  position: relative;
  cursor: pointer;
}
.frame:hover { border-color: #39414a; }
.frame.sel { border-color: var(--text); }
.frame.cur { outline: 1px solid var(--stamp-lit); outline-offset: -2px; }
.shot {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #0b0d0e;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.frame.sel .shot img { opacity: .72; }
.shot .broken {
  font: 10px/1.4 var(--mono);
  color: var(--text-faint);
  text-align: center;
  padding: 8px;
}
/* the exhibit stamp: boxed, rotated, stamp ink. the one memorable mark */
.stamp {
  position: absolute;
  right: 5px;
  bottom: 5px;
  border: 2px solid var(--stamp-lit);
  color: var(--stamp-lit);
  background: rgba(15, 17, 19, .55);
  font: 700 10px/1 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 3px 5px;
  transform: rotate(-3deg);
  max-width: 85%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.star {
  position: absolute;
  left: 5px;
  bottom: 5px;
  font: 11px/1 var(--mono);
  color: #e8c06a;
}
.gps {
  position: absolute;
  right: 5px;
  top: 5px;
  font: 9px/1 var(--mono);
  letter-spacing: .08em;
  color: #d8c38a;
  background: rgba(15, 17, 19, .7);
  border: 1px solid #4a4132;
  padding: 2px 3px;
}
.pick {
  position: absolute;
  left: 4px;
  top: 4px;
  width: 15px;
  height: 15px;
  border: 1px solid var(--text-dim);
  background: rgba(15, 17, 19, .6);
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 10px/1 var(--mono);
  color: #fff;
}
.frame:hover .pick, .frame.sel .pick { opacity: 1; }
.frame.sel .pick { background: var(--stamp); border-color: var(--stamp); }
/* the index strip under each frame is what makes this a sheet, not a gallery */
.strip {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 20px;
  padding: 0 5px;
  border-top: 1px solid var(--line-soft);
  font: 10px/1 var(--mono);
  color: var(--text-faint);
  letter-spacing: .03em;
}
.strip .reg { color: var(--text-dim); }
.strip .date { margin-left: auto; }
.strip .nocat { color: var(--stamp); }

.pager {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 10px 40px;
  font: 11px/1 var(--mono);
  color: var(--text-faint);
}
.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-faint);
  font: 12px/1.8 var(--mono);
  grid-column: 1 / -1;
}

/* ----------------------------------------------------------------- record */
.record {
  border-left: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: var(--bar);
  align-self: start;
  max-height: calc(100vh - var(--bar));
  overflow-y: auto;
  padding-bottom: 40px;
}
.rec-head {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  font: 11px/1 var(--mono);
  letter-spacing: .1em;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}
.rec-head .x { margin-left: auto; }
.rec-shot {
  background: #0b0d0e;
  border-bottom: 1px solid var(--line);
  display: block;
  width: 100%;
  cursor: zoom-in;
}
.rec-shot img { width: 100%; display: block; max-height: 300px; object-fit: contain; }
.rec-body { padding: 10px 8px; }
.fieldset { margin: 0 0 12px; }
.flabel {
  display: block;
  font: 10px/1 var(--mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.frow { display: flex; gap: 6px; }
.frow > * { min-width: 0; }
.in-full { width: 100%; }
textarea.in-full { min-height: 72px; resize: vertical; font: 13px/1.55 var(--sans); }
/* facts table: the chain-of-custody block, mono and tabular */
.facts { width: 100%; border-collapse: collapse; font: 11px/1.5 var(--mono); }
.facts th {
  text-align: left;
  font-weight: 400;
  color: var(--text-faint);
  letter-spacing: .06em;
  padding: 3px 8px 3px 0;
  white-space: nowrap;
  vertical-align: top;
  width: 72px;
}
.facts td { padding: 3px 0; color: var(--text-dim); word-break: break-all; }
.facts tr + tr th, .facts tr + tr td { border-top: 1px solid var(--line-soft); }
.rec-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.warn {
  border-left: 2px solid var(--stamp);
  padding: 5px 8px;
  margin: 0 0 12px;
  font: 11px/1.5 var(--mono);
  color: #d9b2ab;
  background: #1b1516;
}

/* -------------------------------------------------------------- selection */
.selbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 7px 10px;
  background: var(--surface-2);
  border-top: 1px solid #39414a;
  font: 11px/1 var(--mono);
}
.selbar .count { letter-spacing: .08em; color: #fff; }
.selbar .sep { width: 1px; height: 18px; background: var(--line); }

/* --------------------------------------------------------------- lightbox */
.light {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #08090a;
  display: flex;
  flex-direction: column;
}
.light-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}
.light-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.light-stamp {
  position: absolute;
  right: 26px;
  bottom: 26px;
  border: 3px solid var(--stamp-lit);
  color: var(--stamp-lit);
  font: 700 18px/1 var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
  padding: 7px 11px;
  transform: rotate(-4deg);
  background: rgba(8, 9, 10, .45);
}
.light-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 7px 10px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  font: 11px/1.4 var(--mono);
  color: var(--text-dim);
}
.light-bar .cap { color: var(--text); font-family: var(--sans); font-size: 13px; }
.light-bar .right { margin-left: auto; display: flex; gap: 6px; }

/* ------------------------------------------------------------------ modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(8, 9, 10, .72);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 12px 12px;
  overflow-y: auto;
}
/* ⛔ no backdrop-click dismiss anywhere in this app: a modal closes only from
   its own buttons or Esc, so a misclick never discards a filing in progress. */
.modal-box {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 2px;
}
.modal-head {
  display: flex;
  align-items: center;
  height: 30px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  font: 11px/1 var(--mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.modal-main { padding: 12px 10px; }
.modal-foot {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  padding: 10px;
  border-top: 1px solid var(--line);
}
.err { color: #e8a39a; font: 11px/1.5 var(--mono); margin: 6px 0 0; }
.hint { color: var(--text-faint); font: 11px/1.6 var(--mono); margin: 6px 0 0; }

.drop {
  border: 1px dashed var(--line);
  padding: 22px 12px;
  text-align: center;
  color: var(--text-faint);
  font: 11px/1.7 var(--mono);
  cursor: pointer;
}
.drop:hover, .drop.hot { border-color: var(--stamp); color: var(--text); }
.uplist {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  font: 11px/1.7 var(--mono);
  max-height: 180px;
  overflow-y: auto;
}
.uplist li { color: var(--text-dim); display: flex; gap: 8px; }
.uplist .bad { color: #e8a39a; }
.uplist .dup { color: #d8c38a; }
.uplist .ok { color: #9ec08f; }
.bar-prog { height: 2px; background: var(--line); margin-top: 10px; }
.bar-prog i { display: block; height: 2px; background: var(--stamp); width: 0; }

.sheetdrop {
  position: fixed;
  inset: 0;
  z-index: 65;
  background: rgba(8, 9, 10, .8);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.sheetdrop-in {
  border: 2px dashed var(--stamp-lit);
  color: var(--text);
  padding: 40px 60px;
  font: 12px/1 var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 54px;
  transform: translateX(-50%);
  z-index: 80;
  margin: 0;
  background: var(--surface-3);
  border: 1px solid #39414a;
  border-radius: 2px;
  padding: 6px 12px;
  font: 11px/1.4 var(--mono);
  max-width: 90vw;
}
.toast.bad { border-color: var(--stamp); color: #e8a39a; }

/* ----------------------------------------------------------------- mobile */
@media (max-width: 900px) {
  :root { --bar: 36px; }
  .shell, .shell.with-record { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: static;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 14px;
    overflow-x: auto;
    padding: 8px 10px;
  }
  .rail-group { margin: 0; min-width: 150px; }
  .record {
    position: fixed;
    inset: 0;
    z-index: 55;
    max-height: none;
    border-left: 0;
  }
  .sheet { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
  .brand-sub, .tally { display: none; }
  .filters { top: var(--bar); }
}
