/* Front-end & admin preview */
.gallery-grid {
  --acg-gap: 16px;
  --acg-radius: 22px;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--acg-gap);
  align-items: stretch;
  opacity: 0;
  animation: fadeInGrid 0.6s ease-out forwards;
  box-sizing: border-box;
}

/* Reset untuk figure dan img */
.gallery-grid figure {
  margin: 0;
  padding: 0;
  border: none;
  outline: none;
}

.gallery-grid img {
  max-width: none;
  max-height: none;
}

.gallery-grid .acg-link {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  text-decoration: none;
  border: none;
  outline: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

@keyframes fadeInGrid {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.gallery-grid .gallery-item {
  grid-column: span 4;
  position: relative;
  overflow: hidden;
  border-radius: var(--acg-radius);
  -webkit-border-radius: var(--acg-radius);
  -moz-border-radius: var(--acg-radius);
  aspect-ratio: 4 / 3;
  opacity: 0;
  transform: translateY(30px) scale(0.9);
  animation: fadeInItem 0.5s ease-out forwards;
  background: #f8f9fa;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  -webkit-box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  -moz-box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Staggered animation untuk setiap item */
.gallery-grid .gallery-item:nth-child(1) { animation-delay: 0.1s; }
.gallery-grid .gallery-item:nth-child(2) { animation-delay: 0.2s; }
.gallery-grid .gallery-item:nth-child(3) { animation-delay: 0.3s; }
.gallery-grid .gallery-item:nth-child(4) { animation-delay: 0.4s; }
.gallery-grid .gallery-item:nth-child(5) { animation-delay: 0.5s; }
.gallery-grid .gallery-item:nth-child(6) { animation-delay: 0.6s; }
.gallery-grid .gallery-item:nth-child(7) { animation-delay: 0.7s; }
.gallery-grid .gallery-item:nth-child(8) { animation-delay: 0.8s; }
.gallery-grid .gallery-item:nth-child(n+9) { animation-delay: 0.9s; }

@keyframes fadeInItem {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.gallery-grid .gallery-item.is-xl {
  grid-column: span 6;
  aspect-ratio: 16 / 10;
}
.gallery-grid .gallery-item .acg-img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center;
  display: block;
  transition: opacity 0.3s ease, transform 0.3s ease;
  border-radius: inherit;
  -webkit-border-radius: inherit;
  -moz-border-radius: inherit;
  border: none;
  outline: none;
  margin: 0 !important;
  padding: 0 !important;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/* Loading state hanya untuk admin preview */
.acg-preview .gallery-grid .gallery-item .acg-img {
  filter: blur(2px);
  transition: filter 0.3s ease;
}

.acg-preview .gallery-grid .gallery-item .acg-img.loaded {
  filter: blur(0);
}

/* Enhanced hover effects and animations */
.gallery-grid .gallery-item {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
  transform-origin: center;
}

.gallery-grid .gallery-item .acg-link,
.gallery-grid .gallery-item img {
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
  transform-origin: center;
}

.gallery-grid .gallery-item:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
  z-index: 10;
  margin: -2px;
}

.gallery-grid .gallery-item:hover img {
  transform: scale(1.08);
}

/* Mosaic-specific hover effects */
@media (max-width: 640px) {
  .gallery-grid .gallery-item:hover {
    transform: translateY(-2px) scale(1.01);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    z-index: 10;
    margin: -1px;
  }
  
  .gallery-grid .gallery-item:hover img {
    transform: scale(1.05);
  }
}

/* Responsive */
@media (max-width: 1024px) {
  .gallery-grid { grid-template-columns: repeat(8, 1fr); }
  .gallery-grid .gallery-item { grid-column: span 4; }
  .gallery-grid .gallery-item.is-xl { grid-column: span 8; }
}

/* Tablet */
@media (max-width: 768px) {
  .gallery-grid { 
    grid-template-columns: repeat(6, 1fr);
    gap: calc(var(--acg-gap) * 0.8);
  }
  .gallery-grid .gallery-item { 
    grid-column: span 3; 
    aspect-ratio: 4 / 3;
  }
  .gallery-grid .gallery-item.is-xl { 
    grid-column: span 6; 
    aspect-ratio: 16 / 10;
  }
}

/* Mobile - Mosaic Layout */
@media (max-width: 640px) {
  .gallery-grid { 
    grid-template-columns: repeat(4, 1fr);
    gap: calc(var(--acg-gap) * 0.6);
    --acg-radius: calc(var(--acg-radius) * 0.8);
    animation-duration: 0.8s;
    grid-auto-rows: minmax(80px, auto);
    align-items: stretch;
    justify-content: stretch;
    width: 100%;
  }
  
  /* Reset animation delays untuk mobile */
  .gallery-grid .gallery-item {
    animation-delay: 0s;
  }
  
  .gallery-grid .gallery-item:nth-child(1) { animation-delay: 0.1s; }
  .gallery-grid .gallery-item:nth-child(2) { animation-delay: 0.15s; }
  .gallery-grid .gallery-item:nth-child(3) { animation-delay: 0.2s; }
  .gallery-grid .gallery-item:nth-child(4) { animation-delay: 0.25s; }
  .gallery-grid .gallery-item:nth-child(5) { animation-delay: 0.3s; }
  .gallery-grid .gallery-item:nth-child(6) { animation-delay: 0.35s; }
  .gallery-grid .gallery-item:nth-child(7) { animation-delay: 0.4s; }
  .gallery-grid .gallery-item:nth-child(8) { animation-delay: 0.45s; }
  .gallery-grid .gallery-item:nth-child(n+9) { animation-delay: 0.5s; }
  
  /* Mosaic pattern yang lebih rapi untuk mobile */
  .gallery-grid .gallery-item:nth-child(1) { 
    grid-column: span 2; 
    grid-row: span 2;
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(2) { 
    grid-column: span 2; 
    aspect-ratio: 2 / 1;
  }
  .gallery-grid .gallery-item:nth-child(3) { 
    grid-column: span 1; 
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(4) { 
    grid-column: span 1; 
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(5) { 
    grid-column: span 1; 
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(6) { 
    grid-column: span 1; 
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(7) { 
    grid-column: span 2; 
    aspect-ratio: 2 / 1;
  }
  .gallery-grid .gallery-item:nth-child(8) { 
    grid-column: span 2; 
    aspect-ratio: 1 / 1;
  }
  
  /* Pattern yang lebih rapi untuk item selanjutnya */
  .gallery-grid .gallery-item:nth-child(9) {
    grid-column: span 2;
    aspect-ratio: 2 / 1;
  }
  .gallery-grid .gallery-item:nth-child(10) {
    grid-column: span 1;
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(11) {
    grid-column: span 1;
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(12) {
    grid-column: span 2;
    aspect-ratio: 1 / 1;
  }
  
  /* Pattern berulang untuk item 13+ */
  .gallery-grid .gallery-item:nth-child(n+13) {
    grid-column: span 2;
    aspect-ratio: 1 / 1;
  }
  
  /* Memastikan item terakhir mengisi ruang yang tersisa */
  .gallery-grid .gallery-item:last-child {
    grid-column: 1 / -1;
    max-width: 100%;
  }
  
  /* Jika item terakhir adalah item ke-2, 4, 6, 8, 10, 12, dll (genap) */
  .gallery-grid .gallery-item:nth-child(even):last-child {
    grid-column: span 2;
  }
  
  /* Override untuk is-xl di mobile */
  .gallery-grid .gallery-item.is-xl {
    grid-column: span 2 !important;
    grid-row: span 2 !important;
    aspect-ratio: 1 / 1 !important;
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .gallery-grid { 
    gap: calc(var(--acg-gap) * 0.4);
    --acg-radius: calc(var(--acg-radius) * 0.6);
  }
  
  /* Layout yang lebih rapi untuk layar sangat kecil */
  .gallery-grid .gallery-item:nth-child(1) { 
    grid-column: span 2; 
    grid-row: span 2;
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(2) { 
    grid-column: span 2; 
    aspect-ratio: 2 / 1;
  }
  .gallery-grid .gallery-item:nth-child(3) { 
    grid-column: span 1; 
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(4) { 
    grid-column: span 1; 
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(5) { 
    grid-column: span 1; 
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(6) { 
    grid-column: span 1; 
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(7) { 
    grid-column: span 2; 
    aspect-ratio: 2 / 1;
  }
  .gallery-grid .gallery-item:nth-child(8) { 
    grid-column: span 2; 
    aspect-ratio: 1 / 1;
  }
  
  /* Pattern berulang yang rapi */
  .gallery-grid .gallery-item:nth-child(9) {
    grid-column: span 2;
    aspect-ratio: 2 / 1;
  }
  .gallery-grid .gallery-item:nth-child(10) {
    grid-column: span 1;
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(11) {
    grid-column: span 1;
    aspect-ratio: 1 / 1;
  }
  .gallery-grid .gallery-item:nth-child(12) {
    grid-column: span 2;
    aspect-ratio: 1 / 1;
  }
  
  .gallery-grid .gallery-item:nth-child(n+13) {
    grid-column: span 2;
    aspect-ratio: 1 / 1;
  }
}

/* Admin generator */
.acg-preview { 
  background:#fff; 
  padding:8px; 
  border:1px solid #e3e3e3; 
  border-radius:12px; 
  min-height: 200px;
}

.acg-preview .gallery-item { 
  background:#f6f7f7; 
  border: 1px solid #e0e0e0;
}

.acg-notice { 
  background:#fffbe5; 
  border-left:4px solid #ffb900; 
  padding:10px 12px; 
  border-radius: 4px;
  margin: 10px 0;
}

/* Loading state untuk admin preview */
.acg-preview .gallery-item .acg-img {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

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

/* YouTube Video Styles */
.gallery-grid .youtube-item {
  position: relative;
  overflow: hidden;
}

.youtube-embed {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
  background: #000;
}

.youtube-iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: inherit;
  object-fit: cover;
  object-position: center;
  transform: scale(1.5);
  transform-origin: center;
  min-width: 100%;
  min-height: 100%;
}

/* Hide YouTube UI elements */
.youtube-iframe::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: transparent;
  pointer-events: none;
}

/* Hide YouTube controls and buttons */
.youtube-embed iframe {
  pointer-events: auto;
}

/* Additional styling to ensure full coverage */
.youtube-item {
  overflow: hidden !important;
  background: #000;
}

.youtube-embed {
  overflow: hidden !important;
  background: #000;
}

/* Force video to fill container completely */
.youtube-embed iframe {
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) scale(1.5) !important;
  width: 100% !important;
  height: 100% !important;
  min-width: 100% !important;
  min-height: 100% !important;
}

/* Mobile specific iframe positioning */
@media (max-width: 640px) {
  .youtube-embed iframe {
    transform: translate(-50%, -50%) scale(1.8) !important;
  }
}

.youtube-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: transparent;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.youtube-play-indicator {
  background: rgba(0, 0, 0, 0.7);
  border-radius: 50%;
  padding: 8px;
  transition: all 0.3s ease;
}

.youtube-play-indicator svg {
  width: 24px;
  height: 24px;
}

/* Hover effects for YouTube items - disabled overlay */
.gallery-grid .youtube-item:hover .youtube-overlay {
  opacity: 0;
  display: none;
}

.gallery-grid .youtube-item:hover .youtube-play-indicator {
  display: none;
}

/* Click-to-play video styles - no overlay */
.youtube-embed .youtube-overlay {
  opacity: 0;
  display: none;
}

.youtube-embed:hover .youtube-overlay {
  opacity: 0;
  display: none;
}

/* Enhanced hover effects for YouTube items */
.gallery-grid .youtube-item:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
  z-index: 10;
}

/* Mobile responsive for YouTube */
@media (max-width: 640px) {
  .youtube-iframe {
    transform: scale(1.8);
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    min-width: 100%;
    min-height: 100%;
  }
  
  .youtube-embed {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
  }
  
  .youtube-play-indicator {
    padding: 6px;
  }
  
  .youtube-play-indicator svg {
    width: 20px;
    height: 20px;
  }
  
  .gallery-grid .youtube-item:hover {
    transform: translateY(-2px) scale(1.01);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  }
}
