/* RailRadar Punkt 5.5 – Mobile Finalisierung 1.0.0 */

/* Defensive overflow protection for the public app only. */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

@media (max-width: 760px) {
  /* Search / result actions */
  .rr-journey-search,
  .rr-journey-search-form,
  .rr-journey-search-results,
  .rr-search-result,
  .rr-search-result > * {
    min-width: 0;
    max-width: 100%;
  }

  .rr-journey-search-button,
  .rr-search-result-open,
  .rr-search-result-map,
  .rr-journey-map-focus {
    min-height: 44px;
    white-space: normal;
  }

  .rr-search-result-meta,
  .rr-search-result-title strong {
    overflow-wrap: anywhere;
  }

  /* Map layer control stays fully inside the map viewport. */
  .rr-map-layers {
    left: 8px;
    right: auto;
    top: 8px;
    max-width: calc(100% - 62px);
    align-items: stretch;
  }

  .rr-map-layers-toggle {
    min-height: 44px;
    padding: 10px 13px;
    touch-action: manipulation;
  }

  .rr-map-layers-panel {
    width: min(280px, calc(100vw - 40px));
    min-width: 0;
    max-width: calc(100vw - 40px);
    max-height: min(62vh, 430px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .rr-map-layer-option {
    min-height: 44px;
    padding: 9px 4px;
  }

  .rr-map-layer-option input {
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
  }

  .rr-live-filter-select {
    min-height: 44px;
    font-size: 16px; /* avoids unwanted iOS form zoom */
  }

  /* Keep the map usable while controls are open. */
  .maplibregl-ctrl-top-right {
    top: 4px;
    right: 4px;
  }

  .maplibregl-ctrl-group button {
    width: 40px;
    height: 40px;
  }

  /* GPS overlay may not span beyond the viewport. */
  .map-overlay {
    left: 8px;
    right: 8px;
    bottom: 8px;
    max-width: calc(100% - 16px);
    overflow-wrap: anywhere;
  }

  /* Map popups: never wider than the mobile viewport. */
  .maplibregl-popup {
    max-width: calc(100vw - 28px) !important;
  }

  .maplibregl-popup-content {
    width: auto;
    min-width: 0;
    max-width: min(280px, calc(100vw - 44px));
    overflow-wrap: anywhere;
  }

  .rr-live-map-popup,
  .rr-safe-next-map-popup {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .rr-live-map-popup button,
  .rr-safe-next-map-popup button {
    min-height: 44px;
    padding: 10px 12px;
    touch-action: manipulation;
  }

  .maplibregl-popup-close-button {
    width: 36px;
    height: 36px;
    line-height: 32px;
  }

  /* Safe-next marker itself remains compact, but may wrap long place names. */
  .rr-safe-next-map-marker {
    max-width: 132px;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.1;
  }

  /* Journey modal / single renderer */
  .rr-journey-modal {
    align-items: end;
    padding: 8px;
  }

  .rr-journey-dialog {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 16px);
    padding: 16px;
    border-radius: 16px 16px 10px 10px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .rr-journey-close {
    width: 44px;
    height: 44px;
    right: 8px;
    top: 8px;
    touch-action: manipulation;
  }

  .rr-journey-detail h2 {
    margin-right: 52px;
    overflow-wrap: anywhere;
  }

  .rr-journey-step {
    grid-template-columns: 44px 12px minmax(0, 1fr);
    gap: 8px;
  }

  .rr-journey-step-body,
  .rr-active-timeline-content,
  .rr-active-timeline-head,
  .rr-active-timeline-route {
    min-width: 0;
    max-width: 100%;
  }

  .rr-journey-step-body strong,
  .rr-journey-step-body span,
  .rr-journey-step-body small,
  .rr-active-timeline-content strong,
  .rr-active-timeline-route {
    overflow-wrap: anywhere;
  }

  .rr-journey-map-focus {
    min-height: 44px;
  }
}

@media (max-width: 420px) {
  .rr-map-layers {
    max-width: calc(100% - 54px);
  }

  .rr-map-layers-panel {
    width: calc(100vw - 32px);
    max-width: calc(100vw - 32px);
  }

  .maplibregl-popup-content {
    max-width: calc(100vw - 36px);
    padding: 13px 14px;
  }

  .rr-journey-dialog {
    padding: 14px;
  }

  .rr-journey-step {
    grid-template-columns: 40px 10px minmax(0, 1fr);
  }
}
