:root {
  --blu: #003cf0;
  --blu-scuro: #002cb3;
  --blu-chiaro: #e6ebfd;
  --giallo: #ffc900;
  --giallo-chiaro: #fff9e6;
  --verde: #157a5c;
  --verde-chiaro: #ebf7f4;
  --rosso: #c8174f;
  --rosso-chiaro: #fde8ef;
  --ink: #000000;
  --muted: #545a66;
  --line: #e4e6eb;
  --surface: #ffffff;
  --soft: #f6f7fa;
  --radius-card: 16px;
  --radius-btn: 8px;
  --focus: #003cf0;
  font-family: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--surface);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-size: 16px; line-height: 1.6; }
a { color: var(--blu); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 4px; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Testata */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 32px; height: 72px; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 10px; min-height: 40px; color: var(--ink); font-weight: 600; font-size: 19px; }
.brand:hover { text-decoration: none; }
.brand svg { width: 30px; height: 30px; padding: 5px; border-radius: 50%; background: var(--blu); fill: var(--giallo); }
.tabs { display: flex; gap: 6px; }
.tabs a { display: flex; align-items: center; gap: 8px; padding: 9px 18px; border-radius: var(--radius-btn); color: var(--ink); font-weight: 500; }
.tabs a:hover { background: var(--soft); text-decoration: none; }
.tabs a.active { background: var(--blu); color: #fff; }
.count { background: var(--giallo); color: var(--ink); border-radius: 999px; padding: 0 8px; font-size: 13px; font-weight: 600; line-height: 20px; }

main { padding: 32px 32px 56px; max-width: 1440px; margin: 0 auto; outline: none; }
.loading, .empty { color: var(--muted); padding: 24px 0; }
.error-box { background: var(--rosso-chiaro); color: #7d0f31; padding: 14px 18px; border-radius: var(--radius-btn); }

/* Intestazione di pagina */
.summary { display: flex; flex-wrap: wrap; gap: 12px 40px; align-items: flex-end; margin-bottom: 28px; }
.summary h1 { margin: 0 auto 0 0; font-size: 40px; line-height: 1.2; font-weight: 500; letter-spacing: -0.5px; }
.summary .fig { display: flex; flex-direction: column; color: var(--muted); font-size: 14px; line-height: 1.3; }
.summary .fig b { color: var(--ink); font-size: 30px; font-weight: 300; font-variant-numeric: tabular-nums; }

/* Elenco + mappa */
.split { display: grid; grid-template-columns: minmax(420px, 1fr) minmax(360px, 1fr); gap: 24px; align-items: start; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-card); overflow: hidden; }
.filters { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; padding: 16px; background: var(--soft); border-bottom: 1px solid var(--line); }
.filters input, .filters select, .form input, .form select, .form textarea, .inline-select {
  border: 1px solid #c9ced8; border-radius: var(--radius-btn); padding: 10px 12px; background: #fff; min-width: 0;
}
.filters input:focus, .filters select:focus, .form input:focus, .form select:focus, .form textarea:focus, .inline-select:focus {
  border-color: var(--blu); outline: 2px solid var(--blu-chiaro); outline-offset: 0;
}
.list { list-style: none; margin: 0; padding: 0; max-height: calc(100vh - 290px); overflow-y: auto; }
.list li { border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; padding: 14px 18px; color: inherit; font-weight: 400; }
.row:hover, .row.hl { background: var(--blu-chiaro); text-decoration: none; }
.row .code { font-weight: 600; font-size: 17px; letter-spacing: .3px; color: var(--blu); font-variant-numeric: tabular-nums; }
.row .who { grid-column: 1; }
.row .where { grid-column: 1; color: var(--muted); font-size: 14px; }
.row .side { grid-column: 2; grid-row: 1 / span 3; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.kw { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-Attivo { color: var(--verde); background: var(--verde-chiaro); }
.st-Sospeso { color: #7a5500; background: var(--giallo-chiaro); }
.st-Cessato { color: #4a5160; background: #eef0f3; }
.bugs { color: var(--rosso); font-size: 13px; font-weight: 600; }

.map { height: calc(100vh - 220px); min-height: 380px; border-radius: var(--radius-card); border: 1px solid var(--line); position: sticky; top: 96px; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--muted); padding: 10px 4px 0; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 2px solid #fff; box-shadow: 0 0 0 1px #9aa1ad; }
.dot.ring { box-shadow: 0 0 0 3px var(--rosso); }
.leaflet-container { font-family: inherit; }
.leaflet-popup-content-wrapper { border-radius: 12px; }
.leaflet-popup-content { font-size: 14px; line-height: 1.5; }
.leaflet-popup-content b { font-size: 16px; color: var(--blu); }
.leaflet-container .leaflet-control-attribution a { color: #1a3fb8; }
.leaflet-touch .leaflet-bar a { width: 34px; height: 34px; line-height: 34px; }

/* Dettaglio */
.back { display: inline-flex; align-items: center; min-height: 32px; margin-bottom: 12px; }
.pod-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px 24px;
  margin-bottom: 24px; padding: 28px 32px; background: var(--blu-chiaro); border-radius: var(--radius-card);
}
.meter { display: inline-block; color: var(--blu); font-weight: 600; font-size: 36px; letter-spacing: 1.5px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.pod-head h1 { margin: 10px 0 2px; font-size: 26px; font-weight: 500; }
.pod-head .addr { color: var(--muted); }
.detail { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr); gap: 24px; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 24px; margin: 0; padding: 8px 24px 16px; }
.facts div { padding: 12px 0; border-bottom: 1px solid var(--line); }
.facts div:nth-last-child(-n+2) { border-bottom: 0; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 2px 0 0; font-weight: 500; font-variant-numeric: tabular-nums; }
.detail .map { height: 100%; min-height: 360px; position: static; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 40px 0 16px; }
.section-head h2 { margin: 0; font-size: 30px; font-weight: 300; }

.btn { border: 0; border-radius: var(--radius-btn); padding: 12px 28px; font-weight: 500; cursor: pointer; line-height: 1.3; }
.btn-primary, .btn-bug { background: var(--blu); color: #fff; }
.btn-primary:hover, .btn-bug:hover { background: var(--blu-scuro); }
.btn-ghost { background: transparent; color: var(--blu); box-shadow: inset 0 0 0 1px var(--blu); }
.btn-ghost:hover { background: var(--blu-chiaro); }
.btn:disabled { opacity: .6; cursor: progress; }

.form { padding: 24px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; margin-bottom: 20px; background: var(--soft); }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; }
.form .wide { grid-column: 1 / -1; }
.form textarea { min-height: 110px; resize: vertical; }
.form .actions { grid-column: 1 / -1; display: flex; gap: 10px; justify-content: flex-end; }
.form .err { grid-column: 1 / -1; color: var(--rosso); margin: 0; }
.field-err { color: var(--rosso); font-size: 13px; font-weight: 400; }
.form .invalid input, .form .invalid select { border-color: var(--rosso); }
#pod-form-slot { margin-bottom: 20px; }
#pod-form-slot .form { margin-bottom: 0; }

.reports { list-style: none; margin: 0; padding: 0; }
.report { padding: 18px 24px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 4px 20px; }
.report:last-child { border-bottom: 0; }
.report h3 { margin: 0; font-size: 18px; font-weight: 600; }
.report .meta { color: var(--muted); font-size: 13px; }
.report p { margin: 6px 0 0; grid-column: 1; max-width: 75ch; }
.report .ctrl { grid-column: 2; grid-row: 1 / span 3; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.prio { font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: #eef0f3; color: #3c4250; }
.prio-Media { background: var(--giallo-chiaro); color: #7a5500; }
.prio-Alta { background: var(--rosso-chiaro); color: #9b1040; }
.prio-Critica { background: var(--rosso); color: #fff; }
.report.done h3 { color: var(--muted); font-weight: 500; }

/* Tabella segnalazioni */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { font-size: 13px; color: var(--muted); font-weight: 500; background: var(--soft); }
td .sub { color: var(--muted); font-size: 13px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; padding: 16px; background: var(--soft); border-bottom: 1px solid var(--line); }

#toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: #fff; padding: 12px 22px; border-radius: var(--radius-btn); transition: .2s; z-index: 2000; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .split, .detail { grid-template-columns: 1fr; }
  .map { position: static; height: 360px; }
  .list { max-height: none; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters input { grid-column: 1 / -1; }
  .summary h1 { font-size: 32px; }
}
@media (max-width: 560px) {
  .topbar { padding: 0 14px; height: 64px; }
  .brand span { font-size: 16px; }
  .tabs a { padding: 8px 12px; }
  main { padding: 20px 14px 40px; }
  .facts, .form { grid-template-columns: 1fr; }
  .facts div:nth-last-child(2) { border-bottom: 1px solid var(--line); }
  .pod-head { padding: 20px; }
  .meter { font-size: 26px; letter-spacing: 1px; }
  .summary .fig b { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
