/**
 * AR Edilizia - Modern Gallery Grid Layout
 * Professional grid layout for desktop, carousel for mobile
 *
 * Design Philosophy:
 * - Desktop: Hero image + grid of remaining images
 * - Mobile: Full-screen carousel
 * - All images clickable to open lightbox
 *
 * @version 2.0
 * @date October 18, 2025
 */

/* ========================================
   GALLERY SECTION
   ======================================== */
.project-gallery-modern {
  width: 100%;
  background: var(--detail-bg-primary, #0f172a);
  padding: 0;
  margin: 4rem 0;
}

.project-gallery-modern .container {
  padding: 2rem 1.5rem;
}

/* ========================================
   DESKTOP GRID LAYOUT
   ======================================== */
@media (min-width: 769px) {
  /* Hide carousel on desktop */
  .gallery-carousel-mobile {
    display: none;
  }

  /* Show grid on desktop */
  .gallery-grid-desktop {
    display: block;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 2rem;
  }

  /* Grid Container */
  .gallery-grid-container {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(3, 300px);
    gap: 1rem;
    margin-top: 2rem;
  }

  /* Hero Image - Large Feature */
  .gallery-grid-hero {
    grid-column: 1 / 8;
    grid-row: 1 / 3;
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    cursor: pointer;
    background: #000;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
  }

  .gallery-grid-hero:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 40px rgba(14, 165, 233, 0.3);
  }

  .gallery-grid-hero img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: transform 0.6s ease;
  }

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

  /* Secondary Image - Medium */
  .gallery-grid-secondary {
    grid-column: 8 / 13;
    grid-row: 1 / 2;
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    cursor: pointer;
    background: #000;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
  }

  .gallery-grid-secondary:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(14, 165, 233, 0.25);
  }

  .gallery-grid-secondary img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: transform 0.6s ease;
  }

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

  /* Thumbnail Grid Items */
  .gallery-grid-thumb {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    cursor: pointer;
    background: #000;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
  }

  .gallery-grid-thumb:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(14, 165, 233, 0.2);
  }

  .gallery-grid-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: transform 0.6s ease;
  }

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

  /* Specific Grid Positions */
  .gallery-grid-thumb:nth-child(3) {
    grid-column: 8 / 10;
    grid-row: 2 / 3;
  }

  .gallery-grid-thumb:nth-child(4) {
    grid-column: 10 / 12;
    grid-row: 2 / 3;
  }

  .gallery-grid-thumb:nth-child(5) {
    grid-column: 12 / 13;
    grid-row: 2 / 3;
  }

  .gallery-grid-thumb:nth-child(6) {
    grid-column: 1 / 4;
    grid-row: 3 / 4;
  }

  .gallery-grid-thumb:nth-child(7) {
    grid-column: 4 / 7;
    grid-row: 3 / 4;
  }

  /* "View More" Overlay */
  .gallery-grid-more {
    grid-column: 7 / 13;
    grid-row: 3 / 4;
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    cursor: pointer;
    background: #000;
  }

  .gallery-grid-more img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    filter: brightness(0.4);
    transition: all 0.6s ease;
  }

  .gallery-grid-more:hover img {
    filter: brightness(0.5);
    transform: scale(1.05);
  }

  .gallery-grid-more-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    color: #fff;
    transition: background 0.3s ease;
  }

  .gallery-grid-more:hover .gallery-grid-more-overlay {
    background: rgba(14, 165, 233, 0.3);
  }

  .gallery-grid-more-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
  }

  .gallery-grid-more-text {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
  }

  .gallery-grid-more-subtext {
    font-size: 1rem;
    opacity: 0.9;
  }

  /* Image Captions */
  .gallery-grid-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1.5rem;
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0) 100%);
    color: #fff;
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
  }

  .gallery-grid-hero:hover .gallery-grid-caption,
  .gallery-grid-secondary:hover .gallery-grid-caption,
  .gallery-grid-thumb:hover .gallery-grid-caption {
    opacity: 1;
  }
}

/* ========================================
   MOBILE CAROUSEL
   ======================================== */
@media (max-width: 768px) {
  /* Hide grid on mobile */
  .gallery-grid-desktop {
    display: none;
  }

  /* Show carousel on mobile */
  .gallery-carousel-mobile {
    display: block;
  }

  /* Full-width carousel */
  .mobile-carousel {
    position: relative;
    width: 100vw;
    margin-left: calc(-50vw + 50%);
    height: 70vh;
    min-height: 450px;
    max-height: 600px;
    overflow: hidden;
    background: #000;
  }

  .mobile-carousel-track {
    position: relative;
    width: 100%;
    height: 100%;
  }

  .mobile-carousel-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.6s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .mobile-carousel-slide.active {
    opacity: 1;
    visibility: visible;
    z-index: 1;
  }

  .mobile-carousel-slide img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Full-screen on mobile */
    object-position: center;
  }

  /* Mobile Navigation */
  .mobile-carousel-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }

  .mobile-carousel-prev {
    left: 1rem;
  }

  .mobile-carousel-next {
    right: 1rem;
  }

  /* Mobile Indicators */
  .mobile-carousel-indicators {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    padding: 0.75rem 1rem;
    border-radius: 50px;
  }

  .mobile-carousel-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
  }

  .mobile-carousel-indicator.active {
    width: 24px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.95);
  }

  /* Mobile Counter */
  .mobile-carousel-counter {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 10;
  }
}

/* ========================================
   RESPONSIVE GRID ADJUSTMENTS
   ======================================== */

/* Large Desktop (1920px+) */
@media (min-width: 1920px) {
  .gallery-grid-container {
    grid-template-rows: repeat(3, 350px);
  }
}

/* Medium Desktop (1200-1920px) */
@media (min-width: 1200px) and (max-width: 1919px) {
  .gallery-grid-container {
    grid-template-rows: repeat(3, 280px);
  }
}

/* Tablet Landscape (769-1199px) */
@media (min-width: 769px) and (max-width: 1199px) {
  .gallery-grid-container {
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(4, 250px);
  }

  .gallery-grid-hero {
    grid-column: 1 / 6;
    grid-row: 1 / 3;
  }

  .gallery-grid-secondary {
    grid-column: 6 / 9;
    grid-row: 1 / 2;
  }

  .gallery-grid-thumb:nth-child(3) {
    grid-column: 6 / 8;
    grid-row: 2 / 3;
  }

  .gallery-grid-thumb:nth-child(4) {
    grid-column: 8 / 9;
    grid-row: 2 / 3;
  }

  .gallery-grid-thumb:nth-child(5) {
    grid-column: 1 / 3;
    grid-row: 3 / 4;
  }

  .gallery-grid-thumb:nth-child(6) {
    grid-column: 3 / 5;
    grid-row: 3 / 4;
  }

  .gallery-grid-thumb:nth-child(7) {
    grid-column: 5 / 7;
    grid-row: 3 / 4;
  }

  .gallery-grid-more {
    grid-column: 7 / 9;
    grid-row: 3 / 4;
  }
}

/* ========================================
   LOADING STATES
   ======================================== */
.gallery-grid-item {
  position: relative;
}

.gallery-grid-item.loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, #1e293b 0%, #334155 50%, #1e293b 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  z-index: 1;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */
.gallery-grid-item:focus {
  outline: 3px solid rgba(14, 165, 233, 0.8);
  outline-offset: 4px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .gallery-grid-item,
  .gallery-grid-item img,
  .mobile-carousel-slide {
    transition: none !important;
    animation: none !important;
  }
}
