/* ── Base ──────────────────────────────────────────────────────── */
html, body { margin: 0; height: 100%; overflow: hidden; font-family: sans-serif; background: #16213e; }
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ── Header ───────────────────────────────────────────────────── */
#header {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px; background: #0f3460; color: #fff;
    font-size: 13px; z-index: 1000; flex-shrink: 0;
}
#header select {
    background: #1a1a2e; color: #fff; border: 1px solid #0f3460;
    border-radius: 4px; padding: 4px 8px; font-size: 13px;
}
#model-badge {
    background: #e94560; color: #fff; border-radius: 4px;
    padding: 2px 8px; font-size: 12px; font-weight: bold;
}
#model-badge.eu { background: #1f4e9c; }

/* ── Map ──────────────────────────────────────────────────────── */
#map { flex: 1; cursor: pointer; position: relative; }  /* contesto per l'anello long-press */
#map:active { cursor: grabbing; }  /* dito normalmente, manina chiusa durante il trascinamento */

/* ── Timeslider ───────────────────────────────────────────────── */
#timeslider-container {
    padding: 4px 12px 8px; background: #0f3460;
    display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
#timeslider-container label { color: #a0a0c0; font-size: 12px; white-space: nowrap; }
#timeslider-container button {
    background: #1a1a2e; color: #fff; border: 1px solid #0f3460;
    border-radius: 4px; padding: 4px 8px; font-size: 13px; cursor: pointer;
}
#timeslider-container button:hover { background: #e94560; }
#slider-track { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
#slider-labels {
    position: relative; height: 14px;
    font-size: 10px; color: #a0a0c0; margin-top: 2px; user-select: none;
}
#slider-labels span { position: absolute; top: 0; white-space: nowrap; }
/* Flash orario in sovraimpressione alla mappa (50% -> svanisce in 3s) */
#date-flash {
    position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
    z-index: 1500; pointer-events: none;
    background: rgba(15, 52, 96, .9); color: #fff;
    font-size: 32px; font-weight: bold; padding: 6px 22px; border-radius: 9px;
    opacity: 0; transition: opacity 3s ease; white-space: nowrap;
}
#date-flash.show { opacity: .5; transition: none; }
#time-flash {
    position: absolute; top: 70px; left: 50%; transform: translateX(-50%);
    z-index: 1500; pointer-events: none;
    background: rgba(15, 52, 96, .9); color: #fff;
    font-size: 40px; font-weight: bold; padding: 8px 26px; border-radius: 10px;
    opacity: 0; transition: opacity 3s ease;
}
#time-flash.show { opacity: .5; transition: none; }
/* Flash selezione combo: stesso comportamento, sotto l'orario */
#param-flash {
    position: absolute; top: 156px; left: 50%; transform: translateX(-50%);
    z-index: 1500; pointer-events: none;
    background: rgba(15, 52, 96, .9); color: #fff;
    font-size: 32px; font-weight: bold; padding: 6px 22px; border-radius: 9px;
    opacity: 0; transition: opacity 3s ease; white-space: nowrap;
}
#param-flash.show { opacity: .5; transition: none; }
/* Flash messaggi (es. geoloc bloccata): stesso comportamento, testo a capo */
#msg-flash {
    position: absolute; top: 240px; left: 50%; transform: translateX(-50%);
    z-index: 1500; pointer-events: none; max-width: 80%;
    background: rgba(15, 52, 96, .9); color: #fff;
    font-size: 20px; font-weight: bold; padding: 8px 22px; border-radius: 10px;
    opacity: 0; transition: opacity 3s ease; text-align: center;
}
#msg-flash.show { opacity: .85; transition: none; }
#time-slider {
    width: 100%; accent-color: #e94560;
}
/* Barra avanzamento prefetch: un segmento per step (bianco = da caricare,
   grigio chiaro = in cache). Larghezze proporzionali come da specifica. */
#slider-buffer {
    display: flex; gap: 1px; height: 6px; margin: 0 2px;
}
#slider-buffer .pf-seg {
    flex: 1 1 0; background: #fff; border-radius: 1px; opacity: .9;
}
#slider-buffer .pf-seg.on { background: #b0bec5; }

/* ── Legend + Chat AI (stessa altezza, in basso a dx) ─────────── */
#legend-dock {
    position: absolute; bottom: 58px; right: 16px; z-index: 1000;
    display: flex; align-items: stretch; gap: 8px;
    width: calc(100vw - 32px); max-width: 600px; justify-content: flex-end;
}
#legend {
    flex: 1 1 auto; min-width: 0;
    background: rgba(22, 33, 62, 0.9); border: 1px solid #0f3460;
    border-radius: 8px; padding: 6px 10px; font-size: 11px;
    box-shadow: 0 2px 8px rgba(0,0,0,.4); color: #fff;
}
#legend-label {
    font-weight: bold; font-size: 11px; color: #fff;
    margin-bottom: 4px;
}
#legend-bar-wrap { position: relative; width: 100%; }
#legend-canvas { width: 100%; height: 10px; }
#legend-labels {
    display: flex; justify-content: space-between;
    font-size: 10px; color: #fff; margin-top: 2px;
}

/* ── Status overlay (bottom-left) ─────────────────────────────── */
#status-overlay {
    position: absolute; bottom: 58px; left: 16px; z-index: 1000;
    background: rgba(22, 33, 62, 0.9); border: 1px solid #0f3460;
    border-radius: 8px; padding: 6px 12px; font-size: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
    color: #e0e0e0;
}

/* ── Site panel (old site style) ─────────────────────────────── */
#panel {
    position: fixed; top: 10px; right: 10px; z-index: 1000;
    background: rgba(255,255,255,0.97); padding: 12px 16px; border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,.3);
    width: min(440px, calc(100vw - 20px));
    max-width: calc(100vw - 20px);
    box-sizing: border-box; overflow: hidden;
    font-size: 13px; display: none;
}

#panel h3 { margin: 0 0 6px; font-size: 16px; }
#panel .sub { color: #555; margin-bottom: 8px; }
#panel img { max-width: 100%; border: 1px solid #ccc; border-radius: 4px; }
/* Modale consenso geolocalizzazione */
#geoModal.hidden { display: none; }
#geoModal { position: fixed; inset: 0; z-index: 4000; background: rgba(0,0,0,.55);
    display: flex; align-items: center; justify-content: center; padding: 16px;
    box-sizing: border-box; }
.geo-box { background: #fff; border-radius: 14px; padding: 16px; width: 100%;
    max-width: 420px; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.geo-title { font-size: 16px; font-weight: bold; margin-bottom: 6px; }
.geo-sub { font-size: 13px; color: #555; margin-bottom: 12px; }
.geo-btns { display: flex; gap: 8px; }
.geo-btns button { flex: 1; padding: 10px 4px; border-radius: 8px; font-size: 14px;
    cursor: pointer; }
#geoOk { background: #1976d2; color: #fff; border: none; font-weight: bold; }
#geoFine, #geoNo { background: #f0f0f0; border: 1px solid #ccc; }
#imgWrap.wg-full { position: fixed; inset: 0; z-index: 3000;
    background: rgba(0,0,0,.93); display: flex; align-items: center;
    justify-content: center; padding: 12px; box-sizing: border-box; }
#imgWrap.wg-full img { max-width: 96vw; max-height: 94vh; width: auto;
    border: none; cursor: zoom-out; }
#panel .dates { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
#panel .dates button {
    padding: 3px 8px; border: 1px solid #999; border-radius: 4px;
    background: #fff; cursor: pointer; font-size: 12px;
}
#panel .dates button.active { background: #e8402e; color: #fff; border-color: #e8402e; }
#panel .close { float: right; cursor: pointer; font-size: 20px; color: #666; }
#panel .loading { color: #666; font-style: italic; }
/* Spinner per il caricamento windgram (schermo chiaro del panel) */
#panel .wg-spinner {
    display: flex; align-items: center; justify-content: center;
    gap: 10px; padding: 40px 0; color: #666; font-size: 13px;
}
#panel .wg-spinner .spin-dk {
    width: 28px; height: 28px; border: 3px solid rgba(60, 60, 60, .2);
    border-top-color: #e8402e; border-radius: 50%;
    animation: wgSpin .9s linear infinite;
}
@keyframes wgSpin { to { transform: rotate(360deg); } }

/* ── Webcam carosello ────────────────────────────────────────── */
.webcams { display: flex; gap: 8px; overflow-x: auto; padding: 6px 2px; margin: 4px 0; scrollbar-width: thin; }
.webcams .cam { flex: 0 0 auto; border: 1px solid #ccc; border-radius: 6px; overflow: hidden; background: #fafafa; }
.webcams .cam a { display: block; padding: 6px 10px; font-size: 12px; color: #1f4e9c; text-decoration: none; max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.webcams .cam a:active { background: #e8f0fa; }
.webcams .cam .cam-icon { display: block; text-align: center; font-size: 18px; padding-top: 6px; }

/* ── Webcam modal ─────────────────────────────────────────────── */
#webcamModal { position: fixed; inset: 0; z-index: 3000; display: none; background: rgba(0,0,0,.6); }
#webcamModal.open { display: block; }
#webcamModal .box { position: absolute; inset: 4vh 2vw; background: #fff; border-radius: 10px; display: flex; flex-direction: column; overflow: hidden; }
#webcamModal .head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid #ddd; font-size: 14px; font-weight: 600; }
#webcamModal .head .x { margin-left: auto; cursor: pointer; font-size: 22px; color: #666; line-height: 1; padding: 0 4px; }
#webcamModal .head #wcOpenNew { font-size: 12px; color: #1f4e9c; text-decoration: none; padding: 3px 8px; border: 1px solid #1f4e9c; border-radius: 4px; margin-left: 8px; }
#webcamModal iframe { flex: 1; width: 100%; border: 0; }
#webcamModal #wcNote { padding: 24px; text-align: center; color: #ddd; font-size: 14px; background: #111; flex: 1; }
#webcamModal .imgwrap { flex: 1; overflow: auto; display: flex; background: #111; }
#webcamModal img { max-width: 100%; max-height: 100%; margin: auto; object-fit: contain; cursor: zoom-in; }
#webcamModal img.max { max-width: none; max-height: none; margin: 0; cursor: zoom-out; }
@media (max-width: 600px) { #webcamModal .box { inset: 2vh 0 0 0; border-radius: 10px 10px 0 0; } }

/* ── Point modal (HTML windgram) ─────────────────────────── */
#pointModal { position: fixed; inset: 0; z-index: 2000; display: none; background: rgba(0,0,0,.5); }
#pointModal.open { display: flex; align-items: center; justify-content: center; overflow-y: auto; }
.pm-box { background: #1a1a2e; color: #e0e0e0; border-radius: 10px; width: min(600px, 92vw);
           max-height: 88vh; overflow-y: auto; box-shadow: 0 4px 20px rgba(0,0,0,.6);
           font-family: monospace; font-size: 13px; margin: 0 auto; }
/* Su mobile il grafico (562px+) supera width 92vw: con align-items:center
   il box slitta fuori centro e i bordi vengono tagliati dall'overflow del
   flex container. Align top + margin:auto = centratura robusta. */
@media (max-width: 600px) {
    #pointModal.open { align-items: flex-start; padding: 2vh 0; }
    #pointModal.open .pm-box { width: 96vw; max-width: 96vw; }
    /* Recupero spazio verticale su XS: titolo +2pt piu' piccolo, spazi ridotti.
       Specificita' #pointModal.open serve per battere le regole base (dopo). */
    #pointModal.open .pm-head { font-size: 12px; padding: 6px 12px 3px; }
    #pointModal.open .pm-head .x { font-size: 18px; }
    #pointModal.open .pm-body { padding: 6px 10px; }
    #pointModal.open .pm-dates { padding: 0 10px 4px; gap: 5px; }
    #pointModal.open .pm-dates .pm-date { padding: 3px 10px; font-size: 12px; }
}
.pm-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px;
           border-bottom: 1px solid #333; font-size: 14px; font-weight: bold; color: #fff; }
.pm-head .x { margin-left: auto; cursor: pointer; font-size: 22px; color: #888; }
.pm-body { padding: 12px 14px; }
.pm-dates { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 10px; }
.pm-dates .pm-date { cursor: pointer; padding: 4px 12px; border-radius: 14px;
    border: 1px solid #3a3a5e; color: #aab; font-size: 13px; user-select: none; }
.pm-dates .pm-date:hover { background: #2a2a48; }
.pm-dates .pm-date.active { background: #e94560; border-color: #e94560; color: #fff; font-weight: bold; }
.pm-body h4 { margin: 10px 0 4px; color: #e94560; font-size: 12px; text-transform: uppercase; }
.pm-body .row { display: flex; justify-content: space-between; padding: 2px 0; border-bottom: 1px solid #222; }
.pm-body .row .lbl { color: #888; }
.pm-body .row .val { color: #fff; font-weight: bold; }
.pm-body .row .val.good { color: #4caf50; }
.pm-body .row .val.marginal { color: #ff9800; }
.pm-body .row .val.poor { color: #f44336; }
.pm-body .row .val.excellent { color: #2196f3; }
.pm-wind { display: flex; align-items: flex-end; gap: 6px; margin: 6px 0; height: 120px; padding: 4px 0; }
.pm-wind .bar { display: flex; flex-direction: column; align-items: center; flex: 1; }
.pm-wind .bar .shaft { width: 2px; background: #4fc3f7; position: relative; }
.pm-wind .bar .flag { position: absolute; top: 0; width: 8px; height: 6px; background: #4fc3f7; left: 0; }
.pm-wind .bar .spd { font-size: 10px; color: #4fc3f7; margin-top: 2px; }
.pm-wind .bar .alt { font-size: 9px; color: #666; }
.pm-profile { display: flex; align-items: flex-end; gap: 1px; margin: 6px 0; height: 100px; }
.pm-profile .tbar { flex: 1; background: #e94560; min-width: 3px; border-radius: 1px 1px 0 0; }
.pm-thermal-bar { height: 20px; border-radius: 4px; margin: 4px 0; }

/* ── Point modal: grafico giorno (sfondo chiaro) ─────────────── */
.pm-box.chart { background: #fff; color: #222; font-family: sans-serif; }
.pm-box.chart .pm-head { border-bottom: 1px solid #ddd; color: #222; }
.pm-chart-wrap { display: flex; flex-direction: column; background: #fff;
                 border: 1px solid #ccc; border-radius: 6px;
                 padding-bottom: 22px;
                 overflow-x: auto; }  /* scroll orizzontale: 13 colonne non stanno in mobile */
.chart-head { display: flex; border-bottom: 1px solid #ccc; background: #f4f7fb;
              min-width: max-content; }  /* resta largo anche quando scrolli */
.chart-head-legend { width: 42px; text-align: center; font-size: 9px; color: #15508a;
                     font-weight: bold; display: flex; align-items: center; justify-content: center;
                     flex-shrink: 0; }  /* non comprimere: sennò sparisce */
.chart-head-cols { display: flex; flex: 1; }
.chart-head-col { flex: 1 1 0; min-width: 40px; text-align: center; font-size: 10px;
                  font-weight: bold; color: #12337f; border-left: 1px solid #e5e5e5; padding: 1px 0; }
.chart-head-col:first-child { border-left: none; }
.chart-body { display: flex; min-width: max-content; }
.chart-grid { display: flex; flex: 1; position: relative; }
.chart-col { position: relative; flex: 1 1 0; min-width: 40px; border-left: 1px solid #e5e5e5;
             height: 504px; }  /* 560 - 10%: allineato a H nel JS (renderDailyChart) */
.chart-col:first-child { border-left: none; }
.chart-axis { position: relative; width: 42px; height: 504px; border-right: 1px solid #999;
              flex-shrink: 0; }  /* non comprimere: sennò sparisce */
.chart-y { position: absolute; right: 4px; font-size: 9px; color: #666; transform: translateY(50%); }
.chart-h { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center;
           font-size: 10px; color: #444; }
.cloud { position: absolute; left: 50%; margin-left: -10px; font-size: 15px; transform: translateY(50%); }
.bl-line { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid #1a6feb; }
.bl-line::after { content: 'BL'; position: absolute; right: 2px; top: -9px; font-size: 8px; color: #1a6feb; }
.ml-line { position: absolute; left: 0; right: 0; height: 0; border-top: 1.5px dashed #9c27b0; }
.ml-line::after { content: 'ML'; position: absolute; right: 2px; top: -9px; font-size: 8px; color: #9c27b0; }
.pm-summary { margin: 8px 0 4px; padding: 6px 10px; background: #f4f8ff; border-radius: 6px;
              font-size: 12px; color: #15508a; }
.pm-summary b { color: #0d3b6e; }

/* Diagramma modale: bande gradiente + frecce vento con km/h */
.grad-band { position: absolute; left: 0; right: 0; }
.wind-arrow { position: absolute; left: 50%; transform: translate(-50%, -50%); display: flex;
              align-items: center; gap: 2px; }
.wind-arrow svg { flex-shrink: 0; }
.wind-arrow .wspd { font-size: 9px; color: #12337f; font-weight: bold; }

/* Marker modale: triangolo tetto, nuvoletta cumulo, nuvoletta sovrasviluppi */
.red-tri { position: absolute; left: 50%; margin-left: -7px; transform: translateY(-50%); }
.thunder { position: absolute; left: 50%; margin-left: -12px; transform: translateY(-50%); }
.cloud svg, .thunder svg { display: block; }

/* Fiocco zero termico: bianco pieno, posizionato, con ombra per il contrasto */
.snow { position: absolute; left: 50%; margin-left: -7px; transform: translateY(-50%);
        filter: drop-shadow(0 0 2px rgba(0,0,0,.55)); }
.snow svg { display: block; }

/* Ascendenza m/s sopra la colonna oraria */
.asc-top { position: absolute; top: 2px; left: 50%; transform: translateX(-50%);
           background: #fff; border: 1px solid #9ab; border-radius: 8px;
           padding: 0 5px; font-size: 10px; font-weight: bold; color: #12337f;
           z-index: 3; white-space: nowrap; }


/* Sotto-titolo modale (come le immagini: data, ore, modello) */
.pm-sub { padding: 4px 14px 6px; font-size: 11px; color: #556; background: #f7fafd;
          border-bottom: 1px solid #e3e8ef; }

/* Carosello webcam nella modale punto */
.pm-cams { border-bottom: 1px solid #e3e8ef; background: #fafbfe; padding: 8px 10px; }
.pm-cams-head { display: flex; justify-content: space-between; font-size: 12px;
                color: #0d3b6e; margin-bottom: 6px; }
.pm-cam-count { color: #667; font-size: 11px; }


/* Spinner + loader iniziale cartina e loading grafico modale */
#appLoader { position: fixed; inset: 0; z-index: 9000; display: flex; align-items: center;
             justify-content: center; gap: 10px; background: #16213e; color: #eee;
             font: 600 15px sans-serif; }
.spin { width: 22px; height: 22px; border: 3px solid rgba(255,255,255,.25);
        border-top-color: #4fc3f7; border-radius: 50%;
        animation: spin 0.8s linear infinite; display: inline-block; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.pm-loading { display: flex; align-items: center; justify-content: center; gap: 10px;
              padding: 28px 0; color: #15508a; font: 600 14px sans-serif; }

/* Toggle overlay topografico (sopra i colori) */
#topo-toggle-wrap { display: inline-flex; align-items: center; gap: 5px;
                    font-size: 12px; font-weight: bold; color: #cfe3ff; cursor: pointer;
                    user-select: none; white-space: nowrap;
                    border: 1px solid #2a5c9a; border-radius: 4px; padding: 3px 8px;
                    background: rgba(20,60,110,.5); }
#topo-toggle { accent-color: #4fc3f7; cursor: pointer; }

/* Badge livello di zoom */
#zoom-label { font: 700 13px monospace; color: #8fd3ff; background: rgba(15,52,96,.85);
              border: 1px solid #2a5c9a; border-radius: 4px; padding: 3px 8px;
              user-select: none; white-space: nowrap; }

/* Bottone "mia posizione": terzo tasto della barra zoom (continuo, senza spazi) */
/* Toggle layer sempre visibile e cliccabile anche a pannello aperto:
   la lista slitta a sx e lascia spazio al pulsante in alto a dx */
/* Anello long-press 3s: si allarga e sfuma, poi ricentra sulla posizione */
.longpress-ring { position: absolute; width: 64px; height: 64px; margin: -32px 0 0 -32px;
                  border: 3px solid #1976d2; border-radius: 50%;
                  opacity: 0.9; pointer-events: none; z-index: 800; transform: scale(0.3); }
.longpress-ring.go { transition: transform 3s linear, opacity 3s linear;
                     transform: scale(1.6); opacity: 0.15; }
.leaflet-control-layers-expanded { position: relative; padding-right: 54px !important; }
.leaflet-control-layers-expanded .leaflet-control-layers-toggle { display: block !important;
    position: absolute; top: 6px; right: 6px; }
.leaflet-control-zoom .leaflet-control-zoom-out { border-bottom-left-radius: 0 !important;
                                                  border-bottom-right-radius: 0 !important; }
.leaflet-control-zoom .locate-btn { border-top: 1px solid #ccc;
                                    border-bottom-left-radius: 4px; border-bottom-right-radius: 4px;
                                    display: flex !important; align-items: center; justify-content: center; }
.leaflet-control-zoom .locate-btn svg { width: 22px; height: 22px; }
.leaflet-control-zoom .locate-btn.locating { pointer-events: none; opacity: 0.5; }
/* Pulsanti zoom/mirino grandi come il toggle layer (36px) e al 50%;
   opachi solo al passaggio sopra */
.leaflet-control-zoom a { width: 36px !important; height: 36px !important;
                          line-height: 36px !important; font-size: 22px !important; }
.leaflet-control-zoom { opacity: 0.5; transition: opacity 5s ease; }
@media (hover: hover) {
    .leaflet-control-zoom:hover { opacity: 1; transition-duration: 0.15s; }
}
/* Tap/click (anche touch, dove l'hover resta incollato): opaco subito, fade 5s */
.leaflet-control-zoom.lit { opacity: 1; transition-duration: 0.15s; }

/* ── Chat AI panel ── */
#chat-btn { margin-left: 10px; padding: 4px 10px; border-radius: 6px; border: 1px solid #2a6fb5;
            background: #12406b; color: #dcebff; cursor: pointer; font-size: 12px; }
/* Pannello layer custom: icona sempre togglabile anche su touch */
.m2-layers { background: #fff; border: 2px solid rgba(0,0,0,0.2); border-radius: 5px;
    background-clip: padding-box; }
.m2-layers-toggle { display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; }
.m2-layers-panel { display: none; padding: 4px 10px 8px 6px; }
.m2-layers.open .m2-layers-panel { display: block; }
.m2-layers-head { font-size: 12px; font-weight: bold; color: #666;
    padding: 8px 4px 4px 4px; cursor: pointer; }
.m2-layers-panel label { display: flex; align-items: center; gap: 8px;
    padding: 8px 4px; font-size: 14px; white-space: nowrap; cursor: pointer; }
.m2-layers-panel input[type="checkbox"] { width: 20px; height: 20px; }
#chat-btn:hover { background: #1a5590; }
/* Chat AI nel dock legenda: stessa altezza/grafica/trasparenza */
#legend-dock #chat-btn {
    margin-left: 0; border-radius: 8px; border: 1px solid #0f3460;
    background: rgba(22, 33, 62, 0.9); color: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
    font-size: 13px; font-weight: bold; padding: 6px 14px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    flex: 0 0 auto; white-space: nowrap;
}
#legend-dock #chat-btn:hover { background: rgba(35, 55, 95, 0.95); }
#chat-panel { position: absolute; left: 50%; transform: translateX(-50%); bottom: 90px;
              width: min(420px, calc(100vw - 24px)); max-height: 60vh;
              background: rgba(13, 32, 56, .96); border: 1px solid #2a6fb5; border-radius: 10px;
              display: flex; flex-direction: column; z-index: 1100; }
#chat-panel.hidden { display: none; }
#chat-head { padding: 8px 12px; font-weight: 700; color: #8fd3ff; border-bottom: 1px solid #2a6fb5;
             display: flex; justify-content: space-between; align-items: center; }
.chat-close { cursor: pointer; color: #7fa8d0; font-weight: 400; }
.chat-close:hover { color: #fff; }
#chat-msgs { padding: 10px; overflow-y: auto; flex: 1; min-height: 120px; max-height: 40vh;
             font-size: 13px; line-height: 1.45; color: #e8f2fc; white-space: pre-wrap; }
.chat-msg { margin-bottom: 8px; padding: 7px 9px; border-radius: 8px; }
.chat-msg.user { background: #1a5590; margin-left: 24px; }
.chat-msg.bot { background: #0b2847; margin-right: 24px; white-space: pre-line; }
/* Puntini che ballano mentre la chat attende la risposta */
.chat-typing { display: inline-flex; gap: 6px; padding: 2px 0; }
.chat-typing span { width: 8px; height: 8px; border-radius: 50%; background: #9fc2e8;
    animation: chatBounce 1.2s infinite ease-in-out; }
.chat-typing span:nth-child(2) { animation-delay: -0.4s; }
.chat-typing span:nth-child(3) { animation-delay: -0.2s; }
@keyframes chatBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30% { transform: translateY(-6px); opacity: 1; }
}
.chat-msg.err { background: #5a1f1f; color: #ffd8d8; }
#chat-input-row { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #2a6fb5; }
#chat-input { flex: 1; padding: 7px 9px; border-radius: 6px; border: 1px solid #2a6fb5;
              background: #0b2847; color: #e8f2fc; font-size: 13px; }
#chat-mic { background: transparent; border: none; font-size: 18px; cursor: pointer;
    transition: transform .15s; }
#chat-mic:hover { transform: scale(1.15); }
#chat-mic.rec { color: #e94560; animation: micPulse 1s infinite; }
@keyframes micPulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
#chat-input-row button { padding: 6px 12px; border-radius: 6px; border: 1px solid #2a6fb5;
                         background: #12406b; color: #dcebff; cursor: pointer; }

/* Galleggiante webcam: nascosto di default (desktop e modale senza webcam),
   attivo solo su XS nella media query sotto. */
#pmCamFab { display: none; }

/* Nome sito sotto la bandierina: tooltip PERMANENTI, nascosti di default;
   visibili solo quando il container mappa ha .z11plus (zoom >= 11, JS). */
.leaflet-container .leaflet-tooltip.site-label { visibility: hidden; opacity: 0; }
.leaflet-container.z11plus .leaflet-tooltip.site-label { visibility: visible; opacity: 1; }
.leaflet-tooltip.site-label {
    background: rgba(15, 52, 96, 0.92); color: #fff;
    border: 1px solid #0f3460; border-radius: 4px;
    padding: 2px 7px; font-size: 11px; font-weight: bold;
    box-shadow: 0 1px 4px rgba(0,0,0,.4); white-space: nowrap;
}
/* NB: visibility (non display:none) perche' Leaflet calcola la posizione
   del tooltip con le dimensioni reali: con display:none il primo frame a
   z11 risulta disassato (dims 0) e si allinea solo al frame successivo. */
.leaflet-tooltip.site-label::before {
    border-top-color: rgba(15, 52, 96, 0.92);  /* freccia che punta alla bandierina (tooltip in alto) */
}

/* Solo XS: galleggiante tondo semitrasparente in basso a sx → webcam */
@media (max-width: 600px) {
    #pmCamFab {
        position: fixed; left: 14px; bottom: 86px; z-index: 2900;
        display: flex; align-items: center; gap: 5px;
        padding: 12px 14px; border: none; cursor: pointer;
        border-radius: 999px; background: rgba(15, 52, 96, 0.65);
        color: #fff; font-size: 12px; font-weight: bold;
        backdrop-filter: blur(2px); box-shadow: 0 2px 8px rgba(0,0,0,.35);
        /* abbassato di un'altezza pari alla sua */
        transform: translateY(100%);
    }
    #pmCamFab:active { background: rgba(233, 69, 96, 0.8); }
}

/* ── Mobile (max 600px) ───────────────────────────────────────── */
@media (max-width: 600px) {
    #header { flex-wrap: nowrap; row-gap: 0; gap: 6px; }
    #header .header-left { display: flex; flex: 1 1 auto; min-width: 0; gap: 6px; }
    #header .header-right { display: flex; flex: 0 0 auto; align-items: center; }
    #header select { padding: 4px 6px; font-size: 24px; min-width: 0; }
    #param-select { flex: 2.2 1 0; }
    #date-select { flex: 1 1 0; }
    #header .header-right { display: none; }
    #legend-dock { left: 16px; width: auto; }
    #legend-dock #chat-btn { font-size: 12px; padding: 4px 10px; }
    #zoom-label, #model-badge, #info-label { display: none; }
    #chat-btn { margin-left: 0; font-size: 14px; padding: 6px 8px; white-space: nowrap; }
    #timeslider-container { flex-wrap: wrap; padding: 4px 8px 6px; }
    #slider-track { min-width: 120px; }
    #map { min-height: 0; }
}
