/* ===========================================================================
   NiCar Cruising – Stylesheet
   Aufbau der Seite (von oben nach unten):
   Kopfzeile · Meldungsleiste · Eingaben · Ergebnis · Karte (füllt den Rest)
   =========================================================================== */

:root {
  --bg:        #0b1f33;   /* dunkles Blau, Hintergrund */
  --bg-hell:   #12304d;   /* Karten/Kacheln */
  --rand:      #1d456b;
  --text:      #eaf2fa;
  --text-leise:#9db6ce;
  --akzent:    #38bdf8;   /* Hellblau = Route */
  --gruen:     #22c55e;
  --rot:       #f87171;
  --gelb:      #fbbf24;
  --radius:    12px;
}

* { box-sizing: border-box; }

/* Wichtig: Elemente, die per JavaScript mit "hidden" aus- und eingeblendet
   werden (Meldung, Ergebnis, Ladeanzeige, Vorschlagslisten), müssen wirklich
   verschwinden. Ohne diese Zeile gewinnen die display-Regeln weiter unten. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
}

/* Seite als Spalte: alles feste Höhe, nur die Karte wächst */
body {
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

/* --- Kopfzeile ----------------------------------------------------------- */
.kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rand);
}
.kopf-titel { display: flex; align-items: center; gap: 10px; }
.kopf-knoepfe { display: flex; align-items: center; gap: 2px; flex: none; }
.kopf h1 { margin: 0; font-size: 1.15rem; letter-spacing: .5px; }
.untertitel { margin: 0; font-size: .72rem; color: var(--text-leise); }
.logo {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background:
    radial-gradient(circle at 30% 74%, var(--gruen) 0 4px, transparent 5px),
    radial-gradient(circle at 72% 28%, var(--gelb) 0 4px, transparent 5px),
    linear-gradient(135deg, #17395c, #0b1f33);
  box-shadow: inset 0 0 0 1px var(--rand);
}

/* --- Meldungsleiste ------------------------------------------------------ */
.meldung {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px;
  font-size: .88rem;
  line-height: 1.4;
  background: #3b1d22;
  border-bottom: 1px solid #7f2d3a;
  color: #ffd9de;
}
.meldung.info    { background: #12304d; border-bottom-color: var(--rand); color: var(--text); }
.meldung.warnung { background: #3d3416; border-bottom-color: #7a6a1e; color: #ffeeb8; }
.meldung span { flex: 1; }
.meldung a { color: inherit; }

/* --- Eingaben ------------------------------------------------------------ */
.eingaben {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  padding: 12px 14px;
}
.feld { position: relative; }
.feld label {
  display: block;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-leise);
  margin-bottom: 4px;
}
.feld-zeile { position: relative; display: flex; align-items: center; }
.feld input {
  width: 100%;
  padding: 11px 34px 11px 12px;
  border: 1px solid var(--rand);
  border-radius: var(--radius);
  background: var(--bg-hell);
  color: var(--text);
  font-size: 1rem;
}
.feld input:focus { outline: 2px solid var(--akzent); outline-offset: -1px; }
.loeschen { position: absolute; right: 4px; }

/* Der Tausch-Knopf steht rechts über beide Eingabezeilen */
.tauschen { grid-column: 2; grid-row: 1 / span 2; align-self: center; }

.haupt-knopf {
  grid-column: 1 / -1;
  padding: 13px;
  border: none;
  border-radius: var(--radius);
  background: var(--akzent);
  color: #04283a;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}
.haupt-knopf:disabled { opacity: .5; cursor: default; }
.neben-knopf {
  padding: 13px 16px; border: 1px solid var(--rand); border-radius: var(--radius);
  background: transparent; color: var(--text); font-size: 1rem; cursor: pointer;
}
.neben-knopf:disabled { opacity: .4; cursor: default; }
.icon-knopf {
  border: none; background: transparent; color: var(--text-leise);
  font-size: 1.2rem; cursor: pointer; padding: 6px 9px; border-radius: 8px;
}
.icon-knopf:hover { background: var(--bg-hell); color: var(--text); }
.icon-knopf.klein { font-size: .95rem; }

/* --- Autovervollständigung der Adressen ---------------------------------- */
.vorschlaege {
  position: absolute; z-index: 1000; top: 100%; left: 0; right: 0;
  margin: 4px 0 0; padding: 0; list-style: none;
  background: var(--bg-hell);
  border: 1px solid var(--rand);
  border-radius: var(--radius);
  max-height: 240px; overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.vorschlaege li { padding: 10px 12px; cursor: pointer; font-size: .9rem; border-bottom: 1px solid rgba(255,255,255,.05); }
.vorschlaege li:last-child { border-bottom: none; }
.vorschlaege li:hover, .vorschlaege li.aktiv { background: #1a4067; }
.vorschlaege li small { display: block; color: var(--text-leise); font-size: .78rem; margin-top: 2px; }
.vorschlaege li.aussen { opacity: .45; }
.vorschlaege li.aussen small { color: var(--gelb); }

/* --- Ergebnis ------------------------------------------------------------ */
.ergebnis { padding: 0 14px 12px; }
.kennzahlen { display: flex; gap: 10px; }
.kennzahl {
  flex: 1; padding: 10px 12px;
  background: var(--bg-hell); border: 1px solid var(--rand); border-radius: var(--radius);
}
.kennzahl-wert { display: block; font-size: 1.5rem; font-weight: 700; }
.kennzahl-label { display: block; font-size: .7rem; color: var(--text-leise); margin-top: 2px; }

.pruefung { margin-top: 8px; font-size: .82rem; line-height: 1.45; }
.pruefung.ok    { color: var(--gruen); }
.pruefung.fehler{ color: var(--rot); }

.fussnote { margin: 6px 0 0; font-size: .72rem; color: var(--text-leise); line-height: 1.4; }

/* --- Sprachnavigation ---------------------------------------------------- */
.navi-leiste { display: flex; gap: 8px; margin-top: 10px; }
.haupt-knopf.navi { flex: 1; grid-column: auto; }
.haupt-knopf.navi.laeuft { background: var(--rot); color: #3b0d0d; }
.neben-knopf.schmal { flex: none; padding: 13px 14px; font-size: .85rem; }

/* Die große Anzeige während der Fahrt – aus dem Augenwinkel lesbar */
.navi-anzeige {
  margin-top: 10px; padding: 12px 14px;
  background: var(--bg-hell); border: 1px solid var(--rand); border-radius: var(--radius);
}
.navi-abstand { font-size: 2rem; font-weight: 700; line-height: 1.1; color: var(--akzent); }
.navi-text { margin-top: 2px; font-size: 1rem; line-height: 1.3; }
.navi-fuss {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px; font-size: .75rem; color: var(--text-leise);
}
.navi-anzeige.abgekommen { border-color: var(--rot); }
.navi-anzeige.abgekommen .navi-abstand { color: var(--rot); }

/* Der Punkt, der die eigene Position auf der Karte zeigt.
   Weiß gefüllt, nicht blau: Der Punkt liegt ja immer AUF der blauen Route –
   in Routenfarbe wäre nur der dunkle Rand zu sehen, der Punkt selbst nicht. */
.eigene-position {
  width: 20px; height: 20px; border-radius: 50%;
  background: #ffffff;
  border: 4px solid #04283a;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, .95), 0 0 14px rgba(0, 0, 0, .55);
}

/* Kleine Plakette im Kopf: zeigt, ob das eigene Profil greift */
.modus {
  display: inline-block; vertical-align: middle;
  margin-left: 6px; padding: 2px 7px;
  border-radius: 999px; font-size: .6rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px;
  border: 1px solid var(--rand); color: var(--text-leise);
}
.modus:empty      { display: none; }
.modus.ok         { color: var(--gruen);  border-color: #1c5c37; background: #10301f; }
.modus.warnung    { color: var(--gelb);   border-color: #7a6a1e; background: #3d3416; }

.abbiegungen { margin-top: 8px; font-size: .85rem; }
.abbiegungen summary { cursor: pointer; color: var(--text-leise); }
.abbiegungen ol { margin: 8px 0 0; padding-left: 20px; max-height: 180px; overflow-y: auto; }
.abbiegungen li { margin-bottom: 5px; }
.abbiegungen li span { color: var(--text-leise); }

/* --- Karte --------------------------------------------------------------- */
#karte {
  flex: 1;                /* nimmt den restlichen Platz ein */
  min-height: 240px;
  background: #0d2540;
}
.leaflet-container { background: #0d2540; }
/* Beschriftungen der Marker */
.marker-label {
  background: var(--bg-hell); border: 1px solid var(--rand); border-radius: 6px;
  padding: 1px 6px; font-size: .72rem; color: var(--text); white-space: nowrap;
}

/* --- Dialog -------------------------------------------------------------- */
dialog {
  border: 1px solid var(--rand); border-radius: var(--radius);
  background: var(--bg-hell); color: var(--text);
  padding: 0; max-width: 92vw; width: 420px;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog-inhalt { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.dialog-inhalt h2 { margin: 0; font-size: 1.05rem; }
.dialog-hinweis { margin: 0; font-size: .82rem; color: var(--text-leise); line-height: 1.45; }
.dialog-hinweis a { color: var(--akzent); }
.dialog-inhalt input {
  padding: 11px 12px; border: 1px solid var(--rand); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font-size: .95rem;
}
.dialog-inhalt menu { display: flex; gap: 8px; margin: 6px 0 0; padding: 0; }
.dialog-inhalt menu button { flex: 1; }

/* --- Ladeanzeige --------------------------------------------------------- */
.laden {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(11,31,51,.55);
}
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.2);
  border-top-color: var(--akzent);
  animation: dreh .8s linear infinite;
}
@keyframes dreh { to { transform: rotate(360deg); } }

/* --- Favoriten: Stern am Zielfeld ---------------------------------------- */
/* Der Stern liegt links vom Lösch-✕, deshalb braucht das Zielfeld rechts mehr Platz. */
#ziel { padding-right: 62px; }
.feld-zeile .fav-stern { position: absolute; right: 34px; color: var(--gelb); font-size: 1.05rem; }
.feld-zeile .fav-stern[aria-pressed="false"] { color: var(--text-leise); }

/* --- Favoriten: Chip-Reihe unter dem Zielfeld ---------------------------- */
.fav-chips {
  grid-column: 1 / -1; display: flex; gap: 8px;
  overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch;
}
.fav-chip {
  flex: none; white-space: nowrap; padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--rand); background: var(--bg-hell); color: var(--text);
  font-size: .85rem; cursor: pointer;
}
.fav-chip:hover { background: #1a4067; }
.fav-chip.verwalten { color: var(--text-leise); border-style: dashed; }

/* --- Favoriten: Verwaltungs-Liste im Dialog ------------------------------ */
.fav-liste { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.fav-liste li {
  display: flex; align-items: center; gap: 8px; padding: 10px 4px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.fav-liste .fav-name {
  flex: 1; text-align: left; background: transparent; border: none;
  color: var(--text); font-size: .95rem; cursor: pointer; padding: 0;
}
.fav-liste .fav-name small { display: block; color: var(--text-leise); font-size: .78rem; margin-top: 2px; }

/* --- Schmale Navigations-Leiste (nur während der Fahrt sichtbar) ---------- */
.navi-schmal {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 10px 14px; border: none;
  border-bottom: 1px solid var(--rand);
  background: var(--bg-hell); color: var(--text);
  font-size: .95rem; cursor: pointer;
}
.navi-schmal-ziel { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.navi-schmal-pfeil { color: var(--text-leise); }

/* Während der Navigation: Kopf schlank, Eingaben & Kennzahlen weg,
   nur die Fahranzeige + Beenden-Knopf bleiben. Karte gewinnt den Platz. */
body.navi-laeuft .kopf .untertitel { display: none; }
body.navi-laeuft .eingaben,
body.navi-laeuft .kennzahlen,
body.navi-laeuft #fussnote,
body.navi-laeuft #pruefung,
body.navi-laeuft #abbiegungen-box,
body.navi-laeuft #btn-testfahrt { display: none; }

/* Leiste antippen → Eingaben wieder einblenden (Ziel wechseln) */
body.navi-laeuft.eingaben-offen .eingaben { display: grid; }

/* Auf großen Bildschirmen bleibt das Panel stehen (dort ist die Karte eh
   in der zweiten Spalte); die schmale Leiste entfällt. */
@media (min-width: 900px) {
  body.navi-laeuft .eingaben { display: grid; }
  body.navi-laeuft .kennzahlen,
  body.navi-laeuft #fussnote,
  body.navi-laeuft #pruefung { display: flex; }
  .navi-schmal { display: none; }
}

/* --- Große Bildschirme: Bedienfeld links, Karte rechts ------------------- */
@media (min-width: 900px) {
  body {
    display: grid;
    grid-template-columns: 380px 1fr;
    grid-template-rows: auto auto auto auto 1fr;  /* letzte Zeile fängt den Rest auf */
    height: 100vh;
  }
  /* Alle Bedienelemente in Spalte 1 untereinander, die Karte füllt Spalte 2 komplett */
  .kopf, .meldung, .eingaben, .ergebnis { grid-column: 1; }
  .ergebnis { overflow-y: auto; }
  #karte    { grid-column: 2; grid-row: 1 / -1; }
}
