/* ====== متغيرات CSS ====== */
:root {
  --gradient-gallery: linear-gradient(135deg, #8A2BE2 0%, #470d88 100%);
  --gradient-gallery-light: linear-gradient(135deg, rgba(138, 43, 226, 0.08) 0%, rgba(71, 13, 136, 0.04) 100%);
  --shadow-gallery: 0 15px 35px rgba(138, 43, 226, 0.12);
  --shadow-gallery-hover: 0 25px 50px rgba(138, 43, 226, 0.2);
  --shadow-lightbox: 0 30px 60px rgba(0, 0, 0, 0.3);
}

/* ====== إعدادات عامة للمعرض ====== */
.gallery-section {
  padding: 120px 50px;
  background: linear-gradient(135deg, #fdf7ff 0%, #f8f0ff 100%);
  font-family: var(--font-family);
  position: relative;
  overflow: hidden;
}

.gallery-section::before {
  content: "";
  position: absolute;
  top: -150px;
  left: -150px;
  width: 400px;
  height: 400px;
  background: var(--gradient-gallery-light);
  border-radius: 50%;
  opacity: 0.5;
  filter: blur(80px);
  z-index: 0;
}

.gallery-section::after {
  content: "";
  position: absolute;
  bottom: -150px;
  right: -150px;
  width: 500px;
  height: 500px;
  background: var(--gradient-gallery-light);
  border-radius: 50%;
  opacity: 0.4;
  filter: blur(100px);
  z-index: 0;
}

.gallery-container {
  max-width: 1400px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

/* ====== نص المعرض ====== */
.gallery-header {
  text-align: center;
  margin-bottom: 80px;
  position: relative;
}

.gallery-subtitle {
  display: inline-block;
  font-size: 0.9rem;
  font-weight: 600;
  color: #8A2BE2;
  text-transform: uppercase;
  letter-spacing: 2px;
  padding: 8px 24px;
  background: rgba(138, 43, 226, 0.1);
  border-radius: 20px;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}

.gallery-subtitle::after {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  animation: shimmer 3s infinite;
}

.gallery-title {
  font-size: clamp(2.5rem, 4vw, 3.5rem);
  color: #470d88;
  font-weight: 800;
  margin-bottom: 20px;
  line-height: 1.2;
  position: relative;
  display: inline-block;
}

.gallery-title::after {
  content: "";
  position: absolute;
  bottom: -15px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 4px;
  background: var(--gradient-gallery);
  border-radius: 2px;
}

.gallery-desc {
  font-size: 1.2rem;
  color: #64748b;
  max-width: 600px;
  margin: 40px auto 0;
  line-height: 1.6;
  padding: 25px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(138, 43, 226, 0.08);
  border: 1px solid rgba(138, 43, 226, 0.1);
  position: relative;
}

.gallery-desc::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--gradient-gallery);
}

/* ====== شبكة الصور ====== */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 30px;
  animation: fadeInUp 0.8s ease-out 0.3s both;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ====== كرت الصورة ====== */
.gallery-card {
  position: relative;
  overflow: hidden;
  border-radius: 24px;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-gallery);
  background: white;
  border: 1px solid rgba(138, 43, 226, 0.1);
}

.gallery-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 60%, rgba(0, 0, 0, 0.7) 100%);
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: 1;
  border-radius: 24px;
}

.gallery-card:hover {
  transform: translateY(-15px) scale(1.02);
  box-shadow: var(--shadow-gallery-hover);
}

.gallery-card:hover::before {
  opacity: 1;
}

.gallery-image-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: 24px;
  aspect-ratio: 4/3;
}

.gallery-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center;
}

.gallery-card:hover .gallery-image {
  transform: scale(1.15);
  filter: brightness(0.9);
}

/* ====== Overlay تفاعلي ====== */
.gallery-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(45deg, rgba(138, 43, 226, 0.9), rgba(71, 13, 136, 0.95));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 30px;
  z-index: 2;
  border-radius: 24px;
}

.gallery-card:hover .gallery-overlay {
  opacity: 1;
  transform: scale(1);
}

.overlay-content {
  text-align: center;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.4s ease 0.2s;
}

.gallery-card:hover .overlay-content {
  transform: translateY(0);
  opacity: 1;
}

.overlay-icon-wrapper {
  width: 70px;
  height: 70px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.overlay-icon-wrapper i {
  width: 32px;
  height: 32px;
  color: white;
  stroke-width: 2;
}

.overlay-title {
  color: white;
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 10px;
  text-align: center;
}

.overlay-desc {
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.95rem;
  text-align: center;
  line-height: 1.6;
  max-width: 80%;
  margin: 0 auto 20px;
}

.view-more-btn {
  display: inline-block;
  background: white;
  color: #8A2BE2;
  padding: 10px 24px;
  border-radius: 25px;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.3s ease;
}

.view-more-btn:hover {
  background: #f0f0f0;
  transform: translateY(-2px);
}

/* ====== تذييل الكرت ====== */
.gallery-item-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 25px;
  z-index: 1;
  transform: translateY(100%);
  transition: transform 0.4s ease;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent);
  border-radius: 0 0 24px 24px;
}

.gallery-card:hover .gallery-item-footer {
  transform: translateY(0);
}

.gallery-item-title {
  color: white;
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.gallery-item-category {
  display: inline-block;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  padding: 4px 12px;
  border-radius: 15px;
  font-size: 0.85rem;
  backdrop-filter: blur(10px);
}

/* ====== زر تحميل المزيد ====== */
.gallery-load-more {
  text-align: center;
  margin-top: 60px;
}

.load-more-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--gradient-gallery);
  color: white;
  border: none;
  padding: 16px 40px;
  border-radius: 30px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 10px 30px rgba(138, 43, 226, 0.2);
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.load-more-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.6s ease;
  z-index: -1;
}

.load-more-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 15px 40px rgba(138, 43, 226, 0.3);
}

.load-more-btn:hover::before {
  left: 100%;
}

.load-more-btn i {
  width: 20px;
  height: 20px;
  transition: transform 0.3s ease;
}

.load-more-btn:hover i {
  transform: rotate(90deg);
}

.load-more-btn.loading {
  background: #64748b;
  cursor: not-allowed;
}

.spin {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ====== Lightbox ====== */
.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  animation: fadeIn 0.3s ease;
}

.gallery-lightbox.active {
  display: block;
}

.lightbox-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
}

.lightbox-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 1200px;
  max-height: 90vh;
  background: white;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow-lightbox);
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  background: rgba(0, 0, 0, 0.5);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.lightbox-close:hover {
  background: rgba(0, 0, 0, 0.7);
  transform: rotate(90deg);
}

.lightbox-close i {
  width: 24px;
  height: 24px;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 60px;
  height: 60px;
  background: rgba(0, 0, 0, 0.5);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.lightbox-nav:hover {
  background: rgba(0, 0, 0, 0.7);
  transform: translateY(-50%) scale(1.1);
}

.lightbox-nav.prev {
  left: 20px;
}

.lightbox-nav.next {
  right: 20px;
}

.lightbox-nav i {
  width: 28px;
  height: 28px;
}

.lightbox-image-container {
  width: 100%;
  height: 70vh;
  position: relative;
  overflow: hidden;
}

#lightboxImage {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.lightbox-loader {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
}

.loader-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #8A2BE2;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.lightbox-info {
  padding: 30px;
  background: white;
}

.lightbox-info h3 {
  font-size: 1.8rem;
  color: #470d88;
  margin-bottom: 15px;
}

.lightbox-info p {
  color: #64748b;
  line-height: 1.6;
  margin-bottom: 20px;
}

.lightbox-meta {
  display: flex;
  gap: 20px;
}

.lightbox-meta span {
  display: inline-block;
  background: rgba(138, 43, 226, 0.1);
  color: #8A2BE2;
  padding: 6px 15px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 500;
}

/* ====== تأثيرات التحميل ====== */
.gallery-card {
  opacity: 0;
  animation: fadeInUp 0.6s ease forwards;
}

.gallery-card:nth-child(1) { animation-delay: 0.1s; }
.gallery-card:nth-child(2) { animation-delay: 0.2s; }
.gallery-card:nth-child(3) { animation-delay: 0.3s; }
.gallery-card:nth-child(4) { animation-delay: 0.4s; }
.gallery-card:nth-child(5) { animation-delay: 0.5s; }
.gallery-card:nth-child(6) { animation-delay: 0.6s; }
.gallery-card:nth-child(7) { animation-delay: 0.7s; }
.gallery-card:nth-child(8) { animation-delay: 0.8s; }

/* ====== RTL Support ====== */
html[dir="rtl"] .gallery-subtitle::after {
  animation-direction: reverse;
}

html[dir="rtl"] .gallery-desc::before {
  left: auto;
  right: 0;
}

html[dir="rtl"] .lightbox-close {
  right: auto;
  left: 20px;
}

html[dir="rtl"] .lightbox-nav.prev i {
  transform: rotate(180deg);
}

html[dir="rtl"] .lightbox-nav.next i {
  transform: rotate(180deg);
}

/* ====== تأثير التموج ====== */
@keyframes ripple {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

@keyframes shimmer {
  100% {
    left: 100%;
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ====== استجابة ====== */

/* الأجهزة اللوحية الكبيرة */
@media (max-width: 1200px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
  }
}

/* الأجهزة اللوحية */
@media (max-width: 991px) {
  .gallery-section {
    padding: 100px 40px;
  }
  
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
  }
  
  .gallery-image-wrapper {
    aspect-ratio: 3/2;
  }
}

/* الأجهزة اللوحية الصغيرة */
@media (max-width: 768px) {
  .gallery-section {
    padding: 80px 30px;
  }
  
  .gallery-header {
    margin-bottom: 60px;
  }
  
  .gallery-title {
    font-size: 2.5rem;
  }
  
  .gallery-desc {
    font-size: 1.1rem;
    padding: 20px;
  }
  
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
  
  .overlay-icon-wrapper {
    width: 60px;
    height: 60px;
  }
  
  .overlay-title {
    font-size: 1.2rem;
  }
  
  .overlay-desc {
    font-size: 0.9rem;
  }
  
  .lightbox-content {
    width: 95%;
  }
  
  .lightbox-image-container {
    height: 50vh;
  }
}

/* الهواتف الكبيرة */
@media (max-width: 576px) {
  .gallery-section {
    padding: 70px 20px;
  }
  
  .gallery-header {
    margin-bottom: 50px;
  }
  
  .gallery-title {
    font-size: 2.2rem;
  }
  
  .gallery-desc {
    font-size: 1rem;
    padding: 18px;
  }
  
  .gallery-grid {
    grid-template-columns: 1fr;
    max-width: 400px;
    margin: 0 auto;
  }
  
  .gallery-image-wrapper {
    aspect-ratio: 16/9;
  }
  
  .lightbox-nav {
    width: 50px;
    height: 50px;
  }
  
  .lightbox-info h3 {
    font-size: 1.5rem;
  }
}

/* الهواتف الصغيرة */
@media (max-width: 480px) {
  .gallery-section {
    padding: 60px 16px;
  }
  
  .gallery-title {
    font-size: 2rem;
  }
  
  .gallery-subtitle {
    font-size: 0.85rem;
    padding: 6px 20px;
  }
  
  .gallery-desc {
    font-size: 0.95rem;
    padding: 16px;
  }
  
  .gallery-card {
    border-radius: 20px;
  }
  
  .gallery-image-wrapper {
    border-radius: 20px;
  }
  
  .gallery-item-footer {
    padding: 20px;
  }
  
  .gallery-item-title {
    font-size: 1.2rem;
  }
}

/* أصغر الهواتف */
@media (max-width: 360px) {
  .gallery-section {
    padding: 50px 12px;
  }
  
  .gallery-title {
    font-size: 1.8rem;
  }
  
  .gallery-subtitle {
    font-size: 0.8rem;
    letter-spacing: 1px;
  }
  
  .gallery-desc {
    font-size: 0.9rem;
    padding: 14px;
  }
  
  .gallery-item-footer {
    padding: 15px;
  }
  
  .gallery-item-title {
    font-size: 1.1rem;
  }
  
  .overlay-title {
    font-size: 1.1rem;
  }
  
  .overlay-desc {
    font-size: 0.85rem;
  }
}