/* === Reset and root === */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a1a;
}

/* === Map container — заполняет 100% вьюпорта/iframe === */
.map {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  /* Убираем системную синюю подсветку тапов (iOS/Android/эмуляция в DevTools) */
  -webkit-tap-highlight-color: transparent;
  /* И случайное выделение "текста" карты при тапах/драгах */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.map__bg {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

/* === Viewport — фиксированный «холст» 1920×1080, масштабируется и пан-ится через transform === */
.map__viewport {
  position: absolute;
  top: 0;
  left: 0;
  width: 1920px;
  height: 1080px;
  transform-origin: 0 0;
  will-change: transform;
  touch-action: none; /* отдаём управление жестами нашему JS */
  cursor: grab;
}
.map__viewport.is-panning { cursor: grabbing; }

/* === POI layer (иконки инфраструктуры) === */
.map__poi {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* слой прозрачен для кликов, ловят только сами бейджи */
}
.poi-badge {
  pointer-events: auto;
  cursor: pointer;
}
.poi-label {
  opacity: 0;
  transform: translateX(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none; /* кликабельна только иконка — скрытая пилюля не должна перехватывать клики соседей */
}
.poi-badge.is-open .poi-label {
  opacity: 1;
  transform: translateX(0);
}
.poi-label text {
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  font-weight: 600;
  fill: #31130a;
  dominant-baseline: middle;
}

/* === Plots layer === */
.map__plots {
  position: absolute;
  inset: 0;
  pointer-events: none; /* SVG ловит события сам, контейнер прозрачен */
}
.map__plots svg {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* === Plot badges (area + price over each plot) === */
.badge { pointer-events: none; opacity: 0; transition: opacity 0.15s; }
.badges-visible .badge.badge--has-data { opacity: 1; }
.badge__bg {
  fill: #ffffff;
  stroke: #c89f5e;
  stroke-width: 0.2;
}
.badge__area {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 3.5px;
  font-weight: 700;
  fill: #000;
  text-anchor: middle;
  dominant-baseline: middle;
}
.badge__divider { stroke: #cfcfcf; stroke-width: 0.15; }
.badge__price {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 3px;
  fill: #7b7b7b;
  text-anchor: middle;
  dominant-baseline: middle;
}
.plot {
  pointer-events: auto;
  cursor: pointer;
  transition: fill 0.15s ease, stroke-width 0.15s ease;
}
/* SVG gradient fills are defined in index.html → <svg class="svg-defs"> */
.plot[data-status="free"]    { fill: url(#grad-free);  stroke: #fff; stroke-width: 1.5; }
.plot[data-status="sold"]    { fill: url(#grad-sold);  stroke: #fff; stroke-width: 1.5; }
.plot[data-status="bath"]    { fill: url(#grad-bath);  stroke: #fff; stroke-width: 1.5; }
/* unknown is intentionally faded — plots without sheet data should not look like active inventory */
.plot[data-status="unknown"] { fill: #888888; fill-opacity: 0.35; stroke: #fff; stroke-width: 1; }
.plot:hover {
  stroke: #ffffff;
  stroke-width: 2;
  filter: brightness(1.15);
}
/* Active/selected — Figma demo "selected state" (olive gradient) */
.plot.is-selected,
.plot.is-selected:hover {
  fill: url(#grad-selected);
  fill-opacity: 1;
  stroke: #ffffff;
  stroke-width: 2.5;
  filter: drop-shadow(0 0 6px rgba(118, 137, 73, 0.75));
}

/* === Legend === */
.map__legend {
  position: absolute;
  top: 74px; /* под кнопкой «На сайт» */
  left: 24px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 2;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.legend__item { display: flex; align-items: center; gap: 8px; }
.legend__swatch {
  width: 14px; height: 14px; border-radius: 3px;
  display: inline-block;
}
.legend__swatch--free { background: linear-gradient(149deg, #3A5B49 15.92%, #263C30 82.26%); }
.legend__swatch--sold { background: linear-gradient(90deg,  #C89F5E 0%,     #B5873E 100%); }
.legend__swatch--bath { background: linear-gradient(135deg, #8A4523 0%,     #AE6138 100%); }

/* === Compass === */
.map__compass {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 120px;
  height: auto;
  z-index: 2;
  pointer-events: none;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.35));
}
@media (max-width: 768px) {
  .map__compass { width: 80px; top: 8px; right: 8px; }
}

/* === Back to main site (top-left — конвенция «назад/выход») === */
.map__home {
  position: absolute;
  top: 24px;
  left: 24px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.94);
  color: #2a2a2a;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  transition: background 0.12s, transform 0.06s;
}
.map__home:hover { background: #fff; }
.map__home:active { transform: scale(0.96); }
@media (max-width: 768px) {
  .map__home { top: 8px; left: 8px; padding: 8px 12px; font-size: 13px; }
}

/* === Zoom controls === */
.map__zoom {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 3;
}
.map__zoom-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  color: #2a2a2a;
  font-size: 22px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  transition: background 0.12s, transform 0.06s;
  user-select: none;
}
.map__zoom-btn:hover { background: #fff; }
.map__zoom-btn:active { transform: scale(0.94); }
.map__zoom-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.map__zoom-btn--reset { font-size: 18px; margin-top: 4px; }
@media (max-width: 768px) {
  .map__zoom { right: 8px; bottom: 8px; }
  .map__zoom-btn { width: 36px; height: 36px; font-size: 20px; }
}

/* === Popover === */
.popover {
  position: absolute;
  background: #ffffff;
  border-radius: 10px;
  padding: 16px 18px;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  z-index: 3;
  pointer-events: auto;
}
/* Specificity guard: wins over display:flex/grid rules that could beat native [hidden] */
.popover[hidden] { display: none; }
.popover__close {
  position: absolute; top: 6px; right: 8px;
  background: transparent; border: none; cursor: pointer;
  font-size: 20px; line-height: 1; color: #888;
}
.popover__close:hover { color: #000; }
.popover__title { font-weight: 600; margin-bottom: 8px; }
.popover__row { font-size: 13px; color: #555; margin-bottom: 4px; }
.popover__value { color: #000; font-weight: 500; }
.popover__price { font-size: 18px; font-weight: 700; margin: 10px 0; }
.popover__status {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: white;
}
.popover__status[data-status="free"]    { background: #4F6B3A; }
.popover__status[data-status="sold"]    { background: #C9A55C; color: #4a3a1a; }
.popover__status[data-status="bath"]    { background: #8B4543; }
.popover__status[data-status="unknown"] { background: #888; }

/* === Loader / retry === */
.map__loader {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(26, 26, 26, 0.82);
  color: #fff;
}
/* Specificity guard: wins over display:flex rules that could beat native [hidden] */
.map__loader[hidden] { display: none; }
.loader__spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(200, 159, 94, 0.25);
  border-top-color: #c89f5e;
  animation: loader-spin 0.8s linear infinite;
}
.loader__spinner[hidden] { display: none; }
@keyframes loader-spin { to { transform: rotate(360deg); } }
.loader__text { font-size: 15px; }
.loader__retry {
  border: none;
  border-radius: 8px;
  background: #c89f5e;
  color: #31130a;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 26px;
  cursor: pointer;
  transition: background 0.12s, transform 0.06s;
}
.loader__retry:hover { background: #d4ad6e; }
.loader__retry:active { transform: scale(0.96); }

/* === Error / stale notice === */
.map__error {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 220, 100, 0.95);
  color: #4a3a00;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 4;
}
/* Specificity guard: wins over display:flex/grid rules that could beat native [hidden] */
.map__error[hidden] { display: none; }

/* === Mobile === */
@media (max-width: 768px) {
  .map__legend { top: 50px; left: 8px; padding: 8px 10px; font-size: 12px; } /* под кнопкой «На сайт» */
  .popover {
    /* На узких экранах поповер прижимается к низу карты, чтобы не закрывать участок */
    left: 8px !important;
    right: 8px !important;
    bottom: 8px !important;
    top: auto !important;
    min-width: 0;
  }
  .plot:hover { stroke-width: 0; filter: none; } /* без hover на тач-устройствах */
}
@media (hover: none) {
  .plot:hover { stroke-width: 0; filter: none; }
}
