* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
  height: 100dvh; overflow: hidden;
  background: #f5f6f8; color: #1c2733;
  padding-top: env(safe-area-inset-top);
}

/* ── Header ── */
#topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: #0b2a4a; color: #fff;
}
#progress b { font-size: 18px; }
#progress span { font-size: 12px; opacity: .8; }
.spacer { flex: 1; }
.iconbtn {
  border: 0; background: rgba(255,255,255,.12); color: inherit;
  font-size: 17px; line-height: 1;
  min-width: 38px; min-height: 38px; border-radius: 10px; cursor: pointer;
}
#searchbar .iconbtn { background: #e7eaee; color: #1c2733; }
#pending-badge { font-size: 16px; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* ── Search + filtri ── */
#searchbar { display: flex; gap: 8px; padding: 8px 12px 4px; background: #fff; }
#search {
  flex: 1; border: 1px solid #d6dbe1; border-radius: 10px;
  padding: 9px 12px; font-size: 15px; background: #f5f6f8;
}
#filters {
  display: flex; gap: 6px; overflow-x: auto; padding: 6px 12px 10px;
  background: #fff; border-bottom: 1px solid #e3e7ec;
  scrollbar-width: none;
}
#filters::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid #d6dbe1; background: #fff;
  border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer;
  color: #1c2733; white-space: nowrap;
}
.chip span { opacity: .55; font-size: 12px; }
.chip.on { background: #0b2a4a; border-color: #0b2a4a; color: #fff; }
.chip.on span { opacity: .75; }

/* ── Mappa / lista ── */
main { flex: 1; position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }
#map.picking { cursor: crosshair; }
#list {
  position: absolute; inset: 0; overflow-y: auto;
  background: #f5f6f8; z-index: 500; padding: 8px 12px 90px;
}
.row {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 12px; padding: 12px;
  margin-bottom: 8px; box-shadow: 0 1px 2px rgba(16,32,48,.06); cursor: pointer;
}
.row-main { flex: 1; min-width: 0; }
.row-main b { display: block; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main small { color: #68727d; font-size: 12px; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.badge { font-size: 11px; font-weight: 700; border-radius: 6px; padding: 3px 6px; flex: 0 0 auto; }
.badge.task { background: #fff3cd; color: #8a6d00; }
.badge.pos { background: #fde2e2; color: #b02a2a; }
.dist { font-size: 12px; color: #466; flex: 0 0 auto; }
.empty { text-align: center; color: #68727d; padding: 30px 0; }

/* ── FAB ── */
.fab {
  position: absolute; right: 14px; z-index: 600;
  width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: #fff; font-size: 22px; cursor: pointer;
  box-shadow: 0 3px 10px rgba(16,32,48,.25);
  bottom: calc(84px + env(safe-area-inset-bottom));
}
.fab-add { bottom: calc(20px + env(safe-area-inset-bottom)); background: #0b2a4a; color: #fff; }

#pick-banner {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 700; background: #0b2a4a; color: #fff;
  padding: 9px 14px; border-radius: 999px; font-size: 14px;
  display: flex; gap: 10px; align-items: center; white-space: nowrap;
}
#pick-banner button { border: 0; background: rgba(255,255,255,.2); color: #fff; border-radius: 8px; padding: 4px 10px; cursor: pointer; }

/* ── Bottom sheet ── */
#backdrop { position: fixed; inset: 0; background: rgba(8,16,24,.45); z-index: 900; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  background: #fff; border-radius: 18px 18px 0 0;
  max-height: 86dvh; overflow-y: auto;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 24px rgba(8,16,24,.25);
  animation: slideup .18s ease-out;
}
@keyframes slideup { from { transform: translateY(40px); opacity: .5; } }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; }
.sheet-head h3 { font-size: 18px; line-height: 1.25; flex: 1; }
.sheet-head small { color: #68727d; display: block; margin-top: 2px; }
.sheet-head > div { flex: 1; min-width: 0; }
.note-fisse { background: #fff8e1; border-radius: 10px; padding: 8px 10px; font-size: 13px; margin-top: 10px; }
.acts { display: flex; gap: 8px; margin-top: 12px; }
.act {
  flex: 1; text-align: center; border: 1px solid #d6dbe1; border-radius: 12px;
  background: #f5f6f8; color: #0b2a4a; font-size: 15px; font-weight: 600;
  padding: 11px 8px; text-decoration: none; cursor: pointer;
}
.sec { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: #68727d; margin: 16px 0 8px; }
.stati { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stato {
  border: 2px solid var(--c); color: var(--c); background: #fff;
  border-radius: 12px; padding: 12px 8px; font-size: 14px; font-weight: 700; cursor: pointer;
}
.stato.on { background: var(--c); color: #fff; }
#nota {
  width: 100%; min-height: 56px; margin-top: 12px;
  border: 1px solid #d6dbe1; border-radius: 10px; padding: 9px 12px;
  font: inherit; font-size: 14px; resize: vertical; background: #f5f6f8;
}
.mini {
  border: 1px solid #d6dbe1; background: #fff; border-radius: 10px;
  padding: 8px 12px; font-size: 13px; cursor: pointer; margin: 6px 6px 0 0;
}
.tasks-quick { display: flex; flex-wrap: wrap; }
#task-altro { display: flex; gap: 8px; margin-top: 8px; }
#task-altro input { flex: 1; border: 1px solid #d6dbe1; border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.task-row {
  display: flex; align-items: center; gap: 8px;
  background: #fff8e1; border-radius: 10px; padding: 8px 10px; margin-top: 8px; font-size: 13px;
}
.task-row .who { color: #8a6d00; font-size: 11px; }
.task-row button { margin-left: auto; border: 0; background: #2E7D32; color: #fff; border-radius: 8px; padding: 6px 10px; font-size: 12px; cursor: pointer; flex: 0 0 auto; }
.storico-row { padding: 7px 0; border-bottom: 1px solid #eef1f4; font-size: 13px; }
.storico-row small { color: #68727d; }
.meta { margin-top: 14px; font-size: 12px; color: #8a949e; }

/* form aggiungi */
.form label { display: block; font-size: 12px; color: #68727d; margin: 12px 0 4px; }
.form input, .form select {
  width: 100%; border: 1px solid #d6dbe1; border-radius: 10px;
  padding: 10px 12px; font-size: 15px; background: #f5f6f8;
}
.primary {
  width: 100%; margin-top: 16px; border: 0; border-radius: 12px;
  background: #0b2a4a; color: #fff; font-size: 16px; font-weight: 700;
  padding: 13px; cursor: pointer;
}
.primary:disabled { opacity: .5; }
.pos-pick { display: flex; gap: 8px; margin-top: 6px; }
.pos-pick .act { font-size: 13px; padding: 9px 6px; }
.pos-ok { color: #2E7D32; font-weight: 700; }

/* stats */
table.stats { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.stats td, table.stats th { padding: 7px 6px; border-bottom: 1px solid #eef1f4; font-size: 14px; text-align: left; }
table.stats td:last-child, table.stats th:last-child { text-align: right; }

/* ── Toast / gate ── */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(30px + env(safe-area-inset-bottom)); z-index: 2000;
  background: #1c2733; color: #fff; border-radius: 999px;
  padding: 10px 18px; font-size: 14px; max-width: 90vw; text-align: center;
  box-shadow: 0 4px 14px rgba(8,16,24,.3);
}
#gate {
  position: fixed; inset: 0; z-index: 3000; background: #0b2a4a;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.gate-box { background: #fff; border-radius: 18px; padding: 28px 22px; text-align: center; max-width: 340px; }
.gate-box p { margin: 14px 0 20px; color: #444; font-size: 15px; line-height: 1.45; }
.gate-box a {
  display: inline-block; background: #2AABEE; color: #fff; font-weight: 700;
  border-radius: 12px; padding: 12px 22px; text-decoration: none;
}
.hidden { display: none !important; }
