/* Phone discovery owns a map/list switch and a single results scroll area.
   Keep this after the shared stylesheet so historic sidebar rules cannot
   hide results or constrain the full-screen filter sheet to desktop heights. */
#mobileDiscoveryViews,
#mobileDiscoveryResults {
  display: none;
}

@media (max-width: 767px), (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
  body.platform-route-discovery:not(.landing-open) #mobileDiscoveryViews {
    flex: 0 0 auto;
    display: flex;
    align-self: center;
    width: calc(100% - 20px);
    max-width: 420px;
    gap: 4px;
    margin: 7px 10px 0;
    padding: 4px;
    border: 1px solid var(--discovery-border);
    border-radius: 14px;
    background: var(--discovery-surface-raised);
  }

  #mobileDiscoveryViews button {
    flex: 1 1 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 0;
    min-height: 44px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--discovery-muted);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    touch-action: manipulation;
  }

  #mobileDiscoveryViews button[aria-pressed="true"] {
    border-color: var(--discovery-border-strong);
    background: var(--discovery-surface-accent);
    color: var(--discovery-text);
  }

  #mobileDiscoveryViews button:focus-visible {
    outline: 3px solid var(--discovery-accent, #16803d);
    outline-offset: 1px;
  }

  #mobileResultCount {
    min-width: 24px;
    padding: 3px 6px;
    border-radius: 7px;
    background: var(--discovery-surface-soft);
    font-size: 0.8rem;
  }

  body.platform-route-discovery:not(.landing-open) #topbar-search #searchInput {
    font-size: 16px !important;
  }

  body.platform-route-discovery:not(.landing-open) #app {
    min-height: 0 !important;
  }

  body.platform-route-discovery.mobile-discovery-list:not(.landing-open) #mobileDiscoveryResults:not([hidden]) {
    position: absolute;
    inset: 0;
    z-index: 500;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: var(--discovery-surface-raised);
    color: var(--discovery-text);
  }

  body.platform-route-discovery.mobile-discovery-list:not(.landing-open) :is(#map, #floatingActions, #eventMapLegend) {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  body.platform-route-discovery.mobile-discovery-list:not(.landing-open) #app #floatingActions {
    display: none !important;
  }

  body.platform-route-discovery:not(.landing-open) #mobileDiscoveryResults #eventListToolbar {
    display: flex !important;
    flex: 0 0 auto !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 6px !important;
    min-height: 0 !important;
    padding: 8px !important;
    overflow: visible !important;
  }

  body.platform-route-discovery:not(.landing-open) #mobileDiscoveryResults #eventListSummary {
    flex: 1 1 auto;
    min-width: 0;
    padding: 2px 4px;
  }

  body.platform-route-discovery:not(.landing-open) #mobileDiscoveryResults #eventListToolbar button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex: 0 1 auto !important;
    min-width: 0 !important;
    min-height: 44px !important;
    padding: 8px !important;
    font-size: 0.8rem !important;
    white-space: normal !important;
  }

  body.platform-route-discovery:not(.landing-open) #mobileDiscoveryResults #eventListToolbar :is(#toggleEventListFullscreen, #toggleEventCardDensity) {
    display: none !important;
  }

  body.platform-route-discovery:not(.landing-open) #mobileDiscoveryResults .event-empty-reset-btn {
    min-height: 44px;
    background: var(--theme-action) !important;
    color: var(--theme-action-text) !important;
  }

  body.platform-route-discovery:not(.landing-open) #mobileDiscoveryResults #eventList {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 0 !important;
    min-height: 0 !important;
    min-width: 0 !important;
    max-height: none !important;
    padding: 8px 8px max(12px, env(safe-area-inset-bottom)) !important;
    gap: 10px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
    scroll-padding-block: 8px;
  }

  #mobileDiscoveryResults .event-card {
    flex: 0 0 auto !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
  }

  body.platform-route-discovery:not(.landing-open) #mobileDiscoveryResults .favorite-btn {
    min-width: 44px !important;
    min-height: 44px !important;
  }

  body.platform-route-discovery:not(.landing-open) #mobileDiscoveryResults .event-status-text {
    color: var(--discovery-text) !important;
  }

  body.platform-route-discovery:not(.landing-open) #mobileDiscoveryResults .event-facts-grid span {
    color: var(--discovery-muted) !important;
  }

  body.platform-route-discovery:not(.landing-open) #discoveryFooter #legalLinks {
    justify-content: flex-start !important;
  }

  body.platform-route-discovery:not(.landing-open) #sidebar > .filter-actions-row {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    flex: 0 0 auto !important;
    gap: 8px !important;
    margin: 0 !important;
    padding: 10px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)) !important;
    border-top: 1px solid var(--discovery-border);
    background: var(--discovery-surface-raised);
  }

  body.platform-route-discovery:not(.landing-open) #sidebar > .filter-actions-row button {
    display: inline-flex !important;
    justify-content: center;
    align-items: center;
    width: 100% !important;
    min-height: 48px !important;
    padding: 8px !important;
    border: 1px solid var(--discovery-border-strong);
    border-radius: 12px;
    background: var(--discovery-surface-soft);
    color: var(--discovery-text);
    font-size: 0.85rem !important;
    font-weight: 750;
    white-space: normal;
  }

  body.platform-route-discovery:not(.landing-open) #sidebar > .filter-actions-row #applyMobileFiltersBtn {
    background: var(--theme-action) !important;
    color: var(--theme-action-text) !important;
  }

  body.platform-route-discovery.discovery-panel-open:not(.landing-open):not(.sidebar-collapsed):not(.event-list-fullscreen):not(.mobile-filter-open) #sidebar-header {
    flex: 1 1 auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
  }
}

@media (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
  body.platform-route-discovery:not(.landing-open) #topbar {
    grid-template-columns: auto minmax(120px, 1fr) 160px !important;
    grid-template-areas: "left search views" !important;
    min-height: 0 !important;
    height: auto !important;
    padding-block: 6px !important;
  }

  body.platform-route-discovery:not(.landing-open) #topbar #brandHomeLink {
    display: none !important;
  }

  body.platform-route-discovery:not(.landing-open) #mobileDiscoveryViews {
    grid-area: views;
    align-self: center;
    width: 160px;
    margin: 0;
    padding: 3px;
  }

  #mobileDiscoveryViews button {
    gap: 4px;
    padding-inline: 6px;
    font-size: 0.8rem;
  }
}

@media (min-width: 768px) and (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
  body.platform-route-discovery:not(.landing-open) .discovery-panel-mobile-header {
    display: flex !important;
    flex: 0 0 auto !important;
    min-height: 54px !important;
  }

  body.platform-route-discovery:not(.landing-open) #sidebar {
    touch-action: pan-y;
    overscroll-behavior: contain;
  }

  body.platform-route-discovery.discovery-panel-open:not(.landing-open) :is(#map, #eventDrawer, #floatingActions) {
    pointer-events: none !important;
  }
}

/* Tablet result lists must shrink inside the sidebar instead of extending
   below its clipped edge. */
@media (min-width: 768px) and (max-width: 1023px) and (min-height: 501px) {
  body.platform-route-discovery:not(.landing-open) #sidebar #eventList {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
  }

  body.platform-route-discovery:not(.landing-open) #sidebar #eventListToolbar {
    flex-shrink: 0 !important;
  }
}
