/* Höhenblick – PWA über TessaDEM */

:root {
  --ink: #0e1a13;
  --ink-2: #1d2f24;
  --paper: #f6f4ee;
  --panel: rgba(16, 32, 23, .88);
  --panel-solid: #10281b;
  --line: rgba(255, 255, 255, .14);
  --green: #3f9b63;
  --green-2: #2f7d4f;
  --amber: #e8a33d;
  --amber-2: #c8811f;
  --text: #eef3ec;
  --muted: #a9bcae;
  --danger: #e2705f;
  --shadow: 0 14px 40px rgba(0, 0, 0, .35);
  --radius: 14px;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--panel-solid);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

a { color: #9fd8b6; }

.skip {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 5000;
  background: #fff;
  color: #000;
  padding: 8px 12px;
  border-radius: 8px;
}
.skip:focus { left: 8px; }

/* ---------- Topbar ---------- */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 1200;
  height: var(--topbar-h);
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(180deg, rgba(10, 22, 15, .96), rgba(10, 22, 15, .82));
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-mark { width: 26px; height: 26px; color: var(--green); flex: none; }
.brand-name {
  font-weight: 700;
  letter-spacing: .2px;
  font-size: 17px;
  white-space: nowrap;
}

.search {
  position: relative;
  flex: 1 1 auto;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, .08);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding-left: 34px;
  transition: border-color .15s, background .15s;
}
.search:focus-within { border-color: var(--green); background: rgba(255, 255, 255, .12); }
.search-icon {
  position: absolute;
  left: 10px;
  width: 17px;
  height: 17px;
  color: var(--muted);
  pointer-events: none;
}
.search input {
  flex: 1;
  min-width: 0;
  height: 38px;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  padding: 0 6px;
  outline: none;
}
.search input::placeholder { color: #91a798; }
.search input::-webkit-search-cancel-button { filter: invert(.7); }
.search-submit {
  height: 30px;
  margin-right: 4px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: var(--green-2);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.search-submit:hover { background: var(--green); }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #12291c;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 300px;
  overflow: auto;
}
.search-results li button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.search-results li button:hover,
.search-results li button:focus-visible { background: rgba(63, 155, 99, .25); }
.search-results small { display: block; color: var(--muted); font-size: 12px; }

.actions { display: flex; gap: 6px; }

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .07);
  color: var(--text);
  cursor: pointer;
  padding: 0;
  transition: background .15s, border-color .15s;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .28); }
.icon-btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.icon-btn.install { color: var(--amber); }
.icon-btn[aria-pressed="true"] {
  color: var(--amber);
  background: rgba(232, 163, 61, .18);
  border-color: rgba(232, 163, 61, .45);
}

/* Vollbild: Karte bis an den Rand, alle Bedienoberflächen weg */
.fullscreen-exit {
  position: absolute;
  z-index: 1300;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  display: none;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 10px;
  background: rgba(10, 22, 15, .72);
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.fullscreen-exit svg { width: 19px; height: 19px; }
.fullscreen-exit:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* Ebenenauswahl + Standort erscheinen nur kurz nach Bewegung/Zoom.
   Alle Vollbild-Elemente liegen rechts: Beenden, Standort, Ebenen. */
.fullscreen-locate {
  position: absolute;
  z-index: 1300;
  top: calc(58px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  display: none;
  background: rgba(10, 22, 15, .72);
  border-color: rgba(255, 255, 255, .22);
  backdrop-filter: blur(8px);
}

body.is-fullscreen .fullscreen-exit { display: grid; }
body.is-fullscreen #mapWrap { inset: 0; }
body.is-fullscreen .topbar,
body.is-fullscreen .legal,
body.is-fullscreen .skip,
body.is-fullscreen .elev-legend,
body.is-fullscreen .map-tools,
body.is-fullscreen .scale-bar,
body.is-fullscreen .hover-badge,
body.is-fullscreen .profile,
body.is-fullscreen .path-bar,
body.is-fullscreen .status,
body.is-fullscreen .offline,
body.is-fullscreen .leaflet-left,
body.is-fullscreen .leaflet-control-layers { display: none !important; }

body.is-fullscreen.fs-hud .fullscreen-locate { display: grid; }
body.is-fullscreen.fs-hud .leaflet-control-layers { display: block !important; }
body.is-fullscreen .leaflet-top.leaflet-right .leaflet-control { margin: 0 !important; }
body.is-fullscreen.fs-hud .leaflet-top.leaflet-right {
  top: calc(106px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
}

/* Ebenen-Kachel wie die Vollbild-Buttons: 38x38, gleiche Kante, gleiches Panel */
body.is-fullscreen.fs-hud .leaflet-control-layers:not(.leaflet-control-layers-expanded) {
  padding: 0 !important;
  background: transparent !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}
body.is-fullscreen.fs-hud .leaflet-control-layers-toggle {
  width: 38px !important;
  height: 38px !important;
  line-height: 38px !important;
  background-color: rgba(10, 22, 15, .72) !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3 3 8l9 5 9-5-9-5Z' fill='none' stroke='%23eef3ec' stroke-width='1.8' stroke-linejoin='round'/%3E%3Cpath d='m3 12 9 5 9-5M3 16l9 5 9-5' fill='none' stroke='%23eef3ec' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
  background-size: 19px 19px !important;
  background-position: center !important;
  background-repeat: no-repeat !important;
  border: 1px solid rgba(255, 255, 255, .22) !important;
  border-radius: 10px !important;
  box-shadow: none !important;
  backdrop-filter: blur(8px);
}
body.is-fullscreen.fs-hud .leaflet-control-layers-toggle:hover {
  background-color: rgba(255, 255, 255, .14) !important;
}
body.is-fullscreen.fs-hud .leaflet-control-layers-toggle:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

/* Pflicht-Nennung der Kartenquellen bleibt sichtbar, aber sehr unauffällig */
body.is-fullscreen .leaflet-control-attribution {
  background: rgba(10, 22, 15, .55) !important;
  font-size: 9px !important;
  padding: 1px 5px !important;
}

/* Standortpfeil (Kompassrichtung) */
.locator-icon { background: transparent; border: 0; }
.locator-arrow {
  width: 26px;
  height: 26px;
  transform-origin: 50% 50%;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .55));
}
.locator-arrow svg { display: block; width: 100%; height: 100%; }

/* ---------- Map ---------- */

#mapWrap {
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
}
#map { width: 100%; height: 100%; background: #0d1b13; }

.leaflet-container { font: inherit; }
.leaflet-control-attribution {
  background: rgba(10, 22, 15, .78) !important;
  color: #cfe0d4 !important;
  font-size: 11px !important;
  padding: 3px 8px !important;
}
.leaflet-control-attribution a { color: #9fd8b6 !important; }
.leaflet-bar a {
  background: rgba(16, 32, 23, .92) !important;
  color: #eef3ec !important;
  border-color: var(--line) !important;
}
.leaflet-bar a:hover { background: #1d3a28 !important; }
.leaflet-control-layers {
  background: rgba(16, 32, 23, .92) !important;
  color: var(--text) !important;
  border: 1px solid var(--line) !important;
  border-radius: 10px !important;
}
.leaflet-control-layers-separator { border-top-color: var(--line) !important; }
.leaflet-bottom.leaflet-right { bottom: 22px; }

.leaflet-tooltip.elev-tip {
  background: rgba(10, 22, 15, .92);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  box-shadow: none;
  font-size: 12px;
}
.leaflet-tooltip.elev-tip::before { display: none; }

.point-pin {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #1c6fd4;
  border: 2.5px solid #fff;
  box-shadow: 0 0 0 2px rgba(28, 111, 212, .25), 0 3px 8px rgba(0, 0, 0, .35);
}

/* ---------- Höhenlegende ---------- */

.elev-legend {
  position: absolute;
  z-index: 900;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  height: 66%;
  min-height: 190px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 11px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  pointer-events: none;
}
.legend-title {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--muted);
}
.legend-scale {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 48px;
}
.legend-ramp {
  width: 48px;
  height: 100%;
  border: 1px solid rgba(255, 255, 255, .42);
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}
/* Zahlen liegen direkt in der Farbskala */
.legend-ticks {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 3px 3px 4px;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  color: rgba(20, 42, 30, .88);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 1px rgba(255, 255, 255, .55);
}

/* ---------- Tools ---------- */

.map-tools {
  position: absolute;
  z-index: 900;
  top: 14px;
  left: 60px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.tool {
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 96px;
  text-align: left;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}
.tool:hover { background: rgba(255, 255, 255, .1); }
.tool[aria-pressed="true"] {
  background: rgba(63, 155, 99, .3);
  color: #d9f5e3;
  box-shadow: inset 2px 0 0 var(--green);
}

/* ---------- Maßstab ---------- */

.scale-bar {
  position: absolute;
  z-index: 900;
  left: 14px;
  bottom: 24px;
  min-width: 74px;
  padding: 3px 8px 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  color: var(--text);
  pointer-events: none;
}
.scale-bar-label {
  margin-bottom: 3px;
  text-align: center;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.scale-bar-line {
  height: 6px;
  min-width: 40px;
  border: 1.5px solid var(--text);
  background: linear-gradient(90deg, var(--text) 0 50%, transparent 50% 100%);
}

.hover-badge {
  position: absolute;
  z-index: 950;
  pointer-events: none;
  padding: 4px 8px;
  border-radius: 7px;
  background: rgba(10, 22, 15, .94);
  border: 1px solid var(--line);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  transform: translate(14px, -140%);
  white-space: nowrap;
}

/* ---------- Profile ---------- */

.profile {
  position: absolute;
  z-index: 1000;
  left: 14px;
  right: 14px;
  bottom: 56px;
  padding: 12px 16px 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}
.profile-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.profile-head h2 { margin: 0; font-size: 14px; letter-spacing: .3px; text-transform: uppercase; color: var(--muted); }
.profile-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--text);
}
.profile-stats b { color: var(--amber); font-variant-numeric: tabular-nums; }
.profile-canvas-wrap { position: relative; height: 168px; margin-top: 6px; }
#profileCanvas { width: 100%; height: 100%; display: block; }

/* ---------- Path bar / hint / status ---------- */

body.has-profile .path-bar { display: none !important; }

.path-bar {
  position: absolute;
  z-index: 1000;
  right: 14px;
  bottom: 56px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  font-size: 13px;
  white-space: nowrap;
}
.path-bar strong { color: var(--amber); }

.btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 11px;
  background: rgba(255, 255, 255, .07);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: rgba(255, 255, 255, .14); }
.btn.primary { background: var(--green-2); border-color: transparent; font-weight: 600; }
.btn.primary:hover { background: var(--green); }
.btn.ghost { background: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.status {
  position: absolute;
  z-index: 1100;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 10px;
  background: #3a2018;
  border: 1px solid rgba(226, 112, 95, .5);
  color: #ffd9d2;
  font-size: 13px;
  max-width: min(92vw, 560px);
  box-shadow: var(--shadow);
}
.status.info { background: #14291d; border-color: rgba(63, 155, 99, .5); color: #d7f2e0; }

.offline {
  position: absolute;
  z-index: 1100;
  top: 0;
  left: 0;
  right: 0;
  padding: 6px 12px;
  text-align: center;
  background: var(--amber-2);
  color: #1a1205;
  font-size: 12.5px;
  font-weight: 600;
}

.legal {
  position: fixed;
  z-index: 1100;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 3px 10px;
  background: rgba(10, 22, 15, .82);
  border-top: 1px solid var(--line);
  font-size: 10.5px;
  color: var(--muted);
  text-align: right;
  pointer-events: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.legal a { color: #a9d8bd; }

/* ---------- Dialog ---------- */

.sheet {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  width: min(560px, calc(100vw - 28px));
  background: #10281b;
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
.sheet::backdrop { background: rgba(4, 10, 6, .62); backdrop-filter: blur(3px); }
.sheet-inner { padding: 18px 20px 20px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-size: 18px; }

.field { display: block; margin-bottom: 14px; font-size: 13px; }
.field > span { display: block; margin-bottom: 5px; color: var(--muted); font-weight: 600; }
.field input, .field select {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.field select option { background: #10281b; }
.field small { display: block; margin-top: 5px; color: #8ba494; font-size: 11.5px; line-height: 1.4; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 4px 0 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .04);
}
.stats div { text-align: center; }
.stats span { display: block; font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats small { color: var(--muted); font-size: 11px; }

.sheet-error {
  margin: 0 0 12px;
  padding: 8px 10px;
  border: 1px solid rgba(226, 112, 95, .45);
  border-radius: 8px;
  background: rgba(226, 112, 95, .12);
  color: #ffbcb1;
  font-size: 12.5px;
}

.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.sheet-actions .btn { flex: 0 0 auto; }
.sheet-note { margin: 14px 0 0; font-size: 11.5px; color: #8ba494; line-height: 1.5; }

/* ---------- Meine Orte ---------- */

.place-save { width: 100%; margin-bottom: 12px; }
.place-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 46vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.place-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .04);
}
.place-open {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.place-open:hover, .place-open:focus-visible { background: rgba(63, 155, 99, .25); }
.place-open strong { display: block; font-size: 13.5px; font-weight: 600; }
.place-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.place-delete {
  width: 30px;
  height: 30px;
  flex: none;
  font-size: 15px;
  line-height: 1;
}
.places-empty {
  margin: 0;
  padding: 16px 0;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- Mobile ---------- */

@media (max-width: 760px) {
  :root { --topbar-h: 100px; }
  .topbar { flex-wrap: wrap; height: var(--topbar-h); align-content: center; gap: 8px; padding: 8px 10px; }
  .brand { order: 1; }
  .actions { order: 2; margin-left: auto; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .search input { height: 36px; }
  .search-submit { display: none; }
  .brand-name { font-size: 15px; }

  .leaflet-top.leaflet-left { display: none; }
  .elev-legend {
    right: 8px;
    height: 62%;
    min-height: 150px;
    padding: 8px 9px;
    gap: 6px;
  }
  .legend-ramp, .legend-scale { width: 42px; }
  .legend-ticks { font-size: 8.5px; padding: 2px 2px 3px; }
  .map-tools {
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: auto;
    flex-direction: row;
    overflow-x: auto;
    padding: 5px;
  }
  .status { top: 54px; }
  .tool {
    flex: 0 0 auto;
    min-width: 0;
    padding: 7px 10px;
    font-size: 12.5px;
    white-space: nowrap;
  }

  .scale-bar { left: 10px; bottom: 22px; padding: 3px 7px; }
  .scale-bar-label { font-size: 10px; }

  .profile { left: 8px; right: 8px; bottom: 50px; padding: 10px 12px 6px; }
  .profile-canvas-wrap { height: 132px; }

  .path-bar {
    left: 8px;
    right: 8px;
    bottom: 50px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .legal { font-size: 9.5px; padding: 2px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* Leaflet + dark UI tweaks */
/* Höhen-Popup im Stil von topographic-map.com (hell, klar) */
.leaflet-popup-content-wrapper {
  background: #fff;
  color: #16281d;
  border-radius: 12px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .32);
}
.leaflet-popup-tip { background: #fff; box-shadow: none; }
.leaflet-popup-content { margin: 10px 14px 11px; line-height: 1.2; font-size: 13px; }
.leaflet-popup-close-button { color: #5f7568 !important; font-size: 18px !important; padding: 6px 6px 0 0 !important; }
.leaflet-popup-close-button:hover { color: #16281d !important; }

.elev-popup { min-width: 116px; }
.elev-popup-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.4px;
  color: #0f4d2c;
  font-variant-numeric: tabular-nums;
}
.elev-popup-value span { font-size: 13px; font-weight: 600; color: #5f7568; }
.elev-popup-label {
  margin-top: 3px;
  font-size: 11.5px;
  color: #6a7f72;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.elev-popup-source {
  margin-top: 2px;
  font-size: 10px;
  color: #3f9b63;
  font-weight: 600;
  white-space: nowrap;
}
