:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1a1a1a;
  --text-dim: #6b7280;
  --accent: #0066cc;
  --accent-2: #0055aa;
  --success: #1a8a3c;
  --warning: #cc7700;
  --danger: #cc2222;
  --border: #d8dbe0;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* Offline-Banner */
.offline-banner {
  background: var(--warning);
  color: #000;
  text-align: center;
  padding: 6px;
  font-size: 13px;
  font-weight: 600;
}
.hidden { display: none !important; }

/* Tabs */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}
.tab {
  flex: 1;
  padding: 12px 8px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Views */
.view-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 16px;
  display: none;
  z-index: 1;
}
.view.active { display: block; }

/* ============================================
   Suchformular
   ============================================ */
#form-search {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

/* Von und Nach: volle Breite, Label über Input */
#form-search > label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-dim);
}

/* Datum, Uhrzeit, Jetzt: alle in einer Zeile */
#form-search .form-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: flex-end;
  width: 100%;
}

#form-search .form-row > label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  min-width: 0;
}

/* Datum und Uhrzeit teilen sich den Platz */
#form-search .form-row > label:not(.checkbox-label) {
  flex: 1 1 0;
  font-size: 13px;
  color: var(--text-dim);
}

/* Jetzt so schmal wie möglich */
#form-search .form-row > label.checkbox-label {
  flex: 0 0 auto;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding-bottom: 12px;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text-dim);
}

/* Einheitliches Styling für alle Such-Inputs */
#form-search input[type="text"],
#form-search input[type="date"],
#form-search input[type="time"] {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 12px 10px;
  font-size: 15px;
  font-family: inherit;
  text-align: left;
  direction: ltr;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

/* Native iOS-Mindestbreite für date/time ausschalten */
#form-search input[type="date"],
#form-search input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
}

#form-search input:disabled {
  opacity: 0.5;
  background: var(--surface-2);
}

.input-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.input-row input {
  flex: 1;
  min-width: 0;
}
.btn-locate {
  flex-shrink: 0;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
}
.btn-locate:active {
  background: var(--surface);
}
.btn-locate:disabled {
  opacity: 0.5;
  cursor: default;
}

#form-search button[type="submit"] {
  margin-top: 6px;
  padding: 14px;
  width: 100%;
  font-size: 15px;
}

#search-results {
  margin-top: 14px;
}
#view-search form > label {
  position: relative;
}

.suggestions {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 2px;
  max-height: 260px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.suggestions.visible {
  display: block;
}
.suggestion-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.suggestion-item:last-child {
  border-bottom: none;
}
.suggestion-item:hover,
.suggestion-item.active {
  background: var(--surface-2);
}
.suggestion-name {
  font-size: 14px;
  color: var(--text);
}
.suggestion-type {
  font-size: 11px;
  color: var(--text-dim);
}

h2 {
  font-size: 18px;
  margin-bottom: 12px;
  color: var(--accent);
  text-align: left;
}
.hint { color: var(--text-dim); font-size: 13px; margin-bottom: 16px; }

/* Umgebungs-Tab */
.departures-list {
  border-top: 1px solid var(--border);
  padding-top: 6px;
}
.nearby-card {
  padding: 12px;
  border-left-width: 4px;
  border-left-style: solid;
}
.nearby-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}
.nearby-header h3 {
  font-size: 15px;
  margin: 0;
  color: var(--text);
}
.nearby-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
  font-size: 11px;
}
.nearby-cat {
  font-weight: 600;
}
.nearby-merged {
  color: var(--text-dim);
  font-size: 10px;
}
.nearby-distance {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.departure-row {
  display: grid;
  grid-template-columns: 4rem 1fr auto auto;
  gap: 8px;
  align-items: baseline;
  padding: 4px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.departure-row:last-child {
  border-bottom: none;
}
.dep-line {
  font-weight: 600;
  color: var(--accent);
}
.dep-direction {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dep-time {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.dep-platform {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-size: 12px;
}

#view-nearby {
  display: none;
}
#view-nearby.active {
  display: block;
}
#btn-nearby-refresh {
  width: 100%;
  margin-bottom: 12px;
}

/* Buttons */
.btn-primary, .btn-secondary {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-primary:active, .btn-secondary:active { opacity: 0.7; }

/* Reisekarten */
.journey-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  text-align: left;
}
.journey-card h3 {
  font-size: 15px;
  margin-bottom: 6px;
  color: var(--text);
}
.journey-card-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent) inset;
}

.journey-overview {
  font-size: 13px;
  color: var(--text-dim);
  margin: 4px 0 12px;
}

/* Legs */
.leg {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.leg:last-child { border-bottom: none; }
.leg-container {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 6px 0;
}
.leg-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 14px;
}
.leg-line { color: var(--accent); }
.leg-meta { font-size: 12px; color: var(--text-dim); font-weight: 400; }
.leg-row {
  display: grid;
  grid-template-columns: 1fr auto 4.5rem;
  gap: 10px;
  align-items: baseline;
  font-size: 13px;
  padding: 2px 0;
}
.leg-station { color: var(--text); }
.leg-time { color: var(--text); font-variant-numeric: tabular-nums; }
.leg-platform { color: var(--text-dim); text-align: right; font-variant-numeric: tabular-nums; }
.leg-transfer {
  background: rgba(0, 102, 204, 0.06);
  border-left: 3px solid var(--accent);
  padding: 10px 12px 10px 9px;
  margin: 4px 0;
  border-radius: 4px;
}
.leg-transfer .leg-header {
  margin-bottom: 0;
  font-weight: 500;
  color: var(--text-dim);
  font-size: 12px;
}
.leg-transfer .leg-row {
  padding: 4px 0;
  font-size: 12px;
  grid-template-columns: 1fr auto;
}
.leg-transfer .leg-time {
  color: var(--text-dim);
  display: none;
}
.leg-transfer .leg-platform {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.leg-reservations {
  font-size: 11px;
  color: var(--success);
  margin-top: 4px;
}
.leg-platform.changed
.stop-platform.changed { 
  color: var(--warning); 
  font-weight: 600; 
}
.leg-transfer-ok {
  background: rgba(0, 102, 204, 0.06);
  border-left-color: var(--accent);
}
.leg-transfer-tight {
  background: rgba(255, 152, 0, 0.12);
  border-left-color: var(--warning);
}
.leg-transfer-impossible {
  background: rgba(244, 67, 54, 0.12);
  border-left-color: var(--danger);
}
.leg-progress {
  grid-column: 1 / -1;
  margin: 8px 0 4px;
}
.leg-progress-bar {
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
}
.leg-progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.6s ease;
}
.leg-past {
  opacity: 0.55;
}

.stop-past {
  opacity: 0.55;
}
.stop-past .stop-name {
  color: var(--text-dim);
}
.stops-list .stop-current,
.stops-list .stop-next {
  background: rgba(0, 102, 204, 0.12);
  border-left: 3px solid var(--accent);
  padding: 8px 14px 8px 11px;
  margin: 2px -14px;
  border-radius: 4px;
  font-weight: 600;
}

.delay { color: var(--danger); font-weight: 600; }
.on-time { color: var(--success); }
.platform-change { color: var(--warning); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-content {
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 20px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  text-align: left;
}
.modal-content h3 { margin-bottom: 16px; }
.modal-content label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-dim);
}
.modal-content input, .modal-content select {
  display: block;
  width: 100%;
  padding: 10px;
  margin-top: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
}
.modal-content fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}
.modal-content legend {
  font-size: 12px;
  color: var(--accent);
  padding: 0 6px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.modal-actions button { flex: 1; }
#modal-share-text .modal-content {
  max-width: 600px;
}
#modal-share-text textarea {
  min-height: 240px;
  white-space: pre;
  overflow: auto;
}
#modal-db-import .modal-content {
  max-width: 600px;
}
#db-import-text {
  width: 100%;
  min-height: 200px;
  padding: 10px;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}
#btn-import-db {
  font-size: 12px;
  padding: 8px 12px;
}

/* Journey Actions */
.journey-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.journey-actions button, .journey-actions label {
  font-size: 12px;
  padding: 8px 12px;
  flex: 1;
  text-align: center;
}

/* Live-Indicator */
.live-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  margin-right: 6px;
  animation: pulse 2s infinite;
}
.live-indicator.offline { background: var(--warning); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Karte */
#map-content {
  height: 100%;
  min-height: 400px;
  background: var(--surface);
  border-radius: 12px;
  padding: 0;
}

/* Info-Tab */
.info-card {
  font-size: 14px;
  line-height: 1.6;
}
.info-card h3 {
  color: var(--accent);
  margin-bottom: 8px;
  font-size: 15px;
}
.info-card p {
  margin-bottom: 8px;
  color: var(--text);
}
.info-card p:last-child {
  margin-bottom: 0;
}
.info-card a {
  color: var(--accent);
  text-decoration: none;
}
.info-card a:hover {
  text-decoration: underline;
}
.info-card code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* Karten-View: kein Overflow, Karte füllt exakt den Platz */
#view-map {
  overflow: hidden;
  padding: 0;
  display: none;
}
#view-map.active {
  display: flex;
  flex-direction: column;
}
#map-content {
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;       /* hebt das alte min-height: 400px auf */
  border-radius: 0;
  position: relative;
}

/* Leaflet-Attribution immer sichtbar */
.leaflet-bottom.leaflet-right {
  z-index: 500;
}

/* Detailkarte */
.detail-card { padding: 14px; }

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}
.detail-header > div:first-child {
  flex: 1;
  min-width: 0;
}
.detail-header h3 {
  color: var(--accent);
  font-size: 16px;
  margin-bottom: 0;
  text-align: left;
}
.detail-meta { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.detail-update { font-size: 11px; color: var(--text-dim); margin-bottom: 8px; }

.btn-checkin-compact {
  flex-shrink: 0;
  align-self: flex-start;
  background: var(--success);
  color: #fff;
  border: none;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.btn-checkin {
  background: var(--success);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-checkin-done {
  background: var(--text-dim) !important;
  cursor: default;
}

/* Meldungen */
.remarks {
  background: rgba(204, 119, 0, 0.08);
  border-left: 3px solid var(--warning);
  padding: 8px 10px;
  margin-bottom: 16px;
  border-radius: 4px;
}
.remark {
  font-size: 12px;
  padding: 3px 0;
  color: var(--text);
  text-align: left;
}
.remark-time {
  color: var(--text-dim);
  margin-right: 6px;
  font-variant-numeric: tabular-nums;
}
.remark-warning { color: var(--warning); }

/* Halte */
.stops-list { margin-top: 12px; }

details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  padding: 6px 0;
}

.stop-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  text-align: left;
}
.stop-row:last-child { border-bottom: none; }
.stop-row.cancelled { opacity: 0.5; text-decoration: line-through; }

.stop-name { font-weight: 500; color: var(--text); }
.stop-cancel { color: var(--danger); font-size: 11px; margin-left: 6px; }
.stop-times {
  display: flex;
  gap: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  justify-content: flex-end;
}
.stop-platform { color: var(--text); }
.stop-remarks {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--warning);
}

/* Wagenreihung */
.wr-slot { grid-column: 1 / -1; margin-top: 8px; }
.wr-empty { font-size: 11px; color: var(--text-dim); padding: 6px 0; }
.wagenreihung {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px;
  margin: 6px 0;
}
.wr-title { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }
.wr-wagons {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.wagon {
  min-width: 44px;
  padding: 6px 4px;
  background: var(--surface);
  border-radius: 4px;
  text-align: center;
  font-size: 11px;
  border: 1px solid var(--border);
}
.wagon-num { font-weight: 700; font-size: 13px; }
.wagon-type { font-size: 9px; color: var(--text-dim); }
.wagon-reserved {
  border-color: var(--accent);
  background: rgba(0, 102, 204, 0.1);
}
.wagon-res { font-size: 9px; color: var(--accent); font-weight: 600; }
.zugtyp {
  font-size: 11px;
  color: var(--accent);
  margin-left: 4px;
}
.reservation-block { margin-top: 12px; }
.reservation-list { margin-top: 8px; }
.reservation {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  background: var(--surface-2);
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 4px;
}
.btn-remove-res {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
}
.btn-res-add {
  font-size: 12px;
  padding: 6px 10px;
}
.routing-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.routing-toolbar button {
  margin-left: auto;
  font-size: 12px;
  padding: 6px 12px;
}
.routing-toolbar .hint {
  margin: 0;
  line-height: 1.2;
}
.routing-toolbar .live-indicator {
  flex-shrink: 0;
}

/* --- Klickbarer Umsteige-Bahnhof --- */
.btn-transfer-search {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}
.btn-transfer-search:hover,
.btn-transfer-search:focus-visible {
  color: var(--accent, #4a9eff);
  text-decoration-style: solid;
}
.btn-transfer-search:focus-visible {
  outline: 2px solid var(--accent, #4a9eff);
  outline-offset: 2px;
  border-radius: 3px;
}

/* =====================================================================
   iOS: Safe Areas + deterministisches Layout
   ===================================================================== */

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  background: var(--bg, #1a1a2e);
}

body {
  margin: 0 !important;
  padding: 0 !important;
  touch-action: pan-x pan-y;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

/* #app als strikte vertikale Flex-Spalte: Tabs oben, Content darunter.
   Damit kann kein negativer Margin o.ä. den Content unter die Tabs ziehen. */
#app {
  display: flex !important;
  flex-direction: column !important;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: 0 !important;
  margin-top: 0 !important;
}

/* Tabs: sticky, nehmen ihren Platz im Flow ein, mit Safe-Area-Padding */
#app > .tabs {
  position: sticky !important;
  top: 0 !important;
  flex: 0 0 auto !important;
  z-index: 100;
  padding-top: var(--safe-top) !important;
  background: #1a1a2e !important;
  margin: 0 !important;
  isolation: isolate;
}

/* Content-Container: füllt den Rest, KEIN Offset-Trick */
#app > .view-container {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  position: relative !important;
  margin-top: 0 !important;
  padding-top: 0 !important;
  overflow: hidden;
}

/* Alle Views (auch die früher außerhalb stehenden) sind jetzt absolute
   Ebenen innerhalb des View-Containers — sie füllen exakt dessen Bereich
   unterhalb der Tabs. */
#app > .view-container > .view {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  margin-top: 0 !important;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#app > .view-container > .view:not(.active) {
  visibility: hidden;
  pointer-events: none;
}

/* Modals respektieren die Safe-Area ebenfalls */
.modal-content {
  padding-top: max(16px, var(--safe-top));
  padding-bottom: max(16px, var(--safe-bottom));
}

/* --- Pull-to-Refresh-Indikator --- */
#ptr-indicator {
  position: fixed;
  top: var(--safe-top);
  left: 50%;
  width: 40px;
  height: 40px;
  margin-left: -20px;
  border-radius: 50%;
  background: var(--bg-elevated, #25253f);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateY(-60px);
  transition: transform 0.2s ease-out, opacity 0.2s ease-out;
  opacity: 0;
  z-index: 999;
  pointer-events: none;
}

#ptr-indicator.visible {
  opacity: 1;
  transition: transform 0.05s linear, opacity 0.05s linear;
}

#ptr-indicator.ready .ptr-spinner {
  border-top-color: var(--accent, #4a9eff);
  border-right-color: var(--accent, #4a9eff);
  transform: rotate(45deg);
}

#ptr-indicator.refreshing .ptr-spinner {
  animation: ptr-spin 0.7s linear infinite;
  border-top-color: var(--accent, #4a9eff);
  border-right-color: var(--accent, #4a9eff);
}

.ptr-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--text-dim, #888);
  border-top-color: var(--text-dim, #888);
  border-right-color: var(--text-dim, #888);
  border-radius: 50%;
  transition: transform 0.2s ease-out;
}

@keyframes ptr-spin {
  to { transform: rotate(360deg); }
}


/* --- Reisezeit-Spanne über 24 h (über der Trefferliste) --- */
.search-range-info {
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.4;
  background: rgba(74, 158, 255, 0.18);
  border-radius: 8px;
  border-left: 3px solid var(--accent, #4a9eff);
  color: var(--text, #e8e8e8);
}
.search-range-info.hint {
  color: var(--text-dim, #aaa);
  border-left-color: var(--text-dim, #888);
}
.search-range-info strong {
  color: var(--accent, #4a9eff);
  font-weight: 600;
}


/* --- Histogramme unter der Reisezeit-Analyse --- */
.search-range-actions {
  margin-top: 8px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent, #4a9eff);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 0;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}
.btn-link:hover,
.btn-link:focus-visible {
  text-decoration-style: solid;
}

.histograms {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 520px) {
  .histograms {
    grid-template-columns: 1fr;
  }
}

.histogram-block {
  background: rgba(0, 0, 0, 0.18);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--accent, #4a9eff);
}

.histogram-title {
  font-size: 12px;
  color: var(--text-dim, #aaa);
  margin-bottom: 6px;
  line-height: 1.3;
}

.histogram {
  width: 100%;
  height: 100px;
  display: block;
  color: var(--accent, #4a9eff);
}

.histogram-axis-label {
  font-size: 10px;
  fill: var(--text-dim, #888);
  font-family: inherit;
}


/* =====================================================================
   App-Header mit Hamburger-Menü
   ===================================================================== */

#app > .app-header {
  position: sticky;
  top: 0;
  flex: 0 0 auto;
  z-index: 100;
  padding-top: var(--safe-top);
  background: #1a1a2e;
  isolation: isolate;
  margin: 0;
}

.app-header-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  min-height: 44px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.app-header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text, #fff);
}

.menu-toggle {
  background: none;
  border: none;
  color: var(--text, #fff);
  width: 40px;
  height: 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  transition: transform 0.2s, opacity 0.2s;
}

.menu-toggle[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.menu-toggle[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}

.menu-toggle[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Desktop: horizontale Tabs */
@media (min-width: 768px) {
  #app > .app-header > .tabs {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px;
    background: transparent;
    margin: 0;
  }
  
  #app > .app-header > .tabs .tab {
    padding: 8px 14px;
    border-radius: 6px;
    background: transparent;
    border: none;
    color: var(--text-dim, #aaa);
    cursor: pointer;
    font-size: 14px;
  }
  
  #app > .app-header > .tabs .tab.active {
    background: var(--accent, #4a9eff);
    color: #fff;
  }
  
  #app > .app-header > .tabs .tab:hover {
    background: rgba(74, 158, 255, 0.2);
    color: var(--text, #fff);
  }
}

/* Mobile: Hamburger + ausklappbare Tab-Liste */
@media (max-width: 767px) {
  .app-header-bar {
    display: flex;
  }
  
  #app > .app-header > .tabs {
    display: flex;
    flex-direction: column;
    max-height: 0;
    overflow: hidden;
    padding: 0;
    transition: max-height 0.3s ease-out;
    width: 100%;
    background: transparent;
    margin: 0;
  }
  
  #app > .app-header > .tabs.open {
    max-height: 600px;
    padding: 4px 0 8px;
  }
  
  #app > .app-header > .tabs .tab {
    width: 100%;
    text-align: left;
    padding: 14px 20px;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: transparent;
    color: var(--text, #fff);
    font-size: 15px;
    cursor: pointer;
  }
  
  #app > .app-header > .tabs .tab:last-child {
    border-bottom: none;
  }
  
  #app > .app-header > .tabs .tab.active {
    background: rgba(74, 158, 255, 0.15);
    color: var(--accent, #4a9eff);
  }
}


/* --- Einstellungsseite --- */
#form-settings .journey-card {
  margin-bottom: 16px;
}

#form-settings label {
  display: block;
  margin-top: 12px;
}

#form-settings input[type="password"] {
  width: 100%;
  box-sizing: border-box;
}

.settings-status {
  margin-top: 12px;
  min-height: 20px;
  font-size: 14px;
}

.settings-status.success {
  color: #2ecc71;
}

.settings-status.error {
  color: #e74c3c;
}


/* --- Light-theme override for app-header ---
   Menü folgt dem Rest der App: heller Hintergrund, dunkle Schrift. */
#app > .app-header {
  background: var(--bg, #fff) !important;
}
.app-header-bar {
  border-bottom: 1px solid var(--border, rgba(0, 0, 0, 0.1)) !important;
}
.app-header-title,
.menu-toggle {
  color: var(--text, #1a1a2e) !important;
}
@media (max-width: 767px) {
  #app > .app-header > .tabs .tab {
    color: var(--text, #1a1a2e) !important;
    border-bottom-color: var(--border, rgba(0, 0, 0, 0.08)) !important;
  }
  #app > .app-header > .tabs .tab.active {
    background: var(--accent, #4a9eff) !important;
    color: #fff !important;
  }
}
@media (min-width: 768px) {
  #app > .app-header > .tabs .tab {
    color: var(--text-dim, #666) !important;
  }
  #app > .app-header > .tabs .tab:hover {
    color: var(--text, #1a1a2e) !important;
  }
  #app > .app-header > .tabs .tab.active {
    background: var(--accent, #4a9eff) !important;
    color: #fff !important;
  }
}


/* --- Karte füllt verfügbaren Bereich --- */
#app > .view-container > #view-map {
  overflow: hidden !important;
  padding: 0 !important;
  margin: 0 !important;
}

#app > .view-container > #view-map > #map-content {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: auto !important;
  height: auto !important;
  padding: 0 !important;
  margin: 0 !important;
}


/* --- Karte: Leaflet-Controls über Safe-Area --- */
#app > .view-container > #view-map > #map-content .leaflet-bottom {
  bottom: max(8px, env(safe-area-inset-bottom, 0px)) !important;
}
#app > .view-container > #view-map > #map-content .leaflet-left {
  left: max(4px, env(safe-area-inset-left, 0px)) !important;
}
#app > .view-container > #view-map > #map-content .leaflet-right {
  right: max(4px, env(safe-area-inset-right, 0px)) !important;
}


/* --- Früher/Später-Buttons in der Suche --- */
.search-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-controls button {
  flex: 1;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border, rgba(0,0,0,0.15));
  background: var(--bg-elevated, #f0f0f0);
  color: var(--text, #1a1a2e);
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.search-controls button:hover:not(:disabled) {
  background: var(--accent, #4a9eff);
  color: #fff;
  border-color: var(--accent, #4a9eff);
}

.search-controls button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}


/* --- Zweiter Suchsteuerungs-Container (Später-Button unten) --- */
.search-controls.search-controls-below {
  margin-top: 12px;
  margin-bottom: 0;
}


/* --- Tauschen-Button in der Nach-Zeile --- */
.input-row .btn-swap {
  background: none;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.15));
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  color: inherit;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.input-row .btn-swap:hover {
  background: var(--accent, #4a9eff);
  color: #fff;
  border-color: var(--accent, #4a9eff);
}


/* =====================================================================
   Views mit Float-Buttons (Reisen / Details / Karte)
   ===================================================================== */

/* Container mit Float-Buttons: äußerer View scrollt nicht mehr,
   das übernimmt .view-scroll */
#app > .view-container > .view.has-float-controls {
  overflow: hidden !important;
}

/* Innerer Scroll-Container: hält Float-Buttons frei */
#app > .view-container > .view.has-float-controls > .view-scroll {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-top: 56px;
  padding-left: 12px;
  padding-right: 12px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}

/* Float-Buttons */
.float-btn {
  position: absolute;
  z-index: 900;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(26, 26, 46, 0.85);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: background 0.15s;
}
.float-btn:hover {
  background: rgba(74, 158, 255, 0.9);
}

.float-top-left {
  top: 12px;
  left: 12px;
}

.float-top-right {
  top: 12px;
  right: 12px;
}

.float-bottom-center {
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
}

/* Karten-Schließen-Button über Leaflet-Controls halten */
#view-map .float-btn {
  z-index: 1100;
}




/* --- Einheitliches Padding für In-Flow-Views (ohne Float-Buttons) --- */
#view-nearby,
#view-settings,
#view-info {
  padding: 12px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}

#view-nearby > *:first-child,
#view-settings > *:first-child,
#view-info > *:first-child {
  margin-top: 0;
}

/* .journey-card in .view-scroll: kein zusätzliches L/R-Margin */
.view-scroll .journey-card,
.view-scroll .journey-actions {
  margin-left: 0;
  margin-right: 0;
}


/* --- Primäre Float-Button-Variante (Suchen) --- */
.float-btn.float-btn-primary {
  background: rgba(74, 158, 255, 0.95);
  border-color: rgba(74, 158, 255, 0.6);
  font-weight: 600;
}
.float-btn.float-btn-primary:hover {
  background: var(--accent, #4a9eff);
  border-color: var(--accent, #4a9eff);
}


/* =====================================================================
   Loading-Indikatoren
   ===================================================================== */

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Basis-Spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(74, 158, 255, 0.3);
  border-top-color: #4a9eff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.spinner-sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
  vertical-align: middle;
}

/* Initialer Ladezustand (vor dem ersten Rendern) */
.view-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 20px;
  color: var(--text-dim, #888);
  font-size: 14px;
}

/* Refresh-Overlay auf Content-Containern */
.is-refreshing {
  position: relative;
  min-height: 100px;
}

.is-refreshing::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(26, 26, 46, 0.35);
  border-radius: 8px;
  z-index: 98;
  pointer-events: none;
}

.is-refreshing::after {
  content: '';
  position: absolute;
  top: 24px;
  left: 50%;
  width: 28px;
  height: 28px;
  margin-left: -14px;
  border: 3px solid rgba(74, 158, 255, 0.3);
  border-top-color: #4a9eff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  z-index: 99;
  pointer-events: none;
}

/* Check-in-Button im Ladezustand */
.btn-checkin-compact.btn-checkin-loading {
  opacity: 0.85;
  cursor: wait;
}
.btn-checkin-compact:disabled {
  cursor: wait;
}

/* Refresh-Button deaktiviert */
.btn-refresh-action:disabled {
  opacity: 0.55;
  cursor: wait;
}


/* --- Spinner auf primärem Button (weiß, damit auf blau sichtbar) --- */
.btn-primary .spinner,
.btn-primary .spinner-sm {
  border-color: rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  vertical-align: middle;
  margin-right: 6px;
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: wait;
}
