/* ═══ Карта мира /map — стили контейнера, контролов, попапа, шторки ═══
   Цвета карты — токены --map-* из main.css (тёмная/светлая тема автоматически). */

#cwMap {
    position: relative;
    width: 100%;
    margin: 0 auto;
    height: calc(100dvh - var(--header-h, 56px) - 128px);
    min-height: 380px;
    overflow: hidden;
    background: var(--map-water, #0d1117);
    touch-action: none;           /* пинч/драг не скроллят страницу */
    overscroll-behavior: contain;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}
/* Во всю ширину экрана (без боковых полей и рамок) */
@media (min-width: 768px) {
    #cwMap { border-radius: 0; border-left: 0; border-right: 0; }
}
@media (max-width: 767px) {
    #cwMap { border-radius: 0; border-left: 0; border-right: 0; height: calc(100dvh - var(--header-h, 56px) - 144px); }
}

#cwMap.cw-map-dragging { cursor: grabbing; }

/* сцена (мир) и канвас (точки) */
/* тайлы CARTO (Web Mercator): каждый позиционируется сам (left/top/width/height),
   поэтому старый зумовый набор корректно виден во время кроссфейда */
#cwTiles {
    position: absolute;
    inset: 0;
    overflow: hidden;
    opacity: 0;
    transition: opacity .45s;
    background: var(--map-water, #0d1117);
    z-index: 0;
}
#cwTiles .cw-tile {
    position: absolute;
    opacity: 0;
    transition: opacity .25s;
    user-select: none;
    pointer-events: none;
}
#cwTiles .cw-tile.loaded { opacity: 1; }
#cwTiles .cw-tile-old { opacity: 0 !important; transition: opacity .4s; }
#cwMapCanvas { position: absolute; inset: 0; pointer-events: none; z-index: 1; }

/* атрибуция CARTO/OSM (требование лицензии тайлов) */
.cw-map-attr {
    position: absolute;
    right: 6px;
    bottom: 4px;
    z-index: 6;
    font-size: 10px;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.35);
    border-radius: 6px;
    padding: 2px 7px;
}
body.light-theme .cw-map-attr { background: rgba(255, 255, 255, 0.55); }
.cw-map-attr a { color: inherit; text-decoration: none; }
.cw-map-attr a:hover { text-decoration: underline; }

/* скелет-загрузчик (фикс. высота = нет CLS) */
.cw-map-skeleton {
    position: absolute; inset: 0; z-index: 4;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
    color: var(--text-secondary); font-size: 13px; font-weight: 600;
    background: var(--map-water, #0d1117);
    transition: opacity .3s;
}
.cw-map-skeleton.done { opacity: 0; pointer-events: none; }
.cw-map-skeleton-globe {
    width: 44px; height: 44px; border-radius: 50%;
    border: 3px solid var(--map-border, #33415c);
    border-top-color: var(--map-dot, #FF486A);
    animation: cw-map-spin 1s linear infinite;
}
@keyframes cw-map-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .cw-map-skeleton-globe { animation: none; } }

/* зум-кнопки */
.cw-map-ctrl {
    position: absolute; right: 10px; top: 10px; z-index: 8;
    display: flex; flex-direction: column; gap: 5px;
}
.cw-map-ctrl button {
    width: 34px; height: 34px; border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 18px; font-weight: 700; line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.cw-map-ctrl button:hover { border-color: var(--accent-pink); }
.cw-map-ctrl button:focus-visible { outline: 2px solid var(--accent-pink); outline-offset: 2px; }

/* FAB «рядом со мной» */
.cw-map-fab {
    position: absolute; left: 10px; bottom: 12px; z-index: 8;
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 14px; border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 13px; font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
.cw-map-fab:hover { border-color: var(--accent-green); color: var(--accent-green); }
.cw-map-fab:focus-visible { outline: 2px solid var(--accent-green); outline-offset: 2px; }
@media (max-width: 767px) { .cw-map-fab span { display: none; } .cw-map-fab { padding: 11px; } }

/* попап стрима (десктоп) */
.cw-map-popup {
    position: absolute; z-index: 10;
    width: 240px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 8px 28px rgba(0,0,0,.45);
    padding: 8px;
}
.cw-map-popup[hidden] { display: none; }
.cw-map-popup-close {
    position: absolute; right: 6px; top: 6px; z-index: 2;
    width: 24px; height: 24px; border-radius: 8px;
    border: none; background: rgba(0,0,0,.45); color: #fff;
    font-size: 15px; line-height: 1; cursor: pointer;
}
body.light-theme .cw-map-popup-close { background: rgba(0,0,0,.25); }

/* карточка стрима (и в попапе, и в шторке) */
.cw-map-card { display: flex; flex-direction: column; gap: 6px; }
.cw-map-card-img {
    width: 100%; height: 132px; object-fit: cover;
    border-radius: 9px; background: var(--bg-secondary); display: block;
}
.cw-map-card-ph { background: linear-gradient(135deg, var(--bg-secondary), var(--bg-card)); }
.cw-map-card-t {
    font-size: 13px; font-weight: 700; color: var(--text-primary);
    line-height: 1.3; max-height: 2.6em; overflow: hidden;
}
.cw-map-card-c { font-size: 12px; color: var(--text-secondary); }
.cw-map-card-link {
    display: block; text-align: center;
    padding: 8px 10px; border-radius: 9px;
    background: var(--accent-pink); color: #fff;
    font-size: 13px; font-weight: 700; text-decoration: none;
}
.cw-map-card-link:hover { filter: brightness(1.08); }

/* список камер кластера (попап на десктопе) */
.cw-map-popup.listmode { width: min(360px, 92vw); }
.cw-map-list-head { font-size: 14px; font-weight: 800; color: var(--text-primary); padding: 2px 28px 10px 2px; }
.cw-map-list { display: flex; flex-direction: column; gap: 2px; max-height: min(52vh, 440px); overflow-y: auto; scrollbar-width: thin; }
.cw-map-list .cw-map-mini { display: flex; flex-direction: row; align-items: center; gap: 10px; padding: 6px; border-radius: 10px; text-decoration: none; }
.cw-map-list .cw-map-mini:hover { background: var(--bg-secondary); }
.cw-map-list .cw-map-mini img { width: 104px; height: 58px; border-radius: 8px; flex: 0 0 104px; object-fit: cover; background: var(--bg-secondary); display: block; }
.cw-map-list .cw-map-mini-t { font-size: 12.5px; font-weight: 600; color: var(--text-primary); line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* шторка (мобайл) */
.cw-map-sheet {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 12;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(0,0,0,.4);
    padding: 8px 10px 12px;
    max-height: 55%;
    overflow-y: auto;
}
.cw-map-sheet[hidden] { display: none; }
/* десктоп: горизонтальная полоса внизу карты, только горизонтальный скролл */
@media (min-width: 768px) {
    .cw-map-sheet { left: 0; right: 0; width: 100%; border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; max-height: none; }
    .cw-map-sheet-list { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; max-height: none; padding-bottom: 4px; }
    .cw-map-sheet-list .cw-map-mini { flex: 0 0 152px; }
    .cw-map-sheet-list .cw-map-mini img { width: 152px; height: 86px; }
}
.cw-map-sheet-head {
    display: flex; align-items: center; justify-content: space-between;
    font-size: 12px; font-weight: 700; color: var(--text-secondary);
    padding: 2px 2px 8px;
}
.cw-map-sheet-close {
    width: 26px; height: 26px; border-radius: 8px;
    border: 1px solid var(--border); background: transparent;
    color: var(--text-primary); font-size: 15px; line-height: 1; cursor: pointer;
}
.cw-map-sheet-list {
    display: flex; gap: 8px; overflow-x: auto;
    padding-bottom: 10px;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
/* красивый скроллбар под тему (токены сами меняются со светлой/тёмной) */
.cw-map-sheet-list::-webkit-scrollbar { height: 8px; }
.cw-map-sheet-list::-webkit-scrollbar-track { background: var(--bg-secondary); border-radius: 999px; }
.cw-map-sheet-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; border: 2px solid var(--bg-secondary); }
.cw-map-sheet-list::-webkit-scrollbar-thumb:hover { background: var(--accent-pink); border-color: var(--bg-secondary); }
.cw-map-mini {
    flex: 0 0 128px; display: flex; flex-direction: column; gap: 4px;
    text-decoration: none;
}
.cw-map-mini img {
    width: 128px; height: 72px; object-fit: cover; border-radius: 8px;
    background: var(--bg-secondary); display: block;
}
.cw-map-mini-t {
    font-size: 11px; font-weight: 600; color: var(--text-primary);
    line-height: 1.25; max-height: 2.5em; overflow: hidden;
}
.cw-map-card-main { border-top: 1px solid var(--border); padding-top: 8px; }

/* тост */
.cw-map-toast {
    position: absolute; left: 50%; bottom: 64px; transform: translateX(-50%);
    z-index: 14; max-width: 88%;
    background: var(--bg-card); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: 10px;
    padding: 9px 14px; font-size: 13px; font-weight: 600;
    box-shadow: 0 4px 16px rgba(0,0,0,.35);
}
.cw-map-toast[hidden] { display: none; }
