:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #dfe3e8;
  --text: #1c2733;
  --muted: #66707b;
  --accent: #1a6ee0;
  --danger: #b30000;
  --warn: #e6550d;
  --ok: #2b8a3e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  /* Inter Tight: selbst gehostet (fonts/, SIL OFL 1.1) – kein Request an
     Dritte, font-display: swap rendert Text sofort mit der System-Schrift
     und tauscht, sobald Inter Tight geladen ist. */
  font-family: 'Inter Tight', system-ui, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

body {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

#sidebar {
  width: 400px;
  min-width: 340px;
  height: 100%;
  overflow-y: auto;
  padding: 18px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

#map {
  flex: 1;
  height: 100%;
}

header h1 {
  font-size: 1.35rem;
  margin: 0 0 4px;
}

header .sub {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.panel h2 {
  font-size: 0.95rem;
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

label {
  display: block;
  font-size: 0.85rem;
  margin: 10px 0 4px;
  font-weight: 600;
}

input[type="text"], select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.95rem;
}

/* Eingabefeld + 📍-Button nebeneinander (Start/Ziel auf der Karte setzen) */
.geo-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.geo-row input[type="text"] { flex: 1; width: auto; }
.geo-row .secondary { padding: 6px 9px; font-size: 1rem; line-height: 1.3; }
/* ⇅-Tausch-Button: sitzt in der „Ziel"-Beschriftungszeile, rechtsbündig in
   der 📍-Spalte – keine eigene Zeile, keine Zusatzhöhe */
.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 0 4px;
}
.label-row label { margin: 0; }
.label-row .secondary { padding: 2px 9px; font-size: 0.85rem; line-height: 1.25; }

/* Jahr-Select + 🔄 in einer Zeile */
.opt-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.opt-row select { flex: 1; width: auto; }
.opt-row .secondary { padding: 6px 9px; font-size: 1rem; line-height: 1.3; }
/* Datenstand kompakt in der Beschriftungszeile */
#cacheInfo {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}
/* Sprach-Umschalter im Kopf */
.head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.lang-switch { display: flex; gap: 3px; margin-top: 2px; }
.lang-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.lang-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.lang-btn:hover:not(.active) { color: var(--text); }

/* Sprache: Blöcke nur in der aktiven Sprache zeigen */
html.lang-en .only-de { display: none; }
html:not(.lang-en) .only-en { display: none; }

/* „Nebenstraßen meiden"-Flag nur im Auto-Modus sichtbar */
/* „Nebenstraßen meiden"-Flag nur im Auto-Modus sichtbar */
label.car-only { display: none; }
html.car-mode label.car-only { display: flex; }

/* Aufklappbare Hilfe – hält die langen Erklärtexte aus dem Hauptfluss raus */
details.help {
  border: 1px solid var(--border);
  border-radius: 9px;
  margin-bottom: 12px;
  background: #fff;
}
details.help summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
  /* Versions-Stempel rechts neben dem Titel – bleibt auch eingeklappt
     sichtbar (klein, grau, unaufdringlich). Flex statt space-between:
     der Pfeil (::before) ist ein eigenes Flex-Element, space-between
     würde den Titel zwischen Pfeil und Version in die Mitte rücken.
     margin-left: auto schiebt nur die Version an den rechten Rand.
     Titel-Span getrennt von data-en, da applyI18n() textContent
     ganzer Elemente ersetzt und die Versions-Span sonst löscht. */
  display: flex;
  align-items: baseline;
  gap: 8px;
}
details.help summary .ver {
  font-weight: 400;
  font-size: 0.72rem;
  color: #9aa1aa;
  white-space: nowrap;
  margin-left: auto;
}
details.help summary::-webkit-details-marker { display: none; }
details.help summary::before { content: '▸ '; }
details.help[open] summary::before { content: '▾ '; }
details.help summary:hover { color: var(--text); }
details.help .help-body {
  border-top: 1px solid var(--border);
  padding: 4px 12px 10px;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text);
}
details.help .help-body h3 {
  font-size: 0.78rem;
  margin: 10px 0 2px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
details.help .help-body p { margin: 4px 0; }
button.secondary.active {
  border-color: #1a6ee0;
  background: #eaf2fd;
  box-shadow: 0 0 0 2px rgba(26, 110, 224, 0.25);
}

input[type="range"] { width: 100%; }

.modes {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.mode {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px;
  text-align: center;
  cursor: pointer;
  font-weight: 500;
  margin: 0;
}

.mode input { display: none; }
.mode:has(input:checked) {
  border-color: var(--accent);
  background: #eaf2fd;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-weight: 400;
  font-size: 0.85rem;
  margin: 10px 0 0;
  cursor: pointer;
}
.check input { margin-top: 2px; }

button.primary {
  width: 100%;
  margin-top: 14px;
  padding: 11px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
button.primary:hover:not(:disabled) { background: #1258b8; }
button.primary:disabled { opacity: 0.55; cursor: wait; }

/* Route analysieren + Teilen in einer Zeile: die Hauptaktion bleibt
   dominant, Teilen ist ein kompakter Begleiter (erst nach Analyse sichtbar) */
.actions-row { display: flex; gap: 8px; align-items: stretch; }
.actions-row .primary { flex: 1; }
.actions-row .secondary {
  margin-top: 14px;
  width: auto;
  padding: 11px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
}

.status {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

progress { width: 100%; margin-top: 6px; height: 8px; }

.error {
  margin-top: 10px;
  padding: 8px 10px;
  background: #fdecec;
  border: 1px solid #f5b5b5;
  border-radius: 7px;
  color: var(--danger);
  font-size: 0.85rem;
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 10px 0 0;
}

/* Ergebnisse */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.kpi {
  background: var(--bg);
  border-radius: 8px;
  padding: 5px 4px;
  text-align: center;
}

.kpi .num { font-size: 1.1rem; font-weight: 700; }
.kpi .lbl {
  font-size: 0.66rem;
  line-height: 1.25;
  color: var(--muted);
  /* Kein Umbruch in die nächste Zeile – zu lange Labels werden
     mit Auslassungspunkten gekürzt, die Bedeutung steht im Tooltip. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.verdict {
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.4;
  margin-top: 6px;
}
.verdict.high   { background: #fdecec; border: 1px solid #f0b8b8; }
.verdict.medium { background: #fff4e5; border: 1px solid #f5d9a8; }
.verdict.low    { background: #e9f7ec; border: 1px solid #bfe3c8; }

/* Abstand zwischen der Einordnung (grüne Box) und der Einzelaufstellung.
   Die kastenlosen Textzeilen stehen optisch leicht (2 px) innerhalb der
   Kanten der gerahmten Kästen darüber/darunter – ohne Einrückung wirken
   sie, als stünden sie über die Kastenkante hinaus. */
.bars { font-size: 0.75rem; margin-top: 12px; margin-inline: 2px; }
.bar-row { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.bar-row .name { width: 88px; flex-shrink: 0; color: var(--muted); font-size: 0.78rem; }
.bar-row .track { flex: 1; background: #edf0f3; border-radius: 4px; height: 8px; overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 4px; }
.bar-row .val { width: 32px; text-align: right; font-variant-numeric: tabular-nums; }

/* Letzter Listen-Kasten: kein Unterabstand mehr – der Panelrand selbst
   sorgt für die Außenluft, sonst entsteht darunter doppelter Leerraum. */
.route-card:last-child,
.hotspot:last-child,
.rec:last-child { margin-bottom: 0; }

.hotspot {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s, background 0.15s;
}
.hotspot:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.hotspot.active {
  border: 2px solid #1a6ee0;
  background: #eaf2fd;
  box-shadow: 0 2px 10px rgba(26, 110, 224, 0.25);
  padding: 9px 11px; /* 2px mehr Rahmen → Größe ausgleichen */
}

/* Pulsierender Ring um den gewählten Schwerpunkt auf der Karte */
.hotspot-pulse {
  animation: hotspotPulse 1.6s ease-out infinite;
}
@keyframes hotspotPulse {
  0%   { opacity: 0.9; }
  50%  { opacity: 0.25; }
  100% { opacity: 0.9; }
}

.hotspot .top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.hotspot .rank { font-weight: 700; }
.hotspot .tag {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
  white-space: nowrap;
}
.hotspot .meta { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.hotspot .sev { font-size: 0.78rem; margin-top: 3px; }

.rec {
  display: flex;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 9px;
  margin-bottom: 8px;
  font-size: 0.87rem;
  line-height: 1.45;
}
.rec .icon { font-size: 1.15rem; flex-shrink: 0; }
.rec.warn { background: #fff4e5; border: 1px solid #f5d9a8; }
.rec.tip  { background: #eaf2fd; border: 1px solid #c4d9f5; }
.rec b { display: block; margin-bottom: 2px; }

footer {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.5;
  margin: 4px 0 20px;
}
footer a { color: var(--accent); }

/* Wegpunkt-Marker (Start/Ziel/Zwischenziel) */
.wp {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  cursor: grab;
}
.wp.start { background: #2b8a3e; }
.wp.ziel  { background: #b30000; }
.wp.via   { background: #1a6ee0; font-size: 9px; }


button.secondary {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
}
button.secondary:hover:not(:disabled) { background: #f0f3f6; }
button.secondary:disabled { opacity: 0.5; cursor: wait; }

/* Routen-Vergleich */
.route-card {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: box-shadow 0.15s;
}
.route-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.route-card.selected { border-color: var(--accent); background: #eaf2fd; }
/* „Sicherste" Route: grüner Kasten (Farbcodierung wie das Badge und die
   grüne Strecke auf der Karte); grün gewinnt auch bei Auswahl */
.route-card.safest { border-color: #2b8a3e; background: #eef8ee; }
.route-card.selected.safest { border-color: #2b8a3e; background: #eef8ee; }

.route-card .head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.route-card .head b { font-size: 0.95rem; }
.badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
  white-space: nowrap;
}
.badge.fast { background: var(--accent); }
.badge.safe { background: var(--ok); }

.route-card .stats {
  /* Spalte 1 bewusst breiter: dort liegt mit „Unfälle 83 (12 schw.)“ das
     längste Label-Wert-Paar – gleichbreite Spalten zwingen das Label in
     die nächste Zeile. */
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.75fr);
  gap: 2px 10px;
  margin-top: 4px;
}
.route-card .stats span {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}
.route-card .stats span .lbl { color: var(--muted); white-space: nowrap; }
.route-card .stats b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
}
.route-card .delta {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.045);
}
.route-card .delta.safe { color: var(--ok); background: rgba(43, 138, 62, 0.10); }
.route-card .delta.slow { color: var(--warn); background: rgba(230, 85, 13, 0.10); }
.route-card .turns {
  font-size: 0.74rem;
  color: var(--muted);
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}

/* Teaser: Abstand zu den Routenkarten */
#routeRecommendation { margin-bottom: 12px; }

/* Teaser-Aufbau: Kopf / farbige Fakten / dezenter Hinweis */
#routeRecommendation .teaser { display: flex; gap: 10px; align-items: flex-start; }
#routeRecommendation .teaser-icon { font-size: 1.25rem; line-height: 1.2; }
#routeRecommendation .teaser-head { font-size: 0.92rem; }
#routeRecommendation .teaser-head b { font-weight: 700; }
#routeRecommendation .teaser-facts {
  font-size: 0.85rem;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
#routeRecommendation .fact-ok { color: var(--ok); font-weight: 600; }
#routeRecommendation .fact-slow { color: var(--warn); font-weight: 600; }
#routeRecommendation .fact-sep { color: var(--muted); margin: 0 4px; }
#routeRecommendation .teaser-hint { font-size: 0.74rem; color: var(--muted); margin-top: 2px; }

/* Leaflet-Anpassungen */
.leaflet-popup-content { font-size: 0.85rem; line-height: 1.4; margin: 10px 12px; }
.leaflet-popup-content h4 { margin: 0 0 6px; }
.leaflet-popup-content table { font-size: 0.8rem; border-collapse: collapse; }
.leaflet-popup-content td { padding: 1px 8px 1px 0; }
.legend {
  background: rgba(255,255,255,0.92);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  line-height: 1.7;
  box-shadow: 0 1px 5px rgba(0,0,0,0.2);
}
.legend .dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

/* Optische Flucht: Kastenlose Texte, Labels und Überschriften, die bündig
   mit den Kanten gerahmter/hinterlegter Kästen stehen, rücken 2 px in diese
   Kante hinein – Kastenkanten tragen visuelles Gewicht, bündiger Text wirkt
   sonst, als stünde er über die Kante hinaus. (Eingebettete Kästen selbst –
   Inputs, Buttons, .error, .check-Zeilen – bleiben bündig.) */
h1,
header .sub,
.panel h2,
.panel > label:not(.check),
.label-row label,
.status,
.hint,
details.help summary,
footer {
  margin-inline: 2px;
}

@media (max-width: 900px) {
  body { flex-direction: column; }
  #sidebar { width: 100%; min-width: 0; height: 55%; border-right: 0; border-bottom: 1px solid var(--border); }
  #map { height: 45%; }
  /* Mobil: Schweregrad-Legende ausblenden – sie kostet auf dem kleinen
     Kartenausschnitt zu viel Platz; die Farbedeutung steht in den Popups
     und im Detailpanel. */
  .legend { display: none; }
}
