
:root {
  --header-h: 48px;
  --side-w: 340px;
  /* светлая тема */
  --brand: #1f5fbf;
  --on-brand: #fff;
  --header-bg: #1f5fbf;
  --header-fg: #fff;
  --bg: #fff;
  --panel: #fff;
  --text: #1f2328;
  --muted: #5f6670;
  --muted-2: #8a9199;
  --border: #e3e6ea;
  --line: rgba(0, 0, 0, 0.06);
  --hover: #f3f5f7;
  --subtle: #f6f8fa;
  --active: #e8f0fb;
  --active-strong: #dde3ea;
  --accent: #1677ff;
  --error-bg: #fff1f0;
  --error-border: #ffa39e;
  --warn-bg: #fff1e6;
  --warn-fg: #c0580b;
  --shadow: rgba(0, 0, 0, 0.3);
  color-scheme: light;
}

/* тёмная тема Ayu Mirage (палитра ayu-colors, mirage) */
:root[data-theme='ayu_mirage'] {
  --brand: #ffcc66;
  --on-brand: #1f2430;
  --header-bg: #1c212b;
  --header-fg: #cccac2;
  --bg: #1f2430;
  --panel: #242936;
  --text: #cccac2;
  --muted: #a6a59f;
  --muted-2: #707a8c;
  --border: #363c4a;
  --line: rgba(255, 255, 255, 0.06);
  --hover: #2b3140;
  --subtle: #1f2430;
  --active: #33415e;
  --active-strong: #3b4a6b;
  --accent: #73d0ff;
  --error-bg: #3a2329;
  --error-border: #f27983;
  --warn-bg: #3d3122;
  --warn-fg: #ffad66;
  --shadow: rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

html,
body,
#root,
.x-root {
  height: 100%;
  margin: 0;
  font-family: -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  background: var(--header-bg);
  color: var(--header-fg);
  .brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
    white-space: nowrap;
  }
  .brand-title {
    font-size: 18px;
    font-weight: 600;
  }
  .brand-sub {
    font-size: 11px;
    opacity: 0.85;
  }
  .grow {
    flex: 1;
  }
}

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.side {
  width: var(--side-w);
  flex: none;
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.map-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}

.map-root {
  position: absolute;
  inset: 0;
}

.map-tools {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 2;
}

.map-btn.on {
  background: var(--brand);
  color: var(--on-brand);
}
.map-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 1px 4px var(--shadow);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  &:hover {
    background: var(--hover);
  }
}

/* --- панель слоев --- */
.tile-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.tile-panel-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px 8px 14px;
  border-bottom: 1px solid var(--border);
  .title {
    font-weight: 600;
    flex: 1;
  }
}
.tile-panel-search {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.tile-panel-body {
  flex: 1;
  overflow: auto;
  padding: 6px 0 20px;
}
.tile-error {
  margin: 8px 12px;
  padding: 8px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 4px;
  font-size: 12px;
}
.tile-empty {
  margin: 12px;
  color: var(--muted);
  font-size: 13px;
}

.tile-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 0;
  min-height: 30px;
  &.group {
    font-weight: 600;
  }
  &:hover {
    background: var(--subtle);
  }
}
.tile-expander {
  border: 0;
  background: none;
  padding: 0 2px;
  cursor: pointer;
  color: var(--muted);
  display: inline-flex;
}
.tile-icon {
  color: #e0a800;
  flex: none;
}
.tile-label {
  flex: 1;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-count {
  font-size: 11px;
  color: var(--muted-2);
  font-weight: 400;
}
.tile-badge {
  font-size: 10px;
  color: var(--muted);
  background: var(--subtle);
  border-radius: 3px;
  padding: 0 4px;
}
.tile-ibtn {
  border: 0;
  background: none;
  color: var(--muted-2);
  cursor: pointer;
  padding: 2px;
  display: inline-flex;
  border-radius: 3px;
  &:hover,
  &.on {
    color: var(--brand);
    background: var(--active);
  }
}
.tile-layer.off .tile-label {
  color: var(--muted-2);
}
.tile-opacity {
  padding-right: 16px;
  padding-bottom: 6px;
}
.tile-setting {
  margin-bottom: 4px;
}
.tile-setting-label {
  font-size: 12px;
  color: var(--muted);
}
.tile-setting-hint {
  font-size: 11px;
  color: var(--muted-2);
}
.tile-layer.out-of-range .tile-label {
  color: var(--muted-2);
  font-style: italic;
}
.tile-badge.warn {
  background: var(--warn-bg);
  color: var(--warn-fg);
  cursor: pointer;
}
.tile-legend {
  padding: 2px 8px 6px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 260px;
  overflow: auto;
  .legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
    &.off {
      opacity: 0.45;
    }
    &.legend-all {
      border-bottom: 1px dashed var(--border);
      padding-bottom: 2px;
      margin-bottom: 2px;
    }
  }
}
.swatch {
  --c: #999;
  background: var(--c);
  display: inline-block;
  width: 16px;
  height: 12px;
  border: 1px solid rgba(0, 0, 0, 0.3);
  border-radius: 2px;
  flex: none;
  &.line {
    height: 0;
    border: 0;
    border-top: 3px solid var(--c);
    background: none;
  }
  &.circle {
    width: 12px;
    height: 12px;
    border-radius: 50%;
  }
  &.raster {
    background: repeating-linear-gradient(45deg, #b8c4a8 0 3px, #7f9c6b 3px 6px);
  }
}

/* --- подложки --- */
.basemap-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 220px;
}
.basemap-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  padding: 6px 8px;
  cursor: pointer;
  text-align: left;
  &.on {
    border-color: var(--brand);
    background: var(--active);
  }
  img,
  .basemap-ph {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    background: var(--active-strong);
    object-fit: cover;
    flex: none;
  }
}

/* --- попап --- */
.maplibregl-popup-content {
  padding: 10px 12px;
  font-size: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.feature-popup {
  max-height: 320px;
  overflow: auto;
  .fp-title {
    font-weight: 600;
    font-size: 13px;
    margin-right: 16px;
  }
  .fp-layer {
    color: var(--muted-2);
    font-size: 11px;
    margin-bottom: 6px;
  }
  table {
    border-collapse: collapse;
    width: 100%;
  }
  td {
    padding: 2px 6px 2px 0;
    vertical-align: top;
    border-top: 1px solid var(--line);
  }
  td.k {
    color: var(--muted);
    white-space: nowrap;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* --- 3D-режим --- */
.tile-3d {
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  margin: 4px 16px 8px 0;
  .tile-setting-label {
    display: flex;
    align-items: center;
    gap: 8px;
  }
}
.tile-3d-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  font-size: 12px;
  color: var(--muted);
  > span:first-child {
    width: 72px;
    flex: none;
  }
}
.tile-gradient {
  height: 10px;
  border-radius: 3px;
  border: 1px solid var(--border);
  margin-top: 4px;
}
.tile-gradient-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  .muted {
    color: var(--muted-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 6px;
  }
}

/* --- 3D-город и полеты --- */
.city3d-panel,
.flight-panel {
  width: 260px;
  font-size: 13px;
}
.city3d-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  &.col {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }
}
.city3d-hint {
  font-size: 11px;
  color: var(--muted-2);
  margin-top: 8px;
}
.flight-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.flight-label {
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0 2px;
}

/* --- аналитика --- */
.analytics-page {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.analytics-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px 16px;
}
.analytics-tab {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 230px;
  white-space: normal;
  line-height: 1.2;
  .muted {
    color: var(--muted-2);
    font-size: 11px;
    flex: none;
  }
}
.analytics-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
  .grow {
    flex: 1;
  }
}
.analytics-title {
  font-size: 18px;
  font-weight: 600;
}
.analytics-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  .stat {
    min-width: 140px;
    padding: 8px 12px;
    background: var(--subtle);
    border-radius: 6px;
  }
  .stat-v {
    font-size: 18px;
    font-weight: 600;
  }
  .stat-l {
    font-size: 11px;
    color: var(--muted);
  }
}

/* версия и журнал изменений */
.version-badge {
  margin-left: 8px;
  padding: 1px 8px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  font: inherit;
  font-size: 11px;
  line-height: 18px;
  cursor: pointer;
  white-space: nowrap;
  &:hover {
    background: rgba(255, 255, 255, 0.25);
  }
}
.changelog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 12px;
  .muted {
    color: var(--muted);
  }
}
.changelog {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 62vh;
  overflow-y: auto;
  li {
    padding: 8px 4px 8px 12px;
    border-bottom: 1px solid var(--line);
    border-left: 3px solid transparent;
    &.is-change {
      border-left-color: var(--accent);
    }
  }
  .cl-line {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
  }
  .cl-version {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    min-width: 52px;
  }
  .cl-date {
    color: var(--muted-2);
  }
  .cl-commit {
    margin-left: auto;
    color: var(--muted-2);
    font-size: 11px;
  }
  .cl-title {
    margin-top: 2px;
    font-size: 13px;
    line-height: 1.4;
  }
}

.tile-icon-group {
  color: var(--accent);
}

/* машина времени */
.time-banner {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 6px 2px 10px;
  margin-right: 8px;
  border-radius: 14px;
  background: #faad14;
  color: #3d2a00;
  font-size: 13px;
  font-weight: 600;
  button {
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    padding: 0;
  }
  .time-banner-close {
    display: inline-flex;
    padding: 2px;
    border-radius: 50%;
    &:hover {
      background: rgba(0, 0, 0, 0.1);
    }
  }
}
.tm-section {
  margin-bottom: 18px;
}
.tm-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.tm-label {
  font-weight: 600;
  margin-right: auto;
}
.tm-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
  margin-top: 18px;
}
.tm-feed {
  max-height: calc(100vh - 360px);
  overflow-y: auto;
}
.tm-day-head {
  position: sticky;
  top: 0;
  background: var(--panel);
  padding: 6px 0 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.tm-event {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.tm-event-title {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tm-event-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  margin-top: 2px;
  .muted {
    color: var(--muted-2);
  }
}
.tm-time {
  color: var(--muted-2);
  min-width: 38px;
}
.tm-jump {
  margin-left: auto;
}
.fp-history {
  margin-top: 8px;
  font-size: 12px;
  summary {
    cursor: pointer;
    color: var(--accent);
  }
  ul {
    margin: 4px 0 0;
    padding-left: 14px;
  }
  li {
    margin: 3px 0;
  }
  .fh-date {
    display: block;
    color: var(--muted);
  }
  .fh-what {
    display: block;
  }
}

.tm-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  margin: 4px 0 8px;
  i {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    vertical-align: -2px;
    margin-right: 3px;
    &.dashed {
      border: 2px dashed;
      background: transparent;
    }
  }
  .muted {
    color: var(--muted-2);
    margin-left: auto;
  }
}
.tm-counts {
  font-size: 12px;
  max-height: 220px;
  overflow-y: auto;
  .muted {
    color: var(--muted-2);
  }
}
.tm-count-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid var(--line);
}
.tm-count-total {
  font-weight: 600;
}
.tm-count-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- тёмная тема: карта и встроенные элементы MapLibre --- */
:root[data-theme='ayu_mirage'] {
  .maplibregl-popup-content {
    background: var(--panel);
    color: var(--text);
    box-shadow: 0 2px 12px var(--shadow);
  }
  .maplibregl-popup-close-button {
    color: var(--muted);
  }
  .maplibregl-popup-anchor-top .maplibregl-popup-tip,
  .maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
  .maplibregl-popup-anchor-top-right .maplibregl-popup-tip {
    border-bottom-color: var(--panel);
  }
  .maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
  .maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
  .maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip {
    border-top-color: var(--panel);
  }
  .maplibregl-popup-anchor-left .maplibregl-popup-tip {
    border-right-color: var(--panel);
  }
  .maplibregl-popup-anchor-right .maplibregl-popup-tip {
    border-left-color: var(--panel);
  }
  .maplibregl-ctrl-group {
    background: var(--panel);
    button + button {
      border-top-color: var(--border);
    }
    .maplibregl-ctrl-icon {
      filter: invert(0.85);
    }
  }
  .maplibregl-ctrl-attrib,
  .maplibregl-ctrl-attrib.maplibregl-compact {
    background: rgba(31, 36, 48, 0.8);
    color: var(--muted-2);
    a {
      color: var(--muted);
    }
  }
  .maplibregl-ctrl-scale {
    background: rgba(31, 36, 48, 0.75);
    color: var(--text);
    border-color: var(--muted-2);
  }
  .version-badge {
    border-color: var(--border);
    background: var(--panel);
  }
  .time-banner {
    background: #ffcc66;
    color: #1f2430;
  }
  .tm-day-head {
    background: var(--panel);
  }
}

.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--header-fg);
  cursor: pointer;
  &:hover {
    background: rgba(255, 255, 255, 0.15);
  }
}

/* ===== элементы интерфейса без библиотек (вместо antd) ===== */
* {
  box-sizing: border-box;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
a {
  color: var(--accent);
}
.i {
  width: 16px;
  height: 16px;
  flex: none;
  vertical-align: -3px;
}
.tile-row .i,
.tile-ibtn .i {
  width: 14px;
  height: 14px;
}
.map-btn .i {
  width: 18px;
  height: 18px;
}
.muted {
  color: var(--muted-2);
}
.small {
  font-size: 12px;
}
[hidden] {
  display: none !important;
}

/* кнопки шапки */
.hbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--header-fg);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  &:hover {
    background: rgba(255, 255, 255, 0.15);
  }
}
.theme-btn {
  width: 32px;
  padding: 0;
  justify-content: center;
}

/* обычные кнопки */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  &:hover:not(:disabled) {
    border-color: var(--brand);
    color: var(--brand);
  }
  &.primary {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--on-brand);
    &:hover:not(:disabled) {
      filter: brightness(1.08);
      color: var(--on-brand);
    }
  }
  &.small {
    height: 26px;
    padding: 0 8px;
    font-size: 12px;
  }
  &:disabled {
    opacity: 0.5;
    cursor: default;
  }
}
.ibtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  &:hover {
    background: var(--hover);
    color: var(--text);
  }
}

/* поля */
input[type='search'],
input[type='text'],
input[type='date'],
select {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  outline: none;
  &:focus {
    border-color: var(--brand);
  }
}
.tile-panel-search input,
.flight-search input,
.city3d-panel select,
.tile-3d-row select {
  width: 100%;
}
input[type='range'] {
  width: 100%;
  accent-color: var(--brand);
  margin: 6px 0;
}
.range2 {
  position: relative;
  height: 24px;
  input {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: none;
    &::-webkit-slider-thumb {
      pointer-events: auto;
    }
    &::-moz-range-thumb {
      pointer-events: auto;
    }
  }
}
.range-marks {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted-2);
  margin-top: -4px;
}

/* флажок и переключатель */
input.cb,
.legend-item input[type='checkbox'] {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--brand);
  flex: none;
  cursor: pointer;
}
.switch {
  position: relative;
  display: inline-flex;
  flex: none;
  width: 28px;
  height: 16px;
  cursor: pointer;
  input {
    position: absolute;
    opacity: 0;
    inset: 0;
    margin: 0;
    cursor: pointer;
  }
  > span {
    position: absolute;
    inset: 0;
    border-radius: 8px;
    background: var(--active-strong);
    transition: background 0.15s;
    &::after {
      content: '';
      position: absolute;
      top: 2px;
      left: 2px;
      width: 12px;
      height: 12px;
      border-radius: 50%;
      background: #fff;
      transition: transform 0.15s;
      box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    }
  }
  input:checked + span {
    background: var(--brand);
    &::after {
      transform: translateX(12px);
    }
  }
  input:disabled + span {
    opacity: 0.45;
  }
}

/* вкладки и сегменты */
.tabs {
  display: flex;
  gap: 16px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  .tab {
    border: 0;
    background: none;
    padding: 8px 0;
    cursor: pointer;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    &.on {
      color: var(--brand);
      border-bottom-color: var(--brand);
    }
  }
}
.segmented {
  display: inline-flex;
  padding: 2px;
  border-radius: 6px;
  background: var(--subtle);
  border: 1px solid var(--border);
  button {
    border: 0;
    background: none;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    color: var(--muted);
    &.on {
      background: var(--panel);
      color: var(--text);
      box-shadow: 0 1px 2px var(--shadow);
    }
  }
}

/* метки */
.tag {
  display: inline-block;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 11px;
  line-height: 18px;
  background: var(--subtle);
  color: var(--muted);
  border: 1px solid var(--border);
}
.tag-blue {
  color: #1677ff;
  background: rgba(22, 119, 255, 0.1);
  border-color: rgba(22, 119, 255, 0.3);
}
.tag-green {
  color: #389e0d;
  background: rgba(82, 196, 26, 0.12);
  border-color: rgba(82, 196, 26, 0.35);
}
.tag-red {
  color: #cf1322;
  background: rgba(245, 34, 45, 0.1);
  border-color: rgba(245, 34, 45, 0.3);
}
.tag-gold {
  color: #d48806;
  background: rgba(250, 173, 20, 0.12);
  border-color: rgba(250, 173, 20, 0.35);
}
:root[data-theme='ayu_mirage'] {
  .tag-blue { color: #73d0ff; }
  .tag-green { color: #87d96c; }
  .tag-red { color: #f28779; }
  .tag-gold { color: #ffcc66; }
}

/* всплывающие панели у кнопок */
.pop-wrap {
  position: relative;
}
.pop {
  position: absolute;
  z-index: 20;
  top: 0;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px var(--shadow);
  &.pop-left {
    right: calc(100% + 8px);
  }
  &.pop-right {
    right: 0;
    top: calc(100% + 6px);
  }
}
.pop-title {
  font-weight: 600;
  margin-bottom: 8px;
}
.menu {
  display: flex;
  flex-direction: column;
  min-width: 180px;
  button {
    border: 0;
    background: none;
    text-align: left;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text);
    &:hover {
      background: var(--hover);
    }
    &.on {
      color: var(--brand);
      font-weight: 600;
    }
  }
}
.map-btn.active {
  outline: 2px solid var(--brand);
}

/* окно */
.modal {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 10px 40px var(--shadow);
  &::backdrop {
    background: rgba(0, 0, 0, 0.35);
  }
}
.modal-head {
  display: flex;
  align-items: center;
  padding: 12px 12px 8px 16px;
  border-bottom: 1px solid var(--border);
  .modal-title {
    flex: 1;
    font-weight: 600;
  }
}
.modal-body {
  padding: 12px 16px 16px;
}

/* выдвижная панель */
.drawer {
  position: fixed;
  top: var(--header-h);
  right: 0;
  bottom: 0;
  width: min(460px, 100vw);
  z-index: 30;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: -6px 0 20px var(--shadow);
}
.drawer-head {
  display: flex;
  align-items: center;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--border);
  .drawer-title {
    flex: 1;
    font-weight: 600;
  }
}
.drawer-body {
  flex: 1;
  overflow: auto;
  padding: 12px 16px;
}
.tm-feed {
  max-height: none;
}
.tm-empty {
  color: var(--muted-2);
  font-size: 13px;
  padding: 16px 0;
  text-align: center;
}

/* поиск */
.place-search,
.flight-search {
  position: relative;
}
.place-search {
  width: 360px;
  input {
    width: 100%;
    padding-left: 30px;
    background: var(--panel);
    color: var(--text);
  }
  .place-icon {
    position: absolute;
    left: 9px;
    top: 7px;
    color: var(--muted-2);
  }
}
.search-results {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  &:empty {
    display: none;
  }
  .results {
    list-style: none;
    margin: 0;
    padding: 4px;
    max-height: 360px;
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 6px 20px var(--shadow);
  }
  button {
    width: 100%;
    border: 0;
    background: none;
    text-align: left;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text);
    font-size: 13px;
    &:hover {
      background: var(--hover);
    }
  }
  .results-empty {
    padding: 8px 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted-2);
    font-size: 13px;
  }
}

/* дерево */
.tile-group.open > .tile-row .tile-icon .i {
  opacity: 1;
}
.tile-settings {
  padding-right: 16px;
  padding-bottom: 6px;
}
.tile-setting-label {
  display: flex;
  align-items: center;
  gap: 6px;
}
.legend-item {
  user-select: none;
}

/* прогресс */
.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--subtle);
  overflow: hidden;
  .bar {
    height: 100%;
    width: 0;
    background: var(--brand);
  }
}

/* аналитика */
.analytics-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.analytics-nav {
  width: 260px;
  flex: none;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  padding-right: 8px;
  position: sticky;
  top: 0;
}
.analytics-nav .analytics-tab {
  width: auto;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  &:hover {
    background: var(--hover);
  }
  &.on {
    background: var(--active);
    color: var(--brand);
  }
}
.analytics-view {
  flex: 1;
  min-width: 0;
}
.analytics-filter input {
  width: 240px;
}
.alert {
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--subtle);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  &.error {
    background: var(--error-bg);
    border-color: var(--error-border);
  }
}
.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
table.grid {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
  th,
  td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  th {
    position: sticky;
    top: 0;
    background: var(--subtle);
    font-weight: 600;
    a {
      color: var(--text);
      text-decoration: none;
    }
  }
  .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
  }
  tbody tr:hover {
    background: var(--hover);
  }
  .empty {
    text-align: center;
    color: var(--muted-2);
    padding: 16px;
  }
}
.pager {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  margin: 10px 0;
}

/* ===== мобильная верстка ===== */
@media (max-width: 720px) {
  :root {
    --header-h: 52px;
  }
  .app-header {
    gap: 6px;
    padding: 0 6px;
    .brand {
      gap: 6px;
    }
    .brand-title {
      font-size: 16px;
    }
    .brand-sub {
      display: none;
    }
    .version-badge {
      margin-left: 0;
      padding: 0 5px;
      font-size: 10px;
    }
    .grow {
      display: none;
    }
  }
  /* кнопки шапки — только иконки */
  .hbtn {
    padding: 0 8px;
    span {
      display: none;
    }
  }
  .place-search {
    flex: 1;
    min-width: 0;
    width: auto;
  }
  .place-search .search-results {
    position: fixed;
    top: calc(var(--header-h) + 4px);
    left: 6px;
    right: 6px;
  }
  .time-banner {
    margin-right: 0;
    padding: 2px 4px 2px 8px;
    font-size: 12px;
    .time-banner-date {
      max-width: 120px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  /* панель слоев — выезжает поверх карты */
  .side {
    position: fixed;
    z-index: 25;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: min(360px, 90vw);
    box-shadow: 6px 0 24px var(--shadow);
  }
  .tile-row {
    min-height: 38px;
  }
  .tile-ibtn {
    padding: 6px;
  }
  .tile-panel-search input {
    height: 36px;
  }

  /* кнопки карты крупнее под палец */
  .map-btn {
    width: 42px;
    height: 42px;
  }
  .map-tools {
    top: 8px;
    right: 8px;
  }
  .maplibregl-ctrl-group button {
    width: 36px;
    height: 36px;
  }

  /* панели у кнопок карты — снизу на всю ширину */
  .pop.pop-left {
    position: fixed;
    left: 8px;
    right: 8px;
    top: auto;
    bottom: 8px;
    max-height: 70vh;
    overflow: auto;
  }
  .city3d-panel,
  .flight-panel {
    width: auto;
  }
  .pop.pop-right {
    position: fixed;
    top: calc(var(--header-h) + 4px);
    right: 6px;
  }

  /* история — на весь экран */
  .drawer {
    width: 100vw;
    border-left: 0;
  }
  .drawer-body {
    padding: 10px 12px;
  }
  .tm-row {
    gap: 6px;
  }
  .segmented button {
    padding: 4px 8px;
  }

  .modal {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 32px);
  }
  .changelog-head {
    flex-direction: column;
    align-items: flex-start;
  }
  .cl-commit {
    display: none;
  }

  .maplibregl-popup {
    max-width: calc(100vw - 24px) !important;
  }
  .feature-popup {
    max-height: 50vh;
  }

  /* аналитика: вкладки витрин — горизонтальная прокрутка */
  .analytics-body {
    padding: 8px;
  }
  .analytics-layout {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .analytics-view {
    width: 100%;
    overflow: hidden;
  }
  .analytics-head > div:first-child {
    min-width: 0;
    width: 100%;
  }
  .analytics-nav {
    position: static;
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 0 0 6px;
    gap: 4px;
    .analytics-tab {
      flex: none;
      max-width: 220px;
      white-space: nowrap;
      span:first-child {
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }
  .analytics-head {
    flex-wrap: wrap;
    .grow {
      display: none;
    }
  }
  .analytics-filter,
  .analytics-filter input {
    width: 100%;
  }
  .analytics-summary .stat {
    min-width: calc(50% - 4px);
    flex: 1;
  }
  .analytics-title {
    font-size: 16px;
  }
}

/* очень узкие экраны */
@media (max-width: 400px) {
  .brand-title {
    display: none;
  }
}

/* значки подложек без превью */
.basemap-ph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  .i {
    width: 20px;
    height: 20px;
  }
  &.kind-style {
    background: linear-gradient(135deg, #4f8fd9, #7cc28a) !important;
  }
  &.kind-raster {
    background: linear-gradient(135deg, #9a8f6b, #c9b98c) !important;
  }
  &.kind-none {
    background: var(--active-strong) !important;
    color: var(--muted);
  }
}
