:root {
  --ink: #2b2b2b;
  --ink-soft: #5c5c5c;
  --ink-mute: #767676;
  --brand: #393939;
  --accent: #f89d35;
  --accent-hover: #f0891a;
  --accent-ink: #9a5100;
  --line: #e3e0db;
  --line-strong: #cfcac2;
  --bg: #ffffff;
  --bg-soft: #f7f5f2;
  --bg-sel: #fff4e6;
  --danger: #b42318;
  --ok: #1d7a46;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.08);
  --topbar-h: 68px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 var(--font);
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--accent-ink); }
a:hover { color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 2000;
  background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 6px;
}
.skip-link:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* --- Barra superiore ------------------------------------------------------ */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px;
  background: var(--brand); color: #fff;
  position: relative; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; flex: none; }
.brand:hover { color: #fff; }
.brand img { display: block; height: 36px; width: auto; }
.topbar-title { flex: 1; min-width: 0; padding-left: 18px; border-left: 1px solid rgba(255,255,255,.18); }
.topbar-title h1 { margin: 0; font-size: 19px; font-weight: 650; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title h1 .t-short { display: none; }
.topbar-title p { margin: 2px 0 0; font-size: 13px; color: rgba(255,255,255,.72); }
.topbar-title a { color: var(--accent); }
.topbar-title a:hover { color: #fff; }

/* --- Pulsanti ---------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 18px;
  border: 1px solid transparent; border-radius: 999px;
  font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color .15s, border-color .15s;
}
.btn-accent { background: var(--accent); color: #2a1600; }
.btn-accent:hover { background: var(--accent-hover); color: #2a1600; }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-link {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; font-weight: 600;
}
.btn-link:hover { color: var(--ink); }

/* --- Struttura -------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(340px, 420px) 1fr;
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
}
.panel {
  border-right: 1px solid var(--line);
  background: var(--bg);
  overflow: hidden;
  display: flex; flex-direction: column;
  min-height: 0;
}
.panel-view { flex: 1; overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
#list-view { padding: 16px 16px 24px; }
.map-wrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #e8e6e1; }
.noscript { position: absolute; inset: auto 16px 16px; background: #fff; padding: 12px; border-radius: var(--radius); }

/* --- Ricerca e filtri ------------------------------------------------- */
.search { position: relative; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-mute); pointer-events: none; }
.search input[type="search"] {
  width: 100%; height: 44px; padding: 0 14px 0 40px;
  border: 1px solid var(--line-strong); border-radius: 999px; background: var(--bg-soft);
}
.search input[type="search"]:focus { background: #fff; border-color: var(--ink-mute); outline: none; box-shadow: 0 0 0 3px rgba(248,157,53,.35); }

.when { display: grid; gap: 10px; margin-top: 12px; }
.when-row { display: flex; align-items: center; gap: 10px; }
.when-row label { font-weight: 600; font-size: 14px; flex: none; }
.date-range { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.date-range label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }

.filters { margin-top: 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.filters summary {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; cursor: pointer; font-weight: 600; list-style: none;
}
.filters summary::-webkit-details-marker { display: none; }
.filters summary::after {
  content: ""; margin-left: auto; width: 8px; height: 8px;
  border-right: 2px solid var(--ink-soft); border-bottom: 2px solid var(--ink-soft);
  transform: rotate(45deg) translateY(-2px); transition: transform .15s;
}
.filters[open] summary::after { transform: rotate(-135deg) translateY(-2px); }
.filter-count {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--accent); color: #2a1600; font-size: 12px; font-weight: 700;
  display: inline-grid; place-items: center;
}
.filters-body { padding: 4px 14px 14px; display: grid; gap: 12px; }
.filter-row { display: grid; gap: 5px; margin: 0; padding: 0; border: 0; min-width: 0; }
.filter-row > label, .filter-row > legend { font-size: 13px; font-weight: 600; color: var(--ink-soft); padding: 0; margin-bottom: 5px; }
:where(select, input:not([type=checkbox]):not([type=radio]), textarea) {
  width: 100%; min-height: 40px; padding: 8px 11px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: #fff;
}
:where(select) { padding-right: 30px; }
select:focus, input:focus { outline: none; border-color: var(--ink-mute); box-shadow: 0 0 0 3px rgba(248,157,53,.35); }
.reset-link { margin-top: 10px; font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; display: inline-flex; cursor: pointer; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: 999px;
  font-size: 14px; background: #fff; transition: background-color .12s, border-color .12s;
}
.chip input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.chip:hover span { border-color: var(--ink-mute); }

.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--brand); flex: none; }

/* --- Elenco ------------------------------------------------------------ */
.result-count { margin: 16px 2px 8px; font-size: 13px; color: var(--ink-soft); }
.results { list-style: none; margin: 0; padding: 0; }
.results:focus { outline: none; }
.results li + li { border-top: 1px solid var(--line); }
.results li.sep, .results li.sep + li { border-top: 0; }
.results .sep {
  margin: 18px 2px 6px; font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--ink-mute);
}
.result {
  display: grid; grid-template-columns: 52px 1fr; gap: 12px; align-items: start;
  width: 100%; padding: 12px 8px; border: 0; background: none; text-align: left; cursor: pointer;
  border-radius: 8px;
}
.result:hover, .result.is-hover { background: var(--bg-soft); }
.result.is-active { background: var(--bg-sel); }
.result-body { display: grid; gap: 2px; min-width: 0; }
.result-name { font-weight: 600; line-height: 1.3; }
.result-when { font-size: 13px; color: var(--accent-ink); font-weight: 600; }
.result-meta { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-soft); }
.result.is-past .result-name, .result.is-past .result-when { color: var(--ink-soft); }
.empty { padding: 24px 8px; color: var(--ink-soft); }
.panel-foot { margin: 20px 2px 0; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-soft); }

.date-badge {
  display: grid; justify-items: center; align-content: center;
  width: 52px; min-height: 52px; padding: 4px 0; border-radius: 10px;
  background: var(--brand); color: #fff; line-height: 1.05;
}
.db-day { font-size: 21px; font-weight: 700; }
.db-month { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.date-badge.is-ongoing { background: var(--accent); color: #2a1600; }
.date-badge.is-ongoing .db-day, .date-badge.is-ongoing .db-month { font-size: 12px; font-weight: 700; text-transform: uppercase; }
.date-badge.is-past { background: var(--bg-soft); color: var(--ink-soft); }

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); flex: none; }

/* --- Scheda dell'evento ------------------------------------------------- */
.detail:focus { outline: none; }
.detail-head { position: sticky; top: 0; z-index: 2; background: #fff; padding: 12px 16px 8px; }
.back { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px 6px 4px; border: 0; border-radius: 6px; background: none; cursor: pointer; color: var(--ink-soft); font-weight: 600; font-size: 14px; }
.back:hover { background: var(--bg-soft); color: var(--ink); }
.detail-img { display: block; width: calc(100% - 40px); margin: 0 20px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius); background: var(--bg-soft); }
.detail-body { padding: 8px 20px 32px; }
.detail-cat { display: flex; align-items: center; gap: 6px; margin: 8px 0 0; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.detail h2 { margin: 4px 0 4px; font-size: 22px; line-height: 1.25; }
.detail-org { margin: 0; color: var(--ink-soft); }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 6px; }
.detail-actions .btn { min-height: 36px; padding: 0 14px; font-size: 14px; }
.detail .prose { white-space: pre-line; font-size: 14px; margin: 16px 0 0; overflow-wrap: anywhere; }
.detail section { margin-top: 22px; }
.detail h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent-ink); }
.detail-when { margin: 0; font-weight: 650; }
.detail-when::first-letter { text-transform: uppercase; }
.detail-note { margin: 22px 0 0; padding: 12px 14px; background: var(--bg-soft); border-radius: var(--radius); font-size: 14px; }

.tappe { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.tappa { border-bottom: 1px solid var(--line); padding: 4px 0 10px; }
.tappa-main {
  display: grid; gap: 2px; width: 100%; padding: 8px 8px 4px; margin: 0;
  border: 0; border-radius: 8px; background: none; text-align: left; cursor: pointer;
}
.tappa-main:hover { background: var(--bg-soft); }
.tappa.is-active .tappa-main { background: var(--bg-sel); }
.tappa-when { font-weight: 650; font-size: 14px; }
.tappa-when::first-letter { text-transform: uppercase; }
.tappa-title { font-size: 14px; }
.tappa-place { font-size: 14px; color: var(--ink-soft); }
.tappa-approx { font-size: 12px; color: var(--ink-mute); }
.tappa.is-past .tappa-when { color: var(--ink-soft); }
.tappa-actions { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 2px 8px 0; font-size: 13px; }
.tappa-actions a, .tappa-actions .btn-link { font-weight: 600; }
.past-tappe { margin-top: 22px; }
.past-tappe summary { cursor: pointer; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-mute); margin-bottom: 8px; }

/* --- Mappa ------------------------------------------------------------ */
.legend {
  position: absolute; left: 12px; bottom: 24px; z-index: 500; max-width: calc(100% - 24px);
  display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 7px 12px; border-radius: 16px;
  background: rgba(255,255,255,.94); box-shadow: var(--shadow); font-size: 13px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.pin { background: none; border: 0; }
.pin i {
  display: block; width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45);
  transition: transform .12s;
}
.pin.is-past i { opacity: .55; }
.pin.is-active i { transform: scale(1.45); box-shadow: 0 0 0 4px rgba(248,157,53,.55), 0 1px 4px rgba(0,0,0,.45); }
.pin.is-hover i { transform: scale(1.3); }
.cluster {
  display: grid; place-items: center; border-radius: 50%;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 13px;
  border: 3px solid rgba(255,255,255,.95); box-shadow: 0 0 0 5px rgba(57,57,57,.18), 0 1px 4px rgba(0,0,0,.4);
}
.leaflet-popup-content-wrapper { border-radius: var(--radius); }
.leaflet-popup-content { margin: 12px 14px; font: 14px/1.4 var(--font); }
.popup-name { font-weight: 650; display: block; }
.popup-sub { display: block; }
.popup-meta { display: block; color: var(--ink-soft); font-size: 13px; }
.popup-open { display: none; margin-top: 8px; font-weight: 600; }
@media (max-width: 860px) { .popup-open { display: block; } }
.leaflet-container a.popup-open { color: var(--accent-ink); }
.leaflet-container { font-family: var(--font); }
/* Tessere un po' desaturate perché i segnaposto risaltino. */
.leaflet-tile-pane { filter: saturate(.55) brightness(1.03); }

/* --- Schermi piccoli -------------------------------------------------- */
@media (max-width: 860px) {
  :root { --topbar-h: 60px; }
  .topbar { padding: 0 12px; gap: 12px; }
  .brand img { height: 26px; }
  .topbar-title { padding-left: 12px; }
  /* Sui telefoni il titolo breve, al massimo su due righe: oltre, viene troncato con "…". */
  .topbar-title h1 {
    font-size: 15px; white-space: normal; line-height: 1.25; overflow-wrap: anywhere;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  }
  .topbar-title h1 .t-long { display: none; }
  .topbar-title h1 .t-short { display: inline; }
  .topbar-title p { display: none; }

  .layout { display: flex; flex-direction: column; height: auto; }
  .map-wrap { order: 0; height: 52vh; height: 52svh; flex: none; position: sticky; top: 0; z-index: 1; }
  .panel { order: 1; border-right: 0; overflow: visible; position: relative; z-index: 2; background: #fff; box-shadow: 0 -6px 16px rgba(0,0,0,.08); border-radius: 14px 14px 0 0; margin-top: -14px; }
  .panel-view { overflow: visible; }
  .detail-head { top: 0; border-radius: 14px 14px 0 0; }
  .legend { bottom: 26px; font-size: 12px; gap: 4px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
