/* ═══════════════════════════════════════════════════════════════
   КАРТА ГИС — полный CSS
   ═══════════════════════════════════════════════════════════════ */

/* ─────────────── ПЕРЕМЕННЫЕ ─────────────── */
.gismap-wrapper {
    --hydro-accent: #d32f2f;
    --hydro-accent-hover: #b71c1c;
    --hydro-border: #e6e6e6;
    --hydro-border-soft: #f0f0f0;
    --hydro-text: #1a1a1a;
    --hydro-text-muted: #888;
    --hydro-text-dim: #999;
    --hydro-bg: #fff;
    --hydro-radius: 4px;
    --hydro-font-sm: 11px;
    --hydro-font-base: 12.5px;
    --hydro-font-title: 13.5px;
    --hydro-content-height: min(260px, 40vh);
}

/* ─────────────── КОНТЕЙНЕР ─────────────── */
.gismap-wrapper .card-body {
    padding: 0.45rem;
}

.gismap-wrapper #gismap {
    width: 100%;
    height: 75vh;
    min-height: 300px;
    position: relative;
    z-index: 0;
}

.gismap-wrapper .leaflet-control-attribution {
    display: none;
}

/* GPU-ускорение только для маркеров этой карты */
.gismap-wrapper .leaflet-marker-icon {
    will-change: transform;
}

/* ─────────────── КНОПКИ ЗУМА ─────────────── */
.gismap-wrapper .leaflet-control-zoom {
    border: none;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    overflow: hidden;
}

.gismap-wrapper .leaflet-control-zoom a {
    width: 30px;
    height: 30px;
    line-height: 30px;
    font-size: 18px;
    color: #333;
    background: #fff;
    border-bottom: 1px solid #eee;
}

.gismap-wrapper .leaflet-control-zoom a:last-child {
    border-bottom: none;
}

.gismap-wrapper .leaflet-control-zoom a:hover {
    background: #f5f5f5;
    color: #d32f2f;
}

/* ─────────────── ПОПАП ─────────────── */
.hydro-popup {
    font-family: inherit;
    max-width: 100%;
    overflow-wrap: break-word;
}

.hydro-popup-header {
    padding-bottom: 10px;
    border-bottom: 1px solid var(--hydro-border);
    margin-bottom: 10px;
}

.hydro-popup-title {
    font-size: var(--hydro-font-title);
    font-weight: 600;
    color: #111;
    line-height: 1.35;
}

.hydro-popup-subtitle {
    font-size: var(--hydro-font-sm);
    color: var(--hydro-text-muted);
    margin-top: 2px;
}

.hydro-popup-coords {
    font-size: var(--hydro-font-sm);
    color: var(--hydro-text-dim);
    margin-top: 3px;
    letter-spacing: 0.2px;
}

.hydro-popup-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 12px;
    max-width: 100%;
}

.hydro-btn {
    padding: 4px 9px;
    font-size: var(--hydro-font-sm);
    line-height: 1.3;
    border: 1px solid #d0d0d0;
    border-radius: var(--hydro-radius);
    background: var(--hydro-bg);
    color: #333;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
    max-width: 100%;
}

.hydro-btn:hover {
    border-color: var(--hydro-accent);
    color: var(--hydro-accent);
}

.hydro-btn.active {
    background: var(--hydro-accent);
    color: #fff;
    border-color: var(--hydro-accent);
}

.hydro-popup-content {
    height: var(--hydro-content-height);
    position: relative;
    overflow: hidden;
}

.hydro-popup-chart-wrap {
    height: 100%;
    width: 100%;
    position: relative;
}

.hydro-popup-table-wrap {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
}

.hydro-popup-empty {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--hydro-text-dim);
    font-size: var(--hydro-font-base);
    text-align: center;
    padding: 0 16px;
}

.hydro-popup-table-wrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--hydro-font-base);
}

.hydro-popup-table-wrap th {
    position: sticky;
    top: 0;
    background: var(--hydro-bg);
    z-index: 1;
    text-align: left;
    padding: 6px 10px;
    color: var(--hydro-text-muted);
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 1px solid var(--hydro-border);
}

.hydro-popup-table-wrap td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--hydro-border-soft);
    color: #222;
}

.hydro-popup-table-wrap tr:last-child td {
    border-bottom: none;
}

.hydro-status-text {
    font-weight: 600;
    text-shadow:
            -1px -1px 0 rgba(0, 0, 0, 0.6),
            1px -1px 0 rgba(0, 0, 0, 0.6),
            -1px 1px 0 rgba(0, 0, 0, 0.6),
            1px 1px 0 rgba(0, 0, 0, 0.6),
            0 0 3px rgba(0, 0, 0, 0.35);
}

/* ─────────────── СТРЕЛКИ НАПРАВЛЕНИЙ ─────────────── */
.direction-arrow-wrap {
    background: transparent;
    border: none;
    pointer-events: none;
}

.direction-arrow {
    display: block;
    overflow: visible;
    transform-origin: 50% 50%;
    color: #144dc6;
}

/* ─────────────── ЛЕГЕНДА ─────────────── */
.map-legend {
    position: relative;
}

.map-legend-content {
    background: #fff;
    padding: 10px 12px;
    border-radius: 6px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
    font-size: 12px;
    line-height: 1.4;
    min-width: 200px;
}

.map-legend-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border-bottom: 1px solid #eee;
    padding-bottom: 6px;
    margin-bottom: 8px;
}

.map-legend-title {
    font-size: 12.5px;
    font-weight: 600;
    color: #111;
    margin: 0;
    padding: 0;
    border: none;
    line-height: 1.3;
}

.map-legend-section {
    font-size: 10.5px;
    color: #888;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    margin-top: 10px;
    margin-bottom: 6px;
}

.map-legend-section:first-of-type {
    margin-top: 0;
}

.map-legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.map-legend-label {
    color: #333;
}

.map-legend-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
    flex-shrink: 0;
}

.map-legend-diamond {
    display: inline-block;
    width: 11px;
    height: 11px;
    background: #d32f2f;
    transform: rotate(45deg);
    border-radius: 1px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.map-legend-arrow-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* ─────────────── КНОПКИ ЛЕГЕНДЫ ─────────────── */
.map-legend-toggle,
.map-legend-close {
    display: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    flex-shrink: 0;
    padding: 0;
    font-weight: 400;
    text-align: center;
}

.map-legend-toggle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
    color: #d32f2f;
    font-size: 17px;
    font-weight: 700;
    font-style: italic;
    line-height: 32px;
}

.map-legend-close {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #f0f0f0;
    color: #666;
    font-size: 18px;
    line-height: 24px;
}

.map-legend-close:hover {
    background: #e0e0e0;
    color: #d32f2f;
}

.map-legend.collapsed .map-legend-content {
    display: none;
}

.map-legend.collapsed .map-legend-toggle {
    display: block;
}

.map-legend:not(.collapsed) .map-legend-close {
    display: block;
}

/* ─────────────── ПЕРЕКЛЮЧАТЕЛЬ СЛОЁВ ─────────────── */
.gismap-wrapper .leaflet-control-layers {
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
    border: none;
    font-family: inherit;
    color: #333;
}

.gismap-wrapper .leaflet-control-layers-toggle {
    width: 36px;
    height: 36px;
    background-size: 22px 22px;
    background-position: center center;
    background-repeat: no-repeat;
    border-radius: 6px;
}

.gismap-wrapper .leaflet-control-layers-expanded {
    padding: 10px 12px;
    min-width: 190px;
    font-size: 12px;
    line-height: 1.4;
}

.gismap-wrapper .leaflet-control-layers-expanded .leaflet-control-layers-toggle {
    display: none;
}

.gismap-wrapper .leaflet-control-layers label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 4px 0;
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    color: #333;
    transition: background 0.15s;
}

.gismap-wrapper .leaflet-control-layers label:hover {
    background: #f5f5f5;
}

.gismap-wrapper .leaflet-control-layers label:last-child {
    margin-bottom: 0;
}

.gismap-wrapper .leaflet-control-layers-selector {
    margin: 0;
    cursor: pointer;
    accent-color: #d32f2f;
}

.gismap-wrapper .leaflet-control-layers-separator {
    margin: 8px 0;
    border-top: 1px solid #e6e6e6;
}

/* ═══════════════════════════════════════════════════════════════
   МОБИЛЬНАЯ АДАПТАЦИЯ
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 576px) {
    .gismap-wrapper #gismap {
        height: 65vh;
        min-height: 250px;
    }

    .gismap-wrapper .card-body {
        padding: 0;
    }

    .col-lg-12 {
        padding: unset !important;
    }

    /* ── КНОПКИ ЗУМА: 26×26 ── */
    .gismap-wrapper .leaflet-control-zoom a {
        width: 26px !important;
        height: 26px !important;
        line-height: 26px !important;
        font-size: 16px !important;
    }

    /* ── КНОПКА СЛОЁВ: 26×26 ── */
    .gismap-wrapper .leaflet-control-layers-toggle {
        width: 26px !important;
        height: 26px !important;
        background-size: 16px 16px !important;
    }

    /* ── ОТСТУПЫ КОНТРОЛОВ ОТ КРАЁВ ── */
    .gismap-wrapper .leaflet-top.leaflet-left {
        top: 4px !important;
        left: 4px !important;
    }

    .gismap-wrapper .leaflet-top.leaflet-right {
        top: 4px !important;
        right: 4px !important;
    }

    .gismap-wrapper .leaflet-bottom.leaflet-right {
        bottom: 4px !important;
        right: 4px !important;
    }

    /* ── ПАНЕЛЬ СЛОЁВ (раскрытая) ── */
    .gismap-wrapper .leaflet-control-layers-expanded {
        padding: 8px 10px;
        min-width: 160px;
        font-size: 11px;
    }

    .gismap-wrapper .leaflet-control-layers label {
        padding: 4px 6px;
        margin-bottom: 3px;
    }

    /* ── ЛЕГЕНДА ── */
    .map-legend-content {
        min-width: 0;
        width: min(220px, calc(100vw - 70px));
        font-size: 10.5px;
        padding: 8px 10px 10px;
        line-height: 1.35;
    }

    .map-legend-head {
        padding-bottom: 5px;
        margin-bottom: 6px;
        gap: 6px;
    }

    .map-legend-title {
        font-size: 11.5px;
    }

    .map-legend-section {
        font-size: 9.5px;
        margin-top: 7px;
        margin-bottom: 4px;
        letter-spacing: 0.3px;
    }

    .map-legend-row {
        margin-bottom: 2px;
        gap: 6px;
    }

    .map-legend-dot {
        width: 10px;
        height: 10px;
        border-width: 1.5px;
    }

    .map-legend-diamond {
        width: 9px;
        height: 9px;
    }

    .map-legend-toggle {
        width: 28px !important;
        height: 28px !important;
        font-size: 15px !important;
        line-height: 28px !important;
    }

    .map-legend-close {
        width: 22px !important;
        height: 22px !important;
        font-size: 16px !important;
        line-height: 22px !important;
    }

    .gismap-wrapper .leaflet-popup-content-wrapper {
        border-radius: 8px;
        max-width: calc(100vw - 24px);
    }

    .gismap-wrapper .leaflet-popup-content {
        margin: 8px 12px 8px 10px;
        padding-right: 16px;              /* уводим контент из-под крестика */
        max-height: 50vh;
        overflow-y: scroll;               /* трек резервируется всегда */
        overflow-x: hidden;
        font-size: 11px;
        overflow-wrap: break-word;
        scrollbar-width: thin;            /* Firefox */
        scrollbar-color: #d32f2f #ececec; /* Firefox */
    }

    /* Кастомный скролл-бар (Chrome / Safari / Edge / iOS) — виден всегда */
    .gismap-wrapper .leaflet-popup-content::-webkit-scrollbar {
        width: 8px;
        -webkit-appearance: none;
    }

    .gismap-wrapper .leaflet-popup-content::-webkit-scrollbar-track {
        background: #ececec;
        border-radius: 4px;
        /* Трек стартует ниже крестика (4 + 22 = 26px) */
        margin: 28px 0 4px 0;
    }

    .gismap-wrapper .leaflet-popup-content::-webkit-scrollbar-thumb {
        background: #d32f2f;
        border-radius: 4px;
        border: 1px solid #ececec;
        min-height: 32px;
    }

    .gismap-wrapper .leaflet-popup-content::-webkit-scrollbar-thumb:active {
        background: #b71c1c;
    }

    /* Крестик — X рисуется геометрически, не зависит от метрик шрифта.
     Так центр X совпадает с центром круга на Android, iOS и десктопе. */
    .gismap-wrapper .leaflet-popup-close-button {
        width: 22px !important;
        height: 22px !important;
        padding: 0 !important;
        top: 4px !important;
        right: 4px !important;
        background: #fff !important;
        border-radius: 50%;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
        z-index: 10;
        color: transparent !important;   /* прячем текстовый «×» */
        font-size: 0 !important;         /* и его метрики */
        line-height: 0 !important;
    }

    .gismap-wrapper .leaflet-popup-close-button::before,
    .gismap-wrapper .leaflet-popup-close-button::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 11px;
        height: 1.6px;
        background: #666;
        border-radius: 1px;
        transition: background 0.15s;
    }

    .gismap-wrapper .leaflet-popup-close-button::before {
        transform: translate(-50%, -50%) rotate(45deg);
    }

    .gismap-wrapper .leaflet-popup-close-button::after {
        transform: translate(-50%, -50%) rotate(-45deg);
    }

    .gismap-wrapper .leaflet-popup-close-button:hover::before,
    .gismap-wrapper .leaflet-popup-close-button:hover::after {
        background: #d32f2f;
    }

    /* ── ГИДРОХИМИЯ ── */
    .gismap-wrapper {
        --hydro-content-height: min(170px, 30vh);
        --hydro-font-title: 12px;
        --hydro-font-base: 11px;
        --hydro-font-sm: 10px;
    }

    .hydro-popup-header {
        padding-bottom: 6px;
        margin-bottom: 8px;
    }

    .hydro-popup-coords {
        font-size: 9.5px;
        margin-top: 2px;
    }

    .hydro-popup-subtitle {
        font-size: 10px;
    }

    .hydro-popup-buttons {
        gap: 3px;
        margin-bottom: 8px;
    }

    .hydro-btn {
        padding: 3px 7px;
        font-size: 10px;
        white-space: normal;
        word-break: break-word;
        text-align: left;
        line-height: 1.25;
    }

    .hydro-popup-table-wrap th {
        padding: 4px 7px;
        font-size: 9.5px;
    }

    .hydro-popup-table-wrap td {
        padding: 5px 7px;
        font-size: 11px;
    }

    .hydro-popup-empty {
        font-size: 11px;
        padding: 0 12px;
    }
}