/* Gallerie fotografiche: mosaico a colonne, foto intere e didascalie inseparabili.
   I confronti prima/durante/dopo restano fuori da questa regola. */
.photo-anchor { display: block; scroll-margin-top: 110px; }
.static-photo-gallery {
  width: min(100% - 40px, 1180px);
  margin: clamp(42px, 7vw, 88px) auto 0;
}
.static-photo-gallery > h2 { margin: 0 0 24px; }
.static-photo-gallery .gallery-grid { margin-top: 0; }
/* Testate, anche verticali: il file definisce il limite, non il contenitore. */
body main .page-hero__visual {
  max-width: min(100%, var(--photo-native-width, 100%));
  margin-inline: auto;
}

/* Adattare il layout alla foto: nessuna figura a piena riga deve obbligare
   un file piccolo a occupare 720/1160px. Include le righe singole dei lavori. */
body[data-page] main :is(.prose, .project-showcase, .ed-gallery) figure[style] {
  max-width: min(100%, var(--mosaic-native-width, 100%));
}
/* La home mantiene lo schema fotografico approvato, con riquadri ritagliati. */
body[data-page]:not([data-page="home"]) main :is(img.page-hero__visual, .prose img, .project-showcase img,
  .ed-gallery img, .ed-archive__card img, .gallery-grid img,
  .project img, .case img, .ap-hub-grid img)[width][height] {
  width: auto;
  max-width: min(100%, var(--photo-native-width, 100%));
  height: auto;
  aspect-ratio: auto;
  object-fit: contain;
  transform: none;
}
body:not([data-page="home"]) main :is(.page-hero__visual, .project img, .case img, .ap-hub-grid img) {
  margin-inline: auto;
}
body:not([data-page="home"]) main .service-card[style] {
  width: min(100%, var(--card-photo-width, 100%));
  justify-self: center;
}
body:not([data-page="home"]) main .service-card[style] img {
  transform: none;
}
body main :is(.gallery-grid, .prose .gallery-grid.gallery-masonry) {
  display: block;
  columns: 3;
  column-gap: 28px;
  orphans: 1;
  widows: 1;
  margin-block: 28px 0;
}
body main :is(.gallery-grid, .prose .gallery-grid.gallery-masonry) > :is(figure, .gallery-item) {
  display: block;
  vertical-align: top;
  break-inside: avoid;
  page-break-inside: avoid;
  width: min(100%, var(--mosaic-native-width, 100%));
  max-width: 100%;
  margin: 0 0 28px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}
body main :is(.gallery-grid, .prose .gallery-grid.gallery-masonry) > :is(figure, .gallery-item) img {
  display: block;
  width: 100%;
  height: auto;
  max-height: none;
  aspect-ratio: auto;
  object-fit: contain;
  transform: none;
  border-radius: 6px;
}
body main :is(.gallery-grid, .prose .gallery-grid.gallery-masonry) > :is(figure, .gallery-item) figcaption {
  position: static;
  width: 100%;
  margin: 10px 0 0;
  padding: 0;
  background: transparent;
  overflow-wrap: anywhere;
}
body main :is(.gallery-grid, .prose .gallery-grid.gallery-masonry) > :is(figure, .gallery-item):hover img { transform: none; }
body main :is(.gallery-grid, .prose .gallery-grid.gallery-masonry):has(> figure:nth-child(2):last-child) { columns: 2; }
body main :is(.gallery-grid, .prose .gallery-grid.gallery-masonry):has(> figure:only-child) { columns: 1; }
body main :is(.gallery-grid, .prose .gallery-grid.gallery-masonry) > figure:only-child { max-width: 620px; }
@media (max-width: 1000px) {
  body main :is(.gallery-grid, .prose .gallery-grid.gallery-masonry) { columns: 2; column-gap: 24px; }
  body main :is(.gallery-grid, .prose .gallery-grid.gallery-masonry) > :is(figure, .gallery-item) { margin-bottom: 24px; }
}
@media (max-width: 560px) {
  body main :is(.gallery-grid, .prose .gallery-grid.gallery-masonry),
  body main :is(.gallery-grid, .prose .gallery-grid.gallery-masonry):has(> figure:nth-child(2):last-child) { columns: 1; }
}
