/* ================================================================
   MaisBook — Grade de fotos
   Compartilhado por seleção, galerias (link/pasta/colação),
   aprovar-álbum e fotos-evento.

   Mobile: duas colunas coladas na borda, botões de ação de 44px e
   espaço reservado no fim para a barra de ação fixa.
   ================================================================ */

/* fadeIn era referenciado em várias regras sem existir em lugar nenhum, então
   as animações simplesmente não rodavam. Fica aqui porque todas as telas que
   a usam carregam este arquivo. */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ==========================================================================
   0. Breadcrumb de volta (renderizado pelo partial galeria-shell)
   ========================================================================== */

.pasta-breadcrumb {
  margin: 0 0 var(--space-fluid-2xs, 0.5rem);
}

.maisbook-page .pasta-breadcrumb-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tap-min, 44px);
  font-size: var(--font-size-fluid-sm, 0.9375rem);
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.maisbook-page .pasta-breadcrumb-link:hover,
.maisbook-page .pasta-breadcrumb-link:focus-visible {
  color: var(--color-primary);
}

/* ==========================================================================
   1. Carregando / esqueleto
   ========================================================================== */

/* Base do spinner: as páginas de galeria não carregam nenhum outro CSS que
   o defina, então sem isto o estado de carregamento fica invisível. */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-full);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

.gallery-loading {
  text-align: center;
  padding: var(--space-fluid-xl, 3rem) var(--space-fluid-md, 1.25rem);
  animation: fadeIn 0.4s ease;
}

.gallery-loading .spinner {
  display: block;
  width: 40px;
  height: 40px;
  margin: 0 auto var(--space-fluid-sm, 1.25rem);
  border-width: 3px;
  border-color: var(--color-border-strong);
  border-top-color: var(--color-primary);
}

.maisbook-page .gallery-loading p {
  color: var(--color-text-muted);
  font-size: var(--font-size-fluid-sm, 0.9375rem);
  margin: 0;
}

.gallery-skeleton {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gallery-gap);
  padding: var(--space-fluid-sm, 1.25rem) 0;
}

.skeleton-item {
  aspect-ratio: 3 / 4;
  border-radius: var(--gallery-radius);
  background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-shine) 50%, var(--skeleton-base) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@media (min-width: 768px) {
  .gallery-skeleton {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .skeleton-item {
    aspect-ratio: auto;
    height: var(--gallery-row-target);
  }
}

.gallery-load-more-wrap {
  width: 100%;
}

.gallery-load-progress {
  text-align: center;
  padding: 12px 20px 8px;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.gallery-load-more-status {
  text-align: center;
  padding: var(--space-fluid-md, 1.5rem) 20px var(--space-fluid-lg, 2.5rem);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.gallery-load-more-status .spinner {
  display: block;
  width: 32px;
  height: 32px;
  margin: 0 auto 12px;
  border-width: 3px;
  border-color: var(--color-border-strong);
  border-top-color: var(--color-primary);
}

.gallery-load-more-sentinel {
  width: 100%;
  height: 1px;
  pointer-events: none;
}

/* ==========================================================================
   2. Paginação
   ========================================================================== */

.gallery-pager {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: var(--space-fluid-md, 1.5rem) 0;
}

.gallery-pager[hidden] {
  display: none;
}

.maisbook-page .gallery-pager-count {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.gallery-pager-pages {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.gallery-pager-btn {
  min-width: var(--tap-min, 44px);
  height: var(--tap-min, 44px);
  padding: 0 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-soft);
  color: var(--color-text);
  font-family: inherit;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold, 600);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.gallery-pager-btn:hover:not(:disabled):not(.is-current) {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.gallery-pager-btn:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.maisbook-page .gallery-pager-btn.is-current {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
  cursor: default;
}

.gallery-pager-btn.is-nav {
  font-size: var(--font-size-xl);
  line-height: 1;
}

.gallery-pager-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.maisbook-page .gallery-pager-gap {
  display: flex;
  align-items: center;
  padding: 0 2px;
  color: var(--color-text-muted);
}

/* ==========================================================================
   3. Seções de pasta
   ========================================================================== */

.gallery-folder-section {
  margin-bottom: var(--space-fluid-xl, 3rem);
}

.gallery-folder-section:last-child {
  margin-bottom: 0;
}

.gallery-folder-header {
  position: sticky;
  /* Encosta logo abaixo do header compacto para o nome da pasta continuar
     visível enquanto a pessoa rola uma pasta longa. */
  top: var(--header-height-mobile, 56px);
  z-index: var(--z-sticky, 50);
  margin-bottom: var(--space-fluid-sm, 1.25rem);
  padding: var(--space-fluid-2xs, 0.5rem) 0 var(--space-fluid-xs, 0.75rem);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
}

@media (min-width: 768px) {
  .gallery-folder-header {
    top: var(--header-height, 72px);
  }
}

.maisbook-page .gallery-folder-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: var(--font-size-fluid-lg, 1.125rem);
  font-weight: var(--font-weight-bold, 700);
  color: var(--color-text);
  margin: 0;
  letter-spacing: var(--letter-spacing-tight);
}

.gallery-folder-title svg {
  flex-shrink: 0;
  color: var(--color-primary);
  opacity: 0.75;
}

.maisbook-page .gallery-folder-count {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium, 500);
  color: var(--color-text-muted);
  margin-left: 0;
}

/* ==========================================================================
   4. Grade justificada
   Mosaico na ordem do álbum: JS empilha fotos até a linha chegar na altura
   alvo (--gallery-row-target). A caixa de cada foto segue a proporção real.
   ========================================================================== */

.gallery-grid {
  display: flex;
  flex-direction: column;
  gap: var(--gallery-gap);
  padding: var(--space-fluid-sm, 1.25rem) 0 0 0;
}

.gallery-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  justify-content: flex-start;
  gap: var(--gallery-gap);
  width: 100%;
  min-width: 0;
}

.gallery-row.is-single {
  justify-content: center;
}

.gallery-row.is-leftover {
  justify-content: flex-start;
}

.gallery-ad {
  width: 100%;
  min-height: 100px;
  margin: 0;
  box-sizing: border-box;
}

.gallery-ad .adsbygoogle {
  display: block;
  width: 100%;
}

/* Reserva para a barra de ação fixa não cobrir a última linha de fotos. */
.gallery-folder-section:last-child .gallery-grid {
  padding-bottom: calc(var(--actionbar-space, 68px) + var(--space-fluid-md, 1.5rem));
}

.gallery-item {
  position: relative;
  border-radius: var(--gallery-radius);
  overflow: hidden;
  cursor: pointer;
  background: var(--color-bg-soft);
  transition: box-shadow var(--transition-fast), filter var(--transition-fast);
  border: 0;
  box-sizing: border-box;
  flex: 1 1 0;
  width: auto;
  height: 100%;
  min-width: 0;
  line-height: 0;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.gallery-item img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center;
  background: var(--color-bg-soft);
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  -webkit-touch-callout: none;
  transition: filter var(--transition-fast);
}

.gallery-item-shield {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: 0 0;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

@media (hover: hover) {
  .gallery-item:hover img {
    filter: brightness(1.06);
  }
}

.gallery-item:focus:not(:focus-visible) {
  outline: none;
}

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

/* Selecionada: contorno verde — não desloca o mosaico. */
.gallery-item.selected {
  box-shadow: inset 0 0 0 4px var(--color-success);
  z-index: 2;
}

.gallery-item-check {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 12;
  width: 30px;
  height: 30px;
  background: var(--color-success);
  border: 2px solid #fff;
  color: #fff;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(52, 211, 153, 0.4);
  animation: scaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.gallery-item-check svg {
  width: 16px;
  height: 16px;
  stroke-width: 3;
}

.gallery-item-overlay {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity var(--transition-fast);
  pointer-events: none;
  z-index: 5;
}

.gallery-item:hover .gallery-item-overlay {
  opacity: 1;
}

/* ==========================================================================
   5. Ações sobre a foto
   ========================================================================== */

.gallery-item-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 6px;
  z-index: 20;
  pointer-events: auto;
  opacity: 1;
}

@media (hover: hover) {
  .gallery-item-actions {
    opacity: 0.92;
  }

  .gallery-item:hover .gallery-item-actions {
    opacity: 1;
  }
}

.gallery-item-download,
.gallery-item-fullscreen {
  /* No toque o alvo precisa de 44px; no desktop o botão pode ser menor. */
  width: var(--tap-min, 44px);
  height: var(--tap-min, 44px);
  padding: 0;
  background: rgba(10, 10, 16, 0.62);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
  color: #fff;
}

@media (hover: hover) and (pointer: fine) {
  .gallery-item-download,
  .gallery-item-fullscreen {
    width: 38px;
    height: 38px;
  }

  .gallery-item-download:hover,
  .gallery-item-fullscreen:hover {
    background: var(--color-primary);
    border-color: var(--color-primary);
    transform: scale(1.08);
    color: #fff;
  }
}

.gallery-item-download:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.gallery-item-download svg,
.gallery-item-fullscreen svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}

.spinner-small {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border-strong);
  border-top-color: var(--color-text);
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

.spinner-download {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

/* ==========================================================================
   6. Estados: já baixada / limite atingido
   ========================================================================== */

.gallery-item.downloaded {
  box-shadow: inset 0 0 0 3px var(--color-success);
}

.gallery-item.selected.downloaded {
  box-shadow: inset 0 0 0 4px var(--color-success);
}

.gallery-item.downloaded .gallery-item-check {
  background: var(--color-success);
}

.gallery-item.limit-reached {
  opacity: 0.5;
  cursor: not-allowed;
}

.gallery-item.limit-reached:hover img {
  filter: none;
}

.gallery-item-limit-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 16, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px;
  color: #fff;
  font-weight: var(--font-weight-semibold, 600);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-snug, 1.35);
  z-index: 11;
}

/* ==========================================================================
   7. Responsivo
   ========================================================================== */

@media (max-width: 767px) {
  .gallery-item {
    flex: 1 1 auto;
    width: 100%;
  }

  /* contain: a caixa já segue a proporção; cover cortava retratos mais altos. */
  .gallery-item img {
    object-fit: contain;
  }
}

@media (max-width: 479px) {
  .gallery-item {
    border-radius: 4px;
  }

  .gallery-pager-btn {
    min-width: 40px;
    padding: 0 6px;
    font-size: var(--font-size-sm);
  }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-loading,
  .skeleton-item {
    animation: none;
  }

  .gallery-item,
  .gallery-item img,
  .gallery-item-download,
  .gallery-item-fullscreen {
    transition-duration: 1ms;
  }

  .gallery-item:hover img {
    filter: none;
  }

  .gallery-item-download:hover,
  .gallery-item-fullscreen:hover {
    transform: none;
  }

  .gallery-item-check {
    animation: none;
  }
}
