:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #5a6878;
  --line: #d9e2ec;
  --panel: #ffffff;
  --land: #dbe7d1;
  --water: #d7ecf4;
  --accent: #136f63;
  --warn: #ad5f00;
  --high: #b3261e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #eef3f0;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

.shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  font-weight: 700;
}

h2 {
  font-size: 16px;
  margin-bottom: 10px;
}

#freshness {
  color: var(--muted);
  margin-top: 4px;
}

.page-links {
  margin-top: 8px;
  font-size: 13px;
}

.page-links a,
.source-card a,
.source-row a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.page-links a:hover,
.source-card a:hover,
.source-row a:hover {
  text-decoration: underline;
}

.controls {
  display: flex;
  border: 1px solid var(--line);
  background: var(--panel);
}

.controls button {
  min-width: 110px;
  border: 0;
  border-right: 1px solid var(--line);
  padding: 10px 12px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.controls button:last-child {
  border-right: 0;
}

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

.view-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 0;
  align-items: center;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: var(--panel);
  padding: 10px 12px;
}

.view-tabs button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-width: 106px;
  min-height: 34px;
  padding: 8px 12px;
  cursor: pointer;
}

.view-tabs button.active {
  background: #17202a;
  color: #fff;
}

.terrain-toggle,
.view-action {
  margin-left: 0;
}

.terrain-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 8px;
  color: var(--ink);
  font-size: 13px;
}

.view-action {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-width: 96px;
  min-height: 34px;
  padding: 8px 12px;
  cursor: pointer;
}

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

.local-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 12px;
  margin-bottom: 12px;
}

.local-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 10px;
}

#local-status {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.location-controls {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 8px;
  width: min(760px, 100%);
}

.location-controls input,
.location-controls button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 9px;
  min-height: 34px;
}

.location-controls button {
  cursor: pointer;
  background: #17202a;
  color: #fff;
}

.local-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: start;
}

.risk-card {
  border: 1px solid var(--line);
  background: #f8fbf9;
  padding: 9px 10px;
  min-height: 92px;
  align-self: start;
}

.risk-card-wide {
  grid-column: span 2;
}

.risk-card h3 {
  margin: 0 0 6px;
  font-size: 13px;
  line-height: 1.25;
}

.risk-level {
  font-size: 18px;
  font-weight: 700;
  text-transform: capitalize;
  line-height: 1.15;
}

.risk-meta {
  color: var(--muted);
  font-size: 11px;
  margin-top: 5px;
  line-height: 1.28;
}

.risk-list {
  display: grid;
  gap: 5px;
}

.risk-row {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 3px 8px;
  align-items: start;
  border-top: 1px solid var(--line);
  padding-top: 5px;
  font-size: 12px;
}

.risk-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.risk-row span {
  font-weight: 700;
  text-transform: capitalize;
}

.risk-row small {
  grid-column: 2;
  color: var(--muted);
  line-height: 1.25;
  font-size: 11px;
}

.risk-card[data-level="high"],
.risk-card[data-level="very_high"] {
  border-color: #d66a61;
  background: #fff4f2;
}

.risk-card[data-level="moderate"] {
  border-color: #d49a39;
  background: #fff8eb;
}

.risk-card[data-level="unavailable"],
.risk-card[data-level="not_connected"] {
  background: #f5f7f8;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 9px 10px;
}

.stat strong {
  display: block;
  font-size: 20px;
  line-height: 1.15;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

.map-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
  align-items: stretch;
  border-top: 1px solid var(--line);
}

.viz-wrap {
  position: relative;
  min-height: 360px;
  overflow: hidden;
}

canvas,
#globe {
  display: block;
  width: 100%;
  height: auto;
  min-height: 360px;
  background: var(--water);
  border: 1px solid var(--line);
  border-top: 0;
}

#globe {
  display: none;
  height: 620px;
  background: #07131c;
}

.viz-wrap[data-view="globe"] canvas {
  display: none;
}

.viz-wrap[data-view="globe"] #globe {
  display: block;
}

#globe canvas {
  border: 0;
  min-height: 0;
  background: transparent;
}

.map-tools {
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 2;
  display: flex;
  gap: 4px;
}

.map-tools button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  min-width: 32px;
  height: 31px;
  padding: 0 9px;
  cursor: pointer;
}

.legend {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  padding: 12px;
  font-size: 13px;
  line-height: 1.35;
  margin-bottom: 12px;
}

.legend-title {
  font-weight: 700;
  margin-bottom: 7px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(23, 32, 42, 0.18);
  flex: 0 0 auto;
}

.legend-line {
  width: 18px;
  height: 0;
  border-top: 2px solid #647c8a;
  flex: 0 0 auto;
}

.legend-note {
  color: var(--muted);
  margin-top: 8px;
}

.selection {
  background: #f3f7f5;
  border: 1px solid var(--line);
  padding: 10px;
  margin-bottom: 14px;
  font-size: 13px;
  line-height: 1.4;
}

.select-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 5px;
}

#place-focus {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 9px;
  margin-bottom: 14px;
}

.selection strong {
  display: block;
  font-size: 14px;
  margin-bottom: 4px;
}

.signal-list {
  margin-top: 8px;
  border-top: 1px solid var(--line);
}

.signal-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 6px 0;
}

.signal-row span {
  text-transform: capitalize;
}

.signal-row small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  margin-top: 2px;
  text-transform: none;
}

.selection-note {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

#details {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 14px;
  overflow: auto;
}

.source {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.source:first-child {
  border-top: 0;
}

.source-title {
  font-weight: 700;
}

.source-meta,
.source-warn {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

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

.catalog-intro,
.source-section {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 14px;
  margin-bottom: 14px;
}

.catalog-intro p,
.source-section p {
  color: var(--muted);
  line-height: 1.45;
}

.status-key {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}

.status {
  display: inline-block;
  border: 1px solid var(--line);
  background: #f5f7f8;
  color: var(--ink);
  padding: 2px 7px;
  font-size: 11px;
  line-height: 1.5;
  text-transform: uppercase;
  letter-spacing: 0;
}

.status.enabled {
  border-color: #9ac5bb;
  background: #eaf6f1;
  color: #0d5e54;
}

.status.next {
  border-color: #d6b36d;
  background: #fff6dd;
  color: #7a4d00;
}

.status.candidate {
  border-color: #b9c5d6;
  background: #eef4fb;
  color: #2e527c;
}

.status.reference {
  border-color: #d6d2bc;
  background: #f8f6ea;
  color: #5a5638;
}

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

.source-card {
  border: 1px solid var(--line);
  background: #f8fbf9;
  padding: 11px;
  min-height: 170px;
}

.source-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
  margin-bottom: 8px;
}

.source-card h3 {
  font-size: 14px;
  margin: 0;
  line-height: 1.25;
}

.source-card p {
  font-size: 13px;
  margin-bottom: 10px;
}

.source-card a {
  display: block;
  font-size: 12px;
  margin-top: 6px;
}

.schema-code {
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  background: #101820;
  color: #edf7f6;
  padding: 14px;
  font-size: 13px;
  line-height: 1.45;
}

.source-row code,
.schema-code code {
  font-family: Consolas, "Courier New", monospace;
}

.source-table {
  border: 1px solid var(--line);
}

.source-row {
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) minmax(260px, 1.5fr) minmax(180px, 0.9fr);
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 9px 10px;
  font-size: 13px;
  line-height: 1.35;
}

.source-row:first-child {
  border-top: 0;
}

.source-row.header {
  background: #f3f7f5;
  color: var(--muted);
  font-weight: 700;
}

.table-wrap {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 14px;
}

.table-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 12px;
}

#filter-counts {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.table-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
  width: min(720px, 100%);
}

.table-filters label {
  display: block;
}

.table-filters span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.table-filters select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 9px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  border-top: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 700;
}

.level-high,
.level-very_high {
  color: var(--high);
  font-weight: 700;
}

@media (max-width: 860px) {
  .topbar,
  .map-panel {
    display: block;
  }

  .controls {
    margin-top: 12px;
    overflow-x: auto;
  }

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

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

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

  .local-head {
    display: block;
  }

  .location-controls {
    grid-template-columns: 1fr;
    margin-top: 12px;
  }

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

  .risk-card-wide {
    grid-column: span 1;
  }

  #details {
    margin-top: 12px;
  }

  .table-head {
    display: block;
  }

  .table-filters {
    grid-template-columns: 1fr;
    margin-top: 12px;
  }
}
