:root {
  --black: #000;
  --ink: #1d1d1f;
  --gray: #6e6e73;
  --line: #d2d2d7;
  --soft: #f5f5f7;
  --white: #fff;
  --gutter: 22px;
  --nav: 48px;
  --foot: 40px;
  --r: 8px;
  --r-sm: 5px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; background: var(--white); }
body, button, a, label { -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }
body {
  margin: 0;
  padding-bottom: var(--foot);
  overscroll-behavior-y: none;
  background: var(--white);
  color: var(--ink);
  font-family: 'Roboto', system-ui, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
.muted { color: var(--gray); }

/* ---------- Навигация: край в край с картой ---------- */
.nav {
  position: sticky; top: 0; z-index: 1000;
  background: var(--white);
}
.nav-inner { padding: 0 var(--gutter); height: var(--nav); display: flex; align-items: center; justify-content: space-between; }
.logo { text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.logo span { color: var(--gray); font-weight: 300; }
.nav-links { display: flex; align-items: center; gap: 20px; font-size: 13px; }
.nav-links a { text-decoration: none; color: var(--ink); opacity: 0.8; }
.nav-links a:hover { opacity: 1; }
.lang { display: flex; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 2px; }
.lang button { border: 0; background: none; padding: 3px 9px; border-radius: 3px; font-size: 12px; font-weight: 500; cursor: pointer; color: var(--gray); }
.lang button[aria-pressed="true"] { background: var(--black); color: var(--white); }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: var(--r); padding: 12px 24px;
  font-size: 16px; font-weight: 500; text-decoration: none; cursor: pointer;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
}
.btn:active { transform: scale(0.98); }
.btn-dark { background: var(--black); color: var(--white); }
.btn-dark:hover { background: #333; }
.btn-dark:disabled { background: #999; cursor: default; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: var(--r-sm); }

/* ---------- Карта слева, настройки справа ---------- */
.app { padding: 16px var(--gutter) 0; }
.map-wrap {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px;
  height: calc(100vh - var(--nav) - var(--foot) - 32px);
  height: calc(100svh - var(--nav) - var(--foot) - 32px);
  min-height: 480px;
}
.map-box { position: relative; border-radius: var(--r); overflow: hidden; background: var(--soft); }
#map { position: absolute; inset: 0; }
.leaflet-container { background: var(--soft); font-family: inherit; }
.leaflet-control-attribution { font-size: 10px; background: rgba(255, 255, 255, 0.7) !important; }
.leaflet-control-attribution a { color: var(--ink); }
.leaflet-bar { border-radius: var(--r-sm) !important; }
.leaflet-bar a { color: var(--ink); }
.leaflet-bar a:first-child { border-radius: var(--r-sm) var(--r-sm) 0 0 !important; }
.leaflet-bar a:last-child { border-radius: 0 0 var(--r-sm) var(--r-sm) !important; }

.frame {
  position: absolute; left: 50%; top: 50%; z-index: 500; pointer-events: none;
  width: 300px; height: 300px; transform: translate(-50%, -50%);
  border: 2px solid var(--black);
  box-shadow: 0 0 0 9999px rgba(255, 255, 255, 0.45);
}
.frame span {
  position: absolute; left: -2px; top: -26px;
  background: var(--black); color: var(--white); font-size: 12px; font-weight: 500;
  padding: 3px 8px; border-radius: 3px; white-space: nowrap;
}

.panel {
  display: flex; flex-direction: column; gap: 14px;
  min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px; border: 1px solid var(--line); border-radius: var(--r); background: var(--white);
}
.search { position: relative; }
.search input {
  width: 100%; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--white);
  padding: 10px 12px; font-size: 15px; outline: none;
}
.search input:focus { border-color: var(--black); }
.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 2;
  list-style: none; margin: 0; padding: 4px; background: var(--white); border: 1px solid var(--line); border-radius: var(--r-sm); box-shadow: var(--shadow);
  max-height: 260px; overflow: auto;
}
.results li { padding: 8px 9px; border-radius: 3px; font-size: 14px; cursor: pointer; line-height: 1.3; }
.results li:hover, .results li[aria-selected="true"] { background: var(--soft); }

.field-head { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-bottom: 8px; }
.field-head b { font-weight: 500; white-space: nowrap; }
.field.sub { padding-left: 14px; margin-top: -6px; }
.field.sub .field-head { font-size: 13px; color: var(--gray); }
.field.sub.off { opacity: 0.45; pointer-events: none; }
input[type="range"] { width: 100%; -webkit-appearance: none; appearance: none; background: transparent; height: 20px; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: var(--line); border-radius: 2px; }
input[type="range"]::-moz-range-track { height: 3px; background: var(--line); border-radius: 2px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7.5px; border-radius: 4px; background: var(--black); border: 0; }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 4px; background: var(--black); border: 0; }

.toggles { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { position: relative; width: 36px; height: 20px; border-radius: 4px; background: var(--line); transition: background 0.2s; flex: none; }
.toggle i::after { content: ''; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 3px; background: var(--white); transition: transform 0.2s; }
.toggle input:checked + i { background: var(--black); }
.toggle input:checked + i::after { transform: translateX(16px); }
.toggle input:disabled + i { opacity: 0.4; }
.toggle.sub { padding-left: 14px; font-size: 13px; color: var(--gray); }
.toggle.sub:has(input:disabled) { opacity: 0.5; }
.toggle input:focus-visible + i { outline: 2px solid var(--black); outline-offset: 2px; }
.toggles .field.sub { padding: 8px 0 10px 14px; margin: 0; border-bottom: 1px solid var(--line); }

.status { margin: -4px 0 0; font-size: 13px; color: var(--gray); line-height: 1.4; min-height: 18px; }
.status.error { color: var(--black); font-weight: 500; }
.progress { display: block; height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 8px; }
.progress::after { content: ''; display: block; height: 100%; width: 35%; background: var(--black); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

/* ---------- Результат ---------- */
.result { padding: 72px var(--gutter) 24px; }
.result-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 24px; flex-wrap: wrap; }
.result h2 { font-size: clamp(34px, 5vw, 52px); font-weight: 700; }
.result-head .muted { margin: 8px 0 0; font-size: 15px; }
.stats { display: flex; gap: 36px; margin: 0; }
.stats div { text-align: right; }
.stats dt { font-size: 13px; color: var(--gray); }
.stats dd { margin: 2px 0 0; font-size: 32px; font-weight: 300; letter-spacing: -0.02em; }

.stage { position: relative; height: min(66vh, 680px); min-height: 360px; border-radius: var(--r); overflow: hidden; background: var(--soft); }
.viewer, .flat { position: absolute; inset: 0; }
.viewer canvas { display: block; width: 100%; height: 100%; }
.flat { overflow: hidden; cursor: grab; touch-action: none; background: var(--soft); }
.flat:active { cursor: grabbing; }
.flat img { position: absolute; left: 0; top: 0; transform-origin: 0 0; user-select: none; max-width: none; }
.viewer-hint {
  position: absolute; left: 12px; bottom: 12px; z-index: 2; pointer-events: none;
  font-size: 12px; color: var(--gray); background: rgba(255, 255, 255, 0.85); padding: 4px 8px; border-radius: var(--r-sm);
}

/* сегментированный переключатель (карта/спутник, вкладки превью) */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r); background: rgba(255, 255, 255, 0.92); box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12); }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: var(--r-sm); font-size: 13px; font-weight: 500; cursor: pointer; color: var(--ink); }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--black); color: var(--white); }
.maptype { position: absolute; left: 12px; top: 12px; z-index: 700; }
.tabs { margin: 0 0 12px; background: var(--soft); box-shadow: none; }

.downloads { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-top: 12px; }
.dl {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 16px 18px; border-radius: var(--r); border: 1px solid var(--line); background: var(--white);
  cursor: pointer; text-align: left; transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.dl b { font-size: 16px; font-weight: 500; }
.dl span { font-size: 13px; color: var(--gray); }
.dl:hover:not(:disabled) { background: var(--black); color: var(--white); border-color: var(--black); }
.dl:hover:not(:disabled) span { color: #a1a1a6; }
.dl:disabled { opacity: 0.45; cursor: default; }
.dl.busy span::after { content: ' · ' attr(data-busy); }
.quota { font-size: 13px; color: var(--gray); margin: 16px 0 0; }

/* ---------- Вопросы ---------- */
.faq { padding: 80px var(--gutter) 72px; max-width: calc(760px + 2 * var(--gutter)); }
.faq h2 { font-size: clamp(34px, 5vw, 52px); font-weight: 700; line-height: 1.05; margin-bottom: 36px; }
.faq details { border-bottom: 1px solid var(--line); }
.faq summary { list-style: none; cursor: pointer; padding: 18px 0; font-size: 18px; font-weight: 500; display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: '+'; font-weight: 300; font-size: 24px; line-height: 1; transition: transform 0.2s; }
.faq details[open] summary::after { transform: rotate(45deg); }
.faq details p { margin: 0 0 20px; font-size: 16px; line-height: 1.55; color: var(--gray); }

/* ---------- Подвал (закреплён) ---------- */
.footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; height: var(--foot);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 var(--gutter); font-size: 12px;
  background: var(--white);
  box-sizing: content-box; padding-bottom: env(safe-area-inset-bottom);
}
.footer p { margin: 0; white-space: nowrap; }
.footer .credits { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.footer .muted a { color: var(--gray); }
.footer-right { display: flex; align-items: center; gap: 18px; flex: none; font-size: 13px; }
.footer-right a { text-decoration: none; }
.mail { color: var(--gray); }
.mail:hover { color: var(--ink); }
.made a { font-weight: 700; border-bottom: 1px solid currentColor; }

/* ---------- Телеграм (компактный) ---------- */
.tg {
  position: fixed; left: var(--gutter); bottom: calc(var(--foot) + 12px); z-index: 1100;
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px 7px 7px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow);
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
  max-width: calc(100vw - 2 * var(--gutter));
}
.tg-avatar { border: 0; padding: 0; background: none; cursor: pointer; flex: none; display: block; border-radius: 50%; }
.tg img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; display: block; }
.tg.min { padding: 5px; gap: 0; border-radius: 50%; right: auto !important; }
.tg.min .tg-text, .tg.min .btn, .tg.min .tg-close { display: none; }
.tg-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.tg-text b { font-size: 12px; font-weight: 700; }
.tg-text span { font-size: 11px; color: var(--gray); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg-close {
  position: absolute; top: -7px; right: -7px; width: 18px; height: 18px; border-radius: 50%;
  border: 0; background: var(--black); color: var(--white); cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.tg-close svg { width: 8px; height: 8px; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- Адаптив ---------- */
@media (max-width: 1000px) {
  .downloads { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  :root { --gutter: 16px; }
  body { padding-bottom: calc(var(--foot) + 60px); }
  .map-wrap { display: block; height: auto; min-height: 0; }
  .map-box { height: 60vh; min-height: 360px; }
  .panel { margin-top: 12px; overflow: visible; }
  .result { padding-top: 56px; }
  .stats { gap: 20px; }
  .stats div { text-align: left; }
  .downloads { grid-template-columns: 1fr 1fr; }
  .footer .credits { display: none; }
  .footer { justify-content: flex-end; }
  .tg { right: var(--gutter); }
  .tg .btn { margin-left: auto; }
}
