#chatwithus {
  position: fixed;
  width: 40px; /* Dimensione fissa per l'icona */
  height: 40px;
  padding: 5px;
  background: #fff;
  z-index: 9;
  /* border-radius: 50%; /* Rende il contenitore rotondo */
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* Aggiunge un'ombra per un effetto flottante */
}
#chatwithus > svg,
#chatwithus > img {
  color: #fff;
  fill: #fff;
  width: 100%;
  height: auto;
  display: block;
}
#chatwithus > .dcw-icon-mask {
  width: 100%;
  height: 100%;
  display: block;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  background-color: #fff;
}

#chatwithus #popup {
  display: none;
  position: fixed;
  width: min(85vw, 340px);
  box-sizing: border-box;
  margin: 5vw;
  background-color: #fff;
  padding: 0;
  -webkit-box-shadow: 10px 10px 20px 0 rgba(0, 0, 0, 0.2);
  box-shadow: 10px 10px 20px 0 rgba(0, 0, 0, 0.2);
  text-align: center;
  bottom: 0;
  left: 0;
  border: 5px solid #ccc;
  aspect-ratio: 1 / 1;
  max-width: none;

  @media only screen and (min-width: 992px) {
    position: absolute;
    width: 20vw;
    margin: 0;
    bottom: unset;
    left: unset;
  }
}
/* Telefoni piccoli: il popup occupa tutta la larghezza */
@media only screen and (max-width: 480px) {
  #chatwithus #popup {
    width: 100%;
    margin: 0;
  }
}
/* Fix per posizionamento popup e inversione della freccia */
@media only screen and (min-width: 992px) {
  #chatwithus.dcw-position-bl #popup {
    left: 50%;
    bottom: 50%;
  }

  #chatwithus.dcw-position-br #popup {
    right: 50%;
    bottom: 50%;
  }

  #chatwithus.dcw-position-tl #popup {
    left: 50%;
    top: 50%;
  }

  #chatwithus.dcw-position-tr #popup {
    right: 50%;
    top: 50%;
  }
}
/* Contenuto del popup: riempie il quadrato (fuori dal flusso, così l'altezza
   resta quella di aspect-ratio) e centra tutto in verticale e orizzontale.
   Se il contenuto è troppo lungo scorre invece di deformare il quadrato. */
#chatwithus #popup .dcw-popup-inner {
  position: absolute;
  inset: 0;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  justify-content: safe center;
  gap: 15px;
}
/* Il link (immagine + testi) prende tutta l'altezza lasciata libera dal bottone */
#chatwithus #popup #popup-link {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
/* L'area immagine si allarga nello spazio rimasto dopo i testi; è un container
   così l'immagine si dimensiona sul lato più corto (cqw/cqh) */
#chatwithus #popup .dcw-popup-media {
  flex: 1 1 0;
  min-height: 60px;
  width: 100%;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
}
#chatwithus #popup img {
  /* Sempre quadrata e il più grande possibile nello spazio disponibile */
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  max-width: none;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 50%;
  display: block;
  margin: 0;
}
#chatwithus #popup h3,
#chatwithus #popup p {
  margin: 0;
}

/* --- Posizionamento Desktop --- */

/* Default: Bottom Left (bl) */
.dcw-position-bl {
  bottom: 20px;
  left: 20px;
}

/* Bottom Right (br) */
.dcw-position-br {
  bottom: 20px;
  right: 20px;
}

/* Top Right (tr) */
.dcw-position-tr {
  top: 20px;
  right: 20px;
}

/* Top Left (tl) */
.dcw-position-tl {
  top: 20px;
  left: 20px;
}

/* --- Mobile & Tablet (max-width: 1024px) --- */
@media only screen and (max-width: 1024px) {
  #chatwithus #popup .close {
    font-size: 36px;
    padding: 10px;
  }
}

#chatwithus #popup .close {
  color: #aaa;
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.3s;
  line-height: 1rem;
}
