/* Карты: страница /karta, маркеры, панель списка, мини-карта объявления, выбор точки.
   Подключается вместе с leaflet.css только там, где есть карта (в том числе в админке). */
:root {
    --map-green: #2f6b3a;
    --map-red: #b4441a;
    --map-line: #e7e1d3;
    --map-soft: #f1ece0;
    --map-muted: #6b705f;
}

/* ---------- страница /karta: карта на всю высоту под шапкой */
/* Страница карты — ровно во весь видимый экран, без прокрутки страницы.
   В iOS Safari 100vh больше видимой области (нижняя панель браузера то появляется, то прячется),
   а высота шапки зависит от ширины. Поэтому body зафиксирован по краям экрана (fixed следует
   за видимой областью), шапка — сколько займёт, карта — всё остальное. */
body.is-map { position: fixed; inset: 0; overflow: hidden; display: flex; flex-direction: column; overscroll-behavior: none; }
body.is-map .head { position: relative; flex: 0 0 auto; }
body.is-map .foot { display: none; }
main.main--wide { max-width: none; padding: 0; }
body.is-map main.main--wide { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.mapwrap { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
/* Во flex-колонке элементы не сжимаются уже содержимого — строка чипов растягивала карту за экран */
body.is-map main.main--wide, .mapwrap, .mapbar, .mapbar > *, .mapbox { min-width: 0; max-width: 100%; }
.mapbar { padding: 10px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--map-line); background: #faf7f0; }
.mapbar__top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mapbar__h { margin: 0; font-size: 18px; }
.mapbar__n { color: var(--map-muted); font-weight: 400; }
.mapbar .viewsw { margin: 0; }
button.chip { font: inherit; font-size: 14px; cursor: pointer; }
.mapbox { position: relative; flex: 1; min-height: 0; isolation: isolate; z-index: 0; }  /* слои Leaflet (до z-index 1000) не перекрывают меню шапки */
.map { position: absolute; inset: 0; background: #e9e5dc; }
.mapnote { position: absolute; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 500; margin: 0; padding: 7px 14px; border-radius: 999px; background: rgba(255,255,255,.95); box-shadow: 0 1px 2px rgba(31,42,28,.06), 0 4px 14px rgba(31,42,28,.05); font-size: 14px; line-height: 1.35; text-align: center; width: max-content; max-width: calc(100% - 32px); border-radius: 14px; }

/* Панель со списком: справа на компьютере, снизу на телефоне */
.mappanel { position: absolute; z-index: 1100; background: #fff; box-shadow: 0 8px 30px rgba(31,42,28,.18); overflow-y: auto; overscroll-behavior: contain; }
@media (min-width: 720px) { .mappanel { top: 12px; right: 12px; bottom: 12px; width: 380px; border-radius: 14px; } }
@media (max-width: 719px) { .mappanel { left: 0; right: 0; bottom: 0; max-height: 62%; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); } }
.mappanel[hidden] { display: none; }
.mappanel__body { padding: 16px 16px 20px; }
.mappanel__x { position: sticky; top: 8px; float: right; margin: 8px 8px 0 0; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--map-line); background: #fff; cursor: pointer; font-size: 15px; z-index: 1; }
.mappanel__h { margin: 0 40px 2px 0; font-size: 18px; }
.mappanel__sub { margin: 0 0 6px; font-size: 13px; color: var(--map-muted); }
.mappanel__cat { margin: 16px 0 6px; font-size: 15px; }
.mlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.mlist__a { display: flex; gap: 10px; align-items: center; padding: 6px; border-radius: 10px; color: #1f2a1c; text-decoration: none; }
.mlist__a:hover { background: var(--map-soft); }
.mlist__pic { flex: 0 0 56px; height: 56px; border-radius: 8px; overflow: hidden; background: var(--map-soft); display: flex; align-items: center; justify-content: center; font-size: 26px; }
.mlist__pic img { width: 100%; height: 100%; object-fit: cover; }
.mlist__body { min-width: 0; display: flex; flex-direction: column; }
.mlist__title { font-size: 14px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mlist__meta { font-size: 13px; color: var(--map-muted); }
.mlist__meta b { color: var(--map-red); font-weight: 600; }

/* Маркеры: место — «таблетка» с категориями, своя точка продавца — с хвостиком */
.mk-wrap { background: none; border: 0; }
.mk { position: absolute; left: 0; top: 0; transform: translate(-50%, -50%); display: flex; gap: 2px; padding: 3px 5px; border-radius: 999px; background: #fff; border: 2px solid var(--map-green); box-shadow: 0 2px 6px rgba(0,0,0,.25); white-space: nowrap; cursor: pointer; font-size: 15px; line-height: 1; }
.mk--exact { transform: translate(-50%, calc(-100% - 7px)); border-color: var(--map-red); }
.mk--exact::after { content: ""; position: absolute; left: 50%; bottom: -8px; margin-left: -6px; border: 6px solid transparent; border-top-color: var(--map-red); border-bottom: 0; }
.mk__c { display: inline-flex; align-items: center; gap: 1px; padding: 2px 3px; }
.mk__c b { font-size: 12px; font-weight: 700; color: #1f2a1c; }
.mk__more { font-size: 12px; font-weight: 600; color: var(--map-muted); align-self: center; padding: 0 3px; }
.mk--one { padding: 4px 6px; font-size: 18px; }
.mk--pin { cursor: grab; }
.leaflet-marker-icon:hover .mk, .leaflet-marker-icon:focus .mk { box-shadow: 0 0 0 3px rgba(47,107,58,.25), 0 2px 6px rgba(0,0,0,.25); }
.mk--group { border-width: 2px; background: #f4f9f2; font-size: 16px; padding: 4px 6px;
    /* «стопка»: под плашкой видны края ещё двух — значит, внутри несколько мест, клик приближает */
    box-shadow: 3px 3px 0 -1px #fff, 3px 3px 0 1px var(--map-green), 6px 6px 0 -1px #fff, 6px 6px 0 1px var(--map-green), 0 3px 10px rgba(0,0,0,.25); }
.mk--group .mk__c b { font-size: 13px; }
/* Подпись OSM и кнопки масштаба не уходят под «домашнюю» полоску iPhone и под вырез экрана */
.map .leaflet-bottom { margin-bottom: env(safe-area-inset-bottom); }
.map .leaflet-left { margin-left: env(safe-area-inset-left); }
.map .leaflet-right { margin-right: env(safe-area-inset-right); }
.leaflet-container { font: inherit; }
.leaflet-container a { color: var(--map-green); }

/* ---------- мини-карта объявления и выбор точки */
.admap__map { height: 240px; border-radius: 14px; overflow: hidden; border: 1px solid var(--map-line); background: #e9e5dc; position: relative; z-index: 0; }
.admap__note { margin: 8px 0 0; font-size: 14px; color: var(--map-muted); display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: space-between; }
.mpick { display: flex; flex-direction: column; gap: 8px; }
.mpick[hidden] { display: none; }
.mpick__map { height: 260px; border-radius: 12px; overflow: hidden; border: 1px solid var(--map-line); background: #e9e5dc; position: relative; z-index: 0; cursor: crosshair; }
.mpick__bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.mpick__state { font-size: 14px; }
.mpick__bar .btn[hidden] { display: none; }
.my-pick { display: flex; flex-direction: column; gap: 8px; }
.my-pick__label { font-size: 14px; color: var(--map-muted); }

/* Быстрый фильтр категорий в панели */
.mappanel__chips { margin: 4px 0 2px; }
.mappanel__chips .chip { font: inherit; font-size: 14px; cursor: pointer; }
.mappanel [data-pcat-sect][hidden] { display: none; }

/* Кнопка поиска в шапке — только на странице карты и только на телефоне */
.head__find { display: none; }

@media (max-width: 719px) {
    /* Шапка карты: логотип, «Разместить», 🔍 — поиск раскрывается по кнопке */
    body.is-map .head__in { padding-top: 8px; padding-bottom: 8px; flex-wrap: nowrap; gap: 8px; }
    body.is-map .logo__text small, body.is-map .head__map { display: none; }
    body.is-map .logo__mark { font-size: 24px; }
    body.is-map .head__sell { margin-left: auto; }
    body.is-map .head__find { display: inline-flex; align-items: center; justify-content: center; order: 4; width: 38px; height: 38px; flex: 0 0 38px; border-radius: 50%; border: 1px solid var(--map-line); background: #fff; color: #1f2a1c; cursor: pointer; }
    body.is-map .search { display: none; }
    body.is-map.search-open .head__in { flex-wrap: wrap; }
    body.is-map.search-open .search { display: flex; order: 5; flex: 1 1 100%; }

    /* Фильтры — одной прокручиваемой строкой: «Списком», категории, как забрать */
    .mapbar { flex-direction: row; align-items: center; gap: 8px; padding-top: 8px; padding-bottom: 8px; overflow-x: auto; scrollbar-width: none; }
    .mapbar::-webkit-scrollbar { display: none; }
    .mapbar__top, .mapbar .chips { display: contents; }
    .mapbar__h { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    .mapbar .viewsw { flex: 0 0 auto; order: -1; padding: 0; border: 0; background: none; }
    .mapbar .viewsw__i.is-on { display: none; }
    .mapbar .viewsw__i { padding: 7px 12px; border: 1px solid var(--map-green); border-radius: 999px; color: var(--map-green); font-weight: 600; background: #fff; }
    .mapbar .chip { flex: 0 0 auto; }

    /* Нижняя панель браузера в iOS плавает поверх страницы — список должен прокручиваться выше неё */
    .mappanel__body { padding-bottom: calc(24px + env(safe-area-inset-bottom) + 48px); }
}

/* «Рядом со мной»: кнопка и точка посетителя */
.chip--near { border-color: #1f6fd1; color: #1f6fd1; font-weight: 600; }
.chip--near[disabled] { opacity: .6; }
.me-dot { background: none; border: 0; }
.me-dot i { display: block; width: 18px; height: 18px; border-radius: 50%; background: #1f6fd1; border: 3px solid #fff; box-shadow: 0 0 0 2px rgba(31,111,209,.35), 0 2px 6px rgba(0,0,0,.3); }

/* Нижняя панель на телефоне: «ручка» и свайп вниз для закрытия */
.mappanel__grip { display: none; }
@media (max-width: 719px) {
    .mappanel { transition: transform .18s ease-out; touch-action: pan-y; }
    .mappanel.is-dragging { transition: none; }
    .mappanel__grip { display: block; position: sticky; top: 0; z-index: 2; height: 22px; margin-bottom: -22px; background: linear-gradient(#fff 60%, rgba(255,255,255,0)); }
    .mappanel__grip::before { content: ""; position: absolute; left: 50%; top: 8px; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: #d4cfc2; }
    .mappanel__body { padding-top: 22px; }
}
