/* ==========================================================================
   MODAL GALLERY (LIGHTBOX) - PORTFOLIO
   Modale d'affichage, défilement et zoom pour les images des projets (~85% écran)
   ========================================================================== */

:root {
  --mg-backdrop: rgba(6, 10, 18, 0.82);
  --mg-bg: rgba(18, 24, 38, 0.95);
  --mg-border: rgba(255, 255, 255, 0.12);
  --mg-border-subtle: rgba(255, 255, 255, 0.08);
  --mg-text-main: #f8fafc;
  --mg-text-muted: #94a3b8;
  --mg-accent: #38bdf8;
  --mg-accent-hover: #0ea5e9;
  --mg-btn-bg: rgba(255, 255, 255, 0.08);
  --mg-btn-hover: rgba(255, 255, 255, 0.18);
  --mg-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.06);
}

/* Curseur zoom-in sur les images éligibles dans les projets */
img.mg-trigger {
  cursor: zoom-in !important;
  transition: transform 0.25s ease, filter 0.25s ease;
}

img.mg-trigger:hover {
  filter: brightness(1.04);
}

/* Arrière-plan de la modale (Overlay plein écran) */
.mg-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 100000;
  background: var(--mg-backdrop);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.26s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.26s cubic-bezier(0.16, 1, 0.3, 1);
}

.mg-overlay.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Boîte de dialogue de la modale (85% de la taille de l'écran total) */
.mg-dialog {
  position: relative;
  width: min(90vw, 1560px);
  height: 85vh;
  min-width: 320px;
  min-height: 360px;
  max-width: 92vw;
  max-height: 85vh;
  background: var(--mg-bg);
  border: 1px solid var(--mg-border);
  border-radius: 18px;
  box-shadow: var(--mg-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.95) translateY(12px);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.mg-overlay.is-active .mg-dialog {
  transform: scale(1) translateY(0);
}

/* En-tête compact de la modale */
.mg-header {
  height: 44px;
  min-height: 44px;
  padding: 0 16px;
  background: rgba(12, 17, 28, 0.85);
  border-bottom: 1px solid var(--mg-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 10;
  user-select: none;
}

.mg-header__left {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}

.mg-counter {
  font-family: 'Montserrat', sans-serif;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--mg-text-muted);
  background: rgba(255, 255, 255, 0.06);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--mg-border-subtle);
  white-space: nowrap;
}

.mg-caption {
  font-family: 'Montserrat', sans-serif;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--mg-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.9;
}

.mg-header__right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Groupe des boutons de zoom */
.mg-zoom-controls {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--mg-border-subtle);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}

.mg-btn {
  background: transparent;
  border: none;
  color: var(--mg-text-muted);
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
  font-family: inherit;
  padding: 0;
}

.mg-btn:hover {
  background: var(--mg-btn-hover);
  color: var(--mg-text-main);
}

.mg-btn:active {
  transform: scale(0.92);
}

.mg-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mg-zoom-level {
  font-family: 'Montserrat', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--mg-text-main);
  min-width: 44px;
  text-align: center;
  padding: 0 4px;
  user-select: none;
}

.mg-btn--close {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.25);
  margin-left: 4px;
}

.mg-btn--close:hover {
  background: rgba(239, 68, 68, 0.85);
  color: #fff;
  border-color: transparent;
}

/* Zone principale d'affichage de l'image */
.mg-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(circle at center, rgba(30, 41, 59, 0.35) 0%, rgba(10, 15, 26, 0.9) 100%);
  user-select: none;
}

/* Canvas / Viewport pour le zoom et le pan */
.mg-viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 12px 20px;
  box-sizing: border-box;
  touch-action: none;
}

.mg-img-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  transform-origin: center center;
  will-change: transform;
  transition: transform 0.12s ease-out;
  pointer-events: none;
}

.mg-img-wrap.is-animating {
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.mg-img-wrap.is-dragging {
  transition: none;
  cursor: grabbing !important;
}

.mg-current-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  display: block;
  border-radius: 8px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
  cursor: zoom-in;
}

.mg-viewport.is-zoomed .mg-current-img {
  cursor: grab;
}

.mg-viewport.is-zoomed.is-dragging .mg-current-img {
  cursor: grabbing;
}

/* Boutons de navigation Précédent / Suivant */
.mg-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(18, 24, 38, 0.75);
  border: 1px solid var(--mg-border);
  color: var(--mg-text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.2s ease;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.mg-nav--prev {
  left: 14px;
}

.mg-nav--next {
  right: 14px;
}

.mg-nav:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-50%) scale(1.08);
}

.mg-nav:active {
  transform: translateY(-50%) scale(0.94);
}

.mg-nav svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Pied compact de la modale avec miniatures pour navigation rapide */
.mg-footer {
  height: 46px;
  min-height: 46px;
  padding: 4px 12px;
  background: rgba(12, 17, 28, 0.85);
  border-top: 1px solid var(--mg-border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  z-index: 10;
}

.mg-footer::-webkit-scrollbar {
  height: 3px;
}

.mg-footer::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.mg-thumb {
  position: relative;
  height: 36px;
  width: 36px;
  min-width: 36px;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  opacity: 0.55;
  transition: all 0.2s ease;
  background: rgba(0, 0, 0, 0.3);
  padding: 0;
}

.mg-thumb:hover {
  opacity: 0.9;
  border-color: rgba(255, 255, 255, 0.3);
}

.mg-thumb.is-active {
  opacity: 1;
  border-color: var(--mg-accent);
  transform: scale(1.06);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.4);
}

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

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */

/* Écrans moyens (Laptops & Tablettes) */
@media (max-width: 1024px) {
  .mg-dialog {
    width: 92vw;
    height: 85vh;
    max-width: 92vw;
    max-height: 85vh;
  }
}

/* Petits écrans & Mobiles */
@media (max-width: 768px) {
  .mg-overlay {
    padding: 12px;
  }

  .mg-dialog {
    width: 96vw;
    height: 88vh;
    max-width: 96vw;
    max-height: 88vh;
    border-radius: 14px;
  }

  .mg-header {
    height: 48px;
    min-height: 48px;
    padding: 0 10px;
  }

  .mg-caption {
    display: none;
  }

  .mg-nav {
    width: 36px;
    height: 36px;
  }

  .mg-nav--prev {
    left: 8px;
  }

  .mg-nav--next {
    right: 8px;
  }

  .mg-footer {
    height: 52px;
    min-height: 52px;
    padding: 4px 10px;
  }

  .mg-thumb {
    height: 40px;
    width: 40px;
    min-width: 40px;
  }
}
