:root {
  --ink: #17222b;
  --muted: #5f6d78;
  --panel: #ffffff;
  --soft: #f4f7f8;
  --border: #dce4e8;
  --accent: #176b52;
  --accent-dark: #0e4c3a;
  --shadow: 0 14px 34px rgba(23, 34, 43, 0.12);
  --low: #2e8b57;
  --mid: #d6a51e;
  --high: #e47c25;
  --vhigh: #c73b3b;
  --missing: #7d8992;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--soft);
}
button, select { font: inherit; }

.app-shell { width: min(1400px, 100%); margin: 0 auto; padding: 22px; }
.page-header { margin-bottom: 14px; }
.eyebrow { margin: 0 0 5px; font-size: .82rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
h1 { margin: 0; font-size: clamp(1.75rem, 4vw, 2.55rem); line-height: 1.08; }
.intro { max-width: 880px; margin: 10px 0 0; color: var(--muted); line-height: 1.5; }

.survey-toolbar {
  display: grid;
  grid-template-columns: auto minmax(230px, 420px) auto;
  justify-content: center;
  align-items: end;
  gap: 12px;
  padding: 14px;
  margin-bottom: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.survey-title-wrap { display: grid; gap: 5px; text-align: center; }
.survey-title-wrap label { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; color: var(--muted); }
#survey-select { width: 100%; padding: 9px 36px 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: white; font-weight: 700; }
.survey-status { min-height: 1.1em; font-size: .78rem; color: var(--muted); }
.survey-status.pending { color: #9a6810; font-weight: 700; }
.nav-button { border: 1px solid var(--border); background: white; color: var(--accent-dark); border-radius: 10px; padding: 10px 14px; font-weight: 700; cursor: pointer; }
.nav-button:hover:not(:disabled) { background: #eef6f3; }
.nav-button:disabled { opacity: .45; cursor: default; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.summary-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: grid; gap: 3px; }
.summary-card span { color: var(--muted); font-size: .8rem; }
.summary-card strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }

.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: stretch; }
.map-card { position: relative; min-width: 0; }
#map { width: 100%; min-height: 680px; border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; background: #dfe7e9; }

.map-legend { position: absolute; z-index: 500; left: 12px; bottom: 12px; max-width: 300px; background: rgba(255,255,255,.94); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; box-shadow: 0 3px 12px rgba(0,0,0,.12); display: flex; flex-wrap: wrap; gap: 7px 12px; align-items: center; font-size: .78rem; }
.map-legend strong { flex-basis: 100%; }
.map-legend span { display: inline-flex; align-items: center; gap: 5px; }
.map-legend small { flex-basis: 100%; color: var(--muted); }
.swatch { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.band-low { background: var(--low); }
.band-mid { background: var(--mid); }
.band-high { background: var(--high); }
.band-vhigh { background: var(--vhigh); }
.band-missing { background: var(--missing); }

.site-panel { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 22px; box-shadow: var(--shadow); min-width: 0; }
.panel-kicker { margin: 0 0 8px; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; font-size: .76rem; font-weight: 700; }
.site-panel h2 { margin: 0 0 8px; font-size: 1.55rem; }
.site-panel p { line-height: 1.5; }
.result-panel { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 18px; }
.result-main { display: flex; align-items: baseline; flex-wrap: wrap; gap: 5px; }
.result-label { flex-basis: 100%; color: var(--muted); font-size: .82rem; }
.result-main strong { font-size: 2rem; font-variant-numeric: tabular-nums; }
.unit { color: var(--muted); }
.change-box { margin-top: 12px; padding: 11px 12px; border-radius: 10px; background: #f4f7f8; line-height: 1.4; font-size: .92rem; }
.change-box.down { background: #eaf6ef; color: #155e3d; }
.change-box.up { background: #fff0ec; color: #973d2b; }
.change-box.same { background: #f1f3f5; color: #53616b; }

.chart-wrap { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.chart-wrap h3 { margin: 0 0 10px; font-size: 1rem; }
.chart-wrap canvas { width: 100% !important; height: 250px !important; }
.coordinates { margin: 18px 0 0; padding: 14px 0 0; border-top: 1px solid var(--border); }
.coordinates div { display: flex; justify-content: space-between; gap: 12px; margin: 6px 0; }
.coordinates dt { color: var(--muted); }
.coordinates dd { margin: 0; font-variant-numeric: tabular-nums; }

.site-marker { width: 38px; height: 38px; color: white; border: 2px solid white; border-radius: 50%; box-shadow: 0 2px 7px rgba(0,0,0,.35); display: grid; place-items: center; font-weight: 800; font-size: 12px; font-variant-numeric: tabular-nums; text-shadow: 0 1px 2px rgba(0,0,0,.45); transition: transform .12s ease; }
.site-marker:hover { transform: scale(1.08); }
.site-marker.low { background: var(--low); }
.site-marker.mid { background: var(--mid); }
.site-marker.high { background: var(--high); }
.site-marker.vhigh { background: var(--vhigh); }
.site-marker.missing { background: var(--missing); }

.leaflet-popup-content-wrapper { border-radius: 12px; }
.leaflet-popup-content { margin: 14px 16px; line-height: 1.4; }
.popup-ref { font-weight: 800; font-size: 1rem; margin-bottom: 3px; }
.popup-location { color: #4e5e69; margin-bottom: 7px; }
.popup-result { font-weight: 800; }
.popup-note { color: #7c641f; font-size: .85rem; }

.page-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; color: var(--muted); font-size: .82rem; padding: 13px 2px 0; }

@media (max-width: 920px) {
  .app-shell { padding: 12px; }
  .map-layout { grid-template-columns: 1fr; }
  #map { min-height: 540px; }
  .site-panel { order: 2; }
}
@media (max-width: 620px) {
  .survey-toolbar { grid-template-columns: 1fr 1fr; }
  .survey-title-wrap { grid-column: 1 / -1; grid-row: 1; }
  .nav-button { width: 100%; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  #map { min-height: 500px; }
  .map-legend { right: 12px; max-width: none; }
}

/* Detailed NO₂ concentration scale used for marker colours */
.colour-ramp {
  width: 100%;
  height: 12px;
  border: 1px solid rgba(0,0,0,.2);
  border-radius: 3px;
  background: linear-gradient(90deg,
    #000066 0%, #0325d3 14%, #0c95e9 24%, #2cd2ba 33%, #a4eb50 38%,
    #ffff00 43%, #ffd600 50%, #ff8500 61%, #ff3f00 69%, #fa0101 82%,
    #a61313 91%, #331a1a 100%);
}
.legend-range { width: 100%; display: flex !important; justify-content: space-between; gap: 8px !important; font-variant-numeric: tabular-nums; }
.legend-range > span { color: var(--muted); }
.popup-rounded { font-size: .8rem; font-weight: 600; color: #5f6d78; }


/* Collapsible location comparison chart */
.comparison-section {
  margin-top: 16px;
}
.comparison-toggle {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  background: var(--panel);
  color: var(--accent-dark);
  font-weight: 800;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 5px 16px rgba(23, 34, 43, 0.06);
}
.comparison-toggle:hover { background: #eef6f3; }
.comparison-toggle::after {
  content: '▾';
  float: right;
  transition: transform .15s ease;
}
.comparison-toggle[aria-expanded="true"]::after { transform: rotate(180deg); }
.comparison-panel {
  margin-top: 10px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.comparison-heading h2 { margin: 0 0 6px; font-size: 1.35rem; }
.comparison-heading p:last-child { margin: 0 0 12px; color: var(--muted); }
.comparison-chart-wrap { height: 610px; min-height: 460px; }
.comparison-chart-wrap canvas { width: 100% !important; height: 100% !important; }

.comparison-footnote {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

@media (max-width: 620px) {
  .comparison-panel { padding: 14px; }
  .comparison-chart-wrap { height: 720px; }
}

.comparison-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.sort-control {
  display: grid;
  gap: 5px;
  justify-items: end;
  flex: 0 0 auto;
}
.sort-label {
  color: var(--muted);
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.sort-toggle {
  min-width: 142px;
  display: inline-flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--accent-dark);
  font-weight: 750;
  cursor: pointer;
}
.sort-toggle:hover { background: #eef6f3; }
.sort-arrow { font-size: 1.05rem; line-height: 1; }

@media (max-width: 620px) {
  .comparison-heading { flex-direction: column; }
  .sort-control { justify-items: start; width: 100%; }
  .sort-toggle { width: 100%; }
}

/* Collapsible single-location chart across all survey rounds */
.site-history-section { margin-top: 16px; }
.site-history-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
}
.site-history-heading h2 { margin: 0 0 6px; font-size: 1.35rem; }
.site-history-heading p:last-child { margin: 0 0 12px; color: var(--muted); }
.site-history-control {
  min-width: min(420px, 45vw);
  display: grid;
  gap: 6px;
}
.site-history-control label {
  color: var(--muted);
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.site-history-control select {
  width: 100%;
  padding: 9px 34px 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}
.site-history-chart-wrap { height: 430px; min-height: 340px; }
.site-history-chart-wrap canvas { width: 100% !important; height: 100% !important; }

@media (max-width: 720px) {
  .site-history-heading { flex-direction: column; }
  .site-history-control { width: 100%; min-width: 0; }
  .site-history-chart-wrap { height: 500px; }
}


/* Snapshot metrics for the one-location panel */
.site-history-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 8px 0 18px;
}
.site-history-stat {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafb;
  display: grid;
  gap: 4px;
}
.site-history-stat span {
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.25;
}
.site-history-stat strong {
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}
.history-change-up { color: #c62828; }
.history-change-down { color: #15803d; }
.history-change-same { color: #53616b; }
@media (max-width: 760px) {
  .site-history-summary { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 460px) {
  .site-history-summary { grid-template-columns: 1fr; }
}

.worst-trend-section { margin-top: 16px; }


/* Long-term site trend analysis */
.site-trend-section { margin-top: 16px; }
.trend-summary { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:10px; margin:14px 0 18px; }
.trend-summary .summary-card { min-height:72px; }
.trend-table-wrap { overflow-x:auto; border:1px solid var(--border); border-radius:10px; }
.trend-table { width:100%; border-collapse:collapse; min-width:980px; background:#fff; font-size:.88rem; }
.trend-table th, .trend-table td { padding:10px 11px; border-bottom:1px solid var(--border); text-align:left; vertical-align:middle; }
.trend-table th { position:sticky; top:0; background:#f4f7f8; color:var(--muted); font-size:.75rem; text-transform:uppercase; letter-spacing:.035em; z-index:1; }
.trend-table tbody tr { cursor:pointer; }
.trend-table tbody tr:hover { background:#f6fafc; }
.trend-table tbody tr:last-child td { border-bottom:0; }
.trend-site { font-weight:800; white-space:nowrap; }
.trend-site small { display:block; max-width:220px; color:var(--muted); font-weight:500; white-space:normal; margin-top:2px; }
.trend-badge { display:inline-block; padding:4px 7px; border-radius:999px; font-weight:800; white-space:nowrap; }
.trend-improve { color:#15803d; background:#e9f7ee; }
.trend-worsen { color:#c62828; background:#fdecec; }
.trend-stable { color:#53616b; background:#eef2f4; }
.trend-number { font-variant-numeric:tabular-nums; white-space:nowrap; }
@media (max-width:760px){ .trend-summary{grid-template-columns:1fr 1fr;} }
@media (max-width:460px){ .trend-summary{grid-template-columns:1fr;} }

/* Best and worst long-term performers */
.performance-section { margin-top: 16px; }
.performance-grid { display:grid; grid-template-columns:1fr 1fr; gap:16px; margin-top:14px; }
.performance-group { border:1px solid var(--border); border-radius:12px; overflow:hidden; background:#fff; }
.performance-group h3 { margin:0; padding:12px 14px; font-size:1rem; background:#f4f7f8; }
.performance-best h3 { color:#15803d; }
.performance-worst h3 { color:#c62828; }
.performance-list { display:grid; }
.performance-item { appearance:none; width:100%; border:0; border-bottom:1px solid var(--border); background:#fff; color:var(--ink); display:grid; grid-template-columns:30px minmax(0,1fr) auto; gap:10px; align-items:center; padding:12px 14px; text-align:left; cursor:pointer; font:inherit; }
.performance-item:last-child { border-bottom:0; }
.performance-item:hover { background:#f7fafb; }
.performance-rank { width:26px; height:26px; border-radius:50%; display:grid; place-items:center; background:#eef2f4; font-weight:800; }
.performance-site { min-width:0; display:grid; gap:2px; }
.performance-site strong { font-size:.92rem; }
.performance-site small { color:var(--muted); line-height:1.25; }
.performance-metrics { display:grid; gap:2px; text-align:right; white-space:nowrap; font-variant-numeric:tabular-nums; }
.performance-metrics strong { font-size:.9rem; }
.performance-metrics small { color:var(--muted); font-size:.76rem; }
.performance-down strong { color:#15803d; }
.performance-up strong { color:#c62828; }
.performance-same strong { color:#53616b; }
@media (max-width:760px) { .performance-grid { grid-template-columns:1fr; } }
@media (max-width:460px) { .performance-item { grid-template-columns:28px minmax(0,1fr); } .performance-metrics { grid-column:2; text-align:left; } }
