/**
 * RMRR Forms - Modal System Styles
 * Shared styles for image preview and crop modals
 */

/* ============================================
   SHARED MODAL STYLES
   ============================================ */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
  cursor: pointer;
}

/* Ensure preview overlay stays visible even if legacy image-modal styles are present */
.modal-overlay.image-modal {
  display: flex;
}

.modal-close-btn {
  position: absolute;
  top: var(--space-xl);
  right: var(--space-3xl);
  color: white;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  background: none;
  border: none;
  z-index: 3001;
  width: var(--touch-target-min);
  height: var(--touch-target-min);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-base);
  -webkit-tap-highlight-color: transparent;
}

.modal-close-btn:hover {
  transform: scale(1.1);
}

.modal-content {
  max-width: 90%;
  max-height: 90%;
  cursor: default;
}

/* ============================================
   IMAGE PREVIEW MODAL
   ============================================ */

.image-modal .modal-content {
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-image {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-md);
}

/* ============================================
   CROP MODAL
   ============================================ */

.crop-modal {
  padding: var(--space-xl);
  overflow: hidden;
  overscroll-behavior: none;
}

.crop-modal-content {
  max-width: 600px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.crop-modal-buttons {
  display: flex;
  gap: var(--space-xl);
  justify-content: center;
  flex-wrap: wrap;
}

.crop-modal-buttons button {
  padding: var(--space-md) var(--space-2xl);
  border-radius: var(--radius-md);
  border: none;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  min-height: var(--touch-target-min);
  transition: all var(--transition-base);
}

.crop-container {
  position: relative;
  display: inline-block;
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto;
}

.crop-preview-image {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  width: auto;
  height: auto;
}

.crop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

/* Crop corner handles */
.crop-corner {
  position: absolute;
  width: 20px;
  height: 20px;
  background: var(--color-btn-primary);
  border: 2px solid white;
  border-radius: 50%;
  cursor: pointer;
  transform: translate(-50%, -50%);
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: all var(--transition-base);
  -webkit-tap-highlight-color: transparent;
}

.crop-corner:hover,
.crop-corner:active {
  background: var(--color-btn-primary-hover);
  width: 24px;
  height: 24px;
}

html.dark-mode .crop-corner {
  background: var(--color-btn-primary);
}

html.dark-mode .crop-corner:hover,
html.dark-mode .crop-corner:active {
  background: var(--color-btn-primary-hover);
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 640px) {
  .modal-overlay {
    padding: var(--space-md);
  }

  .modal-close-btn {
    top: var(--space-md);
    right: var(--space-md);
    font-size: 32px;
  }

  .crop-modal-buttons {
    flex-direction: column;
    width: 100%;
  }

  .crop-modal-buttons button {
    width: 100%;
  }

  .crop-preview-image {
    max-height: 60vh;
  }
}

/* ============================================
   SCANNER MODAL
   ============================================ */

.scanner-modal {
  padding: 0;
  background: #000;
  overflow: hidden;
}

.scanner-container {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  position: relative;
  background: #000;
}

#reader {
  width: 100%;
  background: #000;
}

/* Customizing html5-qrcode elements */
#reader__scan_region {
  background: rgba(0, 0, 0, 0.5);
}

#reader__dashboard_section_csr span, 
#reader__dashboard_section_swaplink {
  display: none !important;
}

.scanner-close-btn {
  position: absolute;
  top: 15px;
  right: 15px;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.scanner-close-btn:active {
  transform: scale(0.95);
  background: rgba(0, 0, 0, 0.8);
}

.btn-scan {
  background-color: #e5e7eb;
  color: #374151;
  border: 1px solid #d1d5db;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}

.btn-scan:hover {
  background-color: #d1d5db;
  color: #111827;
}

html.dark-mode .btn-scan {
  background-color: #374151;
  color: #e5e7eb;
  border-color: #4b5563;
}

html.dark-mode .btn-scan:hover {
  background-color: #4b5563;
  color: #f3f4f6;
}
