/* ============================================
   StarTrek — Dashboard Styles
   Apple Aesthetic · Light Theme · B&W
   ============================================ */

/* ---- Override globals for light theme ---- */
.dashboard,
.dashboard * {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f7;
  --bg-tertiary: #e8e8ed;
  --bg-card: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.8);

  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;

  --border-subtle: #d2d2d7;
  --border-glass: #e5e5ea;
  --border-active: #1d1d1f;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.1);
}

/* ---- Dashboard Layout ---- */
.dashboard {
  display: grid;
  grid-template-columns: 1fr 370px;
  grid-template-rows: 56px minmax(0, 1fr) auto;
  grid-template-areas:
    "topbar topbar"
    "map    sidebar"
    "bottom sidebar";
  height: 100vh;
  min-height: 600px;
  overflow: hidden;
  background: var(--bg-secondary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;
  color: var(--text-primary);
}

/* ---- Top Bar ---- */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-glass);
  z-index: var(--z-sticky);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Space Grotesk', 'SF Pro Display', sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  color: #1d1d1f;
  text-decoration: none;
  letter-spacing: -0.02em;
}

.topbar-logo-icon {
  width: 28px;
  height: 28px;
  background: #1d1d1f;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

.topbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border-glass);
}

.topbar-title {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  font-weight: 500;
  letter-spacing: -0.01em;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-label {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.control-select {
  background: var(--bg-secondary);
  border: 1px solid var(--border-glass);
  color: var(--text-primary);
  padding: 5px 28px 5px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s ease;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.control-select:focus {
  outline: none;
  border-color: #1d1d1f;
}

.control-input {
  background: var(--bg-secondary);
  border: 1px solid var(--border-glass);
  color: var(--text-primary);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 500;
  transition: border-color 0.2s ease;
}

.control-input:focus {
  outline: none;
  border-color: #1d1d1f;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #1d1d1f;
  animation: none;
}

.topbar-home-link {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
  transition: color 0.2s ease;
}

.topbar-home-link:hover {
  color: #1d1d1f;
}

/* ---- Map Area ---- */
.map-area {
  grid-area: map;
  position: relative;
  overflow: hidden;
  border-radius: 0;
}

#map {
  width: 100%;
  height: 100%;
  background: #f5f5f7;
}

/* Leaflet overrides — Apple clean */
.leaflet-container {
  background: #f5f5f7 !important;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
}

.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow-md) !important;
  border-radius: 10px !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: #ffffff !important;
  color: #1d1d1f !important;
  border: none !important;
  border-bottom: 1px solid #e5e5ea !important;
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  font-size: 16px !important;
  font-weight: 300 !important;
}

.leaflet-control-zoom a:last-child {
  border-bottom: none !important;
}

.leaflet-control-zoom a:hover {
  background: #f5f5f7 !important;
}

.leaflet-popup-content-wrapper {
  background: #ffffff !important;
  border: none !important;
  border-radius: 14px !important;
  color: #1d1d1f !important;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.12) !important;
}

.leaflet-popup-tip {
  background: #ffffff !important;
  border: none !important;
  box-shadow: none !important;
}

.leaflet-popup-content {
  margin: 14px 18px !important;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
  font-size: 0.82rem !important;
  line-height: 1.5 !important;
}

.popup-title {
  font-family: 'Space Grotesk', 'SF Pro Display', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: #1d1d1f;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.popup-aqi {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.78rem;
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}

.popup-detail {
  font-size: 0.78rem;
  color: #6e6e73;
  line-height: 1.6;
}

.popup-detail strong {
  color: #1d1d1f;
}

/* Map overlays — Apple clean */
.map-legend {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: var(--z-dropdown);
  background: #ffffff;
  border: none;
  border-radius: 12px;
  padding: 14px 16px;
  min-width: 170px;
  box-shadow: var(--shadow-md);
}

.map-legend-title {
  font-family: 'Space Grotesk', 'SF Pro Display', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 10px;
}

.legend-scale {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.legend-color {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
}

/* Map layer toggles */
.map-layers {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: var(--z-dropdown);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: #ffffff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-family: inherit;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.layer-toggle:hover {
  background: #f5f5f7;
  color: #1d1d1f;
}

.layer-toggle.active {
  background: #1d1d1f;
  color: #ffffff;
  box-shadow: var(--shadow-md);
}

.layer-toggle.active .layer-toggle-dot {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.4);
}

.layer-toggle-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---- Sidebar ---- */
.sidebar {
  grid-area: sidebar;
  background: #ffffff;
  border-left: 1px solid var(--border-glass);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-section-title {
  font-family: 'Space Grotesk', 'SF Pro Display', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-glass);
}

/* AQI Summary Cards — Apple style */
.aqi-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.aqi-card {
  padding: 16px 14px;
  border-radius: 14px;
  background: var(--bg-secondary);
  border: none;
  text-align: center;
  transition: transform 0.2s ease;
  cursor: default;
}

.aqi-card:hover {
  transform: scale(1.02);
}

.aqi-card-value {
  font-family: 'Space Grotesk', 'SF Pro Display', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
  letter-spacing: -0.03em;
}

.aqi-card-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

/* AQI cards — monochromatic with subtle indicators */
.aqi-card.good {
  background: #f0faf5;
}

.aqi-card.good .aqi-card-value {
  color: #1d1d1f;
}

.aqi-card.good .aqi-card-label {
  color: #34c759;
}

.aqi-card.moderate {
  background: #fef9ec;
}

.aqi-card.moderate .aqi-card-value {
  color: #1d1d1f;
}

.aqi-card.moderate .aqi-card-label {
  color: #ff9f0a;
}

.aqi-card.poor {
  background: #fef1ee;
}

.aqi-card.poor .aqi-card-value {
  color: #1d1d1f;
}

.aqi-card.poor .aqi-card-label {
  color: #ff6b35;
}

.aqi-card.severe {
  background: #feecec;
}

.aqi-card.severe .aqi-card-value {
  color: #1d1d1f;
}

.aqi-card.severe .aqi-card-label {
  color: #ff3b30;
}

/* Metric Gauges — Apple clean */
.metrics-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.metric-gauge {
  padding: 14px 10px;
  background: var(--bg-secondary);
  border: none;
  border-radius: 14px;
  text-align: center;
}

.metric-gauge-value {
  font-family: 'Space Grotesk', 'SF Pro Display', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: #1d1d1f;
  letter-spacing: -0.02em;
}

.metric-gauge-label {
  font-size: 0.6rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  margin-top: 2px;
}

.metric-gauge-bar {
  width: 100%;
  height: 3px;
  background: #e5e5ea;
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}

.metric-gauge-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 1s ease;
  background: #1d1d1f !important;
}

/* Chart container — Apple style */
.chart-container {
  background: var(--bg-secondary);
  border: none;
  border-radius: 14px;
  padding: 16px;
  position: relative;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.chart-title {
  font-family: 'Space Grotesk', 'SF Pro Display', sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  color: #1d1d1f;
  letter-spacing: -0.01em;
}

.chart-legend-inline {
  display: flex;
  gap: 12px;
  font-size: 0.68rem;
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  font-weight: 500;
}

.chart-legend-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.chart-canvas-wrap {
  height: 160px;
  position: relative;
}

/* Station selector — Apple style */
.station-selector {
  background: var(--bg-secondary);
  border: none;
  border-radius: 14px;
  padding: 14px;
}

.station-selector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.station-selector-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: #1d1d1f;
  font-family: 'Space Grotesk', 'SF Pro Display', sans-serif;
}

.station-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 140px;
  overflow-y: auto;
}

.station-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
  transition: all 0.15s ease;
  border: none;
}

.station-item:hover {
  background: #e8e8ed;
  color: #1d1d1f;
}

.station-item.active {
  background: #1d1d1f;
  color: #ffffff;
}

.station-item.active .station-aqi-badge {
  background: rgba(255, 255, 255, 0.2) !important;
  color: #ffffff !important;
}

.station-aqi-badge {
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
}

/* ---- Bottom Panel ---- */
.bottom-panel {
  grid-area: bottom;
  background: #ffffff;
  border-top: 1px solid var(--border-glass);
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  overflow: visible;
  min-height: 200px;
}

.bottom-card {
  background: var(--bg-secondary);
  border: none;
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.bottom-card-title {
  font-family: 'Space Grotesk', 'SF Pro Display', sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Source Regions — Apple minimal */
.source-regions {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: visible;
}

.source-region-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
  padding: 2px 0;
}

.source-region-bar {
  width: 60px;
  height: 4px;
  background: #e5e5ea;
  border-radius: 2px;
  overflow: hidden;
}

.source-region-fill {
  height: 100%;
  border-radius: 2px;
  background: #1d1d1f;
}

/* What-If panel — Apple clean */
.whatif-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.whatif-slider-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.whatif-slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.whatif-slider-value {
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
  color: #1d1d1f;
  font-weight: 700;
}

.whatif-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: #e5e5ea;
  outline: none;
  cursor: pointer;
}

.whatif-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #1d1d1f;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

.whatif-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #1d1d1f;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  border: none;
}

.whatif-btn {
  padding: 8px 16px;
  font-size: 0.78rem;
  background: #1d1d1f;
  border: none;
  color: #ffffff;
  border-radius: 10px;
  cursor: pointer;
  font-family: 'Space Grotesk', 'SF Pro Display', sans-serif;
  font-weight: 600;
  transition: all 0.2s ease;
  align-self: flex-start;
  letter-spacing: -0.01em;
}

.whatif-btn:hover {
  background: #000000;
  transform: scale(1.02);
}

/* Seasonal calendar — Apple minimal */
.season-strip {
  display: flex;
  gap: 4px;
  flex: 1;
  align-items: flex-end;
  padding-bottom: 20px;
}

.season-bar {
  flex: 1;
  border-radius: 4px 4px 0 0;
  min-height: 8px;
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
  background: #1d1d1f !important;
  opacity: 0.3;
}

.season-bar:hover {
  opacity: 0.7;
  transform: scaleY(1.08);
  transform-origin: bottom;
}

.season-bar::after {
  content: attr(data-month);
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.58rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  font-weight: 600;
}

/* ---- Scrollbar — Apple style ---- */
.dashboard ::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

.dashboard ::-webkit-scrollbar-track {
  background: transparent;
}

.dashboard ::-webkit-scrollbar-thumb {
  background: #d2d2d7;
  border-radius: 4px;
}

.dashboard ::-webkit-scrollbar-thumb:hover {
  background: #86868b;
}

/* ---- Responsive Dashboard ---- */
@media (max-width: 1200px) {
  .dashboard {
    grid-template-columns: 1fr 320px;
  }
}

@media (max-width: 900px) {
  .dashboard {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 50vh auto auto;
    grid-template-areas:
      "topbar"
      "map"
      "sidebar"
      "bottom";
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    border-left: none;
    border-top: 1px solid var(--border-glass);
  }

  .bottom-panel {
    grid-template-columns: 1fr;
  }

  .topbar-controls {
    display: none;
  }
}