:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ece7dc;
  --text: #1d1f1c;
  --muted: #6b6a63;
  --line: #ddd6c8;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --yes: #1f8a5b;
  --no: #c4473a;
  --gold: #b7791f;
  --shadow: 0 10px 30px rgba(40, 34, 20, .14), 0 2px 6px rgba(40, 34, 20, .08);
  --radius: 20px;
  --zone: #1f6f5c;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141614; --surface: #1d201d; --surface-2: #272b27; --text: #ecebe6; --muted: #a3a29a;
    --line: #333833; --accent: #4fb795; --accent-ink: #0d1a15; --yes: #43b47f; --no: #e06a5c;
    --gold: #e0a84a; --shadow: 0 10px 30px rgba(0, 0, 0, .5); --zone: #4fb795; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141614; --surface: #1d201d; --surface-2: #272b27; --text: #ecebe6; --muted: #a3a29a;
  --line: #333833; --accent: #4fb795; --accent-ink: #0d1a15; --yes: #43b47f; --no: #e06a5c;
  --gold: #e0a84a; --shadow: 0 10px 30px rgba(0, 0, 0, .5); --zone: #4fb795; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; min-height: 100dvh;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
/* icons only: Leaflet draws zones in its own SVG, which must keep its size */
svg:not(.leaflet-zoom-animated) { width: 22px; height: 22px; fill: currentColor; }
.muted { color: var(--muted); font-size: 14px; }

/* header */
.top { padding: calc(12px + env(safe-area-inset-top)) 16px 10px; background: var(--bg); position: sticky; top: 0; z-index: 20; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.eyebrow { margin: 0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; width: 44px; height: 44px; display: grid; place-items: center; }
.icon-btn[aria-expanded="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.segmented { margin-top: 12px; display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); padding: 4px; border-radius: 14px; }
.segmented button { border: 0; background: transparent; padding: 9px 4px; border-radius: 10px; font-weight: 600; font-size: 15px; color: var(--muted); }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.zone-map-wrap { margin-top: 12px; }
.zone-map { height: 42vh; min-height: 240px; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); }
.zone-meta { margin: 8px 2px 0; font-size: 13px; color: var(--muted); }

/* deck */
main { flex: 1; display: flex; flex-direction: column; padding: 0 16px; }
.view { flex: 1; display: flex; flex-direction: column; }
.deck-bar { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 10px; }
.switch { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); }
.switch input { accent-color: var(--accent); width: 18px; height: 18px; }

.deck { position: relative; flex: 1; min-height: 540px; max-width: 480px; width: 100%; margin: 0 auto; }
.card {
  position: absolute; inset: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; display: flex; flex-direction: column; touch-action: none; user-select: none;
  transition: transform .28s cubic-bezier(.2,.8,.2,1), opacity .28s;
}
.card.dragging { transition: none; }
.card.behind { transform: scale(.95) translateY(14px); filter: brightness(.97); pointer-events: none; }
.photo { position: relative; flex: 0 0 52%; background: var(--surface-2) center/cover no-repeat; }
.photo.empty { display: grid; place-items: center; color: var(--muted); font-size: 14px; }
.photo.empty svg { width: 48px; height: 48px; opacity: .35; display: block; margin: 0 auto 6px; }
.dots { position: absolute; top: 10px; left: 12px; right: 12px; display: flex; gap: 4px; }
.dots i { flex: 1; height: 3px; border-radius: 2px; background: rgba(255,255,255,.45); }
.dots i.on { background: #fff; }
.badge { position: absolute; left: 12px; bottom: 12px; background: rgba(20,20,18,.72); color: #fff; font-size: 12px; font-weight: 600; padding: 5px 9px; border-radius: 999px; backdrop-filter: blur(4px); }
.badge.asta { background: var(--gold); color: #1b1404; }
.stamp { position: absolute; top: 28px; padding: 6px 12px; border: 3px solid; border-radius: 10px; font-weight: 800; font-size: 24px; letter-spacing: .06em; opacity: 0; transform: rotate(-12deg); background: rgba(255,255,255,.85); }
.stamp.yes { left: 18px; color: var(--yes); border-color: var(--yes); }
.stamp.no { right: 18px; color: var(--no); border-color: var(--no); transform: rotate(12deg); }

.info { padding: 14px 16px 10px; display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
.price { font-size: 24px; font-weight: 750; letter-spacing: -.01em; }
.price small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 6px; }
.title { margin: 0; font-size: 16px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; padding: 4px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text); }
.chip.warn { background: color-mix(in srgb, var(--no) 16%, transparent); color: var(--no); }
.mini-map { flex: 1; min-height: 110px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); position: relative; }
.mini-map .where { position: absolute; z-index: 500; left: 8px; bottom: 8px; background: var(--surface); color: var(--text); font-size: 12px; padding: 4px 8px; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.src { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.src a { color: var(--accent); }

.empty-deck { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); border: 2px dashed var(--line); border-radius: var(--radius); }
.empty-deck strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }

.actions { display: flex; justify-content: center; align-items: center; gap: 22px; padding: 14px 0 8px; }
.round { width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center; }
.round svg { width: 30px; height: 30px; }
.round.no { color: var(--no); }
.round.yes { color: var(--yes); }
.round.small { width: 46px; height: 46px; color: var(--muted); }
.round.small svg { width: 22px; height: 22px; }
.round:disabled { opacity: .4; }
.round:active:not(:disabled) { transform: scale(.94); }

/* saved */
.section-title { font-size: 18px; margin: 6px 2px 12px; }
.saved-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.saved-item { display: grid; grid-template-columns: 84px 1fr auto; gap: 12px; align-items: center; background: var(--surface); border-radius: 16px; padding: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.thumb { width: 84px; height: 84px; border-radius: 12px; background: var(--surface-2) center/cover no-repeat; }
.saved-item h3 { margin: 0 0 2px; font-size: 15px; }
.saved-item p { margin: 0; font-size: 13px; color: var(--muted); }
.saved-item .p { font-weight: 700; color: var(--text); font-size: 15px; }
.saved-item a { font-size: 13px; color: var(--accent); }
.remove { border: 0; background: transparent; color: var(--muted); padding: 8px; border-radius: 10px; }
.saved-empty { color: var(--muted); text-align: center; padding: 40px 12px; }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tab { border: 0; background: transparent; padding: 9px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 12px; font-weight: 600; }
.tab.active { color: var(--accent); }
.tab b { font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 12px; font-size: 14px; z-index: 40; max-width: calc(100% - 32px); }

.leaflet-container { background: var(--surface-2); font: inherit; }
@media (min-width: 720px) { .deck { min-height: 620px; } }

/* ---------------------------------------------------------------- 4b: login, zone editor, status */
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 12px; width: 100%; min-height: 44px; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.primary { border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 13px 16px; border-radius: 14px; min-height: 48px; }
.primary:disabled { opacity: .55; }
.ghost { border: 1px solid var(--line); background: var(--surface); font-weight: 600; padding: 12px 16px; border-radius: 14px; min-height: 48px; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 8px; }
.err { color: var(--no); font-size: 14px; min-height: 1.2em; margin: 4px 0 0; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.credits { font-size: 11px; color: var(--muted); text-align: center; margin: 10px 0 18px; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.login-logo { width: 64px; height: 64px; border-radius: 16px; }
.login h1 { font-size: 28px; }
body:has(#login:not([hidden])) { padding-bottom: 0; }

.zone-switch { border: 0; background: none; padding: 0; text-align: left; display: flex; flex-direction: column; min-width: 0; }
.zone-title { font-size: 22px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70vw; }
.zone-title::after { content: " ▾"; font-size: 14px; color: var(--muted); }

.zone-list { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.zone-chip { flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600; }
.zone-chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.zone-chip.new { color: var(--accent); border-style: dashed; }

.panel { background: var(--surface); border-radius: 18px; padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.mode-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.mode-tabs button { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 4px; font-weight: 600; font-size: 14px; color: var(--muted); }
.mode-tabs button[aria-selected="true"] { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.edit-map { height: 44vh; min-height: 260px; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); }
.mode-box { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.range { flex-direction: column; }
.range b { color: var(--text); }
input[type="range"] { padding: 0; border: 0; background: none; accent-color: var(--accent); min-height: 32px; }
.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); }
.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
.toggle { flex-direction: row; justify-content: space-between; align-items: center; color: var(--text); font-size: 15px; padding: 4px 0; }
.toggle input { appearance: none; width: 50px; height: 30px; min-height: 0; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); position: relative; padding: 0; cursor: pointer; flex: 0 0 auto; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.toggle input:checked { background: var(--accent); border-color: var(--accent); }
.toggle input:checked::after { transform: translateX(20px); }
.chip button { border: 0; background: none; padding: 0 0 0 6px; color: var(--muted); }

.stato-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .6s; }
.agents { list-style: none; padding: 0; margin: 12px 0 6px; display: flex; flex-direction: column; gap: 8px; }
.agents li { display: grid; grid-template-columns: 120px 1fr 44px; gap: 8px; align-items: center; font-size: 13px; }
.agents .bar { height: 6px; }
.agents .pct { text-align: right; color: var(--muted); }

.tabs { grid-template-columns: repeat(3, 1fr); }
.tab b:empty { display: none; }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-card { background: var(--surface); width: 100%; max-width: 520px; border-radius: 22px 22px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; max-height: 85dvh; overflow: auto; }
.sheet-card h2 { margin: 0; font-size: 20px; }
.sheet-card h3 { margin: 8px 0 0; font-size: 15px; }
.numeri { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.numeri li { display: flex; justify-content: space-between; align-items: center; background: var(--surface-2); border-radius: 10px; padding: 6px 6px 6px 12px; font-variant-numeric: tabular-nums; }
.leaflet-pm-toolbar a { background-color: var(--surface); }
.switch { flex-direction: row; }
.switch input { width: 18px; min-height: 0; padding: 0; }
