/* ================================================================
   OSM — интерактивная карта + легенда
   Используется: главная (fragments/map.html), отчёт (report-renderer.js)

   Раскладка:
   - < 992px: карта сверху, легенда под ней (flex-column)
   - ≥ 992px: карта слева, легенда справа (grid)
   ================================================================ */

/* ─── Обёртка ─────────────────────────────────────────────────── */
.osm-interactive {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.osm-interactive__map {
    width: 100%;
    height: 420px;
    background: #f0f2f5;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    overflow: hidden;
}

/* На узких экранах карта квадратная */
@media (max-width: 575.98px) {
    .osm-interactive__map {
        height: auto;
        aspect-ratio: 1 / 1;
    }
}

/* ─── Заглушка ────────────────────────────────────────────────── */
.osm-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 40px 20px;
    color: var(--text-secondary);
    background: #f0f2f5;
    border-radius: 12px;
    font-size: 0.9rem;
}
.osm-empty i {
    font-size: 1.8rem;
    opacity: 0.5;
}

/* ─── Маркеры ─────────────────────────────────────────────────── */
.osm-object-marker__pin {
    width: 22px;
    height: 22px;
    background: #00b894;
    border: 3px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    box-sizing: border-box;
}
.osm-poi-marker__dot {
    width: 14px;
    height: 14px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    box-sizing: border-box;
}

/* ─── Легенда ─────────────────────────────────────────────────── */
.osm-legend {
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    padding: 10px 12px;
}

.osm-legend__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.osm-legend__title {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.osm-legend__title i { color: var(--accent-emerald, #00b894); }

.osm-legend__toggle-all {
    font-size: 0.78rem;
    text-decoration: none;
    padding: 0;
    color: var(--accent-emerald, #00b894) !important;
    border: none;
    background: transparent;
    cursor: pointer;
}
.osm-legend__toggle-all:hover {
    text-decoration: underline;
    color: var(--accent-emerald-dark, #008f6f) !important;
}

/* Каждый элемент легенды — на своей строке */
.osm-legend__grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.osm-legend__item {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-primary);
    user-select: none;
    padding: 4px 0;
    width: 100%;
}
.osm-legend__item input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    accent-color: var(--accent-emerald, #00b894);
}
.osm-legend__item i { font-size: 0.9rem; }
.osm-legend__label { line-height: 1.2; }

.osm-legend__count {
    margin-left: auto;        /* счётчик — к правому краю */
    font-size: 0.72rem;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 6px;
    border-radius: 8px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

.osm-legend__footer {
    margin-top: 8px;
    display: flex;
    justify-content: flex-end;
}
.osm-legend__reset {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: transparent;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 8px;
    padding: 4px 10px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}
.osm-legend__reset:hover {
    border-color: var(--accent-emerald, #00b894);
    color: var(--accent-emerald, #00b894);
}

/* ─── Примечание внизу легенды ───────────────────────────────── */
.osm-note {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);

    font-size: 0.75rem;
    line-height: 1.45;
    color: var(--text-muted);
}
.osm-note i {
    color: var(--accent-emerald, #00b894);
    font-size: 0.85rem;
    vertical-align: -1px;
}

/* ─── Список ближайших ─────────────────────────────────────────
   В osm-map.js SHOW_NEARBY = false — элемент не рендерится.
   Стили оставлены на случай возврата функционала.
   ──────────────────────────────────────────────────────────── */
.osm-nearby {
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    overflow: hidden;
}
.osm-nearby__head {
    padding: 8px 12px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.03);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    gap: 6px;
}
.osm-nearby__head i { color: var(--accent-emerald, #00b894); }
.osm-nearby__list { max-height: 280px; overflow-y: auto; }
.osm-nearby__item {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    cursor: pointer;
    transition: background 0.12s ease;
}
.osm-nearby__item:last-child { border-bottom: none; }
.osm-nearby__item:hover { background: rgba(0, 0, 0, 0.03); }
.osm-nearby__icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.85rem;
    flex-shrink: 0;
}
.osm-nearby__body { min-width: 0; }
.osm-nearby__name {
    font-size: 0.86rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.25;
    word-break: break-word;
}
.osm-nearby__meta {
    font-size: 0.76rem;
    color: var(--text-secondary);
    margin-top: 1px;
    line-height: 1.2;
}
.osm-nearby__cat {
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
    background: rgba(0, 0, 0, 0.04);
    padding: 2px 8px;
    border-radius: 8px;
}

/* ─── Popup Leaflet ───────────────────────────────────────────── */
.osm-popup {
    font-size: 0.85rem;
    line-height: 1.35;
    min-width: 180px;
    max-width: 260px;
}
.osm-popup__title {
    font-weight: 600;
    margin-bottom: 4px;
    color: #1a1e2e;
}
.osm-popup__cat {
    font-size: 0.78rem;
    margin-bottom: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.osm-popup__row {
    color: #555;
    margin-top: 3px;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 0.82rem;
}
.osm-popup__row i {
    margin-top: 2px;
    flex-shrink: 0;
    color: #888;
}

/* ─── Секция отчёта: контейнер карты ──────────────────────────── */
.osm-section-body { margin-top: 4px; }
.osm-map-container { margin-bottom: 12px; }

/* ─── Адаптив ─────────────────────────────────────────────────── */
@media (max-width: 575.98px) {
    .osm-legend__item { font-size: 0.78rem; }
    .osm-nearby__item { grid-template-columns: 26px 1fr; gap: 8px; }
    .osm-nearby__cat { display: none; }
}

/* ─── Большие экраны: карта слева, легенда справа ────────────── */
@media (min-width: 992px) {
    .osm-interactive {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 300px;
        grid-template-areas: "map legend";
        grid-template-rows: auto;
        gap: 12px;
        align-items: start;
    }

    .osm-interactive__map {
        grid-area: map;
        height: 520px;
    }

    .osm-interactive > .osm-legend {
        grid-area: legend;
        margin: 0;
        align-self: start;
        max-height: 520px;                /* выровнено с картой */
        overflow-y: auto;
        scrollbar-width: thin;
        scrollbar-color: rgba(0, 0, 0, 0.18) transparent;
    }
    .osm-interactive > .osm-legend::-webkit-scrollbar { width: 4px; }
    .osm-interactive > .osm-legend::-webkit-scrollbar-track { background: transparent; }
    .osm-interactive > .osm-legend::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.18);
        border-radius: 4px;
    }
    .osm-interactive > .osm-legend::-webkit-scrollbar-thumb:hover {
        background: rgba(0, 0, 0, 0.32);
    }
}

/* ─── Очень широкие экраны: легенда чуть шире ────────────────── */
@media (min-width: 1400px) {
    .osm-interactive {
        grid-template-columns: minmax(0, 1fr) 340px;
    }
    .osm-interactive__map {
        height: 560px;
    }
    .osm-interactive > .osm-legend {
        max-height: 560px;
    }
}

/* ─── Тёмная тема ─────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
    .osm-legend,
    .osm-nearby {
        background: rgba(255, 255, 255, 0.04);
        border-color: rgba(255, 255, 255, 0.08);
    }
    .osm-legend__count,
    .osm-nearby__cat {
        background: rgba(255, 255, 255, 0.08);
    }
    .osm-nearby__head {
        background: rgba(255, 255, 255, 0.03);
        border-bottom-color: rgba(255, 255, 255, 0.06);
    }
    .osm-nearby__item {
        border-bottom-color: rgba(255, 255, 255, 0.05);
    }
    .osm-nearby__item:hover {
        background: rgba(255, 255, 255, 0.04);
    }
    .osm-legend__reset {
        border-color: rgba(255, 255, 255, 0.12);
    }
    .osm-note {
        border-top-color: rgba(255, 255, 255, 0.08);
    }
    .osm-popup__title { color: #eaeaea; }
    .osm-popup__row { color: #b8b8b8; }
    .osm-interactive__map,
    .osm-empty {
        background: #2a2e35;
        border-color: rgba(255, 255, 255, 0.08);
    }
}

/* ─── Тёмная тема: скроллбар легенды на больших экранах ──────── */
@media (prefers-color-scheme: dark) and (min-width: 992px) {
    .osm-interactive > .osm-legend {
        scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
    }
    .osm-interactive > .osm-legend::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.18);
    }
    .osm-interactive > .osm-legend::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.32);
    }
}