html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

#panel {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  width: 280px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  padding: 10px 14px 12px;
  font-size: 14px;
}

#panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#panel-header h1 {
  margin: 0;
  font-size: 18px;
}

#collapse {
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  color: #444;
  transition: transform 0.15s;
}

#panel.collapsed #collapse {
  transform: rotate(180deg);
}

#panel.collapsed #panel-body {
  display: none;
}

#search-wrap {
  position: relative;
  margin-bottom: 8px;
}

#search {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid #bbb;
  border-radius: 6px;
  font-size: 14px;
}

#search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1100;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  max-height: 240px;
  overflow-y: auto;
}

#search-results button {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: none;
  text-align: left;
  font-size: 13.5px;
  cursor: pointer;
}

#search-results button:hover,
#search-results button:focus-visible {
  background: #eef4fb;
}

#result {
  margin: 10px 0;
  padding: 8px;
  background: #eef4fb;
  border-radius: 6px;
  min-height: 2.4em;
}

#buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#buttons button {
  flex: 1 1 40%;
}

#n50-row {
  display: block;
  margin-top: 8px;
  cursor: pointer;
  font-size: 13.5px;
}

.elev-svg {
  display: block;
  width: 100%;
  height: 56px;
  margin-top: 6px;
  background: #fff;
  border-radius: 4px;
}

.elev-label {
  font-size: 9px;
  fill: #888;
}

.gray-btn {
  font-size: 18px;
  text-align: center;
}

.gray-btn.active {
  color: #1565c0;
}

.legend-n50 {
  border-top: 3px dotted #7b4a12;
}

/* Terrengrute-seksjonen */
#terrain-sec {
  margin-top: 10px;
  border-top: 1px solid #ddd;
  padding-top: 6px;
}

#terrain-sec summary {
  cursor: pointer;
  font-weight: 600;
  padding: 4px 0;
}

#tr-points {
  width: 100%;
  padding: 8px 0;
  margin: 6px 0;
  border: 1px dashed #e65100;
  border-radius: 6px;
  background: #fff;
  color: #e65100;
  cursor: pointer;
}

#tr-points.active {
  background: #e65100;
  color: #fff;
  border-style: solid;
}

.tr-param {
  margin: 6px 0 2px;
}

.tr-param label {
  display: block;
  font-size: 13px;
}

.tr-param input[type='range'] {
  width: 100%;
}

.tr-check {
  display: block;
  font-size: 13px;
  margin: 4px 0;
  cursor: pointer;
}

#tr-buttons {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

#tr-buttons button {
  flex: 1;
  padding: 8px 0;
  border: 1px solid #bbb;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

#tr-buttons button:disabled {
  opacity: 0.5;
  cursor: default;
}

#tr-result {
  margin-top: 8px;
  font-size: 13.5px;
}

#tr-result:not(:empty) {
  padding: 8px;
  background: #fff3e8;
  border-radius: 6px;
}

#buttons button {
  flex: 1;
  padding: 6px 0;
  border: 1px solid #bbb;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

#buttons button:disabled {
  opacity: 0.5;
  cursor: default;
}

#buttons button:not(:disabled):hover {
  background: #f0f0f0;
}

#status {
  margin-top: 8px;
  min-height: 1.2em;
}

.dim {
  color: #666;
  font-size: 12.5px;
}

/* «Finn meg»-knappen (Leaflet-kontroll) */
.locate-btn {
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  color: #444;
}

.locate-btn.pending {
  color: #888;
  animation: locate-pulse 1s ease-in-out infinite;
}

.locate-btn.follow {
  color: #1565c0;
}

.locate-btn.passive {
  color: #7ba7d7;
}

@keyframes locate-pulse {
  50% { opacity: 0.4; }
}

/* Tegnforklaring */
.legend {
  background: rgba(255, 255, 255, 0.92);
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.7;
  border-radius: 6px;
}

.legend-line {
  display: inline-block;
  width: 26px;
  height: 0;
  margin-right: 4px;
  vertical-align: middle;
}

.legend-trail {
  border-top: 3px dashed #d32f2f;
}

.legend-route {
  border-top: 4px solid #1565c0;
  box-shadow: 0 0 0 1.5px #fff;
}

/* Popup-knappen «Mål herfra» */
.trail-popup .popup-measure {
  margin-top: 8px;
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: #1565c0;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

.trail-popup .popup-measure:hover {
  background: #0f4c8c;
}

/* Synlig tastaturfokus */
button:focus-visible,
#search:focus-visible,
.locate-btn:focus-visible {
  outline: 2px solid #1565c0;
  outline-offset: 2px;
}

/* Mobil: panelet blir en kollapsbar bunn-sheet, store treffflater */
@media (max-width: 600px) {
  #panel {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: auto;
    border-radius: 14px 14px 0 0;
    max-height: 55%;
    overflow-y: auto;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  #collapse {
    min-width: 44px;
    min-height: 44px;
    font-size: 20px;
  }

  #search {
    padding: 11px 10px;
    font-size: 16px; /* <16px trigger auto-zoom i iOS Safari */
  }

  #search-results button {
    padding: 12px 10px;
    font-size: 15px;
  }

  #buttons button {
    min-height: 44px;
    font-size: 15px;
  }

  .locate-btn {
    width: 44px;
    height: 44px;
  }

  /* Leaflet zoom-knapper: større treffflater på touch */
  .leaflet-touch .leaflet-bar a {
    width: 44px;
    height: 44px;
    line-height: 44px;
  }
}
