/**
 * Адаптив для узких экранов (≤899px). Десктоп ≥900px — без изменений.
 */

@media (min-width: 900px) {
  .site-mobile-nav {
    display: none !important;
  }

  .site-mobile-nav-toggle {
    display: none !important;
  }
}

@media (max-width: 899px) {
  .site-desktop-marsh-bar {
    display: none !important;
  }

  .site-mobile-nav-toggle {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 40px;
    height: 40px;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    flex-shrink: 0;
    box-sizing: border-box;
  }

  .site-mobile-nav-toggle:hover {
    background: rgba(255, 255, 255, 0.18);
  }

  .site-mobile-nav-toggle:focus-visible {
    outline: 2px solid rgba(251, 202, 31, 0.85);
    outline-offset: 2px;
  }

  .site-mobile-nav-toggle__bar {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 1px;
    background: #f8fafc;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  .site-mobile-nav-toggle[aria-expanded='true'] .site-mobile-nav-toggle__bar:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
  }

  .site-mobile-nav-toggle[aria-expanded='true'] .site-mobile-nav-toggle__bar:nth-child(2) {
    opacity: 0;
  }

  .site-mobile-nav-toggle[aria-expanded='true'] .site-mobile-nav-toggle__bar:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
  }

  .content_top {
    gap: 8px;
    padding: 4px 8px;
    margin: 4px;
  }

  .logo {
    width: 120px;
    height: 40px;
    margin-left: 4px;
  }

  .left-items {
    gap: 8px;
    min-width: 0;
  }

  .right-items {
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .right-items > span {
    display: inline-flex;
  }

  .right-items .but {
    padding: 0.35em 0.65em;
    font-size: 0.8rem;
  }

  .user-header-acts {
    gap: 4px;
  }

  .user-menu__toggle {
    max-width: min(42vw, 9rem);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0.35em 0.5em;
    font-size: 0.8rem;
  }

  .site-mobile-nav[hidden] {
    display: none !important;
  }

  .site-mobile-nav:not([hidden]) {
    position: fixed;
    inset: 0;
    z-index: 32000;
    display: flex;
    align-items: stretch;
    justify-content: flex-start;
    pointer-events: none;
  }

  .site-mobile-nav:not([hidden]) > * {
    pointer-events: auto;
  }

  .site-mobile-nav__backdrop {
    position: absolute;
    inset: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: rgba(2, 6, 23, 0.55);
    cursor: pointer;
  }

  .site-mobile-nav__sheet {
    position: relative;
    z-index: 1;
    width: min(18rem, 86vw);
    max-width: 100%;
    margin: 0;
    padding: 0;
    background: rgba(15, 23, 42, 0.97);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    min-height: 100%;
    box-sizing: border-box;
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-top: env(safe-area-inset-top, 0);
  }

  .site-mobile-nav__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
  }

  .site-mobile-nav__title {
    font-weight: 700;
    font-size: 1rem;
    color: #f8fafc;
  }

  .site-mobile-nav__close {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #f8fafc;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
  }

  .site-mobile-nav__links {
    display: flex;
    flex-direction: column;
    padding: 8px 10px 16px;
    gap: 4px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .site-mobile-nav__link {
    display: block;
    padding: 12px 14px;
    border-radius: 8px;
    color: #e2e8f0;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 600;
    border: 1px solid transparent;
  }

  .site-mobile-nav__link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
  }

  .site-mobile-nav__link--active {
    background: rgba(251, 202, 31, 0.2);
    border-color: rgba(251, 202, 31, 0.45);
    color: #facc15;
  }

  .content_subtop {
    height: 40px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    margin: 4px;
    padding: 0 8px;
    gap: 8px;
    align-items: center;
  }

  .content_subtop.content_subtop--races-filters {
    height: 40px;
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .content-subtop-filters {
    flex-wrap: nowrap;
    min-width: min-content;
    flex: 1 1 auto;
  }

  .content-subtop-actions {
    flex-shrink: 0;
  }

  .race-subtop-filters {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .content-subtop-mode-toggle {
    flex-shrink: 0;
  }

  .content-subtop-mode-toggle__item {
    font-size: 0.8rem;
    padding: 0.25em 0.5em;
  }

  .map-route-side:not(#mapAddRouteBar) {
    left: 8px;
    right: 8px;
    top: 52px;
    width: auto;
    max-width: none;
    align-items: stretch;
  }

  /* Каталог на карте: сверху, на всю ширину карты (с небольшими боковыми отступами) */
  #mapAddRouteBar.map-route-side.map-route-side--catalog {
    position: absolute;
    top: 10px;
    right: 10px;
    bottom: 10px;
    left: 10px;
    width: auto;
    max-width: none;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    pointer-events: none;
    align-items: stretch;
    z-index: 15000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  #catalogRouteListPanel.catalog-route-list-panel {
    pointer-events: auto;
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: 100%;
    max-width: none;
    max-height: min(calc(100% - 20px), 720px);
    z-index: auto;
    margin: 0;
    flex: 1 1 auto;
    min-height: 0;
  }

  #catalogRouteListPanel.catalog-route-list-panel:not(.map-mobile-panel--expanded) {
    display: none !important;
  }

  #catalogRouteListPanel.catalog-route-list-panel.map-mobile-panel--expanded {
    display: flex !important;
    max-height: min(58vh, 420px);
  }

  .map-route-side.map-route-side--catalog.map-route-side--detail-open #catalogRouteListPanel.map-mobile-panel--expanded {
    flex: 0 1 auto;
    max-height: min(38vh, 280px);
  }

  #catalogRouteSideDetail:not([hidden]) {
    pointer-events: auto;
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    width: 100%;
    max-width: none;
    margin: 0;
    z-index: auto;
    min-height: 0;
    box-sizing: border-box;
    transition: max-height 0.28s ease;
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.04),
      0 8px 28px rgba(0, 0, 0, 0.28);
    flex: 1 1 auto;
  }

  #catalogRouteSideDetail:not([hidden]):not(.map-mobile-panel--expanded) {
    display: none !important;
  }

  #catalogRouteSideDetail:not([hidden]).map-mobile-panel--expanded {
    display: flex !important;
    max-height: min(calc(100% - 20px), 640px);
  }

  #catalogRouteSideDetail:not([hidden]).catalog-route-side-panel--detail-expanded.map-mobile-panel--expanded {
    max-height: min(calc(100% - 20px), 640px);
  }

  #catalogRouteSideDetail:not([hidden]) .catalog-route-side-panel__head {
    flex-shrink: 0;
  }

  #catalogRouteSideDetail:not([hidden]) .catalog-route-side-panel__title-row {
    gap: 6px;
    align-items: flex-start;
  }

  #catalogRouteSideDetail:not([hidden]) .catalog-route-side-panel__title {
    font-size: 0.95rem;
    line-height: 1.25;
    max-height: 2.6em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .map-mobile-panel-rail#catalog_route_list_mobile_rail:not([hidden]) {
    display: inline-flex;
  }

  .route-form-with-tabs.route-form--catalog-readonly:not(.route-ui-constructor-hidden):not(.map-mobile-panel--expanded) {
    pointer-events: none !important;
    visibility: hidden !important;
  }

  .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--collapsed .route-constructor-bookmarks,
  .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--collapsed .route-constructor-panel {
    display: none !important;
  }

  /* Карточка маршрута: верх карты, на всю ширину */
  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded {
    position: absolute !important;
    top: 10px !important;
    right: 10px !important;
    bottom: 10px !important;
    left: 10px !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
    z-index: 15000 !important;
    pointer-events: auto !important;
    visibility: visible !important;
    margin: 0 !important;
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.04),
      0 8px 28px rgba(0, 0, 0, 0.28);
  }

  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded .route-constructor-bookmarks {
    flex-shrink: 0;
  }

  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded .route-constructor-panel.add-container {
    min-height: 0;
    flex: 1 1 auto;
  }

  .map-mobile-panel-rail:not([hidden]) {
    pointer-events: auto;
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 15002;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* Удобная зона нажатия на телефоне (≥44px) */
    min-width: 52px;
    width: 52px;
    min-height: 44px;
    height: 44px;
    padding: 0;
    margin: 0;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.92);
    color: #f8fafc;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .map-mobile-panel-rail:not([hidden]):hover {
    background: rgba(30, 41, 59, 0.96);
  }

  .map-mobile-panel-rail:not([hidden]):focus-visible {
    outline: 2px solid rgba(251, 202, 31, 0.75);
    outline-offset: 2px;
  }

  .map-mobile-panel-collapse:not([hidden]) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    width: 48px;
    min-height: 44px;
    height: 44px;
    padding: 0;
    margin: 0;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    color: #f8fafc;
    cursor: pointer;
    flex-shrink: 0;
    box-sizing: border-box;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .map-mobile-panel-collapse:not([hidden]):focus-visible {
    outline: 2px solid rgba(251, 202, 31, 0.75);
    outline-offset: 2px;
  }

  /* Список / карточка открыты — не перекрывать панелью инструментов карты */
  #map.map--mobile-catalog-panel-open .map-control,
  #map.map--mobile-catalog-panel-open .map-search {
    visibility: hidden !important;
    pointer-events: none !important;
    opacity: 0 !important;
  }

  /* Кнопки в шапке карточки маршрута: один размер; «свернуть» — крайняя справа */
  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded .track-constructor-title__shell {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    width: 100%;
    min-width: 0;
  }

  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded .track-constructor-title__text {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded .track-constructor-title__tools {
    display: inline-flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.35rem;
    flex: 0 0 auto;
  }

  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded .track-constructor-title__tools .route-catalog-drive-route-btn,
  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded .track-constructor-title__tools .route-catalog-readonly-edit-btn,
  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded .track-constructor-title__tools .route-catalog-readonly-close,
  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded .track-constructor-title__tools .map-mobile-panel-collapse {
    box-sizing: border-box;
    min-width: 48px;
    width: 48px;
    min-height: 44px;
    height: 44px;
    padding: 0;
    border-radius: 10px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded .track-constructor-title__tools .route-catalog-readonly-edit-btn svg {
    width: 22px;
    height: 22px;
  }

  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded .track-constructor-title__tools .route-catalog-drive-route-btn__img {
    width: 22px;
    height: 22px;
  }

  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded .track-constructor-title__tools .route-catalog-readonly-close {
    font-size: 1.45rem;
    line-height: 1;
  }

  #map > .route-form-with-tabs.route-form--catalog-readonly.map-mobile-panel--expanded .route-constructor-title-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
  }

  .catalog-route-list-panel__head-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
  }

  .map-route-side.map-route-side--races {
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    top: 52px;
    bottom: 8px;
  }

  .map-search {
    left: 8px;
    width: min(520px, calc(100vw - 16px));
  }

  body {
    background-attachment: scroll;
  }
}
