/*
 * Freedom UTM — публичная карта неба (СПЕК B). Направление 2 «Горизонт операций».
 * Тон функциональный, НЕ кинематографический (в отличие от лендинга) — рабочий
 * инструмент: solid-поверхности, hairline, без backdrop-filter/glassmorphism,
 * без gradient-текста, без border-left-акцентов.
 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h2 {
  font-family: var(--font-display);
  margin: 0;
  color: var(--text);
}

p,
ul {
  margin: 0;
}

ul {
  list-style: none;
  padding: 0;
}

a {
  color: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -48px;
  left: 1rem;
  background: var(--surface);
  color: var(--text);
  padding: 0.75rem 1rem;
  border: 1px solid var(--hairline);
  z-index: 200;
  transition: top 150ms ease;
}

.skip-link:focus {
  top: 1rem;
}

:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------- */
/* Кнопки — тот же язык, что на лендинге (solid amber / outline muted)     */
/* ---------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
  padding: 0.55rem 1.1rem;
  border-radius: 4px;
  border: 1px solid var(--muted);
  color: var(--text);
  background: transparent;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
  white-space: nowrap;
}

.btn--outline:hover {
  border-color: var(--amber);
  color: var(--amber);
}

.btn--small {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
}

/* ---------------------------------------------------------------------- */
/* Шапка — fixed, --surface solid, hairline снизу, БЕЗ blur                */
/* ---------------------------------------------------------------------- */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}

.site-header__inner {
  height: 100%;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 650;
  font-size: 1rem;
  letter-spacing: 0.06em;
  color: var(--text);
  text-decoration: none;
}

.site-header__controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* ---------------------------------------------------------------------- */
/* Сегмент-контрол 2D/3D (.seg / data-mapmode) — реализовано заново        */
/* ---------------------------------------------------------------------- */

.seg {
  display: inline-flex;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  overflow: hidden;
}

.seg__btn {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  padding: 0.45rem 0.9rem;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.seg__btn + .seg__btn {
  border-left: 1px solid var(--hairline);
}

.seg__btn.is-active {
  background: var(--amber);
  color: var(--canvas);
}

.seg__btn:hover:not(.is-active) {
  color: var(--text);
}

/* ---------------------------------------------------------------------- */
/* Раскладка: sidebar слева solid, карта справа во весь остаток экрана     */
/* ---------------------------------------------------------------------- */

.map-shell {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
}

.layer-panel {
  flex: 0 0 300px;
  max-width: 300px;
  background: var(--surface);
  border-right: 1px solid var(--hairline);
  padding: 1.5rem 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.layer-panel__title {
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.layer-panel__list {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.layer-toggle label {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.4rem;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  border-radius: 3px;
  transition: background-color 120ms ease;
}

.layer-toggle label:hover {
  background: color-mix(in oklch, var(--hairline) 60%, transparent);
}

.layer-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--amber);
  flex: none;
}

.layer-panel__legend {
  border-top: 1px solid var(--hairline);
  padding-top: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.layer-panel__legend-title {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.legend-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex: none;
  border: 1px solid var(--hairline);
}

.legend-swatch--hard {
  background: var(--sig-conflict);
  border-color: var(--sig-conflict);
}

.legend-swatch--soft {
  background: var(--amber);
  border-color: var(--amber);
}

.legend-swatch--permitted {
  background: var(--sig-ok);
  border-color: var(--sig-ok);
}

/* M4c: цвет по категории (NOTAM/RESERVED) переопределяет цвет по уровню -
   те же hex, что PALETTE.notam/reserved в map.js. */
.legend-swatch--notam {
  background: #3b82f6;
  border-color: #3b82f6;
}

.legend-swatch--reserved {
  background: #a855f7;
  border-color: #a855f7;
}

.legend-list--scale li {
  font-variant-numeric: tabular-nums;
}

.legend-swatch--density-0 {
  background: var(--surface);
}

.legend-swatch--density-1 {
  background: color-mix(in oklch, var(--amber) 35%, var(--surface));
  border-color: var(--amber);
}

.legend-swatch--density-2 {
  background: color-mix(in oklch, var(--amber) 65%, var(--surface));
  border-color: var(--amber);
}

.legend-swatch--density-3 {
  background: var(--amber);
  border-color: var(--amber);
}

.layer-panel__status {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--hairline);
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------------- */
/* Карта — оба движка занимают весь остаток экрана; активен только один   */
/* ---------------------------------------------------------------------- */

.map-viewport {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.map-engine {
  position: absolute;
  inset: 0;
  display: none;
}

.map-engine.is-active {
  display: block;
}

/* Приглушаем стоковую палитру базовых тайлов (OSM) под drenched-графит —
   функциональная десатурация, не декоративный фильтр поверх UI. */
#map-2d .maplibregl-canvas {
  filter: grayscale(0.15) brightness(0.98) contrast(1.02) saturate(0.95);
}

#map-2d .maplibregl-ctrl-attrib {
  background: color-mix(in oklch, var(--surface) 85%, transparent);
  color: var(--muted);
}

#map-2d .maplibregl-ctrl-attrib a {
  color: var(--muted);
}

#map-3d .cesium-viewer-bottom {
  display: none;
}

/* ---------------------------------------------------------------------- */
/* Лоадер 3D-режима (LIVE_CHECK 15.07.2026, UX-мелочь) - первые ~15-30с    */
/* глобус грузит рельеф/здания без единого визуального сигнала; спиннер   */
/* до первого готового кадра (viewer.scene.globe.tileLoadProgressEvent).  */
/* ---------------------------------------------------------------------- */

.map-loader {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-direction: column;
  background: var(--canvas);
  color: var(--muted);
  font-size: 0.85rem;
  pointer-events: none;
}

.map-loader.is-active {
  display: flex;
}

/* ---------------------------------------------------------------------- */
/* M4b — ховер-тултип зон (2D + 3D, общий DOM-элемент)                      */
/* ---------------------------------------------------------------------- */

.zone-tooltip {
  position: fixed;
  z-index: 300;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 0.75rem 0.9rem;
  font-size: 0.8rem;
  color: var(--text);
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.zone-tooltip[hidden] {
  display: none;
}

.zone-tooltip__title {
  font-family: var(--font-display);
  font-weight: 650;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  word-break: break-word;
}

.zone-info__row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.15rem 0;
  color: var(--muted);
}

.zone-info__row span:last-child {
  color: var(--text);
  text-align: right;
}

.zone-tooltip__msg {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--hairline);
  color: var(--muted);
  white-space: pre-wrap;
  max-height: 160px;
  overflow-y: auto;
}

/* M4b (доработка) — закреплённый попап зоны (клик, не ховер): pointer-
   events:auto (в отличие от .zone-tooltip), прокручиваемый, с кнопкой
   закрытия, не исчезает при уводе курсора. */
.zone-popup {
  position: fixed;
  z-index: 310;
  width: 320px;
  max-height: min(70vh, 420px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 0.9rem 2.25rem 0.9rem 0.9rem;
  font-size: 0.8rem;
  color: var(--text);
  pointer-events: auto;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

.zone-popup[hidden] {
  display: none;
}

.zone-popup__close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.zone-popup__close:hover {
  background: var(--hairline);
  color: var(--text);
}

.zone-popup__title {
  font-family: var(--font-display);
  font-weight: 650;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  padding-right: 0.5rem;
  word-break: break-word;
}

.zone-popup__msg {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--hairline);
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.map-loader__spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--hairline);
  border-top-color: var(--amber);
  animation: map-loader-spin 900ms linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .map-loader__spinner {
    animation: none;
  }
}

@keyframes map-loader-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------------------------------------------------------------------- */
/* Узкие экраны — панель сверху, карта под ней                            */
/* ---------------------------------------------------------------------- */

@media (max-width: 760px) {
  .map-shell {
    flex-direction: column;
  }

  .layer-panel {
    flex: 0 0 auto;
    max-width: none;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--hairline);
  }
}

/* ---------------------------------------------------------------------- */
/* HUD курсора (координаты, время, DEM)                                   */
/* ---------------------------------------------------------------------- */

.cursor-hud {
  position: absolute;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 250;
  background: color-mix(in oklch, var(--surface) 85%, transparent);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 0.4rem 0.8rem;
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--muted);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  pointer-events: none;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}

.cursor-hud span {
  display: inline-block;
  min-width: 60px;
  text-align: center;
}

#hud-coords {
  min-width: 150px;
}

#hud-time {
  color: var(--text);
  font-weight: 600;
}

/* ---------------------------------------------------------------------- */
/* prefers-reduced-motion — карта уже статична по умолчанию (§B.1), тут    */
/* глушим только переходы UI-хрома (seg/toggle hover), без исключений      */
/* ---------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
