/* Compliance Central — phone scanner.
 *
 * Held one-handed, at arm's length, in showroom glare, by someone who is also
 * holding a customer's licence. Every choice below answers to that: the single
 * primary action is gold (the only thing on a navy page that survives direct
 * sunlight), targets are finger-sized, and nothing that matters sits in the
 * band along the bottom edge where a thumb and the browser's own chrome live.
 *
 * Tokens are the same brand set the site and the side panel use, so the three
 * surfaces read as one product. This page's surfaces are the dark end of that
 * palette; the site is the light end. The three faces are the extension's own,
 * self-hosted from docs/fonts so the phone never falls back to whatever the
 * OS ships — the page's CSP allows fonts from this origin only.
 */
@font-face {
  font-family: "Archivo";
  src: url("fonts/archivo-latin-variable.woff2") format("woff2");
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
}

@font-face {
  font-family: "Bricolage Grotesque";
  src: url("fonts/bricolage-grotesque-latin-variable.woff2") format("woff2");
  font-style: normal;
  font-weight: 600 800;
  font-display: swap;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/jetbrains-mono-latin-variable.woff2") format("woff2");
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
}

:root {
  /* Brand */
  --cc-navy: #0d2b4a;
  --cc-navy-deep: #0a2038;
  --cc-gold: #ffcb05;

  /* Type roles — the same three stacks the side panel declares. */
  --font-display: "Bricolage Grotesque", Archivo, system-ui, sans-serif;
  --font-body: Archivo, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Page surfaces (dark end of the brand ramp) */
  --bg-primary: var(--cc-navy-deep);
  --bg-card: #122a45;
  --bg-sunken: #06172d;
  /* The mat behind the two demo-ID pictures. It matches the artwork's own
   * backdrop, so the narrower picture can share a row with the wider one and
   * the extra height reads as margin around the card, not as a letterbox. */
  --id-mat: #01193e;

  --text-primary: #ffffff;
  --text-secondary: #b8c9db;
  --text-muted: #7f97ae;
  /* Text sitting on the translucent panels over live video, which needs to
   * stay legible against whatever the camera happens to be pointed at. */
  --text-on-video: #d6e2ee;

  /* True black behind the camera feed; navy would tint the preview. */
  --video-bg: #000000;
  /* Dims everything outside the barcode strip without hiding it. The strip
   * is a small part of the frame now, so the scrim has to be definite
   * enough to name it as the target and still leave the card's own edges
   * readable above and below it. */
  --frame-scrim: rgba(0, 0, 0, 0.42);

  /* Panels floating over the camera feed. */
  --scrim: rgba(6, 23, 45, 0.92);
  --gold-line: rgba(255, 203, 5, 0.65);
  --gold-halo: rgba(255, 203, 5, 0.2);

  --accent: var(--cc-navy);
  --gold: var(--cc-gold);

  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);

  --border: rgba(255, 255, 255, 0.14);
  --border-strong: rgba(255, 255, 255, 0.32);

  /* Radius scale */
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  /* Elevation — the panel's dark-surface values, under the panel's names. */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);

  /* Type scale — sized for arm's length, not for a desk. */
  --fs-xs: 12px;
  --fs-sm: 14px;
  --fs-md: 15px;
  --fs-base: 16px;
  --fs-lg: 17px;
  --fs-xl: 19px;
  --fs-2xl: 22px;

  /* Space */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;

  /* Clearance kept below the last control so no critical target sits in the
   * band a thumb or the browser's bottom bar covers. */
  --thumb-guard: 44px;

  /* Finger-sized, with room to spare for a gloved or hurried tap. */
  --tap: 52px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The page is a column the height of the phone, so a screen with little on
 * it can still put its decision buttons where the thumb already is instead
 * of stranding them under the heading at the top of a mostly empty page. */
body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(env(safe-area-inset-top), 0px)
    max(env(safe-area-inset-right), var(--sp-4))
    calc(max(env(safe-area-inset-bottom), 0px) + var(--thumb-guard))
    max(env(safe-area-inset-left), var(--sp-4));
}
/* Form controls do not inherit the page face on their own. */
button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

/* width:100% matters now that the body is a flex column: an auto margin on
 * the cross axis opts a flex item out of stretching, which would leave the
 * masthead shrink-wrapped and centred instead of ranged left. */
.cc-header {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) 0 var(--sp-3); margin-bottom: var(--sp-3);
  flex: 0 0 auto;
  width: 100%; max-width: 520px; margin-left: auto; margin-right: auto;
}
.cc-logo { width: 34px; height: 34px; flex: 0 0 auto; }
.cc-header h1 {
  min-width: 0;
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

/* Grow to fill a tall phone, never shrink on a short one: the camera screen
 * is already taller than a small handset and must be allowed to overflow
 * into a scroll rather than be compressed to fit. */
.cc-main {
  display: flex;
  flex-direction: column;
  flex: 1 0 auto;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}
.screen { display: flex; flex-direction: column; flex: 1 0 auto; gap: var(--sp-3); }
.screen.hidden, .hidden { display: none !important; }
/* Every decision on this page sits at the bottom of the screen, in the arc
 * a thumb already covers — never in the top third, and never in a corner. */
#reviewScreen .actions,
#cobuyerPrompt .actions { margin-top: auto; }
/* The done screen's buttons are direct children of the column, where the
 * shared `.btn { flex: 1 }` would stretch them to fill the page. */
#doneScreen > .btn { flex: 0 0 auto; }
#doneScreen > .btn:not(.hidden) { margin-top: auto; }
#doneScreen > .btn:not(.hidden) ~ .btn:not(.hidden) { margin-top: 0; }

h2 {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.hint { color: var(--text-secondary); font-size: var(--fs-base); line-height: 1.45; }
.screen > h2:focus { outline: 2px solid var(--gold); outline-offset: 4px; }

.scan-steps {
  list-style: none;
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr);
  gap: var(--sp-3) var(--sp-2);
}
.scan-step { min-width: 0; }
.scan-step-camera { grid-column: 1 / -1; }
.id-example {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
/* Gold marks the barcode to look for. It stops at a border, though: the
 * loudest gold on the screen belongs to the live target, not to a picture
 * of one, and the halo this card used to carry out-shouted it. */
.id-example.is-target {
  border: 2px solid var(--gold);
}
/* The two pictures differ in width (0.82fr vs 1.18fr) and so in height. The
 * picture box grows to fill whatever the row leaves it and sits the artwork
 * on a mat the same colour as its own backdrop, so both captions start at
 * the same height instead of the narrow card's caption stretching to fill. */
.id-example img {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  height: auto;
  min-height: 0;
  aspect-ratio: 640 / 404;
  object-fit: contain;
  background: var(--id-mat);
}
/* The left card is the narrow one (0.82fr of a 390px phone leaves ~140px).
 * A smaller badge and a tighter gap buy the caption enough room to break at
 * word boundaries instead of orphaning a word per line. */
.id-example figcaption {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 6px;
  min-height: 62px;
  padding: var(--sp-2) 6px;
  color: var(--text-primary);
  font-size: var(--fs-md);
  font-weight: 700;
  line-height: 1.2;
  text-align: left;
}
/* Where the browser can share rows across the two cards, the captions become
 * one grid row: equal height, badges level, headlines on one baseline. */
@supports (grid-template-rows: subgrid) {
  .scan-step:not(.scan-step-camera) {
    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 2;
  }
  .scan-step:not(.scan-step-camera) .id-example {
    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 2;
    height: auto;
  }
  .scan-step:not(.scan-step-camera) .id-example img {
    align-self: stretch;
    height: 100%;
  }
}
.id-example.is-target figcaption { color: var(--gold); }
.id-example figcaption strong,
.id-example figcaption small { display: block; }
.id-example figcaption strong { line-height: 1.15; }
.id-example figcaption small {
  margin-top: 2px;
  color: inherit;
  /* Literal, not a token: tests/scanner-ui.test.js pins this size. */
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  opacity: 0.92;
  text-wrap: pretty;
}
.step-number {
  display: inline-grid;
  place-items: center;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border: 2px solid currentColor;
  border-radius: var(--radius-pill);
  color: inherit;
  font-family: var(--font-body);
  font-size: var(--fs-lg);
  font-weight: 800;
  font-variant-numeric: lining-nums tabular-nums;
  line-height: 1;
}
.id-example figcaption .step-number {
  flex-basis: 26px;
  width: 26px;
  height: 26px;
  font-size: var(--fs-md);
}
.id-example figcaption > span { min-width: 0; }
.id-example.is-target .step-number {
  border-color: var(--gold);
  background: var(--gold);
  color: var(--accent);
}

/* Card 3: the instruction strip sits above the feed, not over it, so the
 * gold corner marks — the one thing on this page a salesperson is meant to
 * line up with — are never hidden under their own instructions. */
.viewport-shell {
  position: relative;
  width: 100%;
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--video-bg);
  overflow: hidden;
}
#video { display: block; width: 100%; height: 100%; object-fit: cover; }
.commercial-camera-view {
  position: absolute !important;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}
/* The target is shaped like the thing being scanned. A PDF417 on the back of
 * a licence is a wide, shallow strip — at most 75.6mm across and 38.1mm tall,
 * with its bars running perpendicular to the card's bottom edge — so a
 * card-shaped box would invite the salesperson to fill the frame with the
 * whole licence and leave the barcode too small to resolve. The track is
 * 8:3; the guide inside it is 94% × 84% of that, which lands the target at
 * almost exactly 3:1. The shape never changes during a session.
 *
 * The guide's rectangle is also the decoder's crop (scan.js measures it live
 * with getBoundingClientRect), so the strip the salesperson sees and the
 * pixels the decoder reads are the same thing by construction. */
.frame-track {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  aspect-ratio: 8 / 3;
  pointer-events: none;
}
.frame-guide {
  position: absolute;
  left: 3%;
  width: 94%;
  height: 84%;
  top: 50%;
  transform: translateY(-50%);
  border-radius: var(--radius);
  background:
    linear-gradient(var(--gold), var(--gold)) left top / 34px 3px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right top / 34px 3px no-repeat,
    linear-gradient(var(--gold), var(--gold)) left bottom / 34px 3px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right bottom / 34px 3px no-repeat,
    linear-gradient(var(--gold), var(--gold)) left top / 3px 34px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right top / 3px 34px no-repeat,
    linear-gradient(var(--gold), var(--gold)) left bottom / 3px 34px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right bottom / 3px 34px no-repeat;
  box-shadow: 0 0 0 100vmax var(--frame-scrim);
  pointer-events: none;
}
.camera-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}
.camera-step .step-number {
  flex-basis: 28px;
  width: 28px;
  height: 28px;
  border-color: var(--gold);
  background: var(--gold);
  color: var(--accent);
  font-size: var(--fs-base);
}
.camera-step > span:last-child { min-width: 0; }
.camera-step strong,
.camera-step small { display: block; }
.camera-step strong { font-size: var(--fs-md); line-height: 1.15; }
.camera-step small {
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  line-height: 1.3;
  text-wrap: pretty;
}
.status { color: var(--text-secondary); font-size: var(--fs-md); line-height: 1.45;
  text-align: center; overflow-wrap: anywhere; }
.status:empty { display: none; }
/* Live guidance, in the dimmed band below the strip: the one line that
 * changes while framing, kept clear of the target it talks about. */
#cameraScreen .viewport-shell .status {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  width: max-content;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--scrim);
  color: var(--text-primary);
  font-size: var(--fs-sm);
  line-height: 1.3;
  pointer-events: none;
}
.camera-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.camera-actions:empty { display: none; }
.camera-actions .btn-ghost.is-active { border-color: var(--gold); color: var(--gold); }
/* Size is literal, not a token: tests/scanner-ui.test.js pins it. The glare
 * legibility this note needed came from lifting the colour instead. */
.privacy-note { color: var(--text-secondary); font-size: 13px; line-height: 1.45;
  text-align: center; text-wrap: pretty; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.diag { color: var(--text-muted); font-size: var(--fs-xs); text-align: center;
  font-family: var(--font-mono); opacity: 0.8;
  word-break: break-word; min-height: 14px; }

/* Six values to check against the card in the other hand. Label above,
 * value below, both flush left: the values then form one column the eye can
 * run straight down. Side by side, a right-aligned value column ragged at
 * its left edge made every name start in a different place, and a long one
 * wrapped into a narrow gutter. */
.fields { background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--sp-2) var(--sp-4); }
.fields:empty { display: none; }
.fields > div { padding: 9px 0; border-bottom: 1px solid var(--border); }
.fields > div:last-child { border-bottom: none; }
.fields dt { color: var(--text-muted); font-size: var(--fs-sm); line-height: 1.25; }
.fields dd { margin-top: 2px; font-size: var(--fs-lg); font-weight: 700; line-height: 1.3;
  font-variant-numeric: lining-nums tabular-nums; overflow-wrap: anywhere; }

.note { background: var(--warning-bg); border: 1px solid var(--warning);
  color: var(--warning); border-radius: var(--radius); padding: var(--sp-3); font-size: var(--fs-md); }

.actions { display: flex; gap: var(--sp-3); }
/* The decision buttons ride above the thumb guard however long the list
 * above them grows, instead of dropping into the band the guard reserves. */
#reviewScreen .actions,
#cobuyerPrompt .actions {
  position: sticky;
  bottom: calc(max(env(safe-area-inset-bottom), 0px) + var(--thumb-guard));
  z-index: 1;
  padding-top: var(--sp-2);
  background: var(--bg-primary);
}
/* One control, one size: every button on the page is the same tap height. */
.btn { flex: 1; min-height: var(--tap); padding: var(--sp-3) var(--sp-4); border: 1px solid transparent;
  border-radius: var(--radius); font-family: var(--font-body); font-size: var(--fs-base); font-weight: 700;
  line-height: 1.25; letter-spacing: 0.005em; cursor: pointer;
  touch-action: manipulation; transition: transform 120ms ease, filter 120ms ease,
  border-color 120ms ease; overflow-wrap: anywhere; }
.btn:disabled { cursor: default; opacity: 0.55; }
.btn:focus { outline: 3px solid var(--gold);
  outline-offset: 3px; }
.btn:focus-visible { outline: 3px solid var(--gold);
  outline-offset: 3px; }
.btn:focus:not(:focus-visible) { outline: none; }
.btn:not(:disabled):active { transform: translateY(1px); }
/* Gold, not navy. A navy button on a navy page is the first thing to vanish
 * under a showroom skylight; gold on this ground clears 10:1. */
.btn-primary { background: var(--gold); border-color: var(--gold); color: var(--accent); font-weight: 800; }
.btn-ghost { background: transparent; color: var(--text-primary);
  border: 1px solid var(--border-strong); }

/* Done: a gold mark on a navy disc, drawn rather than typed, so it renders
 * the same on every phone instead of in whichever fallback face has a tick. */
#doneScreen { align-items: stretch; text-align: center; }
.done-check {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  margin: var(--sp-5) auto var(--sp-1);
  border-radius: 50%;
  background: var(--cc-navy);
  color: var(--gold);
  box-shadow: 0 0 0 1.5px var(--gold-line);
}
.done-check svg { display: block; width: 36px; height: 36px; }
/* The instruction ("go back to your computer") and the delivery state
 * ("sent") were two identical grey paragraphs. The state is the one fact
 * that changes, so it gets a settled chip of its own to sit in. */
#doneScreen #deliveryStatus {
  align-self: center;
  max-width: 100%;
  padding: 6px var(--sp-3);
  border: 1px solid var(--gold-line);
  border-radius: var(--radius-pill);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: var(--fs-sm);
  font-weight: 700;
}
/* The same record list as the review screen, so the recap of what was
 * captured looks like the thing that was confirmed a screen earlier. */
.capture-summary { background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--sp-2) var(--sp-4); text-align: left; }
.capture-summary:empty { display: none; }
.capture-summary .cap-row { padding: 9px 0; border-bottom: 1px solid var(--border); }
.capture-summary .cap-row:last-child { border-bottom: none; }
.capture-summary .cap-row span { color: var(--text-muted); font-size: var(--fs-sm); line-height: 1.25; }
.capture-summary .cap-row strong { display: block; margin-top: 2px; font-size: var(--fs-lg); font-weight: 700;
  line-height: 1.3; overflow-wrap: anywhere; }

.error-banner { background: var(--danger-bg); border: 1px solid var(--danger);
  color: var(--danger); border-radius: var(--radius); padding: var(--sp-3); font-size: var(--fs-md);
  line-height: 1.5; margin: 0 0 var(--sp-4); overflow-wrap: anywhere; }

@media (hover: hover) and (pointer: fine) {
  .btn:not(:disabled):hover { filter: brightness(1.08); }
}

@media (max-width: 420px) {
  .actions { flex-direction: column; }

  /* Below ~420px the left step card is only about 130px wide, and a badge
   * sitting beside the text leaves too little for "Turn it over" to hold a
   * line. Stacking the badge gives the caption the full card width. */
  .id-example figcaption {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }
}

@media (max-width: 330px) {
  .scan-steps { gap: var(--sp-2) 6px; }
  .id-example figcaption { gap: 5px; min-height: 68px; padding: 6px; }
  .step-number { flex-basis: 28px; width: 28px; height: 28px; }
  .camera-step { padding: 8px 10px; }
}

/* Keep recovery actions above the camera on short, narrow phones. The normal
 * capture flow keeps its original order; this only applies while an error is
 * visible and the user needs the retry/photo controls immediately. */
@media (max-width: 330px) and (max-height: 620px) {
  #errorBanner:not(.hidden) + #cameraScreen > h2 { order: -2; }
  #errorBanner:not(.hidden) + #cameraScreen > .camera-actions { order: -1; }
}

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}

@media (forced-colors: active) {
  .frame-guide { border: 2px solid CanvasText; background: none; }
  .btn, .fields, .capture-summary, .error-banner, .id-example, .viewport-shell, .done-check {
    border: 1px solid ButtonText;
  }
  .camera-step { border-bottom: 1px solid ButtonText; }
  .id-example.is-target { outline: 3px solid Highlight; }
}
