html, body { 
    height: 100%; 
    width: 100%; 
    margin: 0; 
    padding: 0; 
    font-family: Arial, sans-serif; 
    overflow: hidden; /* Убирает прокрутку страницы */
    background-color: #1a1a1a; /* Темный фон на всякий случай */
    -webkit-tap-highlight-color: transparent; 
}

#map-container { 
    position: absolute; /* Жесткое позиционирование */
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#map { 
    height: 100%; 
    width: 100%; 
}

.legend, .controls-container, #inline-table-display-area, #toggle-menu-button {
    transition: transform 0.3s ease-out, opacity 0.3s ease-out, left 0.3s ease-in-out; 
}

.legend {
    padding: 6px 10px; 
    font: 11px Arial, Helvetica, sans-serif;
    background: white; 
    background: rgba(255,255,255,0.9);
    box-shadow: 0 0 15px rgba(0,0,0,0.2); 
    border-radius: 5px;
    line-height: 16px; 
    color: #333; 
    max-height: 350px; 
    overflow-y: auto; 
    position: absolute;
    bottom: 30px; 
    right: 10px;
    z-index: 1000; 
}
.legend h4 { 
    margin: 0 0 5px; 
    color: #333; 
    text-align: center; 
}
.legend i { 
    width: 16px; 
    height: 16px; 
    float: left; 
    margin-right: 6px; 
    opacity: 0.85; 
    border: 1px solid #999;
}

#loading-indicator {
    position: absolute; 
    top: 50%; 
    left: 50%; 
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7); 
    color: white; 
    padding: 15px 25px;
    border-radius: 6px; 
    z-index: 10001; 
    font-size: 16px; 
    display: none;
}

.controls-container {
    position: absolute;
    top: 10px;
    left: 10px; 
    background: rgba(255, 255, 255, 0.85); 
    padding: 10px;
    border-radius: 5px; 
    box-shadow: 0 0 15px rgba(0,0,0,0.2);
    z-index: 1001; 
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 250px; 
    max-width: 90%; 
    box-sizing: border-box;
    
    max-height: calc(100vh - 40px); /* Ограничиваем высоту меню высотой экрана */
    overflow-y: auto; /* Добавляем прокрутку внутри меню */
}

.control-item { 
    display: flex; 
    align-items: center; 
    gap: 8px; 
}
.control-item label { 
    font-size: 13px; 
    white-space: nowrap; 
    cursor: pointer;
}
.control-item input[type="range"] { 
    flex-grow: 1; 
    min-width: 60px; 
    margin-right: 8px;
}
.control-item input[type="number"] { 
    width: 45px; 
    padding: 3px 5px;
    box-sizing: border-box;
    text-align: right;
}
.control-item button { 
    padding: 5px 8px; 
    font-size: 11px; 
    cursor: pointer; 
    flex-shrink: 0; 
}
.control-item input[type="checkbox"] { 
    margin-right: 0px; 
    cursor: pointer;
}

body.dark-theme .legend { 
    background: rgba(50,50,50,0.9); 
    color: #f0f0f0; 
}
body.dark-theme .legend h4 { 
    color: #f0f0f0; 
}
body.dark-theme .legend i { 
    border-color: #666; 
}
body.dark-theme .controls-container { 
    background: rgba(40, 40, 40, 0.9); 
    color: #f0f0f0; 
}
body.dark-theme .control-item label { 
    color: #f0f0f0; 
}

.hexagon-label {
    font-weight: bold;
    color: #000000; 
    background-color: rgba(255, 255, 255, 0.75); 
    padding: 1px 3px; 
    border-radius: 3px; 
    white-space: nowrap; 
    text-align: center; 
    pointer-events: none; 
    box-shadow: 0px 0px 1px rgba(0,0,0,0.5); 
    display: flex; 
    align-items: center; 
    justify-content: center;
}

body.dark-theme .hexagon-label {
    color: #FFFFFF; 
    background-color: rgba(20, 20, 20, 0.75); 
    box-shadow: 0px 0px 1px rgba(255,255,255,0.5);
}

.leaflet-control-scale-line {
    border: 2px solid #777;
    border-top: none;
    color: #333; 
    background-color: rgba(255, 255, 255, 0.7); 
    padding: 2px 5px;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    box-shadow: 0 1px 5px rgba(0,0,0,0.4); 
    border-radius: 3px; 
    margin-bottom: 2px; 
}
body.dark-theme .leaflet-control-scale-line {
    border-color: #bbb;
    color: #eee;
    background-color: rgba(40, 40, 40, 0.7);
}

#inline-table-display-area {
    position: absolute;
    background-color: rgba(255, 255, 255, 0.95); 
    border: 1px solid #ccc;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    border-radius: 0 0 5px 5px; 
    z-index: 1000; 
    display: none; 
    flex-direction: column; 
    box-sizing: border-box;
}

body.dark-theme #inline-table-display-area {
    background-color: rgba(50, 50, 50, 0.95);
    border-color: #555;
    color: #f0f0f0;
}

#inline-table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    background-color: #f0f0f0;
    border-bottom: 1px solid #ccc;
    font-weight: bold;
    box-sizing: border-box;
    cursor: move; /* Курсор перетаскивания */
    user-select: none; /* Запрет выделения текста */
}
body.dark-theme #inline-table-header {
    background-color: #444;
    border-bottom-color: #555;
}

#inline-table-title {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; 
}

/* === ИСПРАВЛЕННАЯ КНОПКА ЗАКРЫТИЯ === */
#close-inline-table-button {
    /* Размеры и форма */
    width: 30px;
    height: 30px;
    border-radius: 4px; /* Скругленные углы */
    border: none;
    
    /* Цвета: Красный фон, белый текст */
    background-color: #ff4444; 
    color: white;
    
    /* Выравнивание крестика по центру */
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* Шрифт */
    font-size: 24px;
    font-weight: bold;
    line-height: 1;
    
    cursor: pointer;
    margin-left: 10px; /* Отступ от названия таблицы */
    transition: background-color 0.2s;
}

/* Эффект при наведении мыши */
#close-inline-table-button:hover {
    background-color: #cc0000; /* Темно-красный */
}

/* ВАЖНО: Если в HTML кнопка пустая, этот код сам нарисует крестик */
#close-inline-table-button:empty::after {
    content: "×"; 
}
/* ==================================== */

#inline-table-content {
    overflow-y: auto; 
    flex-grow: 1; 
    padding: 0 5px 5px 5px; 
    box-sizing: border-box;
}

#inline-table-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

#inline-table-content th, 
#inline-table-content td {
    border: 1px solid #ddd;
    padding: 4px 6px;
    text-align: left;
    box-sizing: border-box;
}

#inline-table-content th {
    background-color: #e9e9e9;
    font-weight: bold;
    position: sticky; 
    top: 0;           
    z-index: 1;       
}
#inline-table-content th.sortable {
    cursor: pointer;
}
#inline-table-content th.sortable:hover {
    background-color: #dcdcdc;
}
body.dark-theme #inline-table-content th.sortable:hover {
    background-color: #666;
}

.sort-indicator {
    margin-left: 5px;
    font-size: 0.8em; 
}

body.dark-theme #inline-table-content th {
    background-color: #555;
    border-color: #666;
}
body.dark-theme #inline-table-content td {
    border-color: #666;
}

.inline-table-pagination {
    padding: 8px 5px;
    text-align: center;
    border-top: 1px solid #ccc;
    background-color: #f9f9f9;
    box-sizing: border-box;
}
body.dark-theme .inline-table-pagination {
    border-top-color: #555;
    background-color: #404040;
}
.inline-table-pagination button {
    margin: 0 5px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
}
.inline-table-pagination button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}
.inline-table-pagination span {
    font-size: 12px;
    margin: 0 8px;
}

#toggle-menu-button {
    display: none; 
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 1002; 
    font-size: 24px;
    padding: 5px 10px;
    background-color: rgba(255, 255, 255, 0.8);
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1; 
    box-sizing: border-box;
}
body.dark-theme #toggle-menu-button {
    background-color: rgba(40, 40, 40, 0.8);
    border-color: #555;
    color: #f0f0f0;
}

@media (max-width: 768px) { 
    #toggle-menu-button {
        display: block; 
    }

    .controls-container {
        transform: translateX(-100%); 
        left: 0; 
        height: calc(100vh - 20px); 
        max-height: calc(100vh - 20px);
        overflow-y: auto;
        border-radius: 0 5px 5px 0; 
    }

    .controls-container.open {
        transform: translateX(0); 
    }

    .legend {
        max-height: 150px; 
        font-size: 10px; 
        right: 5px;      
        bottom: 25px;    
        max-width: 120px; 
    }
    .legend i {
        width: 12px;
        height: 12px;
        margin-right: 4px;
    }

    #inline-table-display-area {
        z-index: 1000; 
    }

    .leaflet-control-zoom-in, .leaflet-control-zoom-out {
        font-size: 1.5em !important; 
        width: 34px !important;      
        height: 34px !important;     
        line-height: 34px !important;
    }
    .leaflet-control-scale-line {
        font-size: 10px; 
        margin-left: 50px; 
    }
    .leaflet-control-layers {
        display: none !important;
    }
}

@media (max-width: 480px) { 
    .controls-container {
        gap: 8px; 
        padding: 8px; 
        width: 220px; 
    }
    .control-item label, .control-item small {
        font-size: 11px; 
    }
    .control-item button {
        font-size: 10px;
        padding: 4px 6px;
    }
    .control-item input[type="number"] {
        width: 35px;
    }
    #inline-table-title {
        font-size: 13px;
    }
    .legend {
        max-height: 120px;
        font-size: 9px;
    }
    .leaflet-control-scale-line {
        margin-left: 45px; 
    }
}

.leaflet-popup-content-wrapper {
}
.leaflet-popup-content {
    max-height: 200px; 
    overflow-y: auto;
    margin: 10px !important; 
    font-size: 12px;
    box-sizing: border-box;
}
.leaflet-popup-content pre {
    white-space: pre-wrap;      
    white-space: -moz-pre-wrap; 
    white-space: -pre-wrap;     
    white-space: -o-pre-wrap;   
    word-wrap: break-word;      
    background-color: #f8f8f8;
    border: 1px solid #ddd;
    padding: 5px;
    margin-top: 5px;
    border-radius: 3px;
    font-size: 11px;
    box-sizing: border-box;
}
body.dark-theme .leaflet-popup-content pre {
    background-color: #333;
    border-color: #555;
    color: #f0f0f0;
}

body.dark-theme .leaflet-tooltip {
    background: rgba(45, 45, 45, 0.92); 
    color: #e8e8e8;                  
    border: 1px solid #585858;       
    box-shadow: 0 1px 5px rgba(0,0,0,0.5); 
    font-size: 11px;
    padding: 5px 8px;
}

body.dark-theme .leaflet-tooltip-top:before {
	border-bottom-color: #585858; 
}
body.dark-theme .leaflet-tooltip-bottom:before {
	border-top-color: #585858;
}
body.dark-theme .leaflet-tooltip-left:before {
	border-right-color: #585858;
}
body.dark-theme .leaflet-tooltip-right:before {
	border-left-color: #585858;
}

#layer-controls-panel {
    border-top: 1px solid #ccc;
    margin-top: 10px;
    padding-top: 10px;
    box-sizing: border-box;
}
body.dark-theme #layer-controls-panel {
    border-top-color: #555;
}

#layer-controls-panel h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    text-align: center;
}

.layer-control-item {
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e0e0e0;
}
#layer-controls-panel .layer-control-item:last-of-type {
    border-bottom: none;
    margin-bottom: 15px;
}
body.dark-theme .layer-control-item {
    border-bottom-color: #444;
}

.layer-main-info {
    display: flex;
    align-items: center;
    width: 100%;
    margin-bottom: 6px;
}

.layer-main-info input[type="checkbox"] {
    margin-right: 6px;
    flex-shrink: 0;
    cursor: pointer;
}

.layer-main-info label {
    font-size: 12px;
    flex-grow: 1; 
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
    margin-right: 8px;
    min-width: 0;
}

.point-layer-toggle-item {
    display: flex;
    align-items: center;
    padding-left: 25px;
}

.point-layer-toggle-item input[type="checkbox"] {
    margin-right: 6px;
    flex-shrink: 0;
    cursor: pointer;
}

.point-layer-toggle-item label {
    font-size: 11px;
    white-space: nowrap;
    cursor: pointer;
}

.layer-weight-input {
    width: 50px; 
    padding: 3px 5px;
    text-align: right;
    box-sizing: border-box;
    flex-shrink: 0;
}
.layer-control-item span {
    font-size: 12px;
    margin-left: 2px;
    flex-shrink: 0;
}

.recalculate-container {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid #ccc;
    display: flex;
    flex-direction: column; 
    gap: 8px;
}
body.dark-theme .recalculate-container {
    border-top-color: #555;
}

#recalculate-ratings-button {
    width: 100%; 
    padding: 6px 10px;
    font-size: 13px;
    box-sizing: border-box;
    cursor: pointer;
}

.recalculation-status-text {
    font-size: 11px;
    color: #555;
    min-height: 1.5em; 
    text-align: center;
}

body.dark-theme .recalculation-status-text {
    color: #bbb;
}

.draggable-header {
    background: rgba(255, 255, 255, 0.95);
    padding: 8px 12px;
    font-weight: bold;
    text-align: center;
    border-bottom: 1px solid #ccc;
    margin: -10px -10px 10px -10px;
    cursor: move;
    user-select: none;
}

/* === ФИНАЛЬНЫЙ РЕМОНТ МЕНЮ И ПОИСКА (ВЕРСИЯ 3) === */

/* 1. Настройка самого окна меню */
.controls-container {
    resize: both !important;       /* Разрешает тянуть и вширь, и вниз */
    overflow: auto !important;     /* Обязательно для работы растягивания */
    
    min-width: 260px;              /* Минимальная ширина */
    min-height: 200px;             /* Минимальная высота */
    
    max-width: 95vw;               /* Не шире экрана */
    max-height: 95vh !important;   /* Разрешаем растягивать почти до низа экрана */
    
    padding-bottom: 20px;          /* Место для уголка, чтобы удобно хватать */
    box-sizing: border-box !important;
}

/* 2. УДАЛЯЕМ надпись "Поиск адреса:" */
.control-item:has(#address-input) label {
    display: none !important;      /* Скрыть полностью */
    visibility: hidden !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* 3. Настраиваем контейнер поиска (чтобы кнопка была под полем) */
.control-item:has(#address-input) {
    display: flex !important;
    flex-direction: column !important; /* Столбик */
    width: 100% !important;
    height: auto !important;
    margin-bottom: 15px !important;
    padding-bottom: 10px !important;
    border-bottom: 1px solid #ccc;
    box-sizing: border-box !important;
}

/* 4. Поле ввода на всю ширину */
#address-input {
    width: 100% !important;
    height: 35px !important;
    margin: 0 0 8px 0 !important;  /* Отступ снизу до кнопки */
    box-sizing: border-box !important;
}

/* 5. Кнопка поиска на всю ширину */
#address-input ~ button {
    display: block !important;
    width: 100% !important;
    height: 35px !important;
    background-color: #4CAF50 !important;
    color: white !important;
    border: none !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    margin: 0 !important;
}

/* Скрываем копирайт карты */
.leaflet-control-attribution {
    display: none !important;
}

/* ========================================== */
/* СТИЛИ ДЛЯ ПОДПИСЕЙ ТОЧЕК (LABELS)          */
/* ========================================== */

/* Сам текст подписи */
.static-point-label {
    background: transparent; /* Прозрачный фон */
    border: none;            /* Убираем рамку */
    box-shadow: none;        /* Убираем тень */
    
    color: #000;             /* Черный текст */
    font-weight: bold;       /* Жирный */
    font-size: 11px;         /* Размер шрифта */
    
    /* Белая обводка букв (чтобы читалось на темной карте) */
    text-shadow: 
        -1px -1px 0 #fff,  
         1px -1px 0 #fff,
        -1px  1px 0 #fff,
         1px  1px 0 #fff;
         
    white-space: nowrap;     /* Текст в одну строку */
    
    /* ВАЖНО: Чтобы сквозь текст можно было кликать по карте/маркеру */
    pointer-events: none;    
}

/* Убираем стандартный треугольник-стрелочку Leaflet */
.leaflet-tooltip-top:before, 
.leaflet-tooltip-bottom:before, 
.leaflet-tooltip-left:before, 
.leaflet-tooltip-right:before {
    display: none !important;
}

/* Легенда точек в меню */
.point-legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    margin-left: 2px;
    border: 1px solid rgba(0,0,0,0.2); /* Легкая обводка для светлых цветов */
    vertical-align: middle;
    flex-shrink: 0;
}

/* Выравнивание лейбла чекбокса, чтобы кружок стоял ровно */
.layer-control-item label {
    display: flex;
    align-items: center;
}

















/* =========================================
   ФИНАЛЬНЫЕ СТИЛИ МЕНЮ (UI v5 - Big Sliders)
   ========================================= */

/* Контейнер одного слоя */
.layer-control-item {
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    gap: 6px; /* Отступ между строками */
}

.layer-control-item:last-child {
    border-bottom: none;
}

.layer-control-item.disabled {
    opacity: 0.5;
}
/* Разрешаем кликать по главному чекбоксу даже в disabled состоянии */
.layer-control-item.disabled .layer-header-row {
    pointer-events: auto;
}
.layer-control-item.disabled .layer-slider-row,
.layer-control-item.disabled .point-layer-toggle-item {
    pointer-events: none;
}


/* --- СТРОКА 1: Заголовок и Инпут --- */
.layer-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

/* Лейбл (Чекбокс + Имя) */
.layer-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    flex-grow: 1; /* Занимает все место слева */
    font-size: 13px;
    font-weight: 600;
    color: #333;
    overflow: hidden;
    margin-right: 10px;
}

.layer-name {
    margin-left: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Поле ввода цифр */
input[type="number"].layer-weight-input {
    width: 42px;
    height: 24px;
    font-size: 13px;
    font-weight: bold;
    text-align: center;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #f9f9f9;
    color: #333;
    padding: 0;
    -moz-appearance: textfield; /* Убираем стрелки в Firefox */
}
/* Убираем стрелки в Chrome/Safari */
input[type="number"].layer-weight-input::-webkit-outer-spin-button,
input[type="number"].layer-weight-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"].layer-weight-input:focus {
    border-color: #3498db;
    background: #fff;
    outline: none;
}

.layer-percent-symbol {
    font-size: 12px;
    color: #888;
    margin-left: 4px;
    width: 12px;
}

/* --- СТРОКА 2: Большой Слайдер --- */
.layer-slider-row {
    width: 100%;
    padding: 0 2px; /* Небольшой отступ с краев */
    box-sizing: border-box;
    height: 24px;
    display: flex;
    align-items: center;
}

/* Слайдер */
input[type=range].layer-slider {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
    height: 24px; /* Высота зоны клика */
    cursor: pointer;
    margin: 0;
}

input[type=range].layer-slider:focus {
    outline: none;
}

/* Дорожка (Track) - Жирная */
input[type=range].layer-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px; /* Толстая линия */
    background: #e0e0e0;
    border-radius: 3px;
}
input[type=range].layer-slider::-moz-range-track {
    width: 100%;
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
}

/* Бегунок (Thumb) - Большой и Цветной */
/* Используем переменную --layer-color, которую задает JS */
input[type=range].layer-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 18px; /* Большой кружок */
    width: 18px;
    border-radius: 50%;
    background: var(--layer-color, #3498db); /* Цвет слоя */
    margin-top: -6px; /* Центрирование: (6px - 18px) / 2 */
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: transform 0.1s;
    border: 2px solid white; /* Белая обводка */
}
input[type=range].layer-slider::-moz-range-thumb {
    height: 18px;
    width: 18px;
    border: none;
    border-radius: 50%;
    background: var(--layer-color, #3498db);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    border: 2px solid white;
}

input[type=range].layer-slider:hover::-webkit-slider-thumb {
    transform: scale(1.1);
}

/* --- СТРОКА 3: Точки --- */
.point-layer-toggle-item {
    margin-top: 2px;
    font-size: 12px;
    color: #555;
    display: flex;
    align-items: center;
    padding-top: 4px;
    border-top: 1px dashed #eee; /* Легкий разделитель */
}

.points-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 2px 0;
    width: 100%;
}
.points-label:hover {
    color: #000;
}

/* Чекбокс точек */
.point-layer-toggle-item input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin-right: 6px;
    border-color: #ccc;
}

/* Легенда (Кружок) */
.point-legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}