/* Enhanced Gallery Popup Design - Thumbnails at Bottom */

/* Backdrop with animated gradient */
[role="dialog"][class*="fixed"] {
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.96) 0%, rgba(15, 15, 20, 0.96) 50%, rgba(0, 0, 0, 0.96) 100%) !important;
  backdrop-filter: blur(20px) !important;
  animation: fadeInBackdrop 0.4s ease-out !important;
  z-index: 9999 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 2rem !important;
}

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

/* Main popup container - FORCE COLUMN LAYOUT */
[role="dialog"] > div[class*="relative"] {
  max-width: 90vw !important;
  max-height: 90vh !important;
  width: auto !important;
  height: auto !important;
  background: rgba(15, 15, 20, 0.98) !important;
  backdrop-filter: blur(40px) saturate(180%) !important;
  border: 2px solid rgba(220, 38, 38, 0.4) !important;
  border-radius: 24px !important;
  box-shadow: 
    0 25px 80px 0 rgba(0, 0, 0, 0.6),
    0 0 120px rgba(220, 38, 38, 0.4),
    inset 0 1px 2px rgba(255, 255, 255, 0.1) !important;
  animation: popupSlideIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  position: relative !important;
  margin: auto !important;
}

@keyframes popupSlideIn {
  from {
    transform: scale(0.88) translateY(40px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* Header styling */
[role="dialog"] > div > div:first-child {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.98) 0%, rgba(185, 28, 28, 0.98) 100%) !important;
  border-bottom: 2px solid rgba(255, 255, 255, 0.2) !important;
  padding: 1.25rem 2rem !important;
  position: relative !important;
  overflow: hidden !important;
  flex-shrink: 0 !important;
}

/* Animated background pattern for header */
[role="dialog"] > div > div:first-child::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 50%, rgba(255, 255, 255, 0.15) 0%, transparent 50%);
  animation: headerGlow 3s ease-in-out infinite alternate;
  z-index: 0;
}

@keyframes headerGlow {
  from {
    opacity: 0.5;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(10px);
  }
}

/* Header title styling */
[role="dialog"] h2 {
  color: white !important;
  font-weight: 800 !important;
  font-size: 1.875rem !important;
  text-shadow: 0 2px 15px rgba(0, 0, 0, 0.4) !important;
  position: relative !important;
  z-index: 1 !important;
  letter-spacing: -0.02em !important;
  background: linear-gradient(135deg, #ffffff 0%, #fecaca 100%) !important;
  -webkit-background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  background-clip: text !important;
  margin: 0 !important;
}

/* Close button */
[role="dialog"] button[class*="absolute"][class*="top"] {
  background: rgba(255, 255, 255, 0.2) !important;
  backdrop-filter: blur(10px) !important;
  border: 2px solid rgba(255, 255, 255, 0.4) !important;
  border-radius: 14px !important;
  width: 48px !important;
  height: 48px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
  position: absolute !important;
  z-index: 2 !important;
  color: white !important;
  top: 1.25rem !important;
  right: 1.5rem !important;
}

[role="dialog"] button[class*="absolute"][class*="top"]:hover {
  background: rgba(220, 38, 38, 0.9) !important;
  transform: rotate(180deg) scale(1.15) !important;
  box-shadow: 0 6px 25px rgba(220, 38, 38, 0.5) !important;
  border-color: rgba(255, 255, 255, 0.6) !important;
}

/* Main content wrapper - FORCE VERTICAL STACK */
[role="dialog"] > div > div:not(:first-child) {
  flex: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  padding: 1.5rem !important;
  min-height: 0 !important;
}

/* Image area wrapper - contains image and navigation only */
[role="dialog"] > div > div:not(:first-child) > div:first-child {
  flex: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  position: relative !important;
  min-height: 0 !important;
  overflow: visible !important;
}

/* Image container */
[role="dialog"] div[class*="flex-1"] {
  flex: 1 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  overflow: visible !important;
  padding: 0 !important;
  position: relative !important;
  min-height: 0 !important;
  width: 100% !important;
}

/* Main display image */
[role="dialog"] img[class*="max-h"],
[role="dialog"] div[class*="flex-1"] > img {
  max-height: calc(90vh - 340px) !important;
  max-width: calc(90vw - 180px) !important;
  height: auto !important;
  width: auto !important;
  object-fit: contain !important;
  border-radius: 18px !important;
  box-shadow: 
    0 20px 60px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.1),
    0 0 100px rgba(220, 38, 38, 0.25) !important;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
  animation: imageZoomIn 0.6s ease-out !important;
  position: relative !important;
  z-index: 1 !important;
}

@keyframes imageZoomIn {
  from {
    transform: scale(0.92);
    opacity: 0;
    filter: blur(8px);
  }
  to {
    transform: scale(1);
    opacity: 1;
    filter: blur(0);
  }
}

[role="dialog"] img[class*="max-h"]:hover,
[role="dialog"] div[class*="flex-1"] > img:hover {
  transform: scale(1.02) !important;
  box-shadow: 
    0 25px 70px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.15),
    0 0 120px rgba(220, 38, 38, 0.35) !important;
}

/* Navigation buttons - positioned relative to image area */
[role="dialog"] button[class*="bg-white"],
[role="dialog"] button[aria-label*="Previous"],
[role="dialog"] button[aria-label*="Next"] {
  background: rgba(255, 255, 255, 0.98) !important;
  backdrop-filter: blur(12px) !important;
  border: 3px solid rgba(220, 38, 38, 0.5) !important;
  box-shadow: 
    0 8px 30px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.6) !important;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
  width: 64px !important;
  height: 64px !important;
  border-radius: 50% !important;
  position: absolute !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  z-index: 10 !important;
}

[role="dialog"] button[aria-label*="Previous"] {
  left: 1rem !important;
}

[role="dialog"] button[aria-label*="Next"] {
  right: 1rem !important;
}

[role="dialog"] button[class*="bg-white"]:hover,
[role="dialog"] button[aria-label*="Previous"]:hover,
[role="dialog"] button[aria-label*="Next"]:hover {
  background: linear-gradient(135deg, rgba(220, 38, 38, 1) 0%, rgba(185, 28, 28, 1) 100%) !important;
  border-color: rgba(255, 255, 255, 0.7) !important;
  transform: translateY(-50%) scale(1.2) !important;
  box-shadow: 
    0 12px 50px rgba(220, 38, 38, 0.6),
    0 0 80px rgba(220, 38, 38, 0.5) !important;
}

[role="dialog"] button[aria-label*="Previous"]:hover {
  transform: translateY(-50%) scale(1.2) translateX(-6px) !important;
}

[role="dialog"] button[aria-label*="Next"]:hover {
  transform: translateY(-50%) scale(1.2) translateX(6px) !important;
}

[role="dialog"] button[class*="bg-white"]:hover svg,
[role="dialog"] button[aria-label*="Previous"]:hover svg,
[role="dialog"] button[aria-label*="Next"]:hover svg {
  color: white !important;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.4)) !important;
}

/* Counter badge - below image */
[role="dialog"] div[class*="text-center"]:not([class*="flex"]) {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.3) 0%, rgba(185, 28, 28, 0.3) 100%) !important;
  backdrop-filter: blur(15px) !important;
  border: 2px solid rgba(220, 38, 38, 0.5) !important;
  border-radius: 14px !important;
  padding: 0.75rem 1.75rem !important;
  color: white !important;
  font-weight: 700 !important;
  font-size: 1.125rem !important;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3) !important;
  animation: counterPulse 2.5s ease-in-out infinite !important;
  margin: 1rem auto !important;
  flex-shrink: 0 !important;
  width: fit-content !important;
  position: relative !important;
  z-index: 1 !important;
}

@keyframes counterPulse {
  0%, 100% {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3), 0 0 30px rgba(220, 38, 38, 0.4);
    border-color: rgba(220, 38, 38, 0.5);
  }
  50% {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3), 0 0 50px rgba(220, 38, 38, 0.7);
    border-color: rgba(220, 38, 38, 0.7);
  }
}

/* Thumbnail strip container - FORCE TO BOTTOM */
[role="dialog"] > div > div:not(:first-child) > div:last-child {
  flex-shrink: 0 !important;
  width: 100% !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  position: relative !important;
  z-index: 1 !important;
  background: rgba(15, 15, 20, 0.9) !important;
  border-radius: 12px !important;
  padding: 1rem !important;
  margin-top: 1rem !important;
  display: block !important;
}

/* Thumbnail strip - HORIZONTAL ROW */
[role="dialog"] [class*="flex"][class*="gap"] {
  display: flex !important;
  flex-direction: row !important;
  gap: 1rem !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: flex-start !important;
  padding: 0 !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  width: 100% !important;
}

/* Individual thumbnails */
[role="dialog"] [class*="flex"][class*="gap"] img {
  border: 3px solid rgba(255, 255, 255, 0.25) !important;
  border-radius: 12px !important;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
  cursor: pointer !important;
  min-width: 120px !important;
  min-height: 80px !important;
  max-width: 140px !important;
  max-height: 95px !important;
  width: 120px !important;
  height: 80px !important;
  object-fit: cover !important;
  flex-shrink: 0 !important;
  display: block !important;
}

[role="dialog"] [class*="flex"][class*="gap"] img:hover {
  border-color: rgba(220, 38, 38, 0.9) !important;
  transform: translateY(-5px) scale(1.08) !important;
  box-shadow: 0 12px 35px rgba(220, 38, 38, 0.5) !important;
}

/* Active thumbnail */
[role="dialog"] [class*="flex"][class*="gap"] img[class*="ring"],
[role="dialog"] [class*="flex"][class*="gap"] img[class*="border-red"] {
  border-color: rgb(220, 38, 38) !important;
  border-width: 4px !important;
  box-shadow: 
    0 0 0 4px rgba(220, 38, 38, 0.4),
    0 12px 35px rgba(220, 38, 38, 0.6) !important;
  transform: scale(1.06) !important;
}

/* Scrollbar styling */
[role="dialog"] *::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

[role="dialog"] *::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}

[role="dialog"] *::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.8) 0%, rgba(185, 28, 28, 0.8) 100%);
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.1);
}

[role="dialog"] *::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, rgba(220, 38, 38, 1) 0%, rgba(185, 28, 28, 1) 100%);
}

/* Outer glow effect */
[role="dialog"] > div[class*="relative"]::after {
  content: '';
  position: absolute;
  top: -3px;
  left: -3px;
  right: -3px;
  bottom: -3px;
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.4), rgba(185, 28, 28, 0.4));
  border-radius: 24px;
  z-index: -1;
  filter: blur(25px);
  opacity: 0.7;
  animation: glowPulse 3s ease-in-out infinite alternate;
}

@keyframes glowPulse {
  from {
    opacity: 0.5;
  }
  to {
    opacity: 0.9;
  }
}

/* Responsive adjustments */
@media (max-width: 1200px) {
  [role="dialog"] > div [class*="relative"] {
    max-width: 85vw !important;
    max-height: 85vh !important;
  }
  
  [role="dialog"] img[class*="max-h"],
  [role="dialog"] div[class*="flex-1"] > img {
    max-height: calc(85vh - 320px) !important;
    max-width: calc(85vw - 160px) !important;
  }
}

@media (max-width: 768px) {
  [role="dialog"][class*="fixed"] {
    padding: 1rem !important;
  }
  
  [role="dialog"] > div[class*="relative"] {
    border-radius: 16px !important;
    max-width: 95vw !important;
    max-height: 95vh !important;
  }
  
  [role="dialog"] h2 {
    font-size: 1.375rem !important;
  }
  
  [role="dialog"] img[class*="max-h"],
  [role="dialog"] div[class*="flex-1"] > img {
    max-height: calc(95vh - 340px) !important;
    max-width: calc(95vw - 100px) !important;
  }
  
  [role="dialog"] button[aria-label*="Previous"],
  [role="dialog"] button[aria-label*="Next"] {
    width: 52px !important;
    height: 52px !important;
  }
  
  [role="dialog"] button[aria-label*="Previous"] {
    left: 0.5rem !important;
  }
  
  [role="dialog"] button[aria-label*="Next"] {
    right: 0.5rem !important;
  }
  
  [role="dialog"] [class*="flex"][class*="gap"] img {
    min-width: 100px !important;
    min-height: 70px !important;
    max-width: 120px !important;
    max-height: 85px !important;
    width: 100px !important;
    height: 70px !important;
  }
}


/* CRITICAL: Force thumbnails outside of image container */
[role="dialog"] > div > div:not(:first-child) > * {
  position: relative !important;
}

/* Ensure thumbnail container is absolutely at the bottom */
[role="dialog"] > div > div:not(:first-child) > div:has([class*="flex"][class*="gap"]) {
  position: relative !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  flex-shrink: 0 !important;
  order: 999 !important;
}

/* Force image and navigation to stay in their area */
[role="dialog"] > div > div:not(:first-child) > div:not(:has([class*="flex"][class*="gap"])) {
  position: relative !important;
  order: 1 !important;
}

/* Prevent any absolute positioning on thumbnails that could cause overlap */
[role="dialog"] [class*="flex"][class*="gap"],
[role="dialog"] [class*="flex"][class*="gap"] > * {
  position: relative !important;
  left: auto !important;
  right: auto !important;
  top: auto !important;
  bottom: auto !important;
}

/* Ensure counter stays between image and thumbnails */
[role="dialog"] div[class*="text-center"]:not([class*="flex"]) {
  order: 2 !important;
  position: relative !important;
}


/* COUNTER FIX: Position counter BELOW thumbnails */
[role="dialog"] div[class*="text-center"]:not([class*="flex"]) {
  display: block !important;
  position: relative !important;
  order: 1000 !important;
  margin: 1rem auto 1.5rem auto !important;
  padding: 0.8rem 2rem !important;
  font-size: 1.25rem !important;
  font-weight: 700 !important;
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.4) 0%, rgba(185, 28, 28, 0.4) 100%) !important;
  border: 2px solid rgba(220, 38, 38, 0.7) !important;
  border-radius: 15px !important;
  box-shadow: 
    0 4px 15px rgba(0, 0, 0, 0.3),
    0 0 30px rgba(220, 38, 38, 0.4) !important;
  text-align: center !important;
  width: fit-content !important;
  min-width: 120px !important;
  z-index: 100 !important;
  left: 0 !important;
  right: 0 !important;
  top: auto !important;
  bottom: auto !important;
}

/* Ensure counter text is visible */
[role="dialog"] div[class*="text-center"]:not([class*="flex"]) * {
  color: white !important;
  font-size: inherit !important;
  font-weight: inherit !important;
}
