:root {
  --primary: #2d6cdf;
  --primary-dark: #1f4fa8;
  --primary-tint: #e6eefb;
  --accent: #b4531a;
  --danger: #c62828;
  --danger-tint: #fdecea;
  --success: #1f8a70;
  --success-tint: #e3f4ee;
  --text: #16202b;
  --muted: #5b6670;
  --border: #dde2e6;
  --bg: #f4f5f2;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(22, 32, 43, .06), 0 4px 16px rgba(22, 32, 43, .06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 18px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, Consolas, monospace; }

/* barra superiore */
.topbar {
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 56px;
  background: var(--text); color: #fff; position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 3px rgba(45, 108, 223, .35); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: #c9d2db; padding: 8px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { color: #fff; background: rgba(255, 255, 255, .08); text-decoration: none; }
.nav a.active { color: #fff; background: rgba(255, 255, 255, .14); }
.who { color: #c9d2db; font-size: 14px; display: flex; align-items: center; gap: 12px; }
.who button { color: #fff; border-color: rgba(255, 255, 255, .3); background: transparent; }

main { max-width: 1240px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }

/* pulsanti e campi */
button, .btn {
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; border-radius: 8px;
  padding: 8px 14px; border: 1px solid var(--border); background: var(--card); color: var(--text);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .btn:hover { border-color: #b8c1ca; text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.danger { color: var(--danger); border-color: #efc3c0; }
button.danger:hover { background: var(--danger-tint); }
button.ghost { border-color: transparent; background: transparent; color: var(--primary); padding: 6px 8px; }
button.icon { padding: 6px 9px; }
input, select, textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.field-hint { font-weight: 400; color: var(--muted); font-size: 13px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search { width: 300px; max-width: 100%; }

/* tabella */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfa; }
tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary-tint); color: var(--primary);
  display: grid; place-items: center; font-weight: 700; flex: none;
}
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
td .actions { flex-wrap: nowrap; }
td .actions button, td .actions .btn { padding: 6px 10px; font-size: 13px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--success-tint); color: var(--success); }
.badge.off { background: var(--danger-tint); color: var(--danger); }
.badge.admin { background: var(--primary-tint); color: var(--primary-dark); }
tr.removed td { color: var(--muted); }
tr.removed .avatar { background: #eceff1; color: var(--muted); }
.removed-banner { background: var(--danger-tint); border: 1px solid #efc3c0; color: #8e1c1c; border-radius: 10px; padding: 12px 14px; margin-top: 14px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* finestre di dialogo */
dialog { border: none; border-radius: 14px; padding: 0; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); max-width: min(560px, 94vw); width: 100%; }
dialog::backdrop { background: rgba(22, 32, 43, .45); }
.dlg-head { padding: 18px 22px 0; display: flex; justify-content: space-between; align-items: center; }
.dlg-body { padding: 18px 22px; display: grid; gap: 14px; }
.dlg-foot { padding: 0 22px 20px; display: flex; justify-content: flex-end; gap: 10px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; font-size: 13px; }
.note { background: #fff8e6; border: 1px solid #f3dfa8; border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 1em; }

/* notifiche */
#toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 380px; font-size: 14px; }
.toast.err { background: var(--danger); }

/* login */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 380px; max-width: 100%; padding: 28px; display: grid; gap: 16px; }
.login-card h1 { display: flex; align-items: center; gap: 10px; }

/* dettaglio utente */
.profile { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.profile .avatar { width: 56px; height: 56px; font-size: 22px; }
.stats { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 4px; }
.stat b { display: block; font-size: 20px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.photo-card { overflow: hidden; cursor: pointer; transition: transform .1s; display: flex; flex-direction: column; }
.photo-card:hover { transform: translateY(-2px); }
.photo-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: #e3e7eb; }
.photo-card .meta { padding: 10px 12px; display: grid; gap: 2px; font-size: 13px; }
.photo-card .desc { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lightbox { max-width: min(1000px, 96vw); }
.lightbox-body { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(240px, 1fr); }
.lightbox-body img { width: 100%; max-height: 78vh; object-fit: contain; background: #111; display: block; }
.lightbox-info { padding: 18px 20px; display: grid; gap: 10px; align-content: start; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
@media (max-width: 760px) { .lightbox-body { grid-template-columns: 1fr; } }

/* mappa */
.map-layout { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 56px); }
.sidebar { background: var(--card); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.filters { padding: 18px; display: grid; gap: 12px; border-bottom: 1px solid var(--border); }
.filters .row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.result-head { padding: 12px 18px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); }
.result-list { overflow-y: auto; flex: 1; }
.result { display: flex; gap: 10px; padding: 10px 18px; cursor: pointer; border-bottom: 1px solid #eef1f3; align-items: center; }
.result:hover, .result.sel { background: var(--primary-tint); }
.result img { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; flex: none; background: #e3e7eb; }
.result .t { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result .s { font-size: 12.5px; color: var(--muted); }
#map { width: 100%; height: 100%; }
.map-wrap { position: relative; min-height: 0; }
.map-msg { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.map-msg .card { max-width: 560px; padding: 24px; display: grid; gap: 10px; }
.map-msg ol { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.pin { width: 40px; height: 40px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .35); overflow: hidden; background: var(--primary); }
.pin img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pin.sel { border-color: var(--accent); transform: scale(1.25); }
.iw { display: grid; gap: 6px; max-width: 260px; font-family: system-ui, sans-serif; }
.iw img { width: 260px; max-width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; }
.iw .t { font-weight: 700; font-size: 14px; }
.iw .s { font-size: 13px; color: var(--muted); }
@media (max-width: 860px) {
  .map-layout { grid-template-columns: 1fr; grid-template-rows: auto 60vh; height: auto; }
  .result-list { max-height: 30vh; }
  .topbar { gap: 12px; padding: 0 12px; }
}

/* contatori nella barra */
.nav a .count { display: inline-block; margin-left: 6px; min-width: 20px; padding: 0 6px; border-radius: 10px; background: #4a5a6a; color: #fff; font-size: 12px; line-height: 20px; text-align: center; }
.nav a .count.hot { background: var(--danger); }
/* tipi e stati */
.badge.type-sky { background: #e6eefb; color: #1f4fa8; }
.badge.type-fire { background: #fde8dc; color: #9a3a0c; }
.badge.type-river { background: #dff3f4; color: #11636b; }
.badge.type-other, .badge.type-none { background: #eceff1; color: #4b5560; }
.badge.st-pending { background: #fff4d6; color: #7a5600; }
.badge.st-confirmed { background: var(--success-tint); color: var(--success); }
.badge.st-rejected { background: #eceff1; color: #5b6670; }
.badge.st-open { background: var(--danger-tint); color: var(--danger); }
.badge.st-acknowledged { background: #fff4d6; color: #7a5600; }
.badge.st-closed { background: #eceff1; color: #5b6670; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.photo-card .badges { display: flex; gap: 6px; flex-wrap: wrap; }

/* pagina di valutazione */
.review-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(340px, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1000px) { .review-layout { grid-template-columns: 1fr; } }
.stage { position: relative; background: #111; border-radius: 12px; overflow: hidden; user-select: none; touch-action: none; }
.stage img { display: block; width: 100%; max-height: 78vh; object-fit: contain; pointer-events: none; }
.stage .layer { position: absolute; cursor: crosshair; }
.box { position: absolute; border: 2px solid; border-radius: 3px; }
.box span { position: absolute; left: -2px; top: -22px; font-size: 12px; font-weight: 700; color: #fff; padding: 1px 6px; border-radius: 3px; white-space: nowrap; }
.box-fire { border-color: #ff5a1f; } .box-fire span { background: #ff5a1f; }
.box-smoke { border-color: #b0b7bf; } .box-smoke span { background: #6b737b; }
.box-water { border-color: #18a0b5; } .box-water span { background: #11636b; }
.box-cloud { border-color: #7aa7ff; } .box-cloud span { background: #2d6cdf; }
.box-gauge { border-color: #ffd23f; } .box-gauge span { background: #9a7a00; }
.box-other { border-color: #e04fd0; } .box-other span { background: #93338a; }
.crosshair { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px dashed rgba(255,255,255,.55); pointer-events: none; }
.form-grid { display: grid; gap: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 0; display: grid; gap: 10px; }
legend { font-weight: 700; font-size: 14px; padding: 0 6px; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.checks label { font-weight: 500; display: flex; gap: 8px; align-items: center; }
.minimap { height: 260px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: #e5e8eb; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; display: flex; gap: 8px; flex-wrap: wrap; }
button.ok { background: var(--success); border-color: var(--success); color: #fff; }
.alert-card { padding: 18px 20px; display: grid; gap: 10px; }
.alert-card.open { border-left: 5px solid var(--danger); }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.rules td { padding: 10px 8px; }
.rules td input[type=number] { width: 70px; }
.rules td input[type=text] { width: 100%; min-width: 180px; }
.rules td select { max-width: 160px; }
tr.pending td { background: #fffbea; }
.pending-banner { background: #fff4d6; border: 1px solid #f0dc9c; color: #6b4b00; border-radius: 10px; padding: 12px 14px; margin-top: 14px; }
