/* ==========================================================================
   1. BASE & RESET
   ========================================================================== */
   * {
    box-sizing: border-box;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

body, html { 
    height: 100%; 
    width: 100%;
    margin: 0; 
    padding: 0; 
    overflow: hidden; 
    font-family: 'Montserrat', sans-serif;
    background-color: #f5f5f7;
}

/* ==========================================================================
   2. MAP ELEMENTS
   ========================================================================== */
#map { 
    position: absolute;
    top: 0; left: 0; 
    width: 100%; height: 100%; 
    z-index: 0; 
}

.map-logo {
    position: absolute;
    top: 20px;
    left: 20px;
    height: 30px;
    width: auto;
    z-index: 1000;
    pointer-events: none;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

#compass-container {
    position: absolute;
    top: 55%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 50;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    border-radius: 30px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0.9;
}

#compass-container:active {
    transform: translate(-50%, -50%) scale(0.95);
    opacity: 1;
}

#compass-arrow-wrap {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.1s linear; 
}

#compass-icon { filter: drop-shadow(0 2px 2px rgba(0,0,0,0.1)); }
#compass-dist { font-size: 15px; font-weight: 700; color: #333; min-width: 60px; }

/* ==========================================================================
   3. UI COMPONENTS (Shared)
   ========================================================================== */
   .bottom-sheet {
    position: fixed;
    z-index: 100;
    background: #ffffff;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    
    /* ВЕРНУЛИ СКРОЛЛ, ИНАЧЕ ДЛИННЫЙ ТЕКСТ ОБРЕЖЕТСЯ */
    overflow-y: auto; 
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    
    /* НО ВИЗУАЛЬНО СКРЫВАЕМ ПОЛОСУ ПРОКРУТКИ */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}
/* Скрываем полосу в Chrome/Safari */
.bottom-sheet::-webkit-scrollbar {
    display: none;
}

/* Search Layout */
.search-row {
    display: flex;
    gap: 12px;
    width: 100%;
    align-items: center;
    flex-shrink: 0;
}

.search-box-wrapper {
    flex-grow: 1;
    position: relative;
    background: #F2F2F7;
    border-radius: 12px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    height: 48px;
    transition: all 0.2s;
}

.search-icon-img {
    width: 24px; height: 24px;
    flex-shrink: 0;
    margin-right: 8px;
}

.search-input {
    width: 100%;
    background: transparent;
    border: none;
    font-size: 15px;
    font-weight: 500;
    color: #000;
    padding: 0;
    height: 100%;
}
.search-input::placeholder { color: #8E8E93; }

#clearSearchBtn {
    background: none; border: none; padding: 0;
    margin-left: 8px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    width: 24px; height: 24px;
}

/* Filter Button */
.filter-toggle-btn {
    width: 48px; height: 48px;
    border-radius: 12px;
    background: #381DDB;
    border: 2px solid transparent;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.filter-toggle-btn.active-filter {
    background: #FFFFFF;
    border-color: #381DDB;
}

.filter-toggle-btn.active-filter img {
    filter: invert(14%) sepia(94%) saturate(4972%) hue-rotate(244deg) brightness(86%) contrast(100%);
}

/* Categories List */
.categories-wrapper {
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 16px;
    padding-bottom: 5px;
    
    /* СКРЫВАЕМ СКРОЛЛБАР, НО ОСТАВЛЯЕМ СКРОЛЛ */
    overflow-y: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}
.categories-wrapper::-webkit-scrollbar { 
    display: none; /* Chrome/Safari */
}

.cat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background-color: #F9F9FB;
    color: #000;
    border: 1px solid transparent;
    font-size: 13px; font-weight: 600;
    padding: 8px 14px;
    border-radius: 12px;
    flex-grow: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 40px;
}
.cat-btn:hover { background-color: #F2F2F7; }
.cat-btn.active:hover { background-color: #FFFFFF; }

.cat-btn-icon { width: 20px; height: 20px; object-fit: contain; }

/* Favorites Icon Color Logic */
.cat-btn.active[data-slug="favorites"] img {
    filter: invert(14%) sepia(94%) saturate(4972%) hue-rotate(244deg) brightness(86%) contrast(100%);
}

/* Search Results Button */
.search-results-btn {
    background: #FFFFFF;
    color: #381DDB;
    border: 1px solid #381DDB;
    padding: 10px 20px;
    border-radius: 12px;
    font-size: 13px; font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 12px;
    width: 100%;
}
.search-results-btn:active {
    background: #381DDB;
    color: #FFFFFF;
}

/* Cluster List Item */
.cluster-list-item {
    background: #F2F2F7;
    border: none;
    border-radius: 12px;
    padding: 12px 16px;
    text-align: left;
    display: flex; align-items: center;
    width: 100%;
    cursor: pointer;
    transition: background 0.2s;
}
.cluster-list-item:active { background: #E5E5EA; transform: scale(0.98); }
.cluster-item-icon { width: 32px; height: 32px; margin-right: 12px; flex-shrink: 0; }
.cluster-item-info { display: flex; flex-direction: column; overflow: hidden; }
.cluster-item-title { font-weight: 600; font-size: 14px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cluster-item-cat { font-size: 12px; color: #8E8E93; }

/* Detail View Buttons */
.back-link {
    background: none; border: none;
    color: #8E8E93;
    font-size: 14px; font-weight: 600;
    display: flex; align-items: center;
    padding: 0; cursor: pointer;
    font-family: 'Montserrat', sans-serif;
}
.back-link:hover { color: #000; }

.route-btn {
    background-color: #381DDB !important;
    border: none !important;
    border-radius: 14px !important;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
}
.route-btn:active { opacity: 0.9; }

/* Favorite Button (Card) */
.fav-btn {
    background-color: #FFFFFF;
    color: #000;
    border: 2px solid transparent;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.fav-btn img { filter: grayscale(100%) brightness(0); transition: all 0.2s; }

.fav-btn.is-active {
    background-color: #FFFFFF;
    color: #381DDB;
    border-color: #381DDB;
}
.fav-btn.is-active img {
    filter: invert(14%) sepia(94%) saturate(4972%) hue-rotate(244deg) brightness(86%) contrast(100%);
}

@media (hover: hover) {
    .fav-btn:not(.is-active):hover { background-color: #F2F2F7; color: #000; border-color: transparent; }
    .fav-btn.is-active:hover { background-color: #F9F9FB; color: #381DDB; border-color: #381DDB; }
    .fav-btn.is-active:hover img { filter: invert(14%) sepia(94%) saturate(4972%) hue-rotate(244deg) brightness(86%) contrast(100%); }
}

/* Social & Share Buttons */
.social-row { display: flex; gap: 12px; flex-wrap: wrap; }
.social-btn {
    width: 42px; height: 42px;
    border-radius: 12px;
    background: #FFFFFF;
    border: 1px solid #E5E5EA;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}
.social-btn img { width: 22px; height: 22px; opacity: 0.8; transition: all 0.2s; }
.social-btn:hover { border-color: #381DDB; background: #F9F9FB; }
.social-btn:hover img { opacity: 1; filter: invert(14%) sepia(94%) saturate(4972%) hue-rotate(244deg) brightness(86%) contrast(100%); }

.share-btn {
    width: 58px; flex-shrink: 0;
    border-radius: 14px;
    background: #FFFFFF;
    border: 2px solid #E5E5EA;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}
.share-btn img { width: 24px; height: 24px; opacity: 0.8; }
.share-btn:hover { background: #F9F9FB; border-color: #381DDB; }
.share-btn:hover img { opacity: 1; filter: invert(14%) sepia(94%) saturate(4972%) hue-rotate(244deg) brightness(86%) contrast(100%); }
.share-btn:active { transform: scale(0.96); }

/* Toast Notification */
.copy-toast {
    position: fixed;
    bottom: 30px; left: 50%;
    transform: translateX(-50%) translateY(20px);
    background-color: #333;
    color: #fff;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px; font-weight: 500;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 2000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.copy-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ==========================================================================
   4. MOBILE SPECIFIC STYLES (max-width: 767px)
   ========================================================================== */
   @media (max-width: 767px) {
    .bottom-sheet {
        bottom: 0; left: 0; right: 0;
        width: 100%;
        border-radius: 24px 24px 0 0;
        max-height: 85vh;
        height: auto !important;
        padding: 16px 16px 12px 16px !important;
        
        transition: none; /* Убираем стандартную анимацию */
        
        /* МАГИЯ ПРОТИВ ИСЧЕЗНОВЕНИЯ: */
        transform: translateZ(0); /* Включает GPU-ускорение */
        -webkit-transform: translateZ(0);
        backface-visibility: hidden; /* Исправляет "промигивание" */
        
        /* Важно: overflow должен быть visible, чтобы не резать тени и контент */
        overflow: visible !important; 
        
        display: flex;
        flex-direction: column;
    }
    
    /* Добавь это ниже, чтобы контент внутри скроллился, а не шторка */
    .offcanvas-body, .categories-wrapper, .cluster-list-container {
        overflow-y: auto;
        overscroll-behavior-y: contain; /* Чтобы скролл не передавался карте */
    }

    /* Ручка для свайпа */
    .drag-handle {
        width: 40px; 
        height: 4px;
        background-color: #E5E5EA;
        border-radius: 10px;
        margin: 0 auto 12px auto; /* Чуть больше отступ снизу */
        flex-shrink: 0;
    }

    /* Контейнер категорий */
    .categories-wrapper {
        display: flex !important;
        /* По умолчанию скрыты или показаны - как тебе удобнее. 
           Если хочешь, чтобы всегда были видны, убери max-height: 0. 
           Если хочешь шторку: */
        max-height: 0; 
        opacity: 0;
        overflow: hidden;
        
        /* Анимация только для ВНУТРЕННОСТИ шторки, а не всего окна */
        transition: max-height 0.3s ease, opacity 0.2s ease;
    }

    /* Когда открываем свайпом или кнопкой */
    .categories-wrapper.is-open {
        max-height: 60vh;
        opacity: 1;
        margin-top: 10px;
        overflow-y: auto;
        padding-bottom: 30px; 
    }

    /* --- ФИНАЛЬНЫЙ ФИКС --- */

    /* Когда активен поиск (.is-searching), принудительно скрываем категории */
    .bottom-sheet.is-searching .categories-wrapper {
        display: none !important; /* Убираем их из потока совсем */
    }

    /* Саму шторку сжимаем до размера содержимого (только поиск) */
    .bottom-sheet.is-searching {
        height: auto !important;
        min-height: 0 !important;
        padding-bottom: 0 !important; /* Убираем лишний отступ снизу */
    }

}

/* ==========================================================================
   5. DESKTOP SPECIFIC STYLES (min-width: 768px)
   ========================================================================== */
@media (min-width: 768px) {
    .drag-handle { display: none; }
    
    .bottom-sheet {
        top: 80px; left: 20px; bottom: 20px;
        width: 380px;
        border-radius: 24px;
        max-height: calc(100vh - 100px);
        padding: 16px;
        transition: width 0.3s ease, padding 0.3s ease;
    }

    .categories-wrapper {
        display: flex !important;
        margin-top: 15px;
        overflow-y: auto;
    }

    /* СВЁРНУТОЕ СОСТОЯНИЕ (FINAL FIX) */
    .bottom-sheet.collapsed {
        /* Принудительно задаем размеры и запрещаем расширение */
        overflow: visible !important;
        width: 80px !important;
        min-width: 80px !important;
        max-width: 80px !important;
        
        padding: 20px 0 !important;
       
    }

    /* ЗАПРЕЩАЕМ ДЕТЯМ РАСПИРАТЬ РОДИТЕЛЯ */
    .bottom-sheet.collapsed * {
        max-width: 80px;
        min-width: 0; /* Магия Flexbox: разрешает сжиматься меньше контента */
    }

    /* Поиск в вертикальный режим */
    .bottom-sheet.collapsed .search-row {
        flex-direction: column-reverse !important;
        gap: 20px;
        width: 100% !important;
        margin-bottom: 20px;
        align-items: center !important;
    }

    /* Превращаем поле поиска в кнопку */
    .bottom-sheet.collapsed .search-box-wrapper {
        width: 48px !important;
        height: 48px !important;
        padding: 0 !important;
        justify-content: center !important;
        background: transparent !important;
        cursor: pointer;
        flex-shrink: 0; 
    }

    /* Скрываем инпуты и крестики */
    .bottom-sheet.collapsed .search-input,
    .bottom-sheet.collapsed #clearSearchBtn {
        display: none !important;
    }

    /* Иконка лупы по центру */
    .bottom-sheet.collapsed .search-icon-img {
        margin: 0 !important;
        width: 28px !important; 
        height: 28px !important;
    }

    /* Категории в столбик */
    .bottom-sheet.collapsed .categories-wrapper {
        flex-direction: column !important;
        align-items: center !important;
        width: 100% !important;
        padding: 0 !important;
        margin-top: 0;
        
        /* Важно: разрешаем тултипам вылезать */
        overflow: visible !important; 
    }

    /* Кнопки категорий становятся квадратными */
    .bottom-sheet.collapsed .cat-btn {
        width: 48px !important;
        height: 48px !important;
        min-height: 48px !important;
        padding: 0 !important;
        justify-content: center !important;
        flex-grow: 0 !important;
        overflow: visible !important; /* Разрешаем вылезать из самой панели */
    }

    /* Скрываем текст в кнопках */
    .bottom-sheet.collapsed .cat-btn span {
        display: none !important;
    }

    /* Иконки по центру */
    .bottom-sheet.collapsed .cat-btn-icon {
        margin: 0 !important;
        width: 24px !important; 
        height: 24px !important;
    }

    .bottom-sheet.collapsed #search-results-panel {
        display: none !important;
    }
}

.offcanvas-body {
    overscroll-behavior-y: contain; /* Блокируем передачу скролла родителю */
}

/* --- ДЕСКТОП: СВЕРНУТЫЙ ВИД (DOCK) --- */

/* 1. Кнопка "ВСЕ" в свернутом виде */
/* Скрываем лишний текст " места" */
.bottom-sheet.collapsed .cat-btn[data-slug="all"] .extra-text {
    display: none;
}

/* Показываем слово "Все" по центру, как иконку */
.bottom-sheet.collapsed .cat-btn[data-slug="all"] .btn-text {
    display: flex !important; /* Принудительно показываем */
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    
    font-size: 11px;     /* Размер шрифта, чтобы влезло */
    font-weight: 800;    /* Жирный, чтобы читалось */
    text-transform: uppercase; /* Капсом, стильнее */
    letter-spacing: 0.5px;
    
    margin: 0;           /* Убираем отступы, если были */
}

/* 2. ТУЛТИПЫ (Подсказки справа) */

/* Разрешаем элементам вылезать за пределы свернутой панели */
.bottom-sheet.collapsed .categories-wrapper {
    overflow: visible !important; /* Разрешаем вылезать из самой панели */
}
.bottom-sheet.collapsed .cat-btn {
    position: relative; /* Чтобы позиционировать тултип относительно кнопки */
    overflow: visible !important; /* Разрешаем вылезать из самой панели */
}



/* Анимация плавного появления */
@keyframes fadeInTooltip {
    from { opacity: 0; transform: translate(-5px, -50%); }
    to   { opacity: 1; transform: translate(0, -50%); }
}


.custom-tooltip {
    display: flex;
    align-items: center;
    gap: 0;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.custom-tooltip.show {
    opacity: 1;
}

.tooltip-arrow {
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px 6px 6px 0;
    border-color: transparent #FFFFFF transparent transparent;
}

.tooltip-text {
    background-color: #FFFFFF;
    color: #000000;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}