:root {
  --brand: #0067b1;
  --bg: #f5f7fa;
  --ink: #1c2733;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  width: 100%;
  overflow-x: hidden; /* no horizontal scroll / white gutter on mobile */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
}

header {
  padding: 0.75rem 1rem;
  background: var(--brand);
  color: #fff;
  text-align: center;
}

header h1 {
  margin: 0;
  font-size: 1.15rem;
}

.subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  opacity: 0.9;
}

/* Holds the map (filling it) with the controls floating on top. */
#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
}

/* Floats over the map — transparent, no white strip. */
#controls {
  position: absolute;
  top: 0.75rem;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch; /* so the Search button matches the search bar height */
  justify-content: center;
  padding: 0 1rem;
  background: transparent;
  pointer-events: none; /* let clicks fall through to the map between controls */
}

/* Re-enable interaction on the actual widgets. */
#search-area,
#search-btn {
  pointer-events: auto;
}

/* Anchors the search bar + its recent-searches dropdown. */
#search-area {
  position: relative;
  display: flex;
  flex: 0 1 440px;
  max-width: 440px;
  min-width: 240px;
}

#controls label {
  font-size: 0.85rem;
  font-weight: 600;
}

/* The search bar "box": text field + a location icon button at the right end.
   No `overflow: hidden` here — it would clip Google's prediction dropdown that
   renders inside the autocomplete element. */
#searchbar {
  display: flex;
  align-items: stretch;
  flex: 1 1 auto;
  min-width: 0; /* allow the bar to shrink below the input's intrinsic width */
  background: #fff;
  border: 1px solid #c5cfd9;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

/* Recent-searches dropdown (served from cache, no network call). */
#recent-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 1200;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  background: #fff;
  border: 1px solid #c5cfd9;
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  max-height: 300px;
  overflow-y: auto;
}

#recent-suggestions li {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
}

#recent-suggestions li:hover,
#recent-suggestions li.active {
  background: #eef5fb;
}

#recent-suggestions .sugg-name {
  font-size: 0.85rem;
  font-weight: 600;
}

#recent-suggestions .sugg-addr {
  font-size: 0.75rem;
  color: #5a6b7b;
}

#recent-suggestions .sugg-head {
  padding: 0.3rem 0.7rem 0.2rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8a98a6;
  cursor: default;
}

#recent-suggestions .sugg-head:hover {
  background: transparent;
}

#place-search-slot {
  flex: 1 1 auto;
  min-width: 0;
}

#place-search-slot gmp-place-autocomplete {
  width: 100%;
  min-width: 0; /* don't let the element's intrinsic width force overflow */
  /* Force the light theme so it never renders a dark/black background, even
     when the OS is in dark mode; blend into the surrounding box. */
  color-scheme: light;
  border: none;
  background: transparent;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Location icon button — sits flush at the right end of the search bar box. */
#locate {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  padding: 0;
  border: none;
  border-left: 1px solid #e0e6ec;
  background: #fff;
  color: var(--brand);
  cursor: pointer;
}

#locate svg {
  display: block;
}

#locate:hover {
  background: #eef5fb;
}

#locate[aria-pressed="true"] {
  background: var(--brand);
  color: #fff;
}

#locate:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* Blue Search button, next to the search bar (full height, in line with it). */
#search-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 1.25rem;
  border: 1px solid var(--brand);
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

#search-btn:hover {
  background: #005596;
}

#search-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Pulsing dot for the user's live position */
.user-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ea4335;
  border: 2px solid #fff;
  box-shadow: 0 0 0 rgba(234, 67, 53, 0.6);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(234, 67, 53, 0.5); }
  70%  { box-shadow: 0 0 0 14px rgba(234, 67, 53, 0); }
  100% { box-shadow: 0 0 0 0 rgba(234, 67, 53, 0); }
}

.popup-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.popup-row {
  font-size: 0.8rem;
  margin: 0.1rem 0;
}

.popup-row span {
  color: #5a6b7b;
}

/* 16px on the search field stops iOS Safari from auto-zooming on focus. */
#searchbar {
  font-size: 16px;
}

/* ---- Mobile ---- */
@media (max-width: 600px) {
  header {
    padding: 0.55rem 0.75rem;
  }

  header h1 {
    font-size: 1rem;
  }

  #controls {
    top: 0.5rem;
    padding: 0 0.5rem;
    gap: 0.4rem;
    flex-wrap: nowrap; /* keep the bar + Search button on one line */
  }

  /* Let the search bar shrink/grow to fill the available width. */
  #search-area {
    min-width: 0;
    max-width: none;
    flex: 1 1 auto;
  }

  #search-btn {
    padding: 0 0.9rem;
  }

  /* Popups shouldn't run off a narrow screen. */
  .leaflet-popup-content {
    max-width: 70vw;
  }

  /* Drop the +/- zoom control below the floating search bar so they don't
     overlap (the bar spans full width on mobile). */
  .leaflet-top.leaflet-left {
    top: 56px;
  }
}
