/* Vue « capture » (#/scan, #/scan/:docId) — aperçu caméra plein écran, toujours sombre.
   Les jetons et les composants partagés viennent de base.css : rien n'est redéfini ici. */

.capture {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;

  /* Éclair de capture : blanc par nature, repris du jeton « texte sur accent ». */
  --capture-flash: var(--on-accent);
}

/* Sans dvh (iOS 15.0–15.3) : 100vh dépasse la zone visible et masque les commandes sous la barre Safari. */
@supports not (height: 100dvh) {
  .capture {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    height: auto;
    min-height: 0;
  }
}

/* .icon-btn et .btn imposent un display : sans cette règle, [hidden] resterait visible. */
.capture [hidden] {
  display: none !important;
}

.capture__file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ------------------------------------------------------------------ scène */

.capture__stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.capture__video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  background: var(--bg);
}

.capture__overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s var(--ease);
}

.capture__mask {
  fill: var(--scrim);
  opacity: .7;
}

.capture__outline {
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 2.5;
  stroke-linejoin: round;
  transition: stroke .2s var(--ease);
}

.capture__corner {
  fill: var(--text-dim);
  transition: fill .2s var(--ease);
}

/* Détection fiable (confiance ≥ 0.6) : contour vert franc. */
.capture__overlay--sure .capture__outline {
  stroke: var(--ok);
  stroke-width: 3.5;
}

.capture__overlay--sure .capture__corner {
  fill: var(--ok);
}

.capture__flash {
  position: absolute;
  inset: 0;
  background: var(--capture-flash);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s linear;
}

.capture__flash--on {
  opacity: 1;
}

/* ------------------------------------------------------------ barre haute */

.capture__top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;   /* au-dessus du panneau de repli : « Retour » reste accessible sans caméra */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(6px + var(--safe-t)) calc(6px + var(--safe-r)) 22px calc(6px + var(--safe-l));
  background: linear-gradient(to bottom, var(--scrim), transparent);
  pointer-events: none;
}

.capture__top-btn {
  pointer-events: auto;
  color: var(--text);
  background: color-mix(in srgb, var(--scrim) 70%, transparent);
}

@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .capture__top-btn {
    background: var(--scrim);
  }
}

.capture__top-btn[aria-pressed="true"] {
  background: var(--warn);
  color: var(--bg);
}

/* Boutons de droite : « Scanner » (app native) et lampe torche. */
.capture__top-end {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* Capture classique de l'app native : retour au scanner de l'appareil. */
.capture__scanner {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 16px 0 12px;
  border: 0;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform .12s var(--ease);
}

.capture__scanner:active {
  transform: scale(.96);
}

.capture__hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  z-index: 1;
  max-width: calc(100% - 32px);
  padding: 7px 14px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: var(--scrim);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.capture__hint:empty {
  display: none;
}

/* ------------------------------------------------------ repli sans caméra */

.capture__fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: calc(72px + var(--safe-t)) calc(24px + var(--safe-r)) calc(28px + var(--safe-b)) calc(24px + var(--safe-l));
  background: var(--bg);
  text-align: center;
}

/* Enfant direct : les icônes des boutons du panneau gardent leur taille. */
.capture__fallback > .icon {
  width: 52px;
  height: 52px;
  color: var(--text-dim);
}

.capture__fallback-title {
  font-size: 20px;
}

.capture__fallback-text {
  max-width: 38ch;
  color: var(--text-dim);
  font-size: 15px;
}

.capture__fallback-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(100%, 320px);
  margin-top: 6px;
}

/* ------------------------------------------- scanner natif (app native) */

/* Fond de la vue sous le scanner de l'appareil ; la barre haute (Retour) reste au-dessus. */
.capture__native {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: calc(72px + var(--safe-t)) calc(24px + var(--safe-r)) calc(28px + var(--safe-b)) calc(24px + var(--safe-l));
  background: var(--bg);
  text-align: center;
}

.capture__native-text {
  max-width: 38ch;
  color: var(--text-dim);
  font-size: 15px;
}

/* Proposition « Mode manuel » après l'annulation du scanner natif. Posée dans <body> (la vue capture est déjà
   démontée) : jetons du thème global. Au-dessus du bouton flottant (56 px) et de la barre d'actions du document,
   sous les modales et les toasts. */
.capture-offer {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  z-index: 950;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(calc(100% - 24px - var(--safe-l) - var(--safe-r)), 420px);
  padding: 6px 6px 6px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  animation: capture-offer-in .2s var(--ease);
}

.capture-offer__text {
  flex: 1 1 auto;
  min-width: 0;
}

.capture-offer__btn {
  flex: none;
  min-height: var(--tap);
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

.capture-offer__btn:active {
  background: var(--surface);
}

@keyframes capture-offer-in {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .capture-offer {
    animation: none;
  }
}

/* -------------------------------------------------------------- commandes */

.capture__controls {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
  background: var(--bg);
}

.capture__toggles {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.capture__chip {
  min-height: 40px;
}

.capture__actions {
  display: grid;
  grid-template-columns: 1fr 80px 1fr;
  align-items: center;
  justify-items: center;
  gap: 8px;
}

.capture__slot {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- déclencheur --- */

.capture__shutter {
  position: relative;
  display: grid;
  place-items: center;
  width: 80px;
  height: 80px;
  border-radius: 50%;
}

.capture__shutter[disabled] {
  opacity: .45;
  pointer-events: none;
}

.capture__ring {
  position: absolute;
  inset: 0;
  width: 80px;
  height: 80px;
  max-width: none;
}

.capture__ring-track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 4;
}

.capture__ring-progress {
  fill: none;
  stroke: var(--ok);
  stroke-width: 4;
  stroke-linecap: round;
  opacity: 0;
}

/* L'anneau de progression ne sert qu'en capture automatique. */
.capture__shutter--auto .capture__ring-progress {
  opacity: 1;
}

.capture__shutter-core {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--text);
  transition: transform .12s var(--ease);
}

.capture__shutter:active .capture__shutter-core {
  transform: scale(.9);
}

/* --- actions latérales --- */

.capture__side {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: background-color .15s var(--ease);
}

.capture__side:active {
  background: var(--surface-2);
}

.capture__side-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.capture__batch-box {
  position: relative;
  width: 38px;
  height: 38px;
}

.capture__batch-thumb {
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  object-fit: cover;
}

.capture__batch-count {
  position: absolute;
  top: -7px;
  right: -9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

/* ----------------------------------------------------- écrans plus larges */

@media (min-width: 720px) {
  .capture__controls {
    padding-bottom: calc(20px + var(--safe-b));
  }

  .capture__actions {
    grid-template-columns: 1fr 96px 1fr;
  }

  .capture__shutter,
  .capture__ring {
    width: 88px;
    height: 88px;
  }
}
