:root {
  --bg: #eef1f4;
  --panel: rgba(255, 255, 255, 0.96);
  --text: #1a2332;
  --muted: #5c6773;
  --border: rgba(0, 0, 0, 0.12);
  --shadow: rgba(0, 0, 0, 0.12);
  --low: #1a9d4f;
  --mid: #b8860b;
  --high: #c0392b;
  --accent: #1971c2;
  --header-pad: max(10px, env(safe-area-inset-top));
  --side-pad: max(12px, env(safe-area-inset-left));
  --bottom-pad: max(12px, env(safe-area-inset-bottom));
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app {
  position: relative;
  width: 100%;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #f8f9fa;
}

/* ── Header overlay ── */
.public-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: var(--header-pad) var(--side-pad) 10px;
  padding-right: max(12px, env(safe-area-inset-right));
  background: linear-gradient(to bottom, rgba(255,255,255,.97) 85%, transparent);
  pointer-events: none;
}

.public-header > * { pointer-events: auto; }

.header-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px 12px;
  margin-bottom: 10px;
}

.site-title {
  font-size: clamp(1rem, 3.8vw, 1.45rem);
  font-weight: 800;
  line-height: 1.2;
  flex: 1 1 200px;
  max-width: 100%;
}

.join-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 2px 8px var(--shadow);
}

.join-btn:active { opacity: 0.88; }

.public-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.control-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-row--scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.chip-row--scroll::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 4px var(--shadow);
  transition: border-color 0.12s, color 0.12s;
}

.chip:active { transform: scale(0.97); }

.chip--active {
  border-color: var(--accent);
  color: var(--accent);
  background: #e7f2ff;
}

.privacy-note {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

/* Desktop: country left, city right */
@media (min-width: 768px) {
  .public-controls {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px 24px;
  }

  .control-block { flex: 1 1 200px; }
  .control-block--city { flex: 2 1 280px; }
  .control-block--period { flex: 0 0 auto; }
}

/* ── Pulse widget ── */
.city-pulse {
  position: absolute;
  z-index: 1001;
  top: calc(var(--header-pad) + 8px);
  right: max(12px, env(safe-area-inset-right));
  margin-top: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px 12px 8px;
  min-width: 100px;
  text-align: center;
  box-shadow: 0 2px 12px var(--shadow);
  pointer-events: none;
}

@media (max-width: 767px) {
  .city-pulse {
    top: auto;
    bottom: calc(72px + var(--bottom-pad));
    right: max(10px, env(safe-area-inset-right));
  }
}

@media (min-width: 768px) {
  .city-pulse {
    top: calc(var(--header-pad) + 120px);
  }
}

.cp-drivers {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 2px;
}

.cp-icon { font-size: 14px; }

.cp-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.cp-taxi { font-size: 20px; line-height: 1; }

.cp-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 24px;
}

.cp-trip-icon { font-size: 8px; }

.cp-num { font-size: 14px; font-weight: 800; }
.cp-active .cp-num { color: var(--low); }
.cp-done .cp-num { color: var(--high); }

.hidden { display: none !important; }

/* ── Legend ── */
.legend-wrap {
  position: absolute;
  z-index: 1001;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(10px + var(--bottom-pad));
  max-width: min(96vw, 720px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.legend-toggle {
  display: none;
  min-height: 44px;
  min-width: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--panel);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 10px var(--shadow);
}

.legend-panel {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 12px;
  padding: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 11px;
  color: var(--muted);
  box-shadow: 0 2px 14px var(--shadow);
}

.legend-sep { opacity: 0.35; }
.legend-meta { color: var(--text); font-weight: 600; font-size: 10px; }

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: -1px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.08);
}

.dot.low { background: var(--low); }
.dot.mid { background: var(--mid); }
.dot.high { background: var(--high); }

@media (max-width: 767px) {
  .legend-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .legend-toggle-full { display: none; }
  .legend-panel { display: none; border-radius: 12px; max-width: 92vw; }
  .legend-wrap.legend--open .legend-panel { display: flex; }
  .legend-wrap.legend--open .legend-toggle-compact { display: none; }
  .legend-wrap.legend--open .legend-toggle-full { display: inline; }
}

@media (min-width: 768px) {
  .legend-toggle { display: none; }
  .legend-toggle-compact { display: none !important; }
}

/* ── Hint ── */
.hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1002;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 14px;
  box-shadow: 0 4px 24px var(--shadow);
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}

/* ── Leaflet ── */
.leaflet-container { font: inherit; }

.leaflet-control-zoom {
  margin-top: calc(var(--header-pad) + 140px) !important;
  margin-left: max(10px, env(safe-area-inset-left)) !important;
  border: none !important;
  box-shadow: 0 2px 10px var(--shadow) !important;
}

@media (max-width: 767px) {
  .leaflet-control-zoom {
    margin-top: auto !important;
    margin-bottom: calc(10px + var(--bottom-pad)) !important;
    margin-left: max(10px, env(safe-area-inset-left)) !important;
  }
}

.leaflet-control-zoom a {
  min-width: 44px !important;
  min-height: 44px !important;
  line-height: 44px !important;
  background: var(--panel) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 4px 20px var(--shadow);
}

.leaflet-popup-content { margin: 10px 14px; font-size: 13px; line-height: 1.45; }

.leaflet-control-attribution {
  background: rgba(255,255,255,.88) !important;
  color: var(--muted) !important;
  font-size: 9px !important;
}

/* ── Cell labels ── */
.cell-label-wrap {
  background: transparent !important;
  border: none !important;
}

.cell-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  width: 54px;
  gap: 2px;
  font-size: clamp(10px, 2.8vw, 12px);
  font-weight: 800;
  color: #1a2332;
  text-shadow: 0 0 4px #fff, 0 1px 2px rgba(255,255,255,.95);
  pointer-events: none;
}

.cell-in { flex: 1; color: #15803d; font-size: 9px; text-align: left; }
.cell-out { flex: 1; color: #1d4ed8; font-size: 9px; text-align: right; }
.cell-now { flex: 0 0 auto; font-size: 14px; margin: 0 2px; }
