*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #1a1d26;
  border-right: 1px solid #2d3148;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 10;
}

.sidebar-header {
  padding: 18px 16px 14px;
  border-bottom: 1px solid #2d3148;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo { width: 32px; height: 32px; object-fit: contain; }
.brand-block { display: flex; flex-direction: column; }
.brand { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.02em; color: #fff; line-height: 1.2; }
.brand-sub { font-size: 0.65rem; color: #64748b; letter-spacing: 0.04em; }

.panel {
  padding: 14px 16px;
  border-bottom: 1px solid #2d3148;
}
.panel h3 {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8892a4;
  margin-bottom: 10px;
}

/* Collapsible panels */
.panel-toggle {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-toggle::after {
  content: "";
  width: 6px; height: 6px;
  border-right: 1.5px solid #8892a4;
  border-bottom: 1.5px solid #8892a4;
  transform: rotate(45deg);
  transition: transform 0.2s;
  flex-shrink: 0;
}
.panel-toggle[aria-expanded="false"]::after {
  transform: rotate(-45deg);
}
.panel-toggle[aria-expanded="false"] {
  margin-bottom: 0;
}
.panel-body {
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease;
  max-height: 500px;
  opacity: 1;
}
.panel-body.collapsed {
  max-height: 0;
  opacity: 0;
}

/* Data layer toggles */
.data-toggle {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  cursor: pointer;
  font-size: 0.82rem;
  color: #cbd5e1;
}
.data-toggle input { flex-shrink: 0; accent-color: #22d3ee; }
.data-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.35;
  transition: opacity 0.15s;
}
.data-toggle input:checked ~ .data-dot { opacity: 1; }
.data-dot.airnow        { background: #38bdf8; }
.data-dot.class1        { background: #4ade80; }
.data-dot.nonattainment { background: #ef4444; }
.data-name { font-weight: 500; }

.info-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #334155;
  color: #94a3b8;
  font-size: 0.55rem;
  font-style: italic;
  font-weight: 700;
  cursor: help;
  vertical-align: middle;
  margin-left: 4px;
  flex-shrink: 0;
}
.info-tip:hover { background: #475569; color: #e2e8f0; }

/* Tooltip rendered via JS to avoid sidebar overflow clipping */
.info-tooltip {
  position: fixed;
  background: #1e293b;
  color: #cbd5e1;
  font-size: 0.7rem;
  font-weight: 400;
  line-height: 1.4;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #334155;
  width: 210px;
  white-space: normal;
  z-index: 9999;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

/* Base map switcher */
.basemap-switcher {
  display: flex;
  gap: 6px;
}
.basemap-btn {
  flex: 1;
  padding: 6px 0;
  background: #0f1117;
  border: 1px solid #2d3148;
  border-radius: 6px;
  color: #8892a4;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.basemap-btn:hover { background: #1e293b; color: #cbd5e1; }
.basemap-btn.active {
  background: #1e293b;
  border-color: #3b82f6;
  color: #e2e8f0;
}

/* AQI Legend */
.legend { display: flex; flex-direction: column; gap: 5px; }
.legend-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.8rem; color: #94a3b8;
}
.legend-item span {
  width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0;
}

/* Footer */
.sidebar-footer { padding: 14px 16px; margin-top: auto; }
#btn-locate {
  width: 100%;
  padding: 8px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #cbd5e1;
  font-size: 0.85rem;
  cursor: pointer;
  margin-bottom: 12px;
  transition: background 0.15s;
}
#btn-locate:hover { background: #273548; }

.muted { font-size: 0.75rem; color: #4b5563; line-height: 1.5; }

/* ── Map ─────────────────────────────────────────────────────────────────── */
#map { flex: 1; }

/* ── Station popup ───────────────────────────────────────────────────────── */
.station-popup {
  position: absolute;
  top: 16px; right: 16px;
  width: 300px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: #1a1d26;
  border: 1px solid #2d3148;
  border-radius: 10px;
  z-index: 20;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  padding: 16px;
}
.station-popup.hidden { display: none; }

#popup-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none;
  color: #64748b; font-size: 1rem; cursor: pointer;
}
#popup-close:hover { color: #e2e8f0; }

/* Multiple station cards within the popup */
.popup-card + .popup-card {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #2d3148;
}

.popup-station-name {
  font-size: 0.95rem; font-weight: 600; color: #f1f5f9;
  margin-bottom: 4px; padding-right: 24px;
}
.popup-source {
  font-size: 0.72rem; color: #64748b; margin-bottom: 12px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.popup-aqi-block {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 8px;
  margin-bottom: 14px;
}
.popup-aqi-number {
  font-size: 2rem; font-weight: 700; color: #0f1117; line-height: 1;
}
.popup-aqi-label { font-size: 0.82rem; color: #0f1117; opacity: 0.8; margin-top: 2px; }

.popup-pollutants h4 {
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: #64748b; margin-bottom: 8px;
}
.pollutant-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 0; border-bottom: 1px solid #1e2233;
  font-size: 0.82rem;
}
.pollutant-row:last-child { border-bottom: none; }
.pollutant-name { color: #94a3b8; }
.pollutant-value { color: #e2e8f0; font-weight: 500; }
.pollutant-bar {
  height: 4px; border-radius: 2px; margin-top: 2px;
  min-width: 4px; max-width: 60px;
}
.pollutant-aqi { font-size: 0.72rem; color: #64748b; }

/* Barkjohn correction badge + info tooltip */
.popup-correction {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.correction-badge {
  font-size: 0.68rem;
  font-weight: 600;
  color: #a78bfa;
  background: rgba(167,139,250,0.12);
  border: 1px solid rgba(167,139,250,0.25);
  border-radius: 4px;
  padding: 2px 7px;
  letter-spacing: 0.02em;
}
.correction-info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #2d3148;
  color: #94a3b8;
  font-size: 0.62rem;
  font-weight: 700;
  font-style: italic;
  cursor: pointer;
  flex-shrink: 0;
}
.correction-tooltip {
  display: none;
  position: absolute;
  left: 0; top: 100%;
  margin-top: 6px;
  width: 100%;
  padding: 10px 12px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #94a3b8;
  font-size: 0.72rem;
  line-height: 1.5;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  z-index: 60;
}
.correction-info:hover + .correction-tooltip,
.correction-info:focus + .correction-tooltip {
  display: block;
}

.popup-updated { font-size: 0.72rem; color: #4b5563; margin-top: 10px; }

/* ── Fire / hotspot Mapbox popup ─────────────────────────────────────────── */
.mapboxgl-popup.fire-popup .mapboxgl-popup-content {
  background: #1a1d26;
  border: 1px solid #2d3148;
  border-radius: 10px;
  color: #e2e8f0;
  padding: 14px 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-width: 200px;
}
.mapboxgl-popup.fire-popup .mapboxgl-popup-close-button {
  color: #64748b;
  font-size: 1.1rem;
  right: 6px;
  top: 4px;
}
.mapboxgl-popup.fire-popup .mapboxgl-popup-close-button:hover { color: #e2e8f0; }
.mapboxgl-popup.fire-popup .mapboxgl-popup-tip {
  border-top-color: #1a1d26;
}
.fire-popup-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 10px;
  color: #f97316;
}
.fire-popup-icon {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #f97316;
  box-shadow: 0 0 8px rgba(249,115,22,0.6);
  flex-shrink: 0;
}
.fire-popup-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  font-size: 0.8rem;
  border-bottom: 1px solid #1e2233;
}
.fire-popup-row:last-child { border-bottom: none; }
.fire-popup-label { color: #64748b; }
.fire-popup-value { color: #cbd5e1; font-weight: 500; }
.fire-popup-confidence {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: 3px;
}
.fire-popup-confidence.high    { color: #ef4444; background: rgba(239,68,68,0.15); }
.fire-popup-confidence.nominal { color: #f59e0b; background: rgba(245,158,11,0.15); }
.fire-popup-confidence.low     { color: #64748b; background: rgba(100,116,139,0.15); }

/* ── Error banner ────────────────────────────────────────────────────────── */
#error-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: #991b1b;
  color: #fef2f2;
  text-align: center;
  padding: 10px 16px;
  font-size: 0.85rem;
  z-index: 100;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}
#error-banner.visible { transform: translateY(0); }

/* ── Mobile sidebar toggle ──────────────────────────────────────────────── */
#sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 30;
  background: #1a1d26;
  border: 1px solid #2d3148;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 1.3rem;
  width: 40px; height: 40px;
  cursor: pointer;
  line-height: 1;
}

/* ── AQS pin-drop cursor ────────────────────────────────────────────────── */
.pin-drop-mode,
.pin-drop-mode .mapboxgl-canvas {
  cursor:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='36' viewBox='0 0 24 36'%3E%3Cpath d='M12 0C5.4 0 0 5.4 0 12c0 9 12 24 12 24s12-15 12-24C24 5.4 18.6 0 12 0z' fill='%232563eb'/%3E%3Ccircle cx='12' cy='12' r='5' fill='white'/%3E%3C/svg%3E")
    12 34,
    crosshair !important;
}

/* ── AQS Site Report panel ───────────────────────────────────────────────── */

.aqs-pin-btn {
  width: 100%;
  padding: 7px 10px;
  background: #1e293b;
  border: 1px solid #2d3148;
  border-radius: 6px;
  color: #94a3b8;
  font-size: 0.82rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
}
.aqs-pin-btn:hover, .aqs-pin-btn.active {
  background: #1e3a5f;
  border-color: #2563eb;
  color: #93c5fd;
}

.aqs-coords {
  font-size: 0.75rem;
  color: #60a5fa;
  margin: 5px 0 0;
  font-family: monospace;
}

.aqs-coord-inputs {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.aqs-jump-btn {
  margin-top: 6px;
  width: 100%;
  padding: 6px 0;
  background: transparent;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #94a3b8;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.aqs-jump-btn:hover:not(:disabled) {
  background: #1e293b;
  color: #e2e8f0;
}
.aqs-jump-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.aqs-form { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }

.aqs-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  color: #8892a4;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.aqs-input {
  background: #0f1117;
  border: 1px solid #2d3148;
  border-radius: 5px;
  color: #e2e8f0;
  font-size: 0.82rem;
  padding: 5px 8px;
  width: 100%;
}
.aqs-input:focus { outline: none; border-color: #2563eb; }
.aqs-input-sm { width: 100%; }

.aqs-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.aqs-run-btn {
  padding: 8px;
  background: #2563eb;
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.aqs-run-btn:hover:not(:disabled) { background: #1d4ed8; }
.aqs-run-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Loading */
.aqs-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 0;
  color: #8892a4;
  font-size: 0.8rem;
  text-align: center;
}
.aqs-spinner {
  width: 22px; height: 22px;
  border: 3px solid #2d3148;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Results */
.aqs-result-header { padding: 10px 0 6px; }
.aqs-site-name { font-weight: 600; font-size: 0.88rem; color: #fff; }
.aqs-meta { font-size: 0.72rem; color: #8892a4; margin-top: 2px; }

.aqs-legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  color: #8892a4;
  margin-top: 6px;
}
.aqs-legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.5);
}
.aqs-dot-airnow { background: #38bdf8; }
.aqs-dot-aqs    { background: #f59e0b; margin-left: 8px; }

.aqs-stats-wrap { margin-top: 10px; overflow-x: auto; }

.aqs-stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
}
.aqs-stats-table th {
  color: #8892a4;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 5px;
  text-align: right;
  border-bottom: 1px solid #2d3148;
}
.aqs-stats-table th:first-child { text-align: left; }
.aqs-stats-table td {
  padding: 4px 5px;
  text-align: right;
  border-bottom: 1px solid #1a1d26;
  color: #cbd5e1;
}
.aqs-param-label { text-align: left !important; color: #e2e8f0; font-weight: 500; }

.aqs-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 600;
}
.aqs-badge.good { background: #14532d; color: #86efac; }
.aqs-badge.warn { background: #713f12; color: #fde68a; }
.aqs-badge.bad  { background: #7f1d1d; color: #fca5a5; }
.aqs-badge.na   { background: #1e293b; color: #64748b; }

.aqs-table-note {
  font-size: 0.65rem;
  color: #4b5563;
  margin-top: 4px;
  text-align: center;
}

.aqs-error { font-size: 0.8rem; color: #f87171; padding: 8px 0; }

.aqs-export-row {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.aqs-btn-report, .aqs-btn-csv {
  flex: 1;
  text-align: center;
  padding: 7px 6px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s;
}
.aqs-btn-report:hover, .aqs-btn-csv:hover { opacity: 0.8; }
.aqs-btn-report { background: #2563eb; color: #fff; }
.aqs-btn-csv    { background: #1e293b; border: 1px solid #2d3148; color: #94a3b8; }

/* ── Auth overlay ────────────────────────────────────────────────────────── */
#auth-overlay {
  position: fixed;
  inset: 0;
  background: #0f1117;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.auth-card {
  text-align: center;
  padding: 40px 36px;
  background: #1a1d26;
  border: 1px solid #2d3148;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
  max-width: 360px;
  width: 90%;
}
.auth-logo { width: 56px; height: 56px; object-fit: contain; margin-bottom: 16px; }
.auth-card h1 { font-size: 1.8rem; font-weight: 700; color: #fff; margin-bottom: 4px; }
.auth-sub { font-size: 0.82rem; color: #64748b; margin-bottom: 28px; }
.auth-error {
  font-size: 0.82rem;
  color: #f87171;
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 16px;
}
.auth-google-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  background: #fff;
  color: #1f2937;
  border: none;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: box-shadow 0.15s;
}
.auth-google-btn:hover { box-shadow: 0 4px 16px rgba(255,255,255,0.15); }
.auth-hint { font-size: 0.72rem; color: #4b5563; margin-top: 16px; }

/* User badge in sidebar header */
#user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.78rem;
}
.user-avatar { width: 22px; height: 22px; border-radius: 50%; }
.user-name { color: #94a3b8; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auth-logout {
  background: none;
  border: 1px solid #334155;
  border-radius: 4px;
  color: #64748b;
  font-size: 0.68rem;
  padding: 2px 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.auth-logout:hover { color: #e2e8f0; border-color: #475569; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  #sidebar-toggle { display: block; }
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 25;
  }
  #sidebar.open { transform: translateX(0); }
  .station-popup { top: 8px; right: 8px; left: 8px; width: auto; }
}
