/* ========================================
   ОСНОВНІ СТИЛІ КАРТИ
   ======================================== */
body { margin: 0; padding: 0; font-family: Arial, sans-serif; }
#map { height: 100vh; width: 100%; }

/* ========================================
   ПОШУК
   ======================================== */
.search-box {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    width: 90%;
    max-width: 500px;
}
.search-input {
    width: 100%;
    padding: 12px 20px;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    outline: none;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    box-sizing: border-box;
}
.search-input:focus {
    border-color: #0088cc;
}
.autocomplete-list {
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 300px;
    overflow-y: auto;
    display: none;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
.autocomplete-item {
    padding: 12px 20px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
}
.autocomplete-item:hover {
    background: #f5f5f5;
}
.autocomplete-item:last-child {
    border-bottom: none;
}

/* ========================================
   ЛЕГЕНДА
   ======================================== */
.legend {
    position: fixed;
    bottom: 30px;
    right: 10px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0,0,0,0.3);
    font-size: 14px;
    z-index: 1000;
}
.legend-header {
    padding: 12px 15px;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f5f5f5;
    border-radius: 8px 8px 0 0;
}
.legend-header:hover {
    background: #e0e0e0;
}
.legend-content {
    padding: 10px 15px;
    display: block;
}
.legend-content.collapsed {
    display: none;
}
.legend-item {
    margin: 8px 0;
    display: flex;
    align-items: center;
}
.legend-emoji {
    font-size: 20px;
    margin-right: 8px;
}
.toggle-icon {
    font-size: 18px;
    transition: transform 0.3s;
}
.toggle-icon.collapsed {
    transform: rotate(-90deg);
}
.legend-links {
    padding: 10px 15px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.legend-links a {
    display: block;
    padding: 10px 12px;
    background: #0088cc;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    text-align: center;
    font-size: 13px;
    transition: background 0.3s;
}
.legend-links a:hover {
    background: #006699;
}

/* ========================================
   POPUP
   ======================================== */
.popup-schedule-links {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
    text-align: center;
    font-size: 14px;
}
.popup-schedule-links a {
    color: #0088cc;
    text-decoration: none;
    margin: 0 5px;
}
.popup-schedule-links a:hover {
    text-decoration: underline;
}

/* ========================================
   МАРКЕРИ
   ======================================== */
.emoji-marker {
    font-size: 24px;
    text-align: center;
    line-height: 1;
}

.leaflet-popup-content-wrapper {
    border-radius: 8px;
}

.leaflet-popup-content {
    margin: 15px !important;
    font-size: 16px !important;
    line-height: 1.5 !important;
}

/* ========================================
   КЛАСТЕРИ
   ======================================== */
.marker-cluster-custom {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    text-align: center;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    border: 3px solid;
    display: flex;
    align-items: center;
    justify-content: center;
}
.marker-cluster-custom span {
    font-size: 14px;
    color: #333;
}
.cluster-on {
    border-color: #4CAF50;
    background: rgba(76, 175, 80, 0.15);
}
.cluster-off {
    border-color: #f44336;
    background: rgba(244, 67, 54, 0.15);
}
.cluster-mixed {
    border-color: #FF9800;
    background: rgba(255, 152, 0, 0.15);
}

.cluster-mostly-on {
    border-color: #8BC34A;
    background: rgba(139, 195, 74, 0.15);
}
.cluster-mostly-off {
    border-color: #FF5722;
    background: rgba(255, 87, 34, 0.15);
}
/* ========================================
   МОБІЛЬНІ ПРИСТРОЇ
   ======================================== */
@media (max-width: 768px) {
    .leaflet-control-zoom {
        display: none !important;
    }
    
    .search-box {
        top: 10px;
        left: 10px;
        right: 10px;
        width: auto;
        max-width: none;
        transform: none;
    }
    
    .search-input {
        font-size: 16px;
        padding: 14px 18px;
    }
    
    .autocomplete-item {
        padding: 14px 18px;
        font-size: 15px;
    }
    
    .legend {
        bottom: 10px;
        right: 10px;
        font-size: 13px;
    }
    
    .legend-emoji {
        font-size: 18px;
    }
    
    .emoji-marker {
        font-size: 28px;
    }
    
    .leaflet-popup-content {
        font-size: 16px !important;
        min-width: 260px !important;
    }
    
    #lastUpdate, #weatherInfo {
        font-size: 12px !important;
    }
}

/* ========================================
   BOTTOM SHEET ДЛЯ МОБІЛЬНОГО
   ======================================== */

.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    backdrop-filter: blur(2px);
}

.mobile-overlay.active {
    display: block;
}

.mobile-bottom-sheet {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    z-index: 9999;
    max-height: 85vh;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
}

.mobile-bottom-sheet.active {
    display: block;
    transform: translateY(0);
}

.bottom-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
    position: sticky;
    top: 0;
    background: white;
    border-radius: 16px 16px 0 0;
    z-index: 10;
}

.bottom-sheet-title {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    flex: 1;
    padding-right: 10px;
}

.bottom-sheet-close {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f5f5f5;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.bottom-sheet-close:active {
    background: #e0e0e0;
}

.bottom-sheet-content {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(85vh - 70px);
    -webkit-overflow-scrolling: touch;
}

.bottom-sheet-content p {
    margin: 12px 0;
    font-size: 16px;
    line-height: 1.6;
}

.bottom-sheet-content h3 {
    margin: 0 0 12px 0;
    font-size: 18px;
    font-weight: bold;
}

.bottom-sheet-content strong {
    color: #333;
}

.bottom-sheet-content a {
    color: #0088cc;
    text-decoration: none;
    font-weight: bold;
}

.bottom-sheet-content a:active {
    opacity: 0.7;
}

.schedule-item {
    margin: 8px 0;
    padding: 12px;
    background: #f5f5f5;
    border-radius: 8px;
    font-size: 15px;
}

.bottom-sheet-links {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
    text-align: center;
    font-size: 15px;
}

.bottom-sheet-links a {
    color: #0088cc;
    text-decoration: none;
    margin: 0 8px;
    display: inline-block;
    padding: 4px 0;
}

@media (max-width: 768px) {
    .leaflet-popup {
        display: none !important;
    }
    
    body.bottom-sheet-open .leaflet-container {
        pointer-events: none !important;
    }
    
    body.bottom-sheet-open {
        overflow: hidden;
    }
}

@media (min-width: 769px) {
    .mobile-overlay,
    .mobile-bottom-sheet {
        display: none !important;
    }
}

/* ========================================
   ІНТЕРАКТИВНА ЛЕГЕНДА - ФІЛЬТРАЦІЯ
   ======================================== */

/* Кликабельні елементи легенди */
.legend-item.clickable {
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    padding: 6px 8px;
    margin: 4px 0;
    border-radius: 4px;
}

.legend-item.clickable:hover {
    background-color: rgba(0, 123, 255, 0.1);
    transform: translateX(3px);
}

.legend-item.clickable:active {
    transform: scale(0.98);
}

/* Активний фільтр */
.legend-item.active {
    background-color: rgba(0, 123, 255, 0.2);
    font-weight: bold;
    border-left: 3px solid #007bff;
    padding-left: 5px;
}

/* ========================================
   КНОПКА "ПОКАЗАТИ ВСІ"
   ======================================== */

.show-all-button {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    
    background: #ff4444;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all 0.2s;
}

.show-all-button:hover {
    background: #ff0000;
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.show-all-button:active {
    transform: translateX(-50%) scale(0.98);
}

/* Адаптив для мобільних */
@media (max-width: 768px) {
    .show-all-button {
        top: 10px;
        padding: 10px 20px;
        font-size: 14px;
    }
}
/* ========================================
   КНОПКА ОНОВЛЕННЯ ДАНИХ
   ======================================== */
.refresh-button {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    
    background: #28a745;
    color: white;
    padding: 8px 20px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all 0.3s;
    
    display: flex;
    align-items: center;
    gap: 8px;
}
.refresh-button:hover {
    background: #218838;
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}
.refresh-button:active {
    transform: translateX(-50%) scale(0.98);
}
/* Анімація обертання під час оновлення */
.refresh-button.loading #refreshIcon {
    display: inline-block;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
/* Адаптив для мобільних */
@media (max-width: 768px) {
    .refresh-button {
        top: 70px;
        padding: 8px 16px;
        font-size: 13px;
    }
}

.share-buttons {
    display: flex;
    gap: 10px;
    margin: 24px 0;
    flex-wrap: wrap;
}

.share-buttons a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 999px;
    text-decoration: none;
    font-size: .88rem;
    font-weight: 600;
    transition: opacity .2s, transform .2s;
}

.share-buttons a:hover { opacity: .85; transform: translateY(-2px); }

.share-tg { background: #229ED9; color: #fff; }
.share-wa { background: #25D366; color: #fff; }
.share-fb { background: #1877F2; color: #fff; }
.share-tw { background: #000; color: #fff; }

.grid--hero {
    display: grid;
    grid-template-columns: 2fr 1fr;
    grid-template-rows: auto;
    gap: 20px;
}

.grid--hero .card:nth-child(1) {
    grid-row: 1;
    grid-column: 1;
}

.grid--hero .card:nth-child(2),
.grid--hero .card:nth-child(3),
.grid--hero .card:nth-child(4) {
    grid-column: 2;
}

.grid--hero .card:nth-child(n+5) {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

@media (max-width: 640px) {
    .grid--hero { grid-template-columns: 1fr; }
    .grid--hero .card:nth-child(2),
    .grid--hero .card:nth-child(3),
    .grid--hero .card:nth-child(4) { grid-column: 1; }
    .grid--hero .card:nth-child(n+5) { grid-template-columns: 1fr; }
}