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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: #b0b0b0;
  background: #0a0a0a;
}

/* ── Layout ──
   Десктоп: обычный flex-ряд из двух блоков — .sidebar-outer (320px,
   внутри флекс-колонкой лежат #sidebar-top и #sidebar-bottom подряд,
   визуально один сплошной сайдбар) и .map-wrap (остальная ширина).
   На мобильном (см. медиа-запрос ниже) .sidebar-outer «растворяется»
   через display:contents, и все три блока — #sidebar-top, .map-wrap,
   #sidebar-bottom — становятся элементами грида в новом порядке строк:
   карта встаёт между шагом 4 и шагом 5. */
.layout {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

.sidebar-outer {
  width: 320px;
  flex-shrink: 0;
  background: #121212;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.4);
}

/* ── Sidebar ── */
.sidebar {
  background: #121212;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.4);
  z-index: 10;
}

.sidebar__logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid #1e1e1e;
}

.sidebar__logo a {
  display: flex;
  flex-shrink: 0;
}

.sidebar__title {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  line-height: 1.3;
  flex: 1;
}

.sidebar__cabinet-link {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #7a7a7a;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s;
}

.sidebar__cabinet-link:hover {
  color: #e85232;
}

/* ── Steps (нумерованный прогресс: 1-Откуда … 6-Сохранить) ──
   .steps сам несёт padding — а не вложенные .route-form/.result — иначе
   рельса не может выровняться сразу и по top/bottom, и по left своим
   единственным --gutter, а высота обёртки, растянутой через flex:1
   (см. .result), утягивает "bottom" рельсы вниз мимо последнего кружка. */
.steps {
  position: relative;
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.steps__rail {
  position: absolute;
  top: calc(var(--gutter, 20px) + 11px);
  bottom: calc(var(--gutter, 20px) + 11px);
  left: calc(var(--gutter, 20px) + 11px);
  width: 1.5px;
  background: #2a2a2a;
}

.step {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.step + .step {
  margin-top: 16px;
}

/* Шаг 4 — не настоящий DOM-сосед шага 3 (между ними закрывающийся
   <form>, см. .route-form), поэтому селектор выше его не ловит. */
#step-4 {
  margin-top: 16px;
}

/* Когда маршрут построен, доводим рельсы шагов 4 и 5 до края их
   боксов (#steps-top / #steps-bottom), а не до центра кружка — на
   десктопе эти боксы стоят впритык друг к другу (см. .sidebar-outer),
   так что линия 4→5 становится непрерывной без дополнительного моста.
   На мобильном к этому добавляется сегмент через карту, см. ниже. */
.layout.has-results #steps-top .steps__rail {
  bottom: 0;
}

.layout.has-results #steps-bottom .steps__rail {
  top: 0;
}

.step__num {
  position: relative;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #1e1e1e;
  border: 1.5px solid #2a2a2a;
  color: #7a7a7a;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.step--done .step__num {
  background: #e85232;
  border-color: #e85232;
  color: #0a0a0a;
}

.step__body {
  flex: 1;
  min-width: 0;
}

/* ── Form ──
   display:contents — форма не создаёт свой бокс (без этого её отступы
   удваивали бы padding, доставшийся от .steps), её .step-дети просто
   становятся прямыми потомками общей обёртки .steps вместе с шагом 4. */
.route-form {
  display: contents;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7a7a7a;
}

.autocomplete {
  position: relative;
}

.field-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  color: #b0b0b0;
  background: transparent;
  transition: border-color 0.2s;
  outline: none;
}

.field-input::placeholder {
  color: #555;
}

.field-input:focus {
  border-color: #e85232;
}

.field-input.is-selected {
  border-color: #e85232;
  background: #2a1410;
}

/* ── Dropdown ── */
.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #121212;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  z-index: 100;
  max-height: 220px;
  overflow-y: auto;
}

.dropdown:empty {
  display: none;
}

.dropdown-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
  border-bottom: 1px solid #1e1e1e;
  transition: background 0.15s, color 0.15s;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover,
.dropdown-item.is-focused {
  background: #2a1410;
  color: #e85232;
}

.dropdown-loading {
  padding: 10px 12px;
  font-size: 13px;
  color: #7a7a7a;
}

/* ── Build button ── */
.btn-build {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  background: #e85232;
  border: none;
  border-radius: 4px;
  color: #0a0a0a;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  margin-top: 4px;
}

.btn-build:hover {
  background: #f47355;
}

.btn-build:active {
  background: #b33d24;
}

.btn-build:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-build__loader {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(10,10,10,0.35);
  border-top-color: #0a0a0a;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Form error ── */
.form-error {
  margin-top: 12px;
  font-size: 12px;
  color: #e85232;
  text-align: center;
}

/* ── Result ──
   Только растяжение на десктопе (чтобы фон сайдбара доставал до низа
   колонки без разрыва) — padding и рельса шагов теперь у вложенного
   .steps, который не тянется и поэтому не утягивает линию вниз. */
.result {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.result-distance {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 16px;
  background: #151515;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
}

.result-distance__label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7a7a7a;
}

.result-distance__value {
  font-size: 30px;
  font-weight: 700;
  color: #e85232;
}

.result-stations__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.result-stations__label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7a7a7a;
}

.result-stations__chevron {
  color: #7a7a7a;
  font-size: 12px;
  transition: transform 0.2s;
}

.result-stations__toggle[aria-expanded="true"] .result-stations__chevron {
  transform: rotate(180deg);
}

.station-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  counter-reset: station;
  margin-top: 10px;
}

.station-list.is-collapsed {
  display: none;
}

.station-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 3px;
  font-size: 13px;
  counter-increment: station;
  transition: background 0.15s, color 0.15s;
}

.station-item:hover {
  background: #2a1410;
  color: #e85232;
}

.station-item::before {
  content: counter(station);
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1e1e1e;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  color: #b0b0b0;
  flex-shrink: 0;
}

.station-item:first-child::before,
.station-item:last-child::before {
  background: #e85232;
  color: #0a0a0a;
}

.station-item--no-coords {
  color: #555;
}

.station-item--no-coords::after {
  content: '(нет координат)';
  font-size: 11px;
  color: #444;
  margin-left: 4px;
}

.btn-save {
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px solid #e85232;
  border-radius: 4px;
  color: #e85232;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.btn-save:hover {
  background: #e85232;
  color: #0a0a0a;
}

.btn-save:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.save-route-msg {
  margin-top: 10px;
  font-size: 12px;
  color: #7a7a7a;
  text-align: center;
}

.save-route-msg a {
  color: #e85232;
  font-weight: 600;
}

/* ── Map ── */
.map-wrap {
  flex: 1;
  position: relative;
  background: #0a0a0a;
}

#map {
  position: absolute;
  inset: 0;
}

/* ── Markers ── */
.marker {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e85232;
  border: 1.5px solid #0a0a0a;
  box-shadow: 0 1px 4px rgba(0,0,0,0.6);
  cursor: pointer;
}

.marker--endpoint {
  width: 42px;
  height: 47px;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.6));
}

.marker--endpoint svg {
  display: block;
}

/* ── Popup ── */
.maplibregl-popup-content {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  padding: 10px 28px 10px 14px;
  border-radius: 4px;
  background: #121212;
  color: #e0e0e0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.popup-title {
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.popup-meta {
  font-size: 11.5px;
  color: #9a9a9a;
  font-variant-numeric: tabular-nums;
}

.maplibregl-popup-close-button {
  color: #7a7a7a;
  font-size: 16px;
  padding: 2px 6px;
}

.maplibregl-popup-close-button:hover {
  color: #e85232;
  background: none;
}

.maplibregl-popup-anchor-bottom .maplibregl-popup-tip {
  border-top-color: #121212;
}

.maplibregl-popup-anchor-top .maplibregl-popup-tip {
  border-bottom-color: #121212;
}

.maplibregl-popup-anchor-left .maplibregl-popup-tip {
  border-right-color: #121212;
}

.maplibregl-popup-anchor-right .maplibregl-popup-tip {
  border-left-color: #121212;
}

/* ── Личный кабинет ── */
.cabinet-body {
  height: auto;
  min-height: 100%;
}

.cabinet-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 20px 80px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.cabinet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.cabinet-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
}

.cabinet-back {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #7a7a7a;
  text-decoration: none;
  transition: color 0.15s;
}

.cabinet-back:hover {
  color: #e85232;
}

.cabinet-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.cabinet-hint {
  color: #7a7a7a;
  font-size: 13px;
  text-align: center;
  padding: 40px 0;
}

.cabinet-card {
  background: #121212;
  border: 1px solid #1e1e1e;
  border-radius: 6px;
  padding: 24px;
}

.cabinet-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.cabinet-card h2 {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}

.cabinet-title {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
}

.cabinet-lede {
  font-size: 13.5px;
  color: #7a7a7a;
  margin-bottom: 24px;
  line-height: 1.5;
}

.btn-link {
  background: none;
  border: none;
  color: #7a7a7a;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 0.15s;
}

.btn-link:hover {
  color: #e85232;
}

/* OAuth-кнопки входа */
.oauth-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-oauth {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.2s;
}

.btn-oauth:hover {
  opacity: 0.88;
}

.btn-oauth--yandex {
  background: #ffcc00;
  color: #1a1a1a;
}

.btn-oauth--vk {
  background: #0077ff;
  color: #fff;
}

/* Форма профиля */
.profile-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.profile-form .field-input:disabled {
  color: #7a7a7a;
  border-color: #1e1e1e;
  cursor: not-allowed;
}

.profile-hint {
  font-size: 12.5px;
  color: #e85232;
  background: #2a1410;
  border-radius: 4px;
  padding: 8px 12px;
}

.profile-form__footer {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 4px;
}

.profile-form__footer .btn-build {
  width: auto;
  flex: none;
  padding: 10px 20px;
  margin-top: 0;
}

.profile-saved {
  font-size: 12.5px;
  color: #3f7a5c;
}

/* Список сохранённых маршрутов */
.routes-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.route-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 4px;
  border-top: 1px solid #1e1e1e;
}

.route-item:first-child {
  border-top: none;
}

.route-item__link {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.15s;
}

.route-item__link:hover {
  background: #2a1410;
}

.route-item__name {
  font-size: 13.5px;
  font-weight: 600;
  color: #e0e0e0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-item__link:hover .route-item__name {
  color: #e85232;
}

.route-item__meta {
  font-size: 11.5px;
  color: #7a7a7a;
  font-variant-numeric: tabular-nums;
}

.route-item__action {
  background: none;
  border: none;
  color: #555;
  font-size: 13px;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.route-item__action:hover {
  background: #1e1e1e;
  color: #b0b0b0;
}

.route-item__action--delete:hover {
  color: #e85232;
}

.routes-empty {
  font-size: 13px;
  color: #7a7a7a;
  padding: 12px 4px;
}

/* ── Mobile ── */
@media (max-width: 768px) {
  /* Та же тройка блоков (#sidebar-top / .map-wrap / #sidebar-bottom),
     что и на десктопе, но в один столбец и в другом порядке строк:
     карта встаёт сразу после шага 4 (Расстояние) и «перекрывает» шаги
     5-6 — они уходят под неё, за пределы первого экрана, и открываются
     обычным скроллом страницы вниз. */
  .layout {
    display: grid;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "top"
      "map"
      "bottom";
  }

  /* Растворяем обёртку — #sidebar-top и #sidebar-bottom становятся
     элементами грида напрямую, наравне с картой. */
  .sidebar-outer {
    display: contents;
  }

  #sidebar-top    { grid-area: top; }
  #sidebar-bottom { grid-area: bottom; }
  .map-wrap       { grid-area: map; }

  .sidebar__logo {
    padding: 16px 16px 12px;
  }

  .steps {
    padding: 16px;
    --gutter: 16px;
  }

  /* 16px не даёт iOS Safari зумить страницу при фокусе на поле */
  .field-input {
    font-size: 16px;
  }

  .map-wrap {
    margin-top: 12px;
    min-height: 50vh;
    min-height: 50dvh;
  }

  /* Мост через карту: когда маршрут построен (.has-results), линия
     шагов идёт непрерывно с 1 по 6, а не обрывается на границах трёх
     разных блоков (#steps-top / .map-wrap / #steps-bottom). Сегмент
     карты доводится ровно до края её бокса — иначе более поздний по
     DOM-порядку сосед перекрасит перехлёст своим непрозрачным фоном.
     Продление рельсы шага 4/5 до края бокса — общее для всех разрешений
     правило, см. .has-results выше по файлу. */
  .layout.has-results .map-wrap::before {
    content: '';
    position: absolute;
    top: -12px;
    bottom: 0;
    left: calc(16px + 11px);
    width: 1.5px;
    background: #2a2a2a;
  }
}

/* ── Utility ── */
.hidden {
  display: none !important;
}
