:root {
  --brand: #2c7a7b;
  --brand-dark: #225f60;
  --brand-tint: #e6fffa;
  --surface: #ffffff;
  --page: #f5f7fa;
  --ink: #1f2933;
  --ink-2: #52606d;
  --ink-3: #7b8794;
  --line: #d9e2ec;
  --header-h: 56px;
  --sidebar-w: 360px;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--page);
}

/* ---------- header & navigation ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-weight: bold;
  text-decoration: none;
  white-space: nowrap;
}
.brand:hover { background: var(--brand-dark); }
.main-nav {
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.main-nav::-webkit-scrollbar { display: none; }
.main-nav a {
  flex: none;
  padding: 6px 14px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--ink);
  font-size: 15px;
  text-decoration: none;
  white-space: nowrap;
}
.main-nav a:hover { background: #dde5ee; }
.main-nav a[aria-current="page"] { background: var(--brand); color: #fff; }

/* ---------- pages ---------- */
main { height: calc(100% - var(--header-h)); }
.page { display: none; height: 100%; }
.page.active { display: block; }
.page-frame { width: 100%; height: 100%; border: 0; display: block; }

/* map pages: optional tab row, then sidebar + map */
.map-page { display: none; flex-direction: column; height: 100%; }
.map-page.active { display: flex; }
.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tabs button {
  flex: none;
  padding: 8px 16px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--ink-2);
  font: inherit;
  cursor: pointer;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] {
  border-bottom-color: var(--brand);
  color: var(--ink);
  font-weight: bold;
}
.map-layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  flex: none;
  width: var(--sidebar-w);
  overflow-y: auto;
  padding: 16px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.sidebar h2 { margin: 0 0 4px; font-size: 16px; }
.sidebar .note { margin: 0 0 12px; color: var(--ink-2); font-size: 13px; }
.sidebar .source { margin: 12px 0 0; color: var(--ink-3); font-size: 12px; }
.chart-box { position: relative; width: 100%; }
.map { flex: 1; min-width: 0; background: #e9edf1; }

details.table-view { margin-top: 12px; font-size: 13px; }
details.table-view summary { cursor: pointer; color: var(--brand); }
details.table-view table { width: 100%; margin-top: 6px; border-collapse: collapse; }
details.table-view th, details.table-view td {
  padding: 3px 4px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
details.table-view td.num, details.table-view th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- map controls ---------- */
.legend {
  max-height: 50vh;
  overflow-y: auto;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  font-size: 13px;
  line-height: 1.5;
}
.legend h3 { margin: 0 0 4px; font-size: 13px; }
.legend .row { display: flex; align-items: center; gap: 6px; }
.legend .swatch {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.25);
}
.legend .ramp { width: 160px; height: 12px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, 0.2); }
.legend .ramp-labels { display: flex; justify-content: space-between; color: var(--ink-2); font-size: 12px; }
.legend .line-swatch { flex: none; width: 14px; height: 0; border-top: 2px dashed #000; }

.popup-table { border-collapse: collapse; font-size: 13px; }
.popup-table th { padding: 2px 10px 2px 0; color: var(--ink-2); font-weight: normal; text-align: left; vertical-align: top; }
.popup-table td { padding: 2px 0; }
.leaflet-popup-content h4 { margin: 0 0 6px; font-size: 14px; }

/* ---------- text pages ---------- */
.text-page { height: 100%; overflow-y: auto; }
.text-page article {
  max-width: 900px;
  margin: 2rem auto;
  padding: 1.5rem;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  line-height: 1.6;
}
.text-page h1 { margin-top: 0; color: var(--brand); font-size: 1.6rem; }
.text-page h2 { color: var(--brand); font-size: 1.2rem; margin-top: 1.5rem; }
.text-page a { color: var(--brand); }
.callout {
  margin: 1.5rem 0;
  padding: 1rem;
  background: var(--brand-tint);
  border-left: 4px solid var(--brand);
  border-radius: 4px;
}
.poster-frame {
  width: 100%;
  height: 80vh;
  border: 1px solid var(--line);
  border-radius: 4px;
}

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .site-header { gap: 8px; padding: 0 8px; }
  .brand { padding: 6px 10px; font-size: 14px; }
  .main-nav a { font-size: 14px; padding: 6px 10px; }
  .map-page.active { height: auto; }
  main { height: auto; }
  .page.active.page-iframe { height: calc(100vh - var(--header-h)); }
  .map-layout { flex-direction: column-reverse; }
  .map { flex: none; height: 65vh; }
  .sidebar { width: 100%; border-right: 0; border-top: 1px solid var(--line); }
  .text-page article { margin: 1rem; padding: 1rem; }
  .legend { max-height: 30vh; font-size: 12px; }
}
