:root {
  color-scheme: light;
  --bg: #eef4f4;
  --panel: #ffffff;
  --panel-soft: #f5f8f7;
  --ink: #162129;
  --muted: #62717b;
  --line: #d8e2e0;
  --accent: #0f766e;
  --accent-strong: #0b5c55;
  --water: #2563eb;
  --warn: #d97706;
  --rose: #be123c;
  --shadow: 0 18px 46px rgba(21, 38, 46, .14);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101417;
  --panel: #171d21;
  --panel-soft: #1e272b;
  --ink: #edf5f4;
  --muted: #9caeb5;
  --line: #2c393d;
  --accent: #35b7a9;
  --accent-strong: #67d5ca;
  --water: #60a5fa;
  --warn: #f59e0b;
  --rose: #fb7185;
  --shadow: 0 18px 46px rgba(0, 0, 0, .38);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  appearance: none;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-bar {
  position: fixed;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.brand,
.bar-actions {
  pointer-events: auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 8px 12px 8px 8px;
  border: 1px solid color-mix(in srgb, var(--line), transparent 15%);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel), transparent 10%);
  box-shadow: var(--shadow);
  text-decoration: none;
  backdrop-filter: blur(16px);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 850;
  letter-spacing: 0;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  margin-top: 2px;
}

.bar-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel), transparent 8%);
  color: var(--ink);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.dashboard-shell {
  display: grid;
  grid-template-columns: minmax(420px, 56vw) minmax(440px, 1fr);
  height: 100vh;
}

.map-pane {
  position: relative;
  min-width: 0;
  background: #d6e9ee;
}

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

.map-tools {
  position: absolute;
  left: 14px;
  bottom: 18px;
  z-index: 650;
  display: grid;
  gap: 10px;
  width: min(320px, calc(100% - 28px));
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(86px, 1fr));
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel), transparent 8%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.segmented button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.segmented button.is-active {
  background: var(--accent);
  color: #fff;
}

.layer-panel,
.ods-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel), transparent 8%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.layer-panel {
  display: grid;
  gap: 7px;
  padding: 10px;
}

.layer-panel .eyebrow {
  margin-bottom: 0;
}

.layer-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  color: var(--ink);
  font-size: .88rem;
  font-weight: 700;
}

.layer-panel input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.data-pane {
  min-width: 0;
  height: 100vh;
  overflow: auto;
  padding: 86px clamp(16px, 2.6vw, 30px) 24px;
  border-left: 1px solid var(--line);
  background: var(--bg);
}

.status-row,
.panel-head,
.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: .76rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

.sync-badge,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: .8rem;
  font-weight: 750;
  white-space: nowrap;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.extra-stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: -8px;
}

.stat-card,
.detail-panel,
.chart-panel,
.ods-panel,
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 10px 26px rgba(21, 38, 46, .08);
}

.ods-panel {
  padding: 15px;
  margin-bottom: 12px;
}

.tab-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.tab-buttons button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--muted);
  padding: 6px 10px;
  font-size: .82rem;
  font-weight: 800;
}

.tab-buttons button.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.dataset-panel {
  margin-top: 12px;
}

.dataset-list {
  display: grid;
  gap: 8px;
  max-height: 340px;
  overflow: auto;
  padding-right: 4px;
}

.dataset-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.dataset-row strong,
.dataset-row span,
.dataset-row small {
  display: block;
}

.dataset-row small {
  color: var(--muted);
  line-height: 1.35;
  margin-top: 2px;
}

.dataset-value {
  color: var(--accent-strong);
  font-weight: 850;
  text-align: right;
  white-space: nowrap;
}

.stat-card {
  padding: 13px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 750;
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: 1.45rem;
  line-height: 1.1;
}

.controls-row {
  margin-bottom: 12px;
}

.search-field {
  position: relative;
  flex: 1 1 auto;
  min-width: 220px;
}

.search-field svg {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  color: var(--muted);
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
}

input {
  padding: 8px 12px 8px 38px;
}

select {
  max-width: 190px;
  padding: 8px 32px 8px 12px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 18px, calc(100% - 12px) 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(260px, .88fr) minmax(320px, 1.12fr);
  gap: 12px;
  margin-bottom: 12px;
}

.detail-panel,
.chart-panel {
  min-height: 288px;
  padding: 15px;
}

.chart-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 220px);
  gap: 12px;
}

.chart-box {
  position: relative;
  height: 220px;
  min-height: 220px;
  max-height: 220px;
  overflow: hidden;
}

.chart-box canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-height: 220px;
}

.detail-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.detail-title h2 {
  font-size: 1.35rem;
}

.metric-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin: 15px 0;
}

.metric {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 750;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 1.08rem;
}

.progress {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.progress > span {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  max-width: 100%;
  background: linear-gradient(90deg, var(--water), var(--accent));
}

.detail-meta {
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 0;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 250px;
  color: var(--muted);
  text-align: center;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  background: var(--panel);
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: 0;
  z-index: 2;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.is-active {
  background: var(--panel-soft);
}

.name-cell strong,
.name-cell small {
  display: block;
}

.name-cell small {
  color: var(--muted);
  margin-top: 2px;
}

.source-daily {
  color: var(--accent-strong);
}

.source-general {
  color: var(--warn);
}

.marker {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .28);
  font-size: 11px;
  font-weight: 900;
}

.marker.is-low {
  background: var(--rose);
}

.marker.is-mid {
  background: var(--warn);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--panel);
  color: var(--ink);
}

.popup h3 {
  margin: 0 0 8px;
}

.popup p {
  margin: 5px 0;
}

.geo-popup ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.source-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.45;
}

@media (max-width: 1060px) {
  body {
    overflow: auto;
  }

  .app-bar {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    padding: 10px;
    background: var(--bg);
  }

  .dashboard-shell {
    display: block;
    height: auto;
  }

  .map-pane {
    height: 52vh;
    min-height: 380px;
  }

  .map-tools {
    position: absolute;
    bottom: 12px;
  }

  .data-pane {
    height: auto;
    overflow: visible;
    padding-top: 20px;
    border-left: 0;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .brand small {
    display: none;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .extra-stats-grid {
    grid-template-columns: 1fr;
  }

  .controls-row,
  .status-row {
    align-items: stretch;
    flex-direction: column;
  }

  select {
    max-width: none;
  }

  .metric-list {
    grid-template-columns: 1fr;
  }

  .dataset-row {
    grid-template-columns: 1fr;
  }

  .dataset-value {
    text-align: left;
  }
}
