: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;

  --c-chiuso: #393939;
  --c-aperto: #f08a1c;
  --c-ibrido: #2d7a9a;

  --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 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;
  transition: background-color .15s, border-color .15s;
}
.btn-accent { background: var(--accent); color: #2a1600; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-accent:disabled { opacity: .6; cursor: progress; }
.btn-ghost { background: transparent; border-color: var(--line-strong); }
.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); }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 50%; background: transparent; cursor: pointer; color: var(--ink-soft);
}
.icon-btn:hover { background: var(--bg-soft); color: var(--ink); }

/* --- Struttura -------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(340px, 410px) 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); }

.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; }
:where(textarea) { resize: vertical; min-height: 84px; }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--ink-mute); box-shadow: 0 0 0 3px rgba(248,157,53,.35); }
.filters-body .btn-link { justify-self: start; 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); }
.result {
  display: grid; grid-template-columns: 12px 1fr auto; gap: 4px 12px; align-items: baseline;
  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 .dot { align-self: center; grid-row: 1 / span 2; }
.result-name { font-weight: 600; line-height: 1.3; }
.result-meta { grid-column: 2 / 4; font-size: 13px; color: var(--ink-soft); }
.result-cap { font-size: 12px; color: var(--ink-mute); white-space: nowrap; }
.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: 14px; 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; }
.dot-chiuso { background: var(--c-chiuso); }
.dot-aperto { background: var(--c-aperto); }
.dot-ibrido { background: var(--c-ibrido); }
.dot-altro { background: #999; }

/* --- Scheda del luogo -------------------------------------------------- */
.detail:focus { outline: none; }
.detail-head { position: sticky; top: 0; z-index: 2; background: #fff; padding: 12px 16px 0; }
.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-body { padding: 8px 20px 32px; }
.detail h2 { margin: 6px 0 4px; font-size: 22px; line-height: 1.25; }
.detail-address { margin: 0; color: var(--ink-soft); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 0; padding: 0; list-style: none; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--bg-soft); font-size: 13px; }
.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 section { margin-top: 22px; }
.detail h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent-ink); }
.detail dl { margin: 0; display: grid; grid-template-columns: minmax(110px, 38%) 1fr; border-top: 1px solid var(--line); }
.detail dt, .detail dd { margin: 0; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.detail dt { color: var(--ink-soft); padding-right: 12px; }
.detail dd { white-space: pre-line; overflow-wrap: anywhere; }
.detail .prose { white-space: pre-line; font-size: 14px; margin: 0; overflow-wrap: anywhere; }
.detail-foot { margin-top: 28px; padding: 14px; background: var(--bg-soft); border-radius: var(--radius); font-size: 14px; }
.stars { letter-spacing: 2px; color: var(--accent); }
.stars .off { color: var(--line-strong); }

/* --- Mappa ------------------------------------------------------------ */
.legend {
  position: absolute; left: 12px; bottom: 24px; z-index: 500;
  display: flex; gap: 14px; padding: 7px 12px; border-radius: 999px;
  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-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-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); }

/* --- Modulo ----------------------------------------------------------- */
.form-dialog {
  width: min(760px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 0; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
  color: var(--ink);
}
.form-dialog[open] { display: flex; flex-direction: column; }
.form-dialog::backdrop { background: rgba(30,30,30,.55); }
.form-dialog form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.form-head { display: flex; gap: 16px; align-items: flex-start; padding: 20px 20px 14px 24px; border-bottom: 1px solid var(--line); }
.form-head h2 { margin: 0 0 4px; font-size: 21px; }
.form-head p { margin: 0; color: var(--ink-soft); font-size: 14px; }
.form-body { overflow-y: auto; padding: 8px 24px 20px; flex: 1; min-height: 0; }
.form-body fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.form-body > fieldset { margin-top: 16px; }
.form-body > fieldset > legend { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--accent-ink); margin-bottom: 4px; }
.field { display: block; margin-top: 14px; }
.field > label, .field > .label, .field > legend { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; padding: 0; }
.field small { font-weight: 400; color: var(--ink-mute); }
.field .hint { margin: -2px 0 6px; font-size: 13px; color: var(--ink-soft); }
.req { color: var(--danger); }
.grid-2, .grid-3 { display: grid; gap: 0 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1.4fr 1fr; }
.pick-map { height: 220px; border-radius: 8px; border: 1px solid var(--line-strong); }
.field-error { display: block; margin-top: 4px; color: var(--danger); font-size: 13px; font-weight: 600; }
[aria-invalid="true"] { border-color: var(--danger) !important; }
.hp { position: absolute !important; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.update-note { margin-top: 16px; padding: 12px 14px; background: var(--bg-sel); border-radius: 8px; font-size: 14px; }
.form-foot { display: flex; align-items: center; gap: 12px; padding: 14px 20px 16px 24px; border-top: 1px solid var(--line); background: #fff; }
.form-status { flex: 1; margin: 0; font-size: 14px; color: var(--ink-soft); }
.form-status.is-error { color: var(--danger); font-weight: 600; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.form-done { padding: 40px 28px 32px; text-align: center; }
.form-done:focus { outline: none; }
.form-done svg { color: var(--ok); }
.form-done h2 { margin: 10px 0 6px; }
.form-done p { max-width: 460px; margin: 0 auto 22px; color: var(--ink-soft); }
.form-done .form-actions { justify-content: center; }

/* --- 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; }
  .topbar-title h1 { font-size: 15px; white-space: normal; line-height: 1.25; }
  .topbar-title p { display: none; }
  .topbar .btn { padding: 0 12px; min-height: 38px; }
  .topbar .btn span { display: none; }
  .topbar .btn::after { content: "Proponi"; }

  .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: 10px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .form-head { padding: 14px 12px 12px 16px; }
  .form-body { padding: 4px 16px 20px; }
  .form-foot { flex-direction: column; align-items: stretch; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .form-actions .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
