/* ============================================================
   РАДАР БПЛА — оформление в стиле radar-map.ru
   Тёмная приборная панель + светлая/тёмная/спутник подложка CARTO
   ============================================================ */

:root {
    --bg:            #0d1117;
    --panel:         #161b22;
    --text:          #e6edf3;
    --muted:         #8b949e;
    --accent:        #58a6ff;
    --ok:            #3fb950;
    --warn:          #e6b800;
    --danger:        #f85149;
    --bpla:          #ffb020;
    --bar-border:    #30363d;
    --control-bg:    #0d1117;
    --surface-elev:  #21262d;

    --shadow-pop:    0 8px 24px rgba(0, 0, 0, 0.35);
    --ease-out:      cubic-bezier(0.22, 1, 0.36, 1);
    --ease-spring:   cubic-bezier(0.34, 1.45, 0.64, 1);
    --dur-fast:      0.2s;
    --dur-med:       0.32s;

    --bar-h:         3.4rem;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    font-family: "JetBrains Mono", "Fira Code", ui-monospace, "Cascadia Code", Consolas, monospace;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

body {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

::selection { background: rgba(88,166,255,.35); }

/* ============================================================
   ВЕРХНЯЯ ПАНЕЛЬ
   ============================================================ */
.top-chrome { flex: 0 0 auto; }

.bar {
    position: relative;
    z-index: 1100;
    display: flex;
    align-items: center;
    gap: 0.5rem 1.1rem;
    padding: 0.5rem 0.9rem;
    background: var(--panel);
    border-bottom: 1px solid var(--bar-border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}
.brand__logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem; height: 2rem;
    border-radius: 8px;
    background: rgba(88,166,255,.12);
    border: 1px solid rgba(88,166,255,.35);
    color: var(--accent);
    flex-shrink: 0;
}
.brand__text { min-width: 0; }
.title {
    margin: 0;
    font-size: .95rem;
    font-weight: 700;
    letter-spacing: .04em;
    line-height: 1.1;
    color: var(--text);
}
.sub {
    margin: 0;
    font-size: .68rem;
    color: var(--muted);
    line-height: 1.2;
}

.bar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
}

/* Кнопки-иконки */
.bar-tools {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.bar-tools__btn {
    appearance: none;
    width: 2rem; height: 2rem;
    border-radius: 8px;
    border: 1px solid var(--bar-border);
    background: var(--control-bg);
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font: inherit;
    transition: background var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out),
                transform var(--dur-fast) var(--ease-spring);
}
.bar-tools__btn:hover {
    color: var(--accent);
    border-color: rgba(88,166,255,.55);
    transform: scale(1.06);
}
.bar-tools__btn:active { transform: scale(.94); }
.bar-tools__btn.is-active {
    color: var(--accent);
    border-color: rgba(88,166,255,.55);
    background: rgba(88,166,255,.14);
}

/* Stroke-иконки */
.ui-ico {
    display: block;
    width: 18px; height: 18px;
    flex-shrink: 0;
    color: inherit;
    pointer-events: none;
}
.ui-ico path, .ui-ico polyline, .ui-ico line, .ui-ico polygon, .ui-ico rect {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.ui-ico circle[fill="currentColor"] { fill: currentColor; stroke: none; }

/* Бейдж соединения */
.conn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.65rem;
    padding: .18rem .45rem;
    font-size: .64rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    border: 1px solid var(--bar-border);
    border-radius: 6px;
    color: var(--muted);
    background: var(--control-bg);
}
.conn--ok, .conn--live {
    color: var(--ok);
    border-color: rgba(63,185,80,.4);
    background: rgba(63,185,80,.1);
}
.conn--live::before {
    content: "";
    width: 7px; height: 7px;
    border-radius: 999px;
    margin-right: .4rem;
    background: var(--ok);
    animation: livePulse 1.6s var(--ease-out) infinite;
}
.conn--wait { color: var(--warn); border-color: rgba(230,184,0,.4); background: rgba(230,184,0,.1); }
.conn--err  { color: var(--danger); border-color: rgba(248,81,73,.4); background: rgba(248,81,73,.1); }

@keyframes livePulse {
    0%,100% { opacity:.35; transform: scale(.85); box-shadow: 0 0 0 0 rgba(63,185,80,.4); }
    50%     { opacity:1;   transform: scale(1.1); box-shadow: 0 0 0 5px rgba(63,185,80,0); }
}

/* ============================================================
   ПОПАПЫ (легенда, слои, поиск)
   ============================================================ */
.legend-pop,
.map-prefs__pop,
.bar-tools__search-panel {
    position: absolute;
    z-index: 1200;
    background: var(--surface-elev);
    border: 1px solid var(--bar-border);
    border-radius: 10px;
    box-shadow: var(--shadow-pop);
    color: var(--text);
}
.legend-pop,
.map-prefs__pop { animation: uiPopIn var(--dur-med) var(--ease-spring); }
[hidden] { display: none !important; }

@keyframes uiPopIn {
    from { opacity: 0; transform: translateY(-6px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Легенда */
.legend-pop {
    top: calc(100% + .4rem);
    right: 0;
    width: min(340px, calc(100vw - 1.2rem));
    max-height: min(72vh, calc(100vh - 5rem));
    overflow-y: auto;
    padding: .75rem .85rem;
    font-size: .74rem;
    line-height: 1.4;
}
.legend-pop__title { margin: 0 0 .5rem; font-size: .8rem; font-weight: 700; }
.legend-pop__section + .legend-pop__section { margin-top: .6rem; }
.legend-pop__h {
    margin: 0 0 .3rem;
    font-size: .66rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
}
.legend-pop__list { list-style: none; margin: 0; padding: 0; }
.legend-pop__list li {
    display: flex; align-items: center; gap: .55rem;
    padding: .18rem 0;
}
.legend-pop__list li > span:last-child { flex: 1 1 auto; }
.legend-swatch {
    flex: 0 0 auto;
    width: 1.1rem; height: 1.1rem;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,.18);
}
.sw-bpla   { background: rgba(255,176,32,.30); }
.sw-rocket { background: rgba(248,81,73,.32); }
.sw-fire   { background: rgba(255,80,30,.42); }
.legend-icon {
    flex: 0 0 auto;
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.7rem; height: 1.7rem;
    padding: .18rem;
    background: #eef2f6;
    border: 1px solid #cdd5dd;
    border-radius: 5px;
}
.legend-icon__img { max-width: 100%; max-height: 100%; object-fit: contain; }
.legend-icon__img--dim { opacity: .5; }
.legend-pop__hint {
    margin: .6rem 0 0;
    padding-top: .45rem;
    border-top: 1px solid var(--bar-border);
    font-size: .66rem;
    color: var(--muted);
    line-height: 1.45;
}

/* Слои / подложка */
.map-prefs__pop {
    top: calc(100% + .4rem);
    right: 0;
    min-width: 230px;
    max-width: min(280px, calc(100vw - 1rem));
    padding: .6rem .7rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.source-pick {
    display: flex; align-items: center; gap: .5rem;
    font-size: .72rem; color: var(--muted);
}
.source-pick__label { min-width: 3.2rem; }
.source-pick__select {
    flex: 1;
    font: inherit;
    font-size: .74rem;
    color: var(--text);
    background: var(--control-bg);
    border: 1px solid var(--bar-border);
    border-radius: 6px;
    padding: .28rem .4rem;
    cursor: pointer;
}
.source-pick__select:focus-visible { outline: 2px solid rgba(88,166,255,.5); outline-offset: 1px; }

.layer-toggle {
    display: flex; align-items: center; gap: .5rem;
    font-size: .74rem; color: var(--text);
    cursor: pointer; user-select: none;
}
.layer-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.layer-toggle__box {
    flex: 0 0 auto;
    width: 1.15rem; height: 1.15rem;
    border-radius: 5px;
    border: 1px solid var(--bar-border);
    background: var(--control-bg);
    position: relative;
    transition: background var(--dur-fast), border-color var(--dur-fast);
}
.layer-toggle input:checked + .layer-toggle__box {
    background: var(--accent);
    border-color: var(--accent);
}
.layer-toggle input:checked + .layer-toggle__box::after {
    content: "";
    position: absolute;
    left: 4px; top: 1px;
    width: 4px; height: 8px;
    border: solid #0d1117;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Поиск */
.bar-tools__search-wrap { position: relative; }
.bar-tools__search-panel {
    top: calc(100% + .4rem);
    right: 0;
    padding: .35rem;
    width: min(20rem, 80vw);
}
.bar-tools__search {
    width: 100%;
    font: inherit;
    font-size: .76rem;
    color: var(--text);
    background: var(--control-bg);
    border: 1px solid var(--bar-border);
    border-radius: 7px;
    padding: .42rem .55rem;
}
.bar-tools__search:focus {
    outline: none;
    border-color: rgba(88,166,255,.6);
    box-shadow: 0 0 0 2px rgba(88,166,255,.22);
}
.search-results {
    margin-top: .3rem;
    max-height: 320px;
    overflow-y: auto;
}
.search-result-item {
    padding: .42rem .55rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: .74rem;
    display: flex; justify-content: space-between; align-items: center; gap: .5rem;
}
.search-result-item:hover { background: rgba(88,166,255,.12); }
.search-result-item .region-name { color: var(--text); }
.search-result-item .threat-count { color: var(--muted); font-size: .68rem; }
.search-result-item .threat-count.active { color: var(--danger); }
.search-empty { padding: .5rem; color: var(--muted); font-size: .72rem; text-align: center; }

/* ============================================================
   КАРТА
   ============================================================ */
.main { flex: 1 1 auto; min-height: 0; position: relative; }
.map-wrap { position: absolute; inset: 0; }
#map {
    position: absolute;
    inset: 0;
    width: 100%; height: 100%;
    background: #0b0f14;
    z-index: 1;
}

/* Контролы Leaflet под нашу тему */
.leaflet-bar,
.leaflet-control-zoom { border: none !important; box-shadow: 0 2px 10px rgba(0,0,0,.4) !important; }
.leaflet-control-zoom a {
    background: var(--surface-elev) !important;
    color: var(--text) !important;
    border-color: var(--bar-border) !important;
    width: 30px; height: 30px; line-height: 28px;
}
.leaflet-control-zoom a:hover { background: #2d333b !important; color: var(--accent) !important; }
.leaflet-bar a:first-child { border-top-left-radius: 8px !important; border-top-right-radius: 8px !important; }
.leaflet-bar a:last-child  { border-bottom-left-radius: 8px !important; border-bottom-right-radius: 8px !important; }
.leaflet-control-zoom { margin-bottom: 1rem !important; margin-right: 1rem !important; }
.leaflet-container { font-family: inherit; }
.leaflet-control-attribution { display: none !important; }

/* Оверлей «обновление» */
.map-updating {
    position: absolute;
    inset: 0;
    z-index: 900;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(13,17,23,.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    pointer-events: none;
}
.map-updating--visible { display: flex; }
.map-updating__spinner {
    width: 2rem; height: 2rem;
    border: 2px solid rgba(255,255,255,.18);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: spin .85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.map-updating__content { display: flex; flex-direction: column; align-items: center; gap: .8rem; }
.map-updating__text { margin: 0; font-size: .85rem; font-weight: 600; }

/* ============================================================
   ФИД-ОВЕРЛЕЙ
   ============================================================ */
.feed--overlay {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    z-index: 800;
    width: min(340px, 38vw);
    max-width: 380px;
    padding: .6rem .75rem .85rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: rgba(13,17,23,.62);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-left: 1px solid rgba(255,255,255,.07);
    box-shadow: -8px 0 28px rgba(0,0,0,.3);
    transition: transform var(--dur-med) var(--ease-out);
}
.feed--overlay.feed--collapsed { transform: translateX(calc(100% + 4px)); }

.feed-resize-handle { display: none; }

.feed__chrome { flex: 0 0 auto; }
.feed__title {
    margin: 0 0 .35rem;
    font-size: .72rem; font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
}
.feed__meta-row {
    display: flex; align-items: center; gap: .5rem;
    margin-bottom: .55rem;
}
.feed__meta { margin: 0; font-size: .66rem; color: var(--muted); }

/* Статистика */
.stats {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .45rem;
    margin-bottom: .6rem;
}
.stat-box {
    display: flex; align-items: center; gap: .5rem;
    padding: .5rem .55rem;
    border-radius: 8px;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.07);
}
.stat-icon { font-size: 1rem; opacity: .75; flex: 0 0 auto; }
.stat-content { min-width: 0; }
.stat-box .number {
    font-size: 1.25rem; font-weight: 700; line-height: 1;
    font-variant-numeric: tabular-nums;
}
.stat-box .label {
    margin-top: .25rem;
    font-size: .58rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
}
.stat-active   .stat-icon { color: var(--warn); }
.stat-destroyed .stat-icon { color: var(--danger); }
.stat-regions  .stat-icon { color: var(--accent); }
.stat-fires    .stat-icon { color: #ff6a00; }

/* Лента */
.feed__scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: .15rem;
    margin-right: -.15rem;
}
.feed__list { list-style: none; margin: 0; padding: 0; }
.feed__item {
    position: relative;
    padding: .4rem .5rem .4rem .55rem;
    margin-bottom: .4rem;
    border-radius: 7px;
    background: rgba(255,255,255,.04);
    border-left: 3px solid var(--danger);
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease-out);
}
.feed__item:hover { background: rgba(88,166,255,.1); }
.feed__item.destroyed { border-left-color: var(--warn); }
.feed__item.cancelled { border-left-color: var(--ok); opacity: .6; }
.feed__item--flash { animation: feedFlash 14s var(--ease-out) forwards; }
@keyframes feedFlash {
    0%  { background: rgba(88,166,255,.4); }
    80% { background: rgba(88,166,255,.12); }
    100%{ background: rgba(255,255,255,.04); }
}
.feed__time { display: block; font-size: .62rem; color: var(--muted); margin-bottom: .15rem; }
.feed__region { font-size: .72rem; font-weight: 700; color: var(--text); margin-bottom: .15rem; }
.feed__text {
    font-size: .68rem; line-height: 1.4; color: var(--muted);
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
    overflow: hidden;
}
.feed__badges { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .25rem; }
.feed__badge {
    font-size: .56rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .04em;
    padding: .08rem .35rem; border-radius: 999px;
    background: rgba(255,255,255,.08); color: var(--muted);
}
.feed__badge.rocket { background: rgba(248,81,73,.18); color: #ff7b72; }
.feed__badge.bpla   { background: rgba(255,176,32,.16); color: var(--bpla); }
.feed__badge.ok     { background: rgba(63,185,80,.16); color: var(--ok); }

.loading { padding: 1.5rem; text-align: center; color: var(--muted); font-size: .75rem; }

/* ============================================================
   МАРКЕРЫ НА КАРТЕ
   ============================================================ */
.custom-icon { background: transparent; border: none; }
.mk {
    position: relative;
    display: inline-flex;
    align-items: center; justify-content: center;
    width: 38px; height: 38px;
    border-radius: 50%;
    background: rgba(245,248,252,.92);
    border: 2px solid rgba(255,255,255,.85);
    box-shadow: 0 2px 8px rgba(0,0,0,.45);
}
.mk img {
    width: 26px; height: 26px;
    object-fit: contain;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,.3));
}
.mk--active { border-color: var(--bpla); }
.mk--active img { filter: grayscale(100%) brightness(.55) drop-shadow(0 1px 1px rgba(0,0,0,.3)); }
.mk--destroyed { border-color: var(--warn); }
.mk--rocket { border-color: var(--danger); }

.marker-count {
    position: absolute;
    top: -6px; right: -6px;
    min-width: 18px; height: 18px;
    padding: 0 4px;
    display: flex; align-items: center; justify-content: center;
    background: var(--danger);
    color: #fff;
    border: 2px solid #0d1117;
    border-radius: 999px;
    font-size: 10px; font-weight: 700;
}

.explosion-marker { background: transparent !important; border: none !important; pointer-events: none; }

/* Попапы Leaflet */
.leaflet-popup-content-wrapper {
    background: var(--surface-elev) !important;
    color: var(--text) !important;
    border: 1px solid var(--bar-border) !important;
    border-radius: 10px !important;
    box-shadow: var(--shadow-pop) !important;
}
.leaflet-popup-tip { background: var(--surface-elev) !important; border: 1px solid var(--bar-border); }
.leaflet-popup-content { margin: .7rem .85rem !important; font-family: inherit !important; }
.popup-card { min-width: 220px; font-size: .74rem; line-height: 1.45; }
.popup-card h3 {
    margin: 0 0 .5rem; font-size: .9rem; font-weight: 700; color: var(--accent);
    display: flex; align-items: center; gap: .4rem;
}
.popup-row { margin: .25rem 0; color: var(--text); }
.popup-row b { color: var(--muted); font-weight: 600; margin-right: .3rem; }
.popup-status {
    display: inline-block; padding: .05rem .4rem; border-radius: 5px;
    font-size: .64rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.popup-status.active    { background: rgba(230,184,0,.18); color: var(--warn); }
.popup-status.destroyed { background: rgba(248,81,73,.18); color: #ff7b72; }
.popup-status.cancelled { background: rgba(63,185,80,.18); color: var(--ok); }
.popup-text {
    margin-top: .5rem; padding-top: .5rem;
    border-top: 1px solid var(--bar-border);
    font-size: .68rem; color: var(--muted); line-height: 1.45;
}

/* ============================================================
   СКРОЛЛБАРЫ
   ============================================================ */
.feed__scroll::-webkit-scrollbar,
.search-results::-webkit-scrollbar,
.legend-pop::-webkit-scrollbar { width: 6px; }
.feed__scroll::-webkit-scrollbar-thumb,
.search-results::-webkit-scrollbar-thumb,
.legend-pop::-webkit-scrollbar-thumb { background: #30363d; border-radius: 3px; }
.feed__scroll::-webkit-scrollbar-thumb:hover { background: #484f58; }
.feed__scroll::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   АДАПТИВ
   ============================================================ */
@media (max-width: 760px) {
    :root { --bar-h: auto; }
    .bar { flex-wrap: wrap; gap: .4rem .6rem; padding: .5rem .6rem; }
    .brand__text .sub { display: none; }
    .title { font-size: .82rem; }
    .brand__logo { width: 1.7rem; height: 1.7rem; }
    .bar-tools__btn { width: 1.8rem; height: 1.8rem; }
    .ui-ico { width: 16px; height: 16px; }
    #connBadge { display: none; }

    .legend-pop, .map-prefs__pop, .bar-tools__search-panel {
        position: fixed;
        top: auto;
        left: .5rem; right: .5rem;
        width: auto; max-width: none;
    }
    .legend-pop { top: 4.2rem; max-height: 70vh; }
    .map-prefs__pop { bottom: auto; top: 4.2rem; }
    .bar-tools__search-panel { top: 4.2rem; }

    /* Фид — нижний шит */
    .feed--overlay {
        top: auto; left: 0; right: 0; bottom: 0;
        width: 100%; max-width: none;
        height: var(--feed-h, 42vh);
        max-height: 78vh;
        border-left: none;
        border-top: 1px solid rgba(255,255,255,.08);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -8px 28px rgba(0,0,0,.4);
    }
    .feed--overlay.feed--collapsed { transform: translateY(calc(100% + 4px)); }
    .feed-resize-handle {
        display: block;
        padding: .25rem 0 .35rem;
        cursor: ns-resize;
        touch-action: none;
    }
    .feed-resize-handle__pill {
        display: block;
        width: 42px; height: 5px;
        margin: 0 auto;
        border-radius: 999px;
        background: rgba(139,148,158,.6);
    }
    .feed-resize-handle:active .feed-resize-handle__pill { background: var(--accent); }

    .stats { grid-template-columns: 1fr 1fr; }
    .stat-box .number { font-size: 1.05rem; }
    .feed__list { padding-bottom: 1rem; }
}

@media (max-width: 380px) {
    .stats { grid-template-columns: 1fr; }
    .bar { padding: .45rem .5rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
@media (max-width: 768px) {
    .feed {
        transform: translateY(100%); /* Скрыт по умолчанию */
        transition: transform 0.3s ease;
    }
    
    .feed.feed--open {
        transform: translateY(0); /* Показан */
    }
	
}
