:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --rule: #e4e2dc;
  --focus: #0053a0; /* Linha 1 Azul */
  --shadow: 0 -6px 24px rgb(0 0 0 / 0.12);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  overscroll-behavior: none; /* no pull-to-refresh while panning the map */
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ── Header + search ───────────────────────────────────────────────────── */
.top {
  position: relative;
  z-index: 3;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.brand h1 { margin: 0; font-size: 1.15rem; letter-spacing: -0.01em; }
.muted { color: var(--muted); font-size: 0.8rem; }

.search-wrap { position: relative; }
#search {
  width: 100%;
  font: inherit;
  font-size: 16px; /* ≥16px stops iOS zooming the page on focus */
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}
#search:focus { outline: 2px solid var(--focus); outline-offset: 1px; }

#results {
  position: absolute;
  inset: calc(100% + 4px) 0 auto 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
  max-height: 50vh;
  overflow-y: auto;
}
#results li {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 8px;
  cursor: pointer;
}
#results li span { flex: 1; }
#results li[aria-selected="true"] { background: #eef3fa; }
#results .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* ── Map ───────────────────────────────────────────────────────────────── */
.stage { position: relative; flex: 1; min-height: 0; }
#map {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* we own pan/pinch */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: grab;
}
#map:active { cursor: grabbing; }

#map .lines polyline {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#map .walks line {
  stroke: #9a9a9a;
  stroke-width: calc(var(--w) * 0.5);
  stroke-dasharray: calc(var(--w) * 0.5) calc(var(--w) * 0.6);
  stroke-linecap: round;
}
#map .dot { fill: #fff; stroke: #222; stroke-width: calc(var(--w) * 0.18); }
#map .dot.xfer { stroke-width: calc(var(--w) * 0.3); }
#map .sel { fill: none; stroke: var(--ink); stroke-width: calc(var(--w) * 0.4); pointer-events: none; }
#map .sel.pulse { animation: pulse 0.9s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes pulse {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

#map .labels text {
  fill: var(--ink);
  font-weight: 500;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 0.28em;
  stroke-linejoin: round;
  pointer-events: none;
}
#map .labels text.xfer { font-weight: 700; }

/* ── Zoom buttons ──────────────────────────────────────────────────────── */
.zoom {
  position: absolute;
  right: 12px;
  bottom: calc(12px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.zoom button, .icon {
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
  line-height: 1;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.08);
  cursor: pointer;
}
button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ── Bottom sheet ──────────────────────────────────────────────────────── */
.sheet {
  position: fixed;
  z-index: 4;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px calc(20px + var(--safe-b));
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  transform: translateY(105%);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.open { transform: none; }
.grab { width: 36px; height: 4px; margin: 0 auto 10px; border-radius: 2px; background: var(--rule); }
.sheet-row { display: flex; align-items: center; gap: 12px; }
.sheet h2 { flex: 1; margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
.sheet .icon { box-shadow: none; font-size: 1rem; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.attrib {
  position: fixed;
  left: 8px;
  bottom: calc(4px + var(--safe-b));
  z-index: 1;
  font-size: 0.65rem;
  color: var(--muted);
  pointer-events: none;
}

.fatal { position: fixed; inset: 40% 16px auto; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .sheet { transition: none; }
  #map .sel.pulse { animation: none; }
}
