/* ─────────────────────────────────────────────────────────────────────────────
   DΛREΛKT_ UI — MODULE: social.instagram
   Classification : UI Atom | Social Feed | Responsive Grid
   Version        : 2.1.0
   File           : /tools/modules/social.instagram/social.instagram.css
   ───────────────────────────────────────────────────────────────────────────── */

@layer atoms {

/* ─── Tokens ─────────────────────────────────────────────────────────────────── */
:root {
  --social-ig-cols: 4;
  --social-ig-gap: 4px;
  --social-ig-radius: 0;
  --social-ig-caption-bg: rgba(0, 0, 0, 0.65);
  --social-ig-caption-fg: #fff;
  --social-ig-accent: #E1306C;
  --social-ig-accent-hover: #c9245a;
  --social-ig-header-gap: 0.5rem;
  --social-ig-follow-padding: 0.75rem 2rem;
  --social-ig-skeleton-bg: #e8e8e8;
}

/* ─── Wrapper ────────────────────────────────────────────────────────────────── */
.social-ig__wrap {
  display: block;
  width: 100%;
}

/* ─── Header ─────────────────────────────────────────────────────────────────── */
.social-ig__header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--social-ig-header-gap);
  margin-bottom: 1.5rem;
  text-align: center;
}

.social-ig__title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ui-fg, #111);
}

.social-ig__handle {
  display: inline-block;
  font-size: 1rem;
  font-weight: 500;
  color: var(--social-ig-accent);
  text-decoration: none;
  transition: color 0.2s ease;
}

a.social-ig__handle:hover,
a.social-ig__handle:focus-visible {
  color: var(--social-ig-accent-hover);
  text-decoration: underline;
}

/* ─── Grid (default layout) ──────────────────────────────────────────────────── */
.social-ig__grid {
  display: grid;
  grid-template-columns: repeat(var(--social-ig-cols, 4), 1fr);
  grid-auto-rows: 1fr;
  gap: var(--social-ig-gap);
}

/* ─── Layout: Masonry (CSS columns) ──────────────────────────────────────────── */
.social-ig__grid--masonry {
  display: block;
  columns: var(--social-ig-cols, 4);
  column-gap: var(--social-ig-gap);
}

.social-ig__grid--masonry .social-ig__post {
  aspect-ratio: auto;
  break-inside: avoid;
  margin-bottom: var(--social-ig-gap);
}

.social-ig__grid--masonry .social-ig__image {
  height: auto;
}

/* ─── Layout: Carousel (horizontal scroll) ───────────────────────────────────── */
.social-ig__grid--carousel {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  gap: var(--social-ig-gap);
  padding-bottom: 0.5rem;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.social-ig__grid--carousel::-webkit-scrollbar {
  display: none;
}

.social-ig__grid--carousel .social-ig__post {
  flex: 0 0 min(240px, 70vw);
  scroll-snap-align: start;
  aspect-ratio: 1 / 1;
}

/* Carousel navigation */
.social-ig__carousel-nav {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.social-ig__carousel-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 2px solid var(--social-ig-accent);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  color: var(--social-ig-accent);
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}

.social-ig__carousel-btn:hover {
  background: var(--social-ig-accent);
  color: #fff;
}

/* ─── Layout: Highlight (first large, rest in grid) ──────────────────────────── */
.social-ig__grid--highlight {
  display: grid;
  grid-template-columns: repeat(var(--social-ig-cols, 4), 1fr);
  grid-template-rows: auto;
  gap: var(--social-ig-gap);
}

.social-ig__grid--highlight .social-ig__post:first-child {
  grid-column: 1 / 3;
  grid-row: 1 / 3;
}

/* ─── Post Cell ──────────────────────────────────────────────────────────────── */
.social-ig__post {
  position: relative;
  display: block;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  border-radius: var(--social-ig-radius);
  background: var(--ui-bg-muted, #f0f0f0);
  text-decoration: none;
}

/* Bulletproof square enforcement via padding trick (fallback for older browsers) */
@supports not (aspect-ratio: 1 / 1) {
  .social-ig__post {
    height: 0;
    padding-bottom: 100%;
  }
}

.social-ig__post:focus-visible {
  outline: 2px solid var(--social-ig-accent);
  outline-offset: 2px;
}

/* ─── Hidden Posts (Load More) ──────────────────────────────────────────────── */
.social-ig__post--hidden {
  display: none;
}

/* ─── Image ──────────────────────────────────────────────────────────────────── */
.social-ig__image {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.social-ig__post:hover .social-ig__image {
  transform: scale(1.05);
}

/* ─── Caption Overlay ────────────────────────────────────────────────────────── */
.social-ig__caption {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  padding: 1rem;
  background: var(--social-ig-caption-bg);
  color: var(--social-ig-caption-fg);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.social-ig__post:hover .social-ig__caption,
.social-ig__post:focus-within .social-ig__caption {
  opacity: 1;
}

.social-ig__caption p {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ─── Engagement Overlay ─────────────────────────────────────────────────────── */
.social-ig__engagement {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.25rem 0.5rem;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 6px;
  font-size: 0.75rem;
  color: #fff;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.social-ig__post:hover .social-ig__engagement,
.social-ig__post:focus-within .social-ig__engagement {
  opacity: 1;
}

.social-ig__stat {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.social-ig__stat svg {
  flex-shrink: 0;
}

/* ─── Actions Row (Load More + Follow) ──────────────────────────────────────── */
.social-ig__actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

/* ─── Load More Button ──────────────────────────────────────────────────────── */
.social-ig__load-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 2rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ui-fg, #333);
  background: var(--ui-bg-muted, #f0f0f0);
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.social-ig__load-more:hover,
.social-ig__load-more:focus-visible {
  background: #e4e4e4;
  border-color: #b0b0b0;
  transform: translateY(-1px);
}

.social-ig__load-more:active {
  transform: translateY(0);
}

.social-ig__load-more:focus-visible {
  outline: 2px solid var(--social-ig-accent);
  outline-offset: 2px;
}

/* ─── Follow Button ──────────────────────────────────────────────────────────── */
.social-ig__follow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  width: fit-content;
  padding: var(--social-ig-follow-padding);
  font-size: 0.9375rem;
  font-weight: 600;
  color: #fff;
  background: var(--social-ig-accent);
  border: none;
  border-radius: 6px;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.15s ease;
}

.social-ig__follow svg {
  flex-shrink: 0;
}

.social-ig__follow:hover,
.social-ig__follow:focus-visible {
  background: var(--social-ig-accent-hover);
  transform: translateY(-1px);
}

.social-ig__follow:focus-visible {
  outline: 2px solid var(--social-ig-accent);
  outline-offset: 2px;
}

.social-ig__follow:active {
  transform: translateY(0);
}

/* ─── Skeleton Loading ───────────────────────────────────────────────────────── */
.social-ig__skeleton {
  pointer-events: none;
}

.social-ig__skeleton .social-ig__post {
  background: var(--social-ig-skeleton-bg);
  animation: social-ig-shimmer 1.5s ease-in-out infinite;
}

.social-ig__skeleton .social-ig__post:nth-child(2) {
  animation-delay: 0.15s;
}

.social-ig__skeleton .social-ig__post:nth-child(3) {
  animation-delay: 0.3s;
}

.social-ig__skeleton .social-ig__post:nth-child(4) {
  animation-delay: 0.45s;
}

@keyframes social-ig-shimmer {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ─── Error State ────────────────────────────────────────────────────────────── */
.social-ig__error {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--social-ig-accent);
  font-size: 0.9375rem;
  opacity: 0.7;
}

/* ─── Lightbox ───────────────────────────────────────────────────────────────── */
.social-ig__lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.9);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.social-ig__lightbox[data-active="true"] {
  opacity: 1;
  pointer-events: auto;
}

.social-ig__lightbox-img {
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.social-ig__lightbox-caption {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: 600px;
  text-align: center;
  color: #fff;
  font-size: 0.9375rem;
  line-height: 1.5;
  padding: 0.75rem 1.5rem;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 8px;
}

.social-ig__lightbox-close {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

.social-ig__lightbox-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.social-ig__lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

.social-ig__lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.3);
}

.social-ig__lightbox-nav--prev {
  left: 1.5rem;
}

.social-ig__lightbox-nav--next {
  right: 1.5rem;
}

/* ─── Responsive: Large tablet (5 columns) ─────────────────────────────────── */
@media (max-width: 1024px) {
  .social-ig__grid:not(.social-ig__grid--carousel) {
    --social-ig-cols: 5;
  }

  .social-ig__grid--masonry {
    columns: 5;
  }
}

/* ─── Responsive: Tablet (4 columns) ───────────────────────────────────────── */
@media (max-width: 768px) {
  .social-ig__grid:not(.social-ig__grid--carousel) {
    --social-ig-cols: 4;
  }

  .social-ig__grid--masonry {
    columns: 4;
  }

  .social-ig__title {
    font-size: 1.5rem;
  }

  .social-ig__caption p {
    -webkit-line-clamp: 2;
  }

  .social-ig__lightbox-nav {
    width: 40px;
    height: 40px;
  }

  .social-ig__lightbox-nav--prev { left: 0.75rem; }
  .social-ig__lightbox-nav--next { right: 0.75rem; }
}

/* ─── Responsive: Mobile (2 columns) ──────────────────────────────────────── */
@media (max-width: 480px) {
  .social-ig__grid:not(.social-ig__grid--carousel) {
    --social-ig-cols: 2;
  }

  .social-ig__grid--masonry {
    columns: 2;
  }

  .social-ig__grid--highlight .social-ig__post:first-child {
    grid-column: 1 / -1;
    grid-row: auto;
  }

  .social-ig__title {
    font-size: 1.25rem;
  }

  .social-ig__header {
    margin-bottom: 1rem;
  }

  .social-ig__actions {
    margin-top: 1rem;
    flex-direction: column;
  }

  .social-ig__follow,
  .social-ig__load-more {
    font-size: 0.9rem;
    padding: 0.6rem 1.5rem;
  }

  .social-ig__lightbox-caption {
    font-size: 0.8125rem;
    bottom: 1rem;
    padding: 0.5rem 1rem;
  }
}

/* ─── Dark Mode Support ──────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  .social-ig__title {
    color: var(--ui-fg-dark, #eee);
  }

  .social-ig__post {
    background: var(--ui-bg-dark, #1a1a1a);
  }

  .social-ig__load-more {
    background: #2a2a2a;
    color: #eee;
    border-color: #444;
  }

  .social-ig__load-more:hover {
    background: #333;
    border-color: #555;
  }
}

} /* end @layer atoms */
