/* =====================
   CHXD MAP — Station Map (MapLibre GL JS)
   BEM naming, mobile-first
===================== */

/* --- Stats bar --- */
.plx-stats-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid rgba(var(--primary-rgb), 0.08);
  flex-wrap: wrap;
  grid-column: span 10;
}

.plx-stats-bar__item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-body);
  white-space: nowrap;
}

.plx-stats-bar__number {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--primary);
}

.plx-stats-bar__number--success {
  color: var(--success);
}

.plx-stats-bar__search {
  margin-left: auto;
  position: relative;
}

.plx-stats-bar__input {
  padding: 6px 12px 6px 32px;
  border: 1px solid rgba(var(--primary-rgb), 0.15);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  width: 200px;
  background: var(--bg);
  color: var(--text-main);
  outline: none;
  transition: border-color var(--anim);
}

.plx-stats-bar__input:focus {
  border-color: var(--primary);
}

.plx-stats-bar__input::placeholder {
  color: var(--text-body);
  opacity: 0.6;
}

.plx-stats-bar__search-icon {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  color: var(--text-body);
  pointer-events: none;
}

/* --- Map container --- */
.plx-map-container {
  position: relative;
  width: 100%;
  height: calc(100vh - var(--appbar-h) - 56px);
  min-height: 300px;
  grid-column: span 10;
}

/* --- Legend bar --- */
.plx-map-legend {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  font-size: 0.75rem;
  color: var(--text-body);
  z-index: 2;
  white-space: nowrap;
}

.plx-map-legend__item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.plx-map-legend__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.plx-map-legend__dot--normal {
  background: var(--primary);
}

.plx-map-legend__dot--24h {
  background: var(--success);
}

/* --- MapLibre popup override → PLX theme --- */
.maplibregl-popup.plx-station-popup .maplibregl-popup-content {
  padding: 0;
  border-radius: 0;
  box-shadow: 0 8px 32px rgba(10, 84, 168, 0.15);
  min-width: 260px;
  max-width: 320px;
}

.maplibregl-popup.plx-station-popup .maplibregl-popup-tip {
  border-top-color: var(--surface);
}

.plx-popup {
  padding: 16px;
}

.plx-popup__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.plx-popup__id {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.9375rem;
}

.plx-popup__address {
  font-size: 0.8125rem;
  color: var(--text-body);
  margin-bottom: 10px;
  line-height: 1.4;
}

.plx-popup__section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-body);
  margin-bottom: 8px;
}

.plx-popup__staff {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.plx-popup__staff-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.plx-popup__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(var(--primary-rgb), 0.12);
  color: var(--primary);
  font-size: 0.6875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.plx-popup__staff-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-main);
  margin: 0;
}

.plx-popup__staff-role {
  font-size: 0.6875rem;
  color: var(--text-body);
  margin: 0;
}

.plx-popup__cta {
  width: 100%;
  margin-top: 10px;
  border-radius: 0;
}

/* --- Dark mode --- */
body.dark .plx-stats-bar {
  background: var(--surface);
  border-bottom-color: rgba(255, 255, 255, 0.06);
}

body.dark .plx-stats-bar__input {
  background: var(--surface-2);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

body.dark .plx-map-legend {
  background: rgba(30, 30, 30, 0.95);
  color: var(--text);
}

body.dark .maplibregl-popup.plx-station-popup .maplibregl-popup-content {
  background: var(--surface);
}

body.dark .maplibregl-popup.plx-station-popup .maplibregl-popup-tip {
  border-top-color: var(--surface);
}

body.dark .plx-popup__id {
  color: var(--primary-light);
}

body.dark .plx-popup__address,
body.dark .plx-popup__section-label,
body.dark .plx-popup__staff-role {
  color: var(--text-body);
}

body.dark .plx-popup__staff-name {
  color: var(--text);
}

/* --- Map Bottom Sheet (mobile) --- */
.map-bottom-sheet {
  display: none;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 4px solid var(--accent);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.12);
  max-height: 60dvh;
  overflow-y: auto;
  z-index: 10;
  transform: translateY(100%);
  transition: transform var(--anim);
}

.map-bottom-sheet.open {
  display: block;
  transform: translateY(0);
}

.map-bottom-sheet__handle {
  width: 48px;
  height: 4px;
  background: var(--border-2);
  border-radius: var(--radius-sm);
  margin: 10px auto 4px;
}

.map-bottom-sheet__close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--text-body);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.map-bottom-sheet__body {
  padding: 8px 16px 16px;
}

.map-bottom-sheet__body .plx-popup__header {
  margin-bottom: 6px;
}

.map-bottom-sheet__body .plx-popup__id {
  font-size: 1.0625rem;
}

.map-bottom-sheet__body .plx-popup__cta {
  margin-top: 14px;
  height: 44px;
}

/* --- Mobile --- */
/* --- Station Map — Mobile-first Styles --- */
.plx-stats-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid rgba(var(--primary-rgb), 0.08);
  flex-wrap: wrap;
  grid-column: span 10;
}

.plx-stats-bar__input {
  padding: 6px 12px 6px 32px;
  border: 1px solid rgba(var(--primary-rgb), 0.15);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  width: 140px;
  background: var(--bg);
  color: var(--text-main);
  outline: none;
  transition: border-color var(--anim);
}

.plx-map-container {
  position: relative;
  width: 100%;
  height: calc(100vh - var(--appbar-h) - 48px - 60px);
  min-height: 300px;
  grid-column: span 10;
}

.plx-map-legend {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 6px 12px;
  background: var(--surface); /* Fallback to surface color */
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  font-size: 0.6875rem;
  color: var(--text-body);
  z-index: 2;
  white-space: nowrap;
}

/* Hide MapLibre popup on mobile — bottom sheet replaces it */
.maplibregl-popup.plx-station-popup {
  display: none !important;
}

/* Desktop: Expand UI elements */
@media (min-width: 600px) {
  .plx-stats-bar {
    padding: 12px 16px;
    gap: 12px;
  }

  .plx-stats-bar__input {
    width: 200px;
  }

  .plx-map-container {
    height: calc(100vh - var(--appbar-h) - 56px);
  }

  .plx-map-legend {
    gap: 16px;
    padding: 8px 16px;
    font-size: 0.75rem;
  }

  .maplibregl-popup.plx-station-popup {
    display: block !important;
  }
}

/* --- Dark mode bottom sheet --- */
body.dark .map-bottom-sheet {
  background: var(--surface);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.3);
}

body.dark .map-bottom-sheet__close {
  color: var(--text-body);
}
