/* ============================================================
   AutoGallery — Flatboard 5 Plugin — v1.2.0
   Carousel interactif pour les posts avec plusieurs images
   Transitions : slide, fade, zoom, flip, cube, blur, bounce
   + Diaporama automatique
   ============================================================ */

/* ---------------------------------------------------------------------------
   Source [gallery]...[/gallery] (dégradation gracieuse sans JS)
   --------------------------------------------------------------------------- */
.ag-gallery-source {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.ag-gallery-source img {
  max-width: 100%;
  height: auto;
}

/* ---------------------------------------------------------------------------
   Conteneur principal
   --------------------------------------------------------------------------- */
.ag-gallery {
  position: relative;
  width: 100%;
  background: var(--bg-secondary, #f8f9fa);
  border: 1px solid var(--border-color-dark, #dee2e6);
  border-radius: var(--radius-md, 8px);
  overflow: hidden;
  box-shadow: var(--shadow-md, 0 2px 8px rgba(0,0,0,.1));
  margin: 0.75rem 0;
  outline: none;
}

/* Indicateur de lecture : fine bordure discrète en haut */
.ag-gallery--playing {
  border-top-color: var(--primary-color, #0d6efd);
  border-top-width: 2px;
}

/* ---------------------------------------------------------------------------
   Viewport
   --------------------------------------------------------------------------- */
.ag-viewport {
  position: relative;
  width: 100%;
  overflow: hidden;
  background: var(--bg-primary, #fff);
  max-height: 520px;
}

/* Cube : la perspective doit être sur le viewport */
.ag-gallery--cube .ag-viewport {
  perspective: 1000px;
  overflow: visible;
  transform-style: preserve-3d;
}

/* ---------------------------------------------------------------------------
   Track
   --------------------------------------------------------------------------- */
.ag-track {
  display: flex;
  will-change: transform;
}

/* --- Slide --- */
.ag-track--slide {
  transition: transform 380ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* --- Bounce --- */
.ag-track--bounce {
  transition: transform 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- Fade, Zoom, Flip, Blur --- */
.ag-track--fade,
.ag-track--zoom,
.ag-track--flip,
.ag-track--blur {
  transition: none;
}

/* --- Cube --- */
.ag-track--cube {
  transform-style: preserve-3d;
  transition: transform 600ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
  width: 100%;
  height: 100%;
}

/* ---------------------------------------------------------------------------
   Slides — base
   --------------------------------------------------------------------------- */
.ag-slide {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary, #fff);
  min-height: 200px;
  max-height: 520px;
}

.ag-slide img {
  display: block;
  max-width: 100%;
  max-height: 500px;
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: pointer;
  border-radius: 0;
}

/* ---- FADE ---- */
.ag-track--fade .ag-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 400ms ease;
  pointer-events: none;
}
.ag-track--fade .ag-slide.ag-slide--active {
  position: relative;
  opacity: 1;
  pointer-events: auto;
}

/* ---- ZOOM ---- */
.ag-track--zoom .ag-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: scale(0.75);
  transition: opacity 420ms ease, transform 420ms ease;
  pointer-events: none;
}
.ag-track--zoom .ag-slide.ag-slide--active {
  position: relative;
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}
.ag-track--zoom .ag-slide.ag-slide--leave {
  opacity: 0;
  transform: scale(1.15);
  pointer-events: none;
}

/* ---- FLIP ---- */
.ag-track--flip {
  perspective: 900px;
}
.ag-track--flip .ag-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: rotateY(90deg);
  transition: opacity 400ms ease, transform 400ms ease;
  pointer-events: none;
  backface-visibility: hidden;
}
.ag-track--flip .ag-slide.ag-slide--active {
  position: relative;
  opacity: 1;
  transform: rotateY(0deg);
  pointer-events: auto;
}
.ag-track--flip .ag-slide.ag-slide--leave {
  opacity: 0;
  transform: rotateY(-90deg);
  pointer-events: none;
}

/* ---- BLUR ---- */
.ag-track--blur .ag-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  filter: blur(8px);
  transform: scale(1.04);
  transition: opacity 450ms ease, filter 450ms ease, transform 450ms ease;
  pointer-events: none;
}
.ag-track--blur .ag-slide.ag-slide--active {
  position: relative;
  opacity: 1;
  filter: blur(0);
  transform: scale(1);
  pointer-events: auto;
}
.ag-track--blur .ag-slide.ag-slide--leave {
  opacity: 0;
  filter: blur(12px);
  transform: scale(0.96);
  pointer-events: none;
}

/* ---- CUBE ---- */
.ag-track--cube .ag-slide {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  backface-visibility: hidden;
  pointer-events: none;
}
.ag-track--cube .ag-slide.ag-slide--active {
  opacity: 1;
  pointer-events: auto;
}

/* ---------------------------------------------------------------------------
   Boutons prev/next
   --------------------------------------------------------------------------- */
.ag-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: rgba(0,0,0,.45);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.2s ease, opacity 0.2s ease;
  padding: 0;
  line-height: 1;
}
.ag-btn:hover { background: rgba(0,0,0,.72); }
.ag-btn:focus-visible {
  outline: 2px solid var(--primary-color, #0d6efd);
  outline-offset: 2px;
}
.ag-prev { left: 10px; }
.ag-next { right: 10px; }

/* ---------------------------------------------------------------------------
   Footer
   --------------------------------------------------------------------------- */
.ag-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-secondary, #f8f9fa);
  border-top: 1px solid var(--border-color-dark, #dee2e6);
  min-height: 40px;
  gap: 8px;
}

.ag-footer-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Dots */
.ag-dots {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: center;
}
.ag-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-color-dark, #adb5bd);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
  flex-shrink: 0;
}
.ag-dot:hover { background: var(--primary-color, #0d6efd); }
.ag-dot.ag-dot--active {
  background: var(--primary-color, #0d6efd);
  transform: scale(1.25);
}

/* Counter */
.ag-counter {
  font-size: 0.8rem;
  color: var(--text-muted, #6c757d);
  white-space: nowrap;
  min-width: 3em;
  text-align: right;
}

/* ---------------------------------------------------------------------------
   Bouton diaporama — 3 états visuels
   [en marche, pas de survol] : icône fa-circle-notch spinning (bleu)
   [en marche, survol]        : icône fa-pause (rouge/sombre = "cliquer pour pausé")
   [en pause]                 : icône fa-play (gris, bleu au survol)
   --------------------------------------------------------------------------- */
.ag-slideshow-btn {
  background: transparent;
  border: 1px solid var(--border-color-dark, #dee2e6);
  color: var(--text-muted, #6c757d);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.72rem;
  padding: 0;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
  flex-shrink: 0;
}

/* Pause : survol → bleu pour lancer */
.ag-slideshow-btn:hover {
  background: var(--primary-color, #0d6efd);
  border-color: var(--primary-color, #0d6efd);
  color: #fff;
}

/* En lecture (pas de survol) : spinning bleu */
.ag-gallery--playing .ag-slideshow-btn {
  background: rgba(13, 110, 253, 0.10);
  border-color: var(--primary-color, #0d6efd);
  color: var(--primary-color, #0d6efd);
}

/* En lecture + survol : rouge sombre pour indiquer "cliquer = stopper" */
.ag-gallery--playing .ag-slideshow-btn:hover {
  background: #dc3545;
  border-color: #dc3545;
  color: #fff;
}

.ag-slideshow-btn:focus-visible {
  outline: 2px solid var(--primary-color, #0d6efd);
  outline-offset: 2px;
}

/* Spinning icon speed */
.ag-ss-spin {
  animation-duration: 1.8s !important;
}

/* ---------------------------------------------------------------------------
   Miniatures
   --------------------------------------------------------------------------- */
.ag-thumbs {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  overflow-x: auto;
  background: var(--bg-secondary, #f8f9fa);
  scrollbar-width: thin;
}
.ag-thumbs::-webkit-scrollbar { height: 4px; }
.ag-thumbs::-webkit-scrollbar-thumb {
  background: var(--border-color-dark, #dee2e6);
  border-radius: 2px;
}
.ag-thumb {
  flex-shrink: 0;
  width: 80px;
  height: 60px;
  border-radius: 4px;
  overflow: hidden;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  opacity: 0.65;
}
.ag-thumb:hover { border-color: var(--primary-color, #0d6efd); opacity: 1; }
.ag-thumb.ag-thumb--active {
  border-color: var(--primary-color, #0d6efd);
  box-shadow: 0 0 0 2px rgba(13,110,253,.35);
  opacity: 1;
}
.ag-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---------------------------------------------------------------------------
   Lightbox
   --------------------------------------------------------------------------- */
#ag-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,.92);
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
#ag-lightbox.ag-lightbox--open { display: flex; }
.ag-lb-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-md, 8px);
  box-shadow: 0 4px 24px rgba(0,0,0,.6);
  display: block;
}
.ag-lb-close, .ag-lb-prev, .ag-lb-next {
  position: fixed;
  background: rgba(255,255,255,.15);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background 0.2s ease;
  padding: 0;
  z-index: 10000;
}
.ag-lb-close:hover, .ag-lb-prev:hover, .ag-lb-next:hover {
  background: rgba(255,255,255,.3);
}
.ag-lb-close { top: 16px; right: 16px; }
.ag-lb-prev  { left: 16px; top: 50%; transform: translateY(-50%); }
.ag-lb-next  { right: 16px; top: 50%; transform: translateY(-50%); }
.ag-lb-counter {
  color: rgba(255,255,255,.7);
  font-size: 0.85rem;
  margin-top: 10px;
}

/* ---------------------------------------------------------------------------
   Dark mode
   --------------------------------------------------------------------------- */
[data-theme="dark"] .ag-gallery {
  background: var(--bg-secondary, #2d2d2d);
  border-color: var(--border-color-dark, #444);
}
[data-theme="dark"] .ag-viewport,
[data-theme="dark"] .ag-slide {
  background: var(--bg-primary, #1a1a1a);
}
[data-theme="dark"] .ag-footer,
[data-theme="dark"] .ag-thumbs {
  background: var(--bg-secondary, #2d2d2d);
  border-color: var(--border-color-dark, #444);
}
[data-theme="dark"] .ag-dot { background: #555; }
[data-theme="dark"] .ag-slideshow-btn {
  border-color: #555;
  color: #aaa;
}

/* ---------------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------------- */
@media (max-width: 576px) {
  .ag-btn { width: 32px; height: 32px; font-size: 0.85rem; }
  .ag-prev { left: 6px; }
  .ag-next { right: 6px; }
  .ag-thumb { width: 60px; height: 45px; }
  .ag-lb-prev { left: 8px; }
  .ag-lb-next { right: 8px; }
  .ag-lb-close { top: 8px; right: 8px; }
}
