:root {
  --fondo: #12101c;
  --pannello: #1c1930;
  --bordo: #2e2a4a;
  --testo: #f1eefc;
  --tenue: #a9a3c9;
  --accento: #ff4fa3;
  --accento2: #2fd6c8;
  --altezza-barra: 56px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--fondo); color: var(--testo);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { display: flex; flex-direction: column; overflow: hidden; }
a { color: var(--accento2); }

.barra { display: flex; align-items: center; gap: 12px; padding: 8px 16px;
  background: linear-gradient(90deg, #1c1930, #2a1535); border-bottom: 1px solid var(--bordo); }
.titolo { margin: 0; font-size: 18px; white-space: nowrap; color: var(--accento); letter-spacing: .3px; }
.titolo .sotto { display: block; font-size: 11px; font-weight: 400; color: var(--tenue); }
.cerca { position: relative; flex: 1; min-width: 0; }
.cerca input { width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--bordo);
  background: var(--fondo); color: var(--testo); font-size: 15px; }
.cerca input:focus { outline: 2px solid var(--accento2); }
.suggerimenti { position: absolute; z-index: 1200; left: 0; right: 0; top: 100%; margin: 4px 0 0;
  padding: 4px; list-style: none; background: var(--pannello); border: 1px solid var(--bordo);
  border-radius: 10px; max-height: 50vh; overflow: auto; }
.suggerimenti li { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.suggerimenti li:hover, .suggerimenti li.attivo { background: var(--bordo); }
.suggerimenti .tipo { color: var(--tenue); font-size: 12px; margin-left: 6px; }

.corpo { flex: 1; display: flex; min-height: 0; }
.menu-btn { flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; border-radius: 9px; border: 1px solid var(--bordo);
  background: var(--fondo); color: var(--testo); cursor: pointer; }
.menu-btn:hover { background: var(--bordo); }

/* --- barra laterale dei filtri (come la mappa di riferimento) --- */
.sidebar { flex: none; width: 292px; min-height: 0; display: flex; flex-direction: column;
  background: var(--pannello); border-right: 1px solid var(--bordo); }
.sb-testa { display: flex; align-items: center; gap: 8px; padding: 10px 12px 8px;
  border-bottom: 1px solid var(--bordo); }
.sb-testa strong { font-size: 14px; letter-spacing: .3px; }
.sb-chiudi { margin-left: auto; width: 28px; height: 28px; border: 0; border-radius: 7px;
  background: transparent; color: var(--tenue); font-size: 20px; line-height: 1; cursor: pointer; }
.sb-chiudi:hover { background: var(--bordo); color: var(--testo); }
.sb-cerca { padding: 8px 10px 4px; }
.sb-cerca input { width: 100%; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--bordo);
  background: var(--fondo); color: var(--testo); font-size: 13px; }
.sb-cerca input:focus { outline: 2px solid var(--accento2); }
.sb-azioni { display: flex; gap: 6px; padding: 6px 10px; }
.sb-azioni button { flex: 1; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--bordo);
  background: var(--fondo); color: var(--testo); font-size: 12px; cursor: pointer; }
.sb-azioni button:hover { background: var(--bordo); }
.sb-conteggio { padding: 0 12px 8px; color: var(--tenue); font-size: 12px; }
#lista-filtri { flex: 1; overflow-y: auto; padding-bottom: 24px; scrollbar-width: thin; }
.sb-gruppo { border-top: 1px solid var(--bordo); }
.sb-gruppo-testa { display: flex; align-items: center; gap: 7px; padding: 8px 10px; cursor: pointer;
  user-select: none; }
.sb-gruppo-testa:hover { background: #242040; }
.sb-gruppo-testa input { accent-color: var(--accento); }
.sb-nome { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pallino { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.sb-conta { margin-left: auto; color: var(--tenue); font-size: 11px; font-variant-numeric: tabular-nums; }
.sb-freccia { border: 0; background: transparent; color: var(--tenue); cursor: pointer;
  font-size: 11px; padding: 2px 4px; transition: transform .15s; }
.sb-gruppo.chiuso .sb-freccia { transform: rotate(-90deg); }
.sb-gruppo.chiuso .sb-tipi { display: none; }
.sb-tipi { padding: 0 6px 6px 12px; }
.sb-tipo { display: flex; align-items: center; gap: 7px; padding: 3px 6px; border-radius: 6px;
  font-size: 12.5px; cursor: pointer; }
.sb-tipo:hover { background: #242040; }
.sb-tipo input { accent-color: var(--accento); flex: none; }
.sb-ic { display: inline-flex; width: 16px; height: 16px; flex: none; align-items: center; justify-content: center; }
.sb-ic svg { width: 15px; height: 15px; fill: currentColor; }
.sb-ic img { width: auto; object-fit: contain; }
.sb-tipo-nome { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-tipo input:not(:checked) ~ .sb-ic,
.sb-tipo input:not(:checked) ~ .sb-tipo-nome { opacity: .4; }

@media (max-width: 759px) {
  .sidebar { position: fixed; z-index: 1400; top: 0; bottom: 0; left: 0;
    width: min(88vw, 320px); transform: translateX(-100%); transition: transform .2s;
    box-shadow: 8px 0 24px rgba(0,0,0,.45); }
  .sidebar.aperta { transform: none; }
}
@media (min-width: 760px) {
  .sidebar.chiusa { display: none; }
}

#mappa { flex: 1; min-width: 0; background: #2b8fae; }
.leaflet-container { font: inherit; }

.blip-wrap { background: transparent; border: 0; }
.blip { display: flex; align-items: center; justify-content: center; width: 26px; height: 26px;
  border-radius: 50%; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.5); }
.blip svg { display: block; fill: currentColor; }
.blip-img { border: 0; box-shadow: none; background: transparent; }
.blip-img img { display: block; filter: drop-shadow(0 1px 3px rgba(0,0,0,.55)); }
.blip-wrap.scelto .blip { outline: 3px solid var(--accento); outline-offset: 2px; }
.etichetta-zona { background: rgba(18,16,28,.75); color: #fff; border: 0; border-radius: 6px;
  padding: 2px 6px; font-size: 12px; box-shadow: none; }
.etichetta-zona::before { display: none; }

/* Raggruppamenti (Leaflet.markercluster) nei colori del sito */
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large {
  background: rgba(255, 79, 163, .22);
}
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div {
  background: var(--accento); color: #fff; font-weight: 700;
}
.marker-cluster span { color: #fff; }

.scheda { position: fixed; z-index: 1100; background: var(--pannello); border: 1px solid var(--bordo);
  box-shadow: 0 -6px 24px rgba(0,0,0,.45); overflow: auto; }
.scheda .chiudi { position: sticky; top: 0; float: right; width: 40px; height: 40px; border: 0;
  background: transparent; color: var(--tenue); font-size: 28px; cursor: pointer; }
#scheda-corpo { padding: 16px 18px 24px; }
.scheda h2 { margin: 0 0 4px; font-size: 20px; }
.icona-titolo { color: var(--accento2); display: inline-flex; vertical-align: -4px; margin-right: 4px; }
.scheda .meta { color: var(--tenue); font-size: 13px; margin-bottom: 12px; }
.scheda h3 { margin: 14px 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--accento2); }
.scheda p { margin: 0; white-space: pre-line; }
.scheda .bollino { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px;
  background: #2e7d32; color: #fff; margin-left: 6px; }
.scheda .fonti { margin: 0; padding-left: 18px; }
.scheda .azioni { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.bottone { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--bordo); background: var(--fondo);
  color: var(--testo); cursor: pointer; font-size: 14px; }
.bottone.primario { background: var(--accento); border-color: var(--accento); color: #fff; }
.bottone.pericolo { border-color: #c62828; color: #ff8a80; }

/* Telefono: la scheda sale dal basso */
@media (max-width: 759px) {
  .titolo .sotto { display: none; }
  .titolo { font-size: 16px; }
  .scheda { left: 0; right: 0; bottom: 0; max-height: 62vh; border-radius: 16px 16px 0 0; }
}
/* PC: la scheda sta a destra */
@media (min-width: 760px) {
  .scheda { top: 120px; right: 16px; bottom: 40px; width: 380px; border-radius: 14px; }
}

.crediti { padding: 4px 16px; font-size: 11px; color: var(--tenue); background: var(--fondo);
  border-top: 1px solid var(--bordo); }

/* Editor (solo sul PC, con strumenti/editor.py) */
.editor-barra { position: fixed; z-index: 1150; left: 50%; transform: translateX(-50%); top: 112px;
  background: #8e24aa; color: #fff; padding: 6px 14px; border-radius: 999px; font-size: 13px; }
.modulo label { display: block; margin: 10px 0 3px; font-size: 13px; color: var(--tenue); }
.modulo input, .modulo select, .modulo textarea { width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--bordo); background: var(--fondo); color: var(--testo); font: inherit; }
.modulo textarea { min-height: 64px; resize: vertical; }
.modulo .riga { display: flex; gap: 8px; }
.modulo .riga > * { flex: 1; }
.modulo .errore { color: #ff8a80; margin-top: 10px; }
@media (max-width: 759px) {
  .editor-barra { top: auto; bottom: 8px; font-size: 12px; white-space: nowrap; }
}

/* ================= Telefono: stile D ================= */
.d-ui, .d-velo { display: none; }
@media (max-width: 759px) {
  .barra, #filtri, .crediti, .leaflet-control-zoom { display: none; }
  .d-ui { display: block; }
  .d-velo:not([hidden]) { display: block; }
  .d-titolo { position: fixed; z-index: 1000; top: calc(10px + env(safe-area-inset-top)); left: 64px; right: 64px;
    text-align: center; font-weight: 700; font-size: 15px; color: #fff; pointer-events: none;
    text-shadow: 0 1px 4px #000, 0 0 12px rgba(0,0,0,.6); }
  .d-titolo small { display: block; font-weight: 400; font-size: 12px; opacity: .9; }
  .d-fab { position: fixed; z-index: 1350; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
    transform: translateX(-50%); width: 64px; height: 64px; border-radius: 50%; border: 0;
    background: #fff; color: #111; font-size: 26px; cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,.5); }
  .d-fab-chiudi { display: none; }
  body.d-aperto .d-fab { background: var(--accento); color: #fff; }
  body.d-aperto .d-fab-apri { display: none; }
  body.d-aperto .d-fab-chiudi { display: inline; }
  .d-tondo { position: fixed; z-index: 1000; bottom: calc(31px + env(safe-area-inset-bottom)); width: 44px; height: 44px;
    border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer; color: #fff;
    background: rgba(18,16,28,.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 2px 10px rgba(0,0,0,.4); }
  .d-sx { left: 28px; } .d-dx { right: 28px; }
  body.d-aperto .d-tondo { display: none; }
  .d-attrib { position: fixed; z-index: 900; right: 6px; bottom: calc(2px + env(safe-area-inset-bottom));
    font-size: 9.5px; color: #fff; opacity: .75; text-decoration: none; text-shadow: 0 1px 2px #000; }

  .d-velo { position: fixed; inset: 0; z-index: 1300; background: rgba(0,0,0,.62);
    backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
  .d-pannello { position: absolute; left: 12px; right: 12px; bottom: calc(100px + env(safe-area-inset-bottom)); }
  .d-griglia { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .d-griglia[hidden], .d-tipi[hidden], .d-crediti[hidden] { display: none; }
  .d-cat { position: relative; border: 0; border-radius: 16px; padding: 10px 4px 8px; background: #fff; color: #111;
    font: 600 11.5px/1.2 system-ui, sans-serif; text-align: center; cursor: pointer; min-height: 82px; }
  .d-cat .d-ic { display: flex; height: 30px; align-items: center; justify-content: center; margin-bottom: 4px; }
  .d-cat .d-ic img { height: 28px; width: auto; }
  .d-cat em { display: block; font-style: normal; font-weight: 400; color: #888; font-size: 10.5px; margin-top: 2px; }
  .d-cat.spento { opacity: .4; }
  .d-cat.parziale::after { content: ""; position: absolute; left: 8px; top: 8px; width: 8px; height: 8px;
    border-radius: 50%; background: var(--accento); }
  .d-cat .d-piu { position: absolute; top: 0; right: 0; width: 34px; height: 34px; border: 0; background: transparent;
    color: #999; font-size: 18px; cursor: pointer; }
  .d-comandi { grid-column: 1 / -1; display: flex; gap: 8px; }
  .d-comandi button { flex: 1; padding: 10px 0; border-radius: 14px; border: 0; background: rgba(255,255,255,.92);
    color: #111; font-weight: 600; font-size: 13px; cursor: pointer; }

  .d-tipi, .d-crediti { top: calc(56px + env(safe-area-inset-top)); background: #fff; color: #111; border-radius: 18px;
    display: flex; flex-direction: column; overflow: hidden; }
  .d-tipi-testa { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid #eee; }
  .d-tipi-testa button { border: 0; background: transparent; font-size: 26px; line-height: 1; cursor: pointer; color: #111; padding: 0 6px; }
  .d-tipi-testa b { font-size: 15px; }
  .d-tipi-testa small { display: block; color: #888; font-size: 11px; font-weight: 400; }
  .d-tipi-testa img { height: 24px; }
  .d-tipi-lista { overflow-y: auto; flex: 1; padding: 4px 12px 12px; }
  .d-tipo { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid #f0f0f0; font-size: 13.5px; cursor: pointer; }
  .d-tipo .d-ic { width: 24px; display: inline-flex; justify-content: center; }
  .d-tipo .d-ic svg { width: 20px; height: 20px; }
  .d-tipo .d-ic img { height: 22px; width: auto; }
  .d-tipo .d-n { margin-left: auto; color: #999; font-size: 12px; font-variant-numeric: tabular-nums; }
  .d-tipo input { appearance: none; -webkit-appearance: none; flex: none; width: 36px; height: 21px; border-radius: 11px;
    background: #ddd; position: relative; cursor: pointer; transition: background .15s; margin: 0; }
  .d-tipo input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%;
    background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
  .d-tipo input:checked { background: var(--accento); }
  .d-tipo input:checked::after { left: 17px; }
  .d-crediti { padding: 16px; font-size: 13px; line-height: 1.5; gap: 10px; }
  .d-crediti a { color: #c2185b; }

  /* ricerca: il blocco .cerca della barra, in alto sul velo */
  body.d-cerca .barra { display: flex; position: fixed; z-index: 1340; top: calc(14px + env(safe-area-inset-top));
    left: 12px; right: 12px; padding: 0; background: transparent; border: 0; }
  body.d-cerca .barra .menu-btn, body.d-cerca .barra .titolo { display: none; }
  body.d-cerca .cerca input { padding: 13px 14px; border-radius: 16px; background: #fff; color: #111; border: 0; font-size: 16px; }
  body.d-cerca .suggerimenti { background: #fff; color: #111; border: 0; border-radius: 16px; max-height: 60vh; }
  body.d-cerca .suggerimenti li { padding: 11px 10px; border-bottom: 1px solid #f0f0f0; }
  body.d-cerca .suggerimenti li:hover, body.d-cerca .suggerimenti li.attivo { background: #f4f4f4; }
  body.d-cerca .suggerimenti .tipo { color: #888; }

  /* scheda dal basso, trascinabile */
  .scheda { max-height: none; height: 55vh; height: 55dvh; border-radius: 22px 22px 0 0; z-index: 1360;
    background: #fff; color: #222; border: 0; transition: height .2s; overscroll-behavior: contain; }
  .scheda.piena { height: calc(100dvh - 24px); }
  .scheda.trascina { transition: none; }
  .scheda .maniglia { position: sticky; top: 0; z-index: 2; height: 26px; width: 55%; margin: 0 auto -26px; display: flex;
    justify-content: center; align-items: center; touch-action: none; cursor: grab; background: linear-gradient(#fff 60%, transparent); }
  .scheda .maniglia::before { content: ""; width: 40px; height: 5px; border-radius: 3px; background: #ccc; }
  .scheda .chiudi { color: #888; }
  #scheda-corpo { padding-top: 26px; }
  .scheda .meta { color: #777; }
  .scheda h3 { color: #c2185b; }
  .icona-titolo { color: #c2185b; }
  .scheda .bottone { background: #f2f2f2; color: #111; border-color: #e0e0e0; }
  .scheda .bottone.primario { background: #111; color: #fff; border-color: #111; }
  .scheda .bottone.fatto { background: #2e7d32; color: #fff; border-color: #2e7d32; }
  .editor-barra { bottom: calc(96px + env(safe-area-inset-bottom)); }
}
@media (min-width: 760px) {
  .scheda .maniglia { display: none; }
}
.blip-wrap.trovato { opacity: .45; }
.bottone.fatto { background: #2e7d32; border-color: #2e7d32; color: #fff; }

/* Account Google (facoltativo) */
.sb-account { margin: 0 10px 8px; padding: 8px 10px; border: 1px solid var(--bordo); border-radius: 10px; font-size: 12px; }
.sb-account[hidden] { display: none; }
.acc-testo { margin: 0 0 8px; line-height: 1.4; color: var(--tenue); }
.acc-testo b { color: var(--testo); }
.acc-riga { display: flex; align-items: center; gap: 8px; }
.acc-riga span { flex: 1; }
.acc-esci { padding: 5px 10px; border-radius: 8px; border: 1px solid var(--bordo); background: var(--fondo);
  color: var(--testo); cursor: pointer; font-size: 12px; }
.acc-avviso { margin: 8px 0 0; color: #ff8a80; }
.acc-google { min-height: 40px; }
@media (max-width: 759px) {
  .d-account { font-size: 14px; }
  .d-account .acc-testo { color: #555; }
  .d-account .acc-testo b { color: #111; }
  .d-account .acc-esci { background: #111; color: #fff; border: 0; padding: 8px 14px; }
  .d-comandi button[hidden] { display: none; }
}
@media (max-width: 759px) {
  .d-crediti { top: auto; max-height: calc(100dvh - 180px); overflow-y: auto; }
}

/* Filtro attivo: etichetta rosa in alto, la ✕ torna alla mappa pulita */
.etichetta { position: fixed; z-index: 1050; left: 50%; transform: translateX(-50%); top: 70px;
  display: flex; align-items: center; gap: 6px; padding: 5px 6px 5px 12px; border-radius: 18px;
  background: var(--accento); color: #fff; font: 600 13px/1.2 system-ui, sans-serif; white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0,0,0,.4); max-width: calc(100vw - 32px); }
.etichetta[hidden] { display: none; }
.etichetta span:not(.et-ic) { overflow: hidden; text-overflow: ellipsis; }
.etichetta .et-ic { display: inline-flex; }
.etichetta .et-ic img, .etichetta .et-ic svg { height: 16px; width: auto; fill: currentColor; }
.etichetta button { width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(255,255,255,.28);
  color: #fff; font-size: 13px; cursor: pointer; flex: none; }

/* Mappa pulita: «Cosa cerchi?» */
.invito { position: fixed; z-index: 1040; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(92vw, 380px); padding: 18px 16px 14px; border-radius: 20px; text-align: center;
  background: rgba(18,16,28,.88); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--bordo); box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.invito[hidden] { display: none; }
.invito h2 { margin: 0 0 12px; font-size: 20px; color: #fff; }
.invito .inv-cerca { width: 100%; padding: 12px; border-radius: 14px; border: 0; background: #fff; color: #111;
  font-size: 15px; font-weight: 600; cursor: pointer; }
.inv-scelte { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 12px 0 8px; }
.inv-scelte button { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 16px;
  border: 1px solid var(--bordo); background: var(--pannello); color: var(--testo); font-size: 13px; cursor: pointer; }
.inv-scelte button img, .inv-scelte button svg { height: 18px; width: auto; fill: currentColor; }
.invito .inv-tutto { border: 0; background: transparent; color: var(--tenue); font-size: 12px; text-decoration: underline; cursor: pointer; }

/* «solo» */
.sb-solo { display: none; flex: none; margin-left: 4px; padding: 1px 7px; border-radius: 8px; border: 1px solid var(--accento);
  background: transparent; color: var(--accento); font-size: 10.5px; cursor: pointer; }
.sb-tipo:hover .sb-solo, .sb-gruppo-testa:hover .sb-solo { display: inline-block; }
.suggerimenti li.voce-tipo { font-weight: 600; }
.suggerimenti li.voce-tipo .tipo { color: var(--accento); }
@media (max-width: 759px) {
  .etichetta { top: calc(56px + env(safe-area-inset-top)); }
  .d-solo { flex: none; padding: 3px 9px; border-radius: 10px; border: 1px solid #f3b6d1; background: #fff;
    color: #c2185b; font-size: 11.5px; font-weight: 700; cursor: pointer; }
  body.d-cerca .suggerimenti li.voce-tipo .tipo { color: #c2185b; }
  .d-cat { touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}
@media (min-width: 760px) {
  .etichetta, .invito { left: calc(50% + 146px); }
  body:has(.sidebar.chiusa) .etichetta, body:has(.sidebar.chiusa) .invito { left: 50%; }
}
