/*--------------------------------------------------------------------
VARIABLES
--------------------------------------------------------------------*/
:root {
  --nav-h:       0px;

  /* panel surfaces */
  --panel-bg:    rgba(255, 255, 255, 0.92);
  --panel-bg-2:  rgba(255, 255, 255, 0.96);

  /* text */
  --label:       #1d1d1f;
  --secondary:   #6e6e73;
  --tertiary:    #aeaeb2;

  /* borders / separators */
  --separator:   #e5e5ea;

  /* accents */
  --blue:        #007aff;
  --blue-dim:    #e8f1ff;
  --green:       #34c759;
  --red:         #ff3b30;
  --amber:       #ff9500;

  /* misc */
  --card-radius: 14px;
  --shadow:      0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg:   0 4px 24px rgba(0,0,0,0.11);
}

/*--------------------------------------------------------------------
BASE
--------------------------------------------------------------------*/
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { overflow: hidden; }

body {
  background: #f2f2f7;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
               "Inter", sans-serif;
  color: var(--label);
}

/*--------------------------------------------------------------------
MAP
--------------------------------------------------------------------*/
.map {
  position: absolute;
  top: var(--nav-h);
  bottom: 0; left: 0; right: 0;
  width: 100%;
}

/* zoom / geolocate buttons */
.mapboxgl-ctrl-group {
  background: var(--panel-bg) !important;
  border: 1px solid var(--separator) !important;
  box-shadow: var(--shadow) !important;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 12px !important;
  overflow: hidden;
}
.mapboxgl-ctrl-group button {
  background: transparent !important;
}
.mapboxgl-ctrl-group button + button {
  border-top: 1px solid var(--separator) !important;
}

/*--------------------------------------------------------------------
CONTROLS — left panel
--------------------------------------------------------------------*/
#controls {
  position: absolute;
  top: calc(var(--nav-h) + 14px);
  left: 14px;
  width: 296px;
  max-height: calc(100vh - var(--nav-h) - 28px);
  overflow-y: auto;
  overflow-x: visible;
  z-index: 10;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
  gap: 0;
}
#controls::-webkit-scrollbar { display: none; }

/* search card stays separate — give it bottom margin */
#search-card { margin-bottom: 8px; }

/* all panel-cards merge into one unified block */
.panel-card {
  background: var(--panel-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-left: 1px solid var(--separator);
  border-right: 1px solid var(--separator);
  border-bottom: 1px solid var(--separator);
  border-top: none;
  border-radius: 0;
  box-shadow: none;
  padding: 14px 16px;
}

/* first panel-card: top border + top radius */
#controls .panel-card:nth-child(2) {
  border-top: 1px solid var(--separator);
  border-radius: var(--card-radius) var(--card-radius) 0 0;
}

/* last panel-card: bottom radius */
#controls .panel-card:last-child {
  border-radius: 0 0 var(--card-radius) var(--card-radius);
  /* unified drop shadow on the whole block */
  box-shadow: var(--shadow);
}

.section-label {
  font-size: 9.5px;
  font-weight: 600;
  color: var(--tertiary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 11px;
}

.panel-divider {
  border: none;
  border-top: 1px solid var(--separator);
  margin: 12px 0;
}

/*--------------------------------------------------------------------
SEARCH CARD
--------------------------------------------------------------------*/
#search-card {
  background: var(--panel-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-radius: var(--card-radius);
  border: 1px solid var(--separator);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 10px;
  position: relative;
  z-index: 100;
  overflow: visible;
}

#search-icons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  padding: 4px 0;
}

#icon-circle {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid var(--blue);
  display: block;
}

#icon-dots {
  font-size: 13px;
  color: var(--tertiary);
  line-height: 1;
  letter-spacing: -1px;
}

#icon-pin {
  font-size: 13px;
  color: var(--red);
  line-height: 1;
}

#search-inputs { flex: 1; min-width: 0; }
#geocoder-start { position: relative; z-index: 2; }
#geocoder-end   { position: relative; z-index: 1; }

/* Mapbox geocoder overrides — dark */
#geocoder-start .mapboxgl-ctrl-geocoder,
#geocoder-end   .mapboxgl-ctrl-geocoder {
  min-width: 0; width: 100%; max-width: 100%;
  box-shadow: none;
  background: transparent;
  overflow: visible;
}

#geocoder-start .mapboxgl-ctrl-geocoder--icon-search,
#geocoder-end   .mapboxgl-ctrl-geocoder--icon-search {
  display: none;
}

#geocoder-start .mapboxgl-ctrl-geocoder--input,
#geocoder-end   .mapboxgl-ctrl-geocoder--input {
  padding: 5px 28px 5px 2px;
  font-size: 14px; height: auto;
  color: var(--label);
  background: transparent;
  caret-color: var(--blue);
}

.mapboxgl-ctrl-geocoder .suggestions {
  position: absolute !important;
  z-index: 9999 !important;
  width: 280px; left: 0;
  background: var(--panel-bg);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--separator);
  overflow: hidden;
}
.mapboxgl-ctrl-geocoder .suggestions li a {
  color: var(--label) !important;
}
.mapboxgl-ctrl-geocoder .suggestions li a:hover,
.mapboxgl-ctrl-geocoder .suggestions .active a {
  background: rgba(0,0,0,0.05) !important;
  color: var(--label) !important;
}

#input-divider {
  height: 1px;
  background: var(--separator);
  margin: 4px 0;
}

/*-- GPS + Swap --*/
#search-btns {
  display: flex; flex-direction: column; gap: 5px; flex-shrink: 0;
}

#gps-btn, #swap-btn {
  background: var(--blue-dim);
  border: none; border-radius: 50%;
  width: 28px; height: 28px;
  font-size: 13px; cursor: pointer;
  color: var(--blue);
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  transition: background .15s;
}
#gps-btn:hover, #swap-btn:hover {
  background: rgba(90,200,250,0.24);
}

/*-- Landmarks --*/
#landmarks-grid {
  display: flex; flex-wrap: wrap; gap: 6px; padding-top: 6px;
}

.landmark-btn {
  background: var(--blue-dim);
  border: none;
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px; font-weight: 500;
  color: var(--blue);
  cursor: pointer;
  font-family: inherit;
  transition: background .15s;
  white-space: nowrap;
}
.landmark-btn:hover {
  background: var(--blue);
  color: white;
}

/*--------------------------------------------------------------------
ROUTE PANEL — right side
--------------------------------------------------------------------*/
#route-panel {
  position: fixed;
  top: calc(var(--nav-h) + 14px);
  right: 14px;
  width: 272px;
  z-index: 10;
  display: flex; flex-direction: column; gap: 8px;
}

/*-- Toggle --*/
#route-toggle {
  display: flex;
  background: var(--panel-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-radius: var(--card-radius);
  border: 1px solid var(--separator);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.toggle-btn {
  flex: 1; border: none; background: none;
  padding: 10px 0;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  color: var(--secondary);
  border-right: 1px solid var(--separator);
  font-family: inherit;
  transition: background .15s, color .15s;
}
.toggle-btn:last-child { border-right: none; }
.toggle-btn.active {
  background: var(--blue);
  color: #ffffff;
  font-weight: 600;
}
.toggle-btn:hover:not(.active) {
  background: var(--blue-dim);
  color: var(--blue);
}

/*-- Safety warning --*/
#safety-warning {
  background: rgba(255,100,50,0.12);
  border: 1px solid rgba(255,100,50,0.30);
  color: #ffb340;
  font-size: 13px; font-weight: 500;
  padding: 10px 13px;
  border-radius: 12px;
  font-family: inherit;
}

/*-- Status --*/
#status {
  background: var(--panel-bg);
  border: 1px solid var(--separator);
  color: var(--secondary);
  font-size: 13px;
  padding: 9px 12px;
  border-radius: 10px;
  font-family: inherit;
}

/*-- Route info --*/
#info {
  background: var(--panel-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  padding: 6px 8px;
  border-radius: var(--card-radius);
  border: 1px solid var(--separator);
  box-shadow: var(--shadow);
  font-size: 14px;
  font-family: inherit;
}

.route-row {
  display: flex; flex-direction: column;
  align-items: stretch; gap: 4px;
  padding: 10px 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
  position: relative;
}
.route-row:hover { background: rgba(255,255,255,0.05); }
.route-row.active-route { background: var(--blue-dim); }

.swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 4px; flex-shrink: 0;
}

.route-row-text {
  display: flex; justify-content: space-between;
  align-items: center; gap: 8px;
}

.route-time {
  font-size: 13px; font-weight: 600;
  color: var(--secondary);
  min-width: 40px; text-align: right;
  white-space: nowrap;
}

.route-sub {
  font-size: 12px; color: var(--secondary);
  padding: 2px 8px 8px 24px;
  text-align: left; line-height: 1.3;
  word-break: break-word; width: 100%;
}

/*--------------------------------------------------------------------
LEGEND
--------------------------------------------------------------------*/
.legend-row {
  display: flex; align-items: center;
  gap: 9px; margin-bottom: 7px;
  font-size: 13px; color: var(--label);
  font-family: inherit;
}

.legend-swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 4px; flex-shrink: 0;
}

.legend-circle {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%; flex-shrink: 0;
}

.legend-line {
  display: inline-block;
  width: 20px; height: 3px;
  border-radius: 2px; flex-shrink: 0;
}

.legend-toggle-row { gap: 8px; }

/*-- Toggle switch --*/
.layer-toggle {
  position: relative; display: inline-block;
  width: 30px; height: 18px; flex-shrink: 0;
}
.layer-toggle input {
  opacity: 0; width: 0; height: 0; position: absolute;
}
.toggle-track {
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.18);
  border-radius: 18px; cursor: pointer;
  transition: background .2s;
}
.toggle-track::after {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  background: white; border-radius: 50%;
  top: 2px; left: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  transition: transform .2s;
}
.layer-toggle input:checked + .toggle-track { background: var(--blue); }
.layer-toggle input:checked + .toggle-track::after { transform: translateX(12px); }

/*--------------------------------------------------------------------
RISK FILTER
--------------------------------------------------------------------*/

/* Year period radio buttons */
.year-radio-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.year-radio-label {
  display: flex;
  cursor: pointer;
}

.year-radio-label input[type="radio"] {
  display: none;
}

.year-radio-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--separator);
  background: rgba(0,0,0,0.03);
  transition: background .15s, border-color .15s;
}

.year-radio-label:hover .year-radio-btn {
  background: rgba(0,0,0,0.06);
}

.year-radio-label input:checked + .year-radio-btn {
  background: var(--blue-dim);
  border-color: var(--blue);
}

.year-radio-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--label);
}

.year-radio-sub {
  font-size: 11px;
  color: var(--tertiary);
  font-weight: 400;
}

.dropdown-wrapper { position: relative; margin-top: 8px; }

.risk-dropdown {
  width: 100%;
  padding: 10px 36px 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.13);
  background: white;
  color: var(--label);
  font-size: 14px; cursor: pointer;
  appearance: none; font-family: inherit;
  transition: border-color .2s;
}
.risk-dropdown:hover { border-color: rgba(0,0,0,0.25); }
.risk-dropdown:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(0,122,255,0.15);
}

.dropdown-wrapper::after {
  content: "▼";
  position: absolute; right: 12px; top: 50%;
  transform: translateY(-50%);
  font-size: 10px; color: var(--tertiary);
  pointer-events: none;
}

/*--------------------------------------------------------------------
HOVER TOOLTIP
--------------------------------------------------------------------*/
#hover-tooltip {
  display: none;
  position: fixed;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 12px 15px;
  border-radius: 14px;
  border: 1px solid var(--separator);
  border-left: 3px solid #8b1e21;
  box-shadow: var(--shadow-lg);
  font-size: 13px; pointer-events: none;
  z-index: 1000; max-width: 200px;
  font-family: inherit;
}

#hover-name {
  font-weight: 700; font-size: 13px;
  margin-bottom: 4px; color: var(--label);
  letter-spacing: -0.2px;
}

#hover-level {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 7px; padding: 2px 7px;
  border-radius: 4px; display: inline-block; color: white;
}

#hover-desc {
  font-size: 12px; color: var(--secondary);
  margin-bottom: 6px; line-height: 1.4;
}

#hover-compare {
  font-size: 11px; color: var(--tertiary);
  border-top: 1px solid var(--separator);
  padding-top: 6px; margin-top: 2px;
}

/*--------------------------------------------------------------------
WELCOME MODAL
--------------------------------------------------------------------*/
#welcome-modal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.70);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  align-items: center; justify-content: center;
}

#welcome-box {
  background: #ffffff;
  border-radius: 22px;
  padding: 36px 40px 28px;
  max-width: 420px; width: 90%;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: welcome-in .35s cubic-bezier(.34,1.56,.64,1);
}

@keyframes welcome-in {
  from { opacity: 0; transform: scale(.88) translateY(20px); }
  to   { opacity: 1; transform: scale(1)  translateY(0);     }
}

#welcome-logo-row { margin-bottom: 16px; }
#welcome-logo { height: 160px; width: auto; border-radius: 22px; }

#welcome-subtitle {
  font-size: 13px; color: var(--secondary); margin: 0 0 18px;
}

#welcome-sources {
  text-align: left;
  background: #f7f7f7;
  border-radius: 10px;
  padding: 12px 14px; margin: 0 0 18px;
}

#welcome-sources-title {
  font-size: 11px; font-weight: 600;
  color: var(--tertiary); letter-spacing: 0.5px;
  text-transform: uppercase; margin: 0 0 8px;
}

#welcome-sources ul {
  margin: 0; padding: 0; list-style: none;
  display: flex; flex-direction: column; gap: 4px;
}
#welcome-sources li { font-size: 12px; color: var(--secondary); }
#welcome-sources a { color: var(--blue); text-decoration: none; }
#welcome-sources a:hover { text-decoration: underline; }

#welcome-steps {
  text-align: left; padding: 0; margin: 0 0 24px;
  list-style: none; display: flex; flex-direction: column; gap: 10px;
}
#welcome-steps li {
  font-size: 13.5px;
  color: var(--label);
  line-height: 1.6;
  padding-left: 28px;
  position: relative;
}
.step-icon {
  position: absolute;
  left: 0; top: 1px;
  font-size: 15px;
  color: var(--tertiary);
  width: 20px;
  text-align: center;
}

#welcome-btn {
  width: 100%; padding: 13px;
  background: var(--label); color: #ffffff;
  border: none; border-radius: 12px;
  font-size: 15px; font-weight: 700;
  cursor: pointer; letter-spacing: 0.2px;
  transition: opacity .2s; margin-bottom: 14px;
  font-family: inherit;
}
#welcome-btn:hover { opacity: .85; }

#welcome-skip {
  display: flex; align-items: center;
  justify-content: center; gap: 6px;
  font-size: 12px; color: var(--tertiary); cursor: pointer;
}
#welcome-skip input { cursor: pointer; accent-color: var(--blue); }

/*--------------------------------------------------------------------
LOADING MODAL
--------------------------------------------------------------------*/
#loading-modal {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.55);
  display: none; align-items: center;
  justify-content: center; z-index: 9999;
}

.loading-box {
  background: white;
  padding: 30px 40px;
  border-radius: 16px; text-align: center;
  box-shadow: var(--shadow-lg);
  font-size: 15px; color: var(--label);
}

.spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top: 3px solid var(--blue);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/*--------------------------------------------------------------------
RECENT SEARCHES
--------------------------------------------------------------------*/
#recent-dropdown {
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  overflow: hidden; font-family: inherit;
}

.recent-label {
  font-size: 11px; font-weight: 600;
  color: var(--tertiary); letter-spacing: 0.05em;
  text-transform: uppercase; padding: 10px 14px 4px;
}

.recent-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer;
  transition: background .15s; color: var(--label);
}
.recent-item:hover { background: rgba(255,255,255,0.06); }

.recent-name {
  font-size: 14px; color: var(--label);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/*--------------------------------------------------------------------
COLLAPSIBLE
--------------------------------------------------------------------*/
.collapsible-header {
  cursor: pointer; user-select: none;
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 0;
}
.collapsible-header:hover { color: var(--blue); }

.collapse-arrow {
  font-size: 12px; color: var(--tertiary);
  transition: transform .2s;
}
.collapsible-header.open .collapse-arrow { transform: rotate(180deg); }
.collapsible-body { margin-top: 10px; }

/*--------------------------------------------------------------------
MOBILE FILTERS BUTTON (hidden on desktop)
--------------------------------------------------------------------*/
#mobile-filters-btn {
  display: none;
}

/*--------------------------------------------------------------------
MOBILE OVERLAY
--------------------------------------------------------------------*/
#mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 15;
}
#mobile-overlay.active { display: block; }

/*--------------------------------------------------------------------
MOBILE LAYOUT  ≤ 640 px
--------------------------------------------------------------------*/
@media (max-width: 640px) {
  /* Search card: full-width sticky bar at top */
  #controls {
    position: fixed;
    top: 0; left: 0; right: 0;
    width: 100%;
    max-height: none;
    overflow: visible;
    flex-direction: column;
    gap: 0;
    z-index: 20;
    padding: 10px 12px 0;
    background: transparent;
  }

  #search-card {
    width: 100%;
    margin-bottom: 8px;
    border-radius: var(--card-radius);
  }

  /* Filters toggle button */
  #mobile-filters-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--separator);
    border-radius: 20px;
    padding: 7px 16px;
    font-size: 13px; font-weight: 600;
    color: var(--blue);
    cursor: pointer;
    box-shadow: var(--shadow);
    font-family: inherit;
    margin-bottom: 8px;
    align-self: flex-start;
  }

  /* Panel cards: bottom sheet, hidden until mobile-open */
  #controls .panel-card {
    display: none;
  }

  #controls.mobile-open .panel-card {
    display: block;
  }

  /* Bottom sheet container when open */
  #controls.mobile-open {
    top: auto;
    bottom: 0;
    padding: 0;
    max-height: 80vh;
    overflow-y: auto;
    border-radius: 20px 20px 0 0;
    background: var(--panel-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: 0 -4px 30px rgba(0,0,0,0.15);
    scrollbar-width: none;
    z-index: 20;
  }
  #controls.mobile-open::-webkit-scrollbar { display: none; }

  /* When sheet open, hide search card + filters btn from the sheet */
  #controls.mobile-open #search-card,
  #controls.mobile-open #mobile-filters-btn {
    display: none;
  }

  /* Sheet drag handle */
  #controls.mobile-open::before {
    content: "";
    display: block;
    width: 36px; height: 4px;
    background: var(--tertiary);
    border-radius: 2px;
    margin: 12px auto 8px;
    opacity: 0.5;
  }

  /* Panel cards in sheet: restore borders, remove rounded block styling */
  #controls.mobile-open .panel-card {
    border-left: none; border-right: none;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  #controls.mobile-open .panel-card:first-of-type {
    border-top: none;
  }

  /* GPS + Swap buttons: larger tap targets on mobile */
  #gps-btn, #swap-btn {
    width: 36px; height: 36px;
    font-size: 16px;
  }

  /* Landmark buttons: slightly larger touch target */
  .landmark-btn {
    padding: 8px 14px;
    font-size: 13px;
  }

  /* Route panel: full-width card at bottom */
  #route-panel {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    top: auto;
    width: 100%;
    padding: 0 12px 16px;
    z-index: 10;
    flex-direction: column;
    gap: 6px;
  }

  #route-toggle {
    border-radius: 12px;
  }

  #info {
    border-radius: 12px;
  }

  #safety-warning {
    border-radius: 12px;
  }

  /* Mapbox controls: move up a bit so they don't overlap route panel */
  .mapboxgl-ctrl-bottom-right {
    bottom: 180px !important;
  }

  /* Hover tooltip: disable on mobile (use tap) */
  #hover-tooltip {
    display: none !important;
  }

  /* Welcome modal: full screen on small devices */
  #welcome-box {
    max-width: 100%;
    width: 100%;
    border-radius: 20px 20px 0 0;
    padding: 28px 24px 24px;
    margin-top: auto;
    margin-bottom: 0;
  }
  #welcome-modal {
    align-items: flex-end;
  }
  #welcome-logo {
    height: 100px;
  }

  /* Map: add top padding so search card doesn't cover the map */
  .map {
    top: 0;
  }
}
