:root {
  color-scheme: light;
  --paper: #f3f0e8;
  --paper-2: #e7e2d7;
  --ink: #12202c;
  --muted: #5e6a72;
  --blue: #1546d2;
  --orange: #ef6b2e;
  --acid: #d7f64a;
  --line: #bfc2bb;
  --panel: #faf8f2;
  --header: rgba(243,240,232,.94);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #101820;
  --paper-2: #17232d;
  --ink: #f2efe7;
  --muted: #aab4bc;
  --blue: #7296ff;
  --orange: #ff8a4c;
  --acid: #d7f64a;
  --line: #394754;
  --panel: #14212b;
  --header: rgba(16,24,32,.94);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "DM Sans", system-ui, sans-serif;
  line-height: 1.5;
}
button { font: inherit; }
a { color: inherit; }
.shell { width: min(1240px, calc(100% - 40px)); margin: 0 auto; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--header);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.nav-wrap {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; font-weight: 800; }
.brand-symbol {
  padding: 8px 9px;
  background: var(--ink);
  color: var(--paper);
  font: 700 11px/1 ui-monospace, monospace;
}
nav { display: flex; align-items: center; gap: 22px; }
nav a { text-decoration: none; font-weight: 700; font-size: 13px; }
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 8px 10px;
  cursor: pointer;
  font: 700 11px/1 ui-monospace, monospace;
  text-transform: uppercase;
}

.hero {
  display: grid;
  grid-template-columns: 1.45fr .55fr;
  gap: 70px;
  align-items: end;
  padding: 88px 0 55px;
}
.kicker {
  margin: 0 0 12px;
  color: var(--blue);
  font: 700 11px/1.4 ui-monospace, monospace;
  text-transform: uppercase;
  letter-spacing: .12em;
}
h1, h2 { margin-top: 0; line-height: 1; letter-spacing: -.045em; }
h1 { font-size: clamp(48px, 7.4vw, 94px); margin-bottom: 0; }
h2 { font-size: clamp(30px, 3vw, 48px); margin-bottom: 12px; }
.hero-copy p { color: var(--muted); font-size: 19px; }
.demo-badge {
  display: inline-block;
  background: var(--acid);
  color: #132000;
  padding: 8px 11px;
  font: 700 11px/1 ui-monospace, monospace;
  text-transform: uppercase;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  margin-bottom: 30px;
}
.metrics article {
  min-height: 136px;
  padding: 22px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.metrics span, .metrics small { display: block; color: var(--muted); }
.metrics span { font: 700 11px/1.3 ui-monospace, monospace; text-transform: uppercase; }
.metrics strong { display: block; font-size: 42px; line-height: 1; margin: 15px 0 8px; }

.workspace {
  display: grid;
  grid-template-columns: 1.55fr .45fr;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 12px 12px 0 var(--orange);
}
.map-column { min-width: 0; border-right: 1px solid var(--line); }
.panel-heading {
  min-height: 112px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px;
  border-bottom: 1px solid var(--line);
}
.panel-heading.compact { min-height: auto; align-items: start; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.alert { background: #e2493f; }
.dot.water { background: #2877d5; }
.dot.air { background: #50a45b; }

#map { height: 620px; background: #cfd8dc; }
.map-note { margin: 0; padding: 12px 18px; color: var(--muted); font-size: 11px; }
.detail-panel { padding: 28px; }
.detail-panel > p { color: var(--muted); }
.detail-panel dl { margin: 34px 0 0; }
.detail-panel dl div { padding: 14px 0; border-top: 1px solid var(--line); }
.detail-panel dt {
  color: var(--muted);
  font: 700 10px/1.3 ui-monospace, monospace;
  text-transform: uppercase;
}
.detail-panel dd { margin: 5px 0 0; font-weight: 700; }

.lower-grid {
  display: grid;
  grid-template-columns: .85fr 1.15fr;
  gap: 24px;
  padding: 82px 0;
}
.feed-panel, .source-panel {
  border: 1px solid var(--line);
  background: var(--panel);
}
.feed-list { display: grid; }
.feed-list button {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 6px 15px;
  text-align: left;
  padding: 18px 22px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.feed-list button:hover { background: var(--paper-2); }
.feed-list strong { font-size: 17px; }
.feed-list small { grid-column: 2; color: var(--muted); }
.severity {
  align-self: start;
  justify-self: start;
  padding: 6px 8px;
  color: white;
  font: 700 10px/1 ui-monospace, monospace;
  text-transform: uppercase;
}
.severity.warning { background: #b53a32; }
.severity.elevated { background: #b85b20; }
.severity.good { background: #347a42; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 18px; border-top: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font: 700 10px/1.3 ui-monospace, monospace; text-transform: uppercase; }
td span { color: #2c8f4a; font-weight: 800; }

footer { border-top: 1px solid var(--line); }
.footer-wrap {
  min-height: 94px;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 20px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}
.footer-wrap strong { color: var(--ink); }

.leaflet-container { font: 13px Inter, system-ui, sans-serif; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel);
  color: var(--ink);
}
.demo-marker {
  width: 22px !important;
  height: 22px !important;
  margin-left: -11px !important;
  margin-top: -11px !important;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,.32);
}
.demo-marker.water { background: #2877d5; }
.demo-marker.air { background: #50a45b; }

@media (max-width: 900px) {
  .hero, .workspace, .lower-grid { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .map-column { border-right: 0; border-bottom: 1px solid var(--line); }
  #map { height: 520px; }
}
@media (max-width: 620px) {
  .shell { width: calc(100% - 24px); }
  nav a:not(:first-child) { display: none; }
  .theme-label { display: none; }
  .hero { padding-top: 58px; gap: 28px; }
  .metrics { grid-template-columns: 1fr; }
  .workspace { box-shadow: 7px 7px 0 var(--orange); }
  .panel-heading { display: block; }
  .legend { margin-top: 15px; }
  #map { height: 430px; }
  .footer-wrap { grid-template-columns: 1fr; padding: 26px 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}


/* Stage 2 map containment and control placement */
.site-header {
  z-index: 5000;
}

.workspace,
.map-column,
#map {
  position: relative;
  isolation: isolate;
}

#map {
  z-index: 0;
  overflow: hidden;
}

.leaflet-container {
  z-index: 0;
}

.leaflet-control-container {
  position: relative;
  z-index: 20;
}

.leaflet-bottom.leaflet-right {
  right: 12px;
  bottom: 12px;
}

.leaflet-control-layers {
  max-height: 220px;
  overflow: auto;
}

.leaflet-control-layers-expanded {
  min-width: 170px;
}


/* Stage 3 live data indicators */
.demo-marker.water.rising {
  background: #ef6b2e;
}

#sources td span.pending {
  color: #d78a2e;
}

#sources td span.online {
  color: #2c9b50;
}


/* Stage 3B Leaflet control repair */
.leaflet-control-container {
  position: static !important;
  z-index: auto !important;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute !important;
  z-index: 1000 !important;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-control {
  pointer-events: auto;
}

.leaflet-bottom.leaflet-right {
  right: 12px;
  bottom: 12px;
}

.leaflet-control-layers,
.leaflet-control-zoom {
  margin: 0 0 10px 0 !important;
}

.site-header {
  z-index: 10000 !important;
}
