/* Dark by default. This gets used standing at a cart in a dim reading room,
   and a white full-screen page there is genuinely unpleasant. */

:root {
  --bg: #12141a;
  --panel: #1b1e27;
  --panel-2: #232733;
  --line: #2e3340;
  --text: #e8eaf0;
  --muted: #98a0b3;
  --accent: #4da3ff;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --radius: 12px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --panel-2: #eef0f4;
    --line: #d9dde5;
    --text: #171a20;
    --muted: #5b6474;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body.capturing { overflow: hidden; }

.screen { display: none; }
.screen.active { display: block; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.error { color: var(--danger); }

/* --- buttons ------------------------------------------------------------ */

button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 0.6rem 0.9rem;
  /* Touch targets on a phone held in one hand while the other holds a report. */
  min-height: 44px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06121f;
  font-weight: 600;
}

button.primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.ghost { background: transparent; }
button.small { padding: 0.35rem 0.6rem; min-height: 36px; font-size: 0.85rem; }
button.danger { color: var(--danger); border-color: transparent; }

/* --- lock --------------------------------------------------------------- */

/* No `display` here on purpose. An ID selector setting display would outrank
   `.screen { display: none }` and leave the lock screen on top of the app
   forever - the active-state rule below is the only place it is set. */
#lock {
  min-height: 100dvh;
  place-items: center;
  padding: 1.5rem;
}

#lock.screen.active { display: grid; }

.lock-card {
  width: min(24rem, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.lock-card h1 { margin: 0 0 0.25rem; font-size: 1.25rem; }
.lock-card p { margin: 0 0 1.25rem; font-size: 0.9rem; }

#login-form { display: grid; gap: 0.6rem; }

input[type="password"], input[type="text"] {
  font: inherit;
  padding: 0.7rem 0.8rem;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  width: 100%;
}

/* --- main --------------------------------------------------------------- */

#main { padding: max(0.75rem, env(safe-area-inset-top)) 0.75rem 2rem; max-width: 46rem; margin: 0 auto; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 0;
}

.cases { display: grid; gap: 0.85rem; }

.case {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem;
  display: grid;
  gap: 0.7rem;
}

.case-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.tag {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
}

.tag.done { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }

.note { font-size: 0.9rem; }

.shots { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.slot {
  flex: 1 1 8rem;
  min-height: 6.5rem;
  border-style: dashed;
  display: grid;
  place-items: center;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.slot-icon {
  width: 22px; height: 18px;
  border: 2px solid currentColor;
  border-radius: 4px;
  position: relative;
}
.slot-icon::after {
  content: "";
  position: absolute;
  inset: 4px 5px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.thumb {
  position: relative;
  flex: 1 1 8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}

/* contain, and tall enough to be worth looking at.
   A captured page is portrait - roughly 3:4 once the masked bands are cropped
   off - so a short wide thumbnail box shrinks it to a stamp floating in black.
   The height scales with the viewport and is capped so a wide desktop card
   does not turn into a full-page image. */
.thumb img {
  display: block;
  width: 100%;
  height: clamp(9rem, 30vw, 15rem);
  object-fit: contain;
  background: #000;
  cursor: zoom-in;
}

.thumb-caption {
  display: block;
  padding: 0.3rem 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--panel);
}

.thumb-remove {
  position: absolute;
  top: 4px; right: 4px;
  width: 28px; height: 28px;
  min-height: 28px;
  padding: 0;
  line-height: 1;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border-color: transparent;
}

.foot { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }

/* --- capture overlay ---------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 40;
  display: flex;
  flex-direction: column;
}

/* A class that sets `display` beats the user-agent rule for [hidden], so every
   element toggled by the hidden attribute needs its own override. Without this
   the capture overlay is on screen at load, over the lock screen. */
.overlay[hidden] { display: none; }

.stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.stage[hidden] { display: none; }

.stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  color: #cfd4e0;
  flex: 0 0 auto;
}

.stage-head .muted { flex: 1; text-align: center; }
.stage-head button { color: #cfd4e0; border-color: #333a48; }

.video-wrap, .canvas-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}

#video {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

#editor {
  touch-action: none;      /* the canvas handles its own drags */
  cursor: crosshair;
  display: block;
}

.camera-error {
  position: absolute;
  inset: auto 1rem 1rem;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem;
  font-size: 0.9rem;
}

.stage-foot {
  flex: 0 0 auto;
  padding: 0.75rem 1rem 1rem;
  display: grid;
  place-items: center;
  gap: 0.6rem;
}

.stage-foot.column { justify-items: stretch; }

.shutter {
  width: 68px; height: 68px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid #7d8494;
  padding: 0;
}

.check {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  font-size: 0.85rem;
  color: #cfd4e0;
  line-height: 1.4;
}

.check input { margin-top: 0.15rem; width: 20px; height: 20px; flex: 0 0 auto; }

/* --- viewer ------------------------------------------------------------- */

.viewer {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.viewer[hidden] { display: none; }

.viewer > button { margin: env(safe-area-inset-top) 0.6rem 0.4rem auto; }

.viewer-scroll {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.viewer-scroll img { display: block; width: 100%; height: auto; }

/* --- toast -------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  z-index: 60;
  max-width: 90vw;
}

.toast.bad { border-color: var(--danger); color: var(--danger); }

/* --- review ------------------------------------------------------------- */

/* The capture overlay is a fixed viewport; the review is a document and has to
   scroll, so it opts out of the flex layout its sibling stages rely on. */
.overlay.scrolling {
  display: block;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  color: var(--text);
}

.overlay.scrolling[hidden] { display: none; }

.stage-head.sticky {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding-top: max(0.5rem, env(safe-area-inset-top));
}

.review-body {
  max-width: 46rem;
  margin: 0 auto;
  padding: 0.75rem 0.75rem calc(3rem + env(safe-area-inset-bottom));
}

.review-shot {
  display: block;
  width: 100%;
  max-height: 40vh;
  object-fit: contain;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.note-line {
  font-size: 0.85rem;
  color: var(--muted);
  border-left: 2px solid var(--line);
  padding-left: 0.7rem;
  margin: 0.6rem 0 1rem;
}

.warn { color: #e0a33a; }

/* --- transcribed rows --------------------------------------------------- */

.rrow {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  margin-bottom: 0.55rem;
  background: var(--panel);
}

/* A flagged row failed an identity the report has to satisfy. It is the only
   thing on this screen worth reacting to, so it is the only thing coloured. */
.rrow.flagged {
  border-color: #e0a33a;
  background: color-mix(in srgb, #e0a33a 7%, var(--panel));
}

.rrow-label { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.45rem; }

.rrow-cells {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(4.6rem, 1fr));
  gap: 0.4rem;
}

.rcell { display: grid; gap: 0.15rem; }
.rcell span { font-size: 0.7rem; color: var(--muted); }

.rcell input {
  font: inherit;
  font-variant-numeric: tabular-nums;
  padding: 0.4rem 0.45rem;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  width: 100%;
}

.rflag {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  line-height: 1.4;
  color: #e0a33a;
}

/* --- the read ----------------------------------------------------------- */

#review-read { margin-top: 1.5rem; }

.frameworks {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}

@media (min-width: 46rem) {
  .frameworks { grid-template-columns: 1fr 1fr; }
}

.fw {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
  background: var(--panel);
}

.fw h4 { margin: 0 0 0.5rem; font-size: 0.95rem; }

.narrative {
  white-space: pre-wrap;
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 0;
}

.codes {
  font-size: 0.72rem;
  color: var(--muted);
  word-break: break-word;
  margin: 0.6rem 0 0;
}

.divergences { margin-top: 1rem; }
.divergences h4 { font-size: 0.95rem; margin: 0 0 0.5rem; }

.divergences table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.divergences th, .divergences td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.divergences th { color: var(--muted); font-weight: 600; }
.divergences td:first-child { color: var(--muted); }

.case-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.case-actions button { flex: 1 1 auto; }

.signed { margin-bottom: 1.25rem; }
.signed h4 { font-size: 0.95rem; margin: 0 0 0.5rem; }
.signed img { cursor: zoom-in; max-height: 45vh; }

/* --- the read, on the card ---------------------------------------------- */

/* Full width, not a fourth column. Four columns on a phone is 90px each, and
   the impression is a sentence - it wants a line, not a column. */
.read-panel {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  background: var(--panel-2);
}

.read-label {
  margin: 0 0 0.25rem;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.read-impression {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.45;
}

.read-meta {
  margin: 0.45rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}
