/* Header Instagram */
.instagram-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 20px;
  margin-bottom: 20px;
  background: #fff;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(20px);
  animation: slideInUp 0.6s ease-out forwards;
}

@keyframes slideInUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.profile-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.profile-picture {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  object-fit: cover;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.profile-picture:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 16px rgba(30, 115, 190, 0.3);
}

.profile-name {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.profile-name a {
  color: #262626;
  text-decoration: none;
  transition: color 0.3s ease;
}

.profile-name a:hover {
  color: #0095f6;
}

.follow-button {
  background: linear-gradient(135deg, #1f4181, #248ae4);
  color: white;
  padding: 8px 24px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 4px 15px rgba(30, 115, 190, 0.2);
  position: relative;
  overflow: hidden;
}

.follow-button::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.5s;
}

.follow-button:hover {
  background: linear-gradient(135deg, #1f4181, #2ea3ff);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(30, 115, 190, 0.3);
  text-decoration: none;
  color: white;
}

.follow-button:hover::before {
  left: 100%;
}

.follow-button:active {
  transform: translateY(0);
}

/* Grid Instagram avec animation de chargement */
.instagram-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 15px;
  opacity: 0;
  animation: fadeInGrid 0.8s ease-out 0.3s forwards;
}

@keyframes fadeInGrid {
  to {
    opacity: 1;
  }
}

.instagram-item {
  position: relative;
  width: 100%;
  padding-bottom: 100%;
  overflow: hidden;
  background-color: #f5f5f5;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(30px) scale(0.9);
  transition: all 0.4s ease;
}

/* Animation échelonnée pour les items - système amélioré */
.instagram-item:nth-child(1) {
  animation: slideInItem 0.6s ease-out 0.1s forwards;
}
.instagram-item:nth-child(2) {
  animation: slideInItem 0.6s ease-out 0.2s forwards;
}
.instagram-item:nth-child(3) {
  animation: slideInItem 0.6s ease-out 0.3s forwards;
}
.instagram-item:nth-child(4) {
  animation: slideInItem 0.6s ease-out 0.4s forwards;
}
.instagram-item:nth-child(5) {
  animation: slideInItem 0.6s ease-out 0.5s forwards;
}
.instagram-item:nth-child(6) {
  animation: slideInItem 0.6s ease-out 0.6s forwards;
}
.instagram-item:nth-child(7) {
  animation: slideInItem 0.6s ease-out 0.7s forwards;
}
.instagram-item:nth-child(8) {
  animation: slideInItem 0.6s ease-out 0.8s forwards;
}
.instagram-item:nth-child(9) {
  animation: slideInItem 0.6s ease-out 0.9s forwards;
}
.instagram-item:nth-child(10) {
  animation: slideInItem 0.6s ease-out 1s forwards;
}
.instagram-item:nth-child(11) {
  animation: slideInItem 0.6s ease-out 1.1s forwards;
}
.instagram-item:nth-child(12) {
  animation: slideInItem 0.6s ease-out 1.2s forwards;
}
.instagram-item:nth-child(13) {
  animation: slideInItem 0.6s ease-out 1.3s forwards;
}
.instagram-item:nth-child(14) {
  animation: slideInItem 0.6s ease-out 1.4s forwards;
}
.instagram-item:nth-child(15) {
  animation: slideInItem 0.6s ease-out 1.5s forwards;
}
.instagram-item:nth-child(16) {
  animation: slideInItem 0.6s ease-out 1.6s forwards;
}
.instagram-item:nth-child(17) {
  animation: slideInItem 0.6s ease-out 1.7s forwards;
}
.instagram-item:nth-child(18) {
  animation: slideInItem 0.6s ease-out 1.8s forwards;
}
.instagram-item:nth-child(19) {
  animation: slideInItem 0.6s ease-out 1.9s forwards;
}
.instagram-item:nth-child(20) {
  animation: slideInItem 0.6s ease-out 2s forwards;
}
.instagram-item:nth-child(21) {
  animation: slideInItem 0.6s ease-out 2.1s forwards;
}
.instagram-item:nth-child(22) {
  animation: slideInItem 0.6s ease-out 2.2s forwards;
}
.instagram-item:nth-child(23) {
  animation: slideInItem 0.6s ease-out 2.3s forwards;
}
.instagram-item:nth-child(24) {
  animation: slideInItem 0.6s ease-out 2.4s forwards;
}
.instagram-item:nth-child(25) {
  animation: slideInItem 0.6s ease-out 2.5s forwards;
}
.instagram-item:nth-child(26) {
  animation: slideInItem 0.6s ease-out 2.6s forwards;
}
.instagram-item:nth-child(27) {
  animation: slideInItem 0.6s ease-out 2.7s forwards;
}

/* Pour les éléments au-delà de 27, délai fixe pour éviter une attente trop longue */
.instagram-item:nth-child(n + 28) {
  animation: slideInItem 0.6s ease-out 2.8s forwards;
}

@keyframes slideInItem {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.instagram-item a {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
}

.instagram-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  filter: brightness(1) saturate(1);
}

.instagram-item img.lazy {
  opacity: 0;
}

.instagram-item img:not(.lazy) {
  opacity: 1;
}

/* Effets au survol améliorés */
.instagram-item:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.instagram-item:hover img {
  transform: scale(1.08);
  filter: brightness(1.1) saturate(1.2);
}

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

.video-container video {
  max-width: 100%;
  max-height: 70vh;
}

.video-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.1);
  transition: background-color 0.3s ease;
  pointer-events: none;
}

.video-overlay:hover {
  background: rgba(0, 0, 0, 0.2);
}

.video-overlay.hidden {
  display: none;
}

/* Lightbox avec animations améliorées */
.instagram-lightbox {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0);
  z-index: 1000;
  padding: 2rem;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  opacity: 0;
  backdrop-filter: blur(0px);
  transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  overscroll-behavior: contain;
  touch-action: none;
}

.instagram-lightbox.active {
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 1;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
}

.lightbox-content {
  position: relative;
  display: flex;
  width: 95%;
  max-width: 1200px;
  background: transparent;
  border-radius: 12px;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.8) translateY(50px);
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  will-change: transform, opacity;
  /* Ajout pour stabiliser la hauteur pendant les animations */
  min-height: 300px;
  max-height: 90vh;
}

.lightbox-content.loaded {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.lightbox-content::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: #fff;
  border-right-color: #fff;
  border-radius: 50%;
  /* animation: spinLoader 1.2s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite; */
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 1000;
}

/* .lightbox-content:not(.loaded)::before {
  opacity: 1;
} */

/* @keyframes spinLoader {
  0% {
    transform: translate(-50%, -50%) rotate(0deg) scale(1);
  }
  50% {
    transform: translate(-50%, -50%) rotate(180deg) scale(1.1);
  }
  100% {
    transform: translate(-50%, -50%) rotate(360deg) scale(1);
  }
} */

/* Les éléments du carrousel sont maintenant toujours visibles */
.lightbox-carousel-img,
.video-container {
  opacity: 1;
}

.lightbox-content.loaded::before {
  opacity: 0;
}

.close-lightbox {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2000;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  opacity: 0;
  transform: scale(0.8) rotate(90deg);
  animation: fadeInClose 0.5s ease-out 0.3s forwards;
}

@keyframes fadeInClose {
  to {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

.close-lightbox:hover {
  background: rgba(255, 255, 255, 1);
  transform: scale(1.1) rotate(-5deg);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.close-lightbox svg {
  width: 22px;
  height: 22px;
  fill: #333;
  transition: fill 0.3s ease;
}

.lightbox-media-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  position: relative;
  /* Stabiliser les dimensions */
  min-width: 300px;
  min-height: 300px;
  overflow: hidden;
}

.lightbox-media {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  /* Eviter les débordements pendant les animations */
  overflow: hidden;
}

.lightbox-media img,
.lightbox-media video {
  display: block;
  max-height: 90vh;
  max-width: 100%;
  width: auto;
  height: auto;
  background: #000;
  border-radius: 0 !important;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
  opacity: 1;
  object-fit: contain;
}

/* Style des contrôles vidéo */
.lightbox-media video::-webkit-media-controls-panel {
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7) 0%, transparent 100%);
}

.lightbox-media video::-webkit-media-controls-timeline {
  margin-bottom: 0;
}

.lightbox-media video::-webkit-media-controls-current-time-display,
.lightbox-media video::-webkit-media-controls-time-remaining-display {
  color: #fff;
}

/* Assurer que les contrôles restent visibles */
.lightbox-media video::-webkit-media-controls {
  opacity: 1 !important;
  display: flex !important;
}

.video-play-button {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 96px;
  height: 96px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  z-index: 2;
}

.video-play-button:hover {
  background: rgba(0, 0, 0, 0.9);
  transform: translate(-50%, -50%) scale(1.1);
}

.video-play-button svg {
  width: 40px;
  height: 40px;
  fill: white;
  margin-left: 6px;
  position: relative;
  left: -2px;
}

.video-play-button.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Commentaires */
.lightbox-comments-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  border-top: 1px solid #efefef;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.4s ease;
}

.lightbox-content.loaded .lightbox-comments-container {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0.7s;
}

.lightbox-comment {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  opacity: 0;
  transform: translateX(-10px);
  transition: all 0.3s ease;
}

.lightbox-content.loaded .lightbox-comment {
  opacity: 1;
  transform: translateX(0);
}

.lightbox-comment:nth-child(1) {
  transition-delay: 0.8s;
}
.lightbox-comment:nth-child(2) {
  transition-delay: 0.9s;
}
.lightbox-comment:nth-child(3) {
  transition-delay: 1s;
}
.lightbox-comment:nth-child(4) {
  transition-delay: 1.1s;
}
.lightbox-comment:nth-child(5) {
  transition-delay: 1.2s;
}

.lightbox-comment:last-child {
  margin-bottom: 0;
}

.lightbox-comment-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.lightbox-comment-content {
  flex: 1;
}

.lightbox-comment-username {
  font-weight: 600;
  color: #262626;
  text-decoration: none;
  margin-right: 4px;
}

.lightbox-comment-text {
  color: #262626;
  line-height: 1.5;
  display: inline;
}

.lightbox-comment-time {
  font-size: 0.9em;
  color: #8e8e8e;
  margin-top: 4px;
}

/* Ajuster la structure du sidebar */
.lightbox-sidebar {
  width: 450px;
  min-width: 450px;
  max-width: 450px;
  display: flex;
  flex-direction: column;
  max-height: 100vh;
  /* overflow-y: scroll; */
  /* Coins arrondis pour layout horizontal (901px+) : côté droit */
  border-radius: 0 12px 12px 0;
  background: #fff;
  opacity: 1;
  transform: translateX(0);
  transition: none;
}

/* .lightbox-content.loaded .lightbox-sidebar {
  opacity: 1;
  transform: translateX(0);
} */

.lightbox-caption-container {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  max-height: 44vw;
  padding-top: 16px;
  padding-bottom: 16px;
  padding-left: 16px;
  padding-right: 30px;
  /* border-bottom: 1px solid #efefef; */
}

.lightbox-header {
  padding: 14px 16px;
  /* border-bottom: 1px solid #efefef; */
  display: flex;
  align-items: center;
  gap: 12px;
}

.lightbox-header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.lightbox-header-username {
  font-weight: 600;
  color: #262626;
  text-decoration: none;
}

.lightbox-header-username:hover {
  color: #00376b;
}

.lightbox-caption-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.4s ease;
}

.lightbox-content.loaded .lightbox-caption-header {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0.4s;
}

.lightbox-caption-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.lightbox-caption-avatar:hover {
  transform: scale(1.1);
}

.lightbox-caption-username {
  font-weight: 600;
  color: #262626;
  text-decoration: none;
  font-size: 15px;
  line-height: 1.2;
  transition: color 0.3s ease;
}

.lightbox-caption-username:hover {
  color: #0095f6;
}

.lightbox-caption-text {
  margin-left: 48px;
  margin-top: 4px;
  font-size: 15px;
  color: #222;
  line-height: 1.5;
  word-break: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  text-align: left;
  /* Règles spécifiques pour le japonais */
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  /* Règles de césure japonaise */
  line-break: strict;
  overflow-wrap: anywhere;
  opacity: 0;
  transform: translateY(15px);
  transition: all 0.4s ease;
}

.lightbox-content.loaded .lightbox-caption-text {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0.5s;
}

/* Ajustement pour les liens et hashtags */
.lightbox-caption-text a {
  word-break: keep-all;
  overflow-wrap: break-word;
}

.lightbox-timestamp {
  margin-top: 24px;
  color: #8e8e8e;
  font-size: 0.8em;
  margin-left: 48px;
  /* border-top: 1px solid #efefef; */
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.4s ease;
}

.lightbox-content.loaded .lightbox-timestamp {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0.6s;
}

/* Load More Button avec animations */
.load-more-container {
  text-align: center;
  margin: 30px 0;
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp 0.6s ease-out 1.2s forwards;
}

@keyframes fadeInUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.load-more-button {
  background: linear-gradient(135deg, #1f4181, #248ae4);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 4px 15px rgba(30, 115, 190, 0.2);
  position: relative;
  overflow: hidden;
}

/* État de chargement */
.load-more-button.loading {
  background: linear-gradient(135deg, #6c757d, #868e96);
  cursor: not-allowed;
  pointer-events: none;
  padding-left: 40px; /* Espace pour le spinner */
}

.load-more-button.loading::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 12px;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: loadMoreSpin 1s linear infinite;
}

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

/* État d'erreur */
.load-more-button.error {
  background: linear-gradient(135deg, #dc3545, #e85463);
  animation: errorPulse 0.5s ease-in-out;
}

@keyframes errorPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

/* Effet de brillance existant */
.load-more-button::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.5s;
}

.load-more-button:hover:not(.loading):not(.error) {
  background: linear-gradient(135deg, #1f4181, #2ea3ff);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(30, 115, 190, 0.3);
}

.load-more-button:hover:not(.loading):not(.error)::before {
  left: 100%;
}

.load-more-button:active:not(.loading):not(.error) {
  transform: translateY(0);
}

.load-more-button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Navigation Arrows avec animations améliorées */
.lightbox-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 1010;
  opacity: 0;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.instagram-lightbox.active .lightbox-nav {
  opacity: 0.8;
  animation: slideInNav 0.6s ease-out 0.4s forwards;
}

@keyframes slideInNav {
  to {
    opacity: 0.9;
  }
}

.lightbox-nav.prev {
  left: 50px;
}

.lightbox-nav.next {
  right: 50px;
}

.lightbox-nav:hover {
  background: rgba(255, 255, 255, 1);
  opacity: 1 !important;
  transform: translateY(-50%) scale(1.1);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
}

.lightbox-nav svg {
  width: 26px;
  height: 26px;
  fill: #333;
  transition: all 0.3s ease;
}

.lightbox-nav:hover svg {
  fill: #1e73be;
}

.lightbox-nav.hidden {
  display: none;
}

/* Responsive adjustments */
@media screen and (max-width: 1200px) {
  .lightbox-content {
    width: auto;
    max-width: 100vw;
    height: auto;
    max-height: 95vh;
  }

  .lightbox-media-container {
    width: fit-content;
    max-width: fit-content;
    margin: 0 auto;
    padding: 0;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
  }

  .lightbox-caption-text {
    font-size: 14px;
    line-height: 1.4;
  }

  .lightbox-caption-username {
    font-size: 14px;
  }

  .lightbox-nav {
    width: 38px;
    height: 38px;
  }

  .lightbox-nav svg {
    width: 22px;
    height: 22px;
  }

  .lightbox-nav.prev {
    left: -50px;
  }

  .lightbox-nav.next {
    right: -50px;
  }

  .lightbox-sidebar {
    width: 450px;
    min-width: 450px;
  }
}

@media screen and (max-width: 768px) {
  .instagram-header {
    padding: 15px;
    margin-bottom: 15px;
  }

  .profile-picture {
    width: 40px;
    height: 40px;
  }

  .profile-name {
    font-size: 14px;
  }

  .follow-button {
    padding: 6px 18px;
    font-size: 14px;
  }

  .lightbox-caption-text {
    font-size: 13px;
    margin-left: -10px;
  }

  .lightbox-caption-username {
    font-size: 13px;
  }

  .lightbox-timestamp {
    font-size: 12px;
  }

  .lightbox-content {
    width: 100%;
    max-width: 100%;
    flex-direction: column;
  }

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

  .lightbox-nav svg {
    width: 20px;
    height: 20px;
  }

  .lightbox-nav.prev {
    left: 10px;
  }

  .lightbox-nav.next {
    right: 10px;
  }

  .video-container {
    background: #fff;
    width: 100%;
    height: 100%;
  }

  .video-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
  }

  /* Optimiser les contrôles vidéo pour le tactile */
  .video-play-button {
    width: 72px;
    height: 72px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .video-play-button svg {
    width: 36px;
    height: 36px;
  }

  .video-overlay {
    background: rgba(0, 0, 0, 0.2);
  }

  .lightbox-media img,
  .lightbox-media video {
    object-fit: contain;
  }
}

@media screen and (max-width: 480px) {
  .instagram-header {
    padding: 12px;
    margin-bottom: 12px;
  }

  .profile-picture {
    width: 35px;
    height: 35px;
  }

  .profile-name {
    font-size: 13px;
  }

  .follow-button {
    padding: 5px 15px;
    font-size: 13px;
  }

  .lightbox-caption-text {
    font-size: 12px;
    margin-left: 36px !important;
  }

  .lightbox-caption-username {
    font-size: 12px;
  }

  .lightbox-timestamp {
    font-size: 11px;
    margin-left: 36px !important;
  }

  .instagram-lightbox {
    padding: 0;
  }

  .lightbox-content {
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .lightbox-media-container {
    width: 100%;
    height: 70vh;
    max-height: 90vh;
    background: #fff;
  }

  .lightbox-media {
    width: 100%;
    height: 100%;
  }

  .lightbox-media img,
  .lightbox-media video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    margin: auto;
  }

  .lightbox-sidebar {
    max-height: calc(100vh - 100vw - 60px);
  }

  .lightbox-header,
  .lightbox-caption-container,
  .lightbox-comments-container {
    padding: 12px;
  }

  .close-lightbox {
    top: 8px;
    right: 8px;
  }

  .lightbox-nav {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.7);
  }

  .lightbox-nav svg {
    width: 18px;
    height: 18px;
  }

  .lightbox-nav.prev {
    left: 6px;
  }

  .lightbox-nav.next {
    right: 6px;
  }

  .video-container {
    max-height: none;
    aspect-ratio: 1;
  }

  .video-container video {
    max-height: 80vh;
  }

  .video-play-button {
    width: 64px;
    height: 64px;
  }

  .video-play-button svg {
    width: 32px;
    height: 32px;
  }
}

/* Ajustement pour les appareils en mode paysage */
@media screen and (max-height: 480px) and (orientation: landscape) {
  .lightbox-nav {
    width: 30px;
    height: 30px;
  }

  .lightbox-nav svg {
    width: 16px;
    height: 16px;
  }

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

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

/* Responsive */
@media screen and (max-width: 1200px) {
  .lightbox-content {
    width: 100%;
  }

  .lightbox-media img,
  .lightbox-media video {
    max-height: 80vh;
  }

  .lightbox-sidebar {
    width: 350px;
    min-width: 350px;
  }

  .lightbox-nav.prev {
    left: 5%;
  }

  .lightbox-nav.next {
    right: 5%;
  }
}

/* Responsive mobile et tablette - amélioré */
@media screen and (max-width: 900px) {
  .lightbox-content {
    flex-direction: column;
    width: 95%;
    max-width: 100vw;
    height: auto;
    max-height: 95vh;
    min-height: 200px;
    align-items: center;
    justify-content: flex-start;
    background: transparent;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    overflow: hidden;
  }

  .lightbox-media-container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 0;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border-radius: 12px 12px 0 0;
    overflow: hidden;
    max-height: 50vh;
    min-height: 200px;
  }

  .lightbox-media {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
  }

  .lightbox-media img,
  .lightbox-media video {
    width: 100%;
    height: 100%;
    max-height: 50vh;
    object-fit: contain;
    display: block;
    margin: auto;
  }

  .lightbox-sidebar {
    width: 100%;
    min-width: 0;
    max-width: 500px;
    margin: 0 auto;
    background: #fff;
    box-sizing: border-box;
    max-height: 45vh;
    overflow-y: auto;
    border-radius: 0 0 12px 12px;
    display: flex;
    flex-direction: column;
  }

  .lightbox-caption-container,
  .lightbox-comments-container {
    width: 100%;
    box-sizing: border-box;
    padding-left: 16px;
    padding-right: 16px;
  }

  .lightbox-caption-container {
    padding: 12px 16px;
    max-height: none;
  }

  .lightbox-nav {
    width: 40px;
    height: 40px;
  }

  .lightbox-nav svg {
    width: 20px;
    height: 20px;
  }

  .lightbox-nav.prev {
    left: 10px;
  }

  .lightbox-nav.next {
    right: 10px;
  }

  /* Simplifier les animations sur mobile pour plus de fluidité */
  @keyframes slideInLeftMobile {
    0% {
      transform: translate3d(-100%, 0, 0);
      opacity: 0;
    }
    100% {
      transform: translate3d(0, 0, 0);
      opacity: 1;
    }
  }

  @keyframes slideInRightMobile {
    0% {
      transform: translate3d(100%, 0, 0);
      opacity: 0;
    }
    100% {
      transform: translate3d(0, 0, 0);
      opacity: 1;
    }
  }

  @keyframes slideOutLeftMobile {
    0% {
      transform: translate3d(0, 0, 0);
      opacity: 1;
    }
    100% {
      transform: translate3d(-100%, 0, 0);
      opacity: 0;
    }
  }

  @keyframes slideOutRightMobile {
    0% {
      transform: translate3d(0, 0, 0);
      opacity: 1;
    }
    100% {
      transform: translate3d(100%, 0, 0);
      opacity: 0;
    }
  }

  .slide-in-left {
    animation: slideInLeftMobile 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) forwards !important;
  }

  .slide-in-right {
    animation: slideInRightMobile 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) forwards !important;
  }

  .slide-out-left {
    animation: slideOutLeftMobile 0.3s cubic-bezier(0.4, 0, 0.6, 1) forwards !important;
  }

  .slide-out-right {
    animation: slideOutRightMobile 0.3s cubic-bezier(0.4, 0, 0.6, 1) forwards !important;
  }

  /* Désactiver les animations internes du sidebar pour éviter le jitter mobile */
  .lightbox-caption-header,
  .lightbox-caption-text,
  .lightbox-timestamp,
  .lightbox-comments-container,
  .lightbox-comment,
  .lightbox-comment *,
  .load-more-container {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
    animation: none !important;
  }
}

@media screen and (max-width: 480px) {
  .instagram-lightbox {
    padding: 0;
  }

  .lightbox-content {
    width: 75%;
    height: 75vh;
    max-height: 75vh;
    border-radius: 12px;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    background: transparent;
    box-shadow: none;
    overflow: hidden;
  }

  .lightbox-media-container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    /* Coins arrondis pour layout vertical (480px et moins) : côté haut */
    border-radius: 12px 12px 0 0;
    overflow: hidden;
    /* Dimensions dynamiques contrôlées par JavaScript */
    max-height: 50vh;
    min-height: 20vh;
    height: 26vh; /* Valeur par défaut */
  }

  .lightbox-media {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
  }

  .lightbox-media img,
  .lightbox-media video {
    width: 100%;
    height: 100%;
    max-height: 100%;
    max-width: 100%;
    /* object-fit sera contrôlé dynamiquement par JavaScript */
    object-fit: cover;
    display: block;
    margin: auto;
  }

  .lightbox-sidebar {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin: 0 auto;
    background: #fff;
    box-sizing: border-box;
    /* max-height sera ajusté dynamiquement par JavaScript */
    max-height: 45vh;
    min-height: 15vh;
    height: auto;
    overflow-y: auto;
    border-radius: 0 0 12px 12px;
    /* Enlever flex: 1 pour éviter qu'elle prenne tout l'espace */
  }

  .lightbox-header,
  .lightbox-caption-container,
  .lightbox-comments-container {
    padding: 12px;
    width: 100%;
    box-sizing: border-box;
  }

  .close-lightbox {
    top: 8px;
    right: 8px;
  }

  .lightbox-nav {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.7);
  }

  .lightbox-nav svg {
    width: 18px;
    height: 18px;
  }

  .lightbox-nav.prev {
    left: 6px;
  }

  .lightbox-nav.next {
    right: 6px;
  }

  .video-container {
    /* Dimensions dynamiques contrôlées par JavaScript */
    max-height: 50vh;
    min-height: 20vh;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .video-container video {
    max-height: 100%;
    max-width: 100%;
    width: 100%;
    height: 100%;
    /* object-fit sera contrôlé dynamiquement par JavaScript */
    object-fit: cover;
  }

  .video-play-button {
    width: 64px;
    height: 64px;
  }

  .video-play-button svg {
    width: 32px;
    height: 32px;
  }
}

/* Ajustements pour les appareils en mode paysage */
@media screen and (max-height: 600px) and (orientation: landscape) {
  .lightbox-content {
    flex-direction: row;
    height: 95vh;
  }

  .lightbox-media-container {
    height: 95vh;
    max-height: none;
  }

  .lightbox-media img,
  .lightbox-media video {
    max-height: 95vh;
    height: 95vh;
  }

  .lightbox-sidebar {
    width: 300px;
    min-width: 300px;
    max-height: 95vh;
  }
}

.video-timeline-container {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  background: rgba(0, 0, 0, 0.5);
  padding: 8px 12px 4px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 10;
  box-sizing: border-box;
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
}
.video-timeline {
  flex: 1;
  appearance: none;
  height: 4px;
  background: #fff;
  border-radius: 2px;
  outline: none;
  margin: 0 8px;
  cursor: pointer;
}
.video-timeline::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2196f3;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: background 0.2s;
}
.video-timeline::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2196f3;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: background 0.2s;
}
.video-timeline::-ms-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2196f3;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: background 0.2s;
}
.video-current-time,
.video-duration {
  color: #fff;
  font-size: 13px;
  min-width: 38px;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Flèches du carrousel avec couleurs distinctives */
.carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3000;
  width: 40px;
  height: 40px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.3);
  padding: 0;
  opacity: 0.9;
}

/* Animation d'apparition initiale uniquement */
.carousel-container:not(.carousel-initialized) .carousel-arrow {
  opacity: 0;
  scale: 0.8;
  animation: carouselArrowFadeIn 0.6s ease-out 0.3s forwards;
}

@keyframes carouselArrowFadeIn {
  to {
    opacity: 0.9;
    scale: 1;
  }
}

.carousel-arrow:hover {
  background: rgba(0, 0, 0, 0.9);
  transform: translateY(-50%) scale(1.15);
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.4);
  border-color: rgba(255, 255, 255, 0.6);
  opacity: 1 !important;
}

.carousel-arrow:hover svg {
  fill: #ffd700;
  transform: scale(1.1);
}

.carousel-arrow:active {
  transform: translateY(-50%) scale(1.05);
}

.carousel-arrow-left {
  left: 12px;
}

.carousel-arrow-right {
  right: 12px;
}
@media (max-width: 600px) {
  .carousel-arrow {
    width: 44px;
    height: 44px;
  }
  .carousel-arrow-left {
    left: 8px;
  }
  .carousel-arrow-right {
    right: 8px;
  }
}

.carousel-arrow svg {
  width: 20px;
  height: 20px;
  fill: #fff;
  display: block;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Pagination des carrousels améliorée */
.carousel-pagination {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 3100;
  opacity: 1;
}

/* Animation d'apparition initiale uniquement pour la pagination */
.carousel-container:not(.carousel-initialized) .carousel-pagination {
  opacity: 0;
  animation: carouselPaginationFadeIn 0.6s ease-out 0.5s forwards;
}

@keyframes carouselPaginationFadeIn {
  to {
    opacity: 1;
  }
}

.carousel-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  opacity: 0.8;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.carousel-dot:hover {
  background: rgba(255, 255, 255, 0.9);
  transform: scale(1.2);
  opacity: 1;
}

.carousel-dot.active {
  background: #fff;
  opacity: 1;
  transform: scale(1.3);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
}

.carousel-arrow:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(30, 115, 190, 0.3);
}

.carousel-arrow:focus:not(:hover) {
  transform: translateY(-50%) scale(1.05);
}

.cig-icon {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.1em;
  height: 2.1em;
  min-width: 28px;
  min-height: 28px;
  max-width: 38px;
  max-height: 38px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 50%;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  font-size: 1.1em;
  pointer-events: none;
}
.cig-icon svg {
  width: 1.2em;
  height: 1.2em;
  display: block;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
}
@media (max-width: 900px) {
  .cig-icon {
    width: 1.7em;
    height: 1.7em;
    min-width: 20px;
    min-height: 20px;
    max-width: 28px;
    max-height: 28px;
    font-size: 1em;
    top: 5px;
    right: 5px;
  }
  .cig-icon svg {
    width: 1em;
    height: 1em;
  }
}

@media (max-width: 600px) {
  .lightbox-caption-avatar {
    width: 28px;
    height: 28px;
  }
  /* .lightbox-caption-text {
    margin-left: 36px;
    font-size: 14px;
  } */
  .lightbox-caption-username {
    font-size: 14px;
  }
}

@media screen and (min-width: 901px) and (max-width: 1200px) {
  .lightbox-content {
    max-width: calc(100vw - 120px);
    margin: 0 auto;
  }
}

@media screen and (max-width: 1200px) {
  .lightbox-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2001;
  }
  .lightbox-nav.prev {
    left: 2px !important;
  }
  .lightbox-nav.next {
    right: 2px !important;
  }
}

@media screen and (max-width: 600px) {
  .carousel-arrow {
    width: 42px;
    height: 42px;
  }
}

/* Conteneur fixe pour éviter les redimensionnements */
.carousel-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Forcer des dimensions minimales pour éviter le redimensionnement */
.lightbox-media {
  display: flex;
  position: relative;
  max-width: 100%;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
}

/* Stabiliser les dimensions des éléments média */
.lightbox-carousel-img,
.video-container {
  opacity: 1;
  transition: none !important; /* Supprimer toutes les transitions */
}

.video-container {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Conteneur global et Navigation --- */
.cig-container {
  position: relative;
}

.cig-nav-wrapper {
  display: none; /* Caché par défaut, affiché par la lightbox */
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  /* On prend la largeur max de la lightbox (1200px) + 80px de chaque côté pour les flèches */
  max-width: 1360px;
  height: 0;
  z-index: 1001;
  pointer-events: none;
}

.instagram-lightbox.active .cig-nav-wrapper {
  display: block;
}

/* On stylise directement les flèches d'origine */
.lightbox-nav {
  pointer-events: auto; /* Rend les flèches cliquables */
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  transition: background-color 0.3s, opacity 0.3s;
}

/* On positionne les flèches aux extrémités du wrapper */
.lightbox-nav.prev {
  left: 20px;
}

.lightbox-nav.next {
  right: 20px;
}

/* Sur les écrans assez larges, on colle les flèches aux bords */
@media (min-width: 1360px) {
  .lightbox-nav.prev {
    left: 0;
  }
  .lightbox-nav.next {
    right: 0;
  }
}

@keyframes slideInBottom {
  0% {
    transform: translateY(100%) scale(0.95);
    opacity: 0;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes slideOutLeft {
  0% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateX(-100%) scale(0.98);
    opacity: 0;
  }
}

@keyframes slideOutRight {
  0% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateX(100%) scale(0.98);
    opacity: 0;
  }
}

@keyframes slideInRight {
  0% {
    transform: translateX(100%) scale(0.98);
    opacity: 0;
  }
  100% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
}

@keyframes slideInLeft {
  0% {
    transform: translateX(-100%) scale(0.98);
    opacity: 0;
  }
  100% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
}

/* Classes d'animation avec timing optimisé */
.slide-in-bottom {
  animation: slideInBottom 0.6s cubic-bezier(0.65, 0.05, 0.36, 1) forwards;
}

.slide-out-left {
  animation: slideOutLeft 0.6s cubic-bezier(0.65, 0.05, 0.36, 1) forwards;
}

.slide-out-right {
  animation: slideOutRight 0.6s cubic-bezier(0.65, 0.05, 0.36, 1) forwards;
}

.slide-in-right {
  animation: slideInRight 0.6s cubic-bezier(0.65, 0.05, 0.36, 1) forwards;
}

.slide-in-left {
  animation: slideInLeft 0.6s cubic-bezier(0.65, 0.05, 0.36, 1) forwards;
}

/* Amélioration du responsive - desktop */
@media screen and (min-width: 901px) {
  .lightbox-content {
    flex-direction: row;
    max-height: 85vh;
    height: auto;
  }

  .lightbox-media-container {
    width: 60%;
    height: auto;
    max-height: 85vh;
  }

  .lightbox-sidebar {
    width: 40%;
    min-width: 350px;
    max-width: 450px;
    background: #fff;
    display: flex;
    flex-direction: column;
    max-height: 85vh;
  }
}

/* Nouvelle animation pour la fermeture depuis le bas */
@keyframes slideOutBottom {
  0% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateY(100%) scale(0.95);
    opacity: 0;
  }
}

.slide-out-bottom {
  animation: slideOutBottom 0.4s cubic-bezier(0.4, 0, 0.6, 1) forwards;
}

/* Animation mobile */
@media screen and (max-width: 900px) {
  @keyframes slideOutBottomMobile {
    0% {
      transform: translate3d(0, 0, 0);
      opacity: 1;
    }
    100% {
      transform: translate3d(0, 100%, 0);
      opacity: 0;
    }
  }
  .slide-out-bottom {
    animation: slideOutBottomMobile 0.3s cubic-bezier(0.4, 0, 0.6, 1) forwards !important;
  }
}

/* Animation de fondu du fond pour la fermeture de la lightbox */
.instagram-lightbox.fade-out {
  opacity: 0 !important;
  background: rgba(0, 0, 0, 0) !important;
  backdrop-filter: blur(0px) !important;
}

/* Animation de fondu du fond pour l'ouverture de la lightbox */
@keyframes fadeInOverlay {
  0% {
    opacity: 0;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
  }
  100% {
    opacity: 1;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
  }
}

.instagram-lightbox.fade-in {
  display: flex !important; /* s'assurer qu'elle est visible */
  animation: fadeInOverlay 0.4s ease forwards;
}
