html, body {
  margin: 0;
  height: 100%;
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #1f2933;
}

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

.panel {
  position: absolute;
  z-index: 2;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  box-sizing: border-box;
}

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* Search */

#search {
  z-index: 3;
  top: 12px;
  right: 12px;
  width: 360px;
  padding: 0;
}

#search input {
  width: 100%;
  box-sizing: border-box;
  border: 0;
  border-radius: 6px;
  padding: 12px;
  font: inherit;
  font-size: 15px;
  background: transparent;
  outline: none;
}

#search ul {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  border-top: 1px solid #e5e7eb;
  max-height: 60vh;
  overflow-y: auto;
}

#search li {
  display: flex;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
}

#search li .icon {
  flex: none;
  width: 1em;
  text-align: center;
  color: #6b7785;
}

#search li.active, #search li:not(.item-muted):hover {
  background: #eef4ff;
}

#search li.item-muted {
  color: #8a94a0;
  font-style: italic;
  cursor: default;
}

/* Summary */

#summary {
  top: 64px;
  right: 12px;
  width: 360px;
  padding: 12px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
}

#summary .error {
  color: #c62828;
  margin-bottom: 6px;
}

#summary .route + .route,
#summary .error + .route {
  margin-top: 10px;
}

#summary .route-header {
  font-weight: 600;
}

#summary .dot {
  margin-right: 6px;
}

#summary .legs {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 12px;
  padding-left: 18px;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

#summary .dist {
  text-align: right;
}

#summary .total {
  font-weight: 600;
}

#summary .ranges {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 12px;
  font-variant-numeric: tabular-nums;
}

#summary > .units {
  justify-content: flex-end;
  margin-top: 10px;
}

/* mi | km | nm toggle (summary panel and popover) */

.units {
  display: flex;
  flex: none;
}

.units button {
  border: 1px solid #d0d5dc;
  background: #fff;
  padding: 2px 10px;
  font-size: 12px;
}

.units button + button { border-left: 0; }
.units button:first-child { border-radius: 4px 0 0 4px; }
.units button:last-child { border-radius: 0 4px 4px 0; }
.units button.on { background: #1f6feb; border-color: #1f6feb; color: #fff; }

/* Buttons */

#buttons {
  left: 12px;
  bottom: 28px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
}

#buttons button, .popover-actions > button, .popover-range > button {
  border: 1px solid #d0d5dc;
  background: #fff;
  border-radius: 4px;
  padding: 5px 10px;
  text-align: left;
}

#buttons select {
  font: inherit;
  color: inherit;
  border: 1px solid #d0d5dc;
  background: #fff;
  border-radius: 4px;
  padding: 4px 6px;
  cursor: pointer;
}

#buttons button:hover, .popover-actions > button:hover, .popover-range > button:hover {
  background: #f3f5f8;
}

/* Popover */

.maplibregl-popup-content {
  border-radius: 6px;
  padding: 12px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
}

.popover-title {
  font-weight: 600;
  padding-right: 14px;
}

.popover-coords {
  display: block;
  border: 0;
  background: none;
  padding: 2px 0 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: #52606d;
}

.popover-coords:hover { color: #1f6feb; }

.popover-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.popover-range {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-block: 4px;
  padding-block: 6px;
  border-block: 1px solid #e5e7eb;
}

.popover-range-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.popover-range-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  border: 1px solid #d0d5dc;
  border-radius: 4px;
  padding: 3px 6px;
}

.popover-range-row .units button {
  padding: 2px 7px;
}

@media (max-width: 480px) {
  #search, #summary {
    width: calc(100% - 24px);
  }
  .maplibregl-ctrl-top-left {
    display: none; /* covered by the search box; pinch to zoom */
  }
  #buttons {
    bottom: 56px;
  }
  #summary {
    max-height: 40vh;
  }
}
