/* ============================================
   Adminmatic Gallery Widget
   ============================================ */

/* Container */
.amg-container {
  position: relative;
  width: 100%;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Grid — masonry-style */
.amg-grid {
  display: grid;
  grid-template-columns: repeat(var(--amg-columns, 3), 1fr);
  grid-auto-rows: var(--amg-row-height, 200px);
  grid-auto-flow: dense;
  gap: var(--amg-gap, 8px);
}

/* Grid item */
.amg-item {
  position: relative;
  overflow: hidden;
  border-radius: 4px;
  background: #f0f0f0;
}

/* Square: 1 col × 1 row */
.amg-item.amg-type-square {
  grid-column: span 1;
  grid-row: span 1;
}

/* Portrait: 1 col × 2 rows */
.amg-item.amg-type-portrait {
  grid-column: span 1;
  grid-row: span 2;
}

/* Landscape: 2 cols × 1 row */
.amg-item.amg-type-landscape {
  grid-column: span 2;
  grid-row: span 1;
}

/* Thumbnail */
.amg-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.amg-item:hover .amg-thumb {
  transform: scale(1.05);
}

/* Overlay */
.amg-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.amg-item:hover .amg-overlay {
  opacity: 1;
}

.amg-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.amg-date {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 2px;
}

/* Loader */
.amg-loader {
  display: none;
  justify-content: center;
  padding: 24px 0;
}

.amg-loader.amg-visible {
  display: flex;
}

.amg-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e0e0e0;
  border-top-color: #333;
  border-radius: 50%;
  animation: amg-spin 0.8s linear infinite;
}

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

/* Sentinel (invisible trigger for infinite scroll) */
.amg-sentinel {
  height: 1px;
}

/* Messages */
.amg-message {
  text-align: center;
  padding: 40px 20px;
  color: #666;
  font-size: 16px;
}

.amg-message.amg-error {
  color: #c0392b;
}

.amg-message.amg-all-loaded {
  color: #aaa;
  font-size: 14px;
  padding: 24px 20px;
}

/* ============================================
   Lightbox
   ============================================ */

.amg-lightbox {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.amg-lightbox.amg-open {
  visibility: visible;
  opacity: 1;
}

.amg-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
}

.amg-lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.amg-lightbox-close {
  position: absolute;
  top: -40px;
  right: -8px;
  background: none;
  border: none;
  color: #fff;
  font-size: 32px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  z-index: 1;
}

.amg-lightbox-close:hover {
  color: #ccc;
}

/* Navigation arrows */
.amg-lightbox-prev,
.amg-lightbox-next {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.4);
  border: none;
  color: #fff;
  font-size: 28px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: background 0.2s ease;
}

.amg-lightbox-prev:hover,
.amg-lightbox-next:hover {
  background: rgba(0, 0, 0, 0.7);
}

.amg-lightbox-prev {
  left: 20px;
}

.amg-lightbox-next {
  right: 20px;
}

.amg-lightbox-prev:disabled,
.amg-lightbox-next:disabled {
  opacity: 0.25;
  cursor: default;
}

.amg-lightbox-img {
  max-width: 85vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.amg-lightbox-img.amg-loaded {
  opacity: 1;
}

.amg-lightbox-spinner {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
}

.amg-lightbox-spinner.amg-visible {
  display: flex;
}

.amg-lightbox-spinner .amg-spinner {
  border-color: rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
}

.amg-lightbox-info {
  color: #fff;
  text-align: center;
  padding: 12px 0 0;
  max-width: 600px;
}

.amg-lightbox-title {
  display: block;
  font-size: 16px;
  font-weight: 600;
}

.amg-lightbox-tags {
  display: block;
  font-size: 13px;
  opacity: 0.7;
  margin-top: 4px;
}

/* Grid filler items */
.amg-filler {
  background: #f0f0f0;
  border-radius: 4px;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 1024px) {
  .amg-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .amg-item.amg-type-landscape {
    grid-column: span 2;
  }
}

@media (max-width: 600px) {
  .amg-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: auto;
  }

  .amg-item {
    grid-row: span 1 !important;
    grid-column: span 1 !important;
  }

  .amg-item.amg-type-square {
    aspect-ratio: 1 / 1;
  }

  .amg-item.amg-type-portrait {
    aspect-ratio: 320 / 660;
  }

  .amg-item.amg-type-landscape {
    aspect-ratio: 660 / 320;
  }

  .amg-lightbox-prev,
  .amg-lightbox-next {
    display: none;
  }

  .amg-lightbox-content {
    max-width: 100vw;
    max-height: 100vh;
  }

  .amg-lightbox-img {
    max-width: 100vw;
    max-height: 85vh;
    border-radius: 0;
  }

  .amg-lightbox-close {
    top: -36px;
    right: 4px;
  }
}
