/* ==========================================================================
   INDEX PAGE (Map View)
   Page-specific overrides for templates/pages/index.html (map page).
   Most component styling lives under static/css/src/06-components/*.css
   and is bundled via static/css/main.css. Keep this file small.
   ========================================================================== */

/* -------------------------------------------------------------------------
   Page Layout Overrides
   ------------------------------------------------------------------------- */
/* Prevent page scroll on index; internal panels manage their own scroll */
body {
  overflow: hidden;
}

main {
  overflow: hidden;
  min-height: 0;
}

/* Scope padding to the index root container only */
.index-root {
  padding: var(--space-2);
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* Container for map + overlay panel - needs position:relative for absolute panel */
.index-root>.d-flex.flex-row {
  position: relative;
}

/* The map fills the flex container */
#map {
  flex: 1 1 auto;
  min-height: 500px;
  width: 100%;
  height: 100%;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  background-color: var(--color-bg-subtle);
}

/* -------------------------------------------------------------------------
   Top Filters Bar (Overlay Mode)
   ------------------------------------------------------------------------- */

.random-stop-hint {
  z-index: 1005;
}

/* On wide screens Random is its icon, with the hint on hover, to leave room for the summary. */
@media (min-width: 769px) {
  .random-stop-btn__label {
    display: none;
  }
}

.osm-group-subfilters {
  margin-top: var(--space-2);
  padding-left: var(--space-3);
}

.osm-group-subfilters .form-check {
  margin-bottom: var(--space-1);
}

.osm-pair-subfilters {
  margin-top: var(--space-1);
  margin-bottom: var(--space-1);
  padding-left: var(--space-3);
}

.osm-pair-subfilters .form-check {
  margin-bottom: var(--space-1);
}

/* -------------------------------------------------------------------------
   Smart Search Hint Tooltip
   ------------------------------------------------------------------------- */
.smart-search-hint {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 1002;
  background: var(--color-surface-glass);
  backdrop-filter: blur(8px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2) var(--space-3);
  min-width: 250px;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--color-fg);
  pointer-events: none;
}

.smart-search-hint.random-stop-hint {
  left: 50%;
  transform: translateX(-50%);
  min-width: 0;
  width: 170px;
  max-width: 170px;
  padding: var(--space-2);
  text-align: center;
  white-space: normal;
}

.smart-search-hint.random-stop-hint::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid var(--color-surface-glass);
  filter: drop-shadow(0 -1px 0 var(--color-border));
}

.smart-search-hint__title {
  font-weight: var(--font-semibold);
  color: var(--color-fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: var(--space-1);
  font-size: 0.65rem;
}

.smart-search-hint__item {
  padding: 2px 0;
  line-height: var(--leading-snug);
}

.smart-search-hint__item kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 0.3rem;
  color: var(--color-primary);
  font-weight: var(--font-medium);
}

/* -------------------------------------------------------------------------
   Search suggestions (static/js/components/search-suggest.js)
   ------------------------------------------------------------------------- */
.search-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 1003;
  width: max(100%, 320px);
  max-width: calc(100vw - 2rem);
  max-height: 60vh;
  overflow-y: auto;
  margin: 0;
  padding: var(--space-1) 0;
  list-style: none;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-sans);
}

.search-suggestion {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: var(--space-1) var(--space-3);
  cursor: pointer;
}

.search-suggestion:hover,
.search-suggestion.is-active {
  background: var(--color-primary-subtle);
}

.search-suggestion__main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  min-width: 0;
}

.search-suggestion__name {
  overflow: hidden;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-fg);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-suggestion__ref {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-fg-muted);
}

.search-suggestion__meta {
  font-size: var(--text-xs);
  color: var(--color-fg-muted);
}

.search-suggestion__other::before {
  content: ' · ';
}

.zoom-banner.zoom-banner--filters-open {
  top: calc(var(--navbar-height) + 236px);
}

#activeFilters {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0;
  justify-content: flex-start;
  padding: 0;
  border-top: none;
  background-color: transparent;
  width: 100%;
  max-width: 520px;
}

.header-summary #activeFilters {
  width: 100%;
  max-width: none;
  padding: 0.5rem 0 0;
  border-top: 1px solid var(--color-border);
  background-color: transparent;
}

.header-summary #headerSummaryStats {
  width: 100%;
}

.smart-search-input-group {
  width: 250px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 20px;
}

@media (max-width: 768px) {
  .top-filters-bar {
    gap: var(--space-2);
    padding: var(--space-2);
    max-height: 68vh;
  }

  .top-filters-bar .filter-item {
    width: calc(50% - var(--space-2));
    margin: 0 !important;
  }

  .top-filters-bar .filter-item.mobile-filter-item--search,
  .top-filters-bar .filter-item.mobile-filter-item--random {
    width: 100%;
  }

  .smart-search-input-group {
    width: 100% !important;
    min-width: 0;
  }

  /* The filter panel scrolls and would clip a floating list: push the filters down instead. */
  .search-suggestions {
    position: static;
    width: 100%;
    max-width: none;
    max-height: 40vh;
    margin-top: var(--space-1);
  }

  /* The zoom banner sits where the open panel used to end. */
  .index-root:has(#smartSearchSuggestions:not(.d-none)) .zoom-banner {
    display: none;
  }

  .filter-item .random-stop-btn {
    width: 100%;
    justify-content: center;
  }

  #activeFilters {
    max-width: calc(100vw - 2.5rem);
  }

  #filterInfoContainer {
    margin-top: var(--space-2);
    max-width: none !important;
    width: 100%;
  }

  .zoom-banner.zoom-banner--filters-open {
    top: calc(var(--navbar-height) + 204px);
  }
}

/* Map container fills entire space (panel overlays it) */
#mapContainer {
  flex: 1 1 auto;
  min-width: 0;
  /* Required for Leaflet/Flexbox to work properly */
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
}

/* -------------------------------------------------------------------------
   Map legend (static/js/components/map-legend.js)
   ------------------------------------------------------------------------- */
.map-legend {
  max-width: 250px;
  background: var(--color-surface-glass);
  backdrop-filter: blur(8px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--color-fg);
}

.map-legend__toggle {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  width: 100%;
  padding: var(--space-1) var(--space-2);
  border: 0;
  background: transparent;
  color: var(--color-fg);
  font-weight: var(--font-semibold);
  cursor: pointer;
}

.map-legend__body {
  display: none;
  padding: 0 var(--space-2) var(--space-2);
}

.map-legend.is-open .map-legend__body {
  display: block;
}

.map-legend__list {
  margin: 0 0 var(--space-1);
  padding: 0;
  list-style: none;
}

.map-legend__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 1px 0;
}

.map-legend__marker,
.map-legend__line {
  flex-shrink: 0;
  height: 16px;
}

.map-legend__marker {
  width: 16px;
}

.map-legend__line {
  width: 24px;
}

.map-legend__marker circle {
  stroke-width: 2;
  fill-opacity: 0.5;
}

.map-legend__marker--atlas-matched circle {
  fill: var(--color-map-atlas-matched);
  stroke: var(--color-map-atlas-matched);
}

.map-legend__marker--osm-matched circle {
  fill: var(--color-map-osm-matched);
  stroke: var(--color-map-osm-matched);
}

.map-legend__marker--atlas-unmatched circle {
  fill: var(--color-map-atlas-unmatched);
  stroke: var(--color-map-atlas-unmatched);
}

.map-legend__marker--osm-unmatched circle {
  fill: var(--color-map-osm-unmatched);
  stroke: var(--color-map-osm-unmatched);
}

.map-legend__marker--disused circle {
  fill: var(--color-map-disused-fill);
  fill-opacity: 0.9;
  stroke: var(--color-map-osm-unmatched);
}

.map-legend__marker text {
  fill: var(--color-map-osm-unmatched);
  font-size: 8px;
  font-weight: var(--font-bold);
  text-anchor: middle;
}

.map-legend__line line {
  stroke-width: 2;
}

.map-legend__line--match line {
  stroke: var(--color-map-line-atlas-osm);
}

.map-legend__line--group line {
  stroke: var(--color-map-line-osm-group);
  stroke-dasharray: 6 4;
}

.map-legend__note {
  color: var(--color-fg-muted);
}

.map-legend__letters {
  margin: 0;
  color: var(--color-fg-muted);
  line-height: var(--leading-snug);
}

.map-legend__letters b {
  color: var(--color-fg);
}
