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: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.4);
    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;
    cursor: move;
    user-select: none;
}

.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;
    /* Glassmorphism */
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.15);
    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;
}

/* === RADIUS TOOL CSS === */
/* Disable interaction with the main Canvas (hexagons) when radius mode is active */
.radius-mode-active canvas.leaflet-interactive {
    pointer-events: none !important;
}

/* Allow interaction with the specific SVG renderer used by RadiusManager */
/* Leaflet SVGs are <svg> elements. Paths inside them are <path>. */
/* By default, pointer-events may be inherited. */

/* If map container has radius-mode-active: */
/* 1. Disable all paths by default (to be safe? No, other layers might be SVG) */
/* We only want to disable the Hexagon layer. But Hexagon is Canvas in 99% cases here. */
/* If Hexagon was SVG, we'd need to target it specifically. */
/* Assuming Hexagon is Canvas (id='map' canvas). */

/* 2. Ensure our Radius Circles are interactive. */
/* They are in an SVG element created by this.svgRenderer. */
/* That SVG element sits on top of Canvas usually (overlayPane). */
/* If we don't disable pointer-events on the SVG container, it absorbs clicks? */
/* No, SVG is transparent. Paths capture clicks. */

/* So, simply disabling Canvas pointer-events is enough to let clicks "fall through" 
   the hexagons to the map (for "Add Point" click). */
/* BUT, we need to ensure the Radius Circles defined in the SVG renderer match mouse events. */
/* They will, because they are DOM elements. */

/* Visual feedback for the button */
.radius-control-btn {
    transition: background-color 0.2s;
}

body.dark-theme .legend {
    background: rgba(40, 40, 40, 0.65);
    border-color: rgba(255, 255, 255, 0.1);
    color: #f0f0f0;
}

body.dark-theme .legend h4 {
    color: #f0f0f0;
}

body.dark-theme .legend i {
    border-color: #666;
}

body.dark-theme .controls-container {
    background: rgba(30, 30, 30, 0.7);
    border-color: rgba(255, 255, 255, 0.1);
    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;
    /* Glassmorphism for Table Window */
    background-color: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    border-radius: 0 0 8px 8px;
    z-index: 1000;
    display: none;
    flex-direction: column;
    box-sizing: border-box;
    /* FR: Resizable Window */
    /* resize: both;  <-- REMOVED to avoid conflict with JS DraggableUtils */
    overflow: hidden;
    min-width: 300px;
    min-height: 200px;
}


body.dark-theme #inline-table-display-area {
    background-color: rgba(40, 40, 40, 0.8);
    border-color: rgba(255, 255, 255, 0.1);
    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;
    }
}

/* Removed empty ruleset */

.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;
}

/* === ISOCHRONE LABELS === */
.iso-label {
    background: transparent;
    border: none;
    box-shadow: none;
    color: #fff;
    font-weight: bold;
    text-shadow: 0 0 3px #000;
    font-size: 12px;
    text-align: center;
}

/* === CLASSIC LAYER CONTROL (RESTORED) === */
/* Grouped Layer Control inherits from standard layers, so these styles apply */

/* Ensure headers in Grouped Control look nice */
.leaflet-control-layers-group-name {
    font-weight: bold;
    color: #555;
    margin-bottom: 2px;
    display: block;
    border-bottom: 1px solid #eee;
    padding-top: 5px;
}

/* Remove any pseudo-element headers user hated */
.leaflet-control-layers-list::before {
    content: none !important;
    display: none !important;
}

.leaflet-control-layers-base,
.leaflet-control-layers-overlays {
    margin: 0;
    padding: 0;
    list-style: none;
    /* No bullets */
}

.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;
}

/* Скрываем копирайт карты */

/* === MICRO-INTERACTION ANIMATIONS === */

/* 1. Button Animations */
button,
.btn-premium,
#address-search-button,
.ag-export-btn,
.control-item button {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    transform: scale(1);
}

button:hover,
.btn-premium:hover,
#address-search-button:hover,
.ag-export-btn:hover,
.control-item button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

button:active,
.btn-premium:active,
#address-search-button:active,
.ag-export-btn:active,
.control-item button:active {
    transform: scale(0.95);
}

/* Specific fix for close button to rotate on hover */
#close-inline-table-button {
    transition: transform 0.3s ease, background-color 0.2s;
}

#close-inline-table-button:hover {
    transform: rotate(90deg) scale(1.1);
}

/* 2. Modal/Popup Animations (Fade-in + Scale) */
@keyframes modalAppear {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes popupAppear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Apply to Leaflet Popups */
.leaflet-popup {
    animation: popupAppear 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
    transform-origin: bottom center;
}

/* Apply to Inline Table (Centered Modal-like behavior if centered, but currently it has fixed pos. We'll animate opacity and slight scale from center of itself) */
#inline-table-display-area {
    /* Existing transition is for generic props, let's add specific animation when display changes from none to block */
    /* Note: Display:none to block breaks animations without JS. 
       However, we can add a class for 'active' or just rely on CSS animations triggering on insertion (which Leaflet popups do).
       For inline-table, if it's toggled via display:none, we might not see animation. 
       But we can add a keyframe that runs on render. */
    animation: fadeInScale 0.3s ease-out;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* 3. Sliding Tab Underline Animation (Generic Implementation) */
/* Structure expected: 
   <div class="tabs-container">
     <div class="tab transition-tab active">Tab 1</div>
     <div class="tab transition-tab">Tab 2</div>
     <div class="tab-underline"></div>
   </div>
*/

.tabs-container {
    position: relative;
    display: flex;
    border-bottom: 2px solid #eee;
}

.tab {
    padding: 10px 15px;
    cursor: pointer;
    position: relative;
    color: #555;
    transition: color 0.3s;
    font-weight: 500;
}

.tab.active {
    color: #2196f3;
}

/* The magic underline */
.tab-underline {
    position: absolute;
    bottom: -2px;
    left: 0;
    height: 2px;
    background-color: #2196f3;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    /* Width and Left property should be set via JS, 
       BUT for pure CSS hover effects on simple lists: */
}

/* Pure CSS hover alternative (simple version) */
.tab-hover-effect {
    position: relative;
    overflow: hidden;
}

.tab-hover-effect::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: #2196f3;
    transform: translateX(-101%);
    transition: transform 0.3s ease;
}

.tab-hover-effect:hover::after,
.tab-hover-effect.active::after {
    transform: translateX(0);
}



/* Restore attribution override */
.leaflet-control-attribution {
    display: none !important;
}

/* ========================================== */

/* Сам текст подписи */
/* Numbered Point Markers for Routes */
.route-marker-icon {
    border-radius: 50%;
    color: white;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
    font-size: 13px;
    width: 24px !important;
    height: 24px !important;
}

.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: pre-line;
    /* Многострочный текст */

    /* ВАЖНО: Чтобы сквозь текст можно было кликать по карте/маркеру */
    pointer-events: none;
}

/* Размер шрифта зависит от балла (как на гексах) */
.label-large {
    font-size: 14px !important;
    font-weight: 700 !important;
}

.label-medium {
    font-size: 12px !important;
    font-weight: 600 !important;
}

.label-small {
    font-size: 10px !important;
    font-weight: 500 !important;
}

/* Убираем стандартный треугольник-стрелочку 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;
    appearance: textfield;
    appearance: textfield;
    -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 {
    appearance: none;
    -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);
}


/* === СТИЛИ ДЛЯ ПЕРЕТАСКИВАЕМОГО ЗАГОЛОВКА === */
.draggable-header {
    padding: 10px;
    background-color: rgba(255, 255, 255, 0.3);
    /* Light semi-transparent */
    cursor: move;
    /* Курсор в виде крестика */
    border-bottom: 1px solid #ccc;
    border-radius: 5px 5px 0 0;
    /* Скругление только сверху */
    font-weight: bold;
    text-align: center;
    color: #333;
    user-select: none;
    /* Чтобы текст не выделялся при перетаскивании */

    /* Компенсация padding родительского контейнера, 
       чтобы заголовок был от края до края */
    margin: -10px -10px 10px -10px;
}

/* Поддержка темной темы */
body.dark-theme .draggable-header {
    background-color: rgba(0, 0, 0, 0.3);
    border-bottom-color: #555;
    color: #f0f0f0;
}

/* При перетаскивании делаем меню чуть прозрачным */
.controls-container.dragging {
    opacity: 0.8;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

/* Самодельный статус-бар для таблицы */
#custom-status-bar {
    height: 30px;
    background-color: #f8f8f8;
    border-top: 1px solid #ccc;
    display: flex;
    align-items: center;
    padding: 0 15px;
    font-size: 12px;
    color: #333;
    font-family: 'Roboto', sans-serif;
    gap: 20px;
    /* Расстояние между элементами */
    flex-shrink: 0;
    /* Чтобы не сжимался */
}

#custom-status-bar strong {
    font-weight: 600;
}

/* === MOBILE ADAPTATION === */

/* Mobile Menu Button */
.mobile-menu-btn {
    display: none;
    /* Hidden on desktop */
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2000;
    /* Higher than controls */
    width: 40px;
    height: 40px;
    background-color: white;
    border: none;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #333;
}

/* 4. Routing Button (Custom) */
#routing-btn-container i {
    color: #d32f2f !important;
    /* Redish like standard */
    font-size: 16px !important;
}

/* Force visibility if fa-solid fails */
#routing-btn-container i::before {
    content: "\f23d" !important;
    /* fa-subway or fa-route */
    font-family: "Font Awesome 5 Free" !important;
    font-weight: 900 !important;
}

/* 5. Scale or other custom buttons (Ensure black text) */
.leaflet-control-graphicscale {
    display: none !important;
    /* User said it's blocked? Or maybe just ensure text is dark */
}

/* 6. Magic Wand (AutoTerritory) */
.auto-territory-btn i {
    color: #6a1b9a !important;
    font-size: 16px !important;
}


@media (max-width: 768px) {

    /* Show Menu Button */
    .mobile-menu-btn {
        display: flex;
    }

    /* Sidebar / Controls Container */
    .controls-container {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh !important;
        max-height: 100vh !important;
        width: 300px;
        max-width: 85vw;
        transform: translateX(-110%);
        /* Hidden by default */
        transition: transform 0.3s ease-in-out;
        z-index: 1500;
        border-radius: 0;
        padding-top: 60px;
        /* Space for close button if needed or visual separation */
        overflow-y: auto;
    }

    .controls-container.open {
        transform: translateX(0);
        /* Slide in */
    }

    /* Move Leaflet controls to right or adjust */
    .leaflet-control-zoom {
        margin-top: 60px !important;
        /* Avoid overlap with menu button if on left */
    }

    /* Touch Friendly Sizing */
    .control-item label,
    .layer-label,
    .recalculation-status-text {
        font-size: 14px;
        padding: 5px 0;
    }

    input[type="checkbox"] {
        transform: scale(1.3);
        margin-right: 10px;
    }

    input[type="range"] {
        height: 25px;
        /* Easier to grab */
    }

    button {
        padding: 10px 15px !important;
        font-size: 14px !important;
    }

    /* Adjust Legend */
    .legend {
        bottom: 25px;
        right: 10px;
        max-width: 150px;
        max-height: 200px;
        font-size: 10px;
    }

    /* Inline Table Adjustment */
    #inline-table-display-area {
        width: 100% !important;
        left: 0 !important;
        bottom: 0 !important;
        border-radius: 0;
        max-height: 50vh;
    }
}

/* Dark Theme Adjustments for Mobile */
body.dark-theme .mobile-menu-btn {
    background-color: #333;
    color: #f0f0f0;
}

/* --- LEAFLET POPUP BEAUTIFICATION --- */
.leaflet-popup-content-wrapper {
    /* Glass Popup */
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    padding: 0;
    /* Remove default padding, handle in content */
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 16px;
    line-height: 1.5;
    font-family: 'Inter', sans-serif;
    /* Ensure font matches */
    font-size: 0.95rem;
    color: #333;
}

/* 4. Routing Button (Custom) */
#routing-btn-container i {
    color: #d32f2f !important;
    /* Redish like standard */
    font-size: 16px !important;
}

/* Force visibility if fa-solid fails */
#routing-btn-container i::before {
    content: "\f23d" !important;
    /* fa-subway or fa-route */
    font-family: "Font Awesome 5 Free" !important;
    font-weight: 900 !important;
}

/* 5. Scale or other custom buttons (Ensure black text) */
.leaflet-control-graphicscale {
    display: none !important;
    /* User said it's blocked? Or maybe just ensure text is dark */
}

/* 6. Magic Wand (AutoTerritory) */
.auto-territory-btn i {
    color: #6a1b9a !important;
    font-size: 16px !important;
}


.leaflet-popup-tip {
    box-shadow: 0 4px 25px rgba(0, 0, 0, 0.15);
}

.leaflet-container a.leaflet-popup-close-button {
    color: #999;
    font-size: 18px;
    padding: 8px;
    /* Larger hit area */
    right: 5px;
    top: 5px;
    transition: color 0.2s;
}

.leaflet-container a.leaflet-popup-close-button:hover {
    color: #333;
}

/* 4. Routing Button (Custom) */
#routing-btn-container i {
    color: #d32f2f !important;
    /* Redish like standard */
    font-size: 16px !important;
}

/* Force visibility if fa-solid fails */
#routing-btn-container i::before {
    content: "\f23d" !important;
    /* fa-subway or fa-route */
    font-family: "Font Awesome 5 Free" !important;
    font-weight: 900 !important;
}

/* 5. Scale or other custom buttons (Ensure black text) */
.leaflet-control-graphicscale {
    display: none !important;
    /* User said it's blocked? Or maybe just ensure text is dark */
}

/* 6. Magic Wand (AutoTerritory) */
.auto-territory-btn i {
    color: #6a1b9a !important;
    font-size: 16px !important;
}


/* --- FAVORITES --- */
/* FAVORITE BUTTON (Overlay Style) */
.favorite-btn-wrap {
    cursor: pointer;
    font-size: 1.5rem;
    z-index: 1000;
    width: 24px;
    height: 24px;
    display: block;
    position: absolute;
    /* Placement in Popup */
}

/* Stacking Context: Force icons to overlap */
.favorite-btn-wrap .star-outline,
.favorite-btn-wrap .star-filled,
.favorite-btn-wrap i,
.favorite-btn-wrap svg {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    display: inline-block !important;
    /* Always rendered */
    transition: opacity 0.2s ease, transform 0.2s ease;
    border: none;
    background: none;
    margin: 0 !important;
    padding: 0 !important;
}

/* Base State: Outline Visible, Filled Hidden */
.favorite-btn-wrap .star-outline {
    opacity: 1;
    color: #ccc;
    /* Default Gray */
    z-index: 1;
}

.favorite-btn-wrap .star-filled {
    opacity: 0;
    color: #FFD700 !important;
    /* Gold */
    z-index: 2;
    transform: scale(0.8);
}

/* Hover State */
.favorite-btn-wrap:hover .star-filled {
    opacity: 0.5;
}

.favorite-btn-wrap:hover .star-outline {
    color: #FFD700;
}

/* Active Class: Show Filled, Hide Outline */
.favorite-btn-wrap.active .star-filled {
    opacity: 1 !important;
    transform: scale(1);
}

.favorite-btn-wrap.active .star-outline {
    opacity: 0;
    /* Fade out outline so it doesn't bleed through */
}

/* Grid Action Buttons */
.btn-delete {
    font-size: 1.2rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.btn-delete:hover {
    opacity: 1;
    color: red;
    transform: scale(1.1);
}

/* Fix Leaflet Popup Scroll */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    padding: 0;
}

.leaflet-popup-content {
    margin: 10px 14px;
    width: auto !important;
    min-width: 200px;
    /* Ensure enough width for "H3 ID ... Star" */
    overflow-y: hidden !important;
    /* No scrollbars */
    overflow-x: hidden !important;
}

/* Favorites Grid Navigation Link Style */
.grid-cell-nav {
    color: #1976d2;
    font-weight: bold;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
}

.grid-cell-nav:hover {
    color: #0d47a1;
    text-decoration-style: solid;
}


/* === AG GRID SORT INDICATORS (MULTI-COLUMN) === */
/* Ensure the container isn't hidden */
.ag-theme-material .ag-header-cell-label .ag-sort-indicator-container {
    display: flex;
    align-items: center;
}

/* Style for the sort number badge (1, 2, 3...) */
.ag-theme-material .ag-sort-order {
    background-color: #2196F3;
    /* Material Blue */
    color: white;
    font-size: 10px;
    font-weight: bold;
    border-radius: 50%;
    /* Circle */
    padding: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 4px;
    /* Space between number and arrow */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    margin-left: 4px;
    /* Ensure it's not squashed */
    z-index: 1;
}

/* Ensure the number is visible even without hover if active */
.ag-header-cell-sorted-asc .ag-sort-order,
.ag-header-cell-sorted-desc .ag-sort-order {
    display: flex !important;
}

/* Style for the sort arrow itself to match premium look */
.ag-theme-material .ag-header-icon {
    font-size: 14px;
    color: #555;
    opacity: 0.8;
}

.ag-theme-material .ag-header-cell-sorted-asc .ag-header-icon,
.ag-theme-material .ag-header-cell-sorted-desc .ag-header-icon {
    color: #2196F3;
    /* Active sort color */
    opacity: 1;
}

/* Dark Theme Support for Sort Indicators */
body.dark-theme .ag-theme-material .ag-sort-order {
    background-color: #64b5f6;
    /* Lighter blue for dark mode */
    color: #1a1a1a;
}

/* FR: Stronger Selection Highlight for Copy/Paste Clarity */
.ag-theme-material .ag-row-selected {
    background-color: rgba(187, 222, 251, 0.2) !important;
    /* Subtle row select */
    color: inherit !important;
}

/* Custom Range Selection Polyfill Styles */
.custom-range-selected {
    background-color: #bbdefb !important;
    /* Blue 100 */
    color: black !important;
    border: 1px solid #64b5f6 !important;
}

/* Ensure clean edges */
.custom-range-selected-top {
    border-top: 2px solid #1976d2 !important;
}

.custom-range-selected-bottom {
    border-bottom: 2px solid #1976d2 !important;
}

.custom-range-selected-left {
    border-left: 2px solid #1976d2 !important;
}

.custom-range-selected-right {
    border-right: 2px solid #1976d2 !important;
}

/* Dark Theme */
body.dark-theme .custom-range-selected {
    background-color: #1565c0 !important;
    color: white !important;
}

/* Ensure text selection is visible */
.ag-cell::selection {
    background: #FFD700;
    /* Gold selection for text to differ from row blue */
    color: black;
}

/* FR: Dynamic Row Height Support */
.wrap-text-cell {
    white-space: normal !important;
    line-height: 1.5 !important;
    padding-top: 4px !important;
    padding-bottom: 4px !important;
    padding-bottom: 4px !important;
    word-break: break-word !important;
}

/* === AI ASSISTANT (FR-2.0 Integration) === */

/* Helper for Leaflet Control styling */
.leaflet-control-ai {
    background: white;
    border-radius: 4px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.65);
    cursor: pointer;
}

.leaflet-control-ai a {
    width: 30px;
    /* Standard Leaflet size */
    height: 30px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #333;
    text-decoration: none;
    transition: all 0.2s ease;
}

/* Active State */
.leaflet-control-ai.active,
.leaflet-control-ai.active a {
    background-color: #6200ea !important;
    color: white !important;
}

/* Chat Window - Mimicking .controls-container */
.ai-chat-window {
    position: absolute;
    top: 50px;
    /* Offset from top right controls */
    right: 50px;
    /* Offset to not cover controls if needed */
    width: 360px;
    height: 550px;
    max-height: calc(100vh - 100px);

    /* AI Window Glass */
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    z-index: 1001;
    /* Same as main controls */

    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Roboto', sans-serif;
    transition: opacity 0.2s, transform 0.2s;
    opacity: 1;
    transform: translateY(0);
}

.ai-chat-window.ai-hidden {
    display: none !important;
    opacity: 0;
    transform: translateY(-10px);
}

/* Dark Theme Support for Window */
body.dark-theme .ai-chat-window {
    background: rgba(40, 40, 40, 0.95);
    color: #f0f0f0;
    border: 1px solid #444;
}

/* Header */
.ai-header {
    padding: 10px 15px;
    background-color: rgba(255, 255, 255, 0.3);
    /* Match .draggable-header */
    border-bottom: 1px solid #ccc;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #333;
    cursor: move;
    /* If draggable */
}

body.dark-theme .ai-header {
    background-color: rgba(0, 0, 0, 0.3);
    color: #f0f0f0;
    border-bottom-color: #555;
}

.ai-header .close-btn {
    cursor: pointer;
    font-size: 18px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.ai-header .close-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* Messages Area */
.ai-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-msg {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 8px;
    line-height: 1.4;
    font-size: 13px;
    position: relative;
    word-wrap: break-word;
}

/* Message Styles (FR-3.2) */
.ai-msg.user {
    background-color: #1976d2;
    /* Main App Blue or Green #43a047 */
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.ai-msg.bot {
    background-color: #f5f5f5;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
    border: 1px solid #eee;
}

body.dark-theme .ai-msg.bot {
    background-color: #2d2d2d;
    color: #e0e0e0;
    border-color: #444;
}

.ai-msg.system {
    background: rgba(255, 193, 7, 0.2);
    color: #856404;
    font-size: 12px;
    align-self: center;
    text-align: center;
    border: 1px solid rgba(255, 193, 7, 0.4);
}

body.dark-theme .ai-msg.system {
    background: rgba(255, 193, 7, 0.1);
    color: #ffca28;
    border-color: #554000;
}

/* Input Area */
.ai-input-area {
    padding: 10px;
    border-top: 1px solid #ddd;
    display: flex;
    gap: 8px;
    background: transparent;
}

body.dark-theme .ai-input-area {
    border-top-color: #444;
}

.ai-input-area input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 18px;
    /* Rounded input like messengers */
    font-family: inherit;
    outline: none;
    background: white;
    color: #333;
}

/* 4. Routing Button (Custom) */
#routing-btn-container i {
    color: #d32f2f !important;
    /* Redish like standard */
    font-size: 16px !important;
}

/* Force visibility if fa-solid fails */
#routing-btn-container i::before {
    content: "\f23d" !important;
    /* fa-subway or fa-route */
    font-family: "Font Awesome 5 Free" !important;
    font-weight: 900 !important;
}

/* 5. Scale or other custom buttons (Ensure black text) */
/* 5. Scale Control (Restored & Styled) */
.leaflet-control-graphicscale {
    display: block !important;
    background: transparent !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none;
    box-shadow: none;
    padding: 2px 5px;
    margin-bottom: 25px !important;
    box-sizing: border-box;
    text-shadow: 0px 0px 2px white;
}

body.dark-theme .leaflet-control-graphicscale {
    background: transparent !important;
    border-color: transparent;
    color: #eee;
    text-shadow: 0px 0px 2px black;
}

/* Ensure text inside is visible */
.leaflet-control-graphicscale .label {
    color: #333;
    font-weight: bold;
}

body.dark-theme .leaflet-control-graphicscale .label {
    color: #eee;
}

/* 6. Magic Wand (AutoTerritory) */
.auto-territory-btn i {
    color: #6a1b9a !important;
    font-size: 16px !important;
}


body.dark-theme .ai-input-area input {
    background: #333;
    border-color: #555;
    color: white;
}

.ai-input-area button {
    background: #1976d2;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.ai-input-area button:hover:not(:disabled) {
    background: #1565c0;
}

.ai-input-area button:disabled {
    background: #ccc;
    cursor: default;
}

/* Progress Bar (FR-4) */
.ai-progress-bar {
    padding: 0 15px 10px 15px;
    font-size: 11px;
    color: #666;
    text-align: center;
}

.ai-progress-bar .bar-container {
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    margin-top: 5px;
    overflow: hidden;
}

.ai-progress-bar .bar {
    height: 100%;
    background: linear-gradient(90deg, #42a5f5, #1976d2);
    width: 0%;
    transition: width 0.3s ease;
}

body.dark-theme .ai-progress-bar {
    color: #aaa;
}

body.dark-theme .ai-progress-bar .bar-container {
    background: #555;
}

/* Mobile Adaptiveness (FR-2.2) */
@media (max-width: 600px) {
    .ai-chat-window {
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 60vh;
        border-radius: 12px 12px 0 0;
        margin: 0;
    }
}

/* === CUSTOM ROUTE PANEL === */
.route-panel {
    position: absolute;
    top: 10px;
    left: 270px;
    /* Right of main controls */
    width: 420px;
    /* Route Panel Glass */
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    z-index: 1005;
    /* High enough */
    display: flex;
    flex-direction: column;
    padding: 10px;
    box-sizing: border-box;
    transition: transform 0.3s ease, opacity 0.3s ease;
    max-height: calc(100vh - 40px);
}

.route-panel.hidden {
    display: none !important;
}

/* Header */
.route-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #eee;
    font-weight: bold;
    color: #333;
    font-size: 14px;
}

/* Blocks */
.route-block {
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.route-label {
    font-size: 11px;
    font-weight: bold;
    color: #666;
    text-transform: uppercase;
}

.route-input-group {
    display: flex;
    gap: 5px;
}

.route-input {
    flex: 1;
    padding: 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 12px;
}

.route-btn {
    padding: 0 8px;
    border: 1px solid #ccc;
    /* Generic border */
    background: #f0f0f0;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.route-btn:hover {
    background: #e0e0e0;
}

/* List */
.route-waypoints-list {
    list-style: none;
    padding: 0;
    margin: 5px 0;
    overflow-y: auto;
    flex: 1;
    min-height: 50px;
    border: 1px solid #f0f0f0;
    /* Slight border area */
    border-radius: 4px;
}

.route-item {
    display: flex;
    align-items: center;
    padding: 6px;
    background: white;
    border-bottom: 1px solid #eee;
    cursor: grab;
    transition: background 0.1s;
}

.route-item:last-child {
    border-bottom: none;
}

.route-item.dragging {
    opacity: 0.5;
    background: #e3f2fd;
    border: 1px dashed #2196f3;
}

.route-item-drag-handle {
    margin-right: 8px;
    color: #999;
    cursor: grab;
}

.route-item-text {
    flex: 1;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 5px;
}

.route-item-remove {
    color: #ccc;
    cursor: pointer;
    font-size: 14px;
    padding: 2px;
}

.route-item-remove:hover {
    color: #f44336;
}

.route-panel-footer {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: space-between;
}

/* Colors */
.input-start {
    border-left: 3px solid #4CAF50;
}

.input-finish {
    border-left: 3px solid #f44336;
}

body.dark-theme .route-panel {
    background: rgba(40, 40, 40, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #f0f0f0;
}

body.dark-theme .route-item {
    background: #333;
    border-color: #444;
}

body.dark-theme .route-input {
    background: #2b2b2b;
    border-color: #555;
    color: white;
}

/* === HORIZONTAL RIGHT MENU (CUSTOM REQUEST) === */
.leaflet-top.leaflet-right {
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-start;
    gap: 8px;
    padding-top: 10px;
    padding-right: 10px;
    pointer-events: none;
}

.leaflet-top.leaflet-right .leaflet-control {
    pointer-events: auto;
    margin: 0 0 0 8px !important;
    /* Spacing between controls */
    background: rgba(255, 255, 255, 0.7) !important;
    backdrop-filter: blur(2px);
    border: 1px solid rgba(0, 0, 0, 0.2);
    box-shadow: none !important;
    border-radius: 4px !important;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    /* Default size for single buttons */
    min-width: 30px;
    min-height: 30px;
}

/* ZOOM CONTROL EXCEPTION */
.leaflet-top.leaflet-right .leaflet-control-zoom {
    display: flex;
    flex-direction: column !important;
    /* Stack + and - */
    width: 30px !important;
    height: auto !important;
    /* Allow growing */
    padding: 0;
    min-height: 60px;
    /* 2 buttons */
}

.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
    width: 30px !important;
    height: 30px !important;
    line-height: 30px !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 18px !important;
    color: #333 !important;
    text-decoration: none !important;
    background-color: transparent !important;
    /* Only color, keep structure */
    border-bottom: 1px solid #ccc !important;
}

.leaflet-control-zoom-out {
    border-bottom: none !important;
}

/* LAYER CONTROL EXCEPTION */
.leaflet-top.leaflet-right .leaflet-control-layers {
    width: auto !important;
    /* Allow expansion */
    height: auto !important;
    background: white !important;
}

/* GENERIC LINKS (CUSTOM BUTTONS 5,6,7...) */
/* GENERIC LINKS (CUSTOM BUTTONS 5,6,7...) */
/* [FIX] Exclude standard Leaflet controls to prevent breaking their icons/dimensions */
.leaflet-top.leaflet-right .leaflet-control a:not(.leaflet-control-zoom-in):not(.leaflet-control-zoom-out):not(.leaflet-control-layers-toggle) {
    width: 30px !important;
    height: 30px !important;
    line-height: 30px !important;

    color: #333;
    text-decoration: none;

    display: block !important;
    text-align: center;

    /* Center background icons for other plugins (like Geocoder) */
    background-position: 50% 50%;
    background-repeat: no-repeat;

    cursor: pointer;
}

/* Flex centering for FontAwesome icons or Emojis */
.leaflet-top.leaflet-right .leaflet-control a:not(.leaflet-control-zoom-in):not(.leaflet-control-zoom-out):not(.leaflet-control-layers-toggle):has(i),
.leaflet-top.leaflet-right .leaflet-control a:not(.leaflet-control-zoom-in):not(.leaflet-control-zoom-out):not(.leaflet-control-layers-toggle)[title*="Radius"] {
    /* Hack for Emoji? or just rely on block+text-align */
    display: flex !important;
    align-items: center;
    justify-content: center;
}

/* Ensure controls themselves have the white backing and shadow */
.leaflet-top.leaflet-right .leaflet-control {
    background: rgba(255, 255, 255, 0.9) !important;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4) !important;
    border: none !important;
    border-radius: 4px !important;
}

.leaflet-top.leaflet-right {
    counter-reset: right-menu-num;
}

/* Numbering Badge (Skip layers expanded and zoom) */
.leaflet-top.leaflet-right .leaflet-control:not(.leaflet-control-layers-expanded):not(.leaflet-control-zoom)::after {
    counter-increment: right-menu-num;
    content: counter(right-menu-num);
    position: absolute;
    bottom: -3px;
    right: -3px;
    background: #555;
    color: white;
    font-size: 8px;
    width: 12px;
    height: 12px;
    line-height: 12px;
    text-align: center;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0.9;
}

.leaflet-top.leaflet-right .leaflet-control:hover {
    background: rgba(255, 255, 255, 0.95) !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
}

body.dark-theme .leaflet-top.leaflet-right .leaflet-control {
    background: rgba(40, 40, 40, 0.7) !important;
    border-color: rgba(255, 255, 255, 0.2);
    color: #eee;
}

body.dark-theme .leaflet-top.leaflet-right .leaflet-control a {
    color: #eee;
}



/* === RESTORE LAYERS ICON === */
.leaflet-control-layers-toggle {
    background-image: url('images/layers.png');
    width: 30px;
    height: 30px;
    background-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* === RESTORE LAYERS ICON (STANDARD) === */
.leaflet-control-layers-toggle {
    background-image: url('images/layers.png');
    width: 36px !important;
    height: 36px !important;
    background-size: 24px;
    background-position: center;
    background-repeat: no-repeat;
    background-color: white;
    border-radius: 4px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
}

.leaflet-control-layers-toggle::before {
    content: none !important;
    /* No emoji */
}

/* === CLEAN STANDARD MENU === */
.leaflet-control-layers-expanded {
    padding: 10px !important;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    color: #333;
    width: auto !important;
    min-width: 150px;
}

.leaflet-control-layers-list {
    margin: 0 !important;
    padding: 0 !important;
}

.leaflet-control-layers label {
    display: flex;
    align-items: center;
    margin: 0 !important;
    padding: 4px 0 !important;
}

/* Fix radio/checkbox spacing */
.leaflet-control-layers-selector {
    margin: 0 8px 0 0 !important;
    cursor: pointer;
}

/* === CLASSIC LAYER CONTROL (RESTORED) === */

/* Remove any pseudo-element headers user hated */
.leaflet-control-layers-list::before {
    content: none !important;
    display: none !important;
}

.leaflet-control-layers-base,
.leaflet-control-layers-overlays {
    margin: 0;
    padding: 0;
    list-style: none;
    /* No bullets */
}

/* Container: Compact and Simple */
.leaflet-control-layers-expanded {
    padding: 10px !important;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    color: #333;
    font-size: 13px;
    line-height: normal;
    min-width: 180px;
    /* Ensure content fits */
    width: auto !important;
}

/* Rows: one line only */
.leaflet-control-layers-label {
    white-space: nowrap !important;
}

.leaflet-control-layers label {
    display: flex;
    align-items: center;
    padding: 4px 0 !important;
    margin: 0 !important;
    cursor: pointer;
    white-space: nowrap !important;
    /* [FIX] No wrapping */
}

/* Radio/Checkbox: Standard positioning */
.leaflet-control-layers-selector {
    margin: 0 6px 0 0 !important;
    /* Minimal gap */
    position: relative;
    top: 1px;
    cursor: pointer;
}

/* List: No forced indentation */
.leaflet-control-layers-list {
    padding-left: 0 !important;
}

/* === LEFT MENU NUMBERING === */
.controls-container {
    counter-reset: left-menu-num;

}

.control-item::before {
    counter-increment: left-menu-num;
    content: counter(left-menu-num) ".";
    color: #888;
    font-size: 11px;
    font-weight: bold;
    margin-right: 5px;
    /* Reduced from potential default or flex gap */
    min-width: 15px;
    /* ensure alignment */
    display: inline-block;
}

/* Exclude specific items if needed */
.control-item-group,
.layer-main-info {
    position: relative;
}

.control-item {
    display: flex;
    justify-content: flex-start !important;
    align-items: center;
}

/* Hide annoying Draw Tooltip "Click to cancel..." */
.leaflet-draw-tooltip,
.leaflet-draw-tooltip-single {
    display: none !important;
}

/* === ORDERING OF RIGHT CONTROLS === */
.leaflet-top.leaflet-right {
    display: flex !important;
    flex-direction: column !important;
}



/* Allow children to size naturally */




/* Allow children to size naturally */
.control-item>* {
    flex: 0 1 auto !important;
    margin: 0 !important;
}

/* Checkbox specific */
.control-item input[type="checkbox"] {
    width: auto !important;
    margin: 0 5px 0 0 !important;
    transform: scale(1.1);
    /* Slightly larger */
}


/* === LEFT MENU COMPACTNESS (REVERTED & REFINED) === */
/* User requested revert, but "remove huge problems with checkboxes 4-6" */
/* We keep standard font sizes but fix specific spacing */

.control-item {
    /* Revert to standard or slight padding */
    padding: 5px 0;
    font-size: 14px;
    /* Back to normal */
}

/* Fix for checkboxes 4-6 (Hexagon controls) */
/* Assuming they are items inside controls-container */
.control-item input[type="checkbox"]+label {
    margin-left: 5px;
    display: inline-block;
}

/* Remove 100% width white space if caused by flex */
.controls-container {
    padding-bottom: 2px;
}

/* Compact the group for "Visual Style" to reduce gap before text */
.control-item-group .control-item {
    margin-bottom: 2px;
}

/* Only number top-level items or specific settings */
/* Strategy: Number every .control-item that is direct child or major group? */
/* User said: "pro markiruy vse chichi nastroek" (mark all setting features) */
.control-item::before {
    counter-increment: left-menu-num;
    content: counter(left-menu-num) ". ";
    font-size: 10px;
    color: #888;
    margin-right: 4px;
    font-weight: bold;
}

/* Exclude save/reset buttons container if it's a control-item */
.control-item:has(button)::before {
    content: none;
    counter-increment: none;
}


/* === REVERT TO VERTICAL (FIX) === */
.leaflet-top.leaflet-right {
    flex-direction: column !important;
    /* Revert to vertical */
    align-items: flex-end !important;
    /* Align to right */
    gap: 5px !important;
}

.leaflet-top.leaflet-right .leaflet-control {
    margin-bottom: 5px !important;
    /* Add spacing between buttons */
}

/* [FIX] Remove duplicate background image from toggle and ensure valid CSS */
/* [FIX] Remove duplicate background image from toggle and ensure valid CSS */
.leaflet-control-layers-toggle {
    background-image: none !important;
    background-color: white !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.leaflet-control-layers-toggle::after {
    content: "\f5fd";
    /* fa-layer-group */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 18px;
    color: #333;
}

/* [FORCE FIX] Explicitly draw icons for controls */

/* 1. Zoom Controls */
.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
    font-size: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.leaflet-control-zoom-in::after {
    content: "\f067";
    /* fa-plus */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 16px;
    color: #333;
}

.leaflet-control-zoom-out::after {
    content: "\f068";
    /* fa-minus */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 16px;
    color: #333;
}

/* 3. Search Control (Leaflet Geocoder) */
.leaflet-control-geocoder-icon {
    background-image: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 30px !important;
    height: 30px !important;
}

.leaflet-control-geocoder-icon::after {
    content: "\f002";
    /* fa-search */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 16px;
    color: #333;
}

/* 4. Routing Button (Custom) */
#routing-btn-container i {
    display: none !important;
    /* Hide original i if broken */
}

#routing-btn-container {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

#routing-btn-container::before {
    content: "\f018";
    /* fa-road */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 16px;
    color: #d32f2f;
}

/* 5. Isochrone Buttons */
.iso-btn-api,
.iso-btn-grid {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.iso-btn-api i,
.iso-btn-grid i {
    display: none !important;
}

.iso-btn-api::after {
    content: "\f084";
    /* fa-key */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 16px;
    color: #333;
}

.iso-btn-grid::after {
    content: "\f1de";
    /* fa-sliders-h */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 16px;
    color: #333;
}

/* 6. Magic Wand (AutoTerritory) */
.auto-territory-btn i {
    color: #6a1b9a !important;
    font-size: 16px !important;
}

/* 7. Generic Fallback for Emojis (Radius, etc) */
.leaflet-top.leaflet-right .leaflet-control a {
    color: #333 !important;
    text-align: center !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-decoration: none !important;
}

/* [FIX] Ensure layer control scrolls if list is too long */
.leaflet-control-layers-list {
    max-height: 70vh !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    scrollbar-width: thin;
}

.leaflet-control-layers-list::-webkit-scrollbar {
    width: 6px;
}

.leaflet-control-layers-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.leaflet-control-layers-toggle::after {
    content: "\f5fd";
    /* fa-layer-group */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 18px;
    color: #333;
}

/* [FORCE FIX] Explicitly draw icons for controls */

/* 1. Zoom Controls */
.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
    font-size: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.leaflet-control-zoom-in::after {
    content: "\f067";
    /* fa-plus */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 16px;
    color: #333;
}

.leaflet-control-zoom-out::after {
    content: "\f068";
    /* fa-minus */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 16px;
    color: #333;
}

/* 3. Search Control (Leaflet Geocoder) */
.leaflet-control-geocoder-icon {
    background-image: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 30px !important;
    height: 30px !important;
}

.leaflet-control-geocoder-icon::after {
    content: "\f002";
    /* fa-search */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 16px;
    color: #333;
}

/* 4. Routing Button (Custom) */
#routing-btn-container i {
    display: none !important;
    /* Hide original i if broken */
}

#routing-btn-container {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

#routing-btn-container::before {
    content: "\f018";
    /* fa-road */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 16px;
    color: #d32f2f;
}

/* 5. Isochrone Buttons */
.iso-btn-api,
.iso-btn-grid {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.iso-btn-api i,
.iso-btn-grid i {
    display: none !important;
}

.iso-btn-api::after {
    content: "\f084";
    /* fa-key */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 16px;
    color: #333;
}

.iso-btn-grid::after {
    content: "\f1de";
    /* fa-sliders-h */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 16px;
    color: #333;
}

/* 6. Magic Wand (AutoTerritory) */
.auto-territory-btn i {
    color: #6a1b9a !important;
    font-size: 16px !important;
}

/* 7. Generic Fallback for Emojis (Radius, etc) */
.leaflet-top.leaflet-right .leaflet-control a {
    color: #333 !important;
    text-align: center !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-decoration: none !important;
}

/* [FIX] Ensure layer control scrolls if list is too long */
.leaflet-control-layers-list {
    max-height: 70vh !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    scrollbar-width: thin;
}

.leaflet-control-layers-list::-webkit-scrollbar {
    width: 6px;
}

.leaflet-control-layers-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* === VISUAL TABLE ENHANCEMENTS (Gradient Bars & Sparklines) === */

/* Gradient Bar Container (Overlay Style) */
.bar-cell-container {
    display: flex;
    align-items: center;
    width: 100%;
    height: 100%;
    /* Full cell height */
    position: relative;
    padding: 0 4px;
    /* Slight padding for text */
}

/* Hide track */
.bar-track {
    display: none;
}

/* Gradient Fill (Background Layer) */
.bar-fill {
    position: absolute;
    left: 2px;
    top: 3px;
    bottom: 3px;
    z-index: 1;
    border-radius: 4px;
    transition: width 0.4s ease-out;
    /* Vibrant Gradient: Green -> Cyan -> Blue */
    background: linear-gradient(90deg, rgba(76, 175, 80, 0.8), rgba(33, 150, 243, 0.8));
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

/* Negative/Red Gradient */
.bar-fill.negative {
    background: linear-gradient(90deg, rgba(239, 83, 80, 0.8), rgba(211, 47, 47, 0.8));
}

/* Value Text (Overlay) */
.bar-value {
    position: relative;
    z-index: 2;
    /* On top of bar */
    font-size: 13px;
    font-weight: 700;
    color: #333;
    /* Dark text for contrast against light gradient usually, or assume opacity handles it */
    margin-left: 6px;
    text-shadow: 0 0 2px rgba(255, 255, 255, 0.8);
    /* Ensure readable */
}



body.dark-theme .bar-value {
    color: #ccc;
}

/* Sparklines */
.sparkline-svg {
    width: 100%;
    height: 100%;
    display: block;
    overflow: visible;
}

.sparkline-path {
    fill: none;
    stroke: #2196f3;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
}

.sparkline-fill {
    fill: rgba(33, 150, 243, 0.1);
    /* Subtle fill below line */
    stroke: none;
}

body.dark-theme .sparkline-path {
    stroke: #64b5f6;
}