/* Barcode Scanner Overlay */
.barcode-scanner-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.barcode-scanner-overlay.show {
  display: flex;
  opacity: 1;
}

.barcode-scanner-wrapper {
  width: 100%;
  max-width: 600px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #1a1a1a;
}

.barcode-scanner-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: #2a2a2a;
  color: white;
}

.barcode-scanner-header h5 {
  margin: 0;
  font-size: 1.125rem;
}

.barcode-scanner-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow: hidden;
  position: relative;
}

#barcode-reader {
  width: 100%;
  max-width: 500px;
  position: relative;
}

/* Override html5-qrcode default styles */
#barcode-reader video {
  border-radius: 8px;
  animation: fadeIn 0.5s ease;
}

.barcode-scanner-instructions {
  text-align: center;
  color: white;
  margin-top: 1.5rem;
}

.barcode-scanner-footer {
  padding: 1rem;
  background: #2a2a2a;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes checkmarkScale {
  0% {
    transform: scale(0) rotate(0deg);
    opacity: 0;
  }
  50% {
    transform: scale(1.2) rotate(10deg);
    opacity: 1;
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

@keyframes breathe {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
  }
  50% {
    box-shadow: 0 0 0 15px rgba(59, 130, 246, 0);
  }
}

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

/* Hide custom viewfinder - use html5-qrcode's built-in qrbox instead */
.barcode-scanner-viewfinder {
  display: none;
}

/* Style html5-qrcode's qrbox (the scan region) */
#barcode-reader__scan_region {
  border-radius: 8px;
}

/* Style the qrbox border */
#barcode-reader #qr-shaded-region {
  border-color: rgba(59, 130, 246, 0.5) !important;
}

/* Override html5-qrcode scan region styling */
#barcode-reader__dashboard_section_swaplink {
  color: #3b82f6 !important;
  text-decoration: none !important;
}

#barcode-reader__dashboard_section_swaplink:hover {
  text-decoration: underline !important;
}

/* Success overlay */
.barcode-success-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(34, 197, 94, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  animation: fadeOut 0.5s ease 0.5s forwards;
}

.barcode-success-icon {
  font-size: 4rem;
  color: white;
  animation: checkmarkScale 0.3s ease;
}

/* Loading spinner */
.barcode-scanner-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  color: white;
  text-align: center;
}

.barcode-scanner-loading .spinner-border {
  width: 3rem;
  height: 3rem;
  border-width: 0.3rem;
  border-color: rgba(255, 255, 255, 0.3);
  border-top-color: #3b82f6;
  animation: spin 0.8s linear infinite;
}

/* Mobile responsive */
@media (max-width: 767.98px) {
  .barcode-scanner-wrapper {
    max-width: 100%;
  }

  #barcode-reader {
    width: 100%;
  }

  .barcode-scanner-viewfinder {
    width: 250px;
    height: 150px;
  }
}

/* Desktop modal style */
@media (min-width: 768px) {
  .barcode-scanner-wrapper {
    height: auto;
    max-height: 80vh;
    border-radius: 12px;
    overflow: hidden;
  }
}

/* Accessibility: Focus Indicators (WCAG 2.1 AA - 2.4.7) */
.barcode-scanner-wrapper button:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.3);
}

.barcode-scanner-wrapper button:focus:not(:focus-visible) {
  outline: none;
}

/* Accessibility: Touch Targets (WCAG 2.1 AA - 2.5.5) */
@media (max-width: 767.98px) {
  .barcode-scanner-footer button {
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem;
  }
}

/* Accessibility: Reduced Motion (WCAG 2.1 AA - 2.3.3) */
@media (prefers-reduced-motion: reduce) {
  .barcode-scanner-overlay,
  .barcode-scanner-viewfinder,
  .barcode-success-overlay,
  .barcode-success-icon,
  #barcode-reader video {
    animation: none !important;
  }

  /* Still allow fade in/out but instant */
  .barcode-scanner-overlay {
    transition: opacity 0.1s ease !important;
  }
}
