/* VeloTrek — mobile-first стили */

:root {
  --color-primary: #2d6a4f;
  --color-primary-dark: #1b4332;
  --color-primary-light: #40916c;
  --color-accent: #f4a261;
  --color-route: #40916c;
  --color-poi: #e76f51;
  --color-gps: #f4a261;
  --color-bg: #f0f4f1;
  --color-surface: #ffffff;
  --color-text: #1a2e1f;
  --color-text-secondary: #5a7a63;
  --color-border: #d4e4d9;
  --color-success: #2d6a4f;
  --color-warning: #f4a261;
  --color-error: #e63946;
  --radius: 16px;
  --shadow: 0 1px 4px rgba(29, 53, 37, 0.08);
  --transition: 0.2s ease;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* === Шапка === */

.header {
  background: linear-gradient(
    135deg,
    var(--color-primary-dark) 0%,
    var(--color-primary) 100%
  );
  color: #fff;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 12px rgba(27, 67, 50, 0.3);
  flex-shrink: 0;
}

.header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 600px;
  margin: 0 auto;
}

.header__title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: #fff;
}

.header__back {
  color: #fff;
  text-decoration: none;
  font-size: 1.5rem;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background var(--transition);
}

.header__back:active {
  background: rgba(255, 255, 255, 0.2);
}

.header__action {
  color: #fff;
  text-decoration: none;
  font-size: 1.6rem;
  font-weight: 300;
  line-height: 1;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.header__action:active {
  background: rgba(255, 255, 255, 0.2);
}

/* === Каталог маршрутов === */

.catalog {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

/* === Заголовок раздела каталога === */

.section-header {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--color-primary);
  padding: 16px 0 6px;
  margin-top: 4px;
}

.section-header:first-child {
  margin-top: 0;
  padding-top: 8px;
}

/* === Сворачиваемые разделы === */

.catalog-section--collapsible .section-header--toggle {
  width: 100%;
  background: none;
  border: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--color-primary);
  padding: 16px 0 6px;
  margin-top: 4px;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.catalog-section:first-child .section-header--toggle {
  margin-top: 0;
  padding-top: 8px;
}

.section-header__meta {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.section-chevron {
  display: inline-block;
  font-style: normal;
  font-size: 1rem;
  transition: transform 0.25s ease;
  line-height: 1;
}

.catalog-section--collapsible.is-expanded .section-chevron {
  transform: rotate(90deg);
}

/* Свёрнутый раздел: 3 карточки + половина 4-й (высота задаётся JS через --peek-max-height) */
.catalog-section--collapsible:not(.is-expanded) .section-routes {
  max-height: var(--peek-max-height, 380px);
  overflow: hidden;
  position: relative;
}

.catalog-section--collapsible:not(.is-expanded) .section-routes::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: linear-gradient(to bottom, transparent, var(--color-bg));
  pointer-events: none;
}

.route-card {
  display: block;
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  padding: 16px 16px 16px 14px;
  margin-bottom: 10px;
  text-decoration: none;
  color: var(--color-text);
  user-select: none;
  -webkit-user-select: none;
  transition:
    transform var(--transition),
    border-left-color var(--transition);
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.route-card:active {
  transform: scale(0.98);
  border-left-color: var(--color-accent);
}

.route-card__title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
  line-height: 1.3;
  color: var(--color-text);
}

.route-card__desc {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.route-card__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stat {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  white-space: nowrap;
  background: var(--color-bg);
  padding: 2px 8px;
  border-radius: 100px;
}

.stat__icon {
  margin-right: 2px;
}

.route-card__error {
  font-size: 0.8rem;
  color: var(--color-error);
  margin-top: 4px;
}

.empty-state {
  text-align: center;
  color: var(--color-text-secondary);
  padding: 48px 16px;
  font-size: 0.95rem;
}

.empty-state code {
  background: #eee;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85rem;
}

/* === Загрузка / ошибка === */

.loading {
  text-align: center;
  padding: 48px 16px;
  color: var(--color-text-secondary);
}

.loading__spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 16px;
}

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

.error-msg {
  text-align: center;
  padding: 48px 16px;
  color: var(--color-error);
}

.error-msg__retry {
  display: inline-block;
  margin-top: 12px;
  padding: 10px 28px;
  background: linear-gradient(
    135deg,
    var(--color-primary) 0%,
    var(--color-primary-light) 100%
  );
  color: #fff;
  border: none;
  border-radius: 100px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

/* === Страница маршрута === */

body:has(.route-page) {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.route-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.route-info {
  padding: 14px 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.route-info__name {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin-bottom: 6px;
}

.route-info__desc {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.route-info__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

/* === Карта === */

#map {
  height: 45dvh;
  min-height: 200px;
  flex-shrink: 0;
}

/* === Панель действий === */

.action-bar {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn {
  flex: 1;
  padding: 11px 16px;
  border: none;
  border-radius: 100px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  text-align: center;
  transition:
    opacity var(--transition),
    transform var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.97);
  opacity: 0.9;
}

.btn--primary {
  background: linear-gradient(
    135deg,
    var(--color-primary) 0%,
    var(--color-primary-light) 100%
  );
  color: #fff;
  box-shadow: 0 2px 8px rgba(45, 106, 79, 0.35);
}

.btn--primary:active {
  box-shadow: 0 1px 4px rgba(45, 106, 79, 0.2);
}

.btn--secondary {
  background: var(--color-border);
  color: var(--color-text);
}

.btn--success {
  background: linear-gradient(135deg, #f4a261 0%, #e76f51 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(244, 162, 97, 0.35);
}

.btn--danger {
  background: var(--color-error);
  color: #fff;
}

.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* === Прогресс скачивания === */

.download-panel {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 12px 16px;
}

.download-panel__status {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar__fill {
  height: 100%;
  background: linear-gradient(
    90deg,
    var(--color-primary) 0%,
    var(--color-primary-light) 100%
  );
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}

.progress-bar__fill--done {
  background: var(--color-success);
}

/* === GPS-панель === */

.gps-panel {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.gps-panel__info {
  display: flex;
  gap: 16px;
  font-size: 0.85rem;
}

.gps-panel__item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.gps-panel__value {
  font-size: 1.1rem;
  font-weight: 600;
}

.gps-panel__label {
  font-size: 0.7rem;
  color: var(--color-text-secondary);
  text-transform: uppercase;
}

.gps-panel__value--off-route {
  color: var(--color-error);
}

.gps-panel__value--poor {
  color: var(--color-warning);
}

.btn--center {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex: none;
}

/* === Стрелка GPS на карте === */

.gps-heading {
  background: none !important;
  border: none !important;
}

.gps-heading-arrow {
  width: 12px;
  height: 16px;
  background: #f4a261;
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  filter: drop-shadow(0 0 2px #fff) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

/* === Footer === */

.footer {
  padding: 16px;
  text-align: center;
  max-width: 600px;
  margin: 0 auto;
}

.footer__add-route {
  display: inline-block;
  padding: 10px 24px;
  background: var(--color-surface);
  color: var(--color-primary);
  text-decoration: none;
  border-radius: 100px;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1.5px solid var(--color-border);
  transition: transform var(--transition);
}

.footer__add-route:active {
  transform: scale(0.97);
}

/* Leaflet popup fix */
.leaflet-popup-content {
  font-size: 0.85rem;
  line-height: 1.4;
}

/* === Ссылки в описании === */

.desc-link {
  color: var(--color-primary);
  text-decoration: underline;
  text-decoration-skip-ink: auto;
}

.desc-link:active {
  color: var(--color-primary-dark);
}

/* === Кнопка полного экрана на карте === */

.leaflet-fullscreen-control {
  background: none !important;
  box-shadow: none !important;
  border: none !important;
}

.leaflet-fullscreen-btn {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 36px !important;
  height: 36px !important;
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* === Полноэкранный режим карты === */

body.fullscreen-map .header {
  display: none !important;
}

body.fullscreen-map .route-page {
  flex: none;
  height: 100vh;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

body.fullscreen-map #map {
  height: 100%;
  min-height: 0;
}

body.fullscreen-map .route-info,
body.fullscreen-map .action-bar,
body.fullscreen-map .route-description {
  display: none !important;
}

/* Сдвигаем контролы карты вниз на safe area в полноэкранном режиме */
body.fullscreen-map .leaflet-top {
  top: env(safe-area-inset-top, 0) !important;
}

body.fullscreen-map .leaflet-left {
  left: env(safe-area-inset-left, 0) !important;
}

body.fullscreen-map .leaflet-right {
  right: env(safe-area-inset-right, 0) !important;
}

body.fullscreen-map .gps-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1001;
  border-top: none;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.15);
}

body.fullscreen-map .download-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1002;
  border-top: none;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.15);
}

/* Скрываем флаг в attribution Leaflet */
.leaflet-attribution-flag {
  display: none !important;
}

/* === Описание маршрута (ниже карты и кнопок) === */

.route-description {
  padding: 12px 16px;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--color-text);
}
.route-description p {
  margin: 0 0 8px;
}
.route-description a {
  color: var(--color-primary);
  text-decoration: underline;
}

/* === Тост обновления === */

.update-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-primary-dark);
  color: #fff;
  padding: 10px 16px;
  border-radius: 100px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  font-weight: 500;
  z-index: 9999;
  box-shadow: 0 4px 20px rgba(27, 67, 50, 0.4);
  animation: toast-in 0.3s ease;
  max-width: calc(100vw - 32px);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.update-toast__btn {
  background: var(--color-accent);
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 100px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.update-toast__close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

/* === Общий toast (GPS ошибки, удаление и т.д.) === */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 46, 31, 0.92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 100px;
  font-size: 0.88rem;
  font-weight: 500;
  z-index: 9999;
  max-width: calc(100vw - 32px);
  text-align: center;
  pointer-events: none;
  animation: toast-in 0.25s ease;
}

/* === Офлайн-статус строка === */

.offline-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* === Офлайн-индикатор (badge) === */

.offline-indicator {
  display: inline-flex;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 100px;
  border: 1px solid transparent;
}

.offline-indicator--ready {
  color: var(--color-success);
  background: rgba(45, 106, 79, 0.1);
  border-color: rgba(45, 106, 79, 0.2);
}

.offline-indicator--partial {
  color: #92400e;
  background: rgba(244, 162, 97, 0.15);
  border-color: rgba(244, 162, 97, 0.3);
}

.offline-indicator--online {
  color: var(--color-text-secondary);
  background: var(--color-bg);
  border-color: var(--color-border);
}

/* === Кнопка удаления офлайн-данных === */

.btn-clear-offline {
  background: none;
  border: none;
  color: var(--color-error);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  text-decoration: underline;
  text-underline-offset: 2px;
  -webkit-tap-highlight-color: transparent;
}

.btn-clear-offline:active {
  opacity: 0.7;
}

.btn-clear-offline:disabled {
  opacity: 0.4;
  cursor: default;
}

/* === Скрытие элементов === */

.hidden {
  display: none !important;
}

/* === Safe area для PWA на iPhone === */

@supports (padding-top: env(safe-area-inset-top)) {
  .header {
    padding-top: calc(12px + env(safe-area-inset-top));
  }

  .action-bar,
  .download-panel,
  .gps-panel {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  body.fullscreen-map .gps-panel,
  body.fullscreen-map .download-panel {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .update-toast,
  .toast {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }
}
