:root{ --ui-bg: rgba(255,255,255,.92); --ui-bdr:#e5e7eb; --shadow: 0 6px 18px rgba(0,0,0,.08); }
  html,body{margin:0;padding:0;font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial}
  html, body { width:100%; max-width:100%; overflow-x:hidden; }
  body.chart-mode { overflow-x:auto; }
  .map-shell{position:relative;width:100%; overflow:hidden;}

  #map, #chartContainer{
    width:100%;
    height: clamp(340px, 70vh, 880px);
    border-radius:12px; box-shadow:var(--shadow);
    background:#f6f7f9; border:1px solid #d9dce2; max-width:100%;
  }
  #chartContainer{display:none; overflow-x:auto; overflow-y:hidden;}
  #chartCanvas{display:block;}

  .ui-overlay{
    position:absolute; left:50%; top:12px; transform:translateX(-50%);
    z-index:900; display:flex; gap:12px; align-items:center; flex-wrap:wrap;
    /*background:var(--ui-bg); border:1px solid var(--ui-bdr);
    border-radius:11px;
    box-shadow: var(--shadow);backdrop-filter:blur(6px);*/; padding:10px 14px; width:50%;justify-content: center;
  }
.ui-field{
  display:flex;
  flex-direction:column;
  gap:4px;
}

.ui-label{
  font-size:.63rem;
  font-weight:600;
  color:#374151;
  text-transform:uppercase;
}

  .ui-overlay select{
    font-size:12px; line-height:1.2; appearance:none;
    padding:5px 5px 5px 5px; border:1px solid #cfd5de;
    border-radius:5px; background:#fff; box-shadow: inset 0 1px 0 rgba(255,255,255,.6);
  }
  .ui-overlay .checkbox{
    display:flex; align-items:center; gap:8px; padding:10px 14px;
    /*border:1px solid #cfd5de; border-radius:9999px; background:#fff;box-shadow: inset 0 1px 0 rgba(255,255,255,.6);*/ font-size:12px;
    
  }
  .ui-overlay input[type="checkbox"]{ width:18px; height:18px; accent-color:#2563eb; }

  .leaflet-control-zoom a{
    border-radius:9999px !important; width:44px; height:44px; display:grid; place-items:center;
    box-shadow: 0 2px 8px rgba(0,0,0,.15); border:1px solid #cfd5de; background:#fff; font-size:18px;
  }
  .leaflet-top.leaflet-right { top: 70px; right: 16px; }
  .leaflet-control-container .leaflet-control { z-index: 902; }

  .status{
    display:none;
    position:absolute; right:12px; top:12px; z-index:901;
    background:var(--ui-bg); border:1px solid var(--ui-bdr);
    padding:6px 8px; border-radius:8px; font-size:.8rem
  }

  .legend {
    position: absolute;
    z-index: 900;
    background: var(--ui-bg);
    border: 1px solid var(--ui-bdr);
    padding: 6px 8px;
    border-radius: 10px;
    font-size: .8rem;
    box-shadow: var(--shadow);
    width: 230px;
    max-width: calc(100vw - 24px);
    transition: all .3s ease;
  }
  .legend .ticks {
    display: flex;
    justify-content: space-between;
    font-variant-numeric: tabular-nums;
    opacity: .9;
  }
.legend-labels{
  display:flex;
  justify-content:space-between;
  font-size:.75rem;
  font-weight:500;
  color:#374151;
  margin-bottom:4px;
}

.legend-low{
  text-align:left;
}

.legend-high{
  text-align:right;
}


  .status-map {
    position: absolute;
    right: 12px;
    top: 12px;
    background: var(--ui-bg);
    border: 1px solid var(--ui-bdr);
    padding: 6px 8px;
    border-radius: 8px;
    font-size: .8rem;
    color: #333;
  }

  .status-chart {
    display:none
  }

  .country-label{
    font-size:11px; line-height:1.1; color:#374151;
    text-shadow:0 1px 2px rgba(255,255,255,.9),0 0 2px rgba(255,255,255,.9);
    white-space:nowrap; pointer-events:none;
  }

  .leaflet-interactive { outline: none; }
  .leaflet-interactive:focus { outline: none; }
/* freccia dropdown per i select */
.ui-overlay select{
  appearance:none;
  -webkit-appearance:none;
  -moz-appearance:none;

  padding-right:44px; /* spazio per la freccia */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Cpath d='M5 7l5 6 5-6' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat:no-repeat;
  background-position: right 14px center;
  background-size:18px 18px;
}



  /* ====== MOBILE (<= 560px) ====== */
@media (max-width: 560px){
  body{
    overflow-x:hidden;
  }

  .map-shell{
    padding-top:180px;
  }

  /* 👇 CONTROLLI SOTTO LA LEGENDA */
  .ui-overlay{
    position:absolute;
    top:92px; /* <-- PRIMA ERA 8px */
    left:50%;
    transform:translateX(-50%);
    /*background:transparent;
    border:none;*/
    box-shadow:none;
    gap:6px;
    padding:4px 8px;
    flex-wrap:wrap;
    justify-content:center;
    width:90%;
    
  }

.ui-overlay select{
    font-size:12px;
    padding:6px 36px 6px 10px;   /* ↑ più spazio a destra */
    border-radius:8px;
    box-shadow:none;

    appearance:none;
    -webkit-appearance:none;
    -moz-appearance:none;

    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Cpath d='M5 7l5 6 5-6' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat:no-repeat;
    background-position:right 10px center;
    background-size:16px 16px;
  }
  .ui-overlay .checkbox{
    font-size:13px;
    padding:6px 10px;
    border:none;
    background:transparent;
    box-shadow:none;
  }
  .ui-overlay input[type="checkbox"]{
    width:16px;
    height:16px;
  }

  /* 👇 LEGENDA SOPRA I CONTROLLI */
  .legend{
    top:8px;  /* <-- PRIMA ERA 72px */
    bottom:auto;
    left:50%;
    transform:translateX(-50%);
    right:auto;
    width:90vw;
    max-width:90vw;
    box-shadow:none;
   }
 .legend canvas {
    width: 100% !important;
    height: 14px;
  }
  #map,
  #chartContainer{
    height:70vh;
    min-height:0;
margin-top: 50px;
  }

#chartContainer{
    width: auto !important;        /* lascia che segua il canvas */
    max-width: none !important;
    overflow-x: auto !important;   /* scroll orizzontale */
    overflow-y: hidden;
    padding-bottom: 4px;
margin-top: 50px;
  }

  #chartCanvas{
    display: block;
    height: 70vh !important;
    min-height: 400px;
    max-width: none !important;    /* niente 100% automatico */
  }


  .leaflet-control-zoom a{
    width:40px;
    height:40px;
    font-size:16px;
  }
  .leaflet-top.leaflet-right{
    top:140px;
    right:8px;
  }
}

/* Desktop stretto (<=1280px, NON mobile) */
@media (max-width: 1280px) and (min-width: 561px){

  .ui-overlay{top:0 !important;
    padding: 4px 8px !important;
    gap: 6px !important;
    border-radius: 10px !important;
    justify-content: left;
    left: 20%;
    transform: translateX(0);
  }

  .ui-label{
    font-size: .50rem !important;
    line-height: 1 !important;
  }

  .ui-overlay select{
    font-size: .50rem !important;
    line-height: 1.1 !important;
    padding: 4px 26px 4px 10px !important;
background-position: right 3px center !important;
  }

  .ui-overlay .checkbox{
    font-size: .50rem !important;
    line-height: 1.1 !important;
    padding: 4px 8px !important;
    gap: 5px !important;
  }

  .ui-overlay .checkbox input{
    transform: scale(.85) !important;
  }
}




/* ===== Legenda -30% su schermi piccoli (indipendente dalla risoluzione) ===== */
@media (max-width: 1280px), (max-height: 720px){
  .legend{
    transform: scale(.7) !important;
    transform-origin: bottom left !important;
  }

  .chart-mode .legend{
    transform-origin: top right !important;
  }
}

/* Mobile: mantiene il centraggio */
@media (max-width: 560px){
  .legend{
    transform: translateX(-50%) scale(.7) !important;
    transform-origin: top center !important;
  }
}