/* ============================================================================
 * Shelter — full-screen карта с визуальными фильтрами поверх Apple MapKit JS.
 * Порт визуальных эффектов из iOS-приложения (DesaturationCoordinator,
 * GlassEffectPolyfill, MainFeature.swift cluster/tectonic + bottomBar).
 * Лендинга больше нет — карта занимает весь viewport.
 * ============================================================================ */

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #0a0a0a;
  color: white;
  font-family: 'Inter Tight', sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Map section + плейсхолдер до lazy-init ---------- */

.map-section {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  /* iOS safe area — нижняя челка/home-indicator на iPhone. */
  height: 100dvh;
  background: #000;
  overflow: hidden;
}

.shelter-map {
  width: 100%;
  height: 100%;
  background: #0a0a0a;
}

/* Плейсхолдер показывается до того, как IntersectionObserver инжектит
 * mapkit.js. Та же тёмная палитра + центральный логотип, чтобы переход
 * к загруженной карте был визуально плавным. */
.map-placeholder {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(
      ellipse at center,
      rgba(50, 50, 50, 0.15) 0%,
      transparent 70%
    ),
    #0a0a0a;
  display: grid;
  place-items: center;
  pointer-events: none;
  transition: opacity 0.4s ease-out;
  z-index: 5;
}

.map-placeholder.hidden {
  opacity: 0;
  pointer-events: none;
}

.map-placeholder__label {
  font-family: 'Inter Tight', sans-serif;
  color: rgba(255, 255, 255, 0.4);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* ---------- Главный «фильтр»: desaturation тайлов ----------
 * MapKit JS 5 рендерит тайлы в <canvas>, а аннотации — в DOM-сиблинге
 * .mk-annotation-container, поэтому filter на canvas грейскейлит ровно
 * тайлы (и встроенные иконки/полилинии), не трогая наши кастомные пины.
 *
 * iOS-аналог: DesaturationCoordinator.swift вставляет CALayer с
 * saturationBlendMode под MKAnnotationContainerView. */
.shelter-map canvas {
  filter: grayscale(100%);
  -webkit-filter: grayscale(100%);
}

/* ---------- Аннотации землетрясений (DOM-based, iOS-style) ----------
 *
 * Кастомные DOM-аннотации (через `mapkit.Annotation` с factory'ом, см.
 * js/map.js → makeAnnotation). Они рендерятся в DOM-узле
 * `.mk-annotation-container`, который снаружи `<canvas>` — поэтому
 * canvas grayscale-filter их НЕ задевает (метки остаются цветными).
 *
 * iOS-аналог: MainFeature.swift:614-683 — Circle().fill(color) с
 * Image(systemName: "waveform.path.ecg") внутри для одиночного пина и
 * с числом для кластеров. Внешние «rings» (.opacity(0.2)) убраны — они
 * стоили слишком дорого в Safari при движении камеры. */

.eq-pin {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color, #34c759);
  display: grid;
  place-items: center;
  color: white;
  font-family: 'Inter Tight', sans-serif;
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  /* Изоляция перерисовки + GPU compositing — пины не триггерят
   * layout/paint всей карты при панорамировании. */
  contain: layout style paint;
  transform: translateZ(0);
}

.eq-pin.cluster {
  /* Чуть крупнее одиночного, как в iOS кластера с числом. */
  width: 36px;
  height: 36px;
  font-size: 14px;
}

.eq-pin__icon {
  width: 16px;
  height: 11px;
  fill: none;
  stroke: white;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Glass-effect (iOS GlassEffectPolyfill) ---------- */

.glass {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(44px) saturate(180%);
  -webkit-backdrop-filter: blur(44px) saturate(180%);
}

/* ---------- Right side panel (zoom +/−, locate) ----------
 * iOS-аналог: rightSidePanel — VStack справа сверху, zoom-pair в одной
 * капсуле, locate отдельной кнопкой ниже. */
.map-controls {
  position: absolute;
  top: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 10;
}

.glass-button {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(44px) saturate(180%);
  -webkit-backdrop-filter: blur(44px) saturate(180%);
  color: rgba(255, 255, 255, 0.9);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  padding: 0;
}

.glass-button:hover {
  background: rgba(255, 255, 255, 0.15);
}

.glass-button:active {
  transform: scale(0.96);
  background: rgba(255, 255, 255, 0.2);
}

.glass-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.zoom-pair {
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(44px) saturate(180%);
  -webkit-backdrop-filter: blur(44px) saturate(180%);
}

.zoom-pair .glass-button {
  border: none;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-radius: 0;
}

.zoom-pair .glass-button + .glass-button {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* ---------- Top bar: location pill (reverse-geocoded) ----------
 * iOS-аналог: верхний `locationTitle` лейбл с reverse-geocoded названием
 * региона при пане карты. */
.map-location-label {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: white;
  font-size: 14px;
  font-weight: 500;
  font-family: 'Inter Tight', sans-serif;
  z-index: 10;
  max-width: min(60vw, 480px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.map-location-label.visible {
  opacity: 1;
}

/* ---------- Bottom bar — 3 chip-кнопки ----------
 * Прямой порт iOS bottomBar из MainFeature.swift:855-900:
 *   ScrollView(.horizontal) { HStack(spacing: 12) { 3 × BottomBarButton } }
 * Каждая chip — иконка ИЛИ большая цифра + 2-строчный label.
 * .glassEffect(.regular(tint: .secondary, ...), in: .rect(cornerRadius: 16)). */
.bottom-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 24px;
  z-index: 10;
  padding: 0 24px;
  pointer-events: none;
}

.bottom-bar__scroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-behavior: smooth;
  pointer-events: auto;
  padding: 4px 0;
  /* Прозрачные «отступы» по краям, чтобы тени glass-кнопок не обрезались. */
  margin: 0 -24px;
  padding-left: 24px;
  padding-right: 24px;
}

.bottom-bar__scroll::-webkit-scrollbar {
  display: none;
}

.bottom-bar-button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 20px 15px 16px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(44px) saturate(180%);
  -webkit-backdrop-filter: blur(44px) saturate(180%);
  color: white;
  font-family: 'Inter Tight', sans-serif;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.1s ease;
}

.bottom-bar-button:hover {
  background: rgba(255, 255, 255, 0.15);
}

.bottom-bar-button:active {
  transform: scale(0.97);
}

.bottom-bar-button__icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  color: white;
}

.bottom-bar-button__icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* iOS .largeTitle: size 34, medium weight, rounded design (SF Pro Rounded). */
.bottom-bar-button__large {
  font-size: 34px;
  font-weight: 500;
  font-family:
    'SF Pro Rounded',
    -apple-system,
    'Inter Tight',
    sans-serif;
  line-height: 1;
  /* Чуть приподнимаем большую цифру, чтобы оптически центрировать с двухстрочным title. */
  margin-top: -4px;
}

.bottom-bar-button__title {
  font-size: 17px;
  font-weight: 500;
  line-height: 19px;
  text-align: left;
  white-space: pre-line; /* поддерживаем \n как разделитель строк */
}

/* ---------- Progress indicator ----------
 * iOS-аналог: ProgressIndicator из DesignSystem, показывается во время
 * background load (`isBackgroundLoading` + `loadingProgress` в State).
 *
 * Линейный тонкий бар наверху, indeterminate-mode когда progress=0,
 * determinate-mode когда поступают данные. */
.map-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  z-index: 11;
  transition: opacity 0.3s ease;
}

.map-progress.hidden {
  opacity: 0;
}

.map-progress__bar {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: linear-gradient(90deg, #34c759 0%, #ffcc00 50%, #ff3b30 100%);
  transition: width 0.3s ease;
  width: 0%;
}

.map-progress.indeterminate .map-progress__bar {
  width: 40%;
  animation: progress-slide 1.6s infinite cubic-bezier(0.4, 0, 0.6, 1);
}

@keyframes progress-slide {
  0% {
    left: -40%;
  }
  100% {
    left: 100%;
  }
}

/* ============================================================================
 * Lockdown Mode fallback (см. js/lockdown-fallback.js).
 * Показывается когда WebAssembly недоступен — MapKit JS грузить нельзя,
 * вместо карты — список последних землетрясений в той же тёмной палитре.
 * ============================================================================ */

.lockdown-fallback {
  position: absolute;
  inset: 0;
  background: #0a0a0a;
  color: white;
  z-index: 4;
  display: flex;
  flex-direction: column;
  font-family: 'Inter Tight', sans-serif;
  overflow: hidden;
}

.lockdown-fallback__hero {
  padding: 80px 32px 24px;
  flex-shrink: 0;
}

.lockdown-fallback__badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 204, 0, 0.15);
  color: #ffcc00;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 16px;
}

.lockdown-fallback__title {
  font-size: 36px;
  font-weight: 500;
  line-height: 1.1;
  margin: 0 0 12px;
}

.lockdown-fallback__sub {
  font-size: 15px;
  font-weight: 400;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.55);
  max-width: 560px;
  margin: 0;
}

.lockdown-fallback__list-wrap {
  flex: 1 1 auto;
  overflow-y: auto;
  /* Bottom-bar занимает ~90px снизу → даём отступ, чтобы не перекрывал. */
  padding: 8px 24px 120px;
  -webkit-overflow-scrolling: touch;
}

.lockdown-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
}

.lockdown-list__item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: background 0.15s ease;
}

.lockdown-list__item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.lockdown-list__mag {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 600;
  color: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  font-variant-numeric: tabular-nums;
}

.lockdown-list__info {
  flex: 1 1 auto;
  min-width: 0;
}

.lockdown-list__place {
  font-size: 15px;
  font-weight: 500;
  color: white;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lockdown-list__meta {
  margin-top: 2px;
  font-size: 13px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.5);
}

/* ---------- Responsive ---------- */

@media (max-width: 500px) {
  .lockdown-fallback__hero {
    padding: 56px 20px 16px;
  }
  .lockdown-fallback__title {
    font-size: 28px;
  }
  .lockdown-fallback__sub {
    font-size: 14px;
  }
  .lockdown-fallback__list-wrap {
    padding: 8px 16px 110px;
  }
  .lockdown-list__mag {
    width: 42px;
    height: 42px;
    font-size: 15px;
  }

  .map-controls {
    top: 16px;
    right: 16px;
    gap: 8px;
  }

  .glass-button {
    width: 40px;
    height: 40px;
    border-radius: 14px;
  }

  .map-location-label {
    top: 16px;
    font-size: 13px;
    padding: 8px 14px;
    max-width: 60vw;
  }

  .bottom-bar {
    bottom: 16px;
    padding: 0 16px;
  }

  .bottom-bar__scroll {
    margin: 0 -16px;
    padding-left: 16px;
    padding-right: 16px;
  }

  .bottom-bar-button {
    padding: 13px 16px 13px 14px;
  }

  .bottom-bar-button__large {
    font-size: 30px;
  }

  .bottom-bar-button__title {
    font-size: 15px;
    line-height: 17px;
  }
}
