/* ============================================================
 *  Gallery Page Styles — UI/UX Optimized
 *  gallery.php — masonry grid + filters + lightbox
 * ============================================================ */

/* ---------- Filters ---------- */
.gallery-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-bottom: var(--s-6);
  justify-content: center;
}
.gallery-filter {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: var(--s-2) var(--s-4);
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: var(--fs-small);
  font-weight: 500;
  cursor: pointer;
  transition:
    background var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease);
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  position: relative;
  overflow: hidden;
}
.gallery-filter::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent);
  opacity: 0;
  transition: opacity var(--t-fast) var(--ease);
}
.gallery-filter:hover {
  border-color: var(--shafa-gold-text);
  color: var(--shafa-gold-text);
  transform: translateY(-1px);
}
.gallery-filter.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(var(--accent-rgb), .3);
}
.gallery-filter.is-active::after {
  opacity: 0;
}
.gallery-filter__count {
  font-size: var(--fs-caption);
  opacity: .85;
  font-variant-numeric: tabular-nums;
}

/* ---------- Masonry Grid ---------- */
.gallery-grid {
  column-count: 1;
  column-gap: var(--s-4);
}
@media (min-width: 640px) {
  .gallery-grid { column-count: 2; }
}
@media (min-width: 1024px) {
  .gallery-grid { column-count: 3; }
}
@media (min-width: 1280px) {
  .gallery-grid { column-count: 4; }
}

.gallery-item {
  break-inside: avoid;
  margin-bottom: var(--s-4);
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease), opacity var(--t-base) var(--ease);
  position: relative;
}
.gallery-item:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow-hover);
}
.gallery-item.is-hidden {
  display: none;
}
.gallery-item.is-filtering {
  opacity: 0;
  transform: scale(.95);
}

/* Image wrapper for aspect ratio */
.gallery-item__media {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  cursor: zoom-in;
  line-height: 0;
}
.gallery-item__media::before {
  content: '';
  display: block;
  padding-top: 75%; /* 4:3 default */
}
.gallery-item__media img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 500ms var(--ease), opacity 300ms var(--ease);
  opacity: 0;
}
.gallery-item__media img.is-loaded {
  opacity: 1;
}
.gallery-item:hover .gallery-item__media img {
  transform: scale(1.06);
}
.gallery-item__zoom {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.25);
  opacity: 0;
  transition: opacity var(--t-base) var(--ease);
  pointer-events: none;
  color: #fff;
}
.gallery-item:hover .gallery-item__zoom {
  opacity: 1;
}
.gallery-item__zoom .material-symbols-outlined {
  font-size: 32px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.3));
}
.gallery-item__caption {
  padding: var(--s-3) var(--s-4);
  font-size: var(--fs-small);
  color: var(--text-soft);
  text-align: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* Skeleton loading */
.gallery-item__skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s infinite;
  z-index: 1;
}
@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.gallery-item__media img.is-loaded + .gallery-item__skeleton,
.gallery-item__skeleton.is-hidden {
  display: none;
}

/* Empty state */
.gallery-empty {
  text-align: center;
  padding: var(--s-9) 0;
  color: var(--muted);
}
.gallery-empty svg {
  width: 64px;
  height: 64px;
  margin-bottom: var(--s-4);
  opacity: .5;
}

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal, 1000);
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  transition: opacity var(--t-base) var(--ease), visibility var(--t-base);
}
.lightbox.is-open {
  visibility: visible;
  opacity: 1;
}
.lightbox[aria-hidden="true"] {
  visibility: hidden;
}
.lightbox[aria-hidden="false"] {
  visibility: visible;
}

.lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.lightbox__content {
  position: relative;
  z-index: 1;
  max-width: 92vw;
  max-height: 92vh;
  max-height: 92dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox__img {
  max-width: 92vw;
  max-height: 88vh;
  max-height: 88dvh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(0,0,0,.5);
  opacity: 0;
  transform: scale(.95);
  transition: opacity var(--t-base) var(--ease), transform var(--t-base) var(--ease);
}
.lightbox.is-open .lightbox__img {
  opacity: 1;
  transform: scale(1);
}

.lightbox__close,
.lightbox__prev,
.lightbox__next {
  position: absolute;
  appearance: none;
  border: none;
  background: rgba(255,255,255,.12);
  color: #fff;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    background var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  touch-action: manipulation;
}
.lightbox__close:hover,
.lightbox__prev:hover,
.lightbox__next:hover {
  background: rgba(255,255,255,.25);
  transform: scale(1.08);
}
.lightbox__close:active,
.lightbox__prev:active,
.lightbox__next:active {
  transform: scale(.95);
}

.lightbox__close {
  top: var(--s-4);
  left: var(--s-4);
  z-index: 2;
}
.lightbox__prev {
  left: var(--s-4);
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
}
.lightbox__prev:hover {
  transform: translateY(-50%) scale(1.08);
}
.lightbox__next {
  right: var(--s-4);
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
}
.lightbox__next:hover {
  transform: translateY(-50%) scale(1.08);
}

.lightbox__counter {
  position: absolute;
  top: var(--s-4);
  right: var(--s-4);
  background: rgba(0,0,0,.6);
  color: #fff;
  padding: var(--s-1) var(--s-3);
  border-radius: var(--radius-pill);
  font-size: var(--fs-caption);
  font-variant-numeric: tabular-nums;
  z-index: 2;
  backdrop-filter: blur(4px);
}

.lightbox__caption {
  position: absolute;
  bottom: var(--s-6);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.7);
  color: #fff;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--radius-pill);
  font-size: var(--fs-small);
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 2;
  backdrop-filter: blur(4px);
}

/* Mobile lightbox adjustments */
/* 639.98 نه 640 — هم‌مرزی با min-width:640px در همین فایل را قطعی می‌کند */
@media (max-width: 639.98px) {
  .lightbox__close,
  .lightbox__prev,
  .lightbox__next {
    width: 44px;
    height: 44px;
    background: rgba(0,0,0,.5);
  }
  .lightbox__close {
    top: var(--s-3);
    left: var(--s-3);
  }
  .lightbox__prev {
    left: var(--s-3);
  }
  .lightbox__next {
    right: var(--s-3);
  }
  .lightbox__counter {
    top: var(--s-3);
    right: var(--s-3);
  }
  .lightbox__caption {
    bottom: var(--s-4);
    font-size: var(--fs-caption);
    padding: var(--s-1) var(--s-3);
  }
}

/* ---------- Animations ---------- */
/* حالت پنهانِ اولیه فقط وقتی اعمال می‌شود که gallery.js واقعاً اجرا شده
   باشد (is-enhanced را خودش می‌زند). پیش‌تر `.gallery-item { opacity: 0 }`
   بی‌قیدوشرط بود و چون هیچ اسکریپتی is-visible را اضافه نمی‌کرد، کل گالری
   نامرئی می‌ماند. fill-mode: backwards تا پس از پایان، transform هاور
   دوباره کار کند. */
.gallery-grid.is-enhanced .gallery-item:not(.is-visible) {
  opacity: 0;
  transform: translateY(24px);
}
.gallery-item.is-visible {
  animation: galleryFadeIn 500ms var(--ease) backwards;
}
@keyframes galleryFadeIn {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .gallery-grid.is-enhanced .gallery-item:not(.is-visible) {
    opacity: 1;
    transform: none;
  }
  .gallery-item.is-visible {
    animation: none;
  }
}

/* Staggered animation */
.gallery-item:nth-child(1)  { animation-delay: 0ms; }
.gallery-item:nth-child(2)  { animation-delay: 50ms; }
.gallery-item:nth-child(3)  { animation-delay: 100ms; }
.gallery-item:nth-child(4)  { animation-delay: 150ms; }
.gallery-item:nth-child(5)  { animation-delay: 200ms; }
.gallery-item:nth-child(6)  { animation-delay: 250ms; }
.gallery-item:nth-child(7)  { animation-delay: 300ms; }
.gallery-item:nth-child(8)  { animation-delay: 350ms; }
.gallery-item:nth-child(9)  { animation-delay: 400ms; }
.gallery-item:nth-child(10) { animation-delay: 450ms; }
.gallery-item:nth-child(11) { animation-delay: 500ms; }
.gallery-item:nth-child(12) { animation-delay: 550ms; }

/* Filter transition */
.gallery-item.is-filtering {
  transition: opacity var(--t-base) var(--ease), transform var(--t-base) var(--ease);
}

/* ============================================================
 *  Video items (media_type = video)
 * ============================================================ */

/* فاصلهٔ کمتر بین گروه فیلتر نوع و فیلتر دسته */
.gallery-filters--type {
  margin-bottom: var(--s-3);
}

/* پوستر ندارد: گرادینت جایگزین تا فضای خالی نماند */
.gallery-item__media--video.is-noposter {
  background: linear-gradient(
    135deg,
    var(--surface-2) 0%,
    rgba(var(--accent-rgb), .35) 100%
  );
}

.gallery-item__media--video {
  cursor: pointer;
}

/* دکمهٔ پلی روی ویدیوها — همیشه دیده می‌شود (affordance) */
.gallery-item__play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .18);
  line-height: 1;
  text-decoration: none;
  transition: background var(--t-base) var(--ease);
}
.gallery-item--video:hover .gallery-item__play {
  background: rgba(0, 0, 0, .32);
}
.gallery-item__play-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  transition:
    transform var(--t-base) var(--ease),
    box-shadow var(--t-base) var(--ease);
}
.gallery-item__play-btn .material-symbols-outlined {
  font-size: 32px;
  margin-inline-start: 3px; /* مرکز optical مثلث پلی */
}
.gallery-item--video:hover .gallery-item__play-btn {
  transform: scale(1.12);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}

/* ---------- Lightbox: ویدیو ---------- */
.lightbox__video {
  width: min(92vw, calc(88vh * 16 / 9));
  width: min(92vw, calc(88dvh * 16 / 9));
}
.lightbox__video-frame iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .5);
}

/* پنل ویدیوهای «لینک خارجی» (بدون embed) در lightbox */
.lightbox__external {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-4);
  max-width: 420px;
  padding: var(--s-6);
  text-align: center;
}
.lightbox__external img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius);
}
.lightbox__external-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: var(--s-3) var(--s-5);
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: var(--fs-small);
  font-weight: 600;
  transition:
    transform var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease);
}
.lightbox__external-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}

@media (max-width: 639.98px) {
  .gallery-item__play-btn {
    width: 48px;
    height: 48px;
  }
  .gallery-item__play-btn .material-symbols-outlined {
    font-size: 24px;
  }
}

/* ============================================================
 *  Lab Report items (category = lab-report)
 * ============================================================ */

.gallery-item--lab-report {
  cursor: pointer;
}
.gallery-item--lab-report .gallery-item__media {
  cursor: pointer;
}
.gallery-item__link {
  display: block;
  text-decoration: none;
  color: inherit;
}
.gallery-item__pdf-badge {
  position: absolute;
  top: var(--s-2);
  right: var(--s-2);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent);
  font-size: 24px;
  box-shadow: 0 2px 8px rgba(28, 25, 23, 0.15);
  z-index: 2;
  opacity: 0;
  transition: opacity var(--t-base) var(--ease);
  pointer-events: none;
}
.gallery-item--lab-report:hover .gallery-item__pdf-badge {
  opacity: 1;
}
.gallery-item__lab-report-meta {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: var(--s-1);
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  padding: var(--s-1) var(--s-2);
  font-size: var(--fs-caption);
  font-weight: 500;
  opacity: 0;
  transition: opacity var(--t-base) var(--ease);
  pointer-events: none;
}
.gallery-item--lab-report:hover .gallery-item__lab-report-meta {
  opacity: 1;
}

/* ============================================================
 *  Homepage Gallery Preview — Enhanced Masonry Grid
 *  index.php — featured item + video support + lightbox
 * ============================================================ */

.home-gallery-preview__grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 150px;
  gap: var(--s-3);
}

/* تصویر شاخص — ۲ ستون و ۱ سطر (همه با هم یک اندازه) */
.home-gallery-item--featured {
  grid-column: span 2;
  grid-row: span 1;
}

/* ویدیو — ۲ ستون و ۱ سطر */
.home-gallery-item--video {
  grid-column: span 2;
  grid-row: span 1;
}

.home-gallery-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease);
}

.home-gallery-item:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.home-gallery-item__media {
  position: relative;
  overflow: hidden;
  height: 100%;
  width: 100%;
}

.home-gallery-item__media-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--surface-2) 0%, rgba(var(--accent-rgb), .35) 100%);
}

.home-gallery-item__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .5s var(--ease);
}

.home-gallery-item:hover .home-gallery-item__img {
  transform: scale(1.08);
}

/* هاور آورلی */
.home-gallery-item__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, .6) 0%,
    rgba(0, 0, 0, 0) 50%,
    rgba(0, 0, 0, .3) 100%
  );
  opacity: 0;
  transition: opacity .3s var(--ease);
  display: flex;
  align-items: flex-end;
  padding: var(--s-3);
}

.home-gallery-item:hover .home-gallery-item__overlay {
  opacity: 1;
}

.home-gallery-item__actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  color: #fff;
  width: 100%;
  justify-content: space-between;
}

.home-gallery-item__action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .2);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.home-gallery-item__caption-text {
  font-size: var(--fs-small);
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* دکمه پلی ویدیو */
.home-gallery-item__play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.home-gallery-item__play-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .35);
  transition: transform var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease);
}

.home-gallery-item__play-btn .material-symbols-outlined {
  font-size: 20px;
}

.home-gallery-item--video:hover .home-gallery-item__play-btn {
  transform: scale(1.12);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}

/* دکمه زوم تصویر */
.home-gallery-item__zoom {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.home-gallery-item__zoom .material-symbols-outlined {
  font-size: 28px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .3));
}

/* نشانگر ویدیو در گوشه */
.home-gallery-item--video::after {
  content: '';
  position: absolute;
  top: var(--s-1);
  right: var(--s-1);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
}

/* ریسپانسیو */
@media (max-width: 1024px) {
  .home-gallery-preview__grid {
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 140px;
  }
  .home-gallery-item--featured,
  .home-gallery-item--video {
    grid-column: span 3;
    grid-row: span 1;
  }
}

@media (max-width: 768px) {
  .home-gallery-preview__grid {
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 130px;
  }
  .home-gallery-item--featured,
  .home-gallery-item--video {
    grid-column: span 2;
    grid-row: span 1;
  }
}

@media (max-width: 480px) {
  .home-gallery-preview__grid {
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 110px;
    gap: var(--s-2);
  }
}

/* CTA button count badge */
.btn__count {
  background: rgba(255, 255, 255, .2);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-caption);
}
