* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

#map {
    width: 100%;
    height: 100%;
}

/* Легенда */
.legend {
    position: absolute;
    top: 10px;
    left: 10px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    max-width: 320px;
    max-height: calc(100vh - 20px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #e0e0e0;
    background: #f5f5f5;
}

.legend-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.legend-toggle {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
}

.legend-toggle:hover {
    color: #000;
}

.legend-content {
    overflow-y: auto;
    padding: 8px;
    flex: 1;
}

.legend-section {
    margin-bottom: 16px;
}

.legend-section:last-child {
    margin-bottom: 0;
}

.legend-section h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
}

.basemap-switcher {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.basemap-option {
    display: flex;
    align-items: center;
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.basemap-option:hover {
    background-color: #f0f0f0;
}

.basemap-option input[type="radio"] {
    margin-right: 8px;
}

.basemap-option.active {
    background-color: #e3f2fd;
    font-weight: 500;
}

.layers-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 400px;
    overflow-y: auto;
}

.layer-item {
    display: flex;
    align-items: flex-start;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.layer-item:hover {
    background-color: #f0f0f0;
}

.layer-item input[type="checkbox"] {
    margin-right: 8px;
    margin-top: 2px;
    flex-shrink: 0;
}

.layer-item-label {
    flex: 1;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
}

.layer-sublayers {
    margin-left: 24px;
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.layer-sublayer {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: #666;
    padding: 2px 0;
}

.layer-sublayer-color {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    margin-right: 6px;
    border: 1px solid #ccc;
}

.layer-sublayer-icon {
    width: 16px;
    height: 16px;
    margin-right: 6px;
}

/* Кнопки */
.btn {
    width: 100%;
    padding: 10px 16px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 8px;
}

.btn:last-child {
    margin-bottom: 0;
}

.btn-primary {
    background-color: #1976d2;
    color: white;
}

.btn-primary:hover {
    background-color: #1565c0;
}

.btn-secondary {
    background-color: #f5f5f5;
    color: #333;
    border: 1px solid #ddd;
}

.btn-secondary:hover {
    background-color: #e0e0e0;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* GPS контроль */
.gps-control {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

.gps-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: #666;
}

.gps-btn:hover {
    background: #f5f5f5;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.gps-btn.active {
    background: #1976d2;
    color: white;
}

.gps-btn.tracking {
    background: #4caf50;
    color: white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* Popup */
.popup {
    position: absolute;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    padding: 0;
    z-index: 2000;
    max-width: 300px;
    pointer-events: none;
}

.popup-content {
    padding: 16px;
}

.popup-header {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e0e0e0;
}

.popup-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.popup-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.popup-field-label {
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.popup-field-value {
    font-size: 14px;
    color: #333;
}

.popup-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 18px;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    pointer-events: auto;
}

.popup-close:hover {
    background: #f0f0f0;
    color: #000;
}

/* Індикатор завантаження */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 3000;
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #1976d2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading p {
    margin: 0;
    color: #666;
    font-size: 14px;
}

/* Повідомлення */
.error-message,
.success-message {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 3000;
    max-width: 90%;
    text-align: center;
    font-size: 14px;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.error-message {
    background: #ffebee;
    color: #c62828;
    border: 1px solid #ef5350;
}

.success-message {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #66bb6a;
}

/* Адаптивність для мобільних */
@media (max-width: 768px) {
    .legend {
        max-width: calc(100vw - 20px);
        max-height: calc(100vh - 20px);
    }
    
    .legend.collapsed .legend-content {
        display: none;
    }
    
    .popup {
        max-width: calc(100vw - 40px);
    }
    
    .gps-btn {
        width: 44px;
        height: 44px;
    }
}

/* Маркер GPS */
.gps-marker {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #1976d2;
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.gps-accuracy-circle {
    fill: rgba(25, 118, 210, 0.2);
    stroke: rgba(25, 118, 210, 0.5);
    stroke-width: 2;
}

