/* Mobile (portrait) overrides for the UI system. Loaded directly before mobile-nav.css,
   which owns the bottom nav and the final mobile overrides. */

@media (max-width: 960px) and (orientation: portrait) {
  :root {
    --control-h: 42px;
  }

  .btn {
    padding: 0 var(--sp-4);
  }

  .map-mode-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    justify-content: center;
  }

  .mode-label {
    display: none;
  }

  .tabbar-btn {
    min-height: 44px;
  }

  .sidebar {
    padding: 0;
  }


  body.mobile-progress-open .progress-panel {
    border-top: none;
  }

  /* Line view participates in app navigation: it sits above the tab bar
     instead of covering it, so the user can switch screens normally. */
  body.line-view-open .line-view-panel {
    top: var(--topbar-h);
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: var(--sp-3);
  }

  body.line-view-open .tabbar {
    display: flex;
  }
}

@media (max-width: 960px) and (orientation: portrait) {
  body.map-chrome-hidden .sidebar-quickfilter,
  body.map-chrome-hidden .map-corner-brand,
  body.map-chrome-hidden .map-overlay-controls,
  body.map-chrome-hidden .maplibregl-control-container {
    display: none !important;
  }

  .sheet-handle,
  .line-view-sheet-handle {
    width: 32px;
    height: 3px;
    min-height: 3px;
    margin: 2px auto 2px;
  }

  .line-view-header,
  .filters-panel-header {
    padding-top: 2px;
  }

  .line-view-panel.sheet-peek .line-view-stop-list {
    display: none !important;
  }

  .line-progress-row {
    padding: 6px 0;
    gap: 4px;
  }

  .line-progress-main {
    gap: 8px;
  }

  #overlayProgressList {
    padding: 0;
    margin: 0;
  }

  .progress-overlay-stats {
    gap: var(--sp-2);
  }

  .sidebar-quickfilter .quickfilter-search input[type="search"] {
    font-size: 15px;
  }

  .dialog-close {
    color: var(--ink);
  }

  .line-view-name {
    white-space: normal;
  }

  .line-view-panel.sheet-peek .line-view-facts,
  .line-view-panel.sheet-peek .user-status-card {
    display: none !important;
  }

  .line-view-panel.sheet-peek .line-view-status-text,
  .line-view-panel.sheet-peek .line-view-diagnostics {
    display: none !important;
  }

  .line-view-panel.sheet-peek .line-view-status {
    padding-bottom: 0;
    margin: 0;
  }
}

@media (max-width: 960px) and (orientation: portrait) {
  .topbar-nav {
    display: none;
  }

  .filters-panel-backdrop {
    padding: 0;
    align-items: stretch;
    background: transparent;
  }

  .filters-panel {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    width: auto;
    height: 200px;
    max-height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - 20px);
    z-index: 21;
    padding: var(--sp-4);
    border: none;
    border-top: 1px solid var(--panel-border);
    border-radius: 14px 14px 0 0;
    box-shadow: none;
    overflow: hidden;
    transition: height 0.3s cubic-bezier(0.2, 0.9, 0.25, 1);
  }

  .filters-panel.sheet-full {
    height: min(78dvh, calc(100dvh - var(--topbar-h) - var(--tabbar-h) - 20px));
    overflow-y: auto;
  }

  .filters-panel.sheet-peek {
    height: 76px;
  }

  .filters-panel.sheet-half {
    height: 52dvh;
  }

  .filters-panel.sheet-full {
    height: min(88dvh, calc(100dvh - env(safe-area-inset-top) - 16px));
    overflow-y: auto;
  }

  .filters-panel {
    padding: 14px;
  }

  .filters-panel-body {
    gap: 12px;
  }

  .filters-col {
    max-height: none;
  }

  .filter-section + .filter-section {
    margin-top: 8px;
    padding-top: 8px;
  }

  #progressOverlay .filters-panel {
    padding: 16px;
  }

  #overlayProgressList {
    padding: 0;
    margin: 0;
  }

  .line-progress-row {
    padding: 8px 0;
  }

  .filters-panel.sheet-dragging {
    transition: none;
  }

  .filters-panel-header {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 6px var(--sp-3);
  }

  .sheet-handle {
    display: block;
    grid-column: 1 / -1;
    width: 40px;
    min-height: 4px;
    height: 4px;
    margin: 0 auto 6px;
    border-radius: 999px;
    background: var(--gray-4, rgba(0, 0, 0, 0.25));
    touch-action: none;
  }

  body.mobile-progress-open .line-view-panel,
  body.filters-panel-open .line-view-panel,
  body.progress-overlay-open .line-view-panel {
    display: none;
  }

  .filters-grid,
  .progress-overlay-grid,
  #progressOverlayBody .panel-dropdown-body {
    grid-template-columns: 1fr;
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
  }

  #progressOverlayBody #lineProgressList,
  #overlayProgressList {
    grid-row: auto;
    max-height: none;
  }

  .map-loading-badge {
    left: 12px;
    right: auto;
    bottom: calc(var(--tabbar-h) + 64px + env(safe-area-inset-bottom));
    background: var(--panel);
    color: var(--ink);
  }
}

@media (max-width: 960px) and (orientation: portrait) {
  .user-status-card {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 12px;
  }

  .route-select-panel .route-select-popup,
  .route-select-list,
  .map-loading-badge,
  .map-mode-btn,
  .map-notice-card,
  .maplibregl-popup-content,
  .maplibregl-ctrl-group,
  .line-view-panel,
  .line-view-card {
    background: var(--panel);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

@media (max-width: 960px) and (orientation: portrait) {
  .line-view-panel.is-empty .line-view-stop-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 8px 0;
  }

  body.map-chrome-hidden .sidebar-quickfilter,
  body.map-chrome-hidden .map-corner-brand,
  body.map-chrome-hidden .map-overlay-controls,
  body.map-chrome-hidden .maplibregl-control-container {
    display: none !important;
  }
}

@media (max-width: 960px) and (orientation: portrait) {
  .progress-overlay-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .progress-overlay-stats,
  #overlayProgressList {
    width: 100%;
    max-width: none;
  }

  .line-progress-row {
    padding: 6px 0;
  }

  .sheet-handle,
  .line-view-sheet-handle {
    width: 28px;
    height: 3px;
    min-height: 3px;
    margin: 2px auto 2px;
  }

  .filters-panel-header,
  .line-view-header {
    padding-top: 0;
  }
}
