/* ============================================================
   Giro Citofoni — foglio di stile principale
   ============================================================ */

/* ---------- variabili ---------- */
:root {
  --bg:        #EEF2EF;
  --surface:   #FFFFFF;
  --surface2:  #E3EAE6;
  --ink:       #12201C;
  --muted:     #586A63;
  --line:      #CBD6D0;
  --accent:    #0F6B5C;
  --accent-dk: #0A5347;
  --accent-ink:#FFFFFF;
  --danger:    #B3261E;
  --shadow:    0 -8px 30px rgba(10,30,24,.2);
  --shadow-up: 0 4px 24px rgba(10,30,24,.14);
  --radius:    12px;
  --f-display: 'Bricolage Grotesque','Segoe UI',system-ui,sans-serif;
  --f-body:    'Instrument Sans',system-ui,-apple-system,'Segoe UI',sans-serif;
  --f-mono:    'JetBrains Mono',ui-monospace,Menlo,Consolas,monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0D1412;
    --surface:   #16211E;
    --surface2:  #1F2D29;
    --ink:       #E7EFEB;
    --muted:     #97A9A2;
    --line:      #2C3C37;
    --accent:    #3FC9AE;
    --accent-dk: #2db89e;
    --accent-ink:#06211B;
    --danger:    #FF8A80;
    --shadow:    0 -8px 30px rgba(0,0,0,.55);
    --shadow-up: 0 4px 24px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 var(--f-body);
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- intestazione ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: calc(8px + env(safe-area-inset-top,0px))
           max(16px,env(safe-area-inset-right,0px))
           8px
           max(16px,env(safe-area-inset-left,0px));
  z-index: 1300;
}
.brand { font: 700 19px/1 var(--f-display); letter-spacing: -.01em; white-space: nowrap; }
.brand span { color: var(--accent); }

/* avatar utente in header */
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  font: 700 13px/1 var(--f-mono);
  color: #fff; flex-shrink: 0;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 2px var(--line);
  cursor: pointer; border: 0; background: var(--accent);
}

/* ---------- tab ---------- */
.tabs { display: flex; background: var(--surface2); border-radius: 10px; padding: 3px; gap: 2px; }
.tabs button {
  border: 0; background: transparent;
  padding: 7px 14px; border-radius: 8px;
  font-weight: 600; color: var(--muted); min-height: 36px;
}
.tabs button[aria-selected="true"] {
  background: var(--surface); color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}
.tabs .n { font: 600 12px var(--f-mono); margin-left: 4px; color: var(--muted); }

/* ---------- mappa ---------- */
#view-map { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--surface2); }

.float {
  position: absolute; z-index: 1100;
  display: flex; flex-direction: column; gap: 8px;
  top: 12px; right: max(12px,env(safe-area-inset-right,0px));
  align-items: flex-end;
}

/* ---------- fab ---------- */
.fab {
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 0 18px;
  min-height: 48px; font-weight: 600;
  box-shadow: 0 3px 14px rgba(0,0,0,.28);
  transition: background .15s, color .15s;
}
.fab.primary { background: var(--accent); color: var(--accent-ink); font-size: 16px; }
.fab.primary:active { background: var(--accent-dk); }
.fab.sec { background: var(--surface); color: var(--ink); min-height: 40px; padding: 0 14px; font-size: 14px; }
.fab.sec.on { background: var(--accent); color: var(--accent-ink); }
.fab .dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.fab.live .dot { animation: pulse 1.6s ease-out infinite; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0   rgba(255,255,255,.7); }
  100% { box-shadow: 0 0 0 10px rgba(255,255,255,0); }
}
@media (prefers-reduced-motion: reduce) { .fab.live .dot, .spin { animation: none !important; } }

/* ---------- hint ---------- */
.hint {
  position: absolute; z-index: 1100;
  left:  max(12px,env(safe-area-inset-left,0px));
  right: max(12px,env(safe-area-inset-right,0px));
  bottom: calc(14px + env(safe-area-inset-bottom,0px));
  max-width: 460px; margin-inline: auto;
  background: var(--surface); border-radius: 14px;
  padding: 14px 16px; box-shadow: var(--shadow-up); font-size: 14px;
}
.hint b { font-family: var(--f-display); font-size: 16px; display: block; margin-bottom: 2px; }

/* ---------- targhetta civica ---------- */
.plate {
  display: inline-grid; place-items: center;
  min-width: 34px; height: 26px; padding: 0 6px;
  border-radius: 5px; background: var(--c,#6B7B76);
  color: #fff; font: 700 13px/1 var(--f-mono);
  border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.4);
  white-space: nowrap;
}
/* Plate bianca (stato "new" / da visitare): testo scuro + bordo grigio */
.plate[style*="--c:#FFFFFF"],
.plate[style*="--c: #FFFFFF"] {
  color: #12201C;
  border-color: #8FA89F;
}
.plate.big { min-width: 58px; height: 46px; font-size: 22px; border-radius: 8px; border-width: 3px; }
.pin { background: none; border: 0; }
.pin .plate { width: 100%; }
.pin.active .plate { outline: 3px solid var(--accent); outline-offset: 2px; }
.plate.ghost { background: #fff; color: #12201C; border-color: #0F6B5C; }
.pin.zone .plate { min-width: 28px; height: 22px; font-size: 11px; background: #fff; color: #12201C; border: 1px solid #5F706A; box-shadow: none; }
.target { width: 26px; height: 26px; border-radius: 50%; border: 3px solid #fff; background: rgba(15,107,92,.35); box-shadow: 0 0 0 2px #0F6B5C, 0 2px 8px rgba(0,0,0,.4); }

/* ---------- pallino base (marker fuori viewport / compresso) ---------- */
.pin-dot-wrap { background: none; border: 0; }
.pin-dot {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.45);
  transition: transform .15s ease, opacity .15s ease;
}

/* ---------- animazione pop: plate che entra in viewport ---------- */
@keyframes pin-pop {
  0%   { transform: scale(.4) translateY(4px); opacity: 0; }
  65%  { transform: scale(1.12) translateY(-2px); opacity: 1; }
  100% { transform: scale(1)   translateY(0);    opacity: 1; }
}
.pin > div > .plate {
  animation: pin-pop .22s cubic-bezier(.34,1.56,.64,1) both;
}
/* Il badge autore segue la plate senza animazione propria */
.pin > div > .pin-author { animation: pin-pop .22s cubic-bezier(.34,1.56,.64,1) both; }

/* badge autore sul civico (iniziale utente) */
.pin-author {
  position: absolute; bottom: -4px; right: -4px;
  width: 14px; height: 14px; border-radius: 50%;
  font: 700 8px/14px var(--f-mono);
  color: #fff; text-align: center;
  border: 1.5px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}

/* ---------- cassetto ---------- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 1200; margin-inline: auto; max-width: 640px;
  max-height: 74dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  padding: 24px
           max(16px,env(safe-area-inset-right,0px))
           calc(20px + env(safe-area-inset-bottom,0px))
           max(16px,env(safe-area-inset-left,0px));
}
.sheet::before {
  content: ""; position: absolute; top: 8px; left: 50%;
  width: 42px; height: 4px; margin-left: -21px;
  border-radius: 2px; background: var(--line);
}

/* ---------- etichette e bottoni ---------- */
.lbl {
  font: 600 12px var(--f-body); text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); margin: 18px 0 8px;
  display: flex; align-items: center; gap: 8px;
}
.lbl .n { font-family: var(--f-mono); background: var(--surface2); border-radius: 99px; padding: 1px 8px; letter-spacing: 0; }

.btn {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius); padding: 0 16px;
  min-height: 44px; font-weight: 600;
  transition: background .12s;
}
.btn:active { background: var(--surface2); }
.btn.ghost { background: var(--surface2); border-color: transparent; }
.btn.add { width: 100%; margin-top: 10px; border-style: dashed; color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.primary-full {
  width: 100%; background: var(--accent); color: var(--accent-ink);
  border-color: transparent; font-size: 16px; min-height: 50px;
  border-radius: var(--radius);
}
.btn.primary-full:active { background: var(--accent-dk); }

/* ---------- scheda lookup ---------- */
.lk-head, .h-head { display: flex; align-items: center; gap: 12px; }
.lk-head > div:first-child { flex: 1; min-width: 0; }
.lk-title { font: 700 20px/1.1 var(--f-display); }
.lk-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.lk-msg { display: flex; align-items: center; gap: 10px; padding: 16px 0; color: var(--muted); }
.lk-warn { margin: 12px 0 4px; padding: 10px 12px; border-radius: 10px; background: var(--surface2); font-size: 14px; }

.spin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

.cands { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.cand {
  display: flex; align-items: center; gap: 12px;
  text-align: left; width: 100%;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius); padding: 10px 12px; min-height: 56px;
  transition: background .12s;
}
.cand:active { background: var(--surface2); }
.c-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.c-via { font: 600 16px/1.2 var(--f-display); overflow-wrap: anywhere; }
.c-sub { font-size: 13px; color: var(--muted); }
.c-d { font: 500 13px var(--f-mono); color: var(--muted); }
.lk-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.lk-actions .btn { flex: 1; min-width: 140px; }

/* ---------- scheda civico ---------- */
.h-title { flex: 1; min-width: 0; }
.h-via { font: 700 21px/1.15 var(--f-display); overflow-wrap: anywhere; }
.h-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* badge autore nella scheda */
.h-author {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted); margin-top: 6px;
}
.h-author .dot { width: 10px; height: 10px; border-radius: 50%; }

/* conflitto */
.conflict-banner {
  background: #FFF3CD; color: #856404; border: 1px solid #FFE08A;
  border-radius: var(--radius); padding: 10px 12px;
  font-size: 13px; margin-bottom: 12px;
}
.conflict-banner b { display: block; margin-bottom: 4px; }

.grid-addr { display: grid; grid-template-columns: 1fr 92px; gap: 10px; margin-top: 14px; }
.grid-addr .com { grid-column: 1 / -1; }
.fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fld > span { font-size: 12px; font-weight: 600; color: var(--muted); }

input, textarea {
  font: inherit; font-size: 16px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
  width: 100%; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 72px; }
input:focus, textarea:focus {
  border-color: var(--accent); outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid var(--c); background: transparent;
  color: var(--ink); border-radius: 999px;
  padding: 0 14px; min-height: 40px;
  font-weight: 600; font-size: 14px;
  transition: background .12s, color .12s;
}
.chip.on { background: var(--c); color: #fff; }
/* Chip bianco (stato "new"): bordo grigio visibile invece di bianco su bianco */
.chip[style*="--c:#FFFFFF"] { border-color: var(--line); }
.chip[style*="--c:#FFFFFF"].on {
  background: transparent;
  border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 1px;
  color: var(--ink);
}

.names { display: flex; flex-direction: column; gap: 12px; }
.name {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.name input, .name textarea { background: var(--surface); }
.name .r1 { display: grid; grid-template-columns: 70px 1fr 44px; gap: 8px; }
.name textarea { min-height: 60px; }
.x { border: 0; background: var(--surface2); border-radius: 10px; font-size: 22px; line-height: 1; color: var(--muted); }

.h-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); }
.stamp { font: 500 12px var(--f-mono); color: var(--muted); }
.danger-btn { color: var(--danger) !important; border-color: color-mix(in srgb, var(--danger) 35%, transparent) !important; font-size: 13px; padding: 6px 12px; }

/* ---------- foto citofono ---------- */
.foto-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.foto-empty {
  font-size: 13px; color: var(--muted);
  margin-bottom: 10px;
}
.foto-thumb {
  position: relative; border-radius: 8px; overflow: hidden;
  aspect-ratio: 1; background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
}
.foto-thumb img {
  width: 100%; height: 100%; object-fit: cover;
  display: block;
}
.foto-del {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.55); color: #fff;
  font-size: 15px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.foto-loading {
  opacity: .6;
}
.foto-upload-btn {
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; margin-bottom: 4px;
}

/* ---------- elenco ---------- */
#view-list {
  overflow: auto;
  padding: 14px
           max(16px,env(safe-area-inset-right,0px))
           calc(24px + env(safe-area-inset-bottom,0px))
           max(16px,env(safe-area-inset-left,0px));
}
.list-wrap { max-width: 720px; margin-inline: auto; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.filters .chip { min-height: 34px; font-size: 13px; padding: 0 12px; }

.rows { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px;
  transition: background .12s;
}
.row:active { background: var(--surface2); }
.row .main { flex: 1; min-width: 0; }
.row .via { font: 600 16px/1.2 var(--f-display); overflow-wrap: anywhere; }
.row .meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.row .st { font-size: 12px; font-weight: 600; color: var(--c); white-space: nowrap; }
.row .row-author { width: 22px; height: 22px; border-radius: 50%; font: 700 9px/22px var(--f-mono); color: #fff; text-align: center; flex-shrink: 0; }

.empty { padding: 36px 8px; text-align: center; color: var(--muted); }

.backup { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }
.backup p { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }
.backup .btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- sync status bar ---------- */
.sync-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 2000;
  background: var(--accent); color: var(--accent-ink);
  font-size: 13px; font-weight: 600; text-align: center;
  padding: 6px 16px; transform: translateY(-100%);
  transition: transform .25s;
}
.sync-bar.show { transform: translateY(0); }
.sync-bar.error { background: var(--danger); }
.sync-bar.offline { background: #A86B00; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom,0px));
  z-index: 1500; background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: min(92vw,420px); box-shadow: 0 4px 20px rgba(0,0,0,.35);
}

/* ---------- pagina login / registrazione ---------- */
.auth-page {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px 16px;
  /* background tolto: lo gestisce il body con la canvas */
}
.auth-card {
  width: 100%; max-width: 420px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border: 1px solid var(--line);
  border-radius: 20px; padding: 32px 28px;
  box-shadow: var(--shadow-up);
}
.auth-logo {
  font: 700 28px/1 var(--f-display); color: var(--accent);
  text-align: center; margin-bottom: 6px; letter-spacing: -.02em;
}
.auth-subtitle {
  text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 28px;
}
.auth-fields { display: flex; flex-direction: column; gap: 14px; margin-bottom: 20px; }
.auth-fields label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.auth-fields input { font-size: 16px; }
.auth-link { text-align: center; font-size: 14px; color: var(--muted); margin-top: 16px; }
.auth-link a { color: var(--accent); font-weight: 600; text-decoration: none; }
.auth-link a:hover { text-decoration: underline; }
.auth-error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px;
}

/* colori avatar utente */
.color-picker { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.color-swatch {
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent; transition: transform .12s, border-color .12s;
}
.color-swatch.selected { border-color: var(--ink); transform: scale(1.15); }

/* ---------- menu utente ---------- */
.user-menu {
  position: fixed; top: 0; right: 0; z-index: 1400;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 0 0 0 16px; box-shadow: var(--shadow-up);
  padding: 16px; min-width: 200px;
  transform: translateY(-120%); transition: transform .2s;
}
.user-menu.open { transform: translateY(0); }
.user-menu-name { font: 700 16px/1.2 var(--f-display); margin-bottom: 4px; }
.user-menu-role { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.user-menu .btn { width: 100%; text-align: left; }

/* ---------- Leaflet override ---------- */
.leaflet-container { font-family: var(--f-body); }
