/* ============================================
   GALLERY CONTAINER & SCROLL
   ============================================ */
.gallery-container {
  position: relative;
  width: 90%;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  overflow: hidden;
  transition: opacity 0.4s ease;
  
  /* AGGIUNGI QUESTE RIGHE */
  -webkit-touch-callout: none; /* Disabilita il menu popup (Salva immagine, Copia, ecc.) su iOS */
  -webkit-user-select: none;   /* Safari */
  -moz-user-select: none;      /* Firefox */
  -ms-user-select: none;       /* Edge */
  user-select: none;           /* Standard (Chrome/Android) */
}

.gallery-scroll {
  width: 100%;
  height: auto;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.gallery-scroll::-webkit-scrollbar {
  display: none;
}

/* ============================================
   SLIDES
   ============================================ */
.gallery-slide {
  height: auto;
  min-height: auto;
  scroll-snap-align: start;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.gallery-slide img {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
  
  /* AGGIUNGI QUESTE RIGHE */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ============================================
   PROGRESS BAR
   ============================================ */
.progress-bar-container {
  width: 100%;
  height: 8px;
  background-color: rgba(var(--text-main-rgb), 0.2);
  position: relative;
  cursor: pointer;
  margin-top: 0;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background-color: var(--accent-lime);
  transition: width 0.05s linear;
}

/* ============================================
   NAVIGATION ARROWS
   ============================================ */
.gallery-nav-arrow {
  position: absolute;
  top: 0;
  background: transparent;
  border: none;
  color: transparent;
  cursor: pointer;
  z-index: 99;
  transition: background 0.3s ease;
  width: 50%;
}

.gallery-nav-arrow:hover {
  background: rgba(255, 255, 255, 0.05);
}

.gallery-prev {
  left: 0;
  right: auto;
}

.gallery-next {
  right: 0;
  left: auto;
}

/* ============================================
   PHOTO NAME
   ============================================ */
.photo-name {
  text-align: left;
  color: var(--accent-lime);
  font-size: 1.6vh;
  font-weight: 300;
  margin-top: 0.5vh;
  margin-left: 1vw;
  letter-spacing: -0.02vw; /* Applica lo stesso spacing del footer */
  width: 100%;
}

.gallery-slide:hover .photo-name {
  opacity: 1;
}

/* ============================================
   GRID VIEW
   ============================================ */
.grid-toggle-btn {
  position: fixed !important;
  top: calc(env(safe-area-inset-top) + 3.5vh) !important;
  left: auto !important;
  right: 5vw !important;
  width: 20px;
  height: 20px;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  align-content: center;
  z-index: 99999 !important;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.grid-toggle-btn span {
  width: 2.5px;
  height: 2.5px;
  border-radius: 50%;
  background-color: var(--text-main);
  transition: background-color 0.3s, transform 0.3s ease;
}

.grid-toggle-btn:hover span {
  background-color: var(--accent-lime);
  transform: scale(1.2);
}

.grid-view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  min-height: 100vh;
  height: auto !important;
  background: var(--bg-dark);
  z-index: 90000 !important;
  display: block;
  column-count: 4;
  column-gap: 15px;
  padding: 12vh 5vw 5vh 5vw;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
  box-sizing: border-box;
}

.grid-view.active {
  opacity: 1;
  visibility: visible;
}

.grid-item {
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 12px;
  cursor: pointer;
  overflow: hidden;
  border-radius: 3px;
  display: inline-block;
  width: 100%;
  position: relative;
  background: rgba(var(--text-main-rgb), 0.06);
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  opacity: 0;
  transform: translateY(18px) translateZ(0);
  transition: opacity 0.55s cubic-bezier(0.23, 1, 0.32, 1), 
              transform 0.55s cubic-bezier(0.23, 1, 0.32, 1);
}

.grid-item.grid-item--visible {
  opacity: 1;
  transform: translateY(0) translateZ(0);
}

/* Skeleton shimmer */
.grid-item.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.18) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: gridShimmer 1.6s ease-in-out infinite;
  z-index: 2;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.5s ease;
}

.grid-item:not(.skeleton)::after {
  opacity: 0;
  animation: none;
}

@keyframes gridShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.grid-photo {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
  transition: transform 0.45s cubic-bezier(0.23, 1, 0.32, 1), 
              opacity 0.5s cubic-bezier(0.23, 1, 0.32, 1), 
              filter 0.5s cubic-bezier(0.23, 1, 0.32, 1);
  background-color: rgba(var(--text-main-rgb), 0.08);
  aspect-ratio: 3 / 4;
}

.grid-photo:not(.img-loaded) {
  opacity: 0.35;
  filter: blur(10px) saturate(0.2) brightness(1.1);
  transform: scale(1.04);
}

.grid-photo.img-loaded {
  opacity: 1;
  filter: blur(0) saturate(1) brightness(1);
  transform: scale(1);
}

.grid-item:hover .grid-photo {
  transform: scale(1.03);
}

body.grid-active .gallery-scroll,
body.grid-active .gallery-nav-arrow {
  opacity: 0;
  pointer-events: none;
}

/* ============================================
   VISIBILITY STATES
   ============================================ */
body.category-active .grid-toggle-btn,
body.project-gallery-active .grid-toggle-btn {
  opacity: 1 !important;
  pointer-events: auto !important;
}

body.gallery-menu-open:not(.category-active) .gallery-container {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ============================================
   DESKTOP
   ============================================ */
@media (min-width: 769px) {
  .gallery-container {
    position: fixed;
    right: 10%;
    top: 50%;
    transform: translateY(-50%);
    width: 30%;
    min-height: 0;
    height: auto;
    margin: 0;
    display: block;
  }

  .gallery-scroll {
    height: auto;
  }

  .gallery-slide img {
    height: auto;
  }

  .progress-bar-container {
    height: 8px;
  }

  .photo-name {
    font-size: 1.6vh;
      letter-spacing: -0.02vw; /* Applica lo stesso spacing del footer */

  }

  .grid-toggle-btn {
    top: calc(env(safe-area-inset-top) + 1.2vh) !important; /* Prima era 3.5vh */
    right: 5vw !important;
  }
}

/* ============================================
   TABLET
   ============================================ */
@media (min-width: 481px) and (max-width: 768px) {
  .gallery-container {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    width: 90% !important;
    margin: 0 auto !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    display: block !important;
    align-items: normal !important;
  }

  body.panel-open .gallery-container {
    opacity: 0.2 !important;
    pointer-events: none;
  }

  body.panel-open.project-gallery-active .gallery-container {
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  .gallery-slide {
    width: 100% !important;
    height: auto !important;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .gallery-slide img {
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    object-fit: contain !important;
    display: block;
  }

body.project-gallery-active .gallery-container {
  position: relative !important;
  top: auto !important;
  left: auto !important;
  transform: none !important;
  width: 100% !important;
  height: auto !important;
  max-height: none !important;
  margin: 0 auto !important;
  display: block !important;
  padding: 2vh 5vw 5vh 5vw !important;
  overflow: visible !important;
  
  /* Riduci questo valore per avvicinare l'immagine al testo */
  margin-top: 10vh !important; 
}
}

/* ============================================
   MOBILE
   ============================================ */
@media (max-width: 768px) {
  .gallery-footer-menu {
    top: calc(env(safe-area-inset-top) + 9vh) !important;
    bottom: auto !important;
    left: 5vw !important;
    font-size: 2.4vh !important;
    z-index: 105 !important;
  }

  .gallery-footer-title {
    top: calc(env(safe-area-inset-top) + 3vh) !important;
    bottom: auto !important;
    left: 5vw !important;
    font-size: 3.8vh !important;
    z-index: 105 !important;
  }

  .gallery-footer-subtitle {
    display: none !important;
  }

  .gallery-footer-bg {
    display: none !important;
  }

  .gallery-nav-arrow {
    width: 50%;
  }

  .gallery-back-button {
    top: calc(env(safe-area-inset-top) + 3.5vh) !important;
    left: auto !important;
    right: 5vw !important;
    font-size: 1.6vh;
    z-index: 1001 !important;
    pointer-events: auto !important;
  }

  .gallery-back-button::before {
    font-size: 2vh;
  }

  .gallery-scroll {
    height: auto !important;
    max-height: 100% !important;
    overflow: visible !important;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: none !important;
  }

  body.project-gallery-active .gallery-scroll {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    scroll-snap-type: none !important;
  }

  .gallery-scroll::-webkit-scrollbar {
    display: none;
  }

  .progress-bar-container {
    height: 8px;
  }

  .photo-name {
    font-size: 1.6vh;
    margin-left: 1vw;
      letter-spacing: -0.02vw; /* Applica lo stesso spacing del footer */

  }
  
  .gallery-container {
    z-index: 50 !important;
  }

  .active, .visible {
    z-index: 9999 !important;
  }

  .grid-view { 
    column-count: 2;
    column-gap: 10px; 
    padding-top: 10vh; 
  }
 .grid-item {
  break-inside: avoid;
  -webkit-column-break-inside: avoid; /* Specifico per Safari */
  page-break-inside: avoid;
  margin-bottom: 15px;
  cursor: pointer;
  overflow: hidden;
  border-radius: 2px;
  display: inline-block;
  width: 100%;
  
  /* FORZA IL RENDERING IMMEDIATO (Fix per iOS/Safari) */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

  /* 2. Alza lo z-index per forzare i 9 puntini sopra le frecce invisibili */
  #gridToggleBtn.grid-toggle-btn {
    top: calc(env(safe-area-inset-top) + 1.4vh) !important;
    right: 5vw !important;
    z-index: 100000 !important; /* Alzato per superare il 99999 delle .nav-arrow */
  }

  
}

/* ============================================
   EXTRA SMALL
   ============================================ */
@media (max-width: 480px) {
  .gallery-container {
    position: absolute;
    top: 24vh !important;
    bottom: auto !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 90vw !important;
    height: 55vh !important;
    max-height: 55vh !important;
    margin: 0;
    display: flex;
    align-items: flex-start;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }

  body.panel-open .gallery-container {
    opacity: 0.2 !important;
    pointer-events: none;
  }

  body.panel-open.project-gallery-active .gallery-container {
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  .gallery-slide {
    width: 100% !important;
    height: max-content !important;
    min-height: 100% !important;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .gallery-slide img {
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    object-fit: contain !important;
    display: block;
  }

  .gallery-footer-menu {
    top: calc(env(safe-area-inset-top) + 8vh) !important;
    font-size: 2.2vh !important;
  }

  .gallery-footer-title {
    top: calc(env(safe-area-inset-top) + 2.5vh) !important;
    font-size: 3.4vh !important;
  }

  body.project-gallery-active .gallery-container {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 auto !important;
    display: block !important;
    padding: 2vh 5vw 5vh 5vw !important;
    overflow: visible !important;
    margin-top: 10vh !important;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .grid-view { column-count: 3; }
}

@media (max-width: 768px) {
  /* Usiamo l'ID e la classe insieme per vincere qualsiasi conflitto */
  #gridToggleBtn.grid-toggle-btn {
    top: calc(env(safe-area-inset-top) + 1.4vh) !important;
    right: 5vw !important;
  }
}
/* ============================================
   SOVRASCRITTURA COLORI CMS (Solo per i Progetti)
   ============================================ */

/* Il titolo della foto diventa marrone scuro all'interno dei progetti */
body.project-gallery-active .photo-name {
  color: var(--text-main) !important;
}

/* La nuova descrizione della foto assume il colore marrone scuro */
.project-slide-desc {
  width: 100%;
  text-align: left;
  font-size: 1.6vh !important; /* Allineato alla grandezza del titolo foto (photo-name) */
  font-weight: 300;
  margin-top: 0vh !important; /* Poca distanza tra titolo/foto e descrizione */
  margin-left: 1vw;
  color: var(--text-main) !important;
  line-height: 1.1;
  letter-spacing: -0.05vw; /* Applica lo stesso spacing del footer */
}

@media (max-width: 768px) {
.project-slide-desc {
    width: 90%;
    font-size: 1.6vh !important;
    margin-left: 1vw;
    margin-top: -2vh !important;
  }
}

/* ============================================
   FIX DEFINITIVO SCROLL GRID VIEW (ANTI-CHAINING & OVERFLOW COLONNE)
   ============================================ */
html.grid-active {
    overflow: auto !important; /* Permette lo scroll */
}

body.grid-active {
    overflow: auto !important; /* Permette lo scroll */
    position: relative !important; /* Sovrascrive temporaneamente il blocco del JS (fixed) */
    top: 0 !important; /* Azzera l'offset applicato dal JS */
    left: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 100vh !important;
    overscroll-behavior: none !important;
    touch-action: auto !important;
    background-color: var(--bg-dark) !important;
}

/* Nasconde fisicamente tutti i pannelli e i testi di background quando la griglia è aperta */
body.grid-active .footer-menu,
body.grid-active .footer-title,
body.grid-active .footer-subtitle,
body.grid-active .header-blur-band,
body.grid-active .text-box,
body.grid-active .personal-works-box,
body.grid-active .gallery-container,
body.grid-active .text-box-back,
body.grid-active .mobile-menu-toggle,
body.grid-active #mobileMenuToggle,
body.grid-active .home-profile-box,
body.grid-active #urban\ volumes-textbox,
body.grid-active #urban\ surfaces-textbox,
body.grid-active #inhabitants-textbox,
body.grid-active #product-textbox,
body.grid-active #miscellaneous-textbox {
    display: none !important;
}

/* ============================================
   GRID BUTTON "TRUE X" ANIMATION
   ============================================ */

/* 1. Creiamo le due linee continue per la X (nascoste di default) */
.grid-toggle-btn::before,
.grid-toggle-btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 1.5px;
  background-color: var(--accent-lime); /* Colore arancione per la X */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}

/* Stato iniziale delle linee (piatte e rimpicciolite) */
.grid-toggle-btn::before { transform: translate(-50%, -50%) rotate(0deg) scale(0); }
.grid-toggle-btn::after { transform: translate(-50%, -50%) rotate(0deg) scale(0); }

/* 2. Quando si apre la griglia, i 9 puntini spariscono completamente */
body.grid-active .grid-toggle-btn span {
  opacity: 0 !important;
  transform: scale(0) !important;
}

/* 3. E appaiono le due linee continue ruotate a formare la "X" */
body.grid-active .grid-toggle-btn::before {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(45deg) scale(1);
}
body.grid-active .grid-toggle-btn::after {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(-45deg) scale(1);
}

/* 4. FIX: Assicura che chiudendo la griglia da mobile, il bottone si resetti perfettamente */
@media (hover: none) {
  /* Annulla forzatamente l'effetto hover finto dei telefoni al rilascio del dito */
  .grid-toggle-btn:hover span {
    background-color: var(--text-main); 
    transform: scale(1);
  }
}

/* Titolo con spessore calibrato e armonioso (medium, non pesante) */
.photo-name {
  font-weight: 400 !important; /* Spessore medio-leggero, raffinato */
  letter-spacing: -0.02vw;
}

/* Quando usi il grassetto sui titoli o descrizioni, usiamo un 550/600 invece che 700+ */
.photo-name strong, 
.photo-name b, 
.project-slide-desc strong, 
.project-slide-desc b {
  font-weight: 600 !important;
}

.photo-name u, 
.project-slide-desc u {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.photo-name em, 
.project-slide-desc em {
  font-style: italic;
}

/* Stile per i link inseriti nei testi */
.photo-name a, 
.project-slide-desc a {
  color: inherit !important;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: opacity 0.2s ease;
}

.photo-name a:hover, 
.project-slide-desc a:hover {
  color: var(--accent-lime) !important;
  opacity: 0.8;
}