:root {
  --bg: #0b1626;
  --bg2: #0f1b2d;
  --card: #17273f;
  --card2: #1d3252;
  --line: #223a5a;
  --text: #e8f0fb;
  --muted: #8ea2bf;
  --accent: #2dd4bf;
  --on-accent: #06302b;
  --danger: #f87171;
  --warn: #fbbf24;
  --ring1: #1f3a5c;
  --ring2: #2a5a8a;
  --tabh: 64px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #eef3f8;
    --bg2: #e4ecf4;
    --card: #ffffff;
    --card2: #eef3f8;
    --line: #d5e0ec;
    --text: #0f1b2d;
    --muted: #5d7089;
    --accent: #14b8a6;
    --on-accent: #04302b;
    --danger: #dc2626;
    --warn: #b45309;
    --ring1: #cfdcea;
    --ring2: #a9c3dc;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #eef3f8;
  --bg2: #e4ecf4;
  --card: #ffffff;
  --card2: #eef3f8;
  --line: #d5e0ec;
  --text: #0f1b2d;
  --muted: #5d7089;
  --accent: #14b8a6;
  --on-accent: #04302b;
  --danger: #dc2626;
  --warn: #b45309;
  --ring1: #cfdcea;
  --ring2: #a9c3dc;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.ico {
  width: 24px; height: 24px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- layout ---------- */
#app {
  height: 100dvh;
  padding: calc(var(--sat) + 12px) 20px calc(var(--tabh) + var(--sab) + 12px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.view { display: none; max-width: 520px; margin: 0 auto; min-height: 100%; }
.view.active { display: flex; flex-direction: column; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-head { padding: 14px 0 16px; }
.page-head h2 { font-size: 26px; font-weight: 600; }

/* ---------- tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabh) + var(--sab));
  padding-bottom: var(--sab);
  display: flex; justify-content: space-around;
  background: var(--bg2);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; color: var(--muted); transition: color .15s;
}
.tab.active { color: var(--accent); }

/* ---------- home ---------- */
.hero { padding: 18px 0 0; }
.eyebrow { font-size: 14px; color: var(--muted); }
.hero h1 { font-size: 30px; line-height: 1.15; font-weight: 600; margin-top: 4px; letter-spacing: -.01em; }

.radar {
  position: relative; width: min(78vw, 300px); aspect-ratio: 1;
  margin: auto; margin-block: 28px 8px;
  display: grid; place-items: center;
}
.ring { position: absolute; border-radius: 50%; border: 1px solid var(--ring1); }
.ring.r3 { inset: 0; }
.ring.r2 { inset: 13%; border-color: var(--ring2); }
.orb {
  width: 56%; aspect-ratio: 1; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font-size: 17px; font-weight: 600;
  box-shadow: 0 10px 40px -10px var(--accent);
  transition: transform .12s ease;
  position: relative; z-index: 1;
}
.orb .ico { width: 44px; height: 44px; stroke-width: 1.8; }
.orb:active { transform: scale(.94); }
.orb::after {
  content: ""; position: absolute; inset: -2px; border-radius: 50%;
  border: 2px solid var(--accent); opacity: 0; animation: idle 3.2s ease-out infinite;
}
@keyframes idle { 0% { transform: scale(1); opacity: .55; } 100% { transform: scale(1.5); opacity: 0; } }
.radar.busy .orb::after { animation-duration: 1s; }
.radar.busy .ring.r2 { animation: spin 1.4s linear infinite; border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
.radar.done .orb { animation: pop .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { 0% { transform: scale(.88); } 100% { transform: scale(1); } }

.status { min-height: 22px; text-align: center; font-size: 14px; color: var(--muted); padding-bottom: 14px; }
.status.err { color: var(--danger); }

.card {
  width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 14px 14px 14px 16px;
  display: flex; align-items: center; gap: 12px;
}
.card .badge {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent);
  display: grid; place-items: center;
}
.card .txt { flex: 1; min-width: 0; }
.card .lbl { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.card .addr { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .go {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: var(--accent); color: var(--on-accent); display: grid; place-items: center;
}
.card .go .ico { width: 20px; height: 20px; }
.card.empty { color: var(--muted); font-size: 14px; }
.card.empty .badge { background: var(--card2); color: var(--muted); }

.hint {
  margin-top: 12px; padding: 12px 14px; border-radius: 14px; font-size: 13px;
  background: var(--card2); color: var(--muted); border: 1px dashed var(--line);
}
.hint b { color: var(--text); font-weight: 600; }
.hint { position: relative; padding-right: 40px; }
.hint .hx { position: absolute; top: 4px; right: 4px; width: 36px; height: 36px; margin: 0; color: var(--muted); display: grid; place-items: center; }
.hint .hx .ico { width: 16px; height: 16px; }
.hint ol { margin: 6px 0 0; padding-left: 20px; }
.hint button.lnk { color: var(--accent); font-weight: 600; margin-left: 6px; }

/* ---------- storico ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 10px 10px 10px;
}
.item .thumb {
  width: 52px; height: 52px; border-radius: 12px; flex: none; overflow: hidden;
  background: var(--card2); color: var(--muted); display: grid; place-items: center;
}
.item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.item.current .thumb { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.item .txt { flex: 1; min-width: 0; }
.item .addr { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: 13px; color: var(--muted); }
.item .del { width: 40px; height: 40px; border-radius: 10px; color: var(--muted); display: grid; place-items: center; }
.item .del:active { color: var(--danger); }
.item .del .ico { width: 20px; height: 20px; }
.pill {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 99px; margin-left: 6px;
  background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); vertical-align: 2px;
}
.empty-state { text-align: center; color: var(--muted); padding: 48px 12px; }
.empty-state .ico { width: 44px; height: 44px; margin-bottom: 10px; opacity: .6; }
.empty-state h3 { color: var(--text); font-size: 17px; margin-bottom: 4px; }

/* ---------- impostazioni ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 12px; }
.panel h3 { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.panel p { margin-top: 8px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--card2); border-radius: 12px; padding: 4px; }
.seg.s3 { grid-template-columns: repeat(3, 1fr); }
.seg button { padding: 9px 0; border-radius: 9px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.row-btns { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

.btn {
  min-height: 48px; padding: 0 20px; border-radius: 14px; font-weight: 600; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--on-accent);
}
.btn.ghost { background: var(--card2); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 50%, transparent); }
.btn.grow { flex: 1; }
.btn:active { transform: scale(.98); }
.btn .ico { width: 20px; height: 20px; }

/* ---------- mappa ---------- */
.mapview { position: fixed; inset: 0; z-index: 40; background: var(--bg); }
#map { position: absolute; inset: 0; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.8); }
}
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.8); }
.leaflet-container { background: var(--bg2); font: inherit; }
.leaflet-control-attribution { font-size: 10px !important; }
.fab {
  position: absolute; z-index: 500; width: 46px; height: 46px; border-radius: 50%;
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  display: grid; place-items: center; box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
}
.fab.back { top: calc(var(--sat) + 12px); left: 14px; }
.fab.recenter { top: calc(var(--sat) + 12px); right: 14px; }
.mapsheet {
  position: absolute; z-index: 500; left: 0; right: 0; bottom: 0;
  background: var(--bg2); border-top: 1px solid var(--line);
  border-radius: 24px 24px 0 0; padding: 10px 18px calc(var(--sab) + 18px);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
}
.grab { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.ms-top { display: flex; gap: 12px; align-items: center; }
.ms-top .badge { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.ms-top .txt { flex: 1; min-width: 0; }
.ms-top .addr { font-weight: 600; font-size: 16px; }
.ms-top .meta { font-size: 13px; color: var(--muted); }
.ms-top .photo { width: 52px; height: 52px; border-radius: 12px; object-fit: cover; flex: none; }
.ms-note { margin-top: 10px; padding: 10px 12px; background: var(--card); border-radius: 12px; font-size: 14px; }
.ms-actions { display: flex; gap: 10px; margin-top: 14px; }
.ms-actions .btn.ghost { width: 48px; padding: 0; flex: none; }

.car-pin {
  width: 34px; height: 34px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: var(--accent); border: 3px solid #fff; box-shadow: 0 3px 10px rgba(0, 0, 0, .4);
  display: grid; place-items: center;
}
.car-pin i { width: 10px; height: 10px; border-radius: 50%; background: #06302b; transform: rotate(45deg); display: block; }
.me-dot { width: 16px; height: 16px; border-radius: 50%; background: #3b82f6; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(59, 130, 246, .25); }

/* ---------- sheet dettagli ---------- */
.sheetwrap { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; }
.backdrop { position: absolute; inset: 0; background: rgba(4, 10, 20, .55); animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; } }
.sheet {
  position: relative; width: 100%; max-width: 560px; margin: 0 auto;
  background: var(--bg2); border-radius: 26px 26px 0 0; border: 1px solid var(--line); border-bottom: 0;
  padding: 10px 20px calc(var(--sab) + 20px);
  animation: up .28s cubic-bezier(.2, .9, .3, 1);
  max-height: 92dvh; overflow-y: auto;
}
@keyframes up { from { transform: translateY(100%); } }
.sh-head { display: flex; align-items: center; gap: 12px; }
.sh-ok { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; flex: none; }
.sh-head .txt { flex: 1; min-width: 0; }
.sh-head h3 { font-size: 18px; font-weight: 600; }
.sh-head .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sh-x { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); background: var(--card); flex: none; }
.sh-x .ico { width: 18px; height: 18px; }
.sh-q { margin: 18px 0 10px; font-size: 15px; font-weight: 600; }
.opts { display: flex; flex-direction: column; gap: 8px; }
.opt {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; text-align: left;
  background: var(--card); border: 1.5px solid var(--line); transition: border-color .15s, background .15s;
}
.opt .ico { color: var(--muted); }
.opt .t { flex: 1; font-weight: 500; }
.opt .t small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.opt .tick { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center; color: transparent; }
.opt .tick .ico, .opt.on .tick .ico { color: inherit; width: 14px; height: 14px; stroke-width: 3; }
.opt.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--card)); }
.opt.on .ico { color: var(--accent); }
.opt.on .tick { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.sh-foot { display: flex; gap: 10px; margin-top: 18px; }
.sh-foot .btn.ghost { flex: none; }
.dots { display: flex; gap: 6px; justify-content: center; margin: 14px 0 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--accent); width: 20px; border-radius: 4px; }
.fld-l { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 8px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-width: 48px; height: 44px; padding: 0 14px; border-radius: 12px; background: var(--card); border: 1.5px solid var(--line); font-weight: 600; }
.chip.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.inp {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 14px; font: inherit; color: var(--text);
  background: var(--card); border: 1.5px solid var(--line); outline: 0; resize: none;
}
.inp:focus { border-color: var(--accent); }
.photo-prev { margin-top: 12px; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); position: relative; }
.photo-prev img { display: block; width: 100%; max-height: 240px; object-fit: cover; }
.photo-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-btns .btn { flex-direction: column; min-height: 84px; background: var(--card); color: var(--text); border: 1.5px solid var(--line); }
.photo-btns .btn .ico { color: var(--accent); width: 26px; height: 26px; }

/* ---------- varie ---------- */
.lightbox { position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, .92); display: grid; place-items: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabh) + var(--sab) + 18px); transform: translate(-50%, 20px);
  z-index: 100; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px;
  font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: .25s; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (max-height: 640px) { .radar { width: min(60vw, 220px); margin-block: 14px 4px; } .hero h1 { font-size: 24px; } }

.opts.nav .opt .t { font-size: 16px; }
.sheet .note { margin-top: 12px; font-size: 13px; color: var(--muted); }
.sheet ol.steps { margin: 14px 0 0; padding-left: 22px; }
.sheet ol.steps li { margin-bottom: 8px; }

/* ---------- precisione posizione ---------- */
.accbox {
  --c: var(--accent);
  display: flex; gap: 10px; align-items: flex-start; text-align: left;
  margin: 0 0 14px; padding: 11px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.4;
  background: color-mix(in srgb, var(--c) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  transition: background .3s, border-color .3s;
}
.accbox.warn { --c: var(--warn); }
.accbox.bad { --c: var(--danger); }
.accbox b { font-weight: 600; }
.accbox .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; margin-top: 5px; }
.accbox .dot.pulse { animation: dotp 1.1s ease-in-out infinite; }
@keyframes dotp { 50% { transform: scale(1.5); opacity: .45; } }
.accbox button.lnk { color: var(--c); font-weight: 600; padding: 6px 0 0; }
.sheet .accbox { margin: 14px 0 0; }
