/* Naviate — Oberfläche.
   Farbwelt: nasser Asphalt bei Nacht, Fahrbahnmarkierung, Autobahnschild-Blau,
   Baustellen-Orange (offiziell) und Baustellen-Gelb (selbst gemeldet). */

:root {
  --asphalt:      #101820;
  --asphalt-high: #18242e;
  --asphalt-low:  #0a1016;
  --line:         #263845;
  --paint:        #f1f5f7;
  --paint-dim:    #92a7b5;
  --signal:       #0b7fd4;
  --signal-high:  #3aa0ef;
  --official:     #e2571e;
  --own:          #ffc300;
  --go:           #2fbf71;
  --alert:        #e0343f;

  --sheet-radius: 20px;
  --tap: 46px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* Ohne das gewinnt jedes display:grid/flex gegen das hidden-Attribut — ein
   unsichtbares Overlay würde dann sämtliche Berührungen abfangen. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
  background: var(--asphalt);
  color: var(--paint);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

button, input, select { font-family: inherit; font-size: 16px; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2;
      stroke-linecap: round; stroke-linejoin: round; }

/* --- Grundgerüst. position:absolute statt fixed, sonst bricht die
       Darstellung in der iOS-Homescreen-App. ------------------------------ */
#shell {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#map { position: absolute; inset: 0; background: var(--asphalt-low); z-index: 1; }
.leaflet-container { background: var(--asphalt-low); font-family: var(--font); }
/* Nachtkarte ohne fremden Schluessel: die normale OSM-Kachel wird invertiert. */
.tiles-dark {
  filter: invert(1) hue-rotate(180deg) brightness(.82) contrast(.92) saturate(.75);
}

.leaflet-control-attribution {
  background: rgba(16, 24, 32, .78) !important;
  color: var(--paint-dim) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--signal-high) !important; }

/* --- Kopfzeile -------------------------------------------------------- */
#topbar {
  position: absolute;
  top: calc(var(--safe-top) + 8px);
  left: 10px; right: 10px;
  z-index: 30;
  display: flex; gap: 8px; align-items: center;
}

.icon-btn, .tool-btn {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(16, 24, 32, .92);
  color: var(--paint);
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
}
.icon-btn:active, .tool-btn:active { transform: scale(.94); }

.search-trigger {
  flex: 1;
  height: var(--tap);
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(16, 24, 32, .92);
  color: var(--paint-dim);
  text-align: left;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
  overflow: hidden;
}
.search-trigger span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-trigger.has-target { color: var(--paint); }

.clock {
  height: var(--tap);
  min-width: 68px;
  display: grid; place-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(16, 24, 32, .92);
  font-size: 19px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
  backdrop-filter: blur(8px);
}

#statusline {
  position: absolute;
  top: calc(var(--safe-top) + 62px);
  left: 10px; right: 10px;
  z-index: 29;
  padding: 7px 12px;
  border-radius: 11px;
  background: rgba(11, 127, 212, .16);
  border: 1px solid rgba(58, 160, 239, .4);
  color: var(--paint);
  font-size: 13px;
}

/* --- Seitliche Knöpfe ------------------------------------------------- */
#sidetools {
  position: absolute;
  right: 10px;
  top: calc(var(--safe-top) + 72px);
  z-index: 28;
  display: flex; flex-direction: column; gap: 8px;
}
.tool-roadwork { color: var(--own); }
.tool-roadwork.armed {
  background: var(--own); color: #241a00; border-color: var(--own);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(255, 195, 0, .15); } }
@media (prefers-reduced-motion: reduce) { .tool-roadwork.armed { animation: none; } }
.tool-sos { color: var(--alert); border-color: rgba(224, 52, 63, .5); }
.tool-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px;
  background: var(--own); color: #241a00;
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

/* --- Fahrtanzeige ----------------------------------------------------- */
#hud {
  position: absolute;
  left: 8px; right: 8px;
  bottom: calc(var(--safe-bottom) + 8px);
  z-index: 32;
  padding: 12px 14px calc(10px);
  border-radius: var(--sheet-radius);
  background: rgba(10, 16, 22, .95);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  box-shadow: 0 -6px 28px rgba(0, 0, 0, .5);
}
.hud-maneuver { display: flex; gap: 10px; align-items: baseline; margin-bottom: 10px; }
#hud-maneuver-dist { color: var(--signal-high); font-weight: 700; font-variant-numeric: tabular-nums; }
#hud-maneuver-text { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-progress { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
#hud-progress-bar { height: 100%; width: 0; background: var(--go); transition: width .6s linear; }

.hud-figures {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 4px; margin: 12px 0 8px;
}
.fig { text-align: center; }
.fig strong {
  display: block;
  font-size: 22px; font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.fig-speed strong { font-size: 34px; line-height: 1; color: var(--paint); }
.fig-unit { display: block; margin-top: 2px; font-size: 11px; color: var(--paint-dim); }
.fig-speed .fig-unit { margin-top: 4px; }

.hud-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hud-done { font-size: 12px; color: var(--paint-dim); font-variant-numeric: tabular-nums; }

/* --- Sheets ----------------------------------------------------------- */
.panel, #menu, #preview {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  max-height: 86%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--safe-bottom) + 20px);
  border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
  background: var(--asphalt-high);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .55);
}
.panel-head, .menu-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.panel h2, .menu-head h2 { margin: 0; font-size: 18px; font-weight: 650; }
.sheet-close {
  width: 34px; height: 34px; flex: none;
  border: 0; border-radius: 50%;
  background: var(--line); color: var(--paint);
  font-size: 20px; line-height: 1;
}
#preview { padding-top: 20px; }
#preview h2 { margin: 0 0 2px; font-size: 20px; padding-right: 40px; }
#preview .sheet-close { position: absolute; top: 14px; right: 14px; }

#scrim {
  position: absolute; inset: 0; z-index: 35;
  background: rgba(6, 10, 14, .55);
  backdrop-filter: blur(2px);
}

/* --- Menü ------------------------------------------------------------- */
.menu-user { margin: 0; font-size: 17px; font-weight: 650; }
.menu-list { list-style: none; margin: 0; padding: 0; }
.menu-list li + li { border-top: 1px solid var(--line); }
.menu-list button, .menu-link {
  display: flex; align-items: center; gap: 14px;
  width: 100%; padding: 14px 4px;
  border: 0; background: none; color: var(--paint);
  font-size: 16px; text-align: left; text-decoration: none;
}
.menu-list button span { width: 24px; text-align: center; font-size: 17px; }
.menu-link { color: var(--paint-dim); }

/* --- Listen ----------------------------------------------------------- */
.list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--asphalt);
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 15px; font-weight: 600; }
.row-sub {
  margin-top: 2px; font-size: 12.5px; color: var(--paint-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-actions { display: flex; gap: 6px; flex: none; }
.mini {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 9px;
  background: transparent; color: var(--paint-dim); font-size: 15px;
}
.mini.on { color: var(--own); border-color: rgba(255, 195, 0, .5); }
.mini.danger { color: var(--alert); }
.empty { padding: 22px 4px; color: var(--paint-dim); font-size: 14px; text-align: center; }

.summary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin-bottom: 12px;
}
.summary div {
  padding: 10px; border: 1px solid var(--line); border-radius: 12px; text-align: center;
}
.summary strong { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.summary span { font-size: 11px; color: var(--paint-dim); }

/* --- Verkehrsmittel und Routenwahl ------------------------------------ */
.mode-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0; }
.mode-btn {
  padding: 10px 4px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--asphalt); color: var(--paint-dim);
  font-size: 12px; display: grid; gap: 4px; justify-items: center;
}
.mode-btn span { font-size: 20px; }
.mode-btn.active {
  border-color: var(--signal); background: rgba(11, 127, 212, .16); color: var(--paint);
}

.route-options { display: flex; flex-direction: column; gap: 8px; }
.route-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--asphalt);
  text-align: left; width: 100%;
}
.route-card.active { border-color: var(--go); background: rgba(47, 191, 113, .12); }
.route-card.avoid { border-left: 3px solid var(--own); }
.route-card strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.route-card .row-sub { white-space: normal; }
.route-flag {
  flex: none; padding: 3px 7px; border-radius: 6px;
  font-size: 11px; font-weight: 600;
  background: rgba(255, 195, 0, .16); color: var(--own);
}

.preview-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.preview-actions .btn-block { grid-column: 1 / -1; }

.note {
  margin: 10px 0 0; padding: 9px 11px;
  border-radius: 10px;
  background: rgba(255, 195, 0, .12);
  border: 1px solid rgba(255, 195, 0, .3);
  font-size: 13px; color: #ffd964;
}

/* --- Knöpfe, Felder --------------------------------------------------- */
.btn {
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--asphalt); color: var(--paint);
  font-size: 15px; font-weight: 600;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--signal); border-color: var(--signal); color: #fff; }
.btn-quiet { background: transparent; color: var(--paint-dim); font-weight: 500; }
.btn-block { width: 100%; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 13px; }

input[type="text"], input[type="password"], input[type="search"] {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--asphalt); color: var(--paint);
}
input:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--signal-high); outline-offset: 2px;
}

.setting { padding: 14px 0; border-top: 1px solid var(--line); }
.setting:first-of-type { border-top: 0; }
.setting-title { display: block; margin-bottom: 8px; font-size: 13px; color: var(--paint-dim); }
.switch { display: flex; align-items: center; gap: 12px; font-size: 15px; }
.switch input { width: 22px; height: 22px; accent-color: var(--signal); }
.muted { color: var(--paint-dim); }
.small { font-size: 12.5px; }
.muted.small { margin: 6px 0 0; line-height: 1.45; }

.chip-row { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 10px; }
.chip {
  padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--asphalt); color: var(--paint-dim); font-size: 13px;
}
.chip.active { border-color: var(--signal); color: var(--paint); background: rgba(11, 127, 212, .16); }
.chip:disabled { opacity: .4; }

/* --- Popups ----------------------------------------------------------- */
.popup { position: absolute; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px;
         background: rgba(6, 10, 14, .6); }
.popup-card {
  width: 100%; max-width: 380px;
  padding: 18px;
  border: 1px solid var(--line); border-radius: 18px;
  background: var(--asphalt-high);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
.popup-card h3 { margin: 0 0 10px; font-size: 17px; }
.sos-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.sos-choice {
  display: grid; justify-items: center; gap: 2px;
  padding: 16px 8px;
  border-radius: 14px; text-decoration: none; color: var(--paint);
  border: 1px solid var(--line);
}
.sos-choice span { font-size: 30px; }
.sos-choice strong { font-size: 26px; font-variant-numeric: tabular-nums; }
.sos-choice em { font-style: normal; font-size: 11.5px; color: var(--paint-dim); text-align: center; }
.sos-police { background: rgba(11, 127, 212, .14); border-color: rgba(11, 127, 212, .45); }
.sos-medic  { background: rgba(224, 52, 63, .14); border-color: rgba(224, 52, 63, .45); }

#toast {
  position: absolute;
  left: 16px; right: 16px;
  bottom: calc(var(--safe-bottom) + 18px);
  z-index: 70;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(10, 16, 22, .96);
  border: 1px solid var(--line);
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
#toast.error { border-color: rgba(224, 52, 63, .6); }

/* --- Kartenmarker ----------------------------------------------------- */
.marker-me {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  font-size: 20px;
  border-radius: 50%;
  background: rgba(11, 127, 212, .9);
  border: 2px solid #fff;
  box-shadow: 0 0 0 6px rgba(11, 127, 212, .22);
}
.marker-pin { font-size: 26px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .6)); }
.marker-rw {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 13px;
  background: var(--asphalt);
}
.marker-rw.official { border: 2px solid var(--official); color: var(--official); }
.marker-rw.own { border: 2px dashed var(--own); color: var(--own); }
.marker-fuel {
  width: 22px; height: 22px; display: grid; place-items: center;
  border-radius: 50%; background: rgba(16, 24, 32, .9);
  border: 1px solid var(--paint-dim); font-size: 11px;
}
.leaflet-popup-content-wrapper {
  background: var(--asphalt-high); color: var(--paint);
  border: 1px solid var(--line); border-radius: 12px;
}
.leaflet-popup-tip { background: var(--asphalt-high); }
.leaflet-popup-content { margin: 12px 14px; font-size: 14px; }
.leaflet-popup-content b { display: block; margin-bottom: 3px; }
.leaflet-popup-content .pop-note { color: var(--paint-dim); font-size: 12px; }
.leaflet-popup-content button {
  margin-top: 10px; width: 100%;
  min-height: 38px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--asphalt); color: var(--paint);
  font-size: 13px;
}
.leaflet-popup-content button.danger { color: var(--alert); border-color: rgba(224, 52, 63, .5); }

/* --- Info ------------------------------------------------------------- */
.info-toc { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.info-toc a {
  padding: 7px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--asphalt);
  color: var(--paint-dim); font-size: 12.5px; text-decoration: none;
}
.info { font-size: 15px; line-height: 1.62; max-width: 68ch; }
.info h3 {
  margin: 28px 0 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 17px; scroll-margin-top: 70px;
}
.info h3:first-child { margin-top: 0; border-top: 0; padding-top: 0; }
.info h4 { margin: 18px 0 6px; font-size: 15px; color: var(--signal-high); }
.info p { margin: 0 0 10px; }
.info ul, .info ol { margin: 0 0 12px; padding-left: 20px; }
.info li { margin-bottom: 7px; }
.info em { font-style: normal; color: var(--signal-high); }
.legend { list-style: none; padding: 0; }
.legend li { display: flex; gap: 10px; align-items: flex-start; }
.dot { flex: none; width: 16px; height: 16px; margin-top: 5px; border-radius: 50%; }
.dot-official { border: 3px solid var(--official); }
.dot-own { border: 3px dashed var(--own); }

/* --- Anmeldung -------------------------------------------------------- */
.login-body {
  display: grid; place-items: center; min-height: 100dvh; padding: 24px;
  background:
    radial-gradient(120% 80% at 50% 0%, #16242e 0%, var(--asphalt) 55%, var(--asphalt-low) 100%);
}
.login-shell { width: 100%; max-width: 340px; }
.login-mark { display: flex; flex-direction: column; align-items: center; gap: 7px; margin-bottom: 22px; }
.login-dash { width: 5px; height: 20px; border-radius: 3px; background: var(--paint); opacity: .25; }
.login-dash:last-child { opacity: 1; }
.login-title { margin: 0; text-align: center; font-size: 30px; font-weight: 650; letter-spacing: -.01em; }
.login-sub { margin: 4px 0 22px; text-align: center; color: var(--paint-dim); font-size: 14px; }
.login-form { display: grid; gap: 4px; }
.field { display: block; margin-bottom: 6px; }
.field span { display: block; margin-bottom: 5px; font-size: 12.5px; color: var(--paint-dim); }
.login-error {
  margin: 0 0 16px; padding: 11px 13px;
  border-radius: 11px;
  background: rgba(224, 52, 63, .14); border: 1px solid rgba(224, 52, 63, .45);
  font-size: 14px;
}
.login-foot { margin-top: 20px; text-align: center; font-size: 12.5px; color: var(--paint-dim); }

@media (min-width: 720px) {
  .panel, #menu, #preview { left: auto; right: 14px; bottom: 14px; width: 400px; border-radius: var(--sheet-radius); }
  #hud { left: auto; right: 14px; width: 400px; }
}
