.stato-aperta {
  --popup-color: #27ae60;
}
.stato-chiusa {
  --popup-color: #e74c3c;
}
.stato-in_attesa {
  --popup-color: #f1c40f;
}
.stato-restrizione_parziale {
  --popup-color: #3498db;
}
.stato-non_in_esercizio {
  --popup-color: #7c7c7c;
}

.leaflet-custom-popup .leaflet-popup-content-wrapper:has(.stato-aperta) {
  --popup-color: #27ae60;
}
.leaflet-custom-popup .leaflet-popup-content-wrapper:has(.stato-chiusa) {
  --popup-color: #e74c3c;
}
.leaflet-custom-popup .leaflet-popup-content-wrapper:has(.stato-in_attesa) {
  --popup-color: #f1c40f;
}
.leaflet-custom-popup .leaflet-popup-content-wrapper:has(.stato-restrizione_parziale) {
  --popup-color: #3498db;
}
.leaflet-custom-popup .leaflet-popup-content-wrapper:has(.stato-non_in_esercizio) {
  --popup-color: #7c7c7c;
}

#map_main path.leaflet-interactive {
  outline: none;
}

/* Rimuove tip */
.leaflet-popup-tip {
  display: none;
}

/* Contenitore popup */
.leaflet-custom-popup .leaflet-popup-content-wrapper {
  width: 520px;
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
  border: 3px solid var(--popup-color);
}

/* Rimuove margini default */
.leaflet-custom-popup .leaflet-popup-content {
  width: 100%;
  margin: 0;
}
/* STRUTTURA INTERNA */
.custom-popup {
  position: relative;
  background: #f2efe9;
  font-family: "Barlow Condensed", Sans-serif;
}

.custom-popup b {
  color: var(--popup-color);
}

/* Bottone chiusura */
.popup-close {
  position: absolute;
  color: #666;
  top: -18px;
  right: 10px;
  border: none;
  background: transparent;
  font-size: 30px;
  cursor: pointer;
  width: 20px;
  height: 20px;
}

.popup-close:hover {
  transform: scale(1.2);
  top: -7px;
  background-color: #f2efe9;
  color: #444;
}

.popup-top {
  display: flex;
  gap: 15px;
  padding-top: 35px;
  flex-direction: row;
  align-items: center;
}

/* HEADER */
.popup-header {
  display: flex;
  gap: 15px;
  padding: 20px;
}

/* Blocco verde */
.popup-badge {
  width: 50px;
  height: 70px;
  background: var(--popup-color);
  border-radius: 0 10px 10px 0;
}

/* Testi header */
.popup-id {
  font-size: 28px;
  font-weight: bold;
}

.popup-title {
  font-size: 22px;
  font-weight: 600;
}

/* BODY */
.popup-body {
  padding: 20px;
  font-size: 20px;
  color: #444;
}

.popup-body div {
  margin-bottom: 8px;
}

.popup-body span {
  color: #666;
}

.zone-map-preview {
  position: relative;
  width: 100%;
  overflow: hidden;
  background: #f0f4f8;
}

.polygon-svg {
  width: 100%;
  height: 300px;
  display: block;
}

.leaflet-map-container {
  width: 100%;
}

/* LEGGENDA */

.leaflet-top.leaflet-left {
  z-index: 900;
}

.leaflet-legend {
  background: none;
  padding: 0;
  min-width: 220px;
  max-width: 360px;
  border-radius: 20px;
  font-size: 14px;
  font-family: "Barlow Condensed", Sans-serif;
  transition:
    min-width 0.6s ease,
    max-width 0.6s ease;
}

.legend-header {
  display: flex;
  justify-content: space-between;
  border-radius: 20px 20px 0px 0px;
  align-items: center;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 18px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid #e5e5e5;
  background-color: #03487e;
  color: #fff;
  transition:
    border-radius 0.3s ease,
    border-bottom 0.3s ease;
}

button.legend-toggle {
  border: none;
  font-size: 26px;
  padding: 0 10px 0 0;
  margin-top: -3px;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.3s ease;
}

button.legend-toggle:hover,
button.legend-toggle:focus {
  color: #3d8ca3;
  background-color: transparent;
}

.legend-body {
  padding: 8px 12px 10px;
  background-color: #f5efe6;
  border-radius: 0px 0px 20px 20px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  transition:
    max-height 0.35s ease,
    opacity 0.25s ease,
    padding 0.25s ease;
  max-height: 600px;
  opacity: 1;
}

.legend-section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6d6559;
  margin: 8px 0 4px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.legend-swatch {
  width: 28px;
  height: 20px;
  border-radius: 3px;
  border: 1.5px solid #7c7c7c;
  flex-shrink: 0;
}

.legend-swatch--pattern {
  background: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.45) 0px,
    rgba(255, 255, 255, 0.45) 4px,
    #27ae60 4px,
    #27ae60 8px
  );
}

.legend-text {
  font-family: "Source Sans 3", Sans-serif;
  color: var(--e-global-color-text);
  line-height: 1.4;
}

.legend-divider {
  border-top: 1px solid #eee;
  margin: 8px 0 4px;
}

/* STATO CHIUSO */
.leaflet-legend.collapsed {
  min-width: 150px;
  max-width: 150px;
}

.leaflet-legend.collapsed .legend-body {
  max-height: 0;
  opacity: 0;
  padding-bottom: 0;
}

/* Header compatto */
.leaflet-legend.collapsed .legend-header {
  border-radius: 20px;
  border-bottom-color: transparent;
}

/* Corpo compatto */
.leaflet-legend.collapsed .legend-body {
  padding: 0;
}

@media (max-width: 799px) {
  /* Contenitore popup */
  .leaflet-custom-popup .leaflet-popup-content-wrapper {
    width: 350px;
  }
}
