:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #16202d;
  --muted: #5b6878;
  --line: #d9e0ea;
  --primary: #1e6fd9;
  --primary-text: #ffffff;
  --danger: #b42318;
  --ok: #067647;
  --c-none: #6b7280;
  --c-short: #d97706;
  --c-persistent: #7c3aed;
  --band: rgba(30, 111, 217, .16);
  --curve: #1e6fd9;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1420;
    --card: #151e2d;
    --text: #e6edf6;
    --muted: #9aa8bb;
    --line: #26344a;
    --primary: #5aa2ff;
    --primary-text: #08111f;
    --danger: #ff8a80;
    --ok: #6ce9a6;
    --c-none: #9aa3b0;
    --c-short: #fbbf24;
    --c-persistent: #b794f6;
    --band: rgba(90, 162, 255, .2);
    --curve: #5aa2ff;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .25rem; }
p { margin: .4rem 0; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pad { padding: 1rem; }
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--primary); }
.brand strong { color: var(--text); }
.userbox { display: flex; align-items: center; gap: 8px; min-width: 0; }
.userbox #user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 34vw; }

main { max-width: 1200px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
main.narrow { max-width: 460px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.banner {
  background: #fff4d6; color: #5c4200; border: 1px solid #f0d78a;
  border-radius: var(--radius); padding: 10px 14px;
}
@media (prefers-color-scheme: dark) { .banner { background: #3b2f0b; color: #ffe08a; border-color: #6b5314; } }
.status { min-height: 1.4em; }

/* form */
label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); margin-bottom: 12px; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], input[type=search] {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; width: 100%;
}
input:focus-visible, button:focus-visible, a:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
label.check { display: flex; align-items: flex-start; gap: 8px; color: var(--text); margin: 0 0 12px; }
label.check input { margin-top: 4px; }
.btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card);
  color: var(--text); border-radius: 8px; padding: 8px 14px;
}
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; width: 100%; padding: 11px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
.linkbtn { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; text-align: left; text-decoration: underline; }
.links { display: grid; gap: 8px; margin-top: 16px; font-size: .9rem; }
.msg { border-radius: 8px; padding: 8px 10px; font-size: .9rem; background: rgba(180, 35, 24, .1); color: var(--danger); }
.msg.ok { background: rgba(6, 118, 71, .12); color: var(--ok); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 12px 0 16px; }
.tab { background: none; border: 0; padding: 8px 14px; cursor: pointer; font: inherit; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* filtri */
.grid-filters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 12px; }
.grid-filters .span2 { grid-column: span 2; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.row.between { justify-content: space-between; }
fieldset.states { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; }
fieldset.states legend { float: left; margin-right: 12px; padding: 0; color: var(--muted); font-size: .9rem; }
fieldset.states label.check { margin: 0; }

/* kpi */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 1.7rem; font-weight: 700; line-height: 1.15; }
.kpi .v.sm { font-size: 1.05rem; padding: .3rem 0; }
.kpi .l { color: var(--muted); font-size: .85rem; }

/* grafici */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.charts .legend { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: center; font-size: .9rem; color: var(--muted); }
.legend svg { vertical-align: -2px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .empty { padding: 2rem 0; text-align: center; color: var(--muted); }
svg text { fill: var(--muted); font-size: 11px; font-family: inherit; }
svg .grid { stroke: var(--line); stroke-width: 1; }
svg .axis { stroke: var(--muted); stroke-width: 1; fill: none; }
svg .band { fill: var(--band); }
svg .curve { stroke: var(--curve); stroke-width: 2; fill: none; }
svg .vline { stroke: var(--curve); stroke-width: 2; stroke-dasharray: 5 4; }
svg .pt-none { fill: none; stroke: var(--c-none); stroke-width: 1.8; }
svg .pt-short { fill: var(--c-short); stroke: none; }
svg .pt-persistent { fill: var(--c-persistent); stroke: none; }
svg .pt { cursor: pointer; }
svg .pt:hover { stroke: var(--text); stroke-width: 2; }
svg .bar-none { fill: var(--c-none); opacity: .55; }
svg .bar-short { fill: var(--c-short); }
svg .bar-persistent { fill: var(--c-persistent); }
svg .faded { opacity: .35; }
svg text.n { fill: var(--text); font-size: 10px; text-anchor: middle; }
svg text.ttl { fill: var(--muted); font-size: 11px; }

/* confusione */
table.conf { border-collapse: collapse; margin: 8px 0; }
table.conf th, table.conf td { border: 1px solid var(--line); padding: 8px 14px; text-align: center; }
table.conf th { font-weight: 500; color: var(--muted); background: var(--bg); }
table.conf td { font-size: 1.15rem; font-weight: 600; }

/* mappa */
.map { height: 420px; border-radius: 8px; overflow: hidden; background: var(--bg); border: 1px solid var(--line); }
.map.small { height: 220px; margin-top: 10px; }

/* ultima foto (pagina gratuita) */
.latest-photo-img { display: block; width: 100%; max-height: 420px; object-fit: contain; background: var(--bg); border-radius: 8px; margin-top: 8px; }

/* pubblicita' (solo pagina gratuita, vedi ads.js) */
.ad-slot { margin: 14px 0; min-height: 40px; }
.ad-placeholder { border: 1px dashed var(--line); border-radius: 8px; text-align: center; }
.ads-consent-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -2px 10px rgba(0,0,0,.08);
}
.ads-consent-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* tabella */
.tablewrap { overflow-x: auto; margin-top: 8px; }
table#table { border-collapse: collapse; width: 100%; font-size: .9rem; white-space: nowrap; }
#table th, #table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); }
#table th { color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--card); }
#table th[aria-sort] { color: var(--text); }
#table tbody tr { cursor: pointer; }
#table tbody tr:hover { background: var(--bg); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .78rem; border: 1px solid currentColor; }
.badge.none { color: var(--c-none); }
.badge.short { color: var(--c-short); }
.badge.persistent { color: var(--c-persistent); }
.badge.unknown { color: var(--muted); border-style: dashed; }
/* Solo admin: foto scartata dal controllo automatico, con conferma in riga. */
.badge.flagged { color: var(--danger); margin-left: 4px; white-space: nowrap; }
.btn.tiny { padding: 2px 8px; font-size: .78rem; margin-left: 4px; white-space: nowrap; }
.flagged-filter { color: var(--danger); }
.row-thumb { width: 72px; height: 48px; object-fit: cover; border-radius: 4px; vertical-align: middle;
  margin-left: 4px; background: var(--line); transition: transform .15s; position: relative; }
.row-thumb:hover { transform: scale(3); z-index: 5; box-shadow: 0 4px 16px rgba(0,0,0,.35); }
.pager { justify-content: space-between; margin-top: 12px; }

.method p { max-width: 75ch; }

/* dialog */
.dlg { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); max-width: 560px; width: calc(100% - 32px); padding: 0; }
.dlg::backdrop { background: rgba(0, 0, 0, .45); }
.dlg-inner { padding: 16px; }
dl { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 12px 0 0; font-size: .92rem; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }

.foot { text-align: center; padding: 24px 16px 32px; }

@media (max-width: 800px) {
  .charts { grid-template-columns: minmax(0, 1fr); }
  .grid-filters { grid-template-columns: repeat(2, 1fr); }
  .hide-sm { display: none; }
  .map { height: 320px; }
  dl { grid-template-columns: 1fr; }
  dt { margin-top: 6px; }
}

/* pannello admin (bottoni nell'header + elenco utenti bloccati) */
.admin-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.admin-nav .btn { padding: 6px 10px; font-size: 13px; }
.banned-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.banned-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 12px; }
.banned-info p { margin: 2px 0; }

/* eliminazione di una segnalazione (solo admin, dialogo di dettaglio) */
.detail-admin { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn.danger { background: #b42318; border-color: #b42318; color: #fff; font-weight: 600; }
.btn.danger:disabled { opacity: .6; }

/* foto nel dettaglio di un'osservazione */
.detail-photo { margin: 4px 0 12px; }
.detail-photo img { display: block; width: 100%; max-height: 60vh; object-fit: contain; border-radius: 8px; background: #0b1220; min-height: 60px; }
.detail-photo img:not([src]) { display: none; }
.detail-photo figcaption { margin-top: 6px; }
.photo-mark { display: inline-block; vertical-align: middle; color: var(--primary); }

#admin-rebuild-msg { white-space: pre-line; }
#detail-photo-approve { margin-top: 8px; }

/* pagine di contenuto pubbliche (scie.html, progetto.html, faq.html,
   privacy.html) e menu del sito */
.top { flex-wrap: wrap; }
a.brand { text-decoration: none; }
.site-nav { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .92rem; }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--primary); }
main.article { max-width: 780px; display: block; }
.article h1 { font-size: 1.8rem; line-height: 1.2; margin: .4rem 0 .6rem; }
.article h2 { font-size: 1.25rem; margin: 1.8rem 0 .4rem; }
.article h3 { font-size: 1.05rem; margin: 1.2rem 0 .3rem; }
.article p, .article li { line-height: 1.7; }
.article ul, .article ol { padding-left: 1.3rem; }
.article .lead { font-size: 1.1rem; color: var(--muted); }
.article .note { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--primary); border-radius: 8px; padding: 10px 14px; margin: 1rem 0; }
.article .refs li { font-size: .9rem; color: var(--muted); }
.article details { border-bottom: 1px solid var(--line); padding: 10px 0; }
.article summary { font-weight: 600; cursor: pointer; }
.intro { max-width: 1000px; }
.intro h1 { font-size: 1.6rem; line-height: 1.25; }
.intro-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.intro-grid h2 { margin-bottom: .3rem; }
.foot nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; margin-bottom: 8px; }
