/* ================================================================
   إصلاح SharePoint – إلغاء الخلفية البيضاء + تمركز صورة المودال
   ================================================================ */
#modal > *:not(.modal-content) {
    background: none !important;
}

#modal {
    background: rgba(0,0,0,0.9) !important;
}

#modal img {
    margin: auto !important;
    display: block !important;
}

#modal .modal-content {
    background: none !important;
}

/* ===================================================================
   المتغيرات العامة
   =================================================================== */
:root {
  --radius: 14px;
  --thumb-w: 120px;
  --thumb-h: 86px;
  --gap: 20px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f6f7f8;
  color: #111;
}

.wrap {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 14px;
  overflow: hidden;
}

.main {
  width: 100%;
  height: 48vh;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}

.main img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius);
  cursor: zoom-in;
  display: block;
  opacity: 1;
  transition: opacity .85s ease;
}

.btn {
  position: absolute;
  top: 50%;
  width: 35px;
  height: 60px;
  border-radius: 70%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.611);
  color: #fff;
  font-size: 44px;
  cursor: pointer;
  user-select: none;
  z-index: 6;
  transform: translateY(-50%) translateZ(0);
  will-change: transform;
  backface-visibility: hidden;
  transition: background .25s ease;
  backdrop-filter: none;
}

.btn span {
  display: block;
  pointer-events: none;
  transition: transform .22s ease;
}

.btn:hover span {
  transform: scale(1.13);
  color: #fff;
}

.btn.left  { right: 14px; }
.btn.right { left: 14px; }

/* ===================================================================
   صور المصغرات (Thumbnails)
   =================================================================== */

.thumbs-wrap {
  margin-top: 16px;
  overflow: hidden;
}

.thumbs-track {
  display: flex;
  gap: var(--gap);
  align-items: center;
  transition: transform .42s cubic-bezier(.2,.9,.2,1);
  will-change: transform;
  padding: 6px 18px;
  padding-inline: 18px;
}

.thumb {
  flex: 0 0 auto;
  height: var(--thumb-h);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  opacity: .55;
  border: 1px solid transparent;
  transition: transform .22s, opacity .42s, border-color .22s;
  background: #eceff2;
  display: flex;
}

.thumb.active {
  opacity: 1;
  transform: scale(1.06);
  border-color: #b6b6b6;
}

.thumb:hover {
  opacity: 1;
  transform: scale(1.12);
  border-color: #b6b6b6;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ===================================================================
   المودال (نافذة العرض الكبيرة)
   =================================================================== */
/* جعل المودال بالحجم الكامل للشاشة */
.modal {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  display: none;
  align-items: center !important;
  justify-content: center !important;
  background: rgba(0,0,0,0.92) !important;
  z-index: 999999 !important;
  overflow: hidden !important;    /* يمنع أي محتوى من الخروج */
}

.modal.open {
  display: flex;
}

.modal-content {
  position: relative !important; /* مهم جداً */
  display: flex !important;
  position: relative !important;
  align-items: center !important;
  justify-content: flex-end !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
}

/* ضمان أن الصورة وحاويتها تعمل كتخطيط نسبي */

 .modal-img-box {
    position: relative !important;      /* ضروري لعمل position absolute */
    max-width: 100vw;
    max-height: 100ßvh;
    display: inline-block;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.modal-img-box img {
    width: auto !important;
    max-height: calc(95vh - 70px) !important; /* يمنع تجاوز الصورة أسفل الشاشة */
    object-fit: contain !important;
    border-radius: 18px;
    cursor: zoom-out;
}

/* كابتشن مضبوط داخل حدود الصورة فقط */
.modal-img-box .caption {
    position: absolute !important;
    bottom: 14px !important;
    right: 14px !important;
    background: transparent;
    color: transparent;
    padding: 10px 14px !important;
    border-radius: 8px !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    max-width: 0% !important;    /* لا يتجاوز نصف عرض الصورة */
    text-align: center !important;
    direction: rtl !important;
    overflow-wrap: break-word !important;
    pointer-events: auto !important;
    z-index: 50 !important;
    width: auto !important;       /* لا يتمدد */
}

/* السماح للـ caption فقط داخل modal image بأن يكون له خلفية */


.modal-btn {
  position: absolute;
  top: 50%;
  width: 40px;
  height: 70px;
  border-radius: 70%;
  border-width: 2px;
  border-color: rgba(166, 164, 164, 0.436) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 44px;
  cursor: pointer;
  user-select: none;
  z-index: 1000000;
  transform: translateY(-50%) translateZ(0);
  will-change: transform;
  backface-visibility: hidden;
  transition: background .25s ease;
  box-shadow: 0 0 12px rgba(0,0,0,0.65) !important;
  backdrop-filter: blur(4px) !important; /* يعطي تأثير زجاجي */
}

/* عند المرور فوق السهم */


.modal-btn.left  { right: 40px; }
.modal-btn.right { left: 40px; }

/* ===================================================================
   الأزرار – تأثيرات
   =================================================================== */
.main .btn,
.modal .modal-btn {
  opacity: 0.8;
  transition: opacity .35s ease, background .35s ease;
}

.main:hover .btn,
.modal.open:hover .modal-btn {
  opacity: 1;
}

.main .btn,
.modal .modal-btn {
  background: rgba(0,0,0,.32);
  backdrop-filter: blur(3px);
}

.main .btn:hover span,
.modal .modal-btn:hover span {
  transform: translateX(0) scale(1.54);
}

.main .btn.right:hover span,
.modal .modal-btn.right:hover span {
  transform: translateX(-4px) scale(1.54);
}

.main .btn.left:hover span,
.modal .modal-btn.left:hover span {
  transform: translateX(4px) scale(1.54);
}

.main .btn:hover,
.modal .modal-btn:hover {
  background: rgba(0, 0, 0, 0.506) !important;
  border-color: rgba(255,255,255,0.55) !important;
}

/* ===================================================================
   الكابتشن (Caption)
   =================================================================== */
.caption {
  position: absolute;
  bottom: 16px;
  vertical-align: 50%;
  background: transparent;
  color: transparent;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.2;
  max-width: 0%;
  text-align: center;
  pointer-events: none;
  z-index: 6;
  box-shadow: 0 6px 18px rgba(0,0,0,0.28);
}

.caption a {
  color: #1a16f3;
  text-decoration: underline;
  margin-right: 6px;
  pointer-events: auto;
}

.caption-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
  line-height: 1.3;
  display: block;
}

/* ===================================================================
   Responsive
   =================================================================== */
@media (max-width: 900px) {
  :root {
    --thumb-w: 100px;
    --thumb-h: 74px;
  }
  .main {
    height: 42vh;
  }
  .caption {
    max-width: 72%;
    font-size: 13px;
  }
}

@media (max-width: 640px) {
    :root {
      --thumb-w: 84px;
      --thumb-h: 66px;
    }
    .main {
      height: 32vh;
    }
    .caption {
      max-width: 86%;
      font-size: 10px;
      bottom: 12px;
      right: 12px;
      padding: 8px 10px;
    }

    .caption-title {
      font-size: 12px;
    }

    .modal-content {
        max-width: 100vw !important;
        max-height: 100vh !important;
    }

    .modal-img-box {
        max-width: 100vw !important;
        max-height: 100vh !important;
    }

    .modal-img-box img {
        width: 100% !important;
        height: auto !important;
        max-height: 100vh !important;
        object-fit: contain !important;
    }

    .modal-img-box .caption {
        max-width: 90% !important;
        bottom: 10px !important;
        right: 10px !important;
        font-size: 10px !important;
        padding: 8px 10px !important;
    }

    .modal-btn {
        width: 32px !important;
        height: 56px !important;
        font-size: 36px !important;
    }

    .thumb {
        height: 60px !important;
    }
    .thumb img {
        object-fit: cover;
    }
}

/* السماح لعناصر معينة داخل المودال بامتلاك خلفية */
#modal .caption,
#modal .modal-btn {
    background: initial !important;
    border: none !important;
    outline: none !important;
}


/* السماح بخلفية bin (أزرار التنقل) */
#modal .modal-btn {
    background: rgba(126, 126, 126, 0.392) !important;
}

#modal .modal-btn:hover {
  background: rgba(126, 126, 126, 0.77) !important;
}

/* السماح بخلفية الكابتشن داخل المودال فقط */
#modal .caption {
    background: transparent;
}

/* Accessibility focus outlines */
.btn:focus,
.modal-btn:focus {
  outline: 2px solid rgba(255,255,255,0.85);
  outline-offset: 4px;
}

/* Image Counter */
.image-counter {
  position: absolute;
  top: 14px;
  left: 14px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  z-index: 20;
  pointer-events: none;
}
.modal-counter { z-index: 2000000; }

.section-title {
  box-sizing: border-box;
  padding: 0;
  direction: rtl;
  text-align: center;
  font-family: Cairo-Bold;
  font-weight: 500;
  font-size: 1.5rem;
  color: #414042;
  line-height: 1.5;
  font-style: normal;
  font-variant-ligatures: normal;
  font-variant-caps: normal;
  letter-spacing: normal;
  text-indent: 0;
  text-transform: none;
  word-spacing: 0;
  white-space: normal;
  margin: 0 0 1rem 0 !important;
}
