/* Project gallery popup (shared by index.html and index-ar.html) */

.project-gallery-popup {
  --pg-accent: #b52123;
  --pg-accent-dark: #8a1a1c;
  --pg-text: #2c3e50;
  --pg-muted: #6b7a89;
  --pg-surface: #ffffff;
  --pg-stage: #f2f2f0;

  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  align-items: center;
  justify-content: center;
  overscroll-behavior: contain;
}

.project-gallery-popup.active {
  display: flex;
  animation: pgFadeIn 0.25s ease-out;
}

.popup-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 10, 0.88);
  backdrop-filter: blur(8px);
}

.popup-content {
  position: relative;
  width: min(1280px, 94vw);
  height: min(92vh, 960px);
  background: var(--pg-surface);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  animation: pgSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.project-gallery-popup.closing .popup-content {
  animation: pgSlideDown 0.25s ease-in forwards;
}

.project-gallery-popup.closing .popup-overlay {
  animation: pgFadeOut 0.25s ease-in forwards;
}

/* Header */
.gallery-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 24px 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
  flex-shrink: 0;
}

.gallery-title-section {
  min-width: 0;
  flex: 1;
}

.gallery-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.gallery-title-section h3 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
  color: var(--pg-text);
  font-family: "Poppins", sans-serif;
}

.image-counter {
  background: var(--pg-accent);
  color: #fff;
  padding: 3px 11px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}

.project-type-area {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.project-type {
  background: var(--pg-accent);
  color: #fff;
  padding: 3px 11px;
  border-radius: 15px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.project-area,
.project-category {
  color: var(--pg-muted);
  font-size: 12px;
  font-weight: 500;
  background: #f3f4f6;
  padding: 3px 10px;
  border-radius: 15px;
}

.project-description {
  margin: 10px 0 0;
  max-width: 900px;
  font-size: 14px;
  line-height: 1.55;
  color: #5a6c7d;
  font-family: "Poppins", sans-serif;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.project-description.expanded {
  -webkit-line-clamp: unset;
  line-clamp: unset;
  max-height: 30vh;
  overflow-y: auto;
}

.description-toggle {
  margin-top: 4px;
  padding: 0;
  border: none;
  background: none;
  color: var(--pg-accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.description-toggle[hidden] {
  display: none;
}

.description-toggle:hover {
  text-decoration: underline;
}

/* Close button */
.close-popup {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
  color: var(--pg-accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.close-popup i {
  font-size: 18px;
  transition: transform 0.25s ease;
}

.close-popup:hover {
  background: var(--pg-accent);
  color: #fff;
}

.close-popup:hover i {
  transform: rotate(90deg);
}

/* Body */
.gallery-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
}

.gallery-main {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: var(--pg-stage);
}

.gallery-main .swiper-slide {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.gallery-main .image-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-main img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.3s ease;
  user-select: none;
  -webkit-user-drag: none;
}

.gallery-main .image-container.is-loaded img {
  opacity: 1;
}

/* Spinner while a photo loads */
.gallery-main .image-container:not(.is-loaded)::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 36px;
  height: 36px;
  margin: -18px 0 0 -18px;
  border: 3px solid rgba(181, 33, 35, 0.15);
  border-top-color: var(--pg-accent);
  border-radius: 50%;
  animation: pgSpin 0.8s linear infinite;
}

.gallery-main video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

/* Prev / next buttons */
.nav-btn {
  position: absolute;
  top: 50%;
  z-index: 10;
  width: 48px;
  height: 48px;
  margin-top: -24px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  color: var(--pg-accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease,
    transform 0.2s ease;
}

.nav-btn i {
  font-size: 18px;
}

.nav-btn:hover {
  background: var(--pg-accent);
  color: #fff;
  transform: scale(1.06);
}

.nav-btn:active {
  transform: scale(0.95);
}

.prev-btn {
  inset-inline-start: 16px;
}

.next-btn {
  inset-inline-end: 16px;
}

.nav-btn.swiper-button-disabled {
  opacity: 0.35;
  pointer-events: none;
}

.nav-btn.swiper-button-lock,
.thumbs-nav-btn.swiper-button-lock {
  display: none;
}

/* Thumbnails */
.thumbnails-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.thumbnails-section[hidden] {
  display: none;
}

.gallery-thumbs {
  flex: 1;
  min-width: 0;
  height: 64px;
  overflow: hidden;
}

.gallery-thumbs .swiper-slide {
  position: relative;
  width: 96px;
  height: 64px;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  opacity: 0.55;
  background: var(--pg-stage);
  transition: opacity 0.2s ease;
}

.gallery-thumbs .swiper-slide::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid transparent;
  border-radius: 6px;
  transition: border-color 0.2s ease;
  pointer-events: none;
}

.gallery-thumbs .swiper-slide:hover {
  opacity: 0.85;
}

.gallery-thumbs .swiper-slide-thumb-active {
  opacity: 1;
}

.gallery-thumbs .swiper-slide-thumb-active::after {
  border-color: var(--pg-accent);
}

.gallery-thumbs .swiper-slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumbs-nav-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
  color: var(--pg-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.thumbs-nav-btn:hover {
  background: var(--pg-accent);
  color: #fff;
}

.thumbs-nav-btn.swiper-button-disabled {
  opacity: 0.3;
  pointer-events: none;
}

.thumbs-nav-btn i {
  font-size: 13px;
}

/* Video (Skindose) */
.thumb-video .video-thumb {
  position: relative;
  width: 100%;
  height: 100%;
}

.video-play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 2;
}

.video-play-icon::before {
  content: "";
  border-left: 14px solid #fff;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
}

.main-video-play::before {
  border-left-width: 28px;
  border-top-width: 18px;
  border-bottom-width: 18px;
}

.main-video-poster {
  cursor: pointer;
}

/* Keyboard focus */
.project-gallery-popup button:focus-visible {
  outline: 2px solid var(--pg-accent);
  outline-offset: 2px;
}

/* Arabic / RTL */
[dir="rtl"] .gallery-title-section h3,
[dir="rtl"] .project-description,
[dir="rtl"] .project-type-area,
[dir="rtl"] .description-toggle {
  font-family: "Tajawal", "Cairo", sans-serif;
}

[dir="rtl"] .nav-btn i,
[dir="rtl"] .thumbs-nav-btn i {
  transform: scaleX(-1);
}

/* Tablet */
@media (max-width: 991px) {
  .popup-content {
    width: 96vw;
    height: 94vh;
  }

  .gallery-title-section h3 {
    font-size: 21px;
  }
}

/* Phone: full screen, photo gets most of the space */
@media (max-width: 767px) {
  .popup-content {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
  }

  .gallery-header {
    padding: 14px 16px 10px;
    gap: 12px;
  }

  .gallery-title-section h3 {
    font-size: 18px;
  }

  .project-type-area {
    margin-top: 8px;
  }

  .project-category {
    display: none;
  }

  .project-description {
    font-size: 13px;
  }

  .close-popup {
    width: 40px;
    height: 40px;
  }

  .gallery-container {
    padding: 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    gap: 8px;
  }

  .gallery-main {
    border-radius: 8px;
  }

  .nav-btn {
    width: 38px;
    height: 38px;
    margin-top: -19px;
    background: rgba(255, 255, 255, 0.8);
  }

  .nav-btn i {
    font-size: 15px;
  }

  .prev-btn {
    inset-inline-start: 8px;
  }

  .next-btn {
    inset-inline-end: 8px;
  }

  /* Thumbnails swipe by touch, so the small arrows are not needed */
  .thumbs-nav-btn {
    display: none;
  }

  .gallery-thumbs {
    height: 50px;
  }

  .gallery-thumbs .swiper-slide {
    width: 68px;
    height: 50px;
  }
}

@media (hover: none) {
  .nav-btn:hover {
    background: rgba(255, 255, 255, 0.92);
    color: var(--pg-accent);
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .project-gallery-popup.active,
  .popup-content,
  .project-gallery-popup.closing .popup-content,
  .project-gallery-popup.closing .popup-overlay {
    animation: none;
  }
}

@keyframes pgFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pgFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes pgSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pgSlideDown {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(16px); }
}

@keyframes pgSpin {
  to { transform: rotate(360deg); }
}
