/**
 * Paws Image Modal Styles - Responsive pet image display
 * Follows native modal patterns with image-specific optimizations
 */

/* Base Paws Modal Container */
.paws-image-modal {
  --modal-bg: var(--site-bg, #ffffff);
  --modal-text: var(--site-text, #000000);
  --modal-text-rgb: var(--site-text-rgb, 0, 0, 0);
  --scrim-bg: rgba(0, 0, 0, 0.8); /* Darker for image viewing */
  --border-radius: 12px;
  --elevation-shadow: 0 8px 32px rgba(0, 0, 0, 0.24);
  --animation-duration: 250ms;
  --animation-easing: cubic-bezier(0.4, 0.0, 0.2, 1);
  
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000; /* Higher than control gutter (z-index: 100000) */
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--animation-duration) var(--animation-easing);
  
  /* Prevent body scroll when modal is open */
  overflow: hidden;
}

/* Modal visible state */
.paws-image-modal.paws-modal-visible {
  pointer-events: auto;
  opacity: 1;
}

/* Material Design Backdrop/Scrim - Darker for image viewing */
.paws-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--scrim-bg);
  pointer-events: auto;
  cursor: pointer;
  transition: opacity var(--animation-duration) var(--animation-easing);
}

/* Modal Container - Centered and Responsive */
.paws-modal-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  max-width: 95vw;
  max-height: 95vh;
  pointer-events: auto;
  outline: none;
  transition: transform var(--animation-duration) var(--animation-easing);
  
  /* Ensure proper touch handling */
  touch-action: manipulation;
  
  /* Prevent accidental text selection */
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

/* Container visible state */
.paws-modal-visible .paws-modal-container {
  transform: translate(-50%, -50%) scale(1);
}

/* Responsive Image Styles - The heart of the system */
.paws-modal-image {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  
  /* Responsive constraints for different image orientations */
  min-width: 200px; /* Ensure readability for very small images */
  min-height: 150px;
  
  /* Maintain aspect ratio and center */
  object-fit: contain;
  object-position: center;
  
  /* Smooth loading transition */
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
  
  /* Rounded corners for polish */
  border-radius: var(--border-radius);
  
  /* Subtle shadow for depth */
  box-shadow: var(--elevation-shadow);
  
  /* Ensure crisp rendering */
  image-rendering: auto;
  image-rendering: -webkit-optimize-contrast;
}

/* Image loaded state */
.paws-modal-image[style*="opacity: 1"] {
  opacity: 1;
}

/* Error Message Container */
.paws-error-message {
  background-color: var(--modal-bg);
  color: var(--modal-text);
  padding: 2rem;
  border-radius: var(--border-radius);
  box-shadow: var(--elevation-shadow);
  text-align: center;
  max-width: 400px;
  margin: 0 auto;
}

.paws-error-message h3 {
  margin: 0 0 1rem 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #ef4444; /* Red for error */
}

.paws-error-message p {
  margin: 0 0 1.5rem 0;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--modal-text);
  opacity: 0.8;
}

/* Error Close Button */
.paws-error-button {
  background-color: #ef4444;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px; /* Touch target size */
  min-width: 44px;
  touch-action: manipulation;
}

.paws-error-button:hover {
  background-color: #dc2626;
  transform: translateY(-1px);
}

.paws-error-button:active {
  transform: translateY(0);
}

/* Responsive Design - Tablet and Desktop */
@media (min-width: 768px) {
  .paws-modal-container {
    max-width: 90vw;
    max-height: 90vh;
  }
  
  .paws-modal-image {
    /* Allow larger images on bigger screens */
    min-width: 300px;
    min-height: 200px;
  }
}

/* Responsive Design - Large Desktop */
@media (min-width: 1200px) {
  .paws-modal-container {
    max-width: 85vw;
    max-height: 85vh;
  }
  
  .paws-modal-image {
    /* Even larger on big screens */
    min-width: 400px;
    min-height: 300px;
  }
}

/* Mobile Specific Optimizations */
@media (max-width: 768px) {
  .paws-modal-container {
    max-width: 98vw;
    max-height: 98vh;
  }
  
  .paws-modal-image {
    /* Smaller minimum on mobile for very small images */
    min-width: 150px;
    min-height: 100px;
  }
  
  .paws-error-message {
    padding: 1.5rem;
    margin: 1rem;
  }
}

/* Portrait vs Landscape Image Handling */
@media (orientation: portrait) {
  .paws-modal-image {
    /* Optimize for portrait orientation */
    max-height: 80vh;
    width: auto;
  }
}

@media (orientation: landscape) {
  .paws-modal-image {
    /* Optimize for landscape orientation */
    max-width: 80vw;
    height: auto;
  }
}

/* iOS Safe Area Support */
@supports (padding: max(0px)) {
  .paws-modal-container {
    /* Account for safe areas on iOS devices */
    max-height: calc(95vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-width: calc(95vw - env(safe-area-inset-left) - env(safe-area-inset-right));
  }
}

/* High Contrast Mode Support (Accessibility) */
@media (prefers-contrast: high) {
  .paws-modal-backdrop {
    background-color: rgba(0, 0, 0, 0.95);
  }
  
  .paws-modal-image {
    box-shadow: 0 0 0 2px var(--modal-text);
  }
  
  .paws-error-message {
    border: 2px solid var(--modal-text);
  }
}

/* Reduced Motion Support (Accessibility) */
@media (prefers-reduced-motion: reduce) {
  .paws-image-modal,
  .paws-modal-container,
  .paws-modal-image,
  .paws-error-button {
    transition-duration: 0.01ms !important;
  }
}

/* Focus Indicators (Accessibility) */
.paws-image-modal:focus-visible {
  outline: 2px solid var(--focus-color, #2563eb);
  outline-offset: -2px;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .paws-image-modal {
    --modal-bg: var(--site-bg-dark, #1a1a1a);
    --modal-text: var(--site-text-dark, #ffffff);
    --modal-text-rgb: var(--site-text-rgb-dark, 255, 255, 255);
    --scrim-bg: rgba(0, 0, 0, 0.9); /* Even darker for dark mode */
  }
}

/* Theme Integration */
.paws-image-modal.theme-dark {
  --modal-bg: var(--site-bg-dark, #1a1a1a);
  --modal-text: var(--site-text-dark, #ffffff);
  --modal-text-rgb: var(--site-text-rgb-dark, 255, 255, 255);
  --scrim-bg: rgba(0, 0, 0, 0.9);
}

/* Prevent Body Scroll When Modal Open */
body:has(.paws-image-modal.paws-modal-visible) {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* Fallback for browsers without :has() support */
body.paws-modal-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* Loading State Overlay */
.paws-modal-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 1.1rem;
  font-weight: 500;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

/* Print Styles (Hide modals in print) */
@media print {
  .paws-image-modal {
    display: none !important;
  }
}

/* Very Large Images - Zoom Behavior */
@media (min-width: 1600px) {
  .paws-modal-image {
    /* Allow very large images to use more screen space */
    max-width: 75vw;
    max-height: 75vh;
  }
}

/* Touch Optimization for Image Interaction */
.paws-modal-image {
  /* Prevent accidental zoom/pan on touch devices */
  touch-action: manipulation;
  -webkit-touch-callout: none;
  
  /* Ensure smooth scrolling if image overflows */
  -webkit-overflow-scrolling: touch;
}

/* Control gutter group spacing for paws toggles - match canonical control gutter gap */
.get-paws-toggles-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem; /* same gap used in .control-gutter regions */
  align-items: center;
}

/* Ensure paw toggles inherit the canonical .theme-toggle sizing and pointer behavior */
.get-paws-toggles-group .get-paws-toggle,
.get-paws-toggles-group .theme-toggle {
  pointer-events: auto;
  width: var(--theme-toggle-size, 3rem);
  height: var(--theme-toggle-size, 3rem);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Align icon containers so spacing matches other toggles */
.get-paws-toggles-group .get-paws-toggle-icon {
  width: calc(var(--theme-toggle-size, 3rem) * 0.85);
  height: calc(var(--theme-toggle-size, 3rem) * 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Animation Performance Optimization */
.paws-image-modal * {
  /* Use GPU acceleration for smooth animations */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  will-change: transform, opacity;
}

/* Remove will-change after animation completes */
.paws-modal-visible * {
  will-change: auto;
}