/* ── Camera modal + certificate scanner ─────────────────────────── */
.camera-modal {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.camera-modal[hidden] { display: none; }

.camera-modal__overlay {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  animation: fadeIn 0.15s ease;
}

.camera-modal__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 680px;
  /* A fixed height is what keeps the video visible: with `height: auto`
     the flex child collapsed to a few pixels and the preview looked black. */
  height: min(88vh, 760px);
  overflow: hidden;
  background: var(--overlay);
  color: var(--text);
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.camera-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
}
.camera-modal__header h3 {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-head);
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.camera-modal__close {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: transparent;
  color: var(--dim);
  border: 0;
  cursor: pointer;
}
.camera-modal__close:hover { background: rgba(var(--veil), 0.12); color: var(--text); }

/* Front/back badge in the scanner header. */
.camera-side {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(var(--neon-rgb), 0.55);
  background: rgba(var(--neon-rgb), 0.14);
  color: var(--neon);
  font-family: var(--font-head);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: default;
}
.camera-side.is-button { cursor: pointer; }
.camera-side.is-button:hover { background: rgba(var(--neon-rgb), 0.26); }

.camera-modal__body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.camera-view {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
  overflow: hidden;
}
.camera-view video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* Show the whole camera frame. `cover` on a portrait screen would zoom
     in so far that the capture crop lost most of its resolution. */
  object-fit: contain;
  background: #000;
}

/* Capture frame. JS sizes it to the real 3:2 card shape, centred on the
   visible video rectangle, so it adapts to every screen automatically. */
.camera-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 92%;
  height: 61%;
  border: 2px dashed rgba(74, 144, 217, 0.95);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.camera-frame__guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.55;
}
.camera-frame__corner {
  position: absolute;
  width: 26px;
  height: 26px;
  border: 3px solid #4a90d9;
}
.camera-frame__corner.tl { top: -3px; left: -3px; border-right: 0; border-bottom: 0; border-radius: 12px 0 0 0; }
.camera-frame__corner.tr { top: -3px; right: -3px; border-left: 0; border-bottom: 0; border-radius: 0 12px 0 0; }
.camera-frame__corner.bl { bottom: -3px; left: -3px; border-right: 0; border-top: 0; border-radius: 0 0 0 12px; }
.camera-frame__corner.br { bottom: -3px; right: -3px; border-left: 0; border-top: 0; border-radius: 0 0 12px 0; }

.camera-status {
  margin: 0;
  padding: 8px 16px;
  text-align: center;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text);
  background: rgba(var(--veil), 0.05);
  border-top: 1px solid var(--line-soft);
  flex: 0 0 auto;
}

/* Title + status strip under the camera. */
.camera-notes {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  background: rgba(var(--veil), 0.05);
  border-top: 1px solid var(--line-soft);
}

/* Which side of the card is being scanned - a big blue banner so nobody
   scans the wrong side first. Both languages, like the paper document. */
.camera-side-title {
  margin: 0;
  padding: 10px 16px 8px;
  text-align: center;
  font-family: var(--font-head);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.45;
  text-transform: uppercase;
  color: #1e90ff;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}
.camera-notes .camera-status {
  border-top: 0;
  padding-top: 0;
}

.camera-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line-soft);
  flex: 0 0 auto;
  flex-wrap: wrap;
  background: var(--overlay);
}
.camera-controls .btn { min-width: 0; }

/* ── Scan progress overlay ──────────────────────────────────────── */
.scan-progress {
  position: fixed;
  inset: 0;
  z-index: 3100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--scrim);
}
.scan-progress[hidden] { display: none; }
.scan-progress__panel {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 26px 22px;
  border-radius: 16px;
  background: var(--overlay);
  color: var(--text);
  border: 1px solid var(--line-soft);
  text-align: center;
}
.scan-progress__spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid rgba(var(--veil), 0.18);
  border-top-color: var(--neon);
  animation: scan-spin 0.9s linear infinite;
}
.scan-progress__text { margin: 0; font-size: 14.5px; color: var(--text); }
.scan-progress__bar {
  width: 100%;
  height: 6px;
  border-radius: 99px;
  background: rgba(var(--veil), 0.14);
  overflow: hidden;
}
.scan-progress__bar span {
  display: block;
  width: 2%;
  height: 100%;
  border-radius: 99px;
  background: var(--neon);
  transition: width 0.3s ease;
}
.scan-progress__hint { margin: 0; font-size: 11.5px; color: var(--dim); line-height: 1.45; }

/* ── Scan result ────────────────────────────────────────────────── */
.scan-result {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 20px;
  -webkit-overflow-scrolling: touch;
}
.scan-result__summary {
  margin: 0 0 12px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-soft);
  background: rgba(var(--veil), 0.05);
}
.camera-modal__panel.is-ok .scan-result__summary { border-color: rgba(80, 200, 120, 0.45); }
.camera-modal__panel.is-warn .scan-result__summary { border-color: rgba(235, 176, 66, 0.5); }
.camera-modal__panel.is-error .scan-result__summary { border-color: rgba(230, 90, 90, 0.55); }

.scan-result__list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.scan-result__list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(var(--veil), 0.06);
}
.scan-result__code {
  flex: 0 0 54px;
  font-family: var(--font-head);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--dim);
}
.scan-result__value { font-size: 13px; word-break: break-word; }

.scan-result__raw {
  border-top: 1px solid var(--line-soft);
  padding-top: 10px;
  font-size: 12px;
  color: var(--dim);
}
.scan-result__raw summary { cursor: pointer; }
.scan-result__raw pre {
  margin: 8px 0 0;
  max-height: 240px;
  overflow: auto;
  padding: 10px;
  border-radius: 8px;
  background: rgba(var(--veil), 0.06);
  color: var(--text);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

@keyframes scan-spin { to { transform: rotate(360deg); } }

/* ── Mobile: full-screen scanner (portrait first) ───────────────── */
@media (max-width: 900px), (max-height: 640px) {
  .camera-modal--scanner { padding: 0; }

  .camera-modal--scanner .camera-modal__overlay { background: #000; }

  .camera-modal--scanner .camera-modal__panel {
    height: 100%;
    max-height: none;
    max-width: none;
    border: 0;
    border-radius: 0;
    background: var(--bg);
    box-shadow: none;
  }

  .camera-modal--scanner .camera-modal__body { position: absolute; inset: 0; }
  .camera-modal--scanner .camera-view { position: absolute; inset: 0; }

  .camera-modal--scanner .camera-modal__header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 4;
    padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 16px;
    border: 0;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0));
  }
  .camera-modal--scanner .camera-modal__header h3 {
    color: #fff;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.85);
  }
  .camera-modal--scanner .camera-modal__close {
    color: #fff;
    background: rgba(0, 0, 0, 0.38);
  }

  /* On a phone the header floats over the video, so the badge has to be
     light on dark instead of the theme colour. */
  .camera-modal--scanner .camera-side {
    border-color: rgba(255, 255, 255, 0.38);
    background: rgba(0, 0, 0, 0.38);
    color: #eaf2fb;
  }

  .camera-modal--scanner .camera-notes {
    position: absolute;
    z-index: 4;
    left: 14px;
    right: 14px;
    top: calc(env(safe-area-inset-top, 0px) + 64px);
    padding: 10px 12px;
    border: 0;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.55);
  }

  .camera-modal--scanner .camera-side-title {
    padding: 0 0 6px;
    font-size: 11.5px;
    color: #4da6ff;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  }

  .camera-modal--scanner .camera-status {
    padding: 0;
    background: transparent;
    color: #eaf2fb;
  }

  .camera-modal--scanner .camera-controls {
    position: absolute;
    z-index: 4;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 14px 12px calc(env(safe-area-inset-bottom, 0px) + 14px);
    border: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.78), rgba(0, 0, 0, 0));
  }
  .camera-modal--scanner .camera-controls .btn--primary { flex: 1 1 auto; }
  .camera-modal--scanner .camera-controls .btn { padding: 10px 12px; font-size: 12.5px; }

  .camera-modal--result .camera-modal__panel { height: min(90vh, 760px); }
  .camera-modal--result .camera-controls { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); flex-wrap: wrap; }
  .camera-modal--result .camera-controls .btn { padding: 10px 12px; font-size: 12.5px; }
  /* Primary action gets its own full-width row on phones. */
  .camera-modal--result .camera-controls .btn--primary { flex: 1 1 100%; order: 2; }
}

@media (max-width: 380px) {
  .camera-controls { gap: 6px; }
  .camera-controls .btn { padding: 9px 10px; font-size: 12px; }
}
