/* Grid - uses CSS grid for correct left-to-right, top-to-bottom ordering */
.instagram .instagram-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.instagram .instagram-post {
  display: block;
  position: relative;
  width: 100%;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: none;
  line-height: 0;
  aspect-ratio: 1;
}

.instagram .instagram-post img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease, filter 0.3s ease;
}

.instagram .instagram-post:hover img {
  transform: scale(1.03);
  filter: brightness(0.9);
}

/* Video play icon overlay */
.instagram .instagram-post.is-video::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  background: rgb(0 0 0 / 50%);
  border-radius: 50%;
  pointer-events: none;
}

.instagram .instagram-post.is-video::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-40%, -50%);
  z-index: 1;
  border-style: solid;
  border-width: 8px 0 8px 14px;
  border-color: transparent transparent transparent white;
  pointer-events: none;
}

/* Carousel gallery icon overlay */
.instagram .instagram-post.is-carousel::after {
  content: '';
  position: absolute;
  top: 10px;
  right: 10px;
  width: 20px;
  height: 20px;
  background: rgb(0 0 0 / 50%);
  border-radius: 4px;
  pointer-events: none;
  box-shadow:
    inset -6px -6px 0 -4px white,
    4px 4px 0 -2px rgb(0 0 0 / 50%),
    4px 4px 0 -1px white;
}

.instagram .instagram-view-more {
  display: block;
  margin: 24px auto 0;
  padding: 12px 32px;
  background-color: #5B3E90;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.instagram .instagram-view-more:hover {
  background-color: #3D2066;
}

@media (width >= 600px) {
  .instagram .instagram-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }
}

@media (width >= 900px) {
  .instagram .instagram-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
  }
}

/* Modal */
.instagram-modal::backdrop {
  background-color: rgb(0 0 0 / 80%);
}

.instagram-modal {
  position: fixed;
  width: calc(100vw - 32px);
  max-width: 900px;
  max-height: calc(100dvh - 64px);
  padding: 0;
  border: none;
  border-radius: 12px;
  background: white;
  overflow: hidden;
  opacity: 0;
  animation: instagram-fade-in 0.2s ease forwards;
}

@keyframes instagram-fade-in {
  to { opacity: 1; }
}

.instagram-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgb(0 0 0 / 50%);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.instagram-modal-close:hover {
  background: rgb(0 0 0 / 70%);
}

.instagram-modal-close .close-x {
  position: relative;
  display: block;
  width: 16px;
  height: 16px;
}

.instagram-modal-close .close-x::before,
.instagram-modal-close .close-x::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 2px;
  border-radius: 1px;
  background: white;
}

.instagram-modal-close .close-x::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.instagram-modal-close .close-x::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.instagram-modal-body {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 64px);
}

.instagram-modal-media {
  position: relative;
  flex-shrink: 0;
  max-height: 60vh;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* stylelint-disable-next-line no-descending-specificity */
.instagram-modal-media img,
.instagram-modal-media video {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  display: block;
}

/* Carousel prev/next buttons */
.carousel-prev,
.carousel-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgb(255 255 255 / 85%);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgb(0 0 0 / 20%);
  transition: background 0.2s ease;
}

.carousel-prev { left: 10px; }

.carousel-next { right: 10px; }

.carousel-prev:hover,
.carousel-next:hover {
  background: white;
}

.carousel-prev::after,
.carousel-next::after {
  content: '';
  display: block;
  width: 10px;
  height: 10px;
  border-top: 2px solid #333;
  border-right: 2px solid #333;
}

.carousel-prev::after {
  transform: rotate(-135deg);
  margin-left: 3px;
}

.carousel-next::after {
  transform: rotate(45deg);
  margin-right: 3px;
}

/* Carousel dots */
.carousel-dots {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 1;
}

.carousel-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgb(255 255 255 / 50%);
  cursor: pointer;
  transition: background 0.2s ease;
}

.carousel-dot.active {
  background: white;
}

/* Stats bar */
.instagram-modal-stats {
  display: flex;
  gap: 20px;
  padding: 0 0 16px;
  border-bottom: 1px solid #eee;
  margin-bottom: 16px;
}

.instagram-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #3D2066;
  text-decoration: none;
  font-size: 14px;
  transition: opacity 0.2s ease;
}

.instagram-stat:hover {
  opacity: 0.7;
  color: #3D2066;
}

.instagram-stat svg {
  flex-shrink: 0;
}

.instagram-modal-details {
  padding: 20px 24px 24px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
}

.instagram-modal-caption {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.6;
  color: #3D2066;
  white-space: pre-line;
  overflow-wrap: break-word;
  word-break: break-word;
}

.instagram-modal-actions {
  text-align: center;
}

.instagram-modal-link {
  display: inline-block;
  padding: 10px 24px;
  background-color: #5B3E90;
  color: white !important;
  text-decoration: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: background-color 0.2s ease;
}

.instagram-modal-link:hover {
  background-color: #3D2066;
  color: white !important;
}

@media (width >= 900px) {
  .instagram-modal {
    max-width: 1000px;
  }

  .instagram-modal-body {
    flex-direction: row;
  }

  .instagram-modal-media {
    flex: 1 1 55%;
    max-height: calc(100dvh - 64px);
  }

  /* stylelint-disable-next-line no-descending-specificity */
  .instagram-modal-media img,
  .instagram-modal-media video {
    max-height: calc(100dvh - 64px);
  }

  .instagram-modal-details {
    flex: 1 1 45%;
    min-height: 0;
    padding: 32px;
  }
}

.instagram-section {
  padding: 48px 16px;
  background-color: white;
}

.instagram-section-inner {
  max-width: 1200px;
  margin: 0 auto;
}

.instagram-section-title {
  text-align: center;
  margin: 0 0 32px;
  color: #3D2066;
  font-size: 28px;
  font-weight: 600;
}

@media (width >= 600px) {
  .instagram-section {
    padding: 64px 24px;
  }
}

@media (width >= 900px) {
  .instagram-section {
    padding: 80px 32px;
  }

  .instagram-section-title {
    font-size: 36px;
    margin-bottom: 40px;
  }
}
