/**
 * PhotoCapture Component Styles
 * Square viewfinder camera capture with native feel
 *
 * US-406: Square Photo Viewfinder
 * US-408: Photo Control Placement
 * US-412: Camera Native Feel
 */

/* =============================================================================
   Overlay & Container
   ============================================================================= */

.photo-capture-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #000;
  z-index: 10000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* Ensure no browser chrome is visible */
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.photo-capture-overlay.open {
  display: flex;
}

.photo-capture-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* =============================================================================
   Camera View
   ============================================================================= */

.photo-capture-camera {
  position: relative;
  width: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
}

.photo-capture-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(1);
  background: #000;
}

/* Mirror front camera */
.photo-capture-video.front-facing {
  transform: scaleX(-1);
}

/* =============================================================================
   Square Viewfinder (1:1 Aspect Ratio)
   ============================================================================= */

.photo-capture-viewfinder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(90vw, 90vh);
  height: min(90vw, 90vh);
  pointer-events: none;
}

.viewfinder-frame {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: var(--border-radius-md, 8px);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
}

/* Corner marks for viewfinder */
.viewfinder-frame::before,
.viewfinder-frame::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border: 3px solid #fff;
}

.viewfinder-frame::before {
  top: -1px;
  left: -1px;
  border-right: none;
  border-bottom: none;
}

.viewfinder-frame::after {
  bottom: -1px;
  right: -1px;
  border-left: none;
  border-top: none;
}

/* =============================================================================
   Photo Counter
   ============================================================================= */

.photo-capture-counter {
  position: absolute;
  top: var(--space-md, 16px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  padding: var(--space-xs, 4px) var(--space-sm, 8px);
  border-radius: var(--border-radius-sm, 4px);
  font-size: var(--font-size-sm, 12px);
  font-weight: var(--font-weight-semibold, 600);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  /* Account for safe area */
  top: calc(var(--space-md, 16px) + env(safe-area-inset-top, 0px));
}

/* =============================================================================
   Close Button
   ============================================================================= */

.photo-capture-close {
  position: absolute;
  top: var(--space-md, 16px);
  right: var(--space-md, 16px);
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, 0.6);
  border: none;
  border-radius: 50%;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background-color 0.2s ease, transform 0.2s ease;
  /* Account for safe area */
  top: calc(var(--space-md, 16px) + env(safe-area-inset-top, 0px));
  right: calc(var(--space-md, 16px) + env(safe-area-inset-right, 0px));
}

.photo-capture-close:hover,
.photo-capture-close:focus {
  background: rgba(0, 0, 0, 0.8);
  transform: scale(1.05);
  outline: none;
}

.photo-capture-close:active {
  transform: scale(0.95);
}

.photo-capture-close svg {
  width: 20px;
  height: 20px;
}

/* =============================================================================
   Controls Area
   ============================================================================= */

.photo-capture-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--space-lg, 24px);
  padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px)); /* 30-50px from bottom */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-lg, 24px);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.6) 0%, transparent 100%);
}

/* =============================================================================
   Shutter Button (60px at bottom center)
   ============================================================================= */

.shutter-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  position: relative;
}

.shutter-button-inner {
  width: 80%;
  height: 80%;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.1s ease;
}

.shutter-button:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.shutter-button:active {
  transform: scale(0.95);
}

.shutter-button:active .shutter-button-inner {
  transform: scale(0.9);
}

.shutter-button:focus {
  outline: 2px solid var(--papyrus-gold, #f5e6d3);
  outline-offset: 4px;
}

.shutter-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* =============================================================================
   Done Button
   ============================================================================= */

.done-button {
  position: absolute;
  right: var(--space-lg, 24px);
  padding: 12px 20px;
  border-radius: 9999px; /* Fully rounded pill shape */
  background: var(--green-grade, #71B956);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 400; /* Lighter weight */
  transition: transform 0.2s ease, background-color 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.done-button:hover,
.done-button:focus {
  transform: scale(1.05);
  background: #5fa348;
  outline: none;
}

.done-button:active {
  transform: scale(0.98);
}

.done-button.hidden {
  display: none;
}

.done-button svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.done-button-text {
  white-space: nowrap;
}

/* =============================================================================
   Hidden Canvas (for processing)
   ============================================================================= */

.photo-capture-canvas {
  position: absolute;
  top: -9999px;
  left: -9999px;
  visibility: hidden;
  pointer-events: none;
}

/* =============================================================================
   Error Display
   ============================================================================= */

.photo-capture-error {
  position: absolute;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--red-grade, #D63B3B);
  color: #fff;
  padding: var(--space-md, 16px);
  border-radius: var(--border-radius-md, 8px);
  font-size: var(--font-size-sm, 12px);
  text-align: center;
  max-width: 80%;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm, 8px);
}

.photo-capture-error.visible {
  opacity: 1;
  visibility: visible;
}

.error-message {
  margin-bottom: var(--space-xs, 4px);
}

.error-actions {
  display: none;
  flex-direction: column;
  gap: var(--space-xs, 4px);
  margin-top: var(--space-xs, 4px);
}

.retry-button,
.file-upload-button {
  padding: var(--space-xs, 4px) var(--space-sm, 8px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: var(--border-radius-sm, 4px);
  cursor: pointer;
  font-size: var(--font-size-sm, 12px);
  font-weight: var(--font-weight-semibold, 600);
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.retry-button:hover,
.file-upload-button:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.retry-button:active,
.file-upload-button:active {
  transform: translateY(0);
}

/* =============================================================================
   Loading State
   ============================================================================= */

.photo-capture-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md, 16px);
  color: #fff;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.photo-capture-loading.visible {
  opacity: 1;
  visibility: visible;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* =============================================================================
   Shutter Flash Effect
   ============================================================================= */

.photo-capture-overlay.shutter-flash::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  animation: flash 0.1s ease-out;
  pointer-events: none;
}

@keyframes flash {
  from {
    opacity: 0.8;
  }
  to {
    opacity: 0;
  }
}

/* =============================================================================
   Responsive Adjustments
   ============================================================================= */

/* Landscape orientation */
@media (orientation: landscape) {
  .photo-capture-viewfinder {
    width: min(70vh, 70vw);
    height: min(70vh, 70vw);
  }

  .photo-capture-controls {
    padding-bottom: calc(30px + env(safe-area-inset-bottom, 0px));
  }
}

/* Tablet and larger */
@media (min-width: 768px) {
  .photo-capture-viewfinder {
    width: min(60vw, 60vh);
    height: min(60vw, 60vh);
    max-width: 500px;
    max-height: 500px;
  }

  .shutter-button {
    width: 70px;
    height: 70px;
  }

  .photo-capture-counter {
    font-size: var(--font-size-base, 14px);
    padding: var(--space-sm, 8px) var(--space-md, 16px);
  }
}

/* =============================================================================
   Dark Mode Support
   ============================================================================= */

@media (prefers-color-scheme: dark) {
  .photo-capture-overlay {
    background: #000;
  }
}

/* =============================================================================
   Reduced Motion Support
   ============================================================================= */

@media (prefers-reduced-motion: reduce) {
  .shutter-button,
  .done-button,
  .photo-capture-close {
    transition: none;
  }

  .loading-spinner {
    animation: none;
  }

  @keyframes flash {
    from, to {
      opacity: 0;
    }
  }
}

/* =============================================================================
   High Contrast Mode
   ============================================================================= */

@media (forced-colors: active) {
  .viewfinder-frame {
    border-color: CanvasText;
  }

  .shutter-button {
    border-color: CanvasText;
    background: Canvas;
  }

  .done-button {
    background: Highlight;
    color: HighlightText;
  }
}
