/* ---------------------------------------------------------------------------
   conduco maps – Kartenansicht.

   Die Farben der Bedienoberfläche folgen dem jeweils geladenen Kartenstil,
   nicht dem Betriebssystem des Besuchers: bei dunkler Karte wäre eine helle
   Suchkarte ein Fremdkörper. Der Stil selbst richtet sich beim ersten Besuch
   nach prefers-color-scheme (siehe app.js) – danach gilt die Wahl des
   Besuchers. Deshalb hängen alle Tokens an [data-flavor] auf <html>, nicht an
   einer Media Query.
   --------------------------------------------------------------------------- */

:root,
:root[data-flavor="light"] {
  --ground:   #FAFAFC;
  --chrome:   #ffffff;
  --chrome-2: #f1f1f4;
  --text:     #212125;
  --text-2:   #6a6a75;
  --line:     #e2e2e7;
  --accent:   #2642d3;
  --shadow:   0 1px 2px rgba(33, 33, 37, .12), 0 8px 24px -8px rgba(33, 33, 37, .28);
  --scrim:    rgba(255, 255, 255, .82);
  --icon-invert: 0;
}

:root[data-flavor="dark"] {
  --ground:   #212125;
  --chrome:   #2b2b31;
  --chrome-2: #35353c;
  --text:     #f2f2f5;
  --text-2:   #a0a0ac;
  --line:     #3d3d45;
  --accent:   #60cdfe;
  --shadow:   0 1px 2px rgba(0, 0, 0, .4), 0 8px 28px -8px rgba(0, 0, 0, .75);
  --scrim:    rgba(33, 33, 37, .82);
  /* MapLibre liefert seine Symbole als schwarze Hintergrundgrafiken. Auf
     dunklem Grund müssen sie invertiert werden – sie tragen keine currentColor. */
  --icon-invert: 1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ground);
  color: var(--text);
  /* Barlow läuft schmaler und etwas kleiner als die Systemschriften – 15.5px
     hält die Zeilen auf derselben optischen Größe wie zuvor. */
  font: 15.5px/1.5 "Barlow", ui-sans-serif, -apple-system, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* dvh statt vh: sonst schiebt die Adressleiste mobiler Browser den unteren
   Rand der Karte aus dem Bild. */
#map {
  position: fixed;
  inset: 0;
  height: 100dvh;
}

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Wortmarke ------------------------------------------------------------ */

.brand {
  position: fixed;
  z-index: 3;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 13px 0 10px;
  background: var(--chrome);
  border-radius: 17px;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -.01em;
  text-decoration: none;
  white-space: nowrap;
}

/* Das Icon ist breiter als hoch (217:185) – die Höhe ist das Maß, sonst
   springt die Grundlinie des Schriftzugs. */
.brand-mark { width: 22px; height: 19px; flex: none; display: block; }

/* --- Suche ---------------------------------------------------------------- */

.search {
  position: fixed;
  z-index: 4;
  top: 12px;
  right: 12px;
  width: 372px;
  max-width: calc(100vw - 24px);
  background: var(--chrome);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 0 14px;
  height: 48px;
}

.search-icon { flex: none; color: var(--text-2); }

.search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--text);
}

.search input::placeholder { color: var(--text-2); }
.search input:focus { outline: none; }
.search input::-webkit-search-cancel-button { display: none; }

.icon-btn {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text-2);
  cursor: pointer;
}

.icon-btn:hover { background: var(--chrome-2); color: var(--text); }
.icon-btn[hidden] { display: none; }

/* Trefferliste. Sie sitzt in derselben Karte wie das Eingabefeld, getrennt
   nur durch eine Linie – ein zweiter Schatten direkt darunter wirkt unruhig. */
.results {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  border-top: 1px solid var(--line);
  max-height: min(340px, 60dvh);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.results[hidden] { display: none; }

.results li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 9px 14px;
  cursor: pointer;
}

.results li:hover,
.results li[aria-selected="true"] { background: var(--chrome-2); }

.results .kind {
  flex: none;
  width: 30px;
  height: 30px;
  margin-top: 1px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--chrome-2);
  color: var(--text-2);
}

.results li[aria-selected="true"] .kind { background: var(--chrome); }

.results .label { min-width: 0; display: block; }

.results .name,
.results .addr {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.results .name { font-size: 14px; font-weight: 500; }
.results .name b { font-weight: 700; }
.results .addr { font-size: 12.5px; color: var(--text-2); }

/* Hinweiszeile (nichts gefunden, Dienst nicht erreichbar). Kein Listeneintrag,
   deshalb ohne Zeigefinger und ohne Hover. */
.results .note {
  padding: 14px;
  font-size: 13.5px;
  color: var(--text-2);
  cursor: default;
}

.results .note:hover { background: none; }

/* --- Routenplanung -------------------------------------------------------- */
/* Sitzt an derselben Stelle wie die Suche und ersetzt sie: zwei Karten
   übereinander in derselben Ecke wären beide halb verdeckt. */

.route {
  position: fixed;
  z-index: 4;
  top: 12px;
  right: 12px;
  width: 372px;
  max-width: calc(100vw - 24px);
  padding: 10px 10px 8px;
  background: var(--chrome);
  border-radius: 14px;
  box-shadow: var(--shadow);
  animation: einblenden .22s cubic-bezier(.22, 1, .36, 1);
}

.route[hidden] { display: none; }

body.routenmodus .search { display: none; }

.route-top { display: flex; align-items: flex-start; gap: 4px; }
.route-fields { flex: 1; min-width: 0; }
.route-side { display: flex; flex-direction: column; gap: 2px; padding-top: 3px; }

/* Die Vorschlagsliste hängt absolut darunter – deshalb der Bezugsrahmen. */
.route-field { position: relative; }
.route-field + .route-field { margin-top: 6px; }

/* Verbindung zwischen Start- und Zielpunkt, wie auf der Karte. */
.route-field + .route-field::before {
  content: "";
  position: absolute;
  left: 15px;
  top: -8px;
  width: 2px;
  height: 10px;
  border-radius: 1px;
  background: var(--line);
}

.route-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 4px 0 8px;
  border-radius: 10px;
  background: var(--chrome-2);
}

/* Der Fokusring gehört um die ganze Zeile, nicht um das nackte Feld darin. */
.route-row:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }

.route-pin {
  flex: none;
  width: 11px;
  height: 11px;
  margin-left: 2px;
  border-radius: 50%;
}

/* Dieselben Farben wie die Nadeln auf der Karte – siehe FARBE_START und
   FARBE_ZIEL in routing.js. */
.route-pin.start { background: #39C2FF; }
.route-pin.ziel  { background: #2642D3; }

.route-row input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 14.5px;
  color: var(--text);
}

.route-row input::placeholder { color: var(--text-2); }
.route-row input:focus { outline: none; }
.route-row input::-webkit-search-cancel-button { display: none; }

.route-row .icon-btn { width: 28px; height: 28px; }
.route-row .icon-btn:hover { background: var(--chrome); }
.route-row .icon-btn:disabled { opacity: .5; cursor: default; }

/* Die Vorschläge legen sich über das zweite Feld, statt es nach unten zu
   schieben – sonst springt das Ziel weg, während man den Start tippt. */
.results.pop {
  position: absolute;
  z-index: 2;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  border-top: 0;
  border-radius: 12px;
  background: var(--chrome);
  box-shadow: var(--shadow);
  max-height: min(280px, 44dvh);
}

.route-modes {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  padding: 0 2px;
}

.mode {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  border-radius: 9px;
  background: var(--chrome-2);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

/* Das Radio bleibt bedienbar, nur unsichtbar: Pfeiltasten, Gruppierung und
   Screenreader-Ansage kommen so vom Browser statt aus ARIA-Attributen. */
.mode input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.mode:hover { color: var(--text); }
.mode:has(input:checked) { background: var(--accent); color: var(--chrome); }
.mode:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.route-hint {
  margin: 9px 4px 2px;
  font-size: 11.5px;
  color: var(--text-2);
}

/* --- Trefferkarte --------------------------------------------------------- */

.place {
  position: fixed;
  z-index: 3;
  top: 72px;
  right: 12px;
  width: 372px;
  max-width: calc(100vw - 24px);
  padding: 14px 16px 12px;
  background: var(--chrome);
  border-radius: 14px;
  box-shadow: var(--shadow);
  transform-origin: top right;
  animation: einblenden .22s cubic-bezier(.22, 1, .36, 1);
}

.place[hidden] { display: none; }

@keyframes einblenden {
  from { opacity: 0; transform: translateY(-6px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.grabber { display: none; }

.place-head { display: flex; align-items: flex-start; gap: 12px; }
.place-label { flex: 1; min-width: 0; }

.place-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.place-addr {
  margin: 2px 0 0;
  font-size: 13.5px;
  color: var(--text-2);
}

.place-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.place-meta:empty { display: none; }

.chip {
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--chrome-2);
  color: var(--text-2);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.chip[hidden] { display: none; }

.place-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* Bleibt keine Aktion übrig – etwa wenn die Route nicht berechnet werden
   konnte –, steht sonst eine Trennlinie ohne alles darunter. */
.place-actions:not(:has(.act:not([hidden]))) { display: none; }

.act {
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  /* Passen drei Aktionen nicht in eine Zeile, rutscht die dritte in die
     nächste – besser als ein Umbruch mitten in der Beschriftung. */
  white-space: nowrap;
  cursor: pointer;
}

.act:hover { background: var(--chrome-2); }

/* Die eine Aktion, die weiterführt statt nur zu kopieren. */
.act.stark { background: var(--accent); color: var(--chrome); }
.act.stark:hover { background: var(--accent); filter: brightness(1.08); }

/* --- Routenergebnis ------------------------------------------------------- */
/* Trägt zusätzlich .place und erbt damit Rahmen, Schatten und – auf schmalen
   Viewports – das Sheet-Verhalten. Hier steht nur, was abweicht. */

/* Hängt unter dem Routenpanel. --routeh setzt routing.js aus dessen Höhe;
   sie ändert sich mit der Länge der Adressen in den beiden Feldern. */
.route-result { top: calc(24px + var(--routeh, 0px)); }

/* Die Fahrzeit ist die Antwort auf die Frage – sie darf größer stehen. */
.route-result .place-title { font-size: 21px; }

.steps {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.steps[hidden] { display: none; }

.steps summary {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
}

.steps summary::-webkit-details-marker { display: none; }
.steps summary::after { content: " ▾"; }
.steps[open] summary::after { content: " ▴"; }

.steps ol {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  max-height: min(300px, 38dvh);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.steps li {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 8px 6px;
  font-size: 13.5px;
}

.steps li + li { border-top: 1px solid var(--line); }
.steps li.clickable { cursor: pointer; }
.steps li.clickable:hover { background: var(--chrome-2); }

.step-text { flex: 1; min-width: 0; }

.step-dist {
  flex: none;
  color: var(--text-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* --- Attribution und Rechtliches ------------------------------------------ */

.legal {
  position: fixed;
  z-index: 3;
  left: 0;
  bottom: 0;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 3px 8px 3px 10px;
  border-radius: 0 4px 0 0;
  background: var(--scrim);
  color: var(--text-2);
  font-size: 11px;
  backdrop-filter: blur(4px);
}

/* Der Opt-out steht in derselben Regel wie die Links, nicht in einer eigenen
   daneben: was gleich aussehen soll, wird an einer Stelle beschrieben. Ein
   <button> bleibt es trotzdem – er schaltet etwas um, statt irgendwohin zu
   führen, und ein <a> ohne href wäre für Tastatur und Screenreader ein Ziel,
   das es nicht gibt. */
.legal a,
.legal .legal-btn {
  color: var(--text-2);
  text-decoration: underline;
}

.legal .sep { opacity: .6; }

/* Alles, was das Betriebssystem sonst aus einem <button> macht: eigene
   Schriftgröße, Rahmen, Fläche, zentrierter Text – und in Safari zusätzlich
   ein Aussehen, das `background: none` allein nicht abschaltet. nowrap, weil
   der Knopf als Flex-Element sonst als einziger Eintrag der Zeile umbricht. */
.legal-btn {
  appearance: none;
  flex: none;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}

/* --- Kurzmeldung ---------------------------------------------------------- */

.toast {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 20px;
  background: var(--text);
  color: var(--ground);
  font-size: 13.5px;
  box-shadow: var(--shadow);
  animation: einblenden .18s ease-out;
}

.toast[hidden] { display: none; }

/* --- MapLibre-Bedienelemente ---------------------------------------------- */
/* Zoom, Standort und Maßstab kommen aus MapLibre – damit sind Tastatur- und
   Screenreader-Bedienung abgedeckt. Hier wird nur die Optik angeglichen. */

.maplibregl-ctrl-bottom-right { margin-bottom: 14px; }

.maplibregl-ctrl-group {
  background: var(--chrome);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.maplibregl-ctrl-group:not(:empty) { box-shadow: var(--shadow); }

.maplibregl-ctrl-group button {
  width: 40px;
  height: 40px;
  background: none;
}

.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line); }
.maplibregl-ctrl-group button:hover { background: var(--chrome-2); }

.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(var(--icon-invert)); }

/* Der Stilschalter ist eine eigene Schaltfläche und trägt sein Symbol als
   Inline-SVG mit currentColor – deshalb bleibt der Filter hier außen vor. */
.ctrl-flavor { display: grid; place-items: center; color: var(--text); }
.ctrl-flavor svg { display: block; }

/* 32px: der Maßstab steht über der Zeile mit Attribution und Rechtlichem,
   nicht dahinter. */
.maplibregl-ctrl-scale {
  margin: 0 0 32px 10px;
  padding: 0 4px;
  border: 2px solid var(--text-2);
  border-top: none;
  background: var(--scrim);
  color: var(--text-2);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.maplibregl-marker { cursor: default; }

/* --- Schmale Viewports ---------------------------------------------------- */

@media (max-width: 640px) {
  .search,
  .route {
    left: 12px;
    right: 12px;
    top: 56px;
    width: auto;
    max-width: none;
  }

  /* Oben ist kein Platz mehr – dort steht die Suche. Die Trefferkarte wird
     deshalb zum Sheet am unteren Rand. */
  .place {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: auto;
    max-width: none;
    padding-top: 8px;
    border-radius: 16px 16px 0 0;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    transform-origin: bottom center;
  }

  .grabber {
    display: block;
    width: 36px;
    height: 4px;
    margin: 0 auto 10px;
    border-radius: 2px;
    background: var(--line);
  }

  /* Das Sheet darf die Attribution nicht verdecken: die ODbL-Nennung muss
     sichtbar bleiben. Maßstab, Attribution und Bedienelemente rücken darüber.
     --sheet setzt app.js aus der tatsächlichen Höhe des Sheets. */
  body:has(.place:not([hidden])) .legal { bottom: var(--sheet, 0px); border-radius: 0 4px 4px 0; }
  body:has(.place:not([hidden])) .maplibregl-ctrl-scale { margin-bottom: calc(var(--sheet, 0px) + 32px); }
  body:has(.place:not([hidden])) .maplibregl-ctrl-bottom-right { margin-bottom: calc(var(--sheet, 0px) + 38px); }
}

@media (prefers-reduced-motion: reduce) {
  .place, .route, .toast { animation: none; }
}
