/**
 * 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: calc(var(--space-xl) + env(safe-area-inset-top, 0px)) var(--space-xl) var(--space-xl) var(--space-xl);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

/* 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: calc(var(--space-xl) + env(safe-area-inset-top, 0px));
  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;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.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);
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.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 4px 6px -1px rgba(0, 0, 0, 0.2),
    0 2px 4px -2px rgba(0, 0, 0, 0.15);
  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);
}

/* Magnifier */
.crop-magnifier {
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
  background: black;
  overflow: hidden;
  z-index: 20;
  pointer-events: none;
  display: none;
  transform: translate(-50%, -100%) translateY(-20px);
}

.crop-magnifier-canvas {
  width: 100%;
  height: 100%;
  image-rendering: -moz-crisp-edges;
  image-rendering: pixelated;
}

.crop-magnifier::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  border: 1px solid white;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 100px rgba(0, 0, 0, 0.1);
}

/* ============================================
   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: var(--color-bg-page);
  overflow: hidden;
}

html.dark-mode .scanner-modal {
  background: #000;
}

.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: var(--color-bg-elevated);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border-medium);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  transition: all var(--transition-base);
}

.btn-scan:hover {
  background-color: var(--color-bg-page);
  color: var(--color-text-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* ============================================
   PDF PREVIEW MODAL
   ============================================ */

.pdf-modal {
  flex-direction: column;
  cursor: pointer;
}

.pdf-modal .modal-close-btn {
  color: #ff3b30;
}

.pdf-preview-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 100vw;
  max-height: 95vh;
  cursor: default;
}

/* Scroll-snap container for swipeable pages */
.pdf-pages-wrapper {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  height: calc(100vh - 100px - env(safe-area-inset-bottom, 0px));
  scrollbar-width: none; /* Firefox */
}

.pdf-pages-wrapper::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

/* Individual page slot */
.pdf-page {
  flex: 0 0 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pdf-page canvas {
  max-width: 95vw;
  max-height: calc(95vh - 80px);
  background: white;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-sm);
}

/* Controls bar (arrows + page info) */
.pdf-controls-bar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-top: var(--space-sm);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.pdf-arrow-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.pdf-arrow-btn:active {
  background: rgba(255, 255, 255, 0.3);
}

.pdf-arrow-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

/* Page indicator */
.pdf-page-info {
  color: white;
  font-size: var(--font-size-sm);
  text-align: center;
  background: rgba(0, 0, 0, 0.6);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-lg);
  min-width: 90px;
}

/* Loading spinner */
.pdf-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: pdf-spin 0.8s linear infinite;
}

@keyframes pdf-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 640px) {
  .pdf-modal {
    padding: calc(var(--space-sm) + env(safe-area-inset-top, 0px))
             0
             var(--space-sm)
             0;
  }

  .pdf-pages-wrapper {
    height: calc(100vh - 80px - env(safe-area-inset-bottom, 0px));
  }

  .pdf-arrow-btn {
    width: 32px;
    height: 32px;
    font-size: 1.2rem;
  }
}
