/* Photo Gallery */
.photo-gallery {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  width: 360px;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: gallerySlideIn 0.5s ease;
}

.photo-gallery:hover {
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  transform: translateY(-2px);
}

@keyframes gallerySlideIn {
  from {
    transform: translateX(100px) translateY(100px);
    opacity: 0;
  }
  to {
    transform: translateX(0) translateY(0);
    opacity: 1;
  }
}

/* Gallery Header */
.gallery-header {
  margin-bottom: 12px;
}

.gallery-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 4px 0;
  color: #333;
}

.gallery-description {
  font-size: 0.85rem;
  color: #666;
  margin: 0;
}

/* Main image container */
.gallery-main {
  position: relative;
  width: 100%;
  height: 200px;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
  background: #f0f2f5;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.gallery-main a {
  display: block;
  width: 100%;
  height: 100%;
  text-decoration: none;
}

.gallery-main img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
  display: block;
}

.gallery-main:hover img {
  transform: scale(1.05);
}

.gallery-figure {
  margin: 0;
  position: relative;
  width: 100%;
  height: 100%;
}

.gallery-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 12px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
  color: white;
  font-size: 0.9rem;
  margin: 0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Gallery navigation buttons */
.gallery-nav-controls {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  display: flex;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 2;
}

.gallery-nav-btn {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #2c3e50;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.gallery-nav-btn:hover:not(:disabled) {
  background: white;
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.gallery-nav-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.gallery-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.gallery-nav-btn span.nav-icon svg {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Gallery counter */
.gallery-counter {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  backdrop-filter: blur(4px);
  z-index: 2;
}

/* Thumbnails container */
.gallery-thumbnails-container {
  position: relative;
  width: 100%;
}

.gallery-thumbnails {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  max-height: 100px;
  overflow-x: auto;
  scroll-behavior: smooth;
  padding: 4px 0;
}

/* Hide scrollbar but keep functionality */
.gallery-thumbnails::-webkit-scrollbar {
  height: 4px;
}

.gallery-thumbnails::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.gallery-thumbnails::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

.gallery-thumbnails::-webkit-scrollbar-thumb:hover {
  background: #555;
}

.gallery-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  padding: 0;
  background: none;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  min-width: 70px;
}

.gallery-thumb:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.gallery-thumb.active {
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.3);
}

.thumb-wrapper {
  width: 100%;
  height: 100%;
  position: relative;
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
  display: block;
}

.gallery-thumb:hover img {
  transform: scale(1.1);
}

.thumb-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.gallery-thumb:hover .thumb-overlay {
  opacity: 1;
}

.gallery-thumb.active .thumb-overlay {
  opacity: 0;
}

/* Thumb scroll controls */
.thumb-scroll-controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

.thumb-scroll-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: #333;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  transition: all 0.2s ease;
}

.thumb-scroll-btn:hover {
  background: white;
  transform: scale(1.1);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

/* Modal Styles */
.gallery-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.3s ease;
}

.gallery-modal[hidden] {
  display: none;
}

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

.modal-content {
  width: 90%;
  height: 90%;
  display: flex;
  flex-direction: column;
  background: transparent;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  color: white;
}

.modal-title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 400;
}

.modal-close {
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.modal-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 0;
}

.modal-image-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal-nav {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
  pointer-events: none;
}

.modal-nav-btn {
  width: 50px;
  height: 50px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: white;
  font-size: 2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  pointer-events: auto;
}

.modal-nav-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.modal-info {
  padding: 20px;
  text-align: center;
  color: white;
}

.modal-caption {
  margin: 0 0 8px 0;
  font-size: 1rem;
}

.modal-counter {
  font-size: 0.9rem;
  opacity: 0.8;
}

/* Loading indicator */
.gallery-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
}

.gallery-loading[hidden] {
  display: none;
}

.spinner {
  display: inline-block;
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #3498db;
  animation: spin 1s ease-in-out infinite;
}

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

/* Empty state */
.photo-gallery-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
}

.gallery-empty {
  text-align: center;
  color: #666;
  font-style: italic;
}

/* Responsive design */
@media (max-width: 768px) {
  .photo-gallery {
    bottom: 10px;
    right: 10px;
    width: 280px;
    padding: 12px;
  }

  .gallery-main {
    height: 160px;
  }

  .gallery-thumbnails {
    gap: 6px;
  }

  .gallery-thumb {
    min-width: 60px;
  }

  .gallery-nav-btn {
    width: 30px;
    height: 30px;
  }

  .modal-nav-btn {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
  }

  .modal-title {
    font-size: 1.1rem;
  }
}

@media (max-width: 480px) {
  .photo-gallery {
    width: calc(100% - 20px);
    max-width: 300px;
    left: 50%;
    transform: translateX(-50%);
    right: auto;
  }

  .photo-gallery:hover {
    transform: translateX(-50%) translateY(-2px);
  }

  @keyframes gallerySlideIn {
    from {
      transform: translateX(-50%) translateY(100px);
      opacity: 0;
    }
    to {
      transform: translateX(-50%) translateY(0);
      opacity: 1;
    }
  }

  .gallery-main {
    height: 180px;
  }

  .modal-nav {
    padding: 0 10px;
  }

  .modal-nav-btn {
    width: 35px;
    height: 35px;
    font-size: 1.2rem;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .photo-gallery {
    background: rgba(30, 30, 30, 0.98);
    border-color: rgba(255, 255, 255, 0.1);
  }

  .gallery-title {
    color: #e0e0e0;
  }

  .gallery-description {
    color: #a0a0a0;
  }

  .gallery-main {
    background: #2d2d2d;
  }

  .gallery-nav-btn {
    background: rgba(50, 50, 50, 0.9);
    color: #e0e0e0;
    border-color: rgba(255, 255, 255, 0.1);
  }

  .gallery-nav-btn:hover:not(:disabled) {
    background: #404040;
  }

  .gallery-thumb {
    border-color: #404040;
  }

  .gallery-thumb.active {
    border-color: #3498db;
  }

  .gallery-caption {
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, transparent 100%);
  }

  .gallery-counter {
    background: rgba(0, 0, 0, 0.8);
  }

  .thumb-scroll-btn {
    background: rgba(50, 50, 50, 0.9);
    color: #e0e0e0;
  }

  .thumb-scroll-btn:hover {
    background: #404040;
  }
}


/* Debug: mostra che l'immagine è cliccabile */
.gallery-main-image {
  cursor: pointer;
}

.gallery-main-image:hover {
  opacity: 0.95;
  transition: opacity 0.2s ease;
}



/* Gallery fly-to notification */
.gallery-flyto-notification {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 500;
  z-index: 10001;
  transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  pointer-events: none;
  white-space: nowrap;
  font-family: sans-serif;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
}

.gallery-flyto-notification.show {
  transform: translateX(-50%) translateY(0);
}

.gallery-flyto-notification.error {
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
}

.gallery-flyto-notification::before {
  content: '📍';
  margin-right: 8px;
  display: inline-block;
}

/* Indica che l'immagine è cliccabile */
.gallery-main-image {
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.gallery-main-image:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.gallery-main-image:active {
  transform: scale(0.98);
}

/* Popup styling */
.gallery-flyto-popup {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  padding: 8px 12px;
}

.gallery-flyto-popup::before {
  content: '';
  margin-right: 8px;
  font-size: 16px;
}
