.app-shell { min-height: 100vh; }
body, html, #map-root, #live-map {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}

#map-root {
  position: relative;
  background: #f5f7fb;
}

#map-root .mobile-zoom-hint {
  position: absolute;
  bottom: 18px;
  right: 14px;
  z-index: 12;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(15,23,42,0.82);
  color: #e2e8f0;
  border-radius: 12px;
  font-size: 12px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.18);
  pointer-events: none;
}

#live-map {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.float {
  position: absolute;
  z-index: 10;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.08);
}

.search-panel {
  top: 14px;
  left: 76px;
  right: 14px;
  width: auto;
  max-width: 560px;
  overflow: hidden;
  transition: width 0.2s ease, opacity 0.2s ease;
}
.search-panel.collapsed {
  width: 140px;
  opacity: 0.6;
  pointer-events: auto;
}
.search-panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
}
.search-panel.collapsed input {
  width: 0;
  padding: 0;
  border: 0;
  opacity: 0;
}
.search-panel.hidden input {
  opacity: 0;
}
.search-panel .input-group-text { background: #fff; }

.filter-panel {
  top: 14px;
  right: 14px;
  padding: 6px;
}
.filter-panel .btn.active {
  background: #0f172a;
  color: #fff;
}

.metric-toggle {
  --metric-color: #2563eb;
  border-color: var(--metric-color);
  color: #0f172a;
}
.metric-toggle.active {
  background: var(--metric-color);
  color: #fff;
  border-color: var(--metric-color);
}

.toolbar {
    top: 120px;
    right: 14px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 46px;
}

@media (max-width: 900px) {
  .filter-panel { top: 70px; right: 14px; }
  .toolbar { top: 140px; left: 14px; right: auto; }
}

.legend {
  bottom: 16px;
  left: 14px;
  padding: 10px 12px;
}
.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  background: #f8fafc;
  color: #0f172a;
  border: 1px solid #e6e9f2;
  font-size: 12px;
}
.legend-chip::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
  background: var(--chip-color, #2ecc71);
}

.history-chart {
  position: relative;
  height: 280px;
  max-height: 60vh;
}
#historyChart {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.marker-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--pin-color, #2ecc71);
  color: #fff;
  font-weight: 800;
  border: 2px solid #fff;
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
  font-size: 13px;
}

.cluster-count {
  background: #1f5cf1;
  color: #fff;
  border: 2px solid #fff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-weight: 800;
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

.leaflet-popup-content-wrapper {
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.18);
}
.leaflet-popup-content {
  margin: 0;
  width: auto !important;
}
.station-popup .leaflet-popup-content {
  margin: 0;
}
.popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-weight: 700;
  color: #0f172a;
}
.popup-meta { font-size: 13px; color: #6c768f; margin-bottom: 4px; }
.popup-metrics { font-size: 13px; line-height: 1.4; }
.popup-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  background: #eef2f7;
  font-weight: 700;
  color: #0f172a;
}

.popup-card {
  width: 420px;
  max-width: 92vw;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(0,0,0,0.16);
  padding: 12px 12px 8px;
  border: 1px solid #eef2f7;
}
.simple-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 2px 8px;
}
.simple-title {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.2;
}
.simple-sub {
  font-size: 13px;
  color: #6c768f;
}
.simple-meta {
  font-size: 12px;
  color: #94a3b8;
}
.simple-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 4px 2px 12px;
}
.simple-aqi {
  display: flex;
  align-items: center;
  gap: 10px;
}
.icon-pill {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 18px;
}
.aqi-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.aqi-value { font-size: 34px; font-weight: 800; line-height: 1; }
.aqi-label { font-size: 12px; font-weight: 700; color: #475569; }
.aqi-level { font-size: 13px; font-weight: 700; }
.simple-temp { text-align: right; color: #0f172a; }
.temp-value { font-size: 18px; font-weight: 800; }
.temp-meta { font-size: 12px; color: #64748b; display: flex; align-items: center; gap: 6px; justify-content: flex-end; }

.simple-spark {
  position: relative;
  height: 92px;
  background: #f8fafc;
  border-radius: 14px;
  overflow: hidden;
  margin: 0 2px 10px;
  border: 1px solid #eef2f7;
}
.spark-canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.simple-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  text-align: center;
  gap: 4px;
  padding: 10px 4px 6px;
  border-top: 1px solid #eef2f7;
  border-bottom: 1px solid #eef2f7;
}
.simple-metrics .metric-label {
  font-size: 11px;
  letter-spacing: 0.6px;
  color: #94a3b8;
  text-transform: uppercase;
  font-weight: 700;
}
.simple-metrics .metric-value {
  font-size: 16px;
  font-weight: 800;
  color: #0f172a;
}

.simple-cta {
  width: 100%;
  text-align: center;
  border: none;
  background: transparent;
  color: #2563eb;
  font-weight: 800;
  padding: 10px 4px 6px;
  letter-spacing: 0.4px;
}
.simple-cta:hover { color: #1d4ed8; text-decoration: underline; }

#map-spinner {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 20;
  display: none;
}

.leaflet-popup.station-popup {
  transform: translateX(0);
}

.leaflet-control-zoom {
  margin-top: 14px;
  margin-left: 14px;
}

.mobile-detail {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.24);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.mobile-detail.show {
  display: flex;
}
.mobile-detail-inner {
  background: #fff;
  width: 100%;
  height: 100%;
  border-radius: 18px;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.mobile-detail-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
}
.mobile-detail-body {
  padding: 18px 16px 16px;
  overflow-y: auto;
  height: 100%;
  padding-bottom: 90px; /* leave room for bottom nav */
}
.md-aqi-ring {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 8px solid #22c55e;
  display: grid;
  place-items: center;
  background: #f8fafc;
}
.md-aqi-value {
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}
.md-aqi-label {
  font-size: 11px;
  color: #475569;
}
.md-forecast-label {
  letter-spacing: 0.6px;
}
.md-spark {
  height: 160px;
  background: #f8fafc;
  border-radius: 12px;
  padding: 8px;
  border: 1px solid #eef2f7;
}
.md-spark canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

@media (max-width: 768px) {
  .sidebar { display: none; }
}

@media (max-width: 1024px) {
  .search-panel {
    left: 14px;
    right: 14px;
    max-width: none;
  }
  .leaflet-control-zoom {
    margin-top: 80px; /* clear the full-width search bar on mobile */
  }
  body.mobile-popup-open .leaflet-popup.station-popup {
    transform: none;
    position: fixed !important;
    inset: 0 !important;
    margin: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 1000;
  }
  body.mobile-popup-open .leaflet-popup-content-wrapper,
  body.mobile-popup-open .leaflet-popup-content {
    width: 100% !important;
    height: 100% !important;
    border-radius: 0;
    overflow: hidden;
  }
  body.mobile-popup-open .leaflet-popup-tip {
    display: none;
  }
  body.mobile-popup-open .popup-card {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }
  body.mobile-popup-open .simple-body {
    padding: 12px 2px;
  }
  body.mobile-popup-open .simple-spark {
    flex: 1;
  }
  body.mobile-popup-open .simple-metrics {
    padding-top: 12px;
    padding-bottom: 12px;
  }
  body.mobile-popup-open .simple-cta {
    position: sticky;
    bottom: 0;
    background: #2563eb;
    color: #fff;
    border-radius: 16px;
    margin-top: auto;
    padding: 14px;
  }
  body.mobile-popup-open .float,
  body.mobile-popup-open .leaflet-control-zoom {
    display: none !important;
  }
  body.mobile-popup-open .mobile-bottom-nav {
    z-index: 1100;
  }
  .mobile-close {
    margin-top: 2px;
  }
  body.mobile-detail-open .float,
  body.mobile-detail-open .leaflet-control-zoom,
  body.mobile-detail-open .leaflet-top,
  body.mobile-detail-open .leaflet-bottom {
    display: none !important;
  }
  body.mobile-detail-open #live-map {
    pointer-events: none;
  }
  body.mobile-detail-open .mobile-bottom-nav {
    z-index: 2100;
  }
}

@media (max-width: 768px) {
  .leaflet-control-zoom {
    display: none !important;
  }
  /* Hide any remaining top-left leaflet controls (safety net on small screens) */
  .leaflet-top.leaflet-left .leaflet-control {
    display: none !important;
  }
  #map-root .mobile-zoom-hint {
    display: inline-flex;
  }
}

/* Alert badges in nav */
.nav .badge {
  margin-left: auto;
  background: #2563eb;
  color: #fff;
}
.nav .badge.bg-danger {
  background: #e11d48;
}
.mobile-nav-item {
  position: relative;
}
.mobile-nav-item .mobile-badge {
  position: absolute;
  top: 2px;
  right: 10px;
  background: #e11d48;
  color: #fff;
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 11px;
  line-height: 1;
}
