/* ── Scan code-barres commandes (overlay mobile-first) ─────────────────── */

#barcode-scanner-container {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.94);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: max(10px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  gap: 10px;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}

.obs-scan-sheet {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  flex: 1 0 auto;
}

.obs-title {
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
}

.obs-title strong {
  color: #f97316;
}

.obs-subtitle {
  color: #94a3b8;
  font-size: 0.72rem;
  text-align: center;
  line-height: 1.35;
}

.obs-warn {
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(251, 146, 60, 0.15);
  border: 1px solid rgba(251, 146, 60, 0.35);
  color: #fed7aa;
  font-size: 0.72rem;
  text-align: center;
  line-height: 1.4;
}

/* Grille 2×2 sur mobile, 4 colonnes sur écran large */
.obs-mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.obs-mode-btn {
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid #475569;
  background: #111827;
  color: #94a3b8;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  line-height: 1.25;
  min-height: 44px;
  box-sizing: border-box;
}

.obs-mode-btn.active {
  border: 2px solid #f97316;
  background: rgba(249, 115, 22, 0.2);
  color: #fed7aa;
  font-weight: 700;
}

/* Zone caméra — ratio portrait-friendly */
.obs-reader-wrap {
  position: relative;
  width: 100%;
  border-radius: 14px;
  overflow: hidden;
  border: 3px solid #f97316;
  box-shadow: 0 0 24px rgba(249, 115, 22, 0.45);
  background: #000;
  aspect-ratio: 4 / 3;
  max-height: min(42vh, 320px);
  min-height: 200px;
}

.obs-reader-inner {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  overflow: hidden;
}

/* html5-qrcode : vidéo plein cadre sans écrasement */
.obs-reader-wrap [id^='orders-barcode-reader-'] {
  width: 100% !important;
  height: 100% !important;
  min-height: 100% !important;
  padding: 0 !important;
  border: none !important;
  position: relative !important;
  overflow: hidden !important;
}

.obs-reader-wrap [id^='orders-barcode-reader-'] > div {
  width: 100% !important;
  height: 100% !important;
  min-height: 100% !important;
  padding: 0 !important;
  border: none !important;
}

.obs-reader-wrap video {
  object-fit: cover !important;
  width: 100% !important;
  height: 100% !important;
  display: block !important;
}

.obs-reader-wrap canvas {
  max-width: 100% !important;
}

.obs-reader-wrap #qr-shaded-region {
  border: none !important;
  box-shadow: none !important;
}

.obs-scan-frame {
  pointer-events: none;
  position: absolute;
  inset: 14% 8%;
  border: none;
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
  z-index: 3;
}

.obs-scan-frame::before,
.obs-scan-frame::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid #fff;
}

.obs-scan-frame::before {
  top: 0;
  left: 0;
  border-right: none;
  border-bottom: none;
  border-top-left-radius: 6px;
}

.obs-scan-frame::after {
  top: 0;
  right: 0;
  border-left: none;
  border-bottom: none;
  border-top-right-radius: 6px;
}

.obs-scan-frame .obs-corner-bl,
.obs-scan-frame .obs-corner-br {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid #fff;
  bottom: 0;
}

.obs-scan-frame .obs-corner-bl {
  left: 0;
  border-right: none;
  border-top: none;
  border-bottom-left-radius: 6px;
}

.obs-scan-frame .obs-corner-br {
  right: 0;
  border-left: none;
  border-top: none;
  border-bottom-right-radius: 6px;
}

.obs-status {
  color: #94a3b8;
  font-size: 0.75rem;
  text-align: center;
  line-height: 1.4;
  padding: 0 4px;
}

.obs-switch-cam {
  display: none;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #475569;
  background: #111827;
  color: #e2e8f0;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
}

.obs-switch-cam.visible {
  display: block;
}

.obs-input-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.obs-input {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  font-size: 16px;
  border-radius: 10px;
  border: 2px solid #475569;
  background: #0f172a;
  color: #fff;
  outline: none;
  box-sizing: border-box;
}

.obs-input::placeholder {
  color: #64748b;
  font-size: 0.85rem;
}

.obs-ok-btn {
  width: 100%;
  padding: 12px 18px;
  border-radius: 10px;
  border: none;
  background: #f97316;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  box-sizing: border-box;
  min-height: 44px;
}

.obs-photo-btn {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #475569;
  background: #111827;
  color: #e2e8f0;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  box-sizing: border-box;
  min-height: 44px;
}

.obs-help {
  font-size: 0.68rem;
  color: #64748b;
  text-align: left;
  line-height: 1.45;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.obs-help summary {
  cursor: pointer;
  color: #94a3b8;
  font-weight: 600;
  list-style: none;
}

.obs-help summary::-webkit-details-marker {
  display: none;
}

.obs-cancel-btn {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid #475569;
  background: #1e293b;
  color: #ef4444;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-sizing: border-box;
  min-height: 44px;
  margin-top: 4px;
}

.obs-ble-panel {
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.25);
  box-sizing: border-box;
}

.obs-ble-panel.visible {
  display: flex;
}

.obs-ble-connect {
  padding: 10px 14px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
}

.obs-ble-hint {
  font-size: 0.68rem;
  color: #93c5fd;
  text-align: center;
  line-height: 1.4;
}

@media (min-width: 480px) {
  #barcode-scanner-container {
    align-items: center;
    justify-content: center;
    padding: 16px;
  }

  .obs-title {
    font-size: 1.125rem;
  }

  .obs-subtitle {
    font-size: 0.75rem;
  }

  .obs-mode-row {
    grid-template-columns: repeat(4, 1fr);
  }

  .obs-mode-btn {
    font-size: 0.75rem;
  }

  .obs-reader-wrap {
    max-height: min(50vh, 380px);
  }

  .obs-input-row {
    flex-direction: row;
    align-items: stretch;
  }

  .obs-ok-btn {
    width: auto;
    flex-shrink: 0;
    min-width: 88px;
  }
}

@media (min-width: 640px) {
  .obs-help {
    text-align: center;
  }
}

@media (max-height: 700px) {
  .obs-reader-wrap {
    max-height: 36vh;
    min-height: 160px;
  }

  .obs-subtitle {
    display: none;
  }
}
