/* JG Justified Gallery - Styles optimisés */

.jgl-gallery {
  font-size: 0;
  line-height: 0;
  /* Pour une meilleure accessibilité */
  margin: 0;
  padding: 0;
}

/* États de chargement */
.jgl-gallery.jgl-pending {
  opacity: 0.02;
  transition: opacity 0.2s linear;
}

.jgl-gallery.jgl-ready {
  opacity: 1;
  transition: opacity 0.3s ease-in-out;
}

/* Items de la galerie */
.jgl-item {
  position: relative;
  display: inline-block;
  overflow: hidden;
  vertical-align: bottom;
  /* Accessibilité et UX */
  cursor: pointer;
  outline: none;
}

.jgl-item:focus {
  outline: 2px solid #0073aa;
  outline-offset: 2px;
}

/* Images et vidéos */
.jgl-item img,
.jgl-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* Transition fluide pour les changements de taille */
  transition: transform 0.3s ease;
}

.jgl-item:hover img,
.jgl-item:focus img {
  transform: scale(1.02);
}

/* Légendes */
.jgl-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.4em 0.6em;
  font-size: 12px;
  line-height: 1.2;
  background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.4) 100%);
  color: #fff;
  opacity: 0;
  transition: opacity 0.3s ease;
  /* Accessibilité */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

.jgl-item:hover .jgl-caption,
.jgl-item:focus .jgl-caption {
  opacity: 1;
}

/* Mode Mosaic */
.jgl-gallery[data-mode="mosaic"] .jgl-item {
  display: block;
}

/* Mode Debug */
.jgl-gallery[data-debug="1"] .jgl-item {
  outline: 1px dashed rgba(255,0,0,0.3);
}

/* Responsive Design - Mobile First */
@media (max-width: 768px) {
  .jgl-gallery {
    /* Amélioration du touch sur mobile */
    -webkit-tap-highlight-color: transparent;
  }
  
  .jgl-item {
    /* Plus grand touch target sur mobile */
    touch-action: manipulation;
  }
  
  .jgl-caption {
    font-size: 11px;
    padding: 0.3em 0.5em;
    /* Toujours visible sur mobile (pas de hover) */
    opacity: 1;
    background: rgba(0,0,0,0.7);
  }
  
  .jgl-item:active {
    transform: scale(0.98);
  }
}

@media (max-width: 480px) {
  .jgl-caption {
    font-size: 10px;
    padding: 0.2em 0.4em;
  }
}

/* Amélioration pour les écrans haute résolution */
@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 192dpi) {
  .jgl-item img,
  .jgl-item video {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* Mode contraste élevé (accessibilité) */
@media (prefers-contrast: high) {
  .jgl-item {
    outline: 2px solid currentColor;
  }
  
  .jgl-caption {
    background: #000;
    border-top: 2px solid #fff;
  }
}

/* Mode sombre (prefers-color-scheme) */
@media (prefers-color-scheme: dark) {
  .jgl-caption {
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.5) 100%);
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
  }
}

/* Réduction des animations pour les utilisateurs sensibles */
@media (prefers-reduced-motion: reduce) {
  .jgl-gallery.jgl-pending,
  .jgl-gallery.jgl-ready,
  .jgl-caption,
  .jgl-item img {
    transition: none !important;
    animation: none !important;
  }
}

/* Impression */
@media print {
  .jgl-gallery {
    page-break-inside: avoid;
  }
  
  .jgl-item {
    page-break-inside: avoid;
    display: inline-block;
    max-width: 45%;
    margin: 5px;
  }
  
  .jgl-caption {
    position: static;
    background: transparent;
    color: #000;
    opacity: 1;
    padding: 0.2em 0;
    border-bottom: 1px solid #ccc;
  }
}

/* Amélioration de la lisibilité */
.jgl-gallery[aria-label]::before {
  content: attr(aria-label);
  display: none;
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 15px;
  color: #333;
}

/* Support des lecteurs d'écran */
.jgl-item[role="img"] {
  /* Les lecteurs d'écran liront l'attribut aria-label */
}

/* Loading skeleton amélioré */
.jgl-gallery.jgl-pending .jgl-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, 
    transparent 0%, 
    rgba(255,255,255,0.2) 50%, 
    transparent 100%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.jgl-gallery.jgl-ready .jgl-item::before {
  display: none;
}
