:root {
  --bg: #f4f6f3;
  --panel: #ffffff;
  --panel-soft: #fafbf8;
  --ink: #1b2421;
  --muted: #66736d;
  --line: #d9dfd8;
  --accent: #2f6654;
  --accent-strong: #204d40;
  --amber: #bd6a31;
  --blue: #2e5f8f;
  --missing: #d7ddd8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body,
.app-shell {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 440px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.app-header,
.toolbar,
.dataset-list,
.controls,
.details {
  padding: 18px 22px;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

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

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

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.08;
}

h2 {
  margin-bottom: 10px;
  font-size: 17px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 8px;
  font-size: 14px;
}

.status {
  flex: 0 0 auto;
  min-width: 64px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.toolbar,
.controls {
  display: grid;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

select,
input[type="search"],
input[type="number"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.dataset-list {
  display: grid;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.dataset-button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.dataset-button strong {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
}

.dataset-button span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.dataset-button.is-active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.range-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.range-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.details {
  display: grid;
  gap: 14px;
}

.detail-muted,
.details p,
.metric span,
.legend-note {
  color: var(--muted);
}

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

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

.metric span {
  display: block;
  margin-bottom: 5px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.record-list {
  display: grid;
  gap: 10px;
}

.record-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.record-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-weight: 800;
}

.action-button,
.segment-button {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
  color: var(--accent-strong);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.action-button:disabled {
  border-color: var(--line);
  color: var(--muted);
  cursor: not-allowed;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 100vh;
}

#map {
  position: absolute;
  inset: 0;
}

.legend {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 500;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 36px));
  border: 1px solid rgba(40, 52, 47, 0.16);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 26px rgba(30, 40, 36, 0.12);
  font-size: 12px;
}

.legend:empty { display: none; }

.legend-bar {
  height: 12px;
  margin: 10px 0 7px;
  border-radius: 999px;
  background: linear-gradient(90deg, #f1f0b0, #d79645, #8f2d22);
}

.legend-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.marker-dot {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 8px 18px rgba(12, 32, 55, 0.25);
  font-size: 10px;
  font-weight: 900;
}

.marker-dot.high {
  background: var(--amber);
}

.ec-site-icon {
  overflow: visible;
  background: transparent;
  border: 0;
}

.ec-site-marker {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  white-space: nowrap;
}

.ec-site-dot {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 3px 9px rgba(12, 32, 55, 0.28);
}

.ec-site-label {
  padding: 2px 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.82);
  color: #24302b;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.2;
  text-shadow: 0 1px 0 #fff;
}

.measure-control {
  display: flex;
  overflow: hidden;
  background: #fff;
}

.measure-control button {
  width: auto;
  min-width: 58px;
  height: 30px;
  border: 0;
  border-right: 1px solid #ccc;
  padding: 0 9px;
  background: #fff;
  color: var(--ink);
  font: 700 11px/30px Inter, ui-sans-serif, system-ui, sans-serif;
  cursor: pointer;
}

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

.measure-control button:hover,
.measure-control button:focus-visible,
.measure-control .is-active {
  background: var(--accent);
  color: #fff;
}

.measure-control button:disabled {
  background: #f2f4f1;
  color: #9aa39e;
  cursor: default;
}

#map.is-measuring {
  cursor: crosshair;
}

.distance-tooltip {
  border: 1px solid rgba(32, 77, 64, 0.28);
  border-radius: 4px;
  color: var(--ink);
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
}

.modal.is-open {
  display: block;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 21, 0.38);
}

.modal-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  display: flex;
  flex-direction: column;
  width: min(980px, calc(100vw - 34px));
  max-height: min(760px, calc(100vh - 34px));
  transform: translate(-50%, -50%);
  overflow: hidden;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(9, 16, 13, 0.24);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 20px;
  cursor: pointer;
}

.modal-tools {
  padding: 12px 20px 0;
}

.modal-tools:empty { display: none; }

.modal-body {
  min-height: 0;
  overflow: auto;
  padding: 14px 20px 20px;
}

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 280px;
}

.chart-grid {
  stroke: #e4e8e3;
  stroke-width: 1;
}

.chart-axis {
  stroke: #7b8781;
  stroke-width: 1.2;
}

.chart-label {
  fill: #66736d;
  font-size: 12px;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-point {
  fill: var(--amber);
  stroke: #fff;
  stroke-width: 2;
}

.chart-crosshair {
  stroke: rgba(32, 77, 64, 0.58);
  stroke-width: 1.4;
  stroke-dasharray: 4 4;
  pointer-events: none;
}

.chart-value-tag rect {
  fill: rgba(255, 255, 255, 0.95);
  stroke: var(--line);
}

.chart-hitbox {
  fill: transparent;
  cursor: crosshair;
}

.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel-soft);
  color: var(--muted);
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(360px, 48vh) minmax(480px, 52vh);
  }

  .sidebar {
    order: 2;
    height: auto;
    min-height: 52vh;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .map-stage {
    order: 1;
    min-height: 360px;
  }

  .control-grid,
  .summary-grid,
  .metric-grid,
  .range-pair {
    grid-template-columns: 1fr;
  }
}


.legend-swatch-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  margin-top: 10px;
}

.legend-swatch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.legend-swatch i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
