/* ===== Página Galeria — grelha responsiva + lightbox ===== */

/* O layout-home.css (carregado nesta página para o rodapé completo) redefine
   .o-float-cta como position: relative — repor o comportamento flutuante das subpáginas */
.o-float-cta {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 999;
}

@media (max-width: 480px) {
  .o-float-cta {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
  }
}

.gallery-section {
  padding-top: var(--space-md);
}

.gallery-intro {
  max-width: 60ch;
}

/* ----- Filtros por categoria ----- */
.gallery-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: var(--space-md);
}

.gallery-filter {
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--body);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  min-height: 44px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.gallery-filter:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

.gallery-filter[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--white);
}

.gallery-filter:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Contagem de fotos visíveis (anunciada a leitores de ecrã) */
.gallery-count {
  margin: 0.75rem 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Item escondido pelo filtro */
.gallery-item[hidden] {
  display: none;
}

/* Animação ao aplicar filtro */
@keyframes gallery-pop {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.gallery-grid.is-filtering .gallery-item:not([hidden]) {
  animation: gallery-pop 0.35s ease both;
}

/* ----- Reveal em cascata ao fazer scroll (só com JS activo) ----- */
.gallery-grid.js-reveal .gallery-item {
  opacity: 0;
  transform: translateY(18px);
}

.gallery-grid.js-reveal .gallery-item.is-visible {
  opacity: 1;
  transform: none;
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.gallery-grid.js-reveal .gallery-item.is-visible:hover {
  transform: translateY(-3px);
}

@media (prefers-reduced-motion: reduce) {
  .gallery-grid.js-reveal .gallery-item {
    opacity: 1;
    transform: none;
  }
  .gallery-grid.is-filtering .gallery-item:not([hidden]) {
    animation: none;
  }
}

/* Grelha tipo masonry: 1 coluna em mobile, 2 em tablet, 3 em desktop */
.gallery-grid {
  columns: 1;
  column-gap: 1rem;
  margin-top: var(--space-lg);
}

@media (min-width: 600px) {
  .gallery-grid {
    columns: 2;
  }
}

@media (min-width: 961px) {
  .gallery-grid {
    columns: 3;
  }
}

.gallery-item {
  position: relative;
  display: block;
  width: 100%;
  margin: 0 0 1rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  overflow: hidden;
  break-inside: avoid;
  background: var(--pale);
  box-shadow: var(--shadow);
  cursor: zoom-in;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.gallery-item:hover,
.gallery-item:focus-visible {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}

.gallery-item:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.gallery-item img {
  display: block;
  width: 100%;
  height: auto;
  transition: transform 0.35s ease;
}

.gallery-item:hover img {
  transform: scale(1.03);
}

.gallery-item::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(13, 31, 45, 0.45) 0%, transparent 42%);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.gallery-item:hover::after,
.gallery-item:focus-visible::after {
  opacity: 1;
}

/* ----- Overlay no hover: etiqueta de categoria + lupa ----- */
.gallery-item-hover {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.gallery-item:hover .gallery-item-hover,
.gallery-item:focus-visible .gallery-item-hover {
  opacity: 1;
}

.gallery-item-badge {
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  transform: translateY(8px);
  transition: transform 0.28s ease;
}

.gallery-item-zoom {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--blue-deep);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: translateY(8px);
  transition: transform 0.28s ease 0.05s;
}

.gallery-item:hover .gallery-item-badge,
.gallery-item:hover .gallery-item-zoom,
.gallery-item:focus-visible .gallery-item-badge,
.gallery-item:focus-visible .gallery-item-zoom {
  transform: translateY(0);
}

/* ----- Tilt 3D subtil (desktop, rato) ----- */
.gallery-item {
  --rx: 0deg;
  --ry: 0deg;
}

.gallery-grid.js-reveal .gallery-item.is-visible {
  transform: perspective(700px) rotateX(var(--rx)) rotateY(var(--ry));
}

.gallery-grid.js-reveal .gallery-item.is-visible:hover {
  transform: perspective(700px) rotateX(var(--rx)) rotateY(var(--ry)) translateY(-3px);
}

.gallery-grid.js-reveal .gallery-item.is-visible.is-tilting {
  transition: transform 0.12s ease, box-shadow 0.25s ease;
}

/* ----- Shimmer enquanto a foto carrega ----- */
@keyframes gallery-shimmer {
  from {
    background-position: -200% 0;
  }
  to {
    background-position: 200% 0;
  }
}

.gallery-item.is-loading {
  min-height: 140px;
  background: linear-gradient(100deg, #e6edf3 40%, #f6fafd 50%, #e6edf3 60%);
  background-size: 200% 100%;
  animation: gallery-shimmer 1.2s linear infinite;
}

.gallery-item.is-loading img {
  opacity: 0;
}

.gallery-item img {
  transition: transform 0.35s ease, opacity 0.4s ease;
}

@media (prefers-reduced-motion: reduce) {
  .gallery-item,
  .gallery-item img {
    transition: none;
  }
  .gallery-item:hover {
    transform: none;
  }
  .gallery-item:hover img {
    transform: none;
  }
  .gallery-item.is-loading {
    animation: none;
  }
}

/* ===== Lightbox ===== */
.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(13, 31, 45, 0.88);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  padding: 1rem;
  overflow: hidden;
}

@keyframes lightbox-in {
  from {
    opacity: 0;
  }
}

@keyframes lightbox-img-in {
  from {
    opacity: 0;
    transform: scale(0.93);
  }
}

.gallery-lightbox.open {
  display: flex;
  animation: lightbox-in 0.25s ease;
}

.gallery-lightbox.open .gallery-lightbox-img {
  animation: lightbox-img-in 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-reduced-motion: reduce) {
  .gallery-lightbox.open,
  .gallery-lightbox.open .gallery-lightbox-img {
    animation: none;
  }
}

/* Barra de progresso do slideshow */
.gallery-lightbox-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.16);
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 2;
}

.gallery-lightbox-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #00C4E8, #F5C400);
}

@keyframes lb-progress {
  from {
    width: 0;
  }
  to {
    width: 100%;
  }
}

.gallery-lightbox.is-playing .gallery-lightbox-progress {
  opacity: 1;
}

.gallery-lightbox.is-playing .gallery-lightbox-progress span {
  animation: lb-progress 4s linear;
}

.gallery-lightbox-img {
  max-width: min(100%, 1100px);
  max-height: calc(100dvh - 7.5rem);
  width: auto;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  user-select: none;
  -webkit-user-select: none;
}

.gallery-lightbox-img.is-fading {
  opacity: 0;
}

.gallery-lightbox-img {
  transition: opacity 0.22s ease, transform 0.3s ease;
  cursor: zoom-in;
}

/* Zoom dentro do lightbox (clique na foto) */
.gallery-lightbox-img.is-zoomed {
  transform: scale(1.8);
  cursor: zoom-out;
}

.gallery-lightbox-caption {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(92%, 700px);
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.875rem;
  text-align: center;
  margin: 0;
}

.gallery-lightbox-caption strong {
  color: #fff;
  font-weight: 600;
  margin-right: 0.5rem;
}

/* Botões do lightbox — alvo táctil ≥ 44px */
.gallery-lightbox-btn {
  position: absolute;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.gallery-lightbox-btn:hover,
.gallery-lightbox-btn:focus-visible {
  background: rgba(255, 255, 255, 0.3);
}

.gallery-lightbox-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.gallery-lightbox-close {
  top: max(0.75rem, env(safe-area-inset-top));
  right: max(0.75rem, env(safe-area-inset-right));
}

/* Botão slideshow (play/pausa) */
.gallery-lightbox-play {
  top: max(0.75rem, env(safe-area-inset-top));
  left: max(0.75rem, env(safe-area-inset-left));
  font-size: 1.1rem;
}

.gallery-lightbox-play[aria-pressed="true"] {
  background: var(--accent, #005F90);
}

.gallery-lightbox-prev {
  left: max(0.5rem, env(safe-area-inset-left));
  top: 50%;
  transform: translateY(-50%);
}

.gallery-lightbox-next {
  right: max(0.5rem, env(safe-area-inset-right));
  top: 50%;
  transform: translateY(-50%);
}

@media (max-width: 600px) {
  .gallery-lightbox-prev,
  .gallery-lightbox-next {
    top: auto;
    bottom: max(3rem, calc(env(safe-area-inset-bottom) + 2.5rem));
    transform: none;
  }
  .gallery-lightbox-caption {
    bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
}
