:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3eee5;
  --ink: #1f2a2e;
  --muted: #5d6b70;
  --line: #e4ddd1;
  --sea: #0e5a73;
  --sea-soft: #e3f0f3;
  --olive: #5f6f2f;
  --olive-soft: #edf1df;
  --terra: #b8572f;
  --terra-soft: #f8e9e1;
  --amber: #a7720f;
  --amber-soft: #f8efd9;
  --red: #a33a2c;
  --red-soft: #f6e2df;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 42, 46, .06), 0 6px 18px rgba(31, 42, 46, .06);
  --display: "Fraunces", Georgia, serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--body); }
a { color: var(--sea); }
img { max-width: 100%; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; line-height: 1.15; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; font-family: var(--body); font-weight: 700; letter-spacing: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- header ---------- */
.topbar { position: sticky; top: 0; z-index: 1000; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px; background: rgba(250, 247, 242, .94); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-family: var(--display);
  font-size: 1.1rem; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; fill: var(--sea); }
.brand .door { fill: var(--bg); }
.nav { display: flex; gap: 2px; overflow-x: auto; }
.nav a { padding: 7px 10px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .9rem; white-space: nowrap; }
.nav a.active { background: var(--sea); color: #fff; }
@media (max-width: 560px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 6px; padding: 8px 12px; }
  .nav { justify-content: space-between; }
}

.demo-banner { background: var(--amber-soft); color: #6a4a08; padding: 8px 16px; font-size: .88rem; text-align: center;
  border-bottom: 1px solid #ecdcb4; }

main { max-width: 1180px; margin: 0 auto; padding: 18px 16px 40px; min-height: 60vh; }
.footer { max-width: 1180px; margin: 0 auto; padding: 18px 16px 40px; color: var(--muted); font-size: .8rem; border-top: 1px solid var(--line); }

/* ---------- hero / filtri ---------- */
.hero { margin-bottom: 14px; }
.hero p { margin: 0; color: var(--muted); max-width: 680px; }
.filters { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  box-shadow: var(--shadow); margin-bottom: 14px; }
.filters .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 120px; flex: 1 1 140px; }
.field label { font-size: .75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
select, input[type=number], input[type=text], input[type=search] { width: 100%; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; min-height: 42px; }
select:focus, input:focus { outline: 2px solid var(--sea); outline-offset: 1px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; font: inherit; font-weight: 600; font-size: .88rem; color: var(--muted);
  padding: 7px 13px; border-radius: 999px; cursor: pointer; min-height: 36px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 12px; }
.count { font-weight: 600; }
.btn.more-filters { display: none; }
@media (max-width: 640px) {
  .filters .field.opt { display: none; }
  .filters.open .field.opt { display: flex; }
  .btn.more-filters { display: inline-flex; }
}

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; padding: 9px 14px; border-radius: 10px;
  cursor: pointer; text-decoration: none; min-height: 42px; }
.btn.primary { background: var(--sea); border-color: var(--sea); color: #fff; }
.btn.ghost { background: none; }
.btn:hover { filter: brightness(.97); }

/* ---------- cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); display: flex; flex-direction: column; text-decoration: none; color: inherit; transition: transform .12s; }
.card:hover { transform: translateY(-2px); }
.thumb { position: relative; aspect-ratio: 16 / 10; background: linear-gradient(135deg, var(--sea-soft), var(--surface-2)); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--sea); opacity: .55; }
.thumb .ph svg { width: 54px; height: 54px; fill: currentColor; }
.thumb .tags { position: absolute; left: 8px; top: 8px; display: flex; gap: 5px; flex-wrap: wrap; }
.score { position: absolute; right: 8px; top: 8px; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; color: #fff; font-size: 1.05rem; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.score small { display: block; font-size: .55rem; font-weight: 600; margin-top: -4px; opacity: .9; }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--surface);
  color: var(--ink); letter-spacing: .02em; }
.tag.asta { background: var(--terra); color: #fff; }
.tag.privato { background: var(--olive); color: #fff; }
.tag.drop { background: var(--olive-soft); color: var(--olive); }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-title { font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.price { font-family: var(--display); font-size: 1.35rem; font-weight: 700; }
.specs { color: var(--muted); font-size: .86rem; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: auto; padding-top: 8px; border-top: 1px dashed var(--line); }
.kpi span { display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.kpi b { font-size: .95rem; }
.pos { color: var(--olive); }
.neg { color: var(--red); }

.rec-Ottima { background: #3f6b2a; }
.rec-Buona { background: #6f8a2b; }
.rec-Da-valutare { background: var(--amber); }
.rec-Debole { background: #b06a33; }
.rec-Sconsigliata { background: var(--red); }

#map { height: 62vh; min-height: 360px; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); z-index: 1; }
.leaflet-popup-content { font: 13px/1.4 var(--body); }
.pin { width: 30px; height: 30px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 11px;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); }

.empty { padding: 40px 16px; text-align: center; color: var(--muted); background: var(--surface); border-radius: var(--radius); border: 1px dashed var(--line); }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- scheda immobile ---------- */
.back { display: inline-block; margin-bottom: 10px; text-decoration: none; font-weight: 600; }
.detail-head { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 18px; align-items: start; margin-bottom: 18px; }
@media (max-width: 820px) { .detail-head { grid-template-columns: 1fr; } }
.detail-photo { border-radius: var(--radius); overflow: hidden; }
.detail-photo .thumb { aspect-ratio: 16 / 10; }
.head-info .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.head-info .tag { background: var(--surface-2); }
.head-info .tag.asta { background: var(--terra); }
.verdict { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); margin: 12px 0; }
.verdict .score { position: static; width: 56px; height: 56px; font-size: 1.2rem; flex: none; }
.links { display: flex; gap: 8px; flex-wrap: wrap; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile span { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.tile b { display: block; font-family: var(--display); font-size: 1.35rem; margin-top: 2px; }
.tile small { color: var(--muted); font-size: .78rem; }
.tile.hl { background: var(--sea); border-color: var(--sea); color: #fff; }
.tile.hl span, .tile.hl small { color: rgba(255,255,255,.8); }

.sections { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 820px) { .sections { grid-template-columns: minmax(0, 1fr); } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.panel.wide { grid-column: 1 / -1; }
.panel h2 { display: flex; align-items: center; gap: 8px; }
.step { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--sea-soft);
  color: var(--sea); font: 700 .8rem var(--body); flex: none; }
.lines { width: 100%; border-collapse: collapse; font-size: .92rem; }
.lines td { padding: 6px 0; border-bottom: 1px solid var(--surface-2); vertical-align: top; }
.lines td:last-child { text-align: right; font-weight: 600; white-space: nowrap; padding-left: 10px; }
.lines tr.total td { border-top: 2px solid var(--ink); border-bottom: 0; font-weight: 700; padding-top: 8px; }
.note { font-size: .82rem; color: var(--muted); margin: 8px 0 0; }
.src { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--olive-soft); color: var(--olive); }
.src.warn { background: var(--amber-soft); color: var(--amber); }
.flags { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.flags li { background: var(--amber-soft); border-radius: 10px; padding: 9px 12px; font-size: .88rem; }

.scen { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.scen div { background: var(--surface-2); border-radius: 10px; padding: 9px; text-align: center; }
.scen span { display: block; font-size: .7rem; color: var(--muted); text-transform: uppercase; font-weight: 600; }
.scen b { display: block; font-size: 1rem; }
.scen .mid { background: var(--sea-soft); }

.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--sea); }

.calc { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.calc .check { display: flex; align-items: center; gap: 8px; font-size: .9rem; padding-top: 18px; }
.calc .check input { width: 20px; height: 20px; }
.calc-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.mgr { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--surface-2); }
.mgr:last-child { border-bottom: 0; }
.mgr .badge { font-size: .7rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--sea-soft); color: var(--sea); margin-left: 6px; }

.checklist { counter-reset: s; list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.checklist li { counter-increment: s; position: relative; padding: 2px 0 2px 34px; }
.checklist li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 24px; height: 24px; border-radius: 50%;
  background: var(--sea-soft); color: var(--sea); display: grid; place-items: center; font-weight: 700; font-size: .78rem; }

/* ---------- guida ---------- */
.guide { display: grid; gap: 14px; max-width: 860px; }
.guide .panel ul { margin: 6px 0 0; padding-left: 20px; }
.guide .panel li { margin: 4px 0; }

.city-tabs { margin-bottom: 14px; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.data td .src { white-space: nowrap; }
table.data td { padding: 8px 4px; border-bottom: 1px solid var(--surface-2); }
.table-wrap { overflow-x: auto; }

@media (max-width: 560px) { .hide-sm { display: none; } table.data { font-size: .82rem; } table.data th, table.data td { padding-left: 2px; padding-right: 2px; } .panel { padding: 14px 12px; } }
