:root {
  --geplant: #2563eb;
  --besucht: #16a34a;
  --reserviert: #ea580c;
  --bg: #0f766e;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Formular-Steuerelemente immer im Hell-Schema rendern -> nie weiß-auf-weiß
     (auch wenn iOS/macOS im Dark-Modus sind). Die App ist ohnehin hell. */
  color-scheme: light;
}
/* Explizite Farben für ALLE Eingabe-/Auswahlfelder (Sicherheitsnetz gegen
   System-Dark-Mode: dunkler Text auf hellem Grund, inkl. Dropdown-Optionen). */
input, select, textarea { background-color: #fff; color: #111; }
select option { background-color: #fff; color: #111; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

#topbar {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .75rem; background: var(--bg); color: #fff;
  padding-top: max(.5rem, env(safe-area-inset-top));
  flex-wrap: wrap; position: relative;
}
#topbar .brand { font-size: 1.35rem; flex: 0 0 auto; }
/* Reise-Auswahl = großes Tap-Ziel, füllt die Zeile (schwer zu verfehlen) */
#tripSelect {
  flex: 1 1 auto; min-width: 0;
  font-size: 1rem; padding: .5rem; min-height: 44px;
  border: none; border-radius: 8px; cursor: pointer;
}
#topbar button {
  font-size: .95rem; padding: .5rem .7rem; border-radius: 8px;
  border: none; cursor: pointer; min-height: 44px; flex: 0 0 auto;
  background: #ffffff22; color: #fff; white-space: nowrap;
}
#topbar button:hover { background: #ffffff3a; }
/* "＋" klar abgesetzt, damit es nicht versehentlich getroffen wird */
#newTripBtn { border: 1px solid #ffffff66; }
.hint { flex-basis: 100%; font-size: .78rem; opacity: .9; }

/* Tour-Name-Button (öffnet das Tour-Menü) */
.tour-name {
  flex: 1 1 auto; min-width: 0; text-align: left; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Tour-Auswahlmenü */
#tourMenu {
  position: absolute; top: 100%; left: .5rem; z-index: 30;
  background: #fff; color: #111; border-radius: 8px;
  box-shadow: 0 4px 14px #0004; min-width: 200px; max-width: 80vw;
  max-height: 60vh; overflow: auto; padding: .25rem; margin-top: .25rem;
}
/* Unter #tourMenu gescoped, damit die ID-Spezifität die generische
   Regel "#topbar button { color:#fff }" schlägt (sonst weiß auf weiß). */
#tourMenu .tour-menu-item {
  display: block; width: 100%; text-align: left; background: #fff;
  border: none; color: #111; padding: .55rem .6rem; border-radius: 6px;
  cursor: pointer; font-size: .95rem;
}
#tourMenu .tour-menu-item:hover { background: #f2f2f2; }
#tourMenu .tour-menu-item.active { background: var(--bg); color: #fff; }
.trip-dates { font-size: .8rem; color: #555; margin: 0 0 .4rem; }

/* Ort-Suche */
#searchBox { display: flex; gap: .4rem; margin-bottom: .5rem; }
#searchInput {
  flex: 1; min-width: 0; padding: .45rem; border: 1px solid #ccc;
  border-radius: 8px; font: inherit;
}
#searchBox button {
  border: none; background: var(--bg); color: #fff; border-radius: 8px;
  padding: 0 .7rem; cursor: pointer; font-size: 1rem;
}
/* "Entlang der Route"-Suche: Etappen-Auswahl + Button */
#routeSearchBox { display: flex; gap: .4rem; margin: 0 0 .5rem; }
#routeLegSelect {
  flex: 1 1 auto; min-width: 0; padding: .4rem; min-height: 40px;
  border: 1px solid #ccc; border-radius: 8px; font: inherit;
}
#routeSearchBtn {
  flex: 0 0 auto; padding: .5rem .7rem; border: 1px solid var(--bg); border-radius: 8px;
  background: #f0f7f6; color: var(--bg); font: inherit; font-weight: 600;
  cursor: pointer; min-height: 40px; white-space: nowrap;
}
#routeSearchBtn:hover { background: #e6f1ef; }
.search-result .sr-info { color: #777; font-weight: 400; }
#searchResults { margin-bottom: .3rem; }
/* Einklappbare Fund-Liste der Routensuche */
.camp-results { margin-bottom: .3rem; }
.camp-results > summary {
  cursor: pointer; user-select: none; list-style-position: inside;
  padding: .45rem .55rem; font-size: .85rem; font-weight: 600;
  color: var(--bg); background: #f0f7f6; border-radius: 8px;
}
.camp-results[open] > summary { border-radius: 8px 8px 0 0; }
.camp-sum-text { margin-right: .3rem; }
.camp-clear {
  float: right; border: none; background: none; color: #999;
  font-size: 1rem; line-height: 1.2; cursor: pointer; padding: 0 .1rem;
}
.camp-clear:hover { color: #b91c1c; }
.camp-list {
  padding: .1rem .5rem .2rem; border: 1px solid #eee; border-top: none;
  border-radius: 0 0 8px 8px; max-height: 45vh; overflow-y: auto;
}
.search-hint { font-size: .8rem; color: #777; padding: .3rem 0; }
.search-result {
  display: flex; align-items: center; gap: .4rem;
  padding: .4rem 0; border-bottom: 1px solid #f0f0f0;
}
.search-result .sr-name { flex: 1; font-size: .82rem; cursor: pointer; }
.sr-actions { display: flex; gap: .3rem; }
.sr-actions button {
  border: 1px solid #ccc; background: #fafafa; border-radius: 6px;
  padding: .15rem .45rem; cursor: pointer; font-size: 1rem;
}

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

/* Marker */
.marker {
  width: 22px; height: 22px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); border: 2px solid #fff;
  box-shadow: 0 1px 4px #0006; cursor: pointer;
}
.marker.geplant { background: var(--geplant); }
.marker.besucht { background: var(--besucht); }
.marker.reserviert { background: var(--reserviert); }

/* Marker-Wrapper trägt Pin (gedreht) + aufrechtes Schloss-Badge */
.marker-wrap { position: relative; width: 22px; height: 22px; cursor: pointer; }
.marker-lock {
  position: absolute; top: -11px; right: -11px;
  font-size: 13px; line-height: 1;
  filter: drop-shadow(0 1px 1px #0009);
  pointer-events: none;
}

/* Seitenpanel */
#panel {
  position: absolute; top: 64px; right: 0; z-index: 5;
  width: 320px; max-width: 85vw; max-height: 70vh; overflow: auto;
  background: #fff; box-shadow: -2px 2px 10px #0003;
  border-radius: 10px 0 0 10px;
}
#panel.collapsed #panelBody { display: none; }
#panelToggle {
  position: sticky; top: 0; float: right; margin: .4rem;
  border: none; background: var(--bg); color: #fff;
  border-radius: 8px; padding: .3rem .55rem; cursor: pointer;
}
#panelBody { padding: .5rem .75rem 1rem; }
#tripTitle { margin: .25rem 0 .5rem; font-size: 1.05rem; }
#stopList { list-style: none; margin: 0; padding: 0; }
#stopList li.stop {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .5rem; border-bottom: 1px solid #eee;
}
#stopList li.stop:hover { background: #f6f6f6; }
.drag-handle {
  cursor: grab; color: #aaa; font-size: 1.1rem; line-height: 1;
  user-select: none; touch-action: none;
}
.drag-handle:active { cursor: grabbing; }
.stop-name { flex: 1; cursor: pointer; }
.leg-dist { flex-basis: 100%; font-size: .78rem; color: #666; padding-left: 1.7rem; }
.leg-dist:empty { display: none; }
.stop-res { flex-basis: 100%; font-size: .78rem; color: var(--reserviert); padding-left: 1.7rem; }
.leg-warn { flex-basis: 100%; font-size: .78rem; color: #b91c1c; font-weight: 600; padding-left: 1.7rem; cursor: help; }
.leg-warn:empty { display: none; }
.badge.poi { background: #7c3aed; }
.popup .poi-dist-title { font-weight: 600; margin: .4rem 0 .2rem; }
.popup .poi-dist { font-size: .85rem; }

/* POI-Aufklappmenü im Panel */
.poi-section { margin-top: .6rem; border-top: 1px solid #eee; padding-top: .3rem; }
.poi-section > summary {
  cursor: pointer; font-weight: 600; font-size: .9rem; padding: .3rem 0; user-select: none;
}
#poiList { list-style: none; margin: .2rem 0 0; padding: 0; }
.poi-item {
  display: flex; flex-wrap: wrap; align-items: center; gap: .4rem;
  padding: .4rem 0; border-bottom: 1px solid #f0f0f0;
}
.poi-item .poi-name { flex: 1; cursor: pointer; }
.poi-actions { display: flex; gap: .3rem; }
.poi-actions button {
  background: none; border: 1px solid #ccc; border-radius: 6px;
  padding: .1rem .35rem; cursor: pointer; font-size: .85rem;
}
.poi-note { flex-basis: 100%; font-size: .8rem; color: #555; padding-left: 1.2rem; white-space: pre-wrap; }
/* "in Route"-Schalter je POI */
.poi-route { flex-basis: 100%; display: flex; align-items: center; gap: .35rem;
  font-size: .78rem; color: var(--bg); padding-left: 1.2rem; cursor: pointer; }
.poi-route input { width: auto; margin: 0; cursor: pointer; }
/* POI als Wegpunkt in der Route-Liste */
#stopList li.route-poi { background: #f0f7f6; }
#stopList li.route-poi:hover { background: #e6f1ef; }
.sortable-ghost { opacity: .4; }
.sortable-chosen { background: #eef6f5; }
.trip-total { font-size: .85rem; color: var(--bg); font-weight: 600; margin: .1rem 0 .5rem; }

/* Google-Maps-Control "Mein Standort" */
.locate-btn {
  margin: 10px; width: 40px; height: 40px;
  background: #fff; border: none; border-radius: 8px;
  box-shadow: 0 1px 4px #0003; cursor: pointer;
  font-size: 1.2rem; color: #333;
}
.locate-btn:hover { background: #f4f4f4; }
.badge {
  display: inline-block; font-size: .7rem; color: #fff;
  padding: .05rem .4rem; border-radius: 6px; margin-left: .35rem;
}
.badge.geplant { background: var(--geplant); }
.badge.besucht { background: var(--besucht); }
.badge.reserviert { background: var(--reserviert); }
.row-actions { margin-top: .3rem; display: flex; gap: .4rem; }
.row-actions a, .row-actions button {
  font-size: .75rem; text-decoration: none; padding: .2rem .45rem;
  border-radius: 6px; border: 1px solid #ccc; background: #fafafa;
  color: #111; cursor: pointer;
}

/* Formular */
#stopForm {
  position: absolute; inset: 0; z-index: 20;
  background: #0006; display: flex; align-items: center; justify-content: center;
}
#stopForm.hidden { display: none; }
.form-card {
  background: #fff; padding: 1rem 1.1rem; border-radius: 12px;
  width: 320px; max-width: 90vw; box-shadow: 0 6px 24px #0005;
}
.form-card h3 { margin: 0 0 .6rem; }
.form-card label { display: block; font-size: .85rem; margin: .5rem 0; }
.form-card input, .form-card select, .form-card textarea {
  width: 100%; padding: .4rem; margin-top: .2rem;
  border: 1px solid #ccc; border-radius: 8px; font: inherit;
}
.form-card label.check { display: flex; align-items: center; gap: .5rem; margin: .6rem 0; }
.form-card label.check input { width: auto; margin: 0; }
.field-row[data-showif] { border-left: 3px solid var(--reserviert); padding-left: .6rem; margin: .3rem 0; }
.popup .res-info { margin-top: .35rem; font-size: .8rem; color: var(--reserviert); }
.coords { font-size: .8rem; color: #555; margin: .5rem 0; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }
.form-actions .primary { background: var(--bg); color: #fff; border: none; padding: .45rem .9rem; border-radius: 8px; cursor: pointer; }
.form-actions .ghost { background: #eee; border: none; padding: .45rem .9rem; border-radius: 8px; cursor: pointer; }

/* Modale Overlays (nutzen .form-card / .form-actions) */
#confirmModal, #tourForm {
  position: absolute; inset: 0; z-index: 25;
  background: #0006; display: flex; align-items: center; justify-content: center;
}
#confirmText { margin: .25rem 0 .75rem; line-height: 1.35; }

.hidden { display: none !important; }

/* Login / Registrierung */
#authOverlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
  padding: 1rem; padding-top: max(1rem, env(safe-area-inset-top));
}
.auth-card {
  background: #fff; border-radius: 14px; box-shadow: 0 8px 30px #0005;
  width: 340px; max-width: 92vw; padding: 1.3rem 1.3rem 1rem;
}
.auth-card h2 { margin: 0 0 .1rem; font-size: 1.25rem; }
#authSubtitle { margin: 0 0 .9rem; color: #666; font-size: .9rem; }
.auth-card label { display: block; font-size: .85rem; margin: .55rem 0; color: #333; }
.auth-card input {
  width: 100%; padding: .55rem; margin-top: .25rem; box-sizing: border-box;
  border: 1px solid #ccc; border-radius: 8px; font: inherit;
  background: #fff; color: #111;
}
.auth-error { color: #b91c1c; font-size: .82rem; min-height: 1.1em; margin: .3rem 0; }
#authSubmit {
  width: 100%; padding: .6rem; border: none; border-radius: 8px; cursor: pointer;
  background: var(--bg); color: #fff; font: inherit; font-weight: 600; min-height: 44px;
}
.auth-toggle { text-align: center; font-size: .85rem; color: #666; margin: .8rem 0 .2rem; }
.auth-toggle a { color: var(--bg); font-weight: 600; text-decoration: none; margin-left: .3rem; }

/* Popup-Inhalt */
.popup h4 { margin: 0 0 .3rem; }
.popup .nav-links { display: flex; gap: .4rem; margin-top: .5rem; }
.popup .nav-links a {
  font-size: .8rem; text-decoration: none; padding: .3rem .5rem;
  border-radius: 6px; background: var(--bg); color: #fff;
}
.popup .edit-links { display: flex; gap: .4rem; margin-top: .4rem; }
.popup .edit-links button {
  font-size: .75rem; border: 1px solid #ccc; background: #fafafa;
  border-radius: 6px; padding: .2rem .45rem; cursor: pointer;
}
