/* === GLOBAL RESET === */
html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden; /* ✅ prevents page scrollbars */
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background-color: #f3f4f6; /* soft neutral gray */
}

#map {
  height: 100%;
  width: 100%;
  background-color: #dfe6ed; /* light neutral background under tiles */
}

/* === RESET Leaflet default control box === */
.leaflet-control {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  margin: 0 !important;
}

/* === MAP INTERACTION CURSOR === */
.leaflet-container {
  cursor: grab;
}
.leaflet-container:active {
  cursor: grabbing;
}

/* === MODERN LEGEND === */
.legend {
  background: rgba(255, 255, 255, 0.55); /* frosted-glass effect */
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  padding: 8px 10px;
  font-size: 13px;
  color: #222;
  line-height: 1.4em;
  max-width: 240px;
}

.legend strong {
  display: block;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
}

.legend hr {
  border: none;
  height: 1px;
  background: rgba(0, 0, 0, 0.15);
  margin: 8px 0;
}

/* === COLORED BOXES === */
.legend span.color-box {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

/* === LINE STYLE SVGs === */
.legend svg {
  vertical-align: middle;
  margin-right: 6px;
}
.legend svg line {
  shape-rendering: geometricPrecision;
}

/* === ATTRIBUTION CLEANUP === */
.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.7) !important;
  border: none !important;
  border-radius: 6px;
  padding: 2px 8px !important;
  font-size: 11px !important;
  color: #333 !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* === SEARCH DRAWER === */
.search-div {
  position: absolute;
  top: 60px;
  left: 10px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  padding: 10px;
  width: 320px;
  max-height: 70vh;
  overflow-y: auto;
  z-index: 1000;
  transition: all 0.3s ease;
  transform: translateX(-340px);
  opacity: 0;
}

.search-div.active {
  transform: translateX(0);
  opacity: 1;
}

@media (max-width: 600px) {
  .search-div {
    transform: translateY(100%);
  }
  .search-div.active {
    transform: translateY(0);
  }
}

.search-div input {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}

.search-div input::placeholder {
  color: #777;
}

.search-div [role="list"] {
  margin-top: 10px;
}

.search-div button {
  background: #f7f7f7;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 13px;
}
.search-div button:hover {
  background: #eee;
}

/* === BASEMAP TOGGLE BUTTONS === */
.basemap-toggle button {
  transition: all 0.2s ease-in-out;
}
.basemap-toggle button:hover {
  opacity: 1;
  transform: scale(1.05);
}

/* === LOCATE BUTTON (crosshair) === */
.leaflet-bar button svg {
  pointer-events: none; /* allow clicks anywhere on button */
}

/* === UNIFIED BUTTON THEME === */
button {
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  border-radius: 6px;
  transition: all 0.2s ease-in-out;
}
button:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(30, 144, 255, 0.3);
}

/* === LEGEND TOGGLE BUTTON (mobile) === */
.legend.hidden {
  display: none;
}
.legend-toggle-btn {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background: white;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  padding: 6px 10px;
  font-size: 14px;
  cursor: pointer;
  z-index: 1100;
}
@media (min-width: 601px) {
  .legend-toggle-btn { display: none; }
}

/* === RESPONSIVE TYPOGRAPHY === */
@media (max-width: 600px) {
  body { font-size: 15px; }
  .legend { font-size: 12px; padding: 6px 8px; border-radius: 10px; max-width: 200px; }
  .search-div input { font-size: 15px; }
  .leaflet-control-attribution { font-size: 10px !important; }
}

/* === Step 1: Base switch + map shell === */
:root {
  --bg-cream: #f4f3f0;
  --card-bg: #ffffff;
  --brand: #4b3cc4;
  --brand-80: rgba(75, 60, 196, 0.8);
  --shadow-1: 0 2px 8px rgba(0, 0, 0, 0.06);
  --radius-2xl: 24px;
}
body { background: var(--bg-cream); }
.app-bg { padding: 12px; }
.map-shell {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-1);
  overflow: hidden;

  /* Balanced full-height view without scrollbar */
  height: calc(100vh - 40px);  /* slightly less total height */
  margin: 20px auto;           /* smaller, equal top/bottom space */
  max-width: 100%;
}

#map {
  height: 100%;
  width: 100%;
  background-color: #dfe6ed;
}


.base-switch {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  z-index: 500;
}
.pill-toggle {
  border: none;
  cursor: pointer;
  padding: 8px 14px;
  font: 600 14px/1.2 system-ui;
  border-radius: 999px;
  background: #fff;
  color: #000;
  box-shadow: var(--shadow-1);
  margin-right: 8px;
  transition: all 0.15s;
}
.pill-toggle.is-selected {
  background: var(--brand-80);
  color: #fff;
}

/* === Step 2 FINAL: lock zoom pill to middle-right === */
.leaflet-top.leaflet-left {
  position: static !important;
}
.leaflet-control-zoom {
  position: fixed !important;
  top: 50% !important;
  right: 20px !important;
  transform: translateY(-50%);
  border: none !important;
  background: #fff !important;
  border-radius: 999px !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
  overflow: hidden;
  z-index: 1000;
}
.leaflet-control-zoom a {
  width: 44px !important;
  height: 44px !important;
  line-height: 44px !important;
  font-size: 22px !important;
  font-weight: 600 !important;
  color: #000 !important;
  background: #fff !important;
  border: none !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease-in-out;
}
.leaflet-control-zoom a:hover,
.leaflet-control-zoom a:focus {
  background: rgba(75, 60, 196, 0.8) !important;
  color: #fff !important;
  transform: scale(1.05);
}
.leaflet-control-zoom a + a {
  border-top: none !important;
}

/* === Step 3 REFINED: Locate button full round, snug under zoom === */
.locate-fab {
  position: fixed;
  right: 20px;
  top: calc(50% + 55px);
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
  transition: all 0.15s ease-in-out;
  color: #000;
}
.locate-fab:hover,
.locate-fab:focus {
  background: rgba(75, 60, 196, 0.8);
  color: #fff;
  transform: scale(1.05);
}
.locate-fab svg {
  width: 20px;
  height: 20px;
  pointer-events: none;
}

/* Hide old corner legend */
.leaflet-bottom.leaflet-right .legend {
  display: none !important;
}
/* === Step 4: Legend FAB + Modal UI (restored clean version) === */

/* Round legend button on the left side */
.legend-fab {
  position: fixed;
  left: 20px;
  top: calc(50% + 55px); /* aligns with locate button */
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
  color: #000;
  transition: all .15s ease-in-out;
}
.legend-fab:hover,
.legend-fab:focus {
  background: rgba(75, 60, 196, 0.8);
  color: #fff;
  transform: scale(1.05);
}

/* Modal overlay */
.legend-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.legend-modal[aria-hidden="false"] {
  display: flex;
}
.legend-modal-bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
}

/* Main popup box */
.legend-modal-box {
  position: relative;
  background: #f4f3f0;
  border-radius: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  padding: 18px 20px 20px;
  width: min(90vw, 420px);
  max-height: 80vh;
  overflow: auto;
  z-index: 1;
}


/* === Legend header alignment fix === */
.legend-top {
  position: relative;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;   /* center title text */
  padding: 12px 14px;
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
}

/* Title stays centered */
.legend-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: #111;
}

/* X button pinned to the right */
.legend-close {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  background: #fff;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #000;
  transition: background .15s, color .15s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.legend-close:hover,
.legend-close:focus {
  background: rgba(75,60,196,0.8);
  color: #fff;
}


/* Keep the cream container + inner white sections */
.legend-modal-box{
  background:#f4f3f0;
  border-radius:24px;
  box-shadow:0 8px 32px rgba(0,0,0,0.25);
  padding:16px;
  width:min(90vw,420px);
  max-height:80vh;
  overflow:auto;
}
.legend-modal-inner{
  border-radius:18px;
  overflow:hidden;
}
.legend-sep{
  height:2px;
  background:rgba(0,0,0,0.08);
}
.legend-content{
  background:#fff;
  border-bottom-left-radius:18px;
  border-bottom-right-radius:18px;
  padding:12px 14px;
}
.map-fab {
  position: absolute;
  z-index: 1100;
  width: 44px; height: 44px;
  border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.12);
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
  color: #222;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
}

.map-fab:hover {
  background: #f8f8f8;
}
.map-fab:active {
  transform: translateY(1px);
}
.map-fab svg { opacity: 0.85; }

/* Search FAB — directly under legend */
.map-fab--search {
  position: fixed;
  left: 20px;
  top: calc(50% + 105px);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
  color: #000;
  transition: all 0.15s ease-in-out;
}

/* Stronger selector so it wins */
button.map-fab--search:hover,
button.map-fab--search:focus {
  background: rgba(75, 60, 196, 0.8) !important;
  color: #fff !important;
  transform: scale(1.05);
}

/* === Search Drawer (Centered, half width) === */
.search-drawer {
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  width: 68vw;
  max-width: 880px;
  max-height: 70vh;
  overflow-y: auto;
  z-index: 1200;

  background: #f4f3f0;
  border-radius: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  padding: 0; /* remove inner padding, we'll handle inside sections */
  resize: none !important;
  overflow-x: hidden;
}

/* === Header === */
.search-header {
  background: #fff;
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 14px 18px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.search-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: #111;
}

.search-close {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  background: #fff;
  border: none;
  font-size: 22px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  color: #000;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  transition: background .15s, color .15s;
}
.search-close:hover,
.search-close:focus {
  background: rgba(75,60,196,0.8);
  color: #fff;
}

/* === Body === */
.search-input,
.search-results {
  display: block;
  width: calc(100% - 36px); /* consistent margin with header sides */
  margin-left: auto;
  margin-right: auto;
}

.search-input {
  margin-top: 12px;
  margin-bottom: 12px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
}
.search-input::placeholder { color: #777; }

.search-results {
  background: #fff;
  border-radius: 0 0 24px 24px;
  padding: 10px 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

/* === Each result row === */
.search-result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.search-result-row:last-child {
  border-bottom: none;
}

.search-result-row button {
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 999px;
  padding: 4px 10px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.search-result-row button:hover {
  background: rgba(75,60,196,0.1);
}
