body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* Гарантуємо, що карта займає весь простір */
#map {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    background-color: #e5e9ec; /* Світлий фон поки вантажиться карта */
    z-index: 1;
}

/* --- ТЕМНА ТЕМА --- */
body.dark-theme #map {
    background-color: #2b2b2b;
}
body.dark-theme .leaflet-tile-pane {
    filter: brightness(0.6) invert(1) contrast(3) hue-rotate(200deg) saturate(0.3) brightness(0.7);
}
body.dark-theme #filter-container {
    background: #1f1f1f;
    color: #f0f0f0;
}
body.dark-theme .filter-header {
    border-bottom-color: #333;
}
body.dark-theme #route-list label:hover {
    background-color: #333;
}
body.dark-theme .control-btn {
    background: #333;
    color: #f0f0f0;
    border-color: #555;
}
body.dark-theme #route-list input[type="checkbox"] {
    background-color: #444;
    border-color: #666;
}
body.dark-theme .select-all-label {
    border-bottom-color: #333;
}
body.dark-theme .route-type-header {
    color: #aaa;
    border-top-color: #333;
}

/* --- КНОПКИ КЕРУВАННЯ --- */
.controls-container {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 1000; /* Поверх карти */
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-btn {
    width: 40px;
    height: 40px;
    background: white;
    border: 1px solid rgba(0,0,0,0.2);
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    transition: background-color 0.2s, transform 0.1s;
}

.control-btn:active {
    transform: scale(0.95);
}

/* --- ПАНЕЛЬ ФІЛЬТРІВ (КОМПАКТНА) --- */
#filter-container {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 200px; /* Компактна ширина */
    max-height: calc(100% - 20px);
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 1002;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateX(120%); /* Сховано за замовчуванням на мобільних */
}

/* На десктопі панель видна, якщо не схована */
@media (min-width: 769px) {
    #filter-container {
        transform: translateX(0);
    }
    #toggle-filter-btn {
        display: none;
    }
}

/* На мобільних */
@media (max-width: 768px) {
    .controls-container {
        top: 10px;
        left: 10px;
    }
    
    #filter-container {
        top: 0;
        right: 0;
        width: 240px; /* Трохи ширше для пальців */
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        transform: translateX(100%);
    }

    #filter-container.is-open {
        transform: translateX(0);
    }
    
    #toggle-filter-btn {
        display: flex;
    }
}

.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0; /* Заголовок не стискається */
}

.filter-header h3 {
    margin: 0;
    font-size: 16px;
}

#close-filter-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #888;
    padding: 0 5px;
}

#route-list {
    padding: 8px;
    overflow-y: auto;
    flex-grow: 1;
    -webkit-overflow-scrolling: touch;
}

/* Кнопка "Вибрати всі" */
.select-all-label {
    font-weight: bold;
    border-bottom: 1px solid #eee;
    padding-bottom: 8px;
    margin-bottom: 8px !important;
    font-size: 13px;
}

/* Елемент списку */
#route-list label {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 4px;
    margin-bottom: 2px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.2s;
    user-select: none;
    line-height: 1.2;
}

#route-list label:hover {
    background-color: #f5f5f5;
}

#route-list input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-right: 8px;
    accent-color: #3388ff;
    cursor: pointer;
    flex-shrink: 0;
}

/* Заголовки типів */
.route-type-header {
    color: #888;
    font-size: 11px;
    margin-top: 12px;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-top: 1px solid #eee;
    padding-top: 8px;
    font-weight: bold;
    padding-left: 4px;
}

/* --- МАРКЕРИ ТРАНСПОРТУ --- */
.vehicle-marker-wrapper {
    width: 32px;
    height: 32px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    will-change: transform; /* Оптимізація анімації */
}

.vehicle-arrow-border {
    top: -10px;
    border-width: 0 8px 14px 8px;
    border-color: transparent transparent #333 transparent;
    position: absolute;
    border-style: solid;
    z-index: 0;
}

.vehicle-arrow-fill {
    top: -7px;
    border-width: 0 5px 11px 5px;
    border-color: transparent transparent currentColor transparent;
    position: absolute;
    border-style: solid;
    z-index: 1;
}

.vehicle-circle {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #333;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;
    position: relative;
    color: white;
    font-weight: 700;
    font-size: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    background-color: currentColor;
}

body.dark-theme .vehicle-circle {
    border-color: #fff;
    color: #fff;
    text-shadow: 0 0 2px #000;
}
body.dark-theme .vehicle-arrow-border {
    border-color: transparent transparent #fff transparent;
}

/* Зупинки */
.stop-marker-icon {
    background: white;
    border: 2px solid #3388ff;
    border-radius: 50%;
    box-shadow: 0 0 4px rgba(0,0,0,0.4);
}

/* Лоадер */
#loader {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 2000;
}
.spinner {
    width: 40px; height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

#error-message {
    position: fixed;
    top: 20px; left: 50%;
    transform: translateX(-50%);
    background-color: #ff4444;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    z-index: 2001;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    font-weight: bold;
    display: none;
    text-align: center;
    max-width: 90%;
}

.hidden { display: none !important; }